Auto merge of #116892 - ojeda:rethunk, r=wesleywiser
Add `-Zfunction-return={keep,thunk-extern}` option This is intended to be used for Linux kernel RETHUNK builds. With this commit (optionally backported to Rust 1.73.0), plus a patched Linux kernel to pass the flag, I get a RETHUNK build with Rust enabled that is `objtool`-warning-free and is able to boot in QEMU and load a sample Rust kernel module. Issue: https://github.com/rust-lang/rust/issues/116853.
This commit is contained in:
commit
f45631b10f
17 changed files with 216 additions and 10 deletions
|
@ -4,7 +4,7 @@ use rustc_codegen_ssa::traits::*;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_session::config::OptLevel;
|
||||
use rustc_session::config::{FunctionReturn, OptLevel};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtector};
|
||||
|
@ -118,6 +118,15 @@ pub fn frame_pointer_type_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attr
|
|||
Some(llvm::CreateAttrStringValue(cx.llcx, "frame-pointer", attr_value))
|
||||
}
|
||||
|
||||
fn function_return_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
|
||||
let function_return_attr = match cx.sess().opts.unstable_opts.function_return {
|
||||
FunctionReturn::Keep => return None,
|
||||
FunctionReturn::ThunkExtern => AttributeKind::FnRetThunkExtern,
|
||||
};
|
||||
|
||||
Some(function_return_attr.create_attr(cx.llcx))
|
||||
}
|
||||
|
||||
/// Tell LLVM what instrument function to insert.
|
||||
#[inline]
|
||||
fn instrument_function_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> SmallVec<[&'ll Attribute; 4]> {
|
||||
|
@ -331,8 +340,9 @@ pub fn from_fn_attrs<'ll, 'tcx>(
|
|||
to_add.push(llvm::CreateAttrString(cx.llcx, "use-sample-profile"));
|
||||
}
|
||||
|
||||
// FIXME: none of these three functions interact with source level attributes.
|
||||
// FIXME: none of these functions interact with source level attributes.
|
||||
to_add.extend(frame_pointer_type_attr(cx));
|
||||
to_add.extend(function_return_attr(cx));
|
||||
to_add.extend(instrument_function_attr(cx));
|
||||
to_add.extend(nojumptables_attr(cx));
|
||||
to_add.extend(probestack_attr(cx));
|
||||
|
|
|
@ -200,6 +200,7 @@ pub enum AttributeKind {
|
|||
AllocatedPointer = 38,
|
||||
AllocAlign = 39,
|
||||
SanitizeSafeStack = 40,
|
||||
FnRetThunkExtern = 41,
|
||||
}
|
||||
|
||||
/// LLVMIntPredicate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue