Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM upgrade #34743

Merged
merged 33 commits into from
Aug 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d22a9a2
Upgrade to rust-llvm-2016-07-09
badboy Jul 12, 2016
7420874
[LLVM-3.9] Rename custom methods to Rust-specific ones
badboy Jul 12, 2016
fba1f8f
[LLVM-3.9] Setup the compile unit information immediately
badboy Jul 12, 2016
6ed5db8
[LLVM-3.9] Specify that we are using the legacy interface
badboy Jul 12, 2016
5b44e10
[LLVM-3.9] Preserve certain functions when internalizing
badboy Jul 12, 2016
8433f9b
[LLVM-3.9] Replace NewArchiveIterator with NewArchiveMember
badboy Jul 13, 2016
dbb4178
[LLVM-3.9] Update return type for Archive::create
badboy Jul 13, 2016
9e706f9
[LLVM-3.9] Configure PIE at the module level instead of compilation u…
badboy Jul 12, 2016
12ccff9
Use relative path to type
badboy Jul 14, 2016
deafab1
[LLVM-3.9] Increase PIELevel
badboy Jul 14, 2016
1bc0447
[LLVM-3.9] Maintain backward compatibility in Archiver
badboy Jul 14, 2016
1798c1a
Refactor determining of relocation model into methods
badboy Jul 14, 2016
2bcb2b8
Upgrade LLVM to include std::thread patch
badboy Jul 16, 2016
d0e5aa4
Upgrade compiler-rt
badboy Jul 16, 2016
f439aee
[LLVM-3.9] Use old way of getting next child
badboy Jul 16, 2016
09c3f33
Flip LLVM verion check clause
badboy Jul 16, 2016
ad262d5
Update compiler-rt
badboy Jul 21, 2016
2c92756
Upgrade llvm
badboy Jul 21, 2016
dc7076b
[LLVM-3.9] Pass correct relocation model flag
badboy Jul 21, 2016
079db4f
Use correct error handling type
badboy Jul 21, 2016
2c16e24
Use C type when passing value to LLVM pass
badboy Jul 24, 2016
a36595e
Force check of error
badboy Jul 24, 2016
d851428
configure: Fix grep invocation for llvm-mc argument
alexcrichton Jul 25, 2016
e8f7666
rustc: Fix data-layout for AArch64 targets
alexcrichton Jul 25, 2016
5fa5578
test: Remove the execution-engine test
alexcrichton Jul 25, 2016
75bcda4
rustc: Update LLVM to the LLVM 3.9 release branch
alexcrichton Jul 25, 2016
0509be1
Update parsing llvm-config output
alexcrichton Jul 25, 2016
2492d24
llvm: Remove no longer existent LLVMAddTargetData binding
alexcrichton Jul 26, 2016
330dd39
Remove NO_FILE_METADATA; always use unknown_file_metadata instead of …
vvuk Jul 7, 2016
f38762a
[LLVM-3.9] Use llvm-3.9 branch
badboy Jul 26, 2016
5243072
test: Fix a test on MSVC
alexcrichton Jul 26, 2016
7c0cd30
Update LLVM again
badboy Jul 29, 2016
5d1d247
Upgrade LLVM once more to get a bugfix
badboy Aug 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,12 @@ then
err "bad LLVM version: $LLVM_VERSION, need >=3.7"
;;
esac

if "$CFG_LLVM_ROOT/bin/llvm-mc" -help | grep -- "-relocation-model"; then
msg "found older llvm-mc"
CFG_LLVM_MC_HAS_RELOCATION_MODEL=1
putvar CFG_LLVM_MC_HAS_RELOCATION_MODEL
fi
fi

# Even when the user overrides the choice of CC, still try to detect
Expand Down
9 changes: 8 additions & 1 deletion mk/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,19 @@ define CFG_MAKE_TOOLCHAIN
LLVM_MC_RELOCATION_MODEL="default"
endif

# LLVM changed this flag in 3.9
ifdef CFG_LLVM_MC_HAS_RELOCATION_MODEL
LLVM_MC_RELOC_FLAG := -relocation-model=$$(LLVM_MC_RELOCATION_MODEL)
else
LLVM_MC_RELOC_FLAG := -position-independent
endif

# We're using llvm-mc as our assembler because it supports
# .cfi pseudo-ops on mac
CFG_ASSEMBLE_$(1)=$$(CPP_$(1)) -E $$(2) | \
$$(LLVM_MC_$$(CFG_BUILD)) \
-assemble \
-relocation-model=$$(LLVM_MC_RELOCATION_MODEL) \
$$(LLVM_MC_RELOC_FLAG) \
-filetype=obj \
-triple=$(1) \
-o=$$(1)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler-rt
Submodule compiler-rt updated 691 files
7 changes: 7 additions & 0 deletions src/etc/mklldeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ def runErr(args):
lib = lib.strip()[2:]
elif lib[0] == '-':
lib = lib.strip()[1:]
# If this actually points at a literal file then we're on MSVC which now
# prints full paths, so get just the name of the library and strip off the
# trailing ".lib"
elif os.path.exists(lib):
lib = os.path.basename(lib)[:-4]
elif lib[-4:] == '.lib':
lib = lib[:-4]
f.write("#[link(name = \"" + lib + "\"")
if not llvm_shared and 'LLVM' in lib:
f.write(", kind = \"static\"")
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/aarch64_linux_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn target() -> Target {
llvm_target: "aarch64-linux-android".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
data_layout: "e-m:e-i64:64-i128:128-n32:64-S128".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "android".to_string(),
target_env: "".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/aarch64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn target() -> Target {
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
target_env: "gnu".to_string(),
data_layout: "e-m:e-i64:64-i128:128-n32:64-S128".to_string(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "linux".to_string(),
target_vendor: "unknown".to_string(),
Expand Down
19 changes: 15 additions & 4 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern crate build_helper;

use std::process::Command;
use std::env;
use std::path::PathBuf;
use std::path::{PathBuf, Path};

use build_helper::output;

Expand Down Expand Up @@ -135,8 +135,17 @@ fn main() {
&lib[2..]
} else if lib.starts_with("-") {
&lib[1..]
} else if Path::new(lib).exists() {
// On MSVC llvm-config will print the full name to libraries, but
// we're only interested in the name part
let name = Path::new(lib).file_name().unwrap().to_str().unwrap();
name.trim_right_matches(".lib")
} else if lib.ends_with(".lib") {
// Some MSVC libraries just come up with `.lib` tacked on, so chop
// that off
lib.trim_right_matches(".lib")
} else {
continue;
continue
};

// Don't need or want this library, but LLVM's CMake build system
Expand All @@ -145,7 +154,7 @@ fn main() {
// library and it otherwise may just pull in extra dependencies on
// libedit which we don't want
if name == "LLVMLineEditor" {
continue;
continue
}

let kind = if name.starts_with("LLVM") {
Expand All @@ -165,7 +174,9 @@ fn main() {
let mut cmd = Command::new(&llvm_config);
cmd.arg("--ldflags");
for lib in output(&mut cmd).split_whitespace() {
if is_crossed {
if lib.starts_with("-LIBPATH:") {
println!("cargo:rustc-link-search=native={}", &lib[9..]);
} else if is_crossed {
if lib.starts_with("-L") {
println!("cargo:rustc-link-search=native={}",
lib[2..].replace(&host, &target));
Expand Down
10 changes: 4 additions & 6 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl Attributes {

pub fn apply_callsite(&self, idx: usize, callsite: ValueRef) {
unsafe {
LLVMAddCallSiteAttribute(callsite, idx as c_uint, self.regular.bits());
LLVMRustAddCallSiteAttribute(callsite, idx as c_uint, self.regular.bits());
if self.dereferenceable_bytes != 0 {
LLVMAddDereferenceableCallSiteAttr(callsite, idx as c_uint,
self.dereferenceable_bytes);
Expand Down Expand Up @@ -1056,7 +1056,7 @@ extern {
pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
index: c_uint,
align: c_uint);
pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef,
index: c_uint,
Val: uint64_t);
pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
Expand Down Expand Up @@ -1561,7 +1561,7 @@ extern {
Alignment: c_uint)
-> ValueRef;

pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
pub fn LLVMRustBuildAtomicCmpXchg(B: BuilderRef,
LHS: ValueRef,
CMP: ValueRef,
RHS: ValueRef,
Expand Down Expand Up @@ -1591,9 +1591,6 @@ extern {

/// Creates target data from a target layout string.
pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
/// Adds the target data to the given pass manager. The pass manager
/// references the target data only weakly.
pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
/// Number of bytes clobbered when doing a Store to *T.
pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
-> c_ulonglong;
Expand Down Expand Up @@ -2155,6 +2152,7 @@ extern {

pub fn LLVMRustSetComdat(M: ModuleRef, V: ValueRef, Name: *const c_char);
pub fn LLVMRustUnsetComdat(V: ValueRef);
pub fn LLVMRustSetModulePIELevel(M: ModuleRef);
}

// LLVM requires symbols from this library, but apparently they're not printed
Expand Down
26 changes: 3 additions & 23 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use util::fs::link_or_copy;
use errors::{self, Handler, Level, DiagnosticBuilder};
use errors::emitter::Emitter;
use syntax_pos::MultiSpan;
use context::{is_pie_binary, get_reloc_model};

use std::collections::HashMap;
use std::ffi::{CStr, CString};
Expand Down Expand Up @@ -154,32 +155,11 @@ fn get_llvm_opt_size(optimize: config::OptLevel) -> llvm::CodeGenOptSize {
}

pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
let reloc_model_arg = match sess.opts.cg.relocation_model {
Some(ref s) => &s[..],
None => &sess.target.target.options.relocation_model[..],
};
let reloc_model = match reloc_model_arg {
"pic" => llvm::RelocPIC,
"static" => llvm::RelocStatic,
"default" => llvm::RelocDefault,
"dynamic-no-pic" => llvm::RelocDynamicNoPic,
_ => {
sess.err(&format!("{:?} is not a valid relocation mode",
sess.opts
.cg
.relocation_model));
sess.abort_if_errors();
bug!();
}
};
let reloc_model = get_reloc_model(sess);

let opt_level = get_llvm_opt_level(sess.opts.optimize);
let use_softfp = sess.opts.cg.soft_float;

let any_library = sess.crate_types.borrow().iter().any(|ty| {
*ty != config::CrateTypeExecutable
});

let ffunction_sections = sess.target.target.options.function_sections;
let fdata_sections = ffunction_sections;

Expand Down Expand Up @@ -220,7 +200,7 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
reloc_model,
opt_level,
use_softfp,
!any_library && reloc_model == llvm::RelocPIC,
is_pie_binary(sess),
ffunction_sections,
fdata_sections,
)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
failure_order: AtomicOrdering,
weak: llvm::Bool) -> ValueRef {
unsafe {
llvm::LLVMBuildAtomicCmpXchg(self.llbuilder, dst, cmp, src,
llvm::LLVMRustBuildAtomicCmpXchg(self.llbuilder, dst, cmp, src,
order, failure_order, weak)
}
}
Expand Down
62 changes: 60 additions & 2 deletions src/librustc_trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use rustc::ty::subst::{Substs, VecPerParamSpace};
use rustc::ty::{self, Ty, TyCtxt};
use session::config::NoDebugInfo;
use session::Session;
use session::config;
use symbol_map::SymbolMap;
use util::sha2::Sha256;
use util::nodemap::{NodeMap, NodeSet, DefIdMap, FnvHashMap, FnvHashSet};
Expand Down Expand Up @@ -322,6 +323,38 @@ impl<'a, 'tcx> Iterator for CrateContextMaybeIterator<'a, 'tcx> {
}
}

pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
let reloc_model_arg = match sess.opts.cg.relocation_model {
Some(ref s) => &s[..],
None => &sess.target.target.options.relocation_model[..],
};

match reloc_model_arg {
"pic" => llvm::RelocPIC,
"static" => llvm::RelocStatic,
"default" => llvm::RelocDefault,
"dynamic-no-pic" => llvm::RelocDynamicNoPic,
_ => {
sess.err(&format!("{:?} is not a valid relocation mode",
sess.opts
.cg
.relocation_model));
sess.abort_if_errors();
bug!();
}
}
}

fn is_any_library(sess: &Session) -> bool {
sess.crate_types.borrow().iter().any(|ty| {
*ty != config::CrateTypeExecutable
})
}

pub fn is_pie_binary(sess: &Session) -> bool {
!is_any_library(sess) && get_reloc_model(sess) == llvm::RelocPIC
}

unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) {
let llcx = llvm::LLVMContextCreate();
let mod_name = CString::new(mod_name).unwrap();
Expand All @@ -337,7 +370,25 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
let data_layout = str::from_utf8(CStr::from_ptr(data_layout).to_bytes())
.ok().expect("got a non-UTF8 data-layout from LLVM");

if sess.target.target.data_layout != data_layout {
// Unfortunately LLVM target specs change over time, and right now we
// don't have proper support to work with any more than one
// `data_layout` than the one that is in the rust-lang/rust repo. If
// this compiler is configured against a custom LLVM, we may have a
// differing data layout, even though we should update our own to use
// that one.
//
// As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
// disable this check entirely as we may be configured with something
// that has a different target layout.
//
// Unsure if this will actually cause breakage when rustc is configured
// as such.
//
// FIXME(#34960)
let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
let custom_llvm_used = cfg_llvm_root.trim() != "";

if !custom_llvm_used && sess.target.target.data_layout != data_layout {
bug!("data-layout for builtin `{}` target, `{}`, \
differs from LLVM default, `{}`",
sess.target.target.llvm_target,
Expand All @@ -352,6 +403,11 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
let llvm_target = sess.target.target.llvm_target.as_bytes();
let llvm_target = CString::new(llvm_target).unwrap();
llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());

if is_pie_binary(sess) {
llvm::LLVMRustSetModulePIELevel(llmod);
Copy link
Member

@eddyb eddyb Jul 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to set the PICLevel too, even if the relocation model is PIC.
One potentially related failure is:

note: ld: illegal text-relocation to '_panic_loc21555' in i686-apple-darwin/stage1/lib/rustlib/i686-apple-darwin/lib/std-f53fb285.0.o from '__ZN103_$LT$core..slice..RSplitN$LT$$u27$a$C$$u20$T$C$$u20$P$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$4next17he6277dfc64030327E' in i686-apple-darwin/stage1/lib/rustlib/i686-apple-darwin/lib/std-f53fb285.0.o for architecture i386

EDIT: Not that it would help, given how it's only used in PowerPC.

}

(llcx, llmod)
}

Expand Down Expand Up @@ -558,7 +614,9 @@ impl<'tcx> LocalCrateContext<'tcx> {
&llmod_id[..]);

let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo {
Some(debuginfo::CrateDebugContext::new(llmod))
let dctx = debuginfo::CrateDebugContext::new(llmod);
debuginfo::metadata::compile_unit_metadata(shared, &dctx, shared.tcx.sess);
Some(dctx)
} else {
None
};
Expand Down
Loading