1- use crate :: spec:: { add_link_args, crt_objects} ;
1+ use crate :: spec:: crt_objects;
2+ use crate :: spec:: LinkSelfContainedDefault ;
23use crate :: spec:: { cvs, Cc , DebuginfoKind , LinkerFlavor , Lld , SplitDebuginfo , TargetOptions } ;
3- use crate :: spec:: { LinkSelfContainedDefault , MaybeLazy } ;
44use std:: borrow:: Cow ;
55
66pub 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+ (
99 LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) ,
1010 & [
1111 // Enable ASLR
1212 "--dynamicbase" ,
1313 // ASLR will rebase it anyway so leaving that option enabled only leads to confusion
1414 "--disable-auto-image-base" ,
1515 ] ,
16- ) ;
17- add_link_args (
18- & mut pre_link_args,
16+ ) ,
17+ (
1918 LinkerFlavor :: Gnu ( Cc :: Yes , Lld :: No ) ,
2019 & [
2120 // Tell GCC to avoid linker plugins, because we are not bundling
@@ -24,14 +23,13 @@ pub fn opts() -> TargetOptions {
2423 "-Wl,--dynamicbase" ,
2524 "-Wl,--disable-auto-image-base" ,
2625 ] ,
27- ) ;
28- pre_link_args
29- } ) ;
26+ ) ,
27+ ] ) ;
3028
31- let late_link_args = MaybeLazy :: lazy ( || {
29+ let late_link_args = {
3230 // Order of `late_link_args*` was found through trial and error to work with various
3331 // 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 ] = & [
3533 "-lmsvcrt" ,
3634 "-lmingwex" ,
3735 "-lmingw32" ,
@@ -50,41 +48,33 @@ pub fn opts() -> TargetOptions {
5048 "-luser32" ,
5149 "-lkernel32" ,
5250 ] ;
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+ } ;
5856 // If any of our crates are dynamically linked then we need to use
5957 // the shared libgcc_s-dw2-1.dll. This is required to support
6058 // 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+ } ;
7266 // If all of our crates are statically linked then we can get away
7367 // with statically linking the libgcc unwinding code. This allows
7468 // binaries to be redistributed without the libgcc_s-dw2-1.dll
7569 // dependency, but unfortunately break unwinding across DLL
7670 // 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+ } ;
8878
8979 TargetOptions {
9080 os : "windows" . into ( ) ,
0 commit comments