1
1
use crate :: spec:: crt_objects:: { self , CrtObjectsFallback } ;
2
- use crate :: spec:: { LinkArgs , LinkerFlavor , TargetOptions } ;
2
+ use crate :: spec:: { LinkArgs , LinkerFlavor , LldFlavor , TargetOptions } ;
3
3
4
4
pub fn opts ( ) -> TargetOptions {
5
5
let mut pre_link_args = LinkArgs :: new ( ) ;
@@ -19,51 +19,48 @@ pub fn opts() -> TargetOptions {
19
19
let mut late_link_args_static = LinkArgs :: new ( ) ;
20
20
// Order of `late_link_args*` was found through trial and error to work with various
21
21
// mingw-w64 versions (not tested on the CI). It's expected to change from time to time.
22
- late_link_args. insert (
23
- LinkerFlavor :: Gcc ,
24
- vec ! [
25
- "-lmsvcrt" . to_string( ) ,
26
- "-lmingwex" . to_string( ) ,
27
- "-lmingw32" . to_string( ) ,
28
- // mingw's msvcrt is a weird hybrid import library and static library.
29
- // And it seems that the linker fails to use import symbols from msvcrt
30
- // that are required from functions in msvcrt in certain cases. For example
31
- // `_fmode` that is used by an implementation of `__p__fmode` in x86_64.
32
- // The library is purposely listed twice to fix that.
33
- //
34
- // See https://github.com/rust-lang/rust/pull/47483 for some more details.
35
- "-lmsvcrt" . to_string( ) ,
36
- "-luser32" . to_string( ) ,
37
- "-lkernel32" . to_string( ) ,
38
- ] ,
39
- ) ;
40
- late_link_args_dynamic. insert (
41
- LinkerFlavor :: Gcc ,
42
- vec ! [
43
- // If any of our crates are dynamically linked then we need to use
44
- // the shared libgcc_s-dw2-1.dll. This is required to support
45
- // unwinding across DLL boundaries.
46
- "-lgcc_s" . to_string( ) ,
47
- "-lgcc" . to_string( ) ,
48
- "-lkernel32" . to_string( ) ,
49
- ] ,
50
- ) ;
51
- late_link_args_static. insert (
52
- LinkerFlavor :: Gcc ,
53
- vec ! [
54
- // If all of our crates are statically linked then we can get away
55
- // with statically linking the libgcc unwinding code. This allows
56
- // binaries to be redistributed without the libgcc_s-dw2-1.dll
57
- // dependency, but unfortunately break unwinding across DLL
58
- // boundaries when unwinding across FFI boundaries.
59
- "-lgcc_eh" . to_string( ) ,
60
- "-l:libpthread.a" . to_string( ) ,
61
- "-lgcc" . to_string( ) ,
62
- // libpthread depends on libmsvcrt, so we need to link it *again*.
63
- "-lmsvcrt" . to_string( ) ,
64
- "-lkernel32" . to_string( ) ,
65
- ] ,
66
- ) ;
22
+ let mingw_libs = vec ! [
23
+ "-lmsvcrt" . to_string( ) ,
24
+ "-lmingwex" . to_string( ) ,
25
+ "-lmingw32" . to_string( ) ,
26
+ // mingw's msvcrt is a weird hybrid import library and static library.
27
+ // And it seems that the linker fails to use import symbols from msvcrt
28
+ // that are required from functions in msvcrt in certain cases. For example
29
+ // `_fmode` that is used by an implementation of `__p__fmode` in x86_64.
30
+ // The library is purposely listed twice to fix that.
31
+ //
32
+ // See https://github.com/rust-lang/rust/pull/47483 for some more details.
33
+ "-lmsvcrt" . to_string( ) ,
34
+ "-luser32" . to_string( ) ,
35
+ "-lkernel32" . to_string( ) ,
36
+ ] ;
37
+ late_link_args. insert ( LinkerFlavor :: Gcc , mingw_libs. clone ( ) ) ;
38
+ late_link_args. insert ( LinkerFlavor :: Lld ( LldFlavor :: Ld ) , mingw_libs) ;
39
+ let dynamic_unwind_libs = vec ! [
40
+ // If any of our crates are dynamically linked then we need to use
41
+ // the shared libgcc_s-dw2-1.dll. This is required to support
42
+ // unwinding across DLL boundaries.
43
+ "-lgcc_s" . to_string( ) ,
44
+ "-lgcc" . to_string( ) ,
45
+ "-lkernel32" . to_string( ) ,
46
+ ] ;
47
+ late_link_args_dynamic. insert ( LinkerFlavor :: Gcc , dynamic_unwind_libs. clone ( ) ) ;
48
+ late_link_args_dynamic. insert ( LinkerFlavor :: Lld ( LldFlavor :: Ld ) , dynamic_unwind_libs) ;
49
+ let static_unwind_libs = vec ! [
50
+ // If all of our crates are statically linked then we can get away
51
+ // with statically linking the libgcc unwinding code. This allows
52
+ // binaries to be redistributed without the libgcc_s-dw2-1.dll
53
+ // dependency, but unfortunately break unwinding across DLL
54
+ // boundaries when unwinding across FFI boundaries.
55
+ "-lgcc_eh" . to_string( ) ,
56
+ "-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( ) ,
61
+ ] ;
62
+ late_link_args_static. insert ( LinkerFlavor :: Gcc , static_unwind_libs. clone ( ) ) ;
63
+ late_link_args_static. insert ( LinkerFlavor :: Lld ( LldFlavor :: Ld ) , static_unwind_libs) ;
67
64
68
65
TargetOptions {
69
66
// FIXME(#13846) this should be enabled for windows
0 commit comments