From 956b83fca0c5dff673c480e11d70fcc5e2fd4c72 Mon Sep 17 00:00:00 2001 From: Sharjeel Khan Date: Sun, 12 Jan 2025 01:36:00 -0800 Subject: [PATCH] [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. --- clang/lib/Driver/ToolChains/Linux.cpp | 4 +++- clang/test/Driver/fsanitize.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 1c56355136df86a..c2a85be81981695 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -823,6 +823,7 @@ SanitizerMask Linux::getSupportedSanitizers() const { const bool IsRISCV64 = getTriple().getArch() == llvm::Triple::riscv64; const bool IsSystemZ = getTriple().getArch() == llvm::Triple::systemz; const bool IsHexagon = getTriple().getArch() == llvm::Triple::hexagon; + const bool IsAndroid = getTriple().isAndroid(); SanitizerMask Res = ToolChain::getSupportedSanitizers(); Res |= SanitizerKind::Address; Res |= SanitizerKind::PointerCompare; @@ -831,7 +832,6 @@ SanitizerMask Linux::getSupportedSanitizers() const { Res |= SanitizerKind::Fuzzer; Res |= SanitizerKind::FuzzerNoLink; Res |= SanitizerKind::KernelAddress; - Res |= SanitizerKind::Memory; Res |= SanitizerKind::Vptr; Res |= SanitizerKind::SafeStack; if (IsX86_64 || IsMIPS64 || IsAArch64 || IsLoongArch64) @@ -857,6 +857,8 @@ SanitizerMask Linux::getSupportedSanitizers() const { } if (IsX86_64) Res |= SanitizerKind::NumericalStability; + if (!IsAndroid) + Res |= SanitizerKind::Memory; // Work around "Cannot represent a difference across sections". if (getTriple().getArch() == llvm::Triple::ppc64) diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index 1d3caec748d77a1..429dc51b3356d68 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -399,6 +399,11 @@ // RUN: %clang --target=arm-linux-androideabi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-NO-ASAN // CHECK-ANDROID-NO-ASAN: "-mrelocation-model" "pic" +// RUN: not %clang --target=aarch64-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID +// RUN: not %clang --target=i386-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID +// RUN: not %clang --target=x86_64-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID +// CHECK-MSAN-ANDROID: unsupported option '-fsanitize=memory' for target + // RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN // RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN // RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover=all -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN