]> git.proxmox.com Git - rustc.git/blame - src/librustc_target/spec/windows_base.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_target / spec / windows_base.rs
CommitLineData
9fa01778 1use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
1a4d82fc
JJ
2use std::default::Default;
3
4pub fn opts() -> TargetOptions {
cc61c64b
XL
5 let mut pre_link_args = LinkArgs::new();
6 pre_link_args.insert(LinkerFlavor::Gcc, vec![
1a4d82fc
JJ
7 // Tell GCC to avoid linker plugins, because we are not bundling
8 // them with Windows installer, and Rust does its own LTO anyways.
9 "-fno-use-linker-plugin".to_string(),
10
11 // Always enable DEP (NX bit) when it is available
12 "-Wl,--nxcompat".to_string(),
92a42be0
SL
13
14 // Do not use the standard system startup files or libraries when linking
15 "-nostdlib".to_string(),
cc61c64b
XL
16 ]);
17
18 let mut late_link_args = LinkArgs::new();
19 late_link_args.insert(LinkerFlavor::Gcc, vec![
20 "-lmingwex".to_string(),
21 "-lmingw32".to_string(),
22 "-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
23 "-lmsvcrt".to_string(),
2c00a5a8
XL
24 // mingw's msvcrt is a weird hybrid import library and static library.
25 // And it seems that the linker fails to use import symbols from msvcrt
26 // that are required from functions in msvcrt in certain cases. For example
27 // `_fmode` that is used by an implementation of `__p__fmode` in x86_64.
28 // Listing the library twice seems to fix that, and seems to also be done
29 // by mingw's gcc (Though not sure if it's done on purpose, or by mistake).
30 //
31 // See https://github.com/rust-lang/rust/pull/47483
32 "-lmsvcrt".to_string(),
cc61c64b
XL
33 "-luser32".to_string(),
34 "-lkernel32".to_string(),
35 ]);
36
37 TargetOptions {
38 // FIXME(#13846) this should be enabled for windows
39 function_sections: false,
0531ce1d 40 linker: Some("gcc".to_string()),
cc61c64b
XL
41 dynamic_linking: true,
42 executables: true,
b7449926 43 dll_prefix: String::new(),
cc61c64b
XL
44 dll_suffix: ".dll".to_string(),
45 exe_suffix: ".exe".to_string(),
b7449926 46 staticlib_prefix: String::new(),
cc61c64b
XL
47 staticlib_suffix: ".lib".to_string(),
48 no_default_libraries: true,
49 target_family: Some("windows".to_string()),
50 is_like_windows: true,
51 allows_weak_linkage: false,
3b2f2976 52 pre_link_args,
c30ab7b3 53 pre_link_objects_exe: vec![
92a42be0
SL
54 "crt2.o".to_string(), // mingw C runtime initialization for executables
55 "rsbegin.o".to_string(), // Rust compiler runtime initialization, see rsbegin.rs
c30ab7b3
SL
56 ],
57 pre_link_objects_dll: vec![
92a42be0
SL
58 "dllcrt2.o".to_string(), // mingw C runtime initialization for dlls
59 "rsbegin.o".to_string(),
c30ab7b3 60 ],
3b2f2976 61 late_link_args,
c30ab7b3 62 post_link_objects: vec![
92a42be0 63 "rsend.o".to_string()
c30ab7b3 64 ],
92a42be0 65 custom_unwind_resume: true,
0531ce1d 66 abi_return_struct_as_int: true,
83c7162d
XL
67 emit_debug_gdb_scripts: false,
68 requires_uwtable: true,
1a4d82fc
JJ
69
70 .. Default::default()
71 }
72}