[compiler-rt] e794b66 - [test][HWASAN] Fix test to run on aarch64

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 19:33:06 PDT 2023


Author: Vitaly Buka
Date: 2023-09-26T19:32:53-07:00
New Revision: e794b66268b22c37195eb0bf1425e461cb9ea982

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

LOG: [test][HWASAN] Fix test to run on aarch64

It was built and tested on x86_64 without real HWASAN tagging.

Added: 
    

Modified: 
    compiler-rt/test/sanitizer_common/TestCases/Linux/internal_symbolizer.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/internal_symbolizer.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/internal_symbolizer.cpp
index 2421616676cface..b4e8f953969154b 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/internal_symbolizer.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/internal_symbolizer.cpp
@@ -1,10 +1,12 @@
-// RUN: %clangxx %s -o %t -g && %run %t 2>&1 | FileCheck %s
+// FIXME: Remove -hwasan-globals=0 when implemented.
+// RUN: %clangxx %s -o %t -g -mllvm -hwasan-globals=0 && %run %t 2>&1 | FileCheck %s
 
 // REQUIRES: internal_symbolizer
 
 #include <assert.h>
 #include <dlfcn.h>
 #include <link.h>
+#include <sanitizer/hwasan_interface.h>
 #include <sanitizer/msan_interface.h>
 #include <string.h>
 
@@ -72,9 +74,12 @@ __attribute__((noinline)) FrameInfo A<0>::RecursiveTemplateFunction(const T &) {
 }
 
 __attribute__((no_sanitize_memory)) std::pair<const char *, uint64_t>
-GetModuleAndOffset(void *address) {
+GetModuleAndOffset(const void *address) {
   Dl_info di;
   link_map *lm = nullptr;
+#if __has_feature(hwaddress_sanitizer)
+  address = __hwasan_tag_pointer(address, 0);
+#endif
   assert(
       dladdr1(address, &di, reinterpret_cast<void **>(&lm), RTLD_DL_LINKMAP));
   return {di.dli_fname, reinterpret_cast<uint64_t>(address) - lm->l_addr};
@@ -98,7 +103,7 @@ void TestInline() {
   auto frame = InlineFunction();
   fprintf(stderr, "%s: %s\n", __FUNCTION__, Symbolize(frame).c_str());
   // CHECK-LABEL: TestInline: InlineFunction()
-  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 55]]
+  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 58]]
   // CHECK-NEXT: TestInline()
   // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 5]]
 }
@@ -107,14 +112,14 @@ void TestNoInline() {
   auto frame = NoInlineFunction();
   fprintf(stderr, "%s: %s\n", __FUNCTION__, Symbolize(frame).c_str());
   // CHECK-LABEL: TestNoInline: NoInlineFunction()
-  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 58]]
+  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 61]]
 }
 
 void TestLongFunctionNames() {
   auto frame = A<10>().RecursiveTemplateFunction(0);
   fprintf(stderr, "%s: %s\n", __FUNCTION__, Symbolize(frame).c_str());
   // CHECK-LABEL: TestLongFunctionNames: NoInlineFunction()
-  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 65]]
+  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 68]]
 }
 
 std::string SymbolizeStaticVar() {
@@ -134,8 +139,8 @@ void TestData() {
   // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 13]]
 }
 
-__attribute__((noinline)) std::string SymbolizeLocalVars(FrameInfo frame) {
-  auto modul_offset = GetModuleAndOffset(frame.address);
+__attribute__((noinline)) std::string SymbolizeLocalVars(const void *pc) {
+  auto modul_offset = GetModuleAndOffset(pc);
   char buffer[1024] = {};
   ScopedInSymbolizer in_symbolizer;
   __sanitizer_symbolize_frame(modul_offset.first, modul_offset.second, buffer,
@@ -145,26 +150,19 @@ __attribute__((noinline)) std::string SymbolizeLocalVars(FrameInfo frame) {
 
 __attribute__((
     noinline,
-    no_sanitize_address /* Asan merges allocas destroying variable DI*/)) void
+    no_sanitize_address /* Asan merges allocas destroying variable DI */)) void
 TestFrame() {
   volatile int var = 1;
   void *address = GetPC();
   fprintf(stderr, "%s: %s\n", __FUNCTION__,
-          SymbolizeLocalVars({
-                                 0,
-                                 "",
-                                 "",
-                                 reinterpret_cast<void *>(
-                                     reinterpret_cast<uintptr_t>(address)),
-                             })
-              .c_str());
+          SymbolizeLocalVars(address).c_str());
   // CHECK-LABEL: TestFrame: TestFrame
   // CHECK-NEXT: var
-  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 13]]
+  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 6]]
   // CHECK-NEXT: {{-?[0-9]+ +[0-9]+}}
   // CHECK-NEXT: TestFrame
   // CHECK-NEXT: address
-  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 16]]
+  // CHECK-NEXT: internal_symbolizer.cpp:[[# @LINE - 9]]
   // CHECK-NEXT: {{-?[0-9]+ +[0-9]+}}
 }
 


        


More information about the llvm-commits mailing list