Skip to content

Commit 8bea2ba

Browse files
committed
win: Copy libcc/compiler-rt to the sysroot and use it
Instead of hardcoding -lgcc. This allows to use compiler-rt when compiling with clang. Since -nodefaultlibs is used, compiler-rt isn't added by default, causing various linking failures.
1 parent c51f215 commit 8bea2ba

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/bootstrap/compile.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ impl Step for StartupObjects {
329329
obj);
330330
builder.copy(&src, &sysroot_dir.join(obj));
331331
}
332+
let libgcc = compiler_libgcc(builder, builder.cc(target));
333+
builder.copy(&libgcc, &sysroot_dir.join("libgcc.a"));
332334
}
333335
}
334336

@@ -890,6 +892,18 @@ pub fn compiler_file(
890892
PathBuf::from(out.trim())
891893
}
892894

895+
/// Get the path to libgcc or compiler-rt
896+
fn compiler_libgcc(
897+
builder: &Builder<'_>,
898+
compiler: &Path
899+
) -> PathBuf {
900+
let mut cmd = Command::new(compiler);
901+
cmd.arg("-print-libgcc-file-name");
902+
builder.info(&format!("compiler cmd: {:?}", &cmd));
903+
let out = output(&mut cmd);
904+
PathBuf::from(out.trim())
905+
}
906+
893907
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
894908
pub struct Sysroot {
895909
pub compiler: Compiler,

src/librustc_target/spec/windows_base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub fn opts() -> TargetOptions {
4646
late_link_args.insert(LinkerFlavor::Gcc, vec![
4747
"-lmingwex".to_string(),
4848
"-lmingw32".to_string(),
49-
"-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
5049
"-lmsvcrt".to_string(),
5150
// mingw's msvcrt is a weird hybrid import library and static library.
5251
// And it seems that the linker fails to use import symbols from msvcrt
@@ -87,7 +86,8 @@ pub fn opts() -> TargetOptions {
8786
],
8887
late_link_args,
8988
post_link_objects: vec![
90-
"rsend.o".to_string()
89+
"rsend.o".to_string(),
90+
"libgcc.a".to_string(), // libgcc or compiler-rt
9191
],
9292
custom_unwind_resume: true,
9393
abi_return_struct_as_int: true,

0 commit comments

Comments
 (0)