- MCSectionELF *Result = new (*this) MCSectionELF(
- Entry.first->first.first, Type, Flags, Kind, EntrySize, GroupSym);
- Entry.first->second = Result;
+ return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
+ BeginSymName, nullptr);
+}
+
+MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
+ unsigned Flags, unsigned EntrySize,
+ const MCSymbolELF *GroupSym,
+ unsigned UniqueID,
+ const char *BeginSymName,
+ const MCSectionELF *Associated) {
+ StringRef Group = "";
+ if (GroupSym)
+ Group = GroupSym->getName();
+ // Do the lookup, if we have a hit, return it.
+ auto IterBool = ELFUniquingMap.insert(
+ std::make_pair(ELFSectionKey{Section, Group, UniqueID}, nullptr));
+ auto &Entry = *IterBool.first;
+ if (!IterBool.second)
+ return Entry.second;
+
+ StringRef CachedName = Entry.first.SectionName;
+
+ SectionKind Kind;
+ if (Flags & ELF::SHF_EXECINSTR)
+ Kind = SectionKind::getText();
+ else
+ Kind = SectionKind::getReadOnly();
+
+ MCSymbol *Begin = nullptr;
+ if (BeginSymName)
+ Begin = createTempSymbol(BeginSymName, false);
+
+ MCSectionELF *Result = new (ELFAllocator.Allocate())
+ MCSectionELF(CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID,
+ Begin, Associated);
+ Entry.second = Result;