Re: [PATCH v5 03/10] objtool: Handle PC relative relocation type

From: Tiezhu Yang
Date: Wed Dec 11 2024 - 20:34:45 EST


On 12/12/2024 08:35 AM, Josh Poimboeuf wrote:
On Wed, Dec 11, 2024 at 11:16:33AM +0800, Tiezhu Yang wrote:
When compiling on LoongArch, there are some PC relative relocation types
for rodata, it needs to calculate the symbol offset with "S + A - PC" in
this case according to the spec of "ELF for the LoongArch Architecture",
the "PC" is the index of each jump table which is equal with the value
of reloc_offset(reloc) - reloc_offset(table).

I will add the above description to the commit message to make it clear.

I understand how PC-relative addressing works.

The oddity here is that "PC" is the jump table's base address rather
than the entry address.

If there is only one jump table in the rodata, the "PC" is the entry
address which is equal with the value of reloc_offset(reloc), at this
time, reloc_offset(table) is 0.

If there are many jump tables in the rodata, the "PC" is the offset
of the jump table's base address which is equal with the value of reloc_offset(reloc) - reloc_offset(table).

That has nothing to do with the ELF spec or
even how R_LARCH_32_PCREL is implemented. Rather it seems to be a quirk
related to how loongarch jump table code expects the entries to be.

So the arch_adjust_offset() name seems wrong, as this is specific to
the jump table implementation, rather than relocs in general.

Instead call it arch_jump_table_sym_offset()?

OK, will modify it and add the above description to the commit message
to make it clear.

Thanks,
Tiezhu