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

Jan Beulich jbeulich@suse.com
Mon Feb 9 08:42:16 GMT 2026


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.

I also have to admit that the command line option is pretty long. My minimal
suggestion would be to drop the "use" part.

> @@ -956,6 +957,16 @@ Ignored.  Supported for compatibility with tools that pass the same option to
>  both the assembler and the linker.
>  
>  @ifset ELF
> +@item --reloc-use-section-sym=all
> +@itemx --reloc-use-section-sym=local-label
> +@itemx --reloc-use-section-sym=none
> +Control whether relocations referencing local binding symbols are adjusted to
> +use section symbols instead.  With @code{all} (the default), relocations
> +against all eligible local binding symbols are converted.  With
> +@code{local-label}, only relocations against local labels (symbols matching the
> +@code{.L} prefix) are converted.  With @code{none}, no conversions are
> +performed and all relocations retain their original symbols.

Up to "and" I agree, but what follows is too broad imo. Yes, the context here
is conversion to section symbols, but still - see in particular the use of
symbol_equated_reloc_p() in adjust_reloc_syms().

> --- a/gas/write.c
> +++ b/gas/write.c
> @@ -804,6 +804,10 @@ adjust_reloc_syms (bfd *abfd ATTRIBUTE_UNUSED,
>  
>    dump_section_relocs (abfd, sec, stderr);
>  
> +  /* Disable all conversion for --reloc-use-section-sym=none.  */
> +  if (flag_reloc_use_section_sym == reloc_use_section_sym_none)
> +    return;
> +
>    for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
>      if (fixp->fx_done)
>        /* Ignore it.  */
> @@ -909,6 +913,12 @@ adjust_reloc_syms (bfd *abfd ATTRIBUTE_UNUSED,
>  	if ((symsec->flags & SEC_THREAD_LOCAL) != 0)
>  	  continue;
>  
> +	/* If --reloc-use-section-sym=local-label, don't adjust a reloc against
> +	   a local label.  */
> +        if (flag_reloc_use_section_sym == reloc_use_section_sym_local_label
> +	    && !bfd_is_local_label (stdoutput, symbol_get_bfdsym (sym)))
> +	  continue;

Comment and code look to not match up. I think the comment is inverted and
means to say "..., adjust only if the reloc is against a local label" or
"don't adjust a reloc if it isn't against a local label" or some such.

Jan


More information about the Binutils mailing list