Skip to content

Commit 3db2b69

Browse files
committed
auto merge of #13628 : alexcrichton/rust/issue-13625, r=thestinger
In upgrading LLVM, only rust functions had the "split-stack" attribute added. This commit changes the addition of LLVM's "split-stack" attribute to *always* occur and then we remove it sometimes if the "no_split_stack" rust attribute is present. Closes #13625
2 parents ba25fec + 50fb57b commit 3db2b69

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/librustc/lib/llvm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ pub mod llvm {
709709
pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
710710
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
711711
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
712+
pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, Name: *c_char);
712713
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
713714

714715
pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);

src/librustc/middle/trans/base.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
199199
lib::llvm::SetFunctionCallConv(llfn, cc);
200200
// Function addresses in Rust are never significant, allowing functions to be merged.
201201
lib::llvm::SetUnnamedAddr(llfn, true);
202+
set_split_stack(llfn);
202203

203204
llfn
204205
}
@@ -445,8 +446,8 @@ pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
445446
}
446447

447448
// Add the no-split-stack attribute if requested
448-
if !contains_name(attrs, "no_split_stack") {
449-
set_split_stack(llfn);
449+
if contains_name(attrs, "no_split_stack") {
450+
unset_split_stack(llfn);
450451
}
451452

452453
if contains_name(attrs, "cold") {
@@ -464,6 +465,12 @@ pub fn set_split_stack(f: ValueRef) {
464465
})
465466
}
466467

468+
pub fn unset_split_stack(f: ValueRef) {
469+
"split-stack".with_c_str(|buf| {
470+
unsafe { llvm::LLVMRemoveFunctionAttrString(f, buf); }
471+
})
472+
}
473+
467474
// Double-check that we never ask LLVM to declare the same symbol twice. It
468475
// silently mangles such symbols, breaking our linkage model.
469476
pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: ~str) {

src/rustllvm/RustWrapper.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ extern "C" void LLVMAddFunctionAttrString(LLVMValueRef fn, const char *Name) {
7777
unwrap<Function>(fn)->addFnAttr(Name);
7878
}
7979

80+
extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, const char *Name) {
81+
Function *f = unwrap<Function>(fn);
82+
LLVMContext &C = f->getContext();
83+
AttrBuilder B;
84+
B.addAttribute(Name);
85+
AttributeSet to_remove = AttributeSet::get(C, AttributeSet::FunctionIndex, B);
86+
87+
AttributeSet attrs = f->getAttributes();
88+
f->setAttributes(attrs.removeAttributes(f->getContext(),
89+
AttributeSet::FunctionIndex,
90+
to_remove));
91+
}
8092

8193
extern "C" void LLVMAddReturnAttribute(LLVMValueRef Fn, LLVMAttribute PA) {
8294
Function *A = unwrap<Function>(Fn);

0 commit comments

Comments
 (0)