summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-05-06 08:54:58 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-05-06 08:54:58 +0000
commitef6211fc976514001c798402868fdd8b7723d4e3 (patch)
treef9e5a1e39dd32508d4f82203fb764235726dad53 /lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
parenteb329343b949cf2485ce0e7c776f594e14f4df1a (diff)
[sanitizer] Fix a crash when demangling Swift symbols
To invoke the Swift demangler, we use dlsym to locate swift_demangle. However, dlsym malloc's storage and stores it in thread-local storage. Since allocations from the symbolizer are done with the system allocator (at least in TSan, interceptors are skipped when inside the symbolizer), we will crash when we try to deallocate later using the sanitizer allocator again. To fix this, let's just not call dlsym from the demangler, and call it during initialization. Differential Revision: http://reviews.llvm.org/D19974 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@268716 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.cc26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc b/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
index de1a979bc..2272f61a9 100644
--- a/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
@@ -63,6 +63,20 @@ const char *DemangleCXXABI(const char *name) {
return name;
}
+// As of now, there are no headers for the Swift runtime. Once they are
+// present, we will weakly link since we do not require Swift runtime to be
+// linked.
+typedef char *(*swift_demangle_ft)(const char *mangledName,
+ size_t mangledNameLength, char *outputBuffer,
+ size_t *outputBufferSize, uint32_t flags);
+static swift_demangle_ft swift_demangle_f;
+
+// This must not happen lazily, because dlsym uses thread-local storage, which
+// is not a good thing to do during symbolication.
+static void InitializeSwiftDemangler() {
+ swift_demangle_f = (swift_demangle_ft)dlsym(RTLD_DEFAULT, "swift_demangle");
+}
+
// Attempts to demangle a Swift name. The demangler will return nullptr
/// if a non-Swift name is passed in.
const char *DemangleSwift(const char *name) {
@@ -72,16 +86,6 @@ const char *DemangleSwift(const char *name) {
return nullptr;
}
- // As of now, there are no headers for the Swift runtime. Once they are
- // present, we will weakly link since we do not require Swift runtime to be
- // linked.
- typedef char *(*swift_demangle_ft)(const char *mangledName,
- size_t mangledNameLength,
- char *outputBuffer,
- size_t *outputBufferSize,
- uint32_t flags);
- swift_demangle_ft swift_demangle_f =
- (swift_demangle_ft) dlsym(RTLD_DEFAULT, "swift_demangle");
if (swift_demangle_f)
return swift_demangle_f(name, internal_strlen(name), 0, 0, 0);
@@ -479,6 +483,8 @@ static void ChooseSymbolizerTools(IntrusiveList<SymbolizerTool> *list,
}
Symbolizer *Symbolizer::PlatformInit() {
+ InitializeSwiftDemangler();
+
IntrusiveList<SymbolizerTool> list;
list.clear();
ChooseSymbolizerTools(&list, &symbolizer_allocator_);