Skip to main content

rucc_sysroot/
link.rs

1//! The start files, the libraries and the loader for one target's link.
2//!
3//! Design: `spec/cross-compile/08-sysroots.md` section 8.2 and `spec/cross-compile/11-linking.md`.
4//!
5//! What is here is what has to be linked, in what order, and which loader will start the result.
6//! How that is spelled for a particular linker is [`crate::argv`], which is the division
7//! `spec/cross-compile/11-linking.md` draws: the files are a fact about the target and the flags are
8//! a fact about the linker.
9//!
10//! # Why musl is first
11//!
12//! `spec/cross-compile/09-libc-stubs.md` section 9.3 is the argument. musl exercises the header
13//! tree, the search paths, the start files, the compiler runtime and the link line, and it does
14//! that without symbol versioning and without stub generation, which are the two hardest pieces of
15//! the glibc path. If a musl cross link works end to end then the pipeline is right and what is
16//! left for M9.5 is the glibc specific parts rather than the shape of the thing.
17//!
18//! # Why the line has three parts and not one
19//!
20//! `crtn.o` goes after the libraries and `crti.o` goes before them, because between them they open
21//! and close the `.init` and `.fini` sections and anything contributing to those has to land in the
22//! middle. A link line that is one list gets this wrong in a way that produces a binary which links,
23//! runs, and does not run its static constructors, so the three parts are three fields here rather
24//! than a comment on an ordering somebody has to preserve.
25
26use std::path::{Path, PathBuf};
27
28use rucc_tuple::{Abi, Arch, DataModel, Endian, Env, ObjectFormat, Os, TargetTuple};
29
30use crate::layout::Sysroot;
31
32/// How the program is linked, which decides the first start file and the flags.
33///
34/// Five cases rather than two booleans for static and position independent, because the two are not
35/// independent and the start file is a different file in four of the five. A pair of flags would
36/// admit a sixth combination, a shared object that is not position independent, which is not a thing
37/// any of these linkers will produce.
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
39pub enum LinkMode {
40    /// Everything in the binary, no interpreter, no relocation at load. The default for musl, and
41    /// the mode `spec/cross-compile/02-the-goal.md`'s exit criterion names.
42    #[default]
43    Static,
44    /// Static, and position independent, so the loader may place it anywhere. A different first
45    /// start file, because the program has to relocate itself before `main` and `rcrt1.o` is what
46    /// does that.
47    StaticPie,
48    /// Against the shared libc, position independent, with the libc's loader named in the program
49    /// header. What every distribution builds today and what `-pie` asks for.
50    Dynamic,
51    /// Against the shared libc, at a fixed address, which is `-no-pie`.
52    ///
53    /// The same link as [`LinkMode::Dynamic`] with a different start file, because the reference to
54    /// `main` in `crt1.o` is an absolute one and the reference in `Scrt1.o` is not. Build systems
55    /// that pass `-no-pie` are usually doing it because something in them takes the address of a
56    /// function and compares it, and they get the file that matches.
57    DynamicNoPie,
58    /// A shared object rather than a program, which is `-shared`.
59    ///
60    /// No start file at all, since nothing starts a shared object and it has no `main` to be
61    /// started at, and no loader named either: the program that loads this one carries that.
62    Shared,
63}
64
65impl LinkMode {
66    /// Whether the result is linked against a shared libc, which decides whether a loader is named.
67    #[must_use]
68    pub const fn is_dynamic(self) -> bool {
69        matches!(self, LinkMode::Dynamic | LinkMode::DynamicNoPie | LinkMode::Shared)
70    }
71
72    /// Whether the result may be placed anywhere in memory.
73    #[must_use]
74    pub const fn is_pie(self) -> bool {
75        matches!(self, LinkMode::StaticPie | LinkMode::Dynamic | LinkMode::Shared)
76    }
77}
78
79/// What a produced sysroot holds for a target's C library.
80///
81/// Four cases, from `spec/cross-compile/08-sysroots.md` section 8.2's table, and the line differs
82/// between them in what goes on it rather than in how it is spelled. The table has seven rows and two
83/// of those are legal walls rather than technical ones, so what is left is these four.
84#[derive(Debug, Clone, Copy, PartialEq, Eq)]
85pub enum Libc {
86    /// Nothing, which is the freestanding row: the nine compiler headers and no link inputs at all.
87    /// Our runtime is still there, because an architecture without a division instruction needs it
88    /// whether there is a libc or not.
89    None,
90    /// A real static archive, which today means musl built from source. The only row where the code
91    /// behind the names is present, so the only row a static link can use.
92    Archive,
93    /// A generated stub shared object: the names the platform's libc exports and none of the code.
94    /// glibc is the row this was written for, and bionic, the BSDs and illumos take the same shape
95    /// for the same reason, which is that their libc is a shared object on the target machine and a
96    /// list of names is enough to link against one.
97    Stub,
98    /// A set of import libraries, which is what the same idea is called in COFF.
99    ///
100    /// Windows is the row this is, and it is a separate case from [`Libc::Stub`] rather than a
101    /// spelling of it, for two reasons that both show up on the line. The container is different: a
102    /// Windows program links against an archive of tiny objects per DLL rather than against one
103    /// shared object, which is `spec/cross-compile/09-libc-stubs.md` section 9.4 and what
104    /// `rucc_stub::coff` writes. And the C library is not one file: the msvcrt import library,
105    /// mingw-w64's own `libmingwex.a` and `libmoldname.a`, and the Win32 libraries a CRT calls into
106    /// are all on the line, where a glibc line has one `libc.so` on it.
107    ///
108    /// A static link against this is not refused, which is the other difference. On Windows the C
109    /// library is a DLL on every machine and always has been, so `-static` there is a statement
110    /// about our libraries and mingw-w64's rather than about the CRT, and a program linked that way
111    /// runs. That is why the refusal in [`crate::argv::argv`] is about [`Libc::Stub`] by name.
112    Import,
113}
114
115/// Which of the four cases this target is.
116///
117/// Asked in two places, which is why it is a function rather than a `match` in each: [`LinkLine`]
118/// uses it to pick the files and [`crate::argv::argv`] uses it to refuse a static link against a
119/// stub. Two copies of this rule would be two rules.
120///
121/// The format is asked before the environment, because what holds a libc's names is a property of
122/// the object format and `Env::Gnu` means mingw-w64 on a Windows target and glibc on a Linux one.
123#[must_use]
124pub fn libc(target: TargetTuple) -> Libc {
125    match (target.os(), target.env()) {
126        (Os::None, _) => Libc::None,
127        _ if target.object_format() == ObjectFormat::Coff => Libc::Import,
128        (_, Env::Musl) => Libc::Archive,
129        _ => Libc::Stub,
130    }
131}
132
133/// Our own runtime library, which every one of the three lines below carries.
134///
135/// Named once because three callers ask about it by name: the line that puts it on,
136/// [`crate::argv::argv`] when `-fno-builtins-lib` asks for it to be left off, and the driver that
137/// goes looking for the file. A second spelling of the name anywhere is a flag that stops working
138/// the day the first one is renamed.
139///
140/// Where the file is, is not this crate's answer and used to be. Every line below named it inside
141/// the sysroot, as `sysroot.lib().join(BUILTINS)`, and nothing ever put it there: it is this
142/// compiler's own output for the target rather than anything the platform ships, `cargo xtask
143/// builtins` writes it beside the compiler, and a sysroot fetched from a release will never hold
144/// it. So the lines take the path from whoever built them, which is the driver, and this constant
145/// is the name alone. tamnd/rucc#1514.
146pub const BUILTINS: &str = "librucc_builtins.a";
147
148/// Our runtime as a list, which is what every line below puts at the end of its libraries.
149///
150/// One function rather than the same `into_iter` at four call sites, and it takes the whole answer
151/// rather than a path so that a line reads the same whether the file was found or not.
152fn ours(builtins: Option<&Path>) -> Vec<PathBuf> {
153    builtins.map(Path::to_path_buf).into_iter().collect()
154}
155
156/// The inputs to a link, in the three groups a linker needs them in.
157///
158/// Paths rather than strings, and no flags at all, because
159/// `spec/cross-compile/11-linking.md` owns which linker is invoked and how its arguments are
160/// spelled and [`crate::argv`] is where that happens. What is here is what has to be linked and in
161/// what order, which is a target fact and the same fact whichever linker reads it.
162#[derive(Debug, Clone, PartialEq, Eq)]
163pub struct LinkLine {
164    /// The start files, before the user's objects.
165    pub start: Vec<PathBuf>,
166    /// The libraries, after the user's objects.
167    pub libraries: Vec<PathBuf>,
168    /// The end files, after the libraries.
169    pub end: Vec<PathBuf>,
170}
171
172impl LinkLine {
173    /// The line for a link against this sysroot, whichever libc the target names.
174    ///
175    /// The dispatch rather than the line, and it is [`libc`] that decides: a real archive, a stub
176    /// shared object, or nothing. The three methods below are the three answers. A target whose
177    /// sysroot we do not produce yet still gets the right shape, because the shape follows from
178    /// whether the libc on the target machine is an archive or a shared object and that is known
179    /// before any of it is built.
180    ///
181    /// The runtime is a path from the caller rather than a name joined onto the sysroot, and
182    /// [`None`] means it is not on this machine and the line goes without it. Whether that is worth
183    /// refusing over is the driver's question, since the driver is what knows whether it looked.
184    #[must_use]
185    pub fn for_target(sysroot: &Sysroot, mode: LinkMode, builtins: Option<&Path>) -> Self {
186        match libc(sysroot.target()) {
187            Libc::None => LinkLine::freestanding(builtins),
188            Libc::Archive => LinkLine::musl(sysroot, mode, builtins),
189            Libc::Stub => LinkLine::glibc(sysroot, mode, builtins),
190            Libc::Import => LinkLine::mingw(sysroot, mode, builtins),
191        }
192    }
193
194    /// The line for a freestanding link against this sysroot, which is our runtime and nothing else.
195    ///
196    /// Section 8.2's first row: nine compiler headers and no link inputs. There is no `crt1.o`,
197    /// because nothing here decides what runs before `main` or whether there is a `main` at all, and
198    /// no `crti.o` or `crtn.o`, because those come from a libc too. A kernel or a bootloader brings
199    /// its own start file and says so with `-nostartfiles`, which it would have to pass anyway.
200    ///
201    /// `librucc_builtins.a` stays, because it is ours rather than the platform's.
202    /// `spec/cross-compile/10-runtime.md` is the argument: an architecture with no division
203    /// instruction needs `__divti3` whether there is a libc in the picture or not, and freestanding
204    /// code that does 64-bit arithmetic on a 32-bit target reaches it without asking.
205    ///
206    /// The mode is not a parameter because it changes nothing here. Every difference between the
207    /// modes is a start file and there are none. Neither is the sysroot, now that the one file on
208    /// this line is not in it: a freestanding link reads headers out of a sysroot and links nothing
209    /// out of one.
210    #[must_use]
211    pub fn freestanding(builtins: Option<&Path>) -> Self {
212        LinkLine { start: Vec::new(), libraries: ours(builtins), end: Vec::new() }
213    }
214
215    /// The line for a musl link against this sysroot.
216    ///
217    /// `crt1.o` runs before `main` and calls it. `crti.o` and `crtn.o` are the prologue and the
218    /// epilogue of the `.init` and `.fini` sections, which is why one is at the front and the other
219    /// is at the very back. `libc.a` carries musl's whole C library, and `librucc_builtins.a`
220    /// carries the operations the architecture does not have an instruction for, which
221    /// `spec/cross-compile/10-runtime.md` says has to be ours rather than the platform's.
222    ///
223    /// The builtins go after `libc.a` because musl calls some of them, and an archive that is
224    /// searched before the thing that needs it contributes nothing.
225    ///
226    /// `libc.a` on every mode including the dynamic ones, because what a musl sysroot here holds is
227    /// musl built static: section 9.3 takes musl first precisely because one tarball built one way
228    /// exercises the whole pipeline, and a shared musl is a second build of it that buys nothing
229    /// until somebody asks for a dynamically linked musl program.
230    #[must_use]
231    pub fn musl(sysroot: &Sysroot, mode: LinkMode, builtins: Option<&Path>) -> Self {
232        let lib = sysroot.lib();
233        let mut libraries = vec![lib.join("libc.a")];
234        libraries.extend(ours(builtins));
235        LinkLine { start: start_files(&lib, mode), libraries, end: vec![lib.join("crtn.o")] }
236    }
237
238    /// The line for a link against a generated stub, which is glibc and every other hosted libc that
239    /// is not musl.
240    ///
241    /// Named for glibc because glibc is the case `spec/cross-compile/09-libc-stubs.md` is written
242    /// about and the hard one. bionic, the BSDs and illumos reach the same line for the same reason:
243    /// their libc is a shared object on the target machine, so a list of the names it exports is
244    /// enough to link against it, and that is what `rucc-stub` produces. The paragraphs below about
245    /// `libc_nonshared.a` and `libm` are glibc's own.
246    ///
247    /// The same start files as musl's and a different library, and the library is the whole
248    /// difference between them here. A stub libc is linked against dynamically, so what goes on the
249    /// line is the generated `libc.so` from `rucc-stub` rather than an archive, and the version nodes
250    /// in it are what make a program built here run on an older machine.
251    ///
252    /// `libc_nonshared.a` is deliberately absent and it is a known gap rather than a decision.
253    /// glibc's own `libc.so` is a linker script naming `libc.so.6`, `libc_nonshared.a` and the
254    /// loader as a group, and that archive holds real compiled objects: `atexit`, `__stack_chk_fail_local`
255    /// on i386, and the `stat` family on releases before 2.33. None of it can be synthesized from a
256    /// description, because a stub is a list of names and these are bodies, so it has to be built
257    /// from glibc's sources and that is M9.5's work. A program that needs nothing from it links
258    /// today and a program that does gets an undefined symbol, which is the loud failure rather
259    /// than the quiet one.
260    ///
261    /// `libm.so` is not here either, and that is a decision. glibc's `libm` is real code and a
262    /// program that wants it passes `-lm`, which every build system that does arithmetic already
263    /// does, so putting it on every line would record a dependency the program does not have.
264    ///
265    /// A static glibc link is not one of these: there is no `libc.a` in a sysroot whose libc is a
266    /// stub, because a stub is a list of names and a static link needs bodies.
267    /// [`crate::argv::argv`] refuses that combination by name rather than producing this line with
268    /// `-static` in front of it.
269    #[must_use]
270    pub fn glibc(sysroot: &Sysroot, mode: LinkMode, builtins: Option<&Path>) -> Self {
271        let lib = sysroot.lib();
272        let mut libraries = vec![lib.join("libc.so")];
273        libraries.extend(ours(builtins));
274        LinkLine { start: start_files(&lib, mode), libraries, end: vec![lib.join("crtn.o")] }
275    }
276
277    /// The line for a mingw-w64 link against this sysroot.
278    ///
279    /// One start file and no end file, which is the first thing that is different from every ELF
280    /// line above. `crt2.o` runs before `main` and calls it, `dllcrt2.o` is its counterpart for a
281    /// DLL, and there is no `crti.o` and no `crtn.o` because PE has no `.init` and `.fini` sections
282    /// for a pair of files to open and close. What those two bracket on ELF is done on Windows by a
283    /// table of pointers in the `.CRT$XC` sections, which the linker sorts by section name, so the
284    /// ordering problem the three groups exist for does not arise here.
285    ///
286    /// `crtbegin.o` and `crtend.o` are deliberately absent. They are GCC's files rather than
287    /// mingw-w64's, they bracket GCC's own list of constructors, and a toolchain that is not GCC
288    /// writes that list the way the platform writes it instead. Ours is not written yet: a mingw
289    /// link runs `main` and does not run a file scope constructor, which is a known gap that belongs
290    /// with the sysroot build rather than with the line, and the gap is in the codegen for the
291    /// format rather than here.
292    ///
293    /// The libraries are a set rather than one file, because the C library on Windows is several
294    /// DLLs and the CRT calls into the system ones. `libmingw32.a` holds the start code `crt2.o`
295    /// calls, `libmoldname.a` is the layer that gives the old unprefixed spellings of the names
296    /// Microsoft deprecated, `libmingwex.a` is everything C requires that msvcrt does not have, and
297    /// `libmsvcrt.a` is the import library for the CRT itself. Then the four Win32 libraries that
298    /// mingw-w64's own code calls into, which are on the line for the same reason they are on gcc's:
299    /// a program that uses none of them directly still reaches `kernel32` through `malloc`.
300    ///
301    /// The order is the one a single pass linker needs, which is GNU ld's PE port: a library after
302    /// everything that calls into it. `librucc_builtins.a` is last for the reason it is last on the
303    /// musl line, which is that the things before it call it and it calls none of them. lld's COFF
304    /// linker resolves archives to a fixed point and does not care about any of this, and writing
305    /// the line for the stricter of the two is what makes one line serve both.
306    #[must_use]
307    pub fn mingw(sysroot: &Sysroot, mode: LinkMode, builtins: Option<&Path>) -> Self {
308        let lib = sysroot.lib();
309        let start = match mode {
310            LinkMode::Shared => "dllcrt2.o",
311            _ => "crt2.o",
312        };
313        let theirs = [
314            "libmingw32.a",
315            "libmoldname.a",
316            "libmingwex.a",
317            "libmsvcrt.a",
318            "libadvapi32.a",
319            "libshell32.a",
320            "libuser32.a",
321            "libkernel32.a",
322        ];
323        let mut libraries: Vec<PathBuf> = theirs.iter().map(|name| lib.join(name)).collect();
324        libraries.extend(ours(builtins));
325        LinkLine { start: vec![lib.join(start)], libraries, end: Vec::new() }
326    }
327
328    /// Every input, in the order they reach the linker, with the caller's objects in the middle.
329    ///
330    /// The one function that knows the whole order, so that a caller cannot assemble the three
331    /// groups in the wrong sequence.
332    #[must_use]
333    pub fn with_objects(&self, objects: &[PathBuf]) -> Vec<PathBuf> {
334        let mut all = self.start.clone();
335        all.extend_from_slice(objects);
336        all.extend(self.libraries.iter().cloned());
337        all.extend(self.end.iter().cloned());
338        all
339    }
340}
341
342/// The start files for one mode, in the order they go on the line.
343///
344/// Two files, and which the first one is says how the reference to `main` inside it is written.
345/// `crt1.o` refers to it absolutely, `Scrt1.o` through the global offset table so that a loader may
346/// place the program anywhere, and `rcrt1.o` does that and relocates the program itself before
347/// `main` runs, which is what a static position independent executable needs because there is no
348/// loader to do it. A shared object has none of them.
349///
350/// `crti.o` is always second and `crtn.o` is always last, which is [`LinkLine`]'s three groups
351/// rather than anything here.
352fn start_files(lib: &Path, mode: LinkMode) -> Vec<PathBuf> {
353    let first = match mode {
354        LinkMode::Static | LinkMode::DynamicNoPie => Some("crt1.o"),
355        LinkMode::StaticPie => Some("rcrt1.o"),
356        LinkMode::Dynamic => Some("Scrt1.o"),
357        LinkMode::Shared => None,
358    };
359    first.map(|name| lib.join(name)).into_iter().chain([lib.join("crti.o")]).collect()
360}
361
362/// The absolute path the target's loader is installed at, or [`None`] for a target that has none.
363///
364/// The libc picks the table and the architecture picks the row. [`None`] is the right answer for
365/// three different reasons: a freestanding target has no libc, WASI has no loader of this kind at
366/// all, and Darwin and Windows have one whose path is not written on the link line.
367#[must_use]
368pub fn loader(target: TargetTuple) -> Option<&'static str> {
369    match (target.os(), target.env()) {
370        (Os::Linux, Env::Musl) => Some(musl_loader(target)),
371        (Os::Linux, Env::Gnu) => Some(glibc_loader(target)),
372        // Bionic's is one path per word size and not one per architecture, because Android fixes
373        // the filesystem layout rather than leaving it to the port.
374        (Os::Linux, Env::Android) => Some(match target.pointer_width() {
375            64 => "/system/bin/linker64",
376            _ => "/system/bin/linker",
377        }),
378        _ => None,
379    }
380}
381
382/// The absolute path musl's loader is installed at on the target.
383///
384/// It goes in the program header of a dynamically linked binary, so it is a string about the target
385/// machine's filesystem and not about ours, and it has to be right without anything to check it
386/// against at link time. A wrong one produces a binary that the kernel refuses to start with a
387/// message about a missing file that is on nobody's disk.
388///
389/// 32-bit ARM is the row with two answers, because musl names the hard float and soft float builds
390/// differently and they are not interchangeable. PowerPC is the other row with two, and there the
391/// endianness picks, because musl treats the two byte orders as separate ports.
392#[must_use]
393pub fn musl_loader(target: TargetTuple) -> &'static str {
394    match target.arch() {
395        Arch::X86_64 => match target.data_model() {
396            DataModel::Ilp32On64 => "/lib/ld-musl-x32.so.1",
397            _ => "/lib/ld-musl-x86_64.so.1",
398        },
399        Arch::X86 => "/lib/ld-musl-i386.so.1",
400        Arch::Aarch64 | Arch::Arm64Ec => "/lib/ld-musl-aarch64.so.1",
401        Arch::Arm => match target.resolved_abi() {
402            Abi::DoubleFloat => "/lib/ld-musl-armhf.so.1",
403            _ => "/lib/ld-musl-arm.so.1",
404        },
405        Arch::Riscv64 => "/lib/ld-musl-riscv64.so.1",
406        Arch::Riscv32 => "/lib/ld-musl-riscv32.so.1",
407        Arch::S390x => "/lib/ld-musl-s390x.so.1",
408        Arch::PowerPc64 => match target.endian() {
409            Endian::Little => "/lib/ld-musl-powerpc64le.so.1",
410            Endian::Big => "/lib/ld-musl-powerpc64.so.1",
411        },
412        Arch::LoongArch64 => "/lib/ld-musl-loongarch64.so.1",
413        // musl has no wasm port and wasm has no loader. The caller that gets here asked for a
414        // dynamic musl link on a target with neither, which is a driver bug rather than a user
415        // one, and a path that cannot exist is a better report than a plausible wrong one.
416        Arch::Wasm32 => "/lib/ld-musl-none.so.1",
417    }
418}
419
420/// The absolute path glibc's loader is installed at on the target.
421///
422/// A different table from musl's and not a different spelling of it. musl names every loader after
423/// the architecture in one directory; glibc's names come from each port's history, so three of them
424/// are called `ld64.so` with a number that means something different per architecture, two are in
425/// `/lib64` rather than `/lib`, and i386's carries no architecture in its name at all because it was
426/// the only one when it was named.
427///
428/// The rows with more than one answer are the ones where the loader and the program have to agree
429/// about register usage. 32-bit ARM has the hard float and soft float split, RISC-V and LoongArch
430/// spell the float ABI and the data model into the name, and AArch64 has a byte order in it.
431/// Getting one wrong produces a binary the kernel will not start, with a message about a missing
432/// file, and it is a string nothing at link time can check.
433#[must_use]
434pub fn glibc_loader(target: TargetTuple) -> &'static str {
435    let narrow = target.data_model() == DataModel::Ilp32On64;
436    let hard = matches!(target.resolved_abi(), Abi::DoubleFloat);
437    match target.arch() {
438        Arch::X86_64 if narrow => "/libx32/ld-linux-x32.so.2",
439        Arch::X86_64 => "/lib64/ld-linux-x86-64.so.2",
440        Arch::X86 => "/lib/ld-linux.so.2",
441        Arch::Aarch64 | Arch::Arm64Ec => match (target.endian(), narrow) {
442            (Endian::Little, false) => "/lib/ld-linux-aarch64.so.1",
443            (Endian::Little, true) => "/lib/ld-linux-aarch64_ilp32.so.1",
444            (Endian::Big, false) => "/lib/ld-linux-aarch64_be.so.1",
445            (Endian::Big, true) => "/lib/ld-linux-aarch64_be_ilp32.so.1",
446        },
447        // The one row where the number differs rather than the name. ARM's loader went to 3 when
448        // EABI replaced OABI, and the hard float build is a separate file because passing a double
449        // in a float register is not compatible with passing it in a pair of integer ones.
450        Arch::Arm if hard => "/lib/ld-linux-armhf.so.3",
451        Arch::Arm => "/lib/ld-linux.so.3",
452        Arch::Riscv64 if hard => "/lib/ld-linux-riscv64-lp64d.so.1",
453        Arch::Riscv64 => "/lib/ld-linux-riscv64-lp64.so.1",
454        Arch::Riscv32 if hard => "/lib/ld-linux-riscv32-ilp32d.so.1",
455        Arch::Riscv32 => "/lib/ld-linux-riscv32-ilp32.so.1",
456        // `ld64` here means 64-bit z/Architecture and the 1 is glibc's ABI version for the port,
457        // which is not the 2 on PowerPC's file of the same name. It is in `/lib` and PowerPC's is in
458        // `/lib64`, so the two rows have nothing in common but the stem.
459        Arch::S390x => "/lib/ld64.so.1",
460        // ELFv2, both byte orders, which is the only PowerPC ABI
461        // `spec/cross-compile/06-abis.md` admits. The ELFv1 big-endian world uses `ld64.so.1` and
462        // is out of scope, so a wrong answer here is impossible rather than merely unlikely.
463        Arch::PowerPc64 => "/lib64/ld64.so.2",
464        Arch::LoongArch64 if hard => "/lib64/ld-linux-loongarch-lp64d.so.1",
465        Arch::LoongArch64 => "/lib64/ld-linux-loongarch-lp64s.so.1",
466        // There is no glibc for wasm and no loader for it either. Same reasoning as the musl table
467        // above: a path nothing will ever open beats a plausible one.
468        Arch::Wasm32 => "/lib/ld-linux-wasm32.so.1",
469    }
470}