]>
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(), | |
92a42be0 | 26 | no_default_libraries: true, |
1a4d82fc | 27 | is_like_windows: true, |
5bcae85e | 28 | allows_weak_linkage: false, |
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(), | |
92a42be0 SL |
63 | |
64 | // Do not use the standard system startup files or libraries when linking | |
65 | "-nostdlib".to_string(), | |
66 | ), | |
67 | pre_link_objects_exe: vec!( | |
68 | "crt2.o".to_string(), // mingw C runtime initialization for executables | |
69 | "rsbegin.o".to_string(), // Rust compiler runtime initialization, see rsbegin.rs | |
70 | ), | |
71 | pre_link_objects_dll: vec!( | |
72 | "dllcrt2.o".to_string(), // mingw C runtime initialization for dlls | |
73 | "rsbegin.o".to_string(), | |
74 | ), | |
75 | late_link_args: vec!( | |
76 | "-lmingwex".to_string(), | |
77 | "-lmingw32".to_string(), | |
78 | "-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc | |
79 | "-lmsvcrt".to_string(), | |
80 | "-luser32".to_string(), | |
81 | "-lkernel32".to_string(), | |
82 | ), | |
83 | post_link_objects: vec!( | |
84 | "rsend.o".to_string() | |
1a4d82fc | 85 | ), |
92a42be0 | 86 | custom_unwind_resume: true, |
1a4d82fc JJ |
87 | |
88 | .. Default::default() | |
89 | } | |
90 | } |