[PATCH v2] ld: testsuite: Simplify emulation check in libgot tests
Rainer Orth
ro@CeBiTec.Uni-Bielefeld.DE
Sun Jan 25 15:11:42 GMT 2026
Hi Maciej,
> On Sat, 24 Jan 2026, Rainer Orth wrote:
>
>> while I still like this approach because it allows to extend test
>> coverage to i386 ELF targets without -melf_i386, I primarily would like
>> to go this way to enable removing the non-*_sol2 emulations from native
>> Solaris gld. They are never used outside of the ld testsuite, and I'd
>> rather test the native elf_i386_sol2 etc. emulations that *are* actually
>> used.
>>
>> I guess I'll try this in ld-sparc first, where hardcoded
>> -melf32_sparc/elf64_sparc are only used 54 times, rather than
>> -melf_i386/elf_x86_64 (869 times).
>>
>> I guess I'll try setting emul32/emul64 once in ld-lib.exp, then replace
>> all hardcoded instances of -m<emul> by $emul32/$emul64.
>
> You might consider the MIPS approach where we also used to have an issue
> with various targets using different emulations while still wanting to
> verify non-default ones (legitimate for several MIPS targets) and came up
> with an arrangement where the emulations selected are derived from the
> target triplet. Yes, it's a zoo, but so is the MIPS target collection.
>
> See the `abi_ldflags' setting in ld/testsuite/ld-mips-elf/mips-elf.exp
> for details.
my initial idea had been something like that. However, I then noticed
that this would duplicate much of the information we already have in
ld/configure.tgt and thus the ld -V output.
My current idea runs like this: just set emul32/emul64 in ld-lib.exp
to the first emulation in ld -V that matches a given pattern. E.g. on
Solaris/sparcv9 you get
GNU ld (GNU Binutils) 2.45.90.20260125
Supported emulations:
elf64_sparc_sol2
elf32_sparc_sol2
elf64_sparc
elf32_sparc
For emul64 you'd pick the first emulation matching elf64_sparc.*,
i.e. elf64_sparc_sol2. Similarly you get elf32_sparc_sol2 for emul32.
An implementation would look like this (completely untested):
global emul32 emul64
set emul32 unknown32
set emul64 unknown64
# Extract first emulation matching emul from ld_output.
#
proc ld_first_emul { emul ld_output } {
if [regexp -line "$emul.*" $ld_output first_emul] then {
return $first_emul
}
}
# Determine primary 32 and 64-bit emulations from ld -V.
#
# Only introduce special cases as overrides.
# Maybe introduce secondary matches?
proc set_ld_emuls { } {
global ld
set ld_output [remote_exec host $ld "-V"]
set ld_output [lindex $ld_output 1]
switch -glob "$target" {
i?86-*-* -
x86_64-*-* {
set emul32 [ld_first_emul "elf32_sparc" $ld_output]
set emul64 [ld_first_emul "elf64_sparc" $ld_output]
}
sparc*-*-* {
set emul32 [ld_first_emul "elf32_sparc" $ld_output]
set emul64 [ld_first_emul "elf64_sparc" $ld_output]
}
}
This way, you'd always prefer the native emulations, not a hardcoded one
like elf32_sparc. The latter is only used in the ld testsuite, while
gcc always uses elf32_sparc_sol2. I'm not interested in test results
that don't match actual use. Those are irrelevant IMO.
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
More information about the Binutils
mailing list