Skip to content

Add cmake option to enable/disable searching PATH for symbolizer #129012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

midhuncodes7
Copy link
Contributor

@midhuncodes7 midhuncodes7 commented Feb 27, 2025

Introduced a cmake option that is disabled by default that suppresses searching via the PATH variable for a symbolizer. The option will be enabled for downstream builds where the user will need to specify the symbolizer path more explicitly, e.g., by using ASAN_SYMBOLIZER_PATH.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Midhunesh (midhuncodes7)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/129012.diff

2 Files Affected:

  • (modified) compiler-rt/CMakeLists.txt (+7)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp (+20-15)
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 2c52788de56af..67133b62cd047 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_compile_definitions(SANITIZER_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..7febcf6d4ff00 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 in the runtime build configuration\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;
 }
 

@vitalybuka vitalybuka self-requested a review February 27, 2025 06:53
@vitalybuka
Copy link
Collaborator

Can you please elaborate what kind of issues you have from symbolizer?

Copy link

github-actions bot commented Feb 27, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@midhuncodes7 midhuncodes7 marked this pull request as draft February 27, 2025 07:01
Copy link
Collaborator

@hubert-reinterpretcast hubert-reinterpretcast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When compiling with this new CMake flag on, how are tests expected to pass? That is, there probably should be changes made to the testing to set up the environment variables necessary for the symbolizer to be invoked from the tests.

@hubert-reinterpretcast
Copy link
Collaborator

Can you please elaborate what kind of issues you have from symbolizer?

Disabling the search via PATH may help towards handling concerns similar to the ones expressed by https://cwe.mitre.org/data/definitions/426.html.

@vitalybuka
Copy link
Collaborator

Can you please elaborate what kind of issues you have from symbolizer?

Disabling the search via PATH may help towards handling concerns similar to the ones expressed by https://cwe.mitre.org/data/definitions/426.html.

We usually do not recommend to use sanitizers with heaver runtime in environment sensitive to such vulnerabilities.
E.g. ubsan with min runtime or trap is OK.

@hubert-reinterpretcast
Copy link
Collaborator

We usually do not recommend to use sanitizers with heaver runtime in environment sensitive to such vulnerabilities.
E.g. ubsan with min runtime or trap is OK.

Understood. However, I think it would be reasonable (as a choice by the builder of the sanitizer) to recommend against deploying said sanitizers to environments thought to be sensitive to such vulnerabilities and yet also configure the sanitizers to be less susceptible to such vulnerabilities.

@vitalybuka
Copy link
Collaborator

We usually do not recommend to use sanitizers with heaver runtime in environment sensitive to such vulnerabilities.
E.g. ubsan with min runtime or trap is OK.

Understood. However, I think it would be reasonable (as a choice by the builder of the sanitizer) to recommend against deploying said sanitizers to environments thought to be sensitive to such vulnerabilities and yet also configure the sanitizers to be less susceptible to such vulnerabilities.

SGTM.
Please ping me when it's ready for review.

@hubert-reinterpretcast
Copy link
Collaborator

Please ping me when it's ready for review.

Will do; thanks!

@hubert-reinterpretcast
Copy link
Collaborator

@midhuncodes7, I would recommend not pushing merge-from-upstream commits to a PR branch if there was no manual merge resolution needed and no substantive change to the PR.

The push causes notification noise for reviewers.

Copy link
Collaborator

@hubert-reinterpretcast hubert-reinterpretcast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor comment.
@vitalybuka, I believe that this is ready for your review.
@midhuncodes7, please wait for additional reviews before merging.

Copy link
Collaborator

@hubert-reinterpretcast hubert-reinterpretcast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another minor issue. Sorry for missing this earlier.
Otherwise LGTM.

@vitalybuka, we're looking forward to your review.

Copy link

github-actions bot commented Mar 25, 2025

✅ With the latest revision this PR passed the Python code formatter.

@vitalybuka vitalybuka merged commit d75a40a into llvm:main Mar 25, 2025
9 of 11 checks passed
Copy link

@midhuncodes7 Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 26, 2025

LLVM Buildbot has detected a new failure on builder lldb-remote-linux-ubuntu running on as-builder-9 while building compiler-rt,llvm at step 16 "test-check-lldb-api".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/195/builds/6720

Here is the relevant piece of the build log for the reference
Step 16 (test-check-lldb-api) failure: Test just built components: check-lldb-api completed (failure)
...
PASS: lldb-api :: types/TestCharTypeExpr.py (1236 of 1245)
PASS: lldb-api :: python_api/watchpoint/watchlocation/TestTargetWatchAddress.py (1237 of 1245)
PASS: lldb-api :: types/TestIntegerType.py (1238 of 1245)
PASS: lldb-api :: types/TestRecursiveTypes.py (1239 of 1245)
PASS: lldb-api :: types/TestIntegerTypeExpr.py (1240 of 1245)
PASS: lldb-api :: types/TestShortType.py (1241 of 1245)
PASS: lldb-api :: types/TestShortTypeExpr.py (1242 of 1245)
PASS: lldb-api :: types/TestLongTypes.py (1243 of 1245)
PASS: lldb-api :: types/TestLongTypesExpr.py (1244 of 1245)
TIMEOUT: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py (1245 of 1245)
******************** TEST 'lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py' FAILED ********************
Script:
--
/usr/bin/python3.12 /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin --libcxx-include-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/c++/v1 --libcxx-include-target-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/aarch64-unknown-linux-gnu/c++/v1 --libcxx-library-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib/aarch64-unknown-linux-gnu --arch aarch64 --build-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/lldb --compiler /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang --dsymutil /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin --lldb-obj-root /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb --lldb-libs-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib --platform-url connect://jetson-agx-2198.lab.llvm.org:1234 --platform-working-dir /home/ubuntu/lldb-tests --sysroot /mnt/fs/jetson-agx-ubuntu --env ARCH_CFLAGS=-mcpu=cortex-a78 --platform-name remote-linux --skip-category=lldb-server /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/python_api/process/cancel_attach -p TestCancelAttach.py
--
Exit Code: -9
Timeout: Reached timeout of 600 seconds

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision d75a40a9c1817ca047dec9cf0e1c0f1fec948e06)
  clang revision d75a40a9c1817ca047dec9cf0e1c0f1fec948e06
  llvm revision d75a40a9c1817ca047dec9cf0e1c0f1fec948e06

--
Command Output (stderr):
--
WARNING:root:Custom libc++ is not supported for remote runs: ignoring --libcxx arguments
FAIL: LLDB (/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang-aarch64) :: test_scripted_implementation (TestCancelAttach.AttachCancelTestCase.test_scripted_implementation)

--

********************
Slowest Tests:
--------------------------------------------------------------------------
600.04s: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py
181.00s: lldb-api :: commands/command/script_alias/TestCommandScriptAlias.py
70.37s: lldb-api :: commands/process/attach/TestProcessAttach.py
40.68s: lldb-api :: functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
35.00s: lldb-api :: functionalities/completion/TestCompletion.py
33.89s: lldb-api :: functionalities/single-thread-step/TestSingleThreadStepTimeout.py
23.67s: lldb-api :: python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
20.66s: lldb-api :: functionalities/gdb_remote_client/TestPlatformClient.py
20.42s: lldb-api :: commands/statistics/basic/TestStats.py
19.00s: lldb-api :: functionalities/thread/state/TestThreadStates.py
18.08s: lldb-api :: commands/dwim-print/TestDWIMPrint.py
14.67s: lldb-api :: commands/expression/expr-in-syscall/TestExpressionInSyscall.py
14.59s: lldb-api :: functionalities/data-formatter/data-formatter-stl/generic/set/TestDataFormatterGenericSet.py
14.21s: lldb-api :: python_api/find_in_memory/TestFindRangesInMemory.py

hubert-reinterpretcast added a commit to hubert-reinterpretcast/llvm-zorg that referenced this pull request Mar 27, 2025
llvm/llvm-project#129012 added a new CMake flag. This flag is used by IBM's downstream builds.

This patch sets the flag on the community buildbot for AIX to ensure upstream coverage and visibility.
hubert-reinterpretcast added a commit to llvm/llvm-zorg that referenced this pull request Apr 1, 2025
llvm/llvm-project#129012 added a new CMake flag. This flag is used by
IBM's downstream builds.

This patch sets the flag on the community buildbots (Clang and Flang)
for AIX to ensure upstream coverage and visibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants