]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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. | |
4 | // | |
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. | |
10 | ||
11 | use target::TargetOptions; | |
12 | use std::default::Default; | |
13 | ||
14 | pub fn opts() -> TargetOptions { | |
15 | TargetOptions { | |
16 | // FIXME(#13846) this should be enabled for windows | |
17 | function_sections: false, | |
18 | linker: "gcc".to_string(), | |
19 | dynamic_linking: true, | |
20 | executables: 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 | morestack: false, | |
27 | is_like_windows: true, | |
c1a9b12d | 28 | archive_format: "gnu".to_string(), |
1a4d82fc JJ |
29 | pre_link_args: vec!( |
30 | // And here, we see obscure linker flags #45. On windows, it has been | |
31 | // found to be necessary to have this flag to compile liblibc. | |
32 | // | |
33 | // First a bit of background. On Windows, the file format is not ELF, | |
34 | // but COFF (at least according to LLVM). COFF doesn't officially allow | |
35 | // for section names over 8 characters, apparently. Our metadata | |
36 | // section, ".note.rustc", you'll note is over 8 characters. | |
37 | // | |
38 | // On more recent versions of gcc on mingw, apparently the section name | |
39 | // is *not* truncated, but rather stored elsewhere in a separate lookup | |
40 | // table. On older versions of gcc, they apparently always truncated th | |
41 | // section names (at least in some cases). Truncating the section name | |
42 | // actually creates "invalid" objects [1] [2], but only for some | |
43 | // introspection tools, not in terms of whether it can be loaded. | |
44 | // | |
45 | // Long story short, passing this flag forces the linker to *not* | |
46 | // truncate section names (so we can find the metadata section after | |
47 | // it's compiled). The real kicker is that rust compiled just fine on | |
48 | // windows for quite a long time *without* this flag, so I have no idea | |
49 | // why it suddenly started failing for liblibc. Regardless, we | |
50 | // definitely don't want section name truncation, so we're keeping this | |
51 | // flag for windows. | |
52 | // | |
53 | // [1] - https://sourceware.org/bugzilla/show_bug.cgi?id=13130 | |
54 | // [2] - https://code.google.com/p/go/issues/detail?id=2139 | |
55 | "-Wl,--enable-long-section-names".to_string(), | |
56 | ||
57 | // Tell GCC to avoid linker plugins, because we are not bundling | |
58 | // them with Windows installer, and Rust does its own LTO anyways. | |
59 | "-fno-use-linker-plugin".to_string(), | |
60 | ||
61 | // Always enable DEP (NX bit) when it is available | |
62 | "-Wl,--nxcompat".to_string(), | |
63 | ), | |
64 | ||
65 | .. Default::default() | |
66 | } | |
67 | } |