authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-17 06:24:24+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-17 15:27:49+02:00
logab5ce5b5e1742f54ae2b9a78899f50523f947665
treef4ca03e05aae4b4e9f6e7b2d20c2c1d3c82ecc23
parentb7104c95f249e42d0068bc2a94f7f426c0c740f3
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Target: make DynamicLinker.standard() version range agnostic

Dynamic linker paths do change sometimes, but I'm not aware of a single instance of this happening where a compatibility symlink wasn't left in place. And even if we ignore that, the only two instances that we handled here were FreeBSD 6.0 (~2005) and DragonFly BSD 3.8 (~2014). Removing this requirement helps solve the chicken-and-egg problem going on in std.zig.system.resolveTargetQuery().

2 files changed, 7 insertions(+), 17 deletions(-)

lib/std/Target.zig+5-15
......@@ -2532,8 +2532,8 @@ pub const DynamicLinker = struct {
25322532 /// the ABI; it does not necessarily mean that `abi` makes any sense at all for that platform.
25332533 /// The responsibility for determining whether `abi` is valid in this case rests with the
25342534 /// caller. `Abi.default()` can be used to pick a best-effort default ABI for such platforms.
2535 pub fn standard(cpu: Cpu, os: Os, abi: Abi) DynamicLinker {
2536 return switch (os.tag) {
2535 pub fn standard(cpu: Cpu, os: Os.Tag, abi: Abi) DynamicLinker {
2536 return switch (os) {
25372537 .fuchsia => switch (cpu.arch) {
25382538 .arm,
25392539 .aarch64,
......@@ -2833,12 +2833,7 @@ pub const DynamicLinker = struct {
28332833 else => none,
28342834 },
28352835
2836 .dragonfly => if (cpu.arch == .x86_64) initFmt("{s}/libexec/ld-elf.so.2", .{
2837 if (os.version_range.semver.isAtLeast(.{ .major = 3, .minor = 8, .patch = 0 }) orelse false)
2838 ""
2839 else
2840 "/usr",
2841 }) else none,
2836 .dragonfly => if (cpu.arch == .x86_64) init("/libexec/ld-elf.so.2") else none,
28422837
28432838 .freebsd => switch (cpu.arch) {
28442839 .arm,
......@@ -2849,12 +2844,7 @@ pub const DynamicLinker = struct {
28492844 .riscv64,
28502845 .x86,
28512846 .x86_64,
2852 => initFmt("{s}/libexec/ld-elf.so.1", .{
2853 if (os.version_range.semver.isAtLeast(.{ .major = 6, .minor = 0, .patch = 0 }) orelse false)
2854 ""
2855 else
2856 "/usr",
2857 }),
2847 => init("/libexec/ld-elf.so.1"),
28582848 else => none,
28592849 },
28602850
......@@ -2968,7 +2958,7 @@ pub const DynamicLinker = struct {
29682958};
29692959
29702960pub fn standardDynamicLinkerPath(target: *const Target) DynamicLinker {
2971 return DynamicLinker.standard(target.cpu, target.os, target.abi);
2961 return DynamicLinker.standard(target.cpu, target.os.tag, target.abi);
29722962}
29732963
29742964pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
lib/std/zig/system.zig+2-2
......@@ -995,7 +995,7 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ
995995 // will then look for a dynamic linker with a matching path on the system and pick the ABI
996996 // we associated it with here.
997997 .arch_os_abi => for (all_abis) |abi| {
998 const ld = Target.DynamicLinker.standard(cpu, os, abi);
998 const ld = Target.DynamicLinker.standard(cpu, os.tag, abi);
999999
10001000 // Does the generated target triple actually have a standard dynamic linker path?
10011001 if (ld.get() == null) continue;
......@@ -1141,7 +1141,7 @@ fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os, query: Target.Quer
11411141 .os = os,
11421142 .abi = abi,
11431143 .ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
1144 .dynamic_linker = query.dynamic_linker orelse .standard(cpu, os, abi),
1144 .dynamic_linker = query.dynamic_linker orelse .standard(cpu, os.tag, abi),
11451145 };
11461146}
11471147