Skip to content

Commit d68b66f

Browse files
authored
Unrolled build for rust-lang#130824
Rollup merge of rust-lang#130824 - Darksonn:fix-function-return, r=wesleywiser Add missing module flags for `-Zfunction-return=thunk-extern` This fixes a bug in the `-Zfunction-return=thunk-extern` flag. The flag needs to be passed onto LLVM to ensure that functions such as `asan.module_ctor` and `asan.module_dtor` that are created internally in LLVM have the mitigation applied to them. This was originally discovered [in the Linux kernel](https://lore.kernel.org/all/CANiq72myZL4_poCMuNFevtpYYc0V0embjSuKb7y=C+m3vVA_8g@mail.gmail.com/). Original flag PR: rust-lang#116892 PR for similar issue: rust-lang#129373 Tracking issue: rust-lang#116853 cc ``@ojeda`` r? ``@wesleywiser``
2 parents b8495e5 + 540e41f commit d68b66f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
1919
use rustc_middle::{bug, span_bug};
2020
use rustc_session::Session;
2121
use rustc_session::config::{
22-
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, PAuthKey, PacRet,
22+
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, FunctionReturn, PAuthKey, PacRet,
2323
};
2424
use rustc_span::source_map::Spanned;
2525
use rustc_span::{DUMMY_SP, Span};
@@ -378,6 +378,18 @@ pub(crate) unsafe fn create_module<'ll>(
378378
}
379379
}
380380

381+
match sess.opts.unstable_opts.function_return {
382+
FunctionReturn::Keep => {}
383+
FunctionReturn::ThunkExtern => unsafe {
384+
llvm::LLVMRustAddModuleFlagU32(
385+
llmod,
386+
llvm::LLVMModFlagBehavior::Override,
387+
c"function_return_thunk_extern".as_ptr(),
388+
1,
389+
)
390+
},
391+
}
392+
381393
match (sess.opts.unstable_opts.small_data_threshold, sess.target.small_data_threshold_support())
382394
{
383395
// Set up the small-data optimization limit for architectures that use

tests/codegen/function-return.rs

+6
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ pub fn foo() {
2626
// keep-thunk-extern: attributes #0 = { {{.*}}fn_ret_thunk_extern{{.*}} }
2727
// thunk-extern-keep-NOT: fn_ret_thunk_extern
2828
}
29+
30+
// unset-NOT: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1}
31+
// keep-NOT: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1}
32+
// thunk-extern: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1}
33+
// keep-thunk-extern: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1}
34+
// thunk-extern-keep-NOT: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1}

0 commit comments

Comments
 (0)