[PATCH] gas: add --reloc-use-section-sym={all, temporary, none} option for ELF

Jan Beulich jbeulich@suse.com
Tue Feb 10 08:39:25 GMT 2026


On 10.02.2026 08:17, Fangrui Song wrote:
> On Mon, Feb 9, 2026 at 12:42 AM Jan Beulich <jbeulich@suse.com> wrote:
>> On 08.02.2026 22:03, maskray@sourceware.org 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-use-section-sym to control this conversion:
>>>
>>> - all (default): convert all eligible local symbols
>>> - temporary: 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 preserve
>>> symbol names.
>>>
>>> PR gas/33885
>>> ---
>>>  gas/NEWS                                      |  4 ++++
>>>  gas/as.c                                      | 20 +++++++++++++++-
>>>  gas/as.h                                      | 10 ++++++++
>>>  gas/doc/as.texi                               | 11 +++++++++
>>>  .../gas/i386/reloc-use-section-sym-all.d      | 23 +++++++++++++++++++
>>>  .../i386/reloc-use-section-sym-local-label.d  | 23 +++++++++++++++++++
>>>  .../gas/i386/reloc-use-section-sym-none.d     | 23 +++++++++++++++++++
>>>  .../gas/i386/reloc-use-section-sym.s          | 14 +++++++++++
>>>  gas/testsuite/gas/i386/x86-64.exp             |  4 ++++
>>>  gas/write.c                                   | 12 +++++++++-
>>>  10 files changed, 142 insertions(+), 2 deletions(-)
>>>  create mode 100644 gas/testsuite/gas/i386/reloc-use-section-sym-all.d
>>>  create mode 100644 gas/testsuite/gas/i386/reloc-use-section-sym-local-label.d
>>>  create mode 100644 gas/testsuite/gas/i386/reloc-use-section-sym-none.d
>>>  create mode 100644 gas/testsuite/gas/i386/reloc-use-section-sym.s
>>>
>>> diff --git a/gas/NEWS b/gas/NEWS
>>> index e384d1135c0..1d07f909b8f 100644
>>> --- a/gas/NEWS
>>> +++ b/gas/NEWS
>>> @@ -1,5 +1,9 @@
>>>  -*- text -*-
>>>
>>> +* New command line option --reloc-use-section-sym=[all|local-label|none]
>>> +  controls whether relocations referencing local binding symbols are adjusted
>>> +  to use section symbols.
>>
>> A number of targets set tc_fix_adjustable() to constant-false. Such targets
>> won't be affected at all, which I think wants expressing here by adding some
>> for of conditional. Along these lines I'm also not overly happy to see the
>> new testcases to all be x86_64-only.
> 
> Understood. I wasn't aware that tc_fix_adjustable is defined to 0 for
> many targets.
> 
> Does this warrant a test in gas/testsuite/gas/elf/ ? But it's unclear
> how to write such a generic test that works on all targets.
> I want to avoid enumerating the target list (which I don't even know)
> and run `configure --target=$target && make all-gas && check-gas
> RUNTESTFLAGS=elf.exp`.

I understand your worries, but shouldn't the intended behavior be working
on all intended targets? Hence wanting to be proven to do so? To clarify,
I actually question any ELF target setting tc_fix_adjustable to constant
false; the new test(s) may want XFAILing there.

Jan


More information about the Binutils mailing list