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. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::code_stats::CodeStats;
|
||||
pub use crate::code_stats::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo};
|
||||
use crate::config::{
|
||||
self, CrateType, InstrumentCoverage, OptLevel, OutFileName, OutputType,
|
||||
self, CrateType, FunctionReturn, InstrumentCoverage, OptLevel, OutFileName, OutputType,
|
||||
RemapPathScopeComponents, SwitchWithOptPath,
|
||||
};
|
||||
use crate::config::{ErrorOutputType, Input};
|
||||
@@ -1678,6 +1678,28 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
|
||||
sess.emit_err(errors::IncompatibleLinkerFlavor { flavor, compatible_list });
|
||||
}
|
||||
}
|
||||
|
||||
if sess.opts.unstable_opts.function_return != FunctionReturn::default() {
|
||||
if sess.target.arch != "x86" && sess.target.arch != "x86_64" {
|
||||
sess.emit_err(errors::FunctionReturnRequiresX86OrX8664);
|
||||
}
|
||||
}
|
||||
|
||||
// The code model check applies to `thunk` and `thunk-extern`, but not `thunk-inline`, so it is
|
||||
// kept as a `match` to force a change if new ones are added, even if we currently only support
|
||||
// `thunk-extern` like Clang.
|
||||
match sess.opts.unstable_opts.function_return {
|
||||
FunctionReturn::Keep => (),
|
||||
FunctionReturn::ThunkExtern => {
|
||||
// FIXME: In principle, the inherited base LLVM target code model could be large,
|
||||
// but this only checks whether we were passed one explicitly (like Clang does).
|
||||
if let Some(code_model) = sess.code_model()
|
||||
&& code_model == CodeModel::Large
|
||||
{
|
||||
sess.emit_err(errors::FunctionReturnThunkExternRequiresNonLargeCodeModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Holds data on the current incremental compilation session, if there is one.
|
||||
|
||||
Reference in New Issue
Block a user