[PATCH v2] gas: add --reloc-section-sym={all, internal, none} option for ELF
Fangrui Song
i@maskray.me
Tue Feb 24 18:51:44 GMT 2026
On Mon, Feb 23, 2026 at 11:04 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 23.02.2026 18:36, Fangrui Song wrote:
> > On Sun, Feb 22, 2026 at 11:20 PM Jan Beulich <jbeulich@suse.com> wrote:
> >>
> >> On 22.02.2026 03:03, Fangrui Song wrote:
> >>> --- a/gas/testsuite/gas/elf/elf.exp
> >>> +++ b/gas/testsuite/gas/elf/elf.exp
> >>> @@ -4,15 +4,15 @@
> >>> # it under the terms of the GNU General Public License as published by
> >>> # the Free Software Foundation; either version 3 of the License, or
> >>> # (at your option) any later version.
> >>> -#
> >>> +#
> >>> # This program is distributed in the hope that it will be useful,
> >>> # but WITHOUT ANY WARRANTY; without even the implied warranty of
> >>> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> >>> # GNU General Public License for more details.
> >>> -#
> >>> +#
> >>> # You should have received a copy of the GNU General Public License
> >>> # along with this program; if not, write to the Free Software
> >>> -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
> >>> +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
> >>>
> >>> #
> >>> # elf tests
> >>> @@ -170,30 +170,32 @@ if { [is_elf_format] } then {
> >>> switch -glob $target_triplet {
> >>> alpha*-*-* { }
> >>> am3*-*-* { }
> >>> + avr-*-* { }
> >>> *c54x*-*-* { }
> >>> cr16*-*-* { }
> >>> crx*-*-* { }
> >>> h8300-*-* { }
> >>> - hppa*-*-* { }
> >>> - iq2000*-*-* { }
> >>> - mips*-*-* { }
> >>> + loongarch*-*-* { }
> >>> + m681*-*-* { }
> >>> + m68hc*-*-* { }
> >>> mn10200-*-* { }
> >>> mn10300-*-* { }
> >>> msp43*-*-* { }
> >>> - rl78-*-* { }
> >>> riscv*-*-* { }
> >>> + rl78-*-* { }
> >>> rx-*-* { }
> >>> - loongarch*-*-* { }
> >>> + xgate-*-* { }
> >>> + vax-*-* { }
> >>> default {
> >>> - # The next test can fail if the target does not convert fixups
> >>> - # against ordinary symbols into relocations against section symbols.
> >>> - # This is usually revealed by the error message:
> >>> - # symbol `sym' required but not present
> >>> - setup_xfail "m681*-*-*" "m68hc*-*-*" "xgate-*-*" "vax-*-*" "avr-*-*"
> >>> - run_dump_test redef
> >>> + # The following tests require that the target adjusts relocations
> >>> + # referencing local binding symbols to be against section symbols.
> >>> run_dump_test equ-reloc
> >>> + run_dump_test redef
> >>> + run_dump_test "reloc-section-sym-all"
> >>> + run_dump_test "reloc-section-sym-internal"
> >>> }
> >>> }
> >>> + run_dump_test "reloc-section-sym-none"
> >>> run_dump_test "pseudo"
> >>> run_dump_test "text-prev" $dump_opts
> >>> run_dump_test "text-subsect" $dump_opts
> >>> @@ -245,7 +247,7 @@ if { [is_elf_format] } then {
> >>> # in the symbol type test.
> >>> # We also need to exclude targets that do not support unique objects.
> >>> if { [istarget "*-*-hpux*"]
> >>> - || [istarget "arm*-*-*"]
> >>> + || [istarget "arm*-*-*"]
> >>> || [istarget "mips*-*-*"]
> >>> || [istarget "msp*-*-*"]
> >>> || [istarget "visium-*-*"]
> >>> @@ -380,7 +382,7 @@ if { [is_elf_format] } then {
> >>> run_dump_test "startof"
> >>>
> >>> run_dump_test "missing-build-notes"
> >>> -
> >>> +
> >>> run_dump_test "common1"
> >>> run_dump_test "common2"
> >>>
> >>
> >> This became much more of a change than what v1 had, and I question parts thereof.
> >> You're dropping XFAILs. If there's a proper reason for doing so, it needs stating
> >> in the description. You're further excluding the equ-reloc test for more targets.
> >> This pretty likely is wrong?
> >>
> >> You apparently also try to re-sort the list of excluded targets in that switch,
> >> yet then vax ends up after xgate.
> >
> > I have used a build-all-gas.sh script to build 40+ triplets, including
> > every triplet mentioned in elf.exp.
> > I have determined that the equ-reloc and redef tests actually pass on
> > the disabled hppa and iq2000.
>
> That's good, but definitely wants to be a separate change then, imo.
>
> > The list is now sorted alphabetically.
>
> Only quite, as mentioned.
OK, I will swap xgate and vax.
> > vax is special: its tc_fix_adjustable macro in gas/config/tc-vax.h
> > includes the condition S_IS_LOCAL ((FIX)->fx_addsy)), causing
> > reloc-section-sym-all to fail.
> > setup_xfail only works for the next run_dump_test. I think it's easier
> > to just exclude it.
> >
> > I feel like xfail is often just a placeholder for 'this target is
> > weird but I don't have time to fix it.'
>
> But isn't this what xfail is for (among other purposes)? When you make
> changes to common code and don't know a particular target (hence also
> not why it may exhibit "weird" behavior), marking tests this way is
> often the best you can do. Diligent arch maintainers would then pick
> this up, converting to an exclusion or (preferably) addressing the
> issue.
It appears that equ-reloc should be handled as a standalone case. In
contrast, redef, reloc-section-sym-all, and reloc-section-sym-internal
should be grouped together with the `switch`, as they all rely on the
architecture to implement an aggressive tc_fix_adjustable.
I don't think it makes sense to list XFAIL for redef,
reloc-section-sym-all, and reloc-section-sym-internal, because having
a less aggressive tc_fix_adjustable is sensible. I believe the ideal
default tc_fix_adjustable is more like --reloc-section-sym=internal.
equ-reloc on 45 targets
PASS (42): aarch64-linux-gnu am33_2.0-linux-gnu arc-linux-gnu
arm-linux-gnueabi avr-elf bfin-elf cr16-elf cris-linux-gnu crx-elf
csky-linux-gnu frv-linux-gnu h8300-elf hppa-linux-gnu i686-linux-gnu
ia64-linux-gnu iq2000-elf kvx-linux-gnu loongarch64-linux-gnu
m32r-linux-gnu m68hc11-e
lf m68k-linux-gnu mips64-linux-gnu mn10200-elf msp430-elf
nds32le-linux-gnu or1k-linux-gnu ppc64-linux-gnu pru-elf
riscv64-linux-gnu rl78-elf rx-elf s390x-linux-gnu score-elf
sh-linux-gnu sparc64-linux-gnu tic6x-elf v850-elf vax-linux-gnu
visium-elf x86_64-linux-gnu xgate-elf xtensa-el
f
XFAIL (0):
FAIL (2): alpha-linux-gnu z8k-elf:build
SKIP (1): mmix-mmixware:no-results
> >> I'm also unconvinced all the whitespace changes should go here.
> >
> > While I understand the issue of interleaving functional changes with
> > whitespace noise, I noticed our .editorconfig has
> > trim_trailing_whitespace = true enabled, which is causing neovim to
> > automatically scrub spaces on save.
> > To save everyone the headache of messy diffs, we should probably do a
> > one-time sweep in batch.
>
> Possibly, albeit doing so also has a perhaps significant downside: It
> can badly get in the way of "git blame" or alike.
>
> >> With changes like these, btw, a revlog would also have been helpful.
> >
> > What is revlog?
>
> A brief indication of what changed compared to earlier versions of a
> patch, outside of the commit message area.
>
> Jan
More information about the Binutils
mailing list