objtool: Handle different entry size of rodata

In the most cases, the entry size of rodata is 8 bytes because the
relocation type is 64 bit, but when compiling with Clang on LoongArch,
there exists 32 bit relocation type, the entry size of rodata should
be 4 bytes in this case.

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@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: michael <michael5hzg@gmail.com>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
This commit is contained in:
Tiezhu Yang
2025-02-13 14:26:40 +08:00
committed by maoxiaochuan
parent b30e13e8b8
commit 606869223f
+13 -1
View File
@@ -26,6 +26,10 @@
#define EM_LOONGARCH 258
#endif
#ifndef R_LARCH_32_PCREL
#define R_LARCH_32_PCREL 99
#endif
struct alternative {
struct alternative *next;
struct instruction *insn;
@@ -2096,6 +2100,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
struct reloc *reloc = table;
struct alternative *alt;
unsigned long offset;
unsigned long rodata_entry_size;
/*
* Each @reloc is a switch table relocation which points to the target
@@ -2107,8 +2112,15 @@ 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_type(reloc) == R_LARCH_32_PCREL)
rodata_entry_size = 4;
else
rodata_entry_size = 8;
/* Make sure the table entries are consecutive: */
if (prev_offset && reloc_offset(reloc) != prev_offset + 8)
if (prev_offset && reloc_offset(reloc) != prev_offset + rodata_entry_size)
break;
if (reloc->sym->type == STT_SECTION) {