You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/doc/unstable-book/src/compiler-flags/sanitizer.md
+33-7
Original file line number
Diff line number
Diff line change
@@ -775,22 +775,47 @@ See the [Clang SafeStack documentation][clang-safestack] for more details.
775
775
776
776
# ShadowCallStack
777
777
778
-
ShadowCallStack provides backward edge control flow protection by storing a function's return address in a separately allocated 'shadow call stack' and loading the return address from that shadow call stack.
779
-
780
-
ShadowCallStack requires a platform ABI which reserves `x18` as the instrumentation makes use of this register.
778
+
ShadowCallStack provides backward edge control flow protection by storing a function's return address in a separately allocated 'shadow call stack'
779
+
and loading the return address from that shadow call stack.
780
+
AArch64 and RISC-V both have a platform register defined in their ABIs, which is `x18` and `x3`/`gp` respectively, that can optionally be reserved for this purpose.
781
+
Software support from the operating system and runtime may be required depending on the target platform which is detailed in the remaining section.
782
+
See the [Clang ShadowCallStack documentation][clang-scs] for more details.
781
783
782
784
ShadowCallStack can be enabled with `-Zsanitizer=shadow-call-stack` option and is supported on the following targets:
783
785
784
-
*`aarch64-linux-android`
786
+
## AArch64 family
785
787
786
-
A runtime must be provided by the application or operating system.
788
+
ShadowCallStack requires the use of the ABI defined platform register, `x18`, which is required for code generation purposes.
789
+
When `x18` is not reserved, and is instead used as a scratch register subsequently, enabling ShadowCallStack would lead to undefined behaviour
790
+
due to corruption of return address or invalid memory access when the instrumentation restores return register to the link register `lr` from the
791
+
already clobbered `x18` register.
792
+
In other words, code that is calling into or called by functions instrumented with ShadowCallStack must reserve the `x18` register or preserve its value.
787
793
788
-
See the [Clang ShadowCallStack documentation][clang-scs] for more details.
794
+
### `aarch64-linux-android` and `aarch64-unknown-fuchsia`/`aarch64-fuchsia`
789
795
790
-
*`aarch64-unknown-none`
796
+
This target already reserves the `x18` register.
797
+
A runtime must be provided by the application or operating system.
798
+
If `bionic` is used on this target, the software support is provided.
799
+
Otherwise, a runtime needs to prepare a memory region and points `x18` to the region which serves as the shadow call stack.
800
+
801
+
### `aarch64-unknown-none`
791
802
792
803
In addition to support from a runtime by the application or operating system, the `-Zfixed-x18` flag is also mandatory.
793
804
805
+
## RISC-V 64 family
806
+
807
+
ShadowCallStack uses either the `gp` register for software shadow stack, also known as `x3`, or the `ssp` register if [`Zicfiss`][riscv-zicfiss] extension is available.
808
+
`gp`/`x3` is currently always reserved and available forShadowCallStack instrumentation, and `ssp`incase of `Zicfiss` is only accessible through its dedicated shadow stack instructions.
809
+
810
+
Support from the runtime and operating system is required when `gp`/`x3` is used for software shadow stack.
811
+
A runtime must prepare a memory region and point `gp`/`x3` to the region before executing the code.
812
+
813
+
The following targets support ShadowCallStack.
814
+
815
+
*`riscv64imac-unknown-none-elf`
816
+
*`riscv64gc-unknown-none-elf`
817
+
*`riscv64gc-unknown-fuchsia`
818
+
794
819
# ThreadSanitizer
795
820
796
821
ThreadSanitizer is a data race detection tool. It is supported on the following
@@ -912,3 +937,4 @@ Sanitizers produce symbolized stacktraces when llvm-symbolizer binary is in `PAT
0 commit comments