[compiler-rt] Add cmake option to enable/disable searching PATH for symbolizer (PR #129012)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 26 22:51:49 PST 2025


https://github.com/midhuncodes7 created https://github.com/llvm/llvm-project/pull/129012

Introduced cmake option that is disabled by default allowing searching PATH variable for symbolizer. The option will be enabled for downstream changes to disable searching PATH variable for symbolizer instead use ASAN_SYMBOLIZER_PATH

>From 12cd6b8de54add6a82226457faaf9697873c1c32 Mon Sep 17 00:00:00 2001
From: Midhunesh <midhunesh.p at ibm.com>
Date: Mon, 17 Feb 2025 22:02:56 +0530
Subject: [PATCH 1/3] option to enable/disable PATH search for symbolizer

---
 compiler-rt/CMakeLists.txt                    |  7 ++++
 .../sanitizer_symbolizer_posix_libcdep.cpp    | 35 +++++++++++--------
 .../TestCases/disable_symbolizer_path_search  | 29 +++++++++++++++
 3 files changed, 56 insertions(+), 15 deletions(-)
 create mode 100644 compiler-rt/test/sanitizer_common/TestCases/disable_symbolizer_path_search

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 2c52788de56af..45f651fb7338e 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -830,6 +830,13 @@ pythonize_bool(COMPILER_RT_TEST_USE_LLD)
 option(COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER "Build Compiler RT linked with in LLVM symbolizer" OFF)
 mark_as_advanced(COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER)
 
+option(SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH "Disable searching for external symbolizer in $PATH" OFF)
+mark_as_advanced(SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH)
+
+if (SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH)
+    add_definitions(-DSANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH)
+endif()
+
 add_subdirectory(lib)
 
 if(COMPILER_RT_INCLUDE_TESTS)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
index 0ddc24802d216..c37d5a670c8d2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
@@ -443,23 +443,28 @@ static SymbolizerTool *ChooseExternalSymbolizer(LowLevelAllocator *allocator) {
   }
 
   // Otherwise symbolizer program is unknown, let's search $PATH
+#ifdef SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH
+   VReport(2, "Symbolizer path search is disabled\n");
+   return nullptr;
+#else 
   CHECK(path == nullptr);
-#if SANITIZER_APPLE
-  if (const char *found_path = FindPathToBinary("atos")) {
-    VReport(2, "Using atos found at: %s\n", found_path);
-    return new(*allocator) AtosSymbolizer(found_path, allocator);
-  }
-#endif  // SANITIZER_APPLE
-  if (const char *found_path = FindPathToBinary("llvm-symbolizer")) {
-    VReport(2, "Using llvm-symbolizer found at: %s\n", found_path);
-    return new(*allocator) LLVMSymbolizer(found_path, allocator);
-  }
-  if (common_flags()->allow_addr2line) {
-    if (const char *found_path = FindPathToBinary("addr2line")) {
-      VReport(2, "Using addr2line found at: %s\n", found_path);
-      return new(*allocator) Addr2LinePool(found_path, allocator);
+  #if SANITIZER_APPLE
+    if (const char *found_path = FindPathToBinary("atos")) {
+      VReport(2, "Using atos found at: %s\n", found_path);
+      return new(*allocator) AtosSymbolizer(found_path, allocator);
     }
-  }
+  #endif  // SANITIZER_APPLE
+    if (const char *found_path = FindPathToBinary("llvm-symbolizer")) {
+      VReport(2, "Using llvm-symbolizer found at: %s\n", found_path);
+      return new(*allocator) LLVMSymbolizer(found_path, allocator);
+    }
+    if (common_flags()->allow_addr2line) {
+      if (const char *found_path = FindPathToBinary("addr2line")) {
+        VReport(2, "Using addr2line found at: %s\n", found_path);
+        return new(*allocator) Addr2LinePool(found_path, allocator);
+      }
+    }
+#endif // SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH
   return nullptr;
 }
 
diff --git a/compiler-rt/test/sanitizer_common/TestCases/disable_symbolizer_path_search b/compiler-rt/test/sanitizer_common/TestCases/disable_symbolizer_path_search
new file mode 100644
index 0000000000000..0e190f00a2a84
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/disable_symbolizer_path_search
@@ -0,0 +1,29 @@
+// REQUIRES: static-libs
+
+// RUN: %clangxx %s -o %t -DDISABLE_SYMBOLIZER_PATH_SEARCH=1
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
+
+// RUN: %clangxx %s -o %t -DDISABLE_SYMBOLIZER_PATH_SEARCH=0
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-ALLOCATOR
+
+// REQUIRES: shell
+
+// Mobile device will not have symbolizer in provided path.
+// UNSUPPORTED: ios, android
+
+#include <sanitizer/common_interface_defs.h>
+#include <stdio.h>
+
+static void Symbolize() {
+  char buffer[100];
+  __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", buffer,
+                           sizeof(buffer));
+  printf("%s\n", buffer);
+}
+
+int main() {
+  Symbolize();
+}
+
+// CHECK: Symbolizer path search is disabled
+// CHECK-ALLOCATOR: {{0x.* in main}}

>From 9e2978cd7ce72a70cdde82c3fb118c3221298b3b Mon Sep 17 00:00:00 2001
From: Midhunesh <midhunesh.p at ibm.com>
Date: Mon, 24 Feb 2025 11:49:56 +0530
Subject: [PATCH 2/3] comments fix

---
 compiler-rt/CMakeLists.txt                                      | 2 +-
 .../lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 45f651fb7338e..67133b62cd047 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -834,7 +834,7 @@ option(SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH "Disable searching for external
 mark_as_advanced(SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH)
 
 if (SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH)
-    add_definitions(-DSANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH)
+    add_compile_definitions(SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH)
 endif()
 
 add_subdirectory(lib)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
index c37d5a670c8d2..7febcf6d4ff00 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
@@ -444,7 +444,7 @@ static SymbolizerTool *ChooseExternalSymbolizer(LowLevelAllocator *allocator) {
 
   // Otherwise symbolizer program is unknown, let's search $PATH
 #ifdef SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH
-   VReport(2, "Symbolizer path search is disabled\n");
+   VReport(2, "Symbolizer path search is disabled in the runtime build configuration\n");
    return nullptr;
 #else 
   CHECK(path == nullptr);

>From e97f75dd31a6027e725fd4f0fed303f6978b8b33 Mon Sep 17 00:00:00 2001
From: Midhunesh <midhunesh.p at ibm.com>
Date: Tue, 25 Feb 2025 09:00:38 +0530
Subject: [PATCH 3/3] test file removed

---
 .../TestCases/disable_symbolizer_path_search  | 29 -------------------
 1 file changed, 29 deletions(-)
 delete mode 100644 compiler-rt/test/sanitizer_common/TestCases/disable_symbolizer_path_search

diff --git a/compiler-rt/test/sanitizer_common/TestCases/disable_symbolizer_path_search b/compiler-rt/test/sanitizer_common/TestCases/disable_symbolizer_path_search
deleted file mode 100644
index 0e190f00a2a84..0000000000000
--- a/compiler-rt/test/sanitizer_common/TestCases/disable_symbolizer_path_search
+++ /dev/null
@@ -1,29 +0,0 @@
-// REQUIRES: static-libs
-
-// RUN: %clangxx %s -o %t -DDISABLE_SYMBOLIZER_PATH_SEARCH=1
-// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
-
-// RUN: %clangxx %s -o %t -DDISABLE_SYMBOLIZER_PATH_SEARCH=0
-// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-ALLOCATOR
-
-// REQUIRES: shell
-
-// Mobile device will not have symbolizer in provided path.
-// UNSUPPORTED: ios, android
-
-#include <sanitizer/common_interface_defs.h>
-#include <stdio.h>
-
-static void Symbolize() {
-  char buffer[100];
-  __sanitizer_symbolize_pc(__builtin_return_address(0), "%p %F %L", buffer,
-                           sizeof(buffer));
-  printf("%s\n", buffer);
-}
-
-int main() {
-  Symbolize();
-}
-
-// CHECK: Symbolizer path search is disabled
-// CHECK-ALLOCATOR: {{0x.* in main}}



More information about the llvm-commits mailing list