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

Jan Beulich jbeulich@suse.com
Fri May 15 12:05:11 GMT 2026


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.
In particular ...

> --- /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.

> --- /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 ...

> +.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


More information about the Binutils mailing list