Skip to content

Commit d3adccd

Browse files
committed
auto merge of #15696 : Zoxc/rust/redzone, r=alexcrichton
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.
2 parents 06c7ee9 + 036b9e8 commit d3adccd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustc/driver/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ cgoptions!(
332332
"prefer dynamic linking to static linking"),
333333
no_integrated_as: bool = (false, parse_bool,
334334
"use an external assembler rather than LLVM's integrated one"),
335+
no_redzone: bool = (false, parse_bool,
336+
"disable the use of the redzone"),
335337
relocation_model: String = ("pic".to_string(), parse_string,
336338
"choose the relocation model to use (llc -relocation-model for details)"),
337339
metadata: Vec<String> = (Vec::new(), parse_list,

src/librustc/middle/trans/base.rs

+8
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv,
193193
_ => {}
194194
}
195195

196+
if ccx.tcx.sess.opts.cg.no_redzone {
197+
unsafe {
198+
llvm::LLVMAddFunctionAttribute(llfn,
199+
llvm::FunctionIndex as c_uint,
200+
llvm::NoRedZoneAttribute as uint64_t)
201+
}
202+
}
203+
196204
llvm::SetFunctionCallConv(llfn, cc);
197205
// Function addresses in Rust are never significant, allowing functions to be merged.
198206
llvm::SetUnnamedAddr(llfn, true);

0 commit comments

Comments
 (0)