Skip to content

Commit 3005675

Browse files
committed
modified: compiler/rustc_codegen_llvm/src/attributes.rs
modified: compiler/rustc_mir_transform/src/lib.rs modified: compiler/rustc_mir_transform/src/stack_protector.rs modified: compiler/rustc_target/src/spec/mod.rs modified: tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-64bit.rs modified: tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect.rs
1 parent 342e6bf commit 3005675

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn stackprotector_attr<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> Option<&'
274274
let sspattr = match cx.sess().stack_protector() {
275275
StackProtector::None => return None,
276276
StackProtector::All => AttributeKind::StackProtectReq,
277-
277+
278278
StackProtector::Rusty => {
279279
if cx.tcx.stack_protector.borrow().contains(&def_id) {
280280
AttributeKind::StackProtectStrong

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ fn mir_promoted(
452452
lint_tail_expr_drop_order::run_lint(tcx, def, &body);
453453

454454
let promoted = promote_pass.promoted_fragments.into_inner();
455-
455+
456456
if tcx.sess.stack_protector() == StackProtector::Rusty {
457457
pm::run_passes(
458458
tcx,

compiler/rustc_mir_transform/src/stack_protector.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use std::ops::Deref;
44

55
use rustc_middle::mir::*;
66
use rustc_middle::ty;
7-
use rustc_middle::ty::Instance;
8-
use rustc_middle::ty::TyCtxt;
7+
use rustc_middle::ty::{Instance, TyCtxt};
98
use rustc_target::callconv::PassMode;
109

1110
pub(super) struct StackProtectorFinder;
@@ -41,10 +40,12 @@ impl<'tcx> crate::MirPass<'tcx> for StackProtectorFinder {
4140
}
4241

4342
let instance = Instance::mono(tcx, def_id);
44-
let Ok(fn_abi) = tcx.fn_abi_of_instance(ty::TypingEnv::fully_monomorphized().as_query_input((instance, ty::List::empty())),)
45-
else {
43+
let Ok(fn_abi) = tcx.fn_abi_of_instance(
44+
ty::TypingEnv::fully_monomorphized().as_query_input((instance, ty::List::empty())),
45+
) else {
4646
// FIXME: Find when an Err() message is returned
47-
return;
47+
48+
return;
4849
};
4950

5051
// for arg in fn_abi.args.iter() {
@@ -55,11 +56,11 @@ impl<'tcx> crate::MirPass<'tcx> for StackProtectorFinder {
5556
// }
5657

5758
let ret = &fn_abi.ret;
58-
if matches!(&ret.mode, PassMode::Indirect { attrs: _, meta_attrs: _, on_stack: false}) {
59+
if matches!(&ret.mode, PassMode::Indirect { attrs: _, meta_attrs: _, on_stack: false })
60+
{
5961
tcx.stack_protector.borrow_mut().insert(def_id);
6062
return;
6163
}
62-
6364
}
6465
}
6566

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ pub enum StackProtector {
17651765
/// - calls to stack memory allocation
17661766
/// - obtaining reference/pointer of local variables
17671767
Rusty,
1768-
1768+
17691769
/// Generate stack canaries in all functions.
17701770
All,
17711771
}

tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-64bit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32
209209

210210
// FIXME: rusty stack smash protection needs to support inline scenario detection
211211
// rusty: __security_check_cookie
212-
212+
213213
// strong-NOT: __security_check_cookie
214214
// basic-NOT: __security_check_cookie
215215
// none-NOT: __security_check_cookie
@@ -247,7 +247,7 @@ pub fn local_large_var_moved(f: fn(Gigastruct)) {
247247
// ```
248248

249249
// all: __security_check_cookie
250-
250+
251251
// FIXME: How does the rust compiler handle moves of large structures?
252252
// rusty-NOT: __security_check_cookie
253253

@@ -280,10 +280,10 @@ pub fn local_large_var_cloned(f: fn(Gigastruct)) {
280280
// ```
281281

282282
// all: __security_check_cookie
283-
283+
284284
// FIXME: How does the rust compiler handle moves of large structures?
285285
// rusty-NOT: __security_check_cookie
286-
286+
287287
// strong: __security_check_cookie
288288
// basic: __security_check_cookie
289289
// none-NOT: __security_check_cookie
@@ -322,7 +322,7 @@ extern "C" {
322322
#[no_mangle]
323323
pub fn alloca_small_compile_time_constant_arg(f: fn(*mut ())) {
324324
f(unsafe { alloca(8) });
325-
325+
326326
// all: __security_check_cookie
327327

328328
// FIXME: Rusty thinks a function that returns a mutable raw pointer may

tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32
190190
// the `strong` heuristic.
191191

192192
// all: __stack_chk_fail
193-
193+
194194
// FIXME: rusty stack smash protection needs to support inline scenario detection
195195
// rusty: __stack_chk_fail
196-
196+
197197
// strong-NOT: __stack_chk_fail
198198
// basic-NOT: __stack_chk_fail
199199
// none-NOT: __stack_chk_fail
@@ -231,10 +231,10 @@ pub fn local_large_var_moved(f: fn(Gigastruct)) {
231231
// ```
232232

233233
// all: __stack_chk_fail
234-
234+
235235
// FIXME: How does the rust compiler handle moves of large structures?
236236
// rusty-NOT: __stack_chk_fail
237-
237+
238238
// strong: __stack_chk_fail
239239
// basic: __stack_chk_fail
240240
// none-NOT: __stack_chk_fail
@@ -264,10 +264,10 @@ pub fn local_large_var_cloned(f: fn(Gigastruct)) {
264264
// ```
265265

266266
// all: __stack_chk_fail
267-
267+
268268
// FIXME: How does the rust compiler handle moves of large structures?
269269
// rusty-NOT: __stack_chk_fail
270-
270+
271271
// strong: __stack_chk_fail
272272
// basic: __stack_chk_fail
273273
// none-NOT: __stack_chk_fail
@@ -313,7 +313,7 @@ pub fn alloca_small_compile_time_constant_arg(f: fn(*mut ())) {
313313
// be a stack memory allocation function, so it performs stack smash protection.
314314
// Is it possible to optimize the heuristics?
315315
// rusty: __stack_chk_fail
316-
316+
317317
// strong-NOT: __stack_chk_fail
318318
// basic-NOT: __stack_chk_fail
319319
// none-NOT: __stack_chk_fail
@@ -367,10 +367,10 @@ pub fn unsized_fn_param(s: [u8], l: bool, f: fn([u8])) {
367367
// heuristics.
368368

369369
// all: __stack_chk_fail
370-
370+
371371
// FIXME: Does Rusty need to handle this type of optimization?
372372
// rusty: __stack_chk_fail
373-
373+
374374
// strong-NOT: __stack_chk_fail
375375
// basic-NOT: __stack_chk_fail
376376
// none-NOT: __stack_chk_fail

0 commit comments

Comments
 (0)