--target'[Target triple cpu-manufacturer-kernel\[-os\] to compile]'
--target-cpu'[Select target processor (llc -mcpu=help for details)]'
--target-feature'[Target specific attributes (llc -mattr=help for details)]'
+ --relocation-model'[Relocation model (llc --help for details)]'
{-v,--version}'[Print version info and exit]'
)
_rustc_opts_lint=(
'attribute-usage[detects bad use of attributes]'
- 'ctypes[proper use of std::libc types in foreign modules]'
+ 'ctypes[proper use of libc types in foreign modules]'
'dead-assignment[detect assignments that will never be read]'
'dead-code[detect piece of code that will never be used]'
'default-type-param-usage[prevents explicitly setting a type parameter with a default]'
use std::c_str::ToCStr;
use std::io::Process;
- use std::libc::{c_uint, c_int};
+ use libc::{c_uint, c_int};
use std::str;
// On android, we by default compile for armv7 processors. This enables
(sess.targ_cfg.os == abi::OsMacos &&
sess.targ_cfg.arch == abi::X86_64);
+ let reloc_model = match sess.opts.cg.relocation_model.as_slice() {
+ "pic" => lib::llvm::RelocPIC,
+ "static" => lib::llvm::RelocStatic,
+ "default" => lib::llvm::RelocDefault,
+ "dynamic-no-pic" => lib::llvm::RelocDynamicNoPic,
+ _ => {
+ sess.err(format!("{} is not a valid relocation mode",
+ sess.opts.cg.relocation_model));
+ sess.abort_if_errors();
+ return;
+ }
+ };
+
let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|t| {
sess.opts.cg.target_cpu.with_c_str(|cpu| {
target_feature(sess).with_c_str(|features| {
llvm::LLVMRustCreateTargetMachine(
t, cpu, features,
lib::llvm::CodeModelDefault,
- lib::llvm::RelocPIC,
+ reloc_model,
opt_level,
true,
use_softfp,
// DWARF stack unwinding will not work.
// This behavior may be overridden by --link-args "-static-libgcc"
args.push(~"-shared-libgcc");
+
+ // And here, we see obscure linker flags #45. On windows, it has been
+ // found to be necessary to have this flag to compile liblibc.
+ //
+ // First a bit of background. On Windows, the file format is not ELF,
+ // but COFF (at least according to LLVM). COFF doesn't officially allow
+ // for section names over 8 characters, apparently. Our metadata
+ // section, ".note.rustc", you'll note is over 8 characters.
+ //
+ // On more recent versions of gcc on mingw, apparently the section name
+ // is *not* truncated, but rather stored elsewhere in a separate lookup
+ // table. On older versions of gcc, they apparently always truncated the
+ // section names (at least in some cases). Truncating the section name
+ // actually creates "invalid" objects [1] [2], but only for some
+ // introspection tools, not in terms of whether it can be loaded.
+ //
+ // Long story shory, passing this flag forces the linker to *not*
+ // truncate section names (so we can find the metadata section after
+ // it's compiled). The real kicker is that rust compiled just fine on
+ // windows for quite a long time *without* this flag, so I have no idea
+ // why it suddenly started failing for liblibc. Regardless, we
+ // definitely don't want section name truncation, so we're keeping this
+ // flag for windows.
+ //
+ // [1] - https://sourceware.org/bugzilla/show_bug.cgi?id=13130
+ // [2] - https://code.google.com/p/go/issues/detail?id=2139
+ args.push(~"-Wl,--enable-long-section-names");
}
if sess.targ_cfg.os == abi::OsAndroid {
pub fn span_end_note(&self, sp: Span, msg: &str) {
self.diagnostic().span_end_note(sp, msg)
}
+ pub fn fileline_note(&self, sp: Span, msg: &str) {
+ self.diagnostic().fileline_note(sp, msg)
+ }
pub fn note(&self, msg: &str) {
self.diagnostic().handler().note(msg)
}
"prefer dynamic linking to static linking"),
no_integrated_as: bool = (false, parse_bool,
"use an external assembler rather than LLVM's integrated one"),
+ relocation_model: ~str = (~"pic", parse_string,
+ "choose the relocation model to use (llc -relocation-model for details)"),
)
// Seems out of place, but it uses session, so I'm putting it here