[PATCH] D151388: [HWASan] use hwasan linker for Android 14+
Florian Mayer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 24 16:51:24 PDT 2023
fmayer created this revision.
Herald added a subscriber: danielkiss.
Herald added a project: All.
fmayer requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.
This will allow to compile binaries that use hwasan to run on a
non-HWASan system image.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D151388
Files:
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/linux-ld.c
Index: clang/test/Driver/linux-ld.c
===================================================================
--- clang/test/Driver/linux-ld.c
+++ 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 \
Index: clang/lib/Driver/ToolChains/Linux.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -426,9 +426,17 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151388.525371.patch
Type: text/x-patch
Size: 2160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230524/6cc85b31/attachment.bin>
More information about the cfe-commits
mailing list