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