[RFC PATCH 1/4] objtool: Check local label in find_jump_table()

From: Tiezhu Yang
Date: Fri Jul 12 2024 - 05:15:28 EST


Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
tools/objtool/check.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 0a33d9195b7a..c89c0d8c35d7 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2085,6 +2085,7 @@ static struct reloc *find_jump_table(struct objtool_file *file,
{
struct reloc *table_reloc;
struct instruction *dest_insn, *orig_insn = insn;
+ unsigned long offset;

/*
* Backward search using the @first_jump_src links, these help avoid
@@ -2108,7 +2109,18 @@ static struct reloc *find_jump_table(struct objtool_file *file,
table_reloc = arch_find_switch_table(file, insn);
if (!table_reloc)
continue;
- dest_insn = find_insn(file, table_reloc->sym->sec, reloc_addend(table_reloc));
+
+ if (table_reloc->sym->type == STT_SECTION) {
+ offset = reloc_addend(table_reloc);
+ } else if (table_reloc->sym->local_label) {
+ offset = table_reloc->sym->offset;
+ } else {
+ WARN("unexpected relocation symbol type in %s: %d",
+ table_reloc->sec->name, table_reloc->sym->type);
+ return NULL;
+ }
+
+ dest_insn = find_insn(file, table_reloc->sym->sec, offset);
if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != func)
continue;

--
2.42.0