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