[RFC PATCH 2/4] objtool: Check various types in add_jump_table()

Tiezhu Yang posted 4 patches 1 year, 7 months ago
There is a newer version of this series
[RFC PATCH 2/4] objtool: Check various types in add_jump_table()
Posted by Tiezhu Yang 1 year, 7 months ago
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/objtool/check.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index c89c0d8c35d7..6fa4100206d0 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2027,6 +2027,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
 	unsigned int prev_offset = 0;
 	struct reloc *reloc = table;
 	struct alternative *alt;
+	unsigned long offset;
 
 	/*
 	 * Each @reloc is a switch table relocation which points to the target
@@ -2042,12 +2043,27 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
 		if (prev_offset && reloc_offset(reloc) != prev_offset + 8)
 			break;
 
+		if (reloc->sym->type == STT_SECTION) {
+			offset = reloc_addend(reloc);
+		} else if (reloc->sym->local_label) {
+			offset = reloc->sym->offset;
+		} else if (reloc->sym->type == STT_FUNC) {
+			offset = reloc->sym->offset;
+		} else if (reloc->sym->type == STT_OBJECT) {
+			offset = reloc->sym->offset;
+		} else if (reloc->sym->type == STT_NOTYPE) {
+			offset = reloc->sym->offset;
+		} else {
+			WARN("unexpected relocation symbol type in %s: %d",
+			     table->sec->name, reloc->sym->type);
+			return -1;
+		}
+
 		/* Detect function pointers from contiguous objects: */
-		if (reloc->sym->sec == pfunc->sec &&
-		    reloc_addend(reloc) == pfunc->offset)
+		if (reloc->sym->sec == pfunc->sec && offset == pfunc->offset)
 			break;
 
-		dest_insn = find_insn(file, reloc->sym->sec, reloc_addend(reloc));
+		dest_insn = find_insn(file, reloc->sym->sec, offset);
 		if (!dest_insn)
 			break;
 
-- 
2.42.0