[PATCH] Mangler: Don't prefix MS ABI names with a leading ? character

Reid Kleckner rnk at google.com
Thu Feb 19 15:57:10 PST 2015


Hi rafael, majnemer,

Names with a leading ? are very common when targetting the MS C++ ABI.
Allow them through the mangler unmolested so we don't need to use so
many escapes.

http://reviews.llvm.org/D7775

Files:
  lib/IR/Mangler.cpp
  test/MC/COFF/symbol-mangling.ll
  test/MC/COFF/tricky-names.ll

Index: lib/IR/Mangler.cpp
===================================================================
--- lib/IR/Mangler.cpp
+++ lib/IR/Mangler.cpp
@@ -115,6 +115,13 @@
   StringRef Name = GV->getName();
   char Prefix = DL->getGlobalPrefix();
 
+  // Exit early if this is a Microsoft C++ name starting with '?'. In this
+  // mangling mode, we never apply prefixes or suffixes to these names.
+  if (DL->hasMicrosoftFastStdCallMangling() && Name.startswith("?")) {
+    OS << Name;
+    return;
+  }
+
   // Mangle functions with Microsoft calling conventions specially.  Only do
   // this mangling for x86_64 vectorcall and 32-bit x86.
   const Function *MSFunc = dyn_cast<Function>(GV);
Index: test/MC/COFF/symbol-mangling.ll
===================================================================
--- test/MC/COFF/symbol-mangling.ll
+++ test/MC/COFF/symbol-mangling.ll
@@ -4,14 +4,14 @@
 
 ; RUN: llc -filetype=asm -mtriple i686-pc-win32 %s -o - | FileCheck %s
 
-; CHECK: ?sayhi at A@@QBEXXZ
+; CHECK: "?sayhi at A@@QBEXXZ"
 
 %struct.A = type {}
 
 define i32 @main() {
 entry:
-  tail call void @"\01?sayhi at A@@QBEXXZ"(%struct.A* null)
+  tail call void @"?sayhi at A@@QBEXXZ"(%struct.A* null)
   ret i32 0
 }
 
-declare void @"\01?sayhi at A@@QBEXXZ"(%struct.A*)
+declare void @"?sayhi at A@@QBEXXZ"(%struct.A*)
Index: test/MC/COFF/tricky-names.ll
===================================================================
--- test/MC/COFF/tricky-names.ll
+++ test/MC/COFF/tricky-names.ll
@@ -4,13 +4,14 @@
 ; Check that we can roundtrip these names through our assembler.
 ; RUN: llc -mtriple=i686-pc-win32 %s -o - | llvm-mc -triple i686-pc-win32 -filetype=obj | llvm-readobj -t | FileCheck %s --check-prefix=READOBJ
 
+; We don't need the \01 prefix for MSVC symbols using ?.
 
-@"\01??__E_Generic_object@?$_Error_objects at H@std@@YAXXZ" = global i32 0
+@"??__E_Generic_object@?$_Error_objects at H@std@@YAXXZ" = global i32 0
 @"\01__ZL16ExceptionHandlerP19_EXCEPTION_POINTERS at 4" = global i32 0
 @"\01 at foo.bar" = global i32 0
 
-define weak i32 @"\01??_B?$num_put at _WV?$back_insert_iterator at V?$basic_string at _WU?$char_traits at _W@std@@V?$allocator at _W@2@@std@@@std@@@std@@51"() section ".text" {
-  %a = load i32* @"\01??__E_Generic_object@?$_Error_objects at H@std@@YAXXZ"
+define weak i32 @"??_B?$num_put at _WV?$back_insert_iterator at V?$basic_string at _WU?$char_traits at _W@std@@V?$allocator at _W@2@@std@@@std@@@std@@51"() section ".text" {
+  %a = load i32* @"??__E_Generic_object@?$_Error_objects at H@std@@YAXXZ"
   %b = load i32* @"\01__ZL16ExceptionHandlerP19_EXCEPTION_POINTERS at 4"
   %c = load i32* @"\01 at foo.bar"
   %x = add i32 %a, %b

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7775.20352.patch
Type: text/x-patch
Size: 2597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150219/49019c3e/attachment.bin>


More information about the llvm-commits mailing list