diff options
author | Reid Kleckner <rnk@google.com> | 2018-06-21 20:27:38 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-06-21 20:27:38 +0000 |
commit | 13c9ee684cc3234a3f84dcc8bb8cfbd7d2d4293b (patch) | |
tree | 723ee5c6f2cd4835ea9b5424578fb95505109137 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | 4065b9ae4837d1925a36d2043601738374679224 (diff) | |
download | bcm5719-llvm-13c9ee684cc3234a3f84dcc8bb8cfbd7d2d4293b.tar.gz bcm5719-llvm-13c9ee684cc3234a3f84dcc8bb8cfbd7d2d4293b.zip |
[mingw] Fix GCC ABI compatibility for comdat things
Summary:
GCC and the binutils COFF linker do comdats differently from MSVC.
If we want to be ABI compatible, we have to do what they do, which is to
emit unique section names like ".text$_Z3foov" instead of short section
names like ".text". Otherwise, the binutils linker gets confused and
reports multiple definition errors when two object files from GCC and
Clang containing the same inline function are linked together.
The best description of the issue is probably at
https://github.com/Alexpux/MINGW-packages/issues/1677, we don't seem to
have a good one in our tracker.
I fixed up the .pdata and .xdata sections needed everywhere other than
32-bit x86. GCC doesn't use associative comdats for those, it appears to
rely on the section name.
Reviewers: smeenai, compnerd, mstorsjo, martell, mati865
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D48402
llvm-svn: 335286
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 03a1f6239f2..8518ee7def3 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1060,7 +1060,7 @@ MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal( Selection); } -static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) { +static StringRef getCOFFSectionNameForUniqueGlobal(SectionKind Kind) { if (Kind.isText()) return ".text"; if (Kind.isBSS()) @@ -1072,6 +1072,15 @@ static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) { return ".data"; } +void TargetLoweringObjectFileCOFF::appendComdatSymbolForMinGW( + SmallVectorImpl<char> &SecName, StringRef Symbol, + const DataLayout &DL) const { + if (getTargetTriple().isWindowsGNUEnvironment()) { + SecName.push_back('$'); + getMangler().getNameWithPrefix(SecName, Symbol, DL); + } +} + MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal( const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // If we have -ffunction-sections then we should emit the global value to a @@ -1083,7 +1092,8 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal( EmitUniquedSection = TM.getDataSections(); if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) { - const char *Name = getCOFFSectionNameForUniqueGlobal(Kind); + SmallString<256> Name = getCOFFSectionNameForUniqueGlobal(Kind); + unsigned Characteristics = getCOFFSectionFlags(Kind, TM); Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; @@ -1103,6 +1113,8 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal( if (!ComdatGV->hasPrivateLinkage()) { MCSymbol *Sym = TM.getSymbol(ComdatGV); StringRef COMDATSymName = Sym->getName(); + appendComdatSymbolForMinGW(Name, COMDATSymName, + GO->getParent()->getDataLayout()); return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName, Selection, UniqueID); } else { @@ -1160,13 +1172,14 @@ MCSection *TargetLoweringObjectFileCOFF::getSectionForJumpTable( StringRef COMDATSymName = Sym->getName(); SectionKind Kind = SectionKind::getReadOnly(); - const char *Name = getCOFFSectionNameForUniqueGlobal(Kind); + StringRef SecName = getCOFFSectionNameForUniqueGlobal(Kind); unsigned Characteristics = getCOFFSectionFlags(Kind, TM); Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; unsigned UniqueID = NextUniqueID++; - return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName, - COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE, UniqueID); + return getContext().getCOFFSection( + SecName, Characteristics, Kind, COMDATSymName, + COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE, UniqueID); } void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer, |