Skip to content

Commit

Permalink
auto merge of #15696 : Zoxc/rust/redzone, r=alexcrichton
Browse files Browse the repository at this point in the history
Disabling the redzone is required in x86-64's kernel mode to avoid interrupts trashing the stack.

I'm not sure if decl_fn is the right place to tag all functions with noredzone. It might have interactions with external functions when linking with bitcode built without -C no-redzone although I see no reason to do that.

I'm not sure how to write a test inspecting the bitcode output for noredzone attributes on all functions either.
  • Loading branch information
bors committed Jul 16, 2014
2 parents 06c7ee9 + 036b9e8 commit d3adccd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc/driver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ cgoptions!(
"prefer dynamic linking to static linking"),
no_integrated_as: bool = (false, parse_bool,
"use an external assembler rather than LLVM's integrated one"),
no_redzone: bool = (false, parse_bool,
"disable the use of the redzone"),
relocation_model: String = ("pic".to_string(), parse_string,
"choose the relocation model to use (llc -relocation-model for details)"),
metadata: Vec<String> = (Vec::new(), parse_list,
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv,
_ => {}
}

if ccx.tcx.sess.opts.cg.no_redzone {
unsafe {
llvm::LLVMAddFunctionAttribute(llfn,
llvm::FunctionIndex as c_uint,
llvm::NoRedZoneAttribute as uint64_t)
}
}

llvm::SetFunctionCallConv(llfn, cc);
// Function addresses in Rust are never significant, allowing functions to be merged.
llvm::SetUnnamedAddr(llfn, true);
Expand Down

0 comments on commit d3adccd

Please sign in to comment.