Bug 1489094 - Properly demangle build-specific LLVM signatures on Windows r=ted
authorGabriele Svelto <gsvelto@mozilla.com>
Fri, 14 Dec 2018 10:01:14 +0000
changeset 450506 a01ad4f60152ddfe5f158c4aea91c7003c7fbb33
parent 450505 e3d27539c265e2e34d52bd0ea9b284798ba71c98
child 450531 f78271559c2ee53d24c5248715a9d06cb48dc6b8
child 450533 774451e25c49d07df4155455b90140c396a4e53b
push id35203
push userrmaries@mozilla.com
push dateFri, 14 Dec 2018 16:18:46 +0000
treeherdermozilla-central@a01ad4f60152 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1489094
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1489094 - Properly demangle build-specific LLVM signatures on Windows r=ted Differential Revision: https://phabricator.services.mozilla.com/D14387
toolkit/crashreporter/google-breakpad/src/common/windows/pdb_source_line_writer.cc
toolkit/crashreporter/google-breakpad/src/tools/windows/dump_syms/moz.build
--- a/toolkit/crashreporter/google-breakpad/src/common/windows/pdb_source_line_writer.cc
+++ b/toolkit/crashreporter/google-breakpad/src/common/windows/pdb_source_line_writer.cc
@@ -1019,34 +1019,50 @@ bool PDBSourceLineWriter::FindPEFile() {
         }
       }
     }
   }
 
   return false;
 }
 
+static const DWORD kUndecorateOptions =
+    UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_FUNCTION_RETURNS |
+    UNDNAME_NO_ALLOCATION_MODEL | UNDNAME_NO_ALLOCATION_LANGUAGE |
+    UNDNAME_NO_THISTYPE | UNDNAME_NO_ACCESS_SPECIFIERS |
+    UNDNAME_NO_THROW_SIGNATURES | UNDNAME_NO_MEMBER_TYPE |
+    UNDNAME_NO_RETURN_UDT_MODEL | UNDNAME_NO_ECSU;
+
+static void FixupLlvmUniqueSymbol(BSTR *name) {
+  wchar_t *suffix = wcsstr(*name, L".llvm.");
+
+  if (suffix != nullptr) {
+    *suffix = L'\0';
+
+    const size_t undecorated_len = 1024;
+    wchar_t undecorated[undecorated_len] = {};
+    DWORD res = UnDecorateSymbolNameW(*name, undecorated, undecorated_len,
+                                      kUndecorateOptions);
+    if (res == 0) {
+      fprintf(stderr, "failed to undecorate symbol %S\n", *name);
+    } else {
+      SysFreeString(*name);
+      *name = SysAllocString(undecorated);
+    }
+  }
+}
+
 // static
 bool PDBSourceLineWriter::GetSymbolFunctionName(IDiaSymbol *function,
                                                 BSTR *name,
                                                 int *stack_param_size) {
   *stack_param_size = -1;
-  const DWORD undecorate_options = UNDNAME_NO_MS_KEYWORDS |
-                                   UNDNAME_NO_FUNCTION_RETURNS |
-                                   UNDNAME_NO_ALLOCATION_MODEL |
-                                   UNDNAME_NO_ALLOCATION_LANGUAGE |
-                                   UNDNAME_NO_THISTYPE |
-                                   UNDNAME_NO_ACCESS_SPECIFIERS |
-                                   UNDNAME_NO_THROW_SIGNATURES |
-                                   UNDNAME_NO_MEMBER_TYPE |
-                                   UNDNAME_NO_RETURN_UDT_MODEL |
-                                   UNDNAME_NO_ECSU;
 
   // Use get_undecoratedNameEx to get readable C++ names with arguments.
-  if (function->get_undecoratedNameEx(undecorate_options, name) != S_OK) {
+  if (function->get_undecoratedNameEx(kUndecorateOptions, name) != S_OK) {
     if (function->get_name(name) != S_OK) {
       fprintf(stderr, "failed to get function name\n");
       return false;
     }
 
     // It's possible for get_name to return an empty string, so
     // special-case that.
     if (wcscmp(*name, L"") == 0) {
@@ -1060,16 +1076,18 @@ bool PDBSourceLineWriter::GetSymbolFunct
     // it's already formatted properly to be used as output.  Don't do any
     // additional processing.
     //
     // MSVC7's DIA seems to not undecorate names in as many cases as MSVC8's.
     // This will result in calling get_name for some C++ symbols, so
     // all of the parameter and return type information may not be included in
     // the name string.
   } else {
+    FixupLlvmUniqueSymbol(name);
+
     // C++ uses a bogus "void" argument for functions and methods that don't
     // take any parameters.  Take it out of the undecorated name because it's
     // ugly and unnecessary.
     const wchar_t *replace_string = L"(void)";
     const size_t replace_length = wcslen(replace_string);
     const wchar_t *replacement_string = L"()";
     size_t length = wcslen(*name);
     if (length >= replace_length) {
--- a/toolkit/crashreporter/google-breakpad/src/tools/windows/dump_syms/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/tools/windows/dump_syms/moz.build
@@ -17,15 +17,16 @@ HOST_SOURCES += [
 
 HOST_CXXFLAGS += [
     '-O2',
     '-EHsc',
     '-MD'
 ]
 
 HOST_OS_LIBS += [
+    'dbghelp',
     'diaguids',
-    'imagehlp'
+    'imagehlp',
 ]
 
 LOCAL_INCLUDES += [
     '../../..'
 ]