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(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@A@@QBEXXZ +; CHECK: calll "?withescape@A@@QBEXXZ" +; CHECK: calll "?withquestion@A@@QBEXXZ" +; CHECK: calll "L?privatequestion@A@@QBEXXZ" +; CHECK: calll "L?privatequestionfast@A@@QBEXXZ" %struct.A = type {} define i32 @main() { entry: - tail call void @"\01?sayhi@A@@QBEXXZ"(%struct.A* null) + tail call void @"\01?withescape@A@@QBEXXZ"(%struct.A* null) + tail call void @"?withquestion@A@@QBEXXZ"(%struct.A* null) + tail call void @"?privatequestion@A@@QBEXXZ"(%struct.A* null) + tail call void @"?privatequestionfast@A@@QBEXXZ"(%struct.A* null) ret i32 0 } -declare void @"\01?sayhi@A@@QBEXXZ"(%struct.A*) +declare void @"\01?withescape@A@@QBEXXZ"(%struct.A*) +declare void @"?withquestion@A@@QBEXXZ"(%struct.A*) + +define private void @"?privatequestion@A@@QBEXXZ"(%struct.A*) { + ret void +} + +define private void @"?privatequestionfast@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@H@std@@YAXXZ" = global i32 0 +@"??__E_Generic_object@?$_Error_objects@H@std@@YAXXZ" = global i32 0 @"\01__ZL16ExceptionHandlerP19_EXCEPTION_POINTERS@4" = global i32 0 @"\01@foo.bar" = global i32 0 -define weak i32 @"\01??_B?$num_put@_WV?$back_insert_iterator@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@std@@@std@@51"() section ".text" { - %a = load i32* @"\01??__E_Generic_object@?$_Error_objects@H@std@@YAXXZ" +define weak i32 @"??_B?$num_put@_WV?$back_insert_iterator@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@std@@@std@@51"() section ".text" { + %a = load i32* @"??__E_Generic_object@?$_Error_objects@H@std@@YAXXZ" %b = load i32* @"\01__ZL16ExceptionHandlerP19_EXCEPTION_POINTERS@4" %c = load i32* @"\01@foo.bar" %x = add i32 %a, %b