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

Reid Kleckner rnk at google.com
Fri Feb 27 13:38:59 PST 2015


- Ensure symbols starting with '?' get private prefixes


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
@@ -113,13 +113,22 @@
   }
 
   StringRef Name = GV->getName();
+
   char Prefix = DL->getGlobalPrefix();
 
   // 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);
   if (Name.startswith("\01"))
-    MSFunc = nullptr; // Don't mangle when \01 is present.
+    MSFunc = nullptr; // Don't mangle when the first character is '\01'.
+
+  // Don't add prefixes or MS suffixes for symbols starting with '?'.  Add the
+  // private global prefix if necessary, though.
+  if (Name.startswith("?")) {
+    MSFunc = nullptr;
+    Prefix = '\0';
+  }
+
   CallingConv::ID CC =
       MSFunc ? MSFunc->getCallingConv() : (unsigned)CallingConv::C;
   if (!DL->hasMicrosoftFastStdCallMangling() &&
Index: test/MC/COFF/symbol-mangling.ll
===================================================================
--- test/MC/COFF/symbol-mangling.ll
+++ test/MC/COFF/symbol-mangling.ll
@@ -1,17 +1,33 @@
 ; The purpose of this test is to see if the MC layer properly handles symbol
 ; names needing quoting on MS/Windows. This code is generated by clang when
-; using -cxx-abi microsoft.
+; using -cxx-abi microsoft. At some point, we'd like to stop using the '\01'
+; escape and just use a leading '?'.
 
 ; RUN: llc -filetype=asm -mtriple i686-pc-win32 %s -o - | FileCheck %s
 
-; CHECK: ?sayhi at A@@QBEXXZ
+; CHECK: calll "?withescape at A@@QBEXXZ"
+; CHECK: calll "?withquestion at A@@QBEXXZ"
+; CHECK: calll "L?privatequestion at A@@QBEXXZ"
+; CHECK: calll "L?privatequestionfast at A@@QBEXXZ"
 
 %struct.A = type {}
 
 define i32 @main() {
 entry:
-  tail call void @"\01?sayhi at A@@QBEXXZ"(%struct.A* null)
+  tail call void @"\01?withescape at A@@QBEXXZ"(%struct.A* null)
+  tail call void @"?withquestion at A@@QBEXXZ"(%struct.A* null)
+  tail call void @"?privatequestion at A@@QBEXXZ"(%struct.A* null)
+  tail call void @"?privatequestionfast at A@@QBEXXZ"(%struct.A* null)
   ret i32 0
 }
 
-declare void @"\01?sayhi at A@@QBEXXZ"(%struct.A*)
+declare void @"\01?withescape at A@@QBEXXZ"(%struct.A*)
+declare void @"?withquestion at A@@QBEXXZ"(%struct.A*)
+
+define private void @"?privatequestion at A@@QBEXXZ"(%struct.A*) {
+  ret void
+}
+
+define private void @"?privatequestionfast at A@@QBEXXZ"(%struct.A*) {
+  ret void
+}
Index: test/MC/COFF/tricky-names.ll
===================================================================
--- test/MC/COFF/tricky-names.ll
+++ test/MC/COFF/tricky-names.ll
@@ -3,14 +3,16 @@
 
 ; 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
+; RUN: llc -mtriple=x86_64-pc-win32 %s -o - | llvm-mc -triple x86_64-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.20893.patch
Type: text/x-patch
Size: 3902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150227/09babf20/attachment.bin>


More information about the llvm-commits mailing list