1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use target::TargetOptions;
12 use std::default::Default;
14 pub fn opts() -> TargetOptions {
16 // FIXME(#13846) this should be enabled for windows
17 function_sections: false,
18 linker: "gcc".to_string(),
19 dynamic_linking: true,
21 dll_prefix: "".to_string(),
22 dll_suffix: ".dll".to_string(),
23 exe_suffix: ".exe".to_string(),
24 staticlib_prefix: "".to_string(),
25 staticlib_suffix: ".lib".to_string(),
26 no_default_libraries: true,
27 is_like_windows: true,
29 // And here, we see obscure linker flags #45. On windows, it has been
30 // found to be necessary to have this flag to compile liblibc.
32 // First a bit of background. On Windows, the file format is not ELF,
33 // but COFF (at least according to LLVM). COFF doesn't officially allow
34 // for section names over 8 characters, apparently. Our metadata
35 // section, ".note.rustc", you'll note is over 8 characters.
37 // On more recent versions of gcc on mingw, apparently the section name
38 // is *not* truncated, but rather stored elsewhere in a separate lookup
39 // table. On older versions of gcc, they apparently always truncated th
40 // section names (at least in some cases). Truncating the section name
41 // actually creates "invalid" objects [1] [2], but only for some
42 // introspection tools, not in terms of whether it can be loaded.
44 // Long story short, passing this flag forces the linker to *not*
45 // truncate section names (so we can find the metadata section after
46 // it's compiled). The real kicker is that rust compiled just fine on
47 // windows for quite a long time *without* this flag, so I have no idea
48 // why it suddenly started failing for liblibc. Regardless, we
49 // definitely don't want section name truncation, so we're keeping this
52 // [1] - https://sourceware.org/bugzilla/show_bug.cgi?id=13130
53 // [2] - https://code.google.com/p/go/issues/detail?id=2139
54 "-Wl,--enable-long-section-names".to_string(),
56 // Tell GCC to avoid linker plugins, because we are not bundling
57 // them with Windows installer, and Rust does its own LTO anyways.
58 "-fno-use-linker-plugin".to_string(),
60 // Always enable DEP (NX bit) when it is available
61 "-Wl,--nxcompat".to_string(),
63 // Do not use the standard system startup files or libraries when linking
64 "-nostdlib".to_string(),
66 pre_link_objects_exe: vec!(
67 "crt2.o".to_string(), // mingw C runtime initialization for executables
68 "rsbegin.o".to_string(), // Rust compiler runtime initialization, see rsbegin.rs
70 pre_link_objects_dll: vec!(
71 "dllcrt2.o".to_string(), // mingw C runtime initialization for dlls
72 "rsbegin.o".to_string(),
75 "-lmingwex".to_string(),
76 "-lmingw32".to_string(),
77 "-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
78 "-lmsvcrt".to_string(),
79 "-luser32".to_string(),
80 "-lkernel32".to_string(),
82 post_link_objects: vec!(
85 custom_unwind_resume: true,