1 use crate::spec::crt_objects::{self, LinkSelfContainedDefault};
2 use crate::spec::{cvs, Cc, DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, TargetOptions};
5 pub fn opts() -> TargetOptions {
6 let mut pre_link_args = TargetOptions::link_args(
7 LinkerFlavor::Gnu(Cc::No, Lld::No),
11 // ASLR will rebase it anyway so leaving that option enabled only leads to confusion
12 "--disable-auto-image-base",
17 LinkerFlavor::Gnu(Cc::Yes, Lld::No),
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 =
46 TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), mingw_libs);
47 super::add_link_args(&mut late_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), mingw_libs);
48 // If any of our crates are dynamically linked then we need to use
49 // the shared libgcc_s-dw2-1.dll. This is required to support
50 // unwinding across DLL boundaries.
51 let dynamic_unwind_libs = &["-lgcc_s"];
52 let mut late_link_args_dynamic =
53 TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), dynamic_unwind_libs);
55 &mut late_link_args_dynamic,
56 LinkerFlavor::Gnu(Cc::Yes, Lld::No),
59 // If all of our crates are statically linked then we can get away
60 // with statically linking the libgcc unwinding code. This allows
61 // binaries to be redistributed without the libgcc_s-dw2-1.dll
62 // dependency, but unfortunately break unwinding across DLL
63 // boundaries when unwinding across FFI boundaries.
64 let static_unwind_libs = &["-lgcc_eh", "-l:libpthread.a"];
65 let mut late_link_args_static =
66 TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), static_unwind_libs);
68 &mut late_link_args_static,
69 LinkerFlavor::Gnu(Cc::Yes, Lld::No),
77 // FIXME(#13846) this should be enabled for windows
78 function_sections: false,
79 linker: Some("gcc".into()),
80 dynamic_linking: true,
81 dll_prefix: "".into(),
82 dll_suffix: ".dll".into(),
83 exe_suffix: ".exe".into(),
84 families: cvs!["windows"],
85 is_like_windows: true,
86 allows_weak_linkage: false,
88 pre_link_objects: crt_objects::pre_mingw(),
89 post_link_objects: crt_objects::post_mingw(),
90 pre_link_objects_self_contained: crt_objects::pre_mingw_self_contained(),
91 post_link_objects_self_contained: crt_objects::post_mingw_self_contained(),
92 link_self_contained: LinkSelfContainedDefault::Mingw,
94 late_link_args_dynamic,
95 late_link_args_static,
96 abi_return_struct_as_int: true,
97 emit_debug_gdb_scripts: false,
98 requires_uwtable: true,
99 eh_frame_header: false,
100 // FIXME(davidtwco): Support Split DWARF on Windows GNU - may require LLVM changes to
101 // output DWO, despite using DWARF, doesn't use ELF..
102 debuginfo_kind: DebuginfoKind::Pdb,
103 supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),