Re: [PATCH v5 02/10] objtool: Handle different entry size of rodata

From: Tiezhu Yang
Date: Tue Dec 10 2024 - 22:12:01 EST


On 12/10/2024 03:54 AM, Josh Poimboeuf wrote:
On Sat, Dec 07, 2024 at 09:59:07AM +0800, Tiezhu Yang wrote:
+__weak unsigned int arch_reloc_size(struct reloc *reloc)
+{
+ return 8;
+}

Instead of making a weak function, each arch should have an explicit
definition of this function, as it's not always 8:

- x86 has R_X86_64_PC32 and R_X86_64_PLT32 which are 4 bytes.

- 32-bit powerpc

- 64-bit powerpc has R_PPC64_REL32

For x86, like this, I am not sure "case R_X86_64_32" is necessary,
leave it as is if no objections, please let me know if it should be
removed.

unsigned int arch_reloc_size(struct reloc *reloc)
{
switch (reloc_type(reloc)) {
case R_X86_64_32:
case R_X86_64_PC32:
case R_X86_64_PLT32:
return 4;
default:
return 8;
}
}

For ppc, like this:

unsigned int arch_reloc_size(struct reloc *reloc)
{
switch (reloc_type(reloc)) {
case R_PPC_REL32:
case R_PPC64_REL32:
return 4;
default:
return 8;
}
}


@@ -1967,8 +1973,10 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
if (reloc != table && reloc == next_table)
break;

+ entry_size = arch_reloc_size(reloc);
+
/* Make sure the table entries are consecutive: */
- if (prev_offset && reloc_offset(reloc) != prev_offset + 8)
+ if (prev_offset && reloc_offset(reloc) != prev_offset + entry_size)
break;

No need to use a variable here, just call arch_reloc_size() directly.

OK, will do it.

Thanks,
Tiezhu