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 | da881a2742387360206798093624f6b226807d1b (patch) | |
tree | 110f2fc9cfeb00483a6923c732a5c9b41d11e7f9 /llvm/lib | |
parent | 263fde068f11f55ca928899f6fc15416191f8252 (diff) | |
download | bcm5719-llvm-da881a2742387360206798093624f6b226807d1b.tar.gz bcm5719-llvm-da881a2742387360206798093624f6b226807d1b.zip |
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.
llvm-svn: 199203
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/Mangler.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp index d3b53a9bddc..c067f0f3923 100644 --- a/llvm/lib/IR/Mangler.cpp +++ b/llvm/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 |