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,21 +59,16 @@ 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; + +static swift_demangle_ft swift_demangle_f; +static void InitializeSwiftDemangler() { swift_demangle_f = swift_demangle; } // Attempts to demangle a Swift name. The demangler will return nullptr if a // non-Swift name is passed in.