Skip to content

Commit a27a557

Browse files
authored
Merge pull request #914 from rust-lang/feature/stack-protector
Implement stack protector
2 parents 1bb4b16 + d5ed2d4 commit a27a557

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

build_system/src/test.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fn get_runners() -> Runners {
2828
("Run failing ui pattern tests", test_failing_ui_pattern_tests),
2929
);
3030
runners.insert("--test-failing-rustc", ("Run failing rustc tests", test_failing_rustc));
31+
runners.insert("--run-ui-tests", ("Run specified rustc UI tests", run_ui_tests));
3132
runners.insert("--projects", ("Run the tests of popular crates", test_projects));
3233
runners.insert("--test-libcore", ("Run libcore tests", test_libcore));
3334
runners.insert("--alloc-tests", ("Run alloc tests", test_alloc));
@@ -1218,6 +1219,45 @@ fn test_failing_ui_pattern_tests(env: &Env, args: &TestArg) -> Result<(), String
12181219
)
12191220
}
12201221

1222+
fn run_ui_tests(env: &Env, args: &TestArg) -> Result<(), String> {
1223+
let mut env = env.clone();
1224+
let rust_path = setup_rustc(&mut env, args)?;
1225+
1226+
let extra =
1227+
if args.is_using_gcc_master_branch() { "" } else { " -Csymbol-mangling-version=v0" };
1228+
1229+
let rustc_args = format!(
1230+
"{test_flags} -Zcodegen-backend={backend} --sysroot {sysroot}{extra}",
1231+
test_flags = env.get("TEST_FLAGS").unwrap_or(&String::new()),
1232+
backend = args.config_info.cg_backend_path,
1233+
sysroot = args.config_info.sysroot_path,
1234+
extra = extra,
1235+
);
1236+
1237+
env.get_mut("RUSTFLAGS").unwrap().clear();
1238+
1239+
let mut command: Vec<&dyn AsRef<OsStr>> = vec![
1240+
&"./x.py",
1241+
&"test",
1242+
&"--run",
1243+
&"always",
1244+
&"--stage",
1245+
&"0",
1246+
&"--set",
1247+
&"build.compiletest-allow-stage0=true",
1248+
&"--compiletest-rustc-args",
1249+
&rustc_args,
1250+
&"--bypass-ignore-backends",
1251+
];
1252+
1253+
for test_name in &args.test_args {
1254+
command.push(test_name);
1255+
}
1256+
1257+
run_command_with_output_and_env(&command, Some(&rust_path), Some(&env))?;
1258+
Ok(())
1259+
}
1260+
12211261
fn retain_files_callback<'a>(
12221262
file_path: &'a str,
12231263
test_type: &'a str,

src/gcc_util.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use gccjit::Version;
77
use rustc_codegen_ssa::target_features;
88
use rustc_data_structures::smallvec::{SmallVec, smallvec};
99
use rustc_session::Session;
10-
use rustc_target::spec::{Arch, RelocModel};
10+
use rustc_target::spec::{Arch, RelocModel, StackProtector};
1111

1212
fn gcc_features_by_flags(sess: &Session, features: &mut Vec<String>) {
1313
target_features::retpoline_features_by_flags(sess, features);
@@ -204,6 +204,13 @@ pub fn new_context<'gcc>(sess: &Session) -> Context<'gcc> {
204204
});
205205
}
206206

207+
match sess.stack_protector() {
208+
StackProtector::All => context.add_command_line_option("-fstack-protector-all"),
209+
StackProtector::Strong => context.add_command_line_option("-fstack-protector-strong"),
210+
StackProtector::Basic => context.add_command_line_option("-fstack-protector"),
211+
StackProtector::None => (),
212+
}
213+
207214
add_pic_option(&context, sess.relocation_model());
208215

209216
let target_cpu = target_cpu(sess);

tests/failing-ui-tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,5 @@ tests/ui/eii/static/default_cross_crate_explicit.rs
106106
tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs
107107
tests/ui/abi/rust-tail-cc.rs
108108
tests/ui/abi/rust-preserve-none-cc.rs
109-
tests/ui/abi/stack-protector.rs
110109
tests/ui/extern/extern-types-field-offset.rs
111110
tests/ui/abi/stack-probes-lto.rs

0 commit comments

Comments
 (0)