diff options
author | David Blaikie <dblaikie@gmail.com> | 2013-10-22 23:41:52 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2013-10-22 23:41:52 +0000 |
commit | 2b3ea3cdad927cb0e346dd24e9bf84f8eb83babf (patch) | |
tree | 9f3e7575ee060cc4efe92e3168bb625168817418 /lib | |
parent | f45787c645cdf9fb9e0f65b77d48630579a6d3e3 (diff) | |
download | external_llvm-2b3ea3cdad927cb0e346dd24e9bf84f8eb83babf.zip external_llvm-2b3ea3cdad927cb0e346dd24e9bf84f8eb83babf.tar.gz external_llvm-2b3ea3cdad927cb0e346dd24e9bf84f8eb83babf.tar.bz2 |
MC: Support multiple sections with the same name in the same comdat group
Code review by Eric Christopher and Rafael Espindola.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193209 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 19 | ||||
-rw-r--r-- | lib/MC/MCContext.cpp | 18 |
2 files changed, 23 insertions, 14 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index c5f7287..eb197f2 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -1298,10 +1298,12 @@ void ELFObjectWriter::WriteSection(MCAssembler &Asm, // Remove ".rel" and ".rela" prefixes. unsigned SecNameLen = (Section.getType() == ELF::SHT_REL) ? 4 : 5; StringRef SectionName = Section.getSectionName().substr(SecNameLen); + StringRef GroupName = + Section.getGroup() ? Section.getGroup()->getName() : ""; - InfoSection = Asm.getContext().getELFSection(SectionName, - ELF::SHT_PROGBITS, 0, - SectionKind::getReadOnly()); + InfoSection = Asm.getContext().getELFSection(SectionName, ELF::SHT_PROGBITS, + 0, SectionKind::getReadOnly(), + 0, GroupName); sh_info = SectionIndexMap.lookup(InfoSection); break; } @@ -1351,11 +1353,12 @@ void ELFObjectWriter::WriteSection(MCAssembler &Asm, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC, SectionKind::getText())); } else if (SecName.startswith(".ARM.exidx")) { - sh_link = SectionIndexMap.lookup( - Asm.getContext().getELFSection(SecName.substr(sizeof(".ARM.exidx") - 1), - ELF::SHT_PROGBITS, - ELF::SHF_EXECINSTR | ELF::SHF_ALLOC, - SectionKind::getText())); + StringRef GroupName = + Section.getGroup() ? Section.getGroup()->getName() : ""; + sh_link = SectionIndexMap.lookup(Asm.getContext().getELFSection( + SecName.substr(sizeof(".ARM.exidx") - 1), ELF::SHT_PROGBITS, + ELF::SHF_EXECINSTR | ELF::SHF_ALLOC, SectionKind::getText(), 0, + GroupName)); } } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 6e4d82b..67904f6 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -25,10 +25,15 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Signals.h" #include "llvm/Support/SourceMgr.h" + +#include <map> + using namespace llvm; +typedef std::pair<std::string, std::string> SectionGroupPair; + typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; -typedef StringMap<const MCSectionELF*> ELFUniqueMapTy; +typedef std::map<SectionGroupPair, const MCSectionELF *> ELFUniqueMapTy; typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy; @@ -249,8 +254,9 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags, ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)ELFUniquingMap; // Do the lookup, if we have a hit, return it. - StringMapEntry<const MCSectionELF*> &Entry = Map.GetOrCreateValue(Section); - if (Entry.getValue()) return Entry.getValue(); + std::pair<ELFUniqueMapTy::iterator, bool> Entry = Map.insert( + std::make_pair(SectionGroupPair(Section, Group), (MCSectionELF *)0)); + if (!Entry.second) return Entry.first->second; // Possibly refine the entry size first. if (!EntrySize) { @@ -261,9 +267,9 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags, if (!Group.empty()) GroupSym = GetOrCreateSymbol(Group); - MCSectionELF *Result = new (*this) MCSectionELF(Entry.getKey(), Type, Flags, - Kind, EntrySize, GroupSym); - Entry.setValue(Result); + MCSectionELF *Result = new (*this) MCSectionELF( + Entry.first->first.first, Type, Flags, Kind, EntrySize, GroupSym); + Entry.first->second = Result; return Result; } |