[llvm] r233539 - Special case the creation of relocation sections.
Rafael Espindola
rafael.espindola at gmail.com
Mon Mar 30 06:39:16 PDT 2015
Author: rafael
Date: Mon Mar 30 08:39:16 2015
New Revision: 233539
URL: http://llvm.org/viewvc/llvm-project?rev=233539&view=rev
Log:
Special case the creation of relocation sections.
These sections are never looked up and we know when have to create them. Use
that to save adding them to the regular map and avoid a symbol->string->symbol
conversion for the group symbol.
This also makes the implementation independent of the details of how unique
sections are implemented.
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCContext.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=233539&r1=233538&r2=233539&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Mon Mar 30 08:39:16 2015
@@ -194,6 +194,7 @@ namespace llvm {
StringMap<const MCSectionMachO*> MachOUniquingMap;
std::map<ELFSectionKey, const MCSectionELF *> ELFUniquingMap;
std::map<COFFSectionKey, const MCSectionCOFF *> COFFUniquingMap;
+ StringMap<bool> ELFRelSecNames;
/// Do automatic reset in destructor
bool AutoReset;
@@ -304,6 +305,10 @@ namespace llvm {
StringRef Group, bool Unique,
const char *BeginSymName = nullptr);
+ const MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
+ unsigned Flags, unsigned EntrySize,
+ const MCSymbol *Group);
+
void renameELFSection(const MCSectionELF *Section, StringRef Name);
const MCSectionELF *CreateELFGroupSection();
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=233539&r1=233538&r2=233539&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Mon Mar 30 08:39:16 2015
@@ -1167,15 +1167,12 @@ ELFObjectWriter::createRelocationSection
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
unsigned Flags = 0;
- StringRef Group = "";
- if (Section.getFlags() & ELF::SHF_GROUP) {
+ if (Section.getFlags() & ELF::SHF_GROUP)
Flags = ELF::SHF_GROUP;
- Group = Section.getGroup()->getName();
- }
- const MCSectionELF *RelaSection = Ctx.getELFSection(
+ const MCSectionELF *RelaSection = Ctx.createELFRelSection(
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
- Flags, EntrySize, Group, true);
+ Flags, EntrySize, Section.getGroup());
return &Asm.getOrCreateSectionData(*RelaSection);
}
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=233539&r1=233538&r2=233539&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Mon Mar 30 08:39:16 2015
@@ -275,6 +275,18 @@ void MCContext::renameELFSection(const M
const_cast<MCSectionELF*>(Section)->setSectionName(CachedName);
}
+const MCSectionELF *
+MCContext::createELFRelSection(StringRef Name, unsigned Type, unsigned Flags,
+ unsigned EntrySize, const MCSymbol *Group) {
+ StringMap<bool>::iterator I;
+ bool Inserted;
+ std::tie(I, Inserted) = ELFRelSecNames.insert(std::make_pair(Name, true));
+
+ return new (*this)
+ MCSectionELF(I->getKey(), Type, Flags, SectionKind::getReadOnly(),
+ EntrySize, Group, true, nullptr);
+}
+
const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
StringRef Group, bool Unique,
More information about the llvm-commits
mailing list