]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_target/src/spec/windows_gnu_base.rs
New upstream version 1.54.0+dfsg1
[rustc.git] / compiler / rustc_target / src / spec / windows_gnu_base.rs
CommitLineData
f9f354fc 1use crate::spec::crt_objects::{self, CrtObjectsFallback};
3dfed10e 2use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, TargetOptions};
1a4d82fc
JJ
3
4pub fn opts() -> TargetOptions {
cc61c64b 5 let mut pre_link_args = LinkArgs::new();
dfeec247
XL
6 pre_link_args.insert(
7 LinkerFlavor::Gcc,
8 vec![
1a4d82fc
JJ
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(),
fc512014
XL
12 // Enable ASLR
13 "-Wl,--dynamicbase".to_string(),
14 // ASLR will rebase it anyway so leaving that option enabled only leads to confusion
15 "-Wl,--disable-auto-image-base".to_string(),
dfeec247
XL
16 ],
17 );
cc61c64b
XL
18
19 let mut late_link_args = LinkArgs::new();
ba9703b0
XL
20 let mut late_link_args_dynamic = LinkArgs::new();
21 let mut late_link_args_static = LinkArgs::new();
f035d41b
XL
22 // Order of `late_link_args*` was found through trial and error to work with various
23 // mingw-w64 versions (not tested on the CI). It's expected to change from time to time.
3dfed10e
XL
24 let mingw_libs = vec![
25 "-lmsvcrt".to_string(),
26 "-lmingwex".to_string(),
27 "-lmingw32".to_string(),
1b1a35ee 28 "-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
3dfed10e
XL
29 // mingw's msvcrt is a weird hybrid import library and static library.
30 // And it seems that the linker fails to use import symbols from msvcrt
31 // that are required from functions in msvcrt in certain cases. For example
32 // `_fmode` that is used by an implementation of `__p__fmode` in x86_64.
33 // The library is purposely listed twice to fix that.
34 //
35 // See https://github.com/rust-lang/rust/pull/47483 for some more details.
36 "-lmsvcrt".to_string(),
37 "-luser32".to_string(),
38 "-lkernel32".to_string(),
39 ];
40 late_link_args.insert(LinkerFlavor::Gcc, mingw_libs.clone());
41 late_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), mingw_libs);
42 let dynamic_unwind_libs = vec![
43 // If any of our crates are dynamically linked then we need to use
44 // the shared libgcc_s-dw2-1.dll. This is required to support
45 // unwinding across DLL boundaries.
46 "-lgcc_s".to_string(),
3dfed10e
XL
47 ];
48 late_link_args_dynamic.insert(LinkerFlavor::Gcc, dynamic_unwind_libs.clone());
49 late_link_args_dynamic.insert(LinkerFlavor::Lld(LldFlavor::Ld), dynamic_unwind_libs);
50 let static_unwind_libs = vec![
51 // If all of our crates are statically linked then we can get away
52 // with statically linking the libgcc unwinding code. This allows
53 // binaries to be redistributed without the libgcc_s-dw2-1.dll
54 // dependency, but unfortunately break unwinding across DLL
55 // boundaries when unwinding across FFI boundaries.
56 "-lgcc_eh".to_string(),
57 "-l:libpthread.a".to_string(),
3dfed10e
XL
58 ];
59 late_link_args_static.insert(LinkerFlavor::Gcc, static_unwind_libs.clone());
60 late_link_args_static.insert(LinkerFlavor::Lld(LldFlavor::Ld), static_unwind_libs);
cc61c64b
XL
61
62 TargetOptions {
29967ef6
XL
63 os: "windows".to_string(),
64 env: "gnu".to_string(),
65 vendor: "pc".to_string(),
cc61c64b
XL
66 // FIXME(#13846) this should be enabled for windows
67 function_sections: false,
0531ce1d 68 linker: Some("gcc".to_string()),
cc61c64b
XL
69 dynamic_linking: true,
70 executables: true,
b7449926 71 dll_prefix: String::new(),
cc61c64b
XL
72 dll_suffix: ".dll".to_string(),
73 exe_suffix: ".exe".to_string(),
17df50a5 74 families: vec!["windows".to_string()],
cc61c64b
XL
75 is_like_windows: true,
76 allows_weak_linkage: false,
3b2f2976 77 pre_link_args,
f9f354fc
XL
78 pre_link_objects: crt_objects::pre_mingw(),
79 post_link_objects: crt_objects::post_mingw(),
80 pre_link_objects_fallback: crt_objects::pre_mingw_fallback(),
81 post_link_objects_fallback: crt_objects::post_mingw_fallback(),
82 crt_objects_fallback: Some(CrtObjectsFallback::Mingw),
3b2f2976 83 late_link_args,
ba9703b0
XL
84 late_link_args_dynamic,
85 late_link_args_static,
0531ce1d 86 abi_return_struct_as_int: true,
83c7162d
XL
87 emit_debug_gdb_scripts: false,
88 requires_uwtable: true,
f9652781 89 eh_frame_header: false,
1a4d82fc 90
dfeec247 91 ..Default::default()
1a4d82fc
JJ
92 }
93}