diff options
author | Nico Rieck <nico.rieck@gmail.com> | 2014-01-14 11:53:26 +0000 |
---|---|---|
committer | Nico Rieck <nico.rieck@gmail.com> | 2014-01-14 11:53:26 +0000 |
commit | 1b1321f0805d74481af18c1bdefd6ed7ef2b60e6 (patch) | |
tree | 0b3bb45fe7076f7ca661939a405b8c49c3a18631 /lib/IR | |
parent | d13b9da1b6575329cebcaadb31fcf8f200cbd2c6 (diff) | |
download | llvm-1b1321f0805d74481af18c1bdefd6ed7ef2b60e6.tar.gz llvm-1b1321f0805d74481af18c1bdefd6ed7ef2b60e6.tar.bz2 llvm-1b1321f0805d74481af18c1bdefd6ed7ef2b60e6.tar.xz |
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@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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199203 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r-- | lib/IR/Mangler.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/IR/Mangler.cpp b/lib/IR/Mangler.cpp index d3b53a9bdd..c067f0f392 100644 --- a/lib/IR/Mangler.cpp +++ b/lib/IR/Mangler.cpp @@ -81,7 +81,9 @@ void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName, 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(SmallVectorImpl<char> &OutName, 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 |