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

Tiezhu Yang posted 4 patches 1 year, 7 months ago
There is a newer version of this series
[RFC PATCH 1/4] objtool: Check local label in find_jump_table()
Posted by Tiezhu Yang 1 year, 7 months ago
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 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