[PATCH v2 4/7] objtool/powerpc: Add necessary support for inline static calls

Christophe Leroy christophe.leroy at csgroup.eu
Sat Jul 9 03:31:23 AEST 2022


In order to support inline static calls for powerpc, objtool needs
the following additions:
- R_REL32 macro
- Support for JUMP instruction used for tail calls

Add the support of decoding branch instruction 'b' which is the jump
instruction used for tail calls. This is because a static call can be
a tail call.

Signed-off-by: Christophe Leroy <christophe.leroy at csgroup.eu>
---
 tools/objtool/arch/powerpc/decode.c           | 16 ++++++++++------
 tools/objtool/arch/powerpc/include/arch/elf.h |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index 06fc0206bf8e..ba84869cd134 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -59,13 +59,17 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 	opcode = insn >> 26;
 
 	switch (opcode) {
-	case 18: /* bl */
-		if ((insn & 3) == 1) {
+	case 18: /* bl/b */
+		if ((insn & 3) == 1)
 			*type = INSN_CALL;
-			*immediate = insn & 0x3fffffc;
-			if (*immediate & 0x2000000)
-				*immediate -= 0x4000000;
-		}
+		else if ((insn & 3) == 0)
+			*type = INSN_JUMP_UNCONDITIONAL;
+		else
+			break;
+
+		*immediate = insn & 0x3fffffc;
+		if (*immediate & 0x2000000)
+			*immediate -= 0x4000000;
 		break;
 	}
 
diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
index 73f9ae172fe5..befc2e30d38b 100644
--- a/tools/objtool/arch/powerpc/include/arch/elf.h
+++ b/tools/objtool/arch/powerpc/include/arch/elf.h
@@ -6,5 +6,6 @@
 #define R_NONE R_PPC_NONE
 #define R_ABS64 R_PPC64_ADDR64
 #define R_ABS32 R_PPC_ADDR32
+#define R_REL32 R_PPC_REL32 /* R_PPC64_REL32 is identical */
 
 #endif /* _OBJTOOL_ARCH_ELF */
-- 
2.36.1



More information about the Linuxppc-dev mailing list