Skip to content

Commit 88a2327

Browse files
unconditionally allow shadow call-stack for AArch64 whenever fixed-x18 is applied
1 parent 8c7e0e1 commit 88a2327

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

Diff for: compiler/rustc_session/src/session.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,12 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
11871187

11881188
// Sanitizers can only be used on platforms that we know have working sanitizer codegen.
11891189
let supported_sanitizers = sess.target.options.supported_sanitizers;
1190-
let unsupported_sanitizers = sess.opts.unstable_opts.sanitizer - supported_sanitizers;
1190+
let mut unsupported_sanitizers = sess.opts.unstable_opts.sanitizer - supported_sanitizers;
1191+
// Niche: if `fixed-x18`, or effectively switching on `reserved-x18` flag, is enabled
1192+
// we should allow Shadow Call Stack sanitizer.
1193+
if sess.opts.unstable_opts.fixed_x18 && sess.target.arch == "aarch64" {
1194+
unsupported_sanitizers -= SanitizerSet::SHADOWCALLSTACK;
1195+
}
11911196
match unsupported_sanitizers.into_iter().count() {
11921197
0 => {}
11931198
1 => {

Diff for: src/doc/rustc/src/platform-support/android.md

+5
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ Currently the `riscv64-linux-android` target requires the following architecture
6161
* `Zba` (address calculation instructions)
6262
* `Zbb` (base instructions)
6363
* `Zbs` (single-bit instructions)
64+
65+
### aarch64-linux-android on Nightly compilers
66+
67+
As soon as `-Zfixed-x18` compiler flag is supplied, the [`ShadowCallStack` sanitizer](https://releases.llvm.org/7.0.1/tools/clang/docs/ShadowCallStack.html)
68+
instrumentation is also made avaiable by supplying the second compiler flag `-Zsanitizer=shadow-call-stack`.

Diff for: src/doc/unstable-book/src/compiler-flags/fixed-x18.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# `fixed-x18`
22

33
This option prevents the compiler from using the x18 register. It is only
4-
supported on aarch64.
4+
supported on `aarch64`.
55

66
From the [ABI spec][arm-abi]:
77

@@ -23,6 +23,11 @@ Currently, the `-Zsanitizer=shadow-call-stack` flag is only supported on
2323
platforms that always treat x18 as a reserved register, and the `-Zfixed-x18`
2424
flag is not required to use the sanitizer on such platforms. However, the
2525
sanitizer may be supported on targets where this is not the case in the future.
26+
One way to do so now on Nightly compilers is to explicitly supply this `-Zfixed-x18`
27+
flag with `aarch64` targets, so that the sanitizer is available for instrumentation
28+
on targets like `aarch64-unknown-none`, for instance. However, discretion is still
29+
required to make sure that the runtime support is in place for this sanitizer
30+
to be effective.
2631

2732
It is undefined behavior for `-Zsanitizer=shadow-call-stack` code to call into
2833
code where x18 is a temporary register. On the other hand, when you are *not*

Diff for: src/doc/unstable-book/src/compiler-flags/sanitizer.md

+4
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,10 @@ A runtime must be provided by the application or operating system.
787787
788788
See the [Clang ShadowCallStack documentation][clang-scs] for more details.
789789
790+
* `aarch64-unknown-none`
791+
792+
In addition to support from a runtime by the application or operating system, `-Zfixed-x18` flag is mandatory.
793+
790794
# ThreadSanitizer
791795
792796
ThreadSanitizer is a data race detection tool. It is supported on the following
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ needs-llvm-components: aarch64
2+
//@ revisions: aarch64 android
3+
//@[aarch64] compile-flags: --target aarch64-unknown-none -Zfixed-x18 -Zsanitizer=shadow-call-stack
4+
//@[android] compile-flags: --target aarch64-linux-android -Zfixed-x18 -Zsanitizer=shadow-call-stack
5+
6+
#![allow(internal_features)]
7+
#![crate_type = "rlib"]
8+
#![feature(no_core, lang_items)]
9+
#![no_core]
10+
11+
#[lang = "sized"]
12+
trait Sized {}
13+
14+
// CHECK: ; Function Attrs:{{.*}}shadowcallstack
15+
#[no_mangle]
16+
pub fn foo() {}
17+
18+
// CHECK: attributes #0 = {{.*}}shadowcallstack{{.*}}+reserve-x18

Diff for: tests/ui/abi/shadow-call-stack-without-fixed-x18.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ compile-flags: --target aarch64-unknown-none -Zsanitizer=shadow-call-stack
2+
//@ error-pattern: shadow-call-stack sanitizer is not supported for this target
3+
//@ dont-check-compiler-stderr
4+
//@ needs-llvm-components: aarch64
5+
6+
#![allow(internal_features)]
7+
#![crate_type = "rlib"]
8+
#![feature(no_core, lang_items)]
9+
#![no_core]
10+
11+
#[lang = "sized"]
12+
trait Sized {}
13+
14+
#[no_mangle]
15+
pub fn foo() {}

0 commit comments

Comments
 (0)