Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0c7a0e9

Browse files
committedAug 22, 2017
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.
1 parent 8606782 commit 0c7a0e9

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed
 

‎src/bootstrap/compile.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ impl Step for Std {
7777
target,
7878
});
7979
println!("Uplifting stage1 std ({} -> {})", from.host, target);
80+
81+
// Even if we're not building std this stage, the new sysroot must
82+
// still contain the musl startup objects.
83+
if target.contains("musl") && !target.contains("mips") {
84+
let libdir = builder.sysroot_libdir(compiler, target);
85+
copy_musl_third_party_objects(build, target, &libdir);
86+
}
87+
8088
builder.ensure(StdLink {
8189
compiler: from,
8290
target_compiler: compiler,
@@ -89,6 +97,11 @@ impl Step for Std {
8997
println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
9098
&compiler.host, target);
9199

100+
if target.contains("musl") && !target.contains("mips") {
101+
let libdir = builder.sysroot_libdir(compiler, target);
102+
copy_musl_third_party_objects(build, target, &libdir);
103+
}
104+
92105
let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
93106
build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
94107
let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "build");
@@ -105,6 +118,20 @@ impl Step for Std {
105118
}
106119
}
107120

121+
/// Copies the crt(1,i,n).o startup objects
122+
///
123+
/// Since musl supports fully static linking, we can cross link for it even
124+
/// with a glibc-targeting toolchain, given we have the appropriate startup
125+
/// files. As those shipped with glibc won't work, copy the ones provided by
126+
/// musl so we have them on linux-gnu hosts.
127+
fn copy_musl_third_party_objects(build: &Build,
128+
target: Interned<String>,
129+
into: &Path) {
130+
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
131+
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
132+
}
133+
}
134+
108135
/// Configure cargo to compile the standard library, adding appropriate env vars
109136
/// and such.
110137
pub fn std_cargo(build: &Build,
@@ -189,10 +216,6 @@ impl Step for StdLink {
189216
let libdir = builder.sysroot_libdir(target_compiler, target);
190217
add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
191218

192-
if target.contains("musl") && !target.contains("mips") {
193-
copy_musl_third_party_objects(build, target, &libdir);
194-
}
195-
196219
if build.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
197220
// The sanitizers are only built in stage1 or above, so the dylibs will
198221
// be missing in stage0 and causes panic. See the `std()` function above
@@ -208,18 +231,6 @@ impl Step for StdLink {
208231
}
209232
}
210233

211-
/// Copies the crt(1,i,n).o startup objects
212-
///
213-
/// Since musl supports fully static linking, we can cross link for it even
214-
/// with a glibc-targeting toolchain, given we have the appropriate startup
215-
/// files. As those shipped with glibc won't work, copy the ones provided by
216-
/// musl so we have them on linux-gnu hosts.
217-
fn copy_musl_third_party_objects(build: &Build, target: Interned<String>, into: &Path) {
218-
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
219-
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
220-
}
221-
}
222-
223234
fn copy_apple_sanitizer_dylibs(native_dir: &Path, platform: &str, into: &Path) {
224235
for &sanitizer in &["asan", "tsan"] {
225236
let filename = format!("libclang_rt.{}_{}_dynamic.dylib", sanitizer, platform);

0 commit comments

Comments
 (0)
Please sign in to comment.