diff options
| author | Ali Clark <ali@clark.gb.net> | 2016-01-21 02:43:22 +0000 |
|---|---|---|
| committer | Ali Clark <ali@clark.gb.net> | 2016-01-21 02:50:48 +0000 |
| commit | 2cbffd5642c83b02d206110c483d5d83aed51c54 (patch) | |
| tree | 62f78c563e0f9c714947e96d38f5f874f5c20a31 | |
| parent | 7dce32e65d53ff9cfd8dba89121efa4c977030de (diff) | |
| download | rust-2cbffd5642c83b02d206110c483d5d83aed51c54.tar.gz rust-2cbffd5642c83b02d206110c483d5d83aed51c54.zip | |
actively disable stack execution on linux and bsd
| -rw-r--r-- | src/librustc_back/target/dragonfly_base.rs | 3 | ||||
| -rw-r--r-- | src/librustc_back/target/freebsd_base.rs | 13 | ||||
| -rw-r--r-- | src/librustc_back/target/linux_base.rs | 3 | ||||
| -rw-r--r-- | src/librustc_back/target/netbsd_base.rs | 3 | ||||
| -rw-r--r-- | src/librustc_back/target/openbsd_base.rs | 3 |
5 files changed, 25 insertions, 0 deletions
diff --git a/src/librustc_back/target/dragonfly_base.rs b/src/librustc_back/target/dragonfly_base.rs index b78fdc9f59b..ead16f95707 100644 --- a/src/librustc_back/target/dragonfly_base.rs +++ b/src/librustc_back/target/dragonfly_base.rs @@ -24,6 +24,9 @@ pub fn opts() -> TargetOptions { // libraries which follow this flag. Thus, use it before // specifying libraries to link to. "-Wl,--as-needed".to_string(), + + // Always enable NX protection when it is available + "-Wl,-z,noexecstack".to_string(), ), position_independent_executables: true, archive_format: "gnu".to_string(), diff --git a/src/librustc_back/target/freebsd_base.rs b/src/librustc_back/target/freebsd_base.rs index e955f8c302b..9b5d55fa0d5 100644 --- a/src/librustc_back/target/freebsd_base.rs +++ b/src/librustc_back/target/freebsd_base.rs @@ -17,6 +17,19 @@ pub fn opts() -> TargetOptions { dynamic_linking: true, executables: true, has_rpath: true, + pre_link_args: vec![ + // We want to be able to strip as much executable code as possible + // from the linker command line, and this flag indicates to the + // linker that it can avoid linking in dynamic libraries that don't + // actually satisfy any symbols up to that point (as with many other + // resolutions the linker does). This option only applies to all + // following libraries so we're sure to pass it as one of the first + // arguments. + "-Wl,--as-needed".to_string(), + + // Always enable NX protection when it is available + "-Wl,-z,noexecstack".to_string(), + ], archive_format: "gnu".to_string(), exe_allocation_crate: super::maybe_jemalloc(), diff --git a/src/librustc_back/target/linux_base.rs b/src/librustc_back/target/linux_base.rs index 0efcf73ee86..20aae113f7b 100644 --- a/src/librustc_back/target/linux_base.rs +++ b/src/librustc_back/target/linux_base.rs @@ -26,6 +26,9 @@ pub fn opts() -> TargetOptions { // following libraries so we're sure to pass it as one of the first // arguments. "-Wl,--as-needed".to_string(), + + // Always enable NX protection when it is available + "-Wl,-z,noexecstack".to_string(), ], position_independent_executables: true, archive_format: "gnu".to_string(), diff --git a/src/librustc_back/target/netbsd_base.rs b/src/librustc_back/target/netbsd_base.rs index 361f71f6995..ead8a7259f0 100644 --- a/src/librustc_back/target/netbsd_base.rs +++ b/src/librustc_back/target/netbsd_base.rs @@ -24,6 +24,9 @@ pub fn opts() -> TargetOptions { // libraries which follow this flag. Thus, use it before // specifying libraries to link to. "-Wl,--as-needed".to_string(), + + // Always enable NX protection when it is available + "-Wl,-z,noexecstack".to_string(), ), position_independent_executables: true, archive_format: "gnu".to_string(), diff --git a/src/librustc_back/target/openbsd_base.rs b/src/librustc_back/target/openbsd_base.rs index 2e4aa27cf88..e0c2d062949 100644 --- a/src/librustc_back/target/openbsd_base.rs +++ b/src/librustc_back/target/openbsd_base.rs @@ -24,6 +24,9 @@ pub fn opts() -> TargetOptions { // libraries which follow this flag. Thus, use it before // specifying libraries to link to. "-Wl,--as-needed".to_string(), + + // Always enable NX protection when it is available + "-Wl,-z,noexecstack".to_string(), ), position_independent_executables: true, archive_format: "gnu".to_string(), |
