[compiler-rt] ebad19f - [compiler-rt][hwasan] Introduce MaybeDieIfNoTaggingAbi()

Alexander Potapenko via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 25 01:32:15 PDT 2022


Author: Alexander Potapenko
Date: 2022-08-25T10:32:01+02:00
New Revision: ebad19fedc40b9da51cf38cdb4df6e9e7456429d

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

LOG: [compiler-rt][hwasan] Introduce MaybeDieIfNoTaggingAbi()

Use a helper function to print an error message and die in the case
flags()->fail_without_syscall_abi is set.

Because x86 doesn't have `sysctl abi.tagged_addr_disabled`, do not
mention it in the error message for non-Android runtime.

Depends on D132543

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

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_linux.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp b/compiler-rt/lib/hwasan/hwasan_linux.cpp
index e81b55f7e4573..2194ffe1ffd46 100644
--- a/compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -110,6 +110,13 @@ static void InitializeShadowBaseAddress(uptr shadow_size_bytes) {
       FindDynamicShadowStart(shadow_size_bytes);
 }
 
+static void MaybeDieIfNoTaggingAbi(const char *message) {
+  if (!flags()->fail_without_syscall_abi)
+    return;
+  Printf("FATAL: %s\n", message);
+  Die();
+}
+
 #  define PR_SET_TAGGED_ADDR_CTRL 55
 #  define PR_GET_TAGGED_ADDR_CTRL 56
 #  define PR_TAGGED_ADDR_ENABLE (1UL << 0)
@@ -139,12 +146,8 @@ void InitializeOsSupport() {
     // case.
     return;
 #  else
-    if (flags()->fail_without_syscall_abi) {
-      Printf(
-          "FATAL: "
-          "HWAddressSanitizer requires a kernel with tagged address ABI.\n");
-      Die();
-    }
+    MaybeDieIfNoTaggingAbi(
+        "HWAddressSanitizer requires a kernel with tagged address ABI.");
 #  endif
   }
 
@@ -162,13 +165,15 @@ void InitializeOsSupport() {
       return;
     }
 #  endif  // defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
-    if (flags()->fail_without_syscall_abi) {
-      Printf(
-          "FATAL: HWAddressSanitizer failed to enable tagged address syscall "
-          "ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
-          "configuration.\n");
-      Die();
-    }
+
+#  if SANITIZER_ANDROID
+  MaybeDieIfNoTaggingAbi(
+      "HWAddressSanitizer failed to enable tagged address syscall ABI.\n"
+      "Check the `sysctl abi.tagged_addr_disabled` configuration.");
+#  else
+  MaybeDieIfNoTaggingAbi(
+      "HWAddressSanitizer failed to enable tagged address syscall ABI.\n");
+#  endif
   }
 }
 


        


More information about the llvm-commits mailing list