mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 12:06:36 +00:00
Add cmake option to enable/disable searching PATH for symbolizer (#129012)
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.
This commit is contained in:
parent
bff94d774c
commit
d75a40a9c1
@ -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)
|
||||
|
@ -448,13 +448,19 @@ 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 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
|
||||
# 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);
|
||||
@ -466,6 +472,7 @@ static SymbolizerTool *ChooseExternalSymbolizer(LowLevelAllocator *allocator) {
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
# endif // SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH
|
||||
}
|
||||
|
||||
static void ChooseSymbolizerTools(IntrusiveList<SymbolizerTool> *list,
|
||||
|
@ -10,6 +10,8 @@ pythonize_bool(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC)
|
||||
|
||||
pythonize_bool(COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER)
|
||||
|
||||
pythonize_bool(SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH)
|
||||
|
||||
pythonize_bool(COMPILER_RT_HAS_AARCH64_SME)
|
||||
|
||||
pythonize_bool(COMPILER_RT_HAS_NO_DEFAULT_CONFIG_FLAG)
|
||||
|
@ -330,6 +330,10 @@ if config.have_zlib:
|
||||
if config.have_internal_symbolizer:
|
||||
config.available_features.add("internal_symbolizer")
|
||||
|
||||
if config.have_disable_symbolizer_path_search:
|
||||
config.available_features.add("disable_symbolizer_path_search")
|
||||
|
||||
|
||||
# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
|
||||
# in RUN lines.
|
||||
config.substitutions.append(
|
||||
@ -372,6 +376,30 @@ def get_ios_commands_dir():
|
||||
)
|
||||
|
||||
|
||||
# When cmake flag to disable path search is set, symbolizer is not allowed to search in $PATH,
|
||||
# need to specify it via XXX_SYMBOLIZER_PATH
|
||||
tool_symbolizer_path_list = [
|
||||
"ASAN_SYMBOLIZER_PATH",
|
||||
"HWASAN_SYMBOLIZER_PATH",
|
||||
"RTSAN_SYMBOLIZER_PATH",
|
||||
"TSAN_SYMBOLIZER_PATH",
|
||||
"MSAN_SYMBOLIZER_PATH",
|
||||
"LSAN_SYMBOLIZER_PATH",
|
||||
"UBSAN_SYMBOLIZER_PATH",
|
||||
]
|
||||
|
||||
if config.have_disable_symbolizer_path_search:
|
||||
symbolizer_path = os.path.join(config.llvm_tools_dir, "llvm-symbolizer")
|
||||
|
||||
for sanitizer in tool_symbolizer_path_list:
|
||||
if sanitizer not in config.environment:
|
||||
config.environment[sanitizer] = symbolizer_path
|
||||
|
||||
env_unset_command = " ".join(f"-u {var}" for var in tool_symbolizer_path_list)
|
||||
config.substitutions.append(
|
||||
("%env_unset_tool_symbolizer_path", f"env {env_unset_command}")
|
||||
)
|
||||
|
||||
# Allow tests to be executed on a simulator or remotely.
|
||||
if emulator:
|
||||
config.substitutions.append(("%run", emulator))
|
||||
|
@ -72,6 +72,7 @@ else:
|
||||
set_default("target_suffix", "-%s" % config.target_arch)
|
||||
|
||||
set_default("have_internal_symbolizer", @COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER_PYBOOL@)
|
||||
set_default("have_disable_symbolizer_path_search", @SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH_PYBOOL@)
|
||||
set_default("have_zlib", @ZLIB_FOUND_PYBOOL@)
|
||||
set_default("zlib_include_dir", "@ZLIB_INCLUDE_DIR@")
|
||||
set_default("zlib_library", "@ZLIB_LIBRARY@")
|
||||
|
@ -0,0 +1,19 @@
|
||||
// REQUIRES: disable_symbolizer_path_search
|
||||
|
||||
// RUN: %clangxx %s -o %t
|
||||
// RUN: %env_unset_tool_symbolizer_path \
|
||||
// RUN: %env_tool_opts=verbosity=3 %run %t 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: Symbolizer path search is disabled in the runtime build configuration
|
||||
|
||||
#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(); }
|
@ -53,6 +53,7 @@ write_cmake_config("lit_common_configured") {
|
||||
"COMPILER_RT_BUILD_STANDALONE_LIBATOMIC_PYBOOL=False",
|
||||
"COMPILER_RT_DEBUG_PYBOOL=False",
|
||||
"COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER_PYBOOL=False",
|
||||
"SANITIZER_DISABLE_SYMBOLIZER_PATH_SEARCH_PYBOOL=False",
|
||||
"COMPILER_RT_HAS_NO_DEFAULT_CONFIG_FLAG_PYBOOL=True",
|
||||
"COMPILER_RT_INTERCEPT_LIBDISPATCH_PYBOOL=False",
|
||||
"COMPILER_RT_RESOLVED_EXEC_OUTPUT_DIR=" +
|
||||
|
Loading…
x
Reference in New Issue
Block a user