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