Skip to content

Commit 3d1d24d

Browse files
Rollup merge of #77208 - mati865:late-link-args-order, r=petrochenkov
Late link args order MSYS2 changed how winpthreads is built and as the result it now depends on more mingw-w64 libraries. This PR affects only MinGW targets since nobody else is using `late_link_args_{dynamic,static}`. Now the order is similar to how it used to be before #67502.
2 parents bb416f3 + bfdb790 commit 3d1d24d

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1333,9 +1333,6 @@ fn add_late_link_args(
13331333
crate_type: CrateType,
13341334
codegen_results: &CodegenResults,
13351335
) {
1336-
if let Some(args) = sess.target.target.options.late_link_args.get(&flavor) {
1337-
cmd.args(args);
1338-
}
13391336
let any_dynamic_crate = crate_type == CrateType::Dylib
13401337
|| codegen_results.crate_info.dependency_formats.iter().any(|(ty, list)| {
13411338
*ty == crate_type && list.iter().any(|&linkage| linkage == Linkage::Dynamic)
@@ -1349,6 +1346,9 @@ fn add_late_link_args(
13491346
cmd.args(args);
13501347
}
13511348
}
1349+
if let Some(args) = sess.target.target.options.late_link_args.get(&flavor) {
1350+
cmd.args(args);
1351+
}
13521352
}
13531353

13541354
/// Add arbitrary "post-link" args defined by the target spec.

compiler/rustc_target/src/spec/windows_gnu_base.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn opts() -> TargetOptions {
2323
"-lmsvcrt".to_string(),
2424
"-lmingwex".to_string(),
2525
"-lmingw32".to_string(),
26+
"-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
2627
// mingw's msvcrt is a weird hybrid import library and static library.
2728
// And it seems that the linker fails to use import symbols from msvcrt
2829
// that are required from functions in msvcrt in certain cases. For example
@@ -41,8 +42,6 @@ pub fn opts() -> TargetOptions {
4142
// the shared libgcc_s-dw2-1.dll. This is required to support
4243
// unwinding across DLL boundaries.
4344
"-lgcc_s".to_string(),
44-
"-lgcc".to_string(),
45-
"-lkernel32".to_string(),
4645
];
4746
late_link_args_dynamic.insert(LinkerFlavor::Gcc, dynamic_unwind_libs.clone());
4847
late_link_args_dynamic.insert(LinkerFlavor::Lld(LldFlavor::Ld), dynamic_unwind_libs);
@@ -54,10 +53,6 @@ pub fn opts() -> TargetOptions {
5453
// boundaries when unwinding across FFI boundaries.
5554
"-lgcc_eh".to_string(),
5655
"-l:libpthread.a".to_string(),
57-
"-lgcc".to_string(),
58-
// libpthread depends on libmsvcrt, so we need to link it *again*.
59-
"-lmsvcrt".to_string(),
60-
"-lkernel32".to_string(),
6156
];
6257
late_link_args_static.insert(LinkerFlavor::Gcc, static_unwind_libs.clone());
6358
late_link_args_static.insert(LinkerFlavor::Lld(LldFlavor::Ld), static_unwind_libs);

0 commit comments

Comments
 (0)