1
- use crate :: spec:: { LinkArgs , LinkerFlavor , LldFlavor , TargetOptions } ;
1
+ // https://docs.microsoft.com/en-us/cpp/build/reference/linking
2
+ // https://docs.microsoft.com/en-us/cpp/build/reference/libpath-additional-libpath
3
+ // > LINK first processes options specified in the LINK environment variable, followed by options
4
+ // > in the order they are specified on the command line and in command files.
5
+ // > If an option is repeated with different arguments, the last one processed takes precedence.
6
+ // > Options apply to the entire build; no options can be applied to specific input files.
7
+ // > If you want to specify more than one directory, you must specify multiple /LIBPATH options.
8
+ // > The linker will then search the specified directories in order.
9
+ //
10
+ // Therefore all options that are not input files are order-independent and either non-overridable
11
+ // or right-overridable. Library search directories are left-overridable.
12
+
13
+ use crate :: spec:: { LinkArgsMap , LinkerFlavor , LldFlavor , NewLinkArgs , TargetOptions } ;
2
14
3
15
pub fn opts ( ) -> TargetOptions {
4
- let pre_link_args_msvc = vec ! [
5
- // Suppress the verbose logo and authorship debugging output, which would needlessly
6
- // clog any log files.
7
- "/NOLOGO" . to_string( ) ,
8
- // Tell the compiler that non-code sections can be marked as non-executable,
9
- // including stack pages.
10
- // UEFI is fully compatible to non-executable data pages.
11
- // In fact, firmware might enforce this, so we better let the linker know about this,
12
- // so it will fail if the compiler ever tries placing code on the stack
13
- // (e.g., trampoline constructs and alike).
14
- "/NXCOMPAT" . to_string( ) ,
15
- ] ;
16
- let mut pre_link_args = LinkArgs :: new ( ) ;
17
- pre_link_args. insert ( LinkerFlavor :: Msvc , pre_link_args_msvc. clone ( ) ) ;
18
- pre_link_args. insert ( LinkerFlavor :: Lld ( LldFlavor :: Link ) , pre_link_args_msvc) ;
16
+ let new_link_args = NewLinkArgs {
17
+ unordered_non_overridable : vec ! [
18
+ // Suppress the verbose logo and authorship debugging output, which would needlessly
19
+ // clog any log files.
20
+ "/NOLOGO" . to_string( ) ,
21
+ ] ,
22
+ unordered_right_overridable : vec ! [
23
+ // Tell the compiler that non-code sections can be marked as non-executable,
24
+ // including stack pages.
25
+ // UEFI is fully compatible to non-executable data pages.
26
+ // In fact, firmware might enforce this, so we better let the linker know about this,
27
+ // so it will fail if the compiler ever tries placing code on the stack
28
+ // (e.g., trampoline constructs and alike).
29
+ "/NXCOMPAT" . to_string( ) ,
30
+ ] ,
31
+ ..Default :: default ( )
32
+ } ;
33
+
34
+ let mut link_args = LinkArgsMap :: new ( ) ;
35
+ link_args. insert ( LinkerFlavor :: Msvc , new_link_args. clone ( ) ) ;
36
+ link_args. insert ( LinkerFlavor :: Lld ( LldFlavor :: Link ) , new_link_args) ;
19
37
20
38
TargetOptions {
21
39
executables : true ,
@@ -26,7 +44,7 @@ pub fn opts() -> TargetOptions {
26
44
// messages if a link error occurred.
27
45
link_env : vec ! [ ( "VSLANG" . to_string( ) , "1033" . to_string( ) ) ] ,
28
46
lld_flavor : LldFlavor :: Link ,
29
- pre_link_args ,
47
+ link_args ,
30
48
abi_return_struct_as_int : true ,
31
49
emit_debug_gdb_scripts : false ,
32
50
0 commit comments