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

Fix building on ARM #32503

Merged
merged 2 commits into from
Mar 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 1 addition & 6 deletions src/bootstrap/build/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ pub fn llvm(build: &Build, target: &str) {

let _ = fs::remove_dir_all(&dst.join("build"));
t!(fs::create_dir_all(&dst.join("build")));
let mut assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};

// Disable LLVM assertions on ARM compilers until #32360 is fixed
if target.contains("arm") && target.contains("gnu") {
assertions = "OFF";
}
let assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};

// http://llvm.org/docs/CMake.html
let mut cfg = cmake::Config::new(build.src.join("src/llvm"));
Expand Down
12 changes: 10 additions & 2 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,10 @@ extern {
pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
Name: *const c_char,
Value: *const c_char);
pub fn LLVMRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: uint64_t);
Copy link
Contributor

Choose a reason for hiding this comment

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

how come attr doens't need to be c_ulonglong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The C side uses uint64_t not unsigned long long.

pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_uint;
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_uint);
Copy link
Member

Choose a reason for hiding this comment

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

Ouch, #17795 strikes again!

Copy link
Member

Choose a reason for hiding this comment

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

@alexcrichton would it be possible to use ctest to check the validity of these LLVM bindings?

Copy link
Member

Choose a reason for hiding this comment

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

In theory yeah, but may be nontrivial to integrate


/* Operations on parameters */
pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
Expand Down Expand Up @@ -2184,6 +2185,13 @@ pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
}
}

pub fn RemoveFunctionAttributes(fn_: ValueRef, attr: Attribute) {
unsafe {
LLVMRemoveFunctionAttributes(fn_, FunctionIndex as c_uint,
attr.bits() as uint64_t)
}
}

/* Memory-managed interface to target data. */

pub struct TargetData {
Expand Down
31 changes: 6 additions & 25 deletions src/librustc_trans/trans/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.
//! Set and unset common attributes on LLVM values.

use libc::{c_uint, c_ulonglong};
use libc::c_uint;
use llvm::{self, ValueRef};
use session::config::NoDebugInfo;
pub use syntax::attr::InlineAttr;
Expand All @@ -28,9 +28,7 @@ pub fn inline(val: ValueRef, inline: InlineAttr) {
let attr = llvm::Attribute::InlineHint |
llvm::Attribute::AlwaysInline |
llvm::Attribute::NoInline;
unsafe {
llvm::LLVMRemoveFunctionAttr(val, attr.bits() as c_ulonglong)
}
llvm::RemoveFunctionAttributes(val, attr)
},
};
}
Expand All @@ -41,25 +39,15 @@ pub fn emit_uwtable(val: ValueRef, emit: bool) {
if emit {
llvm::SetFunctionAttribute(val, llvm::Attribute::UWTable);
} else {
unsafe {
llvm::LLVMRemoveFunctionAttr(
val,
llvm::Attribute::UWTable.bits() as c_ulonglong,
);
}
llvm::RemoveFunctionAttributes(val, llvm::Attribute::UWTable);
}
}

/// Tell LLVM whether the function can or cannot unwind.
#[inline]
pub fn unwind(val: ValueRef, can_unwind: bool) {
if can_unwind {
unsafe {
llvm::LLVMRemoveFunctionAttr(
val,
llvm::Attribute::NoUnwind.bits() as c_ulonglong,
);
}
llvm::RemoveFunctionAttributes(val, llvm::Attribute::NoUnwind);
} else {
llvm::SetFunctionAttribute(val, llvm::Attribute::NoUnwind);
}
Expand All @@ -72,12 +60,7 @@ pub fn set_optimize_for_size(val: ValueRef, optimize: bool) {
if optimize {
llvm::SetFunctionAttribute(val, llvm::Attribute::OptimizeForSize);
} else {
unsafe {
llvm::LLVMRemoveFunctionAttr(
val,
llvm::Attribute::OptimizeForSize.bits() as c_ulonglong,
);
}
llvm::RemoveFunctionAttributes(val, llvm::Attribute::OptimizeForSize);
}
}

Expand All @@ -87,9 +70,7 @@ pub fn naked(val: ValueRef, is_naked: bool) {
if is_naked {
llvm::SetFunctionAttribute(val, llvm::Attribute::Naked);
} else {
unsafe {
llvm::LLVMRemoveFunctionAttr(val, llvm::Attribute::Naked.bits() as c_ulonglong);
}
llvm::RemoveFunctionAttributes(val, llvm::Attribute::Naked);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ extern "C" void LLVMAddFunctionAttrStringValue(LLVMValueRef Fn, unsigned index,
F->addAttributes(index, AttributeSet::get(F->getContext(), index, B));
}

extern "C" void LLVMRemoveFunctionAttributes(LLVMValueRef Fn, unsigned index, uint64_t Val) {
Function *A = unwrap<Function>(Fn);
const AttributeSet PAL = A->getAttributes();
AttrBuilder B(Val);
const AttributeSet PALnew =
PAL.removeAttributes(A->getContext(), index,
AttributeSet::get(A->getContext(), index, B));
A->setAttributes(PALnew);
}

extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, unsigned index, const char *Name) {
Function *f = unwrap<Function>(fn);
LLVMContext &C = f->getContext();
Expand Down