rustc_target/spec/base/
windows_gnullvm.rs

1use std::borrow::Cow;
2
3use crate::spec::crt_objects::pre_mingw_self_contained;
4use crate::spec::{
5    Abi, BinaryFormat, Cc, DebuginfoKind, Env, LinkSelfContainedDefault, LinkerFlavor, Lld, Os,
6    SplitDebuginfo, TargetOptions, add_link_args, cvs,
7};
8
9pub(crate) fn opts() -> TargetOptions {
10    // We cannot use `-nodefaultlibs` because compiler-rt has to be passed
11    // as a path since it's not added to linker search path by the default.
12    // There were attempts to make it behave like libgcc (so one can just use -l<name>)
13    // but LLVM maintainers rejected it: https://reviews.llvm.org/D51440
14    let pre_link_args = TargetOptions::link_args(
15        LinkerFlavor::Gnu(Cc::Yes, Lld::No),
16        &["-nolibc", "--unwindlib=none"],
17    );
18    // Order of `late_link_args*` does not matter with LLD.
19    let mingw_libs = &["-lmingw32", "-lmingwex", "-lmsvcrt", "-lkernel32", "-luser32"];
20
21    let mut late_link_args =
22        TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), mingw_libs);
23    add_link_args(&mut late_link_args, LinkerFlavor::Gnu(Cc::Yes, Lld::No), mingw_libs);
24
25    TargetOptions {
26        os: Os::Windows,
27        env: Env::Gnu,
28        vendor: "pc".into(),
29        abi: Abi::Llvm,
30        linker: Some("clang".into()),
31        dynamic_linking: true,
32        dll_tls_export: false,
33        dll_prefix: "".into(),
34        dll_suffix: ".dll".into(),
35        exe_suffix: ".exe".into(),
36        families: cvs!["windows"],
37        is_like_windows: true,
38        binary_format: BinaryFormat::Coff,
39        allows_weak_linkage: false,
40        pre_link_args,
41        pre_link_objects_self_contained: pre_mingw_self_contained(),
42        link_self_contained: LinkSelfContainedDefault::InferredForMingw,
43        late_link_args,
44        abi_return_struct_as_int: true,
45        emit_debug_gdb_scripts: false,
46        requires_uwtable: true,
47        eh_frame_header: false,
48        no_default_libraries: false,
49        has_thread_local: true,
50        crt_static_allows_dylibs: true,
51        crt_static_respected: true,
52        debuginfo_kind: DebuginfoKind::Dwarf,
53        // FIXME(davidtwco): Support Split DWARF on Windows GNU - may require LLVM changes to
54        // output DWO, despite using DWARF, doesn't use ELF..
55        supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
56        ..Default::default()
57    }
58}