[RFC 4/4] ld: bfd: sframe: fix incorrect r_addend in RELA entries

Jan Beulich jbeulich@suse.com
Tue Mar 11 07:08:59 GMT 2025


On 10.03.2025 14:16, Jens Remus wrote:
> On 08.03.2025 08:38, Indu Bhagat wrote:
>> With the fix in GAS, we now use a different PC-relative RELA for
>> updating the SFrame FDE function start address: The value is the offset
>> of the start PC of the function from the start of the SFrame section.
>>
>> When RELAs are output (e.g. for relocatable links), there is need to
>> adjust the r_addend.  This is because the r_addend values still have the
>> correct values for the _input_ SFrame section being linked / relocated.
>> The values must now be (before outputing the RELAs) with respect to the
>> _output_ SFrame section.
>>
>> PS: This patch should be merged with the previous commits before final
>> commit (Otherwise the tests will fail).  It is currently a separate
>> patch as I would like to check if this is OK to do.  If such a "addend
>> fixup" is risky or wrong, it seems we will need a new type of RELOC for
>> SFrame sections.
> 
>> diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c
> 
>> @@ -574,6 +574,37 @@ _bfd_elf_sframe_section_offset (bfd *output_bfd ATTRIBUTE_UNUSED,
>>   	  + out_fde_idx * sizeof (sframe_func_desc_entry));
>>   }
>>   
>> +/* Get the "canonicalized" addend for the symbol reference corresponding to the
>> +   relocation at RELOC_INDEX.  E.g.,  for the following reloc for the SFrame
> 
> Nit: s/reloc/relocs/
> 
>> +   FDE function start address:
>> +	Offset          Type          Sym. Name + Addend
>> +	00000000001c  R_X86_64_PC32   .text + 1c
>> +	000000000030  R_X86_64_PC32   .text + 3b
>> +   The canonicalized addend are 0 and b respectively as the relocs are for
>> +   symbols (.text + 0) and (.text + b) respectively.
> 
> Maybe it would help to use the function symbols foo and bar in the example:
> 
>     relocation at RELOC_INDEX.  E.g.,  for the following annotated relocs for the SFrame
>     FDE function start address of FDE[0] and FDE[1] for functions foo and bar:
> 	Offset          Type          Sym. Name + Addend
> 	00000000001c  R_X86_64_PC32   .text + 1c   // FDE[0] for foo at .text + 0
> 	000000000030  R_X86_64_PC32   .text + 3b   // FDE[1] for bar at .text + b
>     With:
>       1c = 0 + sizeof(sframe_header) + 0 * sizeof(sframe_fde)
>       3b = b + sizeof(sframe_header) + 1 * sizeof(sframe_fde)
>     The canonicalized addend are 0 and b respectively as the relocs are for
>     symbols (.text + 0) and (.text + b) respectively.

Hmm, wait - there's a mix between .text and .sframe then, isn't there? That
would explain why custom handling is then necessary. Yet as said in the other
mail, custom handling should not be necessary. Not the least because other
ELF-consuming tools also need to work, not just what GNU binutils provides.

Jan


More information about the Binutils mailing list