Skip to content

Commit 734d554

Browse files
authored
De-support SafeStack on non-x86 Fuchsia (#164855)
The Fuchsia Compiler ABI will no longer provide the unsafe stack for SafeStack on machines other than x86-64. The x86_64-fuchsia target still both supports -fsanitize=safe-stack and defaults to it. Fuchsia targets that default to -fsanitize=shadow-call-stack do not need SafeStack also to be available.
1 parent 8a5f153 commit 734d554

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

clang/lib/Driver/ToolChains/Fuchsia.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,11 @@ SanitizerMask Fuchsia::getSupportedSanitizers() const {
481481
Res |= SanitizerKind::Fuzzer;
482482
Res |= SanitizerKind::FuzzerNoLink;
483483
Res |= SanitizerKind::Leak;
484-
Res |= SanitizerKind::SafeStack;
485484
Res |= SanitizerKind::Scudo;
486485
Res |= SanitizerKind::Thread;
486+
if (getTriple().getArch() == llvm::Triple::x86_64) {
487+
Res |= SanitizerKind::SafeStack;
488+
}
487489
return Res;
488490
}
489491

clang/test/Driver/fuchsia.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,13 @@
312312
// RUN: | FileCheck %s -check-prefix=CHECK-NOSTDLIB-NOLIBC
313313
// CHECK-NOSTDLIB-NOLIBC-NOT: "warning:"
314314
// CHECK-NOSTDLIB-NOLIBC-NOT: "error:"
315+
316+
// RUN: not %clang -### %s --target=aarch64-unknown-fuchsia \
317+
// RUN: -fsanitize=safe-stack 2>&1 \
318+
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
319+
// RUN: | FileCheck %s -check-prefix=CHECK-NONX86-SAFESTACK
320+
// RUN: not %clang -### %s --target=riscv64-unknown-fuchsia \
321+
// RUN: -fsanitize=safe-stack 2>&1 \
322+
// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
323+
// RUN: | FileCheck %s -check-prefix=CHECK-NONX86-SAFESTACK
324+
// CHECK-NONX86-SAFESTACK: error: unsupported option '-fsanitize=safe-stack' for target '{{.*}}'

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29521,11 +29521,6 @@ AArch64TargetLowering::getSafeStackPointerLocation(IRBuilderBase &IRB) const {
2952129521
if (Subtarget->isTargetAndroid())
2952229522
return UseTlsOffset(IRB, 0x48);
2952329523

29524-
// Fuchsia is similar.
29525-
// <zircon/tls.h> defines ZX_TLS_UNSAFE_SP_OFFSET with this value.
29526-
if (Subtarget->isTargetFuchsia())
29527-
return UseTlsOffset(IRB, -0x8);
29528-
2952929524
return TargetLowering::getSafeStackPointerLocation(IRB);
2953029525
}
2953129526

llvm/test/Transforms/SafeStack/AArch64/abi_ssp.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
; RUN: opt -safe-stack -S -mtriple=aarch64-linux-android < %s -o - | FileCheck --check-prefixes=TLS,ANDROID %s
2-
; RUN: opt -safe-stack -S -mtriple=aarch64-unknown-fuchsia < %s -o - | FileCheck --check-prefixes=TLS,FUCHSIA %s
32
; RUN: opt -passes=safe-stack -S -mtriple=aarch64-linux-android < %s -o - | FileCheck --check-prefixes=TLS,ANDROID %s
4-
; RUN: opt -passes=safe-stack -S -mtriple=aarch64-unknown-fuchsia < %s -o - | FileCheck --check-prefixes=TLS,FUCHSIA %s
53

64
define void @foo() nounwind uwtable safestack sspreq {
75
entry:
@@ -10,7 +8,6 @@ entry:
108

119
; TLS: %[[TP2:.*]] = call ptr @llvm.thread.pointer.p0()
1210
; ANDROID: %[[B:.*]] = getelementptr i8, ptr %[[TP2]], i32 40
13-
; FUCHSIA: %[[B:.*]] = getelementptr i8, ptr %[[TP2]], i32 -16
1411
; TLS: %[[StackGuard:.*]] = load ptr, ptr %[[B]]
1512
; TLS: store ptr %[[StackGuard]], ptr %[[StackGuardSlot:.*]]
1613
%a = alloca i128, align 16

0 commit comments

Comments
 (0)