diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp @@ -59,28 +59,19 @@ 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. +// As of now, there are no headers for the Swift runtime. Provide a weak version +// of that symbol and rely on weak symbol resolution to pick the right one. 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"); - (void)dlerror(); // Cleanup error message in case of failure -} + +extern "C" SANITIZER_WEAK_ATTRIBUTE swift_demangle_ft swift_demangle = nullptr; // 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) { - if (swift_demangle_f) - return swift_demangle_f(name, internal_strlen(name), 0, 0, 0); - + if (swift_demangle) + return swift_demangle(name, internal_strlen(name), 0, 0, 0); return nullptr; }