1
- use crate :: spec:: { add_link_args, crt_objects} ;
1
+ use crate :: spec:: crt_objects;
2
+ use crate :: spec:: LinkSelfContainedDefault ;
2
3
use crate :: spec:: { cvs, Cc , DebuginfoKind , LinkerFlavor , Lld , SplitDebuginfo , TargetOptions } ;
3
- use crate :: spec:: { LinkSelfContainedDefault , MaybeLazy } ;
4
4
use std:: borrow:: Cow ;
5
5
6
6
pub fn opts ( ) -> TargetOptions {
7
- let pre_link_args = MaybeLazy :: lazy ( || {
8
- let mut pre_link_args = TargetOptions :: link_args_base (
7
+ let pre_link_args = TargetOptions :: link_args_list ( & [
8
+ (
9
9
LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) ,
10
10
& [
11
11
// Enable ASLR
12
12
"--dynamicbase" ,
13
13
// ASLR will rebase it anyway so leaving that option enabled only leads to confusion
14
14
"--disable-auto-image-base" ,
15
15
] ,
16
- ) ;
17
- add_link_args (
18
- & mut pre_link_args,
16
+ ) ,
17
+ (
19
18
LinkerFlavor :: Gnu ( Cc :: Yes , Lld :: No ) ,
20
19
& [
21
20
// Tell GCC to avoid linker plugins, because we are not bundling
@@ -24,14 +23,13 @@ pub fn opts() -> TargetOptions {
24
23
"-Wl,--dynamicbase" ,
25
24
"-Wl,--disable-auto-image-base" ,
26
25
] ,
27
- ) ;
28
- pre_link_args
29
- } ) ;
26
+ ) ,
27
+ ] ) ;
30
28
31
- let late_link_args = MaybeLazy :: lazy ( || {
29
+ let late_link_args = {
32
30
// Order of `late_link_args*` was found through trial and error to work with various
33
31
// mingw-w64 versions (not tested on the CI). It's expected to change from time to time.
34
- let mingw_libs = & [
32
+ const MINGW_LIBS : & [ & str ] = & [
35
33
"-lmsvcrt" ,
36
34
"-lmingwex" ,
37
35
"-lmingw32" ,
@@ -50,41 +48,33 @@ pub fn opts() -> TargetOptions {
50
48
"-luser32" ,
51
49
"-lkernel32" ,
52
50
] ;
53
- let mut late_link_args =
54
- TargetOptions :: link_args_base ( LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) , mingw_libs ) ;
55
- add_link_args ( & mut late_link_args , LinkerFlavor :: Gnu ( Cc :: Yes , Lld :: No ) , mingw_libs ) ;
56
- late_link_args
57
- } ) ;
51
+ TargetOptions :: link_args_list ( & [
52
+ ( LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) , MINGW_LIBS ) ,
53
+ ( LinkerFlavor :: Gnu ( Cc :: Yes , Lld :: No ) , MINGW_LIBS ) ,
54
+ ] )
55
+ } ;
58
56
// If any of our crates are dynamically linked then we need to use
59
57
// the shared libgcc_s-dw2-1.dll. This is required to support
60
58
// unwinding across DLL boundaries.
61
- let late_link_args_dynamic = MaybeLazy :: lazy ( || {
62
- let dynamic_unwind_libs = & [ "-lgcc_s" ] ;
63
- let mut late_link_args_dynamic =
64
- TargetOptions :: link_args_base ( LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) , dynamic_unwind_libs) ;
65
- add_link_args (
66
- & mut late_link_args_dynamic,
67
- LinkerFlavor :: Gnu ( Cc :: Yes , Lld :: No ) ,
68
- dynamic_unwind_libs,
69
- ) ;
70
- late_link_args_dynamic
71
- } ) ;
59
+ let late_link_args_dynamic = {
60
+ const DYNAMIC_UNWIND_LIBS : & [ & str ] = & [ "-lgcc_s" ] ;
61
+ TargetOptions :: link_args_list ( & [
62
+ ( LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) , DYNAMIC_UNWIND_LIBS ) ,
63
+ ( LinkerFlavor :: Gnu ( Cc :: Yes , Lld :: No ) , DYNAMIC_UNWIND_LIBS ) ,
64
+ ] )
65
+ } ;
72
66
// If all of our crates are statically linked then we can get away
73
67
// with statically linking the libgcc unwinding code. This allows
74
68
// binaries to be redistributed without the libgcc_s-dw2-1.dll
75
69
// dependency, but unfortunately break unwinding across DLL
76
70
// boundaries when unwinding across FFI boundaries.
77
- let late_link_args_static = MaybeLazy :: lazy ( || {
78
- let static_unwind_libs = & [ "-lgcc_eh" , "-l:libpthread.a" ] ;
79
- let mut late_link_args_static =
80
- TargetOptions :: link_args_base ( LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) , static_unwind_libs) ;
81
- add_link_args (
82
- & mut late_link_args_static,
83
- LinkerFlavor :: Gnu ( Cc :: Yes , Lld :: No ) ,
84
- static_unwind_libs,
85
- ) ;
86
- late_link_args_static
87
- } ) ;
71
+ let late_link_args_static = {
72
+ const STATIC_UNWIND_LIBS : & [ & str ] = & [ "-lgcc_eh" , "-l:libpthread.a" ] ;
73
+ TargetOptions :: link_args_list ( & [
74
+ ( LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) , STATIC_UNWIND_LIBS ) ,
75
+ ( LinkerFlavor :: Gnu ( Cc :: Yes , Lld :: No ) , STATIC_UNWIND_LIBS ) ,
76
+ ] )
77
+ } ;
88
78
89
79
TargetOptions {
90
80
os : "windows" . into ( ) ,
0 commit comments