Skip to content

Commit fdfe7e7

Browse files
[Driver] Error when using msan on Android (#122540)
Msan is not supported on Android as mentioned in google/sanitizers#1381. We proactively give the warning saying it is unsupported to fix android/ndk#1958.
1 parent a536444 commit fdfe7e7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
823823
const bool IsRISCV64 = getTriple().getArch() == llvm::Triple::riscv64;
824824
const bool IsSystemZ = getTriple().getArch() == llvm::Triple::systemz;
825825
const bool IsHexagon = getTriple().getArch() == llvm::Triple::hexagon;
826+
const bool IsAndroid = getTriple().isAndroid();
826827
SanitizerMask Res = ToolChain::getSupportedSanitizers();
827828
Res |= SanitizerKind::Address;
828829
Res |= SanitizerKind::PointerCompare;
@@ -831,7 +832,6 @@ SanitizerMask Linux::getSupportedSanitizers() const {
831832
Res |= SanitizerKind::Fuzzer;
832833
Res |= SanitizerKind::FuzzerNoLink;
833834
Res |= SanitizerKind::KernelAddress;
834-
Res |= SanitizerKind::Memory;
835835
Res |= SanitizerKind::Vptr;
836836
Res |= SanitizerKind::SafeStack;
837837
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsLoongArch64)
@@ -857,6 +857,8 @@ SanitizerMask Linux::getSupportedSanitizers() const {
857857
}
858858
if (IsX86_64)
859859
Res |= SanitizerKind::NumericalStability;
860+
if (!IsAndroid)
861+
Res |= SanitizerKind::Memory;
860862

861863
// Work around "Cannot represent a difference across sections".
862864
if (getTriple().getArch() == llvm::Triple::ppc64)

clang/test/Driver/fsanitize.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@
399399
// RUN: %clang --target=arm-linux-androideabi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-NO-ASAN
400400
// CHECK-ANDROID-NO-ASAN: "-mrelocation-model" "pic"
401401

402+
// RUN: not %clang --target=aarch64-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
403+
// RUN: not %clang --target=i386-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
404+
// RUN: not %clang --target=x86_64-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
405+
// CHECK-MSAN-ANDROID: unsupported option '-fsanitize=memory' for target
406+
402407
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
403408
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
404409
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover=all -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN

0 commit comments

Comments
 (0)