summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc')
-rw-r--r--lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc37
1 files changed, 23 insertions, 14 deletions
diff --git a/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc b/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
index de1a979bc..097fafeb7 100644
--- a/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
@@ -63,25 +63,29 @@ const char *DemangleCXXABI(const char *name) {
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 @@ Symbolizer *Symbolizer::PlatformInit() {
return new(symbolizer_allocator_) Symbolizer(list);
}
+void Symbolizer::LateInitialize() {
+ Symbolizer::GetOrInit();
+ InitializeSwiftDemangler();
+}
+
} // namespace __sanitizer
#endif // SANITIZER_POSIX