|
44 | 44 | #include "llvm/MC/SectionKind.h"
|
45 | 45 | #include "llvm/Support/Casting.h"
|
46 | 46 | #include "llvm/Support/CommandLine.h"
|
47 |
| -#include "llvm/Support/EndianStream.h" |
48 | 47 | #include "llvm/Support/ErrorHandling.h"
|
49 | 48 | #include "llvm/Support/MemoryBuffer.h"
|
50 | 49 | #include "llvm/Support/Path.h"
|
@@ -549,42 +548,16 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
|
549 | 548 | if (GroupSym)
|
550 | 549 | Group = GroupSym->getName();
|
551 | 550 | assert(!(LinkedToSym && LinkedToSym->getName().empty()));
|
| 551 | + // Do the lookup, if we have a hit, return it. |
| 552 | + auto IterBool = ELFUniquingMap.insert(std::make_pair( |
| 553 | + ELFSectionKey{Section.str(), Group, |
| 554 | + LinkedToSym ? LinkedToSym->getName() : "", UniqueID}, |
| 555 | + nullptr)); |
| 556 | + auto &Entry = *IterBool.first; |
| 557 | + if (!IterBool.second) |
| 558 | + return Entry.second; |
552 | 559 |
|
553 |
| - // Sections are differentiated by the quadruple (section_name, group_name, |
554 |
| - // unique_id, link_to_symbol_name). Sections sharing the same quadruple are |
555 |
| - // combined into one section. As an optimization, non-unique sections without |
556 |
| - // group or linked-to symbol have a shorter unique-ing key. |
557 |
| - std::pair<StringMap<MCSectionELF *>::iterator, bool> EntryNewPair; |
558 |
| - // Length of the section name, which are the first SectionLen bytes of the key |
559 |
| - unsigned SectionLen; |
560 |
| - if (GroupSym || LinkedToSym || UniqueID != MCSection::NonUniqueID) { |
561 |
| - SmallString<128> Buffer; |
562 |
| - Section.toVector(Buffer); |
563 |
| - SectionLen = Buffer.size(); |
564 |
| - Buffer.push_back(0); // separator which cannot occur in the name |
565 |
| - if (GroupSym) |
566 |
| - Buffer.append(GroupSym->getName()); |
567 |
| - Buffer.push_back(0); // separator which cannot occur in the name |
568 |
| - if (LinkedToSym) |
569 |
| - Buffer.append(LinkedToSym->getName()); |
570 |
| - support::endian::write(Buffer, UniqueID, endianness::native); |
571 |
| - StringRef UniqueMapKey = StringRef(Buffer); |
572 |
| - EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr)); |
573 |
| - } else if (!Section.isSingleStringRef()) { |
574 |
| - SmallString<128> Buffer; |
575 |
| - SectionLen = Buffer.size(); |
576 |
| - StringRef UniqueMapKey = Section.toStringRef(Buffer); |
577 |
| - EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr)); |
578 |
| - } else { |
579 |
| - SectionLen = Section.getSingleStringRef().size(); |
580 |
| - StringRef UniqueMapKey = Section.getSingleStringRef(); |
581 |
| - EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr)); |
582 |
| - } |
583 |
| - |
584 |
| - if (!EntryNewPair.second) |
585 |
| - return EntryNewPair.first->second; |
586 |
| - |
587 |
| - StringRef CachedName = EntryNewPair.first->getKey().take_front(SectionLen); |
| 560 | + StringRef CachedName = Entry.first.SectionName; |
588 | 561 |
|
589 | 562 | SectionKind Kind;
|
590 | 563 | if (Flags & ELF::SHF_ARM_PURECODE)
|
@@ -628,7 +601,7 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
|
628 | 601 | MCSectionELF *Result =
|
629 | 602 | createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
|
630 | 603 | IsComdat, UniqueID, LinkedToSym);
|
631 |
| - EntryNewPair.first->second = Result; |
| 604 | + Entry.second = Result; |
632 | 605 |
|
633 | 606 | recordELFMergeableSectionInfo(Result->getName(), Result->getFlags(),
|
634 | 607 | Result->getUniqueID(), Result->getEntrySize());
|
|
0 commit comments