When tracing function validation, instruction state changes can
report changes involving registers. These registers are reported
with the name "r<num>" (e.g. "r3"). Print the CPU specific register
name instead of a generic name (e.g. print "rbx" instead of "r3"
on x86).
Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
tools/objtool/arch/loongarch/decode.c | 11 +++++++++++
tools/objtool/arch/powerpc/decode.c | 12 ++++++++++++
tools/objtool/arch/x86/decode.c | 8 ++++++++
tools/objtool/disas.c | 7 +++++++
tools/objtool/include/objtool/arch.h | 2 ++
5 files changed, 40 insertions(+)
diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loongarch/decode.c
index bf5ac6750512..fbad237e54fb 100644
--- a/tools/objtool/arch/loongarch/decode.c
+++ b/tools/objtool/arch/loongarch/decode.c
@@ -7,6 +7,17 @@
#include <linux/objtool_types.h>
#include <arch/elf.h>
+const char *arch_reg_name[CFI_NUM_REGS] = {
+ "zero", "ra", "tp", "sp",
+ "a0", "a1", "a2", "a3",
+ "a4", "a5", "a6", "a7",
+ "t0", "t1", "t2", "t3",
+ "t4", "t5", "t6", "t7",
+ "t8", "u0", "fp", "s0",
+ "s1", "s2", "s3", "s4",
+ "s5", "s6", "s7", "s8"
+};
+
int arch_ftrace_match(char *name)
{
return !strcmp(name, "_mcount");
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index c0fcab2d643c..df5bf6476b78 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -9,6 +9,18 @@
#include <objtool/builtin.h>
#include <objtool/endianness.h>
+const char *arch_reg_name[CFI_NUM_REGS] = {
+ "r0", "sp", "r2", "r3",
+ "r4", "r5", "r6", "r7",
+ "r8", "r9", "r10", "r11",
+ "r12", "r13", "r14", "r15",
+ "r16", "r17", "r18", "r19",
+ "r20", "r21", "r22", "r23",
+ "r24", "r25", "r26", "r27",
+ "r28", "r29", "r30", "r31",
+ "ra"
+};
+
int arch_ftrace_match(char *name)
{
return !strcmp(name, "_mcount");
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 6c13c67ed9b9..56e2df35c9ee 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -23,6 +23,14 @@
#include <objtool/builtin.h>
#include <arch/elf.h>
+const char *arch_reg_name[CFI_NUM_REGS] = {
+ "rax", "rcx", "rdx", "rbx",
+ "rsp", "rbp", "rsi", "rdi",
+ "r8", "r9", "r10", "r11",
+ "r12", "r13", "r14", "r15",
+ "ra"
+};
+
int arch_ftrace_match(char *name)
{
return !strcmp(name, "__fentry__");
diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c
index 4326c608f925..8265ad7479a3 100644
--- a/tools/objtool/disas.c
+++ b/tools/objtool/disas.c
@@ -38,6 +38,7 @@ struct disas_context {
const char *register_name(unsigned int reg)
{
static char rname_buffer[REGISTER_NAME_MAXLEN];
+ const char *rname;
switch (reg) {
case CFI_UNDEFINED:
@@ -50,6 +51,12 @@ const char *register_name(unsigned int reg)
return "(bp)";
}
+ if (reg < CFI_NUM_REGS) {
+ rname = arch_reg_name[reg];
+ if (rname)
+ return rname;
+ }
+
if (snprintf(rname_buffer, REGISTER_NAME_MAXLEN, "r%d", reg) == 1)
return NULL;
diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/objtool/arch.h
index aecf8fc29571..4736b08805d6 100644
--- a/tools/objtool/include/objtool/arch.h
+++ b/tools/objtool/include/objtool/arch.h
@@ -106,4 +106,6 @@ unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc *tabl
int arch_disas_info_init(struct disassemble_info *dinfo);
+extern const char *arch_reg_name[CFI_NUM_REGS];
+
#endif /* _ARCH_H */
--
2.43.5