[clang] a2684ac - [HWASan] use hwasan linker for Android 14+

Florian Mayer via cfe-commits cfe-commits at lists.llvm.org
Fri May 26 14:25:53 PDT 2023


Author: Florian Mayer
Date: 2023-05-26T14:25:46-07:00
New Revision: a2684acfb61d40f441e240035d7f1ba50da637c8

URL: https://github.com/llvm/llvm-project/commit/a2684acfb61d40f441e240035d7f1ba50da637c8
DIFF: https://github.com/llvm/llvm-project/commit/a2684acfb61d40f441e240035d7f1ba50da637c8.diff

LOG: [HWASan] use hwasan linker for Android 14+

This will allow to compile binaries that use hwasan to run on a
non-HWASan system image.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D151388

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Linux.cpp
    clang/test/Driver/linux-ld.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 853ff99d9fe59..920da6e4bfd49 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -426,9 +426,17 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
 
   const Distro Distro(getDriver().getVFS(), Triple);
 
-  if (Triple.isAndroid())
+  if (Triple.isAndroid()) {
+    if (getSanitizerArgs(Args).needsHwasanRt() &&
+        !Triple.isAndroidVersionLT(34) && Triple.isArch64Bit()) {
+      // On Android 14 and newer, there is a special linker_hwasan64 that
+      // allows to run HWASan binaries on non-HWASan system images. This
+      // is also available on HWASan system images, so we can just always
+      // use that instead.
+      return "/system/bin/linker_hwasan64";
+    }
     return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker";
-
+  }
   if (Triple.isMusl()) {
     std::string ArchName;
     bool IsArm = false;

diff  --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c
index 287750ac20469..d4e3bf95d6813 100644
--- a/clang/test/Driver/linux-ld.c
+++ b/clang/test/Driver/linux-ld.c
@@ -1259,6 +1259,22 @@
 // CHECK-ANDROID-32: "-dynamic-linker" "/system/bin/linker"
 // CHECK-ANDROID-64: "-dynamic-linker" "/system/bin/linker64"
 //
+// Test that Android 14 and newer use linker_hwasan64 for hwasan builds
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN:     -fsanitize=hwaddress \
+// RUN:     --target=x86_64-linux-android33 \
+// RUN:     --gcc-toolchain="" \
+// RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-OLD %s
+// RUN: %clang -### %s -no-pie 2>&1 \
+// RUN:     -fsanitize=hwaddress \
+// RUN:     --target=x86_64-linux-android34 \
+// RUN:     --gcc-toolchain="" \
+// RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NEW %s
+// CHECK-ANDROID-OLD: "-dynamic-linker" "/system/bin/linker64"
+// CHECK-ANDROID-NEW: "-dynamic-linker" "/system/bin/linker_hwasan64"
+//
 // Test that -pthread does not add -lpthread on Android.
 // RUN: %clang -### %s -no-pie 2>&1 \
 // RUN:     --target=arm-linux-androideabi -pthread \


        


More information about the cfe-commits mailing list