Copy musl startup objects before building std
They are required for linking it, even though it is a library, because crtn.o in post_link_objects, as hardcoded in src/librustc_back/target/ linux_musl_base.rs, is added to the linker command line for both executables and libraries.
This commit is contained in:
parent
8606782bc1
commit
0c7a0e9851
|
@ -77,6 +77,14 @@ impl Step for Std {
|
|||
target,
|
||||
});
|
||||
println!("Uplifting stage1 std ({} -> {})", from.host, target);
|
||||
|
||||
// Even if we're not building std this stage, the new sysroot must
|
||||
// still contain the musl startup objects.
|
||||
if target.contains("musl") && !target.contains("mips") {
|
||||
let libdir = builder.sysroot_libdir(compiler, target);
|
||||
copy_musl_third_party_objects(build, target, &libdir);
|
||||
}
|
||||
|
||||
builder.ensure(StdLink {
|
||||
compiler: from,
|
||||
target_compiler: compiler,
|
||||
|
@ -89,6 +97,11 @@ impl Step for Std {
|
|||
println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
|
||||
&compiler.host, target);
|
||||
|
||||
if target.contains("musl") && !target.contains("mips") {
|
||||
let libdir = builder.sysroot_libdir(compiler, target);
|
||||
copy_musl_third_party_objects(build, target, &libdir);
|
||||
}
|
||||
|
||||
let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
|
||||
build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
|
||||
let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "build");
|
||||
|
@ -105,6 +118,20 @@ impl Step for Std {
|
|||
}
|
||||
}
|
||||
|
||||
/// Copies the crt(1,i,n).o startup objects
|
||||
///
|
||||
/// Since musl supports fully static linking, we can cross link for it even
|
||||
/// with a glibc-targeting toolchain, given we have the appropriate startup
|
||||
/// files. As those shipped with glibc won't work, copy the ones provided by
|
||||
/// musl so we have them on linux-gnu hosts.
|
||||
fn copy_musl_third_party_objects(build: &Build,
|
||||
target: Interned<String>,
|
||||
into: &Path) {
|
||||
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
|
||||
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// Configure cargo to compile the standard library, adding appropriate env vars
|
||||
/// and such.
|
||||
pub fn std_cargo(build: &Build,
|
||||
|
@ -189,10 +216,6 @@ impl Step for StdLink {
|
|||
let libdir = builder.sysroot_libdir(target_compiler, target);
|
||||
add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
|
||||
|
||||
if target.contains("musl") && !target.contains("mips") {
|
||||
copy_musl_third_party_objects(build, target, &libdir);
|
||||
}
|
||||
|
||||
if build.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
|
||||
// The sanitizers are only built in stage1 or above, so the dylibs will
|
||||
// be missing in stage0 and causes panic. See the `std()` function above
|
||||
|
@ -208,18 +231,6 @@ impl Step for StdLink {
|
|||
}
|
||||
}
|
||||
|
||||
/// Copies the crt(1,i,n).o startup objects
|
||||
///
|
||||
/// Since musl supports fully static linking, we can cross link for it even
|
||||
/// with a glibc-targeting toolchain, given we have the appropriate startup
|
||||
/// files. As those shipped with glibc won't work, copy the ones provided by
|
||||
/// musl so we have them on linux-gnu hosts.
|
||||
fn copy_musl_third_party_objects(build: &Build, target: Interned<String>, into: &Path) {
|
||||
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
|
||||
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_apple_sanitizer_dylibs(native_dir: &Path, platform: &str, into: &Path) {
|
||||
for &sanitizer in &["asan", "tsan"] {
|
||||
let filename = format!("libclang_rt.{}_{}_dynamic.dylib", sanitizer, platform);
|
||||
|
|
Loading…
Reference in New Issue