Skip to content

Commit b87543c

Browse files
author
George Karpenkov
committed
Prefer atos to llvm-symbolizer on Darwin
atos is the default symbolizer on Apple's compiler for quite a few years now. llvm-symbolizer is quite fragile on Darwin: for example, unless a .dSYM file was explicitly generated symbolication would not work. It is also very convenient when the behavior of LLVM open source compiler matches to that of Apple's compiler on Apple's platform. Furthermore, llvm-symbolizer is not installed on Apple's platform by default, which leads to strange behavior during debugging: the test might fail under lit (where it has llvm-symbolizer) but would run properly when launched on the command line (where it does not, and atos would be used). Indeed, there's a downside: atos does not work properly with inlined functions, hence the test change. We do not think that this is a major problem, as users would often compile with -O0 when debugging, and in any case it is preferable to symbolizer not being able to symbolize. Differential Revision: https://reviews.llvm.org/D35745 llvm-svn: 308908
1 parent e6f1b72 commit b87543c

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,16 @@ static SymbolizerTool *ChooseExternalSymbolizer(LowLevelAllocator *allocator) {
471471

472472
// Otherwise symbolizer program is unknown, let's search $PATH
473473
CHECK(path == nullptr);
474-
if (const char *found_path = FindPathToBinary("llvm-symbolizer")) {
475-
VReport(2, "Using llvm-symbolizer found at: %s\n", found_path);
476-
return new(*allocator) LLVMSymbolizer(found_path, allocator);
477-
}
478474
#if SANITIZER_MAC
479475
if (const char *found_path = FindPathToBinary("atos")) {
480476
VReport(2, "Using atos found at: %s\n", found_path);
481477
return new(*allocator) AtosSymbolizer(found_path, allocator);
482478
}
483479
#endif // SANITIZER_MAC
480+
if (const char *found_path = FindPathToBinary("llvm-symbolizer")) {
481+
VReport(2, "Using llvm-symbolizer found at: %s\n", found_path);
482+
return new(*allocator) LLVMSymbolizer(found_path, allocator);
483+
}
484484
if (common_flags()->allow_addr2line) {
485485
if (const char *found_path = FindPathToBinary("addr2line")) {
486486
VReport(2, "Using addr2line found at: %s\n", found_path);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Check that without suppressions, we catch the issue.
2+
// RUN: %clangxx_asan -O0 %s -o %t
3+
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
4+
5+
// RUN: echo "interceptor_via_fun:crash_function" > %t.supp
6+
// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
7+
8+
// UNSUPPORTED: ios
9+
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
#include <string.h>
13+
14+
void crash_function() {
15+
char *a = (char *)malloc(6);
16+
free(a);
17+
size_t len = strlen(a); // BOOM
18+
fprintf(stderr, "strlen ignored, len = %zu\n", len);
19+
}
20+
21+
int main() {
22+
crash_function();
23+
}
24+
25+
// CHECK-CRASH: AddressSanitizer: heap-use-after-free
26+
// CHECK-CRASH-NOT: strlen ignored
27+
// CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free
28+
// CHECK-IGNORE: strlen ignored

compiler-rt/test/asan/TestCases/suppressions-function.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
// XFAIL: android,win32
1111
// UNSUPPORTED: ios
1212

13+
// FIXME: atos does not work for inlined functions, yet llvm-symbolizer
14+
// does not always work with debug info on Darwin.
15+
// UNSUPPORTED: darwin
16+
1317
#include <stdio.h>
1418
#include <stdlib.h>
1519
#include <string.h>

0 commit comments

Comments
 (0)