[llvm] r199203 - Fix fastcall mangling of dllimported symbols

Nico Rieck nico.rieck at gmail.com
Tue Jan 14 03:53:26 PST 2014


Author: nrieck
Date: Tue Jan 14 05:53:26 2014
New Revision: 199203

URL: http://llvm.org/viewvc/llvm-project?rev=199203&view=rev
Log:
Fix fastcall mangling of dllimported symbols

fastcall requires @ as global prefix instead of _ but getNameWithPrefix
wrongly assumes the OutName buffer is empty and replaces at index 0.
For imported functions this buffer is pre-filled with "__imp_" resulting
in broken "@_imp_foo at 0" mangling.

Instead replace at the proper index. We also never have to prepend the
@-prefix because this fastcall mangling is only used on 32-bit Windows
targets which have _ has global prefix.

Modified:
    llvm/trunk/lib/IR/Mangler.cpp

Modified: llvm/trunk/lib/IR/Mangler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Mangler.cpp?rev=199203&r1=199202&r2=199203&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Mangler.cpp (original)
+++ llvm/trunk/lib/IR/Mangler.cpp Tue Jan 14 05:53:26 2014
@@ -81,7 +81,9 @@ void Mangler::getNameWithPrefix(SmallVec
     PrefixTy = Mangler::Private;
   else if (GV->hasLinkerPrivateLinkage() || GV->hasLinkerPrivateWeakLinkage())
     PrefixTy = Mangler::LinkerPrivate;
-  
+
+  size_t NameBegin = OutName.size();
+
   // If this global has a name, handle it simply.
   if (GV->hasName()) {
     StringRef Name = GV->getName();
@@ -106,13 +108,10 @@ void Mangler::getNameWithPrefix(SmallVec
     if (const Function *F = dyn_cast<Function>(GV)) {
       CallingConv::ID CC = F->getCallingConv();
     
-      // fastcall functions need to start with @.
-      // FIXME: This logic seems unlikely to be right.
+      // fastcall functions need to start with @ instead of _.
       if (CC == CallingConv::X86_FastCall) {
-        if (OutName[0] == '_')
-          OutName[0] = '@';
-        else
-          OutName.insert(OutName.begin(), '@');
+        assert(OutName[NameBegin] == '_' && DL->getGlobalPrefix() == '_');
+        OutName[NameBegin] = '@';
       }
     
       // fastcall and stdcall functions usually need @42 at the end to specify





More information about the llvm-commits mailing list