Index: compiler-rt/trunk/lib/asan/asan_rtl.cc =================================================================== --- compiler-rt/trunk/lib/asan/asan_rtl.cc +++ compiler-rt/trunk/lib/asan/asan_rtl.cc @@ -553,6 +553,8 @@ InitializeSuppressions(); + Symbolizer::LateInitialize(); + VReport(1, "AddressSanitizer Init done\n"); } Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h @@ -82,6 +82,7 @@ /// Initialize and return platform-specific implementation of symbolizer /// (if it wasn't already initialized). static Symbolizer *GetOrInit(); + static void LateInitialize(); // Returns a list of symbolized frames for a given address (containing // all inlined functions, if necessary). SymbolizedStack *SymbolizePC(uptr address); Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc @@ -63,25 +63,29 @@ return name; } -// Attempts to demangle a Swift name. The demangler will return nullptr -/// if a non-Swift name is passed in. +// 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 at symbolication time, because dlsym uses +// malloc and 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) { - // Not to call dlsym every time we demangle, check if we are dealing with - // Swift mangled name first. + // Check if we are dealing with a Swift mangled name first. if (name[0] != '_' || name[1] != 'T') { 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); @@ -485,6 +489,11 @@ return new(symbolizer_allocator_) Symbolizer(list); } +void Symbolizer::LateInitialize() { + Symbolizer::GetOrInit(); + InitializeSwiftDemangler(); +} + } // namespace __sanitizer #endif // SANITIZER_POSIX Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc @@ -279,6 +279,10 @@ return new(symbolizer_allocator_) Symbolizer(list); } +void Symbolizer::LateInitialize() { + Symbolizer::GetOrInit(); +} + } // namespace __sanitizer #endif // _WIN32 Index: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc =================================================================== --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc @@ -370,6 +370,8 @@ #endif ctx->initialized = true; + Symbolizer::LateInitialize(); + if (flags()->stop_on_start) { Printf("ThreadSanitizer is suspended at startup (pid %d)." " Call __tsan_resume().\n",