Compute the ELF SectionKind from the flags.

Any code creating an MCSectionELF knows ELF and already provides the flags.

SectionKind is an abstraction used by common code that uses a plain
MCSection.

Use the flags to compute the SectionKind. This removes a lot of
guessing and boilerplate from the MCSectionELF construction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227476 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-01-29 17:33:21 +00:00
parent dec5091220
commit 9936b80df5
21 changed files with 192 additions and 387 deletions

View File

@@ -252,10 +252,9 @@ getMachOSection(StringRef Segment, StringRef Section,
Reserved2, Kind);
}
const MCSectionELF *MCContext::
getELFSection(StringRef Section, unsigned Type, unsigned Flags,
SectionKind Kind) {
return getELFSection(Section, Type, Flags, Kind, 0, "");
const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
unsigned Flags) {
return getELFSection(Section, Type, Flags, 0, "");
}
void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) {
@@ -271,25 +270,27 @@ void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) {
const_cast<MCSectionELF*>(Section)->setSectionName(CachedName);
}
const MCSectionELF *MCContext::
getELFSection(StringRef Section, unsigned Type, unsigned Flags,
SectionKind Kind, unsigned EntrySize, StringRef Group) {
const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
StringRef Group) {
// Do the lookup, if we have a hit, return it.
auto IterBool = ELFUniquingMap.insert(
std::make_pair(SectionGroupPair(Section, Group), nullptr));
auto &Entry = *IterBool.first;
if (!IterBool.second) return Entry.second;
// Possibly refine the entry size first.
if (!EntrySize) {
EntrySize = MCSectionELF::DetermineEntrySize(Kind);
}
MCSymbol *GroupSym = nullptr;
if (!Group.empty())
GroupSym = GetOrCreateSymbol(Group);
StringRef CachedName = Entry.first.first;
SectionKind Kind;
if (Flags & ELF::SHF_EXECINSTR)
Kind = SectionKind::getText();
else
Kind = SectionKind::getReadOnly();
MCSectionELF *Result = new (*this)
MCSectionELF(CachedName, Type, Flags, Kind, EntrySize, GroupSym);
Entry.second = Result;