1 use crate::spec::crt_objects::{self, LinkSelfContainedDefault};
2 use crate::spec::{cvs, DebuginfoKind, LinkerFlavor, SplitDebuginfo, TargetOptions};
5 pub fn opts() -> TargetOptions {
6 let mut pre_link_args = TargetOptions::link_args(
11 // ASLR will rebase it anyway so leaving that option enabled only leads to confusion
12 "--disable-auto-image-base",
19 // Tell GCC to avoid linker plugins, because we are not bundling
20 // them with Windows installer, and Rust does its own LTO anyways.
21 "-fno-use-linker-plugin",
23 "-Wl,--disable-auto-image-base",
27 // Order of `late_link_args*` was found through trial and error to work with various
28 // mingw-w64 versions (not tested on the CI). It's expected to change from time to time.
33 "-lgcc", // alas, mingw* libraries above depend on libgcc
34 // mingw's msvcrt is a weird hybrid import library and static library.
35 // And it seems that the linker fails to use import symbols from msvcrt
36 // that are required from functions in msvcrt in certain cases. For example
37 // `_fmode` that is used by an implementation of `__p__fmode` in x86_64.
38 // The library is purposely listed twice to fix that.
40 // See https://github.com/rust-lang/rust/pull/47483 for some more details.
45 let mut late_link_args = TargetOptions::link_args(LinkerFlavor::Ld, mingw_libs);
46 super::add_link_args(&mut late_link_args, LinkerFlavor::Gcc, mingw_libs);
47 // If any of our crates are dynamically linked then we need to use
48 // the shared libgcc_s-dw2-1.dll. This is required to support
49 // unwinding across DLL boundaries.
50 let dynamic_unwind_libs = &["-lgcc_s"];
51 let mut late_link_args_dynamic =
52 TargetOptions::link_args(LinkerFlavor::Ld, dynamic_unwind_libs);
53 super::add_link_args(&mut late_link_args_dynamic, LinkerFlavor::Gcc, dynamic_unwind_libs);
54 // If all of our crates are statically linked then we can get away
55 // with statically linking the libgcc unwinding code. This allows
56 // binaries to be redistributed without the libgcc_s-dw2-1.dll
57 // dependency, but unfortunately break unwinding across DLL
58 // boundaries when unwinding across FFI boundaries.
59 let static_unwind_libs = &["-lgcc_eh", "-l:libpthread.a"];
60 let mut late_link_args_static = TargetOptions::link_args(LinkerFlavor::Ld, static_unwind_libs);
61 super::add_link_args(&mut late_link_args_static, LinkerFlavor::Gcc, static_unwind_libs);
67 // FIXME(#13846) this should be enabled for windows
68 function_sections: false,
69 linker: Some("gcc".into()),
70 dynamic_linking: true,
71 dll_prefix: "".into(),
72 dll_suffix: ".dll".into(),
73 exe_suffix: ".exe".into(),
74 families: cvs!["windows"],
75 is_like_windows: true,
76 allows_weak_linkage: false,
78 pre_link_objects: crt_objects::pre_mingw(),
79 post_link_objects: crt_objects::post_mingw(),
80 pre_link_objects_self_contained: crt_objects::pre_mingw_self_contained(),
81 post_link_objects_self_contained: crt_objects::post_mingw_self_contained(),
82 link_self_contained: LinkSelfContainedDefault::Mingw,
84 late_link_args_dynamic,
85 late_link_args_static,
86 abi_return_struct_as_int: true,
87 emit_debug_gdb_scripts: false,
88 requires_uwtable: true,
89 eh_frame_header: false,
90 // FIXME(davidtwco): Support Split DWARF on Windows GNU - may require LLVM changes to
91 // output DWO, despite using DWARF, doesn't use ELF..
92 debuginfo_kind: DebuginfoKind::Pdb,
93 supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),