Skip to content

Commit 5dbd97d

Browse files
committed
rustc: Implement stack probes for x86
This commit implements stack probes on x86/x86_64 using the freshly landed support upstream in LLVM. The purpose of stack probes here are to guarantee a segfault on stack overflow rather than having a chance of running over the guard page already present on all threads by accident. At this time there's no support for any other architecture because LLVM itself does not have support for other architectures.
1 parent 8cab2c7 commit 5dbd97d

32 files changed

+170
-3
lines changed

src/librustc_back/target/i386_apple_ios.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn target() -> TargetResult {
2626
linker_flavor: LinkerFlavor::Gcc,
2727
options: TargetOptions {
2828
max_atomic_width: Some(64),
29+
stack_probes: true,
2930
.. base
3031
}
3132
})

src/librustc_back/target/i686_apple_darwin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn target() -> TargetResult {
1616
base.cpu = "yonah".to_string();
1717
base.max_atomic_width = Some(64);
1818
base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m32".to_string()]);
19+
base.stack_probes = true;
1920

2021
Ok(Target {
2122
llvm_target: "i686-apple-darwin".to_string(),

src/librustc_back/target/i686_linux_android.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn target() -> TargetResult {
2222
// http://developer.android.com/ndk/guides/abis.html#x86
2323
base.cpu = "pentiumpro".to_string();
2424
base.features = "+mmx,+sse,+sse2,+sse3,+ssse3".to_string();
25+
base.stack_probes = true;
2526

2627
Ok(Target {
2728
llvm_target: "i686-linux-android".to_string(),

src/librustc_back/target/i686_unknown_dragonfly.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn target() -> TargetResult {
1616
base.cpu = "pentium4".to_string();
1717
base.max_atomic_width = Some(64);
1818
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string());
19+
base.stack_probes = true;
1920

2021
Ok(Target {
2122
llvm_target: "i686-unknown-dragonfly".to_string(),

src/librustc_back/target/i686_unknown_freebsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn target() -> TargetResult {
1616
base.cpu = "pentium4".to_string();
1717
base.max_atomic_width = Some(64);
1818
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string());
19+
base.stack_probes = true;
1920

2021
Ok(Target {
2122
llvm_target: "i686-unknown-freebsd".to_string(),

src/librustc_back/target/i686_unknown_haiku.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn target() -> TargetResult {
1616
base.cpu = "pentium4".to_string();
1717
base.max_atomic_width = Some(64);
1818
base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m32".to_string()]);
19+
base.stack_probes = true;
1920

2021
Ok(Target {
2122
llvm_target: "i686-unknown-haiku".to_string(),

src/librustc_back/target/i686_unknown_linux_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn target() -> TargetResult {
1616
base.cpu = "pentium4".to_string();
1717
base.max_atomic_width = Some(64);
1818
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string());
19+
base.stack_probes = true;
1920

2021
Ok(Target {
2122
llvm_target: "i686-unknown-linux-gnu".to_string(),

src/librustc_back/target/i686_unknown_linux_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn target() -> TargetResult {
1717
base.max_atomic_width = Some(64);
1818
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string());
1919
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,-melf_i386".to_string());
20+
base.stack_probes = true;
2021

2122
// The unwinder used by i686-unknown-linux-musl, the LLVM libunwind
2223
// implementation, apparently relies on frame pointers existing... somehow.

src/librustc_back/target/i686_unknown_netbsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn target() -> TargetResult {
1616
base.cpu = "pentium4".to_string();
1717
base.max_atomic_width = Some(64);
1818
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string());
19+
base.stack_probes = true;
1920

2021
Ok(Target {
2122
llvm_target: "i686-unknown-netbsdelf".to_string(),

0 commit comments

Comments
 (0)