[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241119065655.21123-7-yangtiezhu@loongson.cn>
Date: Tue, 19 Nov 2024 14:56:51 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: Huacai Chen <chenhuacai@...nel.org>,
Josh Poimboeuf <jpoimboe@...nel.org>,
Peter Zijlstra <peterz@...radead.org>
Cc: loongarch@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: [PATCH v3 06/10] objtool: Handle unsorted table offset of rodata
When compling with Clang on LoongArch, there are unsorted table offset
of rodata if there exist many jump tables, it will get the wrong table
end and find the wrong jump destination instructions in add_jump_table(),
so it needs to check the table size of rodata to break the process when
parsing the relocation section of rodata.
This is preparation for later patch on LoongArch, there is no effect for
the other archs with this patch.
Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
---
tools/objtool/check.c | 7 +++++++
tools/objtool/include/objtool/check.h | 1 +
2 files changed, 8 insertions(+)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 17df3738e087..cad9e0c21123 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2093,6 +2093,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
struct alternative *alt;
unsigned long offset;
unsigned long rodata_entry_size;
+ unsigned long rodata_table_size = insn->table_size;
/*
* Each @reloc is a switch table relocation which points to the target
@@ -2104,6 +2105,12 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
if (reloc != table && reloc == next_table)
break;
+ /* Handle the special cases compiled with Clang on LoongArch */
+ if (file->elf->ehdr.e_machine == EM_LOONGARCH &&
+ reloc->sym->type == STT_SECTION && reloc != table &&
+ reloc_offset(reloc) == reloc_offset(table) + rodata_table_size)
+ break;
+
/* Handle the special cases compiled with Clang on LoongArch */
if (file->elf->ehdr.e_machine == EM_LOONGARCH &&
reloc_type(reloc) == R_LARCH_32_PCREL)
diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/objtool/check.h
index daa46f1f0965..11aafcc7b0c7 100644
--- a/tools/objtool/include/objtool/check.h
+++ b/tools/objtool/include/objtool/check.h
@@ -46,6 +46,7 @@ struct instruction {
struct section *sec;
unsigned long offset;
unsigned long immediate;
+ unsigned long table_size;
u8 len;
u8 prev_len;
--
2.42.0
Powered by blists - more mailing lists