[PATCH v3] gas: add --reloc-section-sym={all, internal, none} option for ELF
Jan Beulich
jbeulich@suse.com
Mon Jun 15 06:44:47 GMT 2026
On 13.06.2026 06:49, Fangrui Song wrote:
> On Sat, May 16, 2026 at 12:38 AM Fangrui Song <i@maskray.me> wrote:
>> On Fri, May 15, 2026 at 5:05 AM Jan Beulich <jbeulich@suse.com> wrote:
>>> On 28.02.2026 07:19, Fangrui Song wrote:
>>>> From: Fangrui Song <maskray@sourceware.org>
>>>>
>>>> When generating relocations for non-ifunc local symbols that satisfies
>>>> several conditions, GAS converts them to reference the section symbol
>>>> (STT_SECTION) instead, folding the original symbol's offset into the
>>>> addend. This allows the original local symbol to be omitted from
>>>> .symtab, but the STT_SECTION symbol itself must be present, so the
>>>> conversion saves .symtab entries only when a section has more than one
>>>> local symbol referenced by relocations.
>>>>
>>>> Add --reloc-section-sym to control this conversion:
>>>>
>>>> - all (default): convert all eligible local symbols
>>>> - internal: only convert compiler-generated locals (.L prefix)
>>>> - none: never convert; keep all symbols as-is in relocations
>>>>
>>>> This is useful for debugging and for tools that benefit from preserved
>>>> symbol names.
>>>>
>>>> PR gas/33885
>>>
>>> Okay, provided you checked the new tests pass for a wide range of targets.
This remains as a prereq to approval.
>>> In particular ...
>>
>> Thanks for taking a look.
>>
>>>> --- /dev/null
>>>> +++ b/gas/testsuite/gas/elf/reloc-section-sym-all.d
>>>> @@ -0,0 +1,12 @@
>>>> +#source: reloc-section-sym.s
>>>> +#as: --reloc-section-sym=all
>>>> +#objdump: -rsj .data
>>>> +#name: reloc-section-sym=all
>>>> +
>>>> +.*: +file format .*
>>>> +
>>>> +RELOCATION RECORDS FOR \[\.data\]:
>>>> +OFFSET +TYPE +VALUE
>>>> +0*0 [^ ]+ +\.text.*
>>>> +0*4 [^ ]+ +\.text.*
>>>> +#pass
>>>> --- /dev/null
>>>> +++ b/gas/testsuite/gas/elf/reloc-section-sym-internal.d
>>>> @@ -0,0 +1,12 @@
>>>> +#source: reloc-section-sym.s
>>>> +#as: --reloc-section-sym=internal
>>>> +#objdump: -rsj .data
>>>> +#name: reloc-section-sym=internal
>>>> +
>>>> +.*: +file format .*
>>>> +
>>>> +RELOCATION RECORDS FOR \[\.data\]:
>>>> +OFFSET +TYPE +VALUE
>>>> +0*0 [^ ]+ +local.*
>>>> +0*4 [^ ]+ +\.text.*
>>>> +#pass
>>>> --- /dev/null
>>>> +++ b/gas/testsuite/gas/elf/reloc-section-sym-none.d
>>>> @@ -0,0 +1,12 @@
>>>> +#source: reloc-section-sym.s
>>>> +#as: --reloc-section-sym=none
>>>> +#objdump: -rsj .data
>>>> +#name: reloc-section-sym=none
>>>> +
>>>> +.*: +file format .*
>>>> +
>>>> +RELOCATION RECORDS FOR \[\.data\]:
>>>> +OFFSET +TYPE +VALUE
>>>> +0*0 [^ ]+ +local.*
>>>> +0*4 [^ ]+ +\.Ltemp.*
>>>> +#pass
>>>> --- /dev/null
>>>> +++ b/gas/testsuite/gas/elf/reloc-section-sym.s
>>>> @@ -0,0 +1,9 @@
>>>> + .text
>>>> +local:
>>>> + .byte 0
>>>> +.Ltemp:
>>>> + .byte 0
>>>> +
>>>> + .data
>>>> + .long local + 16
>>>> + .long .Ltemp + 16
>>>
>>> ... here I wonder whether .dc.a wouldn't be the more portable directive to
>>> use when it comes to relocations.
>>
>> With .long the relocation offset is target-agnostic. section5.s uses
>> .long relocations as well, so I think .long relocations is portable.
>>
>>>> --- /dev/null
>>>> +++ b/gas/testsuite/gas/i386/reloc-section-sym.s
>>>> @@ -0,0 +1,14 @@
>>>> + .text
>>>> + nop
>>>> +local:
>>>> + .byte 0
>>>
>>> Better "nop" here as well, just like ...
>>
>> I think `.byte 0` doesn't hurt here...
>> .byte 0/int3/nop is to introduce some nuance. While it probably
>> doesn't matter for this particular test, it helps in other tests when
>> using objdump -s.
>>
>>>> +.Ltemp:
>>>> + nop
>>>
>>> ... you have it here?
>>>
>>> Which further reminds me to ask why in the generic test you don't use .nop
>>> in favor of .byte.
>>>
>>> Jan
>>
>> I didn't realize that .nop is portable. However, .nop introduces
>> target-dependent offsets, which is exactly what we want to avoid in a
>> generic test.
>> Sticking to explicit offsets like 0/4/8 IMHO is clearer than using .*
>
> Hi Jan, are you happy with the patch as is ? :)
Not really, no. .byte in .text isn't very nice. Can't you use .bss in place
of .text, if you want to avoid using .nop?`
Jan
More information about the Binutils
mailing list