diff options
author | Kuba Brecka <kuba.brecka@gmail.com> | 2015-03-22 10:02:50 +0000 |
---|---|---|
committer | Kuba Brecka <kuba.brecka@gmail.com> | 2015-03-22 10:02:50 +0000 |
commit | 685b17119930a915deae176e483e29ed751fd1a9 (patch) | |
tree | b94943561639f1f4026f8a89b6459e2039e3cf98 /lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc | |
parent | fd082c74ce297319e0df868aff1406b466abd4ce (diff) |
Add AtosSymbolizer and DlAddrSymbolizer as fallbacks for OS X
This patch changes the symbolizer chain on OS X (which currently only uses 1
symbolizer at most) to use this behavior:
* By default, use LLVMSymbolizer -> DlAddrSymbolizer.
* If the llvm-symbolizer binary is not found, use AtosSymbolizer
-> DlAddrSymbolizer.
* If the user specifies ASAN_SYMBOLIZER_PATH=.../atos, then use AtosSymbolizer
-> DlAddrSymbolizer.
* If neither llvm-symbolizer or atos is found, or external symbolication is
disabled with ASAN_SYMBOLIZER_PATH="", use DlAddrSymbolizer.
Reviewed at http://reviews.llvm.org/D8285
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@232908 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc | 95 |
1 files changed, 67 insertions, 28 deletions
diff --git a/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc b/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc index ceb0de534..efd284d5b 100644 --- a/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc @@ -23,6 +23,7 @@ #include "sanitizer_procmaps.h" #include "sanitizer_symbolizer_internal.h" #include "sanitizer_symbolizer_libbacktrace.h" +#include "sanitizer_symbolizer_mac.h" #include <unistd.h> @@ -413,49 +414,87 @@ class POSIXSymbolizer : public Symbolizer { bool modules_fresh_; }; -static SymbolizerTool *ChooseSymbolizer(LowLevelAllocator *allocator) { +static SymbolizerTool *ChooseExternalSymbolizer(LowLevelAllocator *allocator) { + const char *path = common_flags()->external_symbolizer_path; + const char *binary_name = path ? StripModuleName(path) : ""; + if (path && path[0] == '\0') { + VReport(2, "External symbolizer is explicitly disabled.\n"); + return nullptr; + } else if (!internal_strcmp(binary_name, "llvm-symbolizer")) { + VReport(2, "Using llvm-symbolizer at user-specified path: %s\n", path); + return new(*allocator) LLVMSymbolizer(path, allocator); + } else if (!internal_strcmp(binary_name, "atos")) { +#if SANITIZER_MAC + VReport(2, "Using atos at user-specified path: %s\n", path); + return new(*allocator) AtosSymbolizer(path, allocator); +#else // SANITIZER_MAC + Report("ERROR: Using `atos` is only supported on Darwin.\n"); + Die(); +#endif // SANITIZER_MAC + } else if (!internal_strcmp(binary_name, "addr2line")) { + VReport(2, "Using addr2line at user-specified path: %s\n", path); + return new(*allocator) Addr2LinePool(path, allocator); + } else if (path) { + Report("ERROR: External symbolizer path is set to '%s' which isn't " + "a known symbolizer. Please set the path to the llvm-symbolizer " + "binary or other known tool.\n", path); + Die(); + } + + // Otherwise symbolizer program is unknown, let's search $PATH + CHECK(path == nullptr); + 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 SANITIZER_MAC + 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_MAC + 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); + } + } + return nullptr; +} + +static void ChooseSymbolizerTools(IntrusiveList<SymbolizerTool> *list, + LowLevelAllocator *allocator) { if (!common_flags()->symbolize) { VReport(2, "Symbolizer is disabled.\n"); - return nullptr; + return; } if (SymbolizerTool *tool = InternalSymbolizer::get(allocator)) { VReport(2, "Using internal symbolizer.\n"); - return tool; + list->push_back(tool); + return; } if (SymbolizerTool *tool = LibbacktraceSymbolizer::get(allocator)) { VReport(2, "Using libbacktrace symbolizer.\n"); - return tool; - } - const char *path_to_external = common_flags()->external_symbolizer_path; - if (path_to_external && path_to_external[0] == '\0') { - // External symbolizer is explicitly disabled. Do nothing. - return nullptr; + list->push_back(tool); + return; } - // Find path to llvm-symbolizer if it's not provided. - if (!path_to_external) { - path_to_external = FindPathToBinary("llvm-symbolizer"); - } - if (path_to_external) { - VReport(2, "Using llvm-symbolizer at path: %s\n", path_to_external); - return new(*allocator) LLVMSymbolizer(path_to_external, allocator); - } - if (common_flags()->allow_addr2line) { - // If llvm-symbolizer is not found, try to use addr2line. - if (const char *addr2line_path = FindPathToBinary("addr2line")) { - VReport(2, "Using addr2line at path: %s\n", addr2line_path); - return new(*allocator) Addr2LinePool(addr2line_path, allocator); - } + + if (SymbolizerTool *tool = ChooseExternalSymbolizer(allocator)) { + list->push_back(tool); + } else { + VReport(2, "No internal or external symbolizer found.\n"); } - VReport(2, "No internal or external symbolizer found.\n"); - return nullptr; + +#if SANITIZER_MAC + VReport(2, "Using dladdr symbolizer.\n"); + list->push_back(new(*allocator) DlAddrSymbolizer()); +#endif // SANITIZER_MAC } Symbolizer *Symbolizer::PlatformInit() { IntrusiveList<SymbolizerTool> list; list.clear(); - if (SymbolizerTool *tool = ChooseSymbolizer(&symbolizer_allocator_)) { - list.push_back(tool); - } + ChooseSymbolizerTools(&list, &symbolizer_allocator_); return new(symbolizer_allocator_) POSIXSymbolizer(list); } |