]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/windows_base.rs
Auto merge of #66206 - PotHix:master, r=estebank
[rust.git] / src / librustc_target / spec / windows_base.rs
1 use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
2 use std::default::Default;
3
4 pub fn opts() -> TargetOptions {
5     let mut pre_link_args = LinkArgs::new();
6     pre_link_args.insert(LinkerFlavor::Gcc, vec![
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(),
13
14             // Do not use the standard system startup files or libraries when linking
15             "-nostdlib".to_string(),
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(),
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(),
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,
40         linker: Some("gcc".to_string()),
41         dynamic_linking: true,
42         executables: true,
43         dll_prefix: String::new(),
44         dll_suffix: ".dll".to_string(),
45         exe_suffix: ".exe".to_string(),
46         staticlib_prefix: String::new(),
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,
52         pre_link_args,
53         pre_link_objects_exe: vec![
54             "crt2.o".to_string(),    // mingw C runtime initialization for executables
55             "rsbegin.o".to_string(), // Rust compiler runtime initialization, see rsbegin.rs
56         ],
57         pre_link_objects_dll: vec![
58             "dllcrt2.o".to_string(), // mingw C runtime initialization for dlls
59             "rsbegin.o".to_string(),
60         ],
61         late_link_args,
62         post_link_objects: vec![
63             "rsend.o".to_string()
64         ],
65         custom_unwind_resume: true,
66         abi_return_struct_as_int: true,
67         emit_debug_gdb_scripts: false,
68         requires_uwtable: true,
69
70         .. Default::default()
71     }
72 }