[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240712091506.28140-3-yangtiezhu@loongson.cn>
Date: Fri, 12 Jul 2024 17:15:04 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: Josh Poimboeuf <jpoimboe@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Huacai Chen <chenhuacai@...nel.org>
Cc: Xi Ruoyao <xry111@...111.site>,
loongarch@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: [RFC PATCH 2/4] objtool: Check various types in add_jump_table()
Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.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
Powered by blists - more mailing lists