[PATCH v1 6/6] objtool/LoongArch: Add support for goto table

Tiezhu Yang posted 6 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v1 6/6] objtool/LoongArch: Add support for goto table
Posted by Tiezhu Yang 1 month, 1 week ago
If find_reloc_by_table_annotate() failed, it means that there
is no relocation info of switch table address in the section
".rela.discard.tablejump_annotate", then objtool can find the
relocation against the nearest instruction before the jump
instruction with find_reloc_by_dest_range(), which points to
the goto table.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/objtool/arch/loongarch/special.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/loongarch/special.c
index 65b1ed297d57..d2a6071d772f 100644
--- a/tools/objtool/arch/loongarch/special.c
+++ b/tools/objtool/arch/loongarch/special.c
@@ -47,8 +47,18 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,
 	unsigned long table_offset;
 
 	annotate_reloc = find_reloc_by_table_annotate(file, insn);
-	if (!annotate_reloc)
-		return NULL;
+	if (!annotate_reloc) {
+		annotate_reloc = find_reloc_by_dest_range(file->elf, insn->sec,
+							  insn->offset, insn->len);
+		if (!annotate_reloc)
+			return NULL;
+
+		if (!annotate_reloc->sym->sec->rodata)
+			return NULL;
+
+		if (reloc_type(annotate_reloc) != R_LARCH_NONE)
+			return NULL;
+	}
 
 	table_sec = annotate_reloc->sym->sec;
 	table_offset = annotate_reloc->sym->offset;
-- 
2.42.0