[PATCH] D19974: [sanitizer] Fix a crash when demangling Swift symbols

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 02:00:56 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL268716: [sanitizer] Fix a crash when demangling Swift symbols (authored by kuba.brecka).

Changed prior to commit:
  http://reviews.llvm.org/D19974?vs=56285&id=56388#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19974

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc

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,6 +63,20 @@
   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 @@
     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 @@
 }
 
 Symbolizer *Symbolizer::PlatformInit() {
+  InitializeSwiftDemangler();
+
   IntrusiveList<SymbolizerTool> list;
   list.clear();
   ChooseSymbolizerTools(&list, &symbolizer_allocator_);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19974.56388.patch
Type: text/x-patch
Size: 2133 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160506/69252ba9/attachment.bin>


More information about the llvm-commits mailing list