I'll put it here without a better zulip "stream" .
Code examples from compiler/build/src/link.rs:
Ok((
Command::new("ld")
// Don't allow LD_ env vars to affect this
.env_clear()
.env("PATH", &env_path)
// Keep NIX_ env vars
.envs(
env::vars()
.filter(|&(ref k, _)| k.starts_with("NIX_"))
.collect::<HashMap<String, String>>(),
)
.args(&[
"--gc-sections",
"--eh-frame-hdr",
"--arch",
arch_str(target),
"-pie",
libcrt_path.join("crti.o").to_str().unwrap(),
libcrt_path.join("crtn.o").to_str().unwrap(),
])
let libgcc_name = "libgcc_s.so.1";
let libgcc_path = library_path(["/lib", &architecture, libgcc_name])
.or_else(|| library_path(["/usr", "lib", &architecture, libgcc_name]))
.or_else(|| library_path(["/usr", "lib", libgcc_name]))
.or_else(|| library_path([&nixos_path(), libgcc_name]))
.unwrap();
Problems:
Again, it would be better to generate build files for a build system like Ninja and that to find libraries. Also don't find libraries in "/usr/lib" if the user doesn't specify that path, since we don't need legacy support for a new language.
yeah we're working on a linking system that replaces all this with a totally different approach, and runs way faster too!
it's not feature-complete enough to replace this yet though
Last updated: Jun 16 2026 at 16:19 UTC