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

@ -271,11 +271,11 @@ namespace llvm {
} }
const MCSectionELF *getELFSection(StringRef Section, unsigned Type, const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
unsigned Flags, SectionKind Kind); unsigned Flags);
const MCSectionELF *getELFSection(StringRef Section, unsigned Type, const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
unsigned Flags, SectionKind Kind, unsigned Flags, unsigned EntrySize,
unsigned EntrySize, StringRef Group); StringRef Group);
void renameELFSection(const MCSectionELF *Section, StringRef Name); void renameELFSection(const MCSectionELF *Section, StringRef Name);

View File

@ -92,10 +92,6 @@ public:
static bool classof(const MCSection *S) { static bool classof(const MCSection *S) {
return S->getVariant() == SV_ELF; return S->getVariant() == SV_ELF;
} }
// Return the entry size for sections with fixed-width data.
static unsigned DetermineEntrySize(SectionKind Kind);
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -52,8 +52,8 @@ void ErlangGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
// Put this in a custom .note section. // Put this in a custom .note section.
AP.OutStreamer.SwitchSection( AP.OutStreamer.SwitchSection(
AP.getObjFileLowering().getContext().getELFSection( AP.getObjFileLowering().getContext().getELFSection(".note.gc",
".note.gc", ELF::SHT_PROGBITS, 0, SectionKind::getDataRel())); ELF::SHT_PROGBITS, 0));
// For each function... // For each function...
for (GCModuleInfo::FuncInfoVec::iterator FI = Info.funcinfo_begin(), for (GCModuleInfo::FuncInfoVec::iterator FI = Info.funcinfo_begin(),

View File

@ -71,7 +71,6 @@ void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer &Streamer,
const MCSection *Sec = getContext().getELFSection(NameData, const MCSection *Sec = getContext().getELFSection(NameData,
ELF::SHT_PROGBITS, ELF::SHT_PROGBITS,
Flags, Flags,
SectionKind::getDataRel(),
0, Label->getName()); 0, Label->getName());
unsigned Size = TM.getDataLayout()->getPointerSize(); unsigned Size = TM.getDataLayout()->getPointerSize();
Streamer.SwitchSection(Sec); Streamer.SwitchSection(Sec);
@ -219,7 +218,7 @@ const MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
} }
return getContext().getELFSection(SectionName, return getContext().getELFSection(SectionName,
getELFSectionType(SectionName, Kind), Flags, getELFSectionType(SectionName, Kind), Flags,
Kind, /*EntrySize=*/0, Group); /*EntrySize=*/0, Group);
} }
/// getSectionPrefixForGlobal - Return the section prefix name used by options /// getSectionPrefixForGlobal - Return the section prefix name used by options
@ -268,9 +267,8 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Group = C->getName(); Group = C->getName();
} }
return getContext().getELFSection(Name.str(), return getContext().getELFSection(
getELFSectionType(Name.str(), Kind), Name.str(), getELFSectionType(Name.str(), Kind), Flags, 0, Group);
Flags, Kind, 0, Group);
} }
if (Kind.isText()) return TextSection; if (Kind.isText()) return TextSection;
@ -283,21 +281,19 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
unsigned Align = unsigned Align =
TM.getDataLayout()->getPreferredAlignment(cast<GlobalVariable>(GV)); TM.getDataLayout()->getPreferredAlignment(cast<GlobalVariable>(GV));
const char *SizeSpec = ".rodata.str1."; unsigned EntrySize = 1;
if (Kind.isMergeable2ByteCString()) if (Kind.isMergeable2ByteCString())
SizeSpec = ".rodata.str2."; EntrySize = 2;
else if (Kind.isMergeable4ByteCString()) else if (Kind.isMergeable4ByteCString())
SizeSpec = ".rodata.str4."; EntrySize = 4;
else else
assert(Kind.isMergeable1ByteCString() && "unknown string width"); assert(Kind.isMergeable1ByteCString() && "unknown string width");
std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
std::string Name = SizeSpec + utostr(Align); std::string Name = SizeSpec + utostr(Align);
return getContext().getELFSection(Name, ELF::SHT_PROGBITS, return getContext().getELFSection(
ELF::SHF_ALLOC | Name, ELF::SHT_PROGBITS,
ELF::SHF_MERGE | ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize, "");
ELF::SHF_STRINGS,
Kind);
} }
if (Kind.isMergeableConst()) { if (Kind.isMergeableConst()) {
@ -357,7 +353,6 @@ static const MCSectionELF *getStaticStructorSection(MCContext &Ctx,
std::string Name; std::string Name;
unsigned Type; unsigned Type;
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE; unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
SectionKind Kind = SectionKind::getDataRel();
StringRef COMDAT = KeySym ? KeySym->getName() : ""; StringRef COMDAT = KeySym ? KeySym->getName() : "";
if (KeySym) if (KeySym)
@ -389,7 +384,7 @@ static const MCSectionELF *getStaticStructorSection(MCContext &Ctx,
Type = ELF::SHT_PROGBITS; Type = ELF::SHT_PROGBITS;
} }
return Ctx.getELFSection(Name, Type, Flags, Kind, 0, COMDAT); return Ctx.getELFSection(Name, Type, Flags, 0, COMDAT);
} }
const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection( const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
@ -410,16 +405,10 @@ TargetLoweringObjectFileELF::InitializeELF(bool UseInitArray_) {
if (!UseInitArray) if (!UseInitArray)
return; return;
StaticCtorSection = StaticCtorSection = getContext().getELFSection(
getContext().getELFSection(".init_array", ELF::SHT_INIT_ARRAY, ".init_array", ELF::SHT_INIT_ARRAY, ELF::SHF_WRITE | ELF::SHF_ALLOC);
ELF::SHF_WRITE | StaticDtorSection = getContext().getELFSection(
ELF::SHF_ALLOC, ".fini_array", ELF::SHT_FINI_ARRAY, ELF::SHF_WRITE | ELF::SHF_ALLOC);
SectionKind::getDataRel());
StaticDtorSection =
getContext().getELFSection(".fini_array", ELF::SHT_FINI_ARRAY,
ELF::SHF_WRITE |
ELF::SHF_ALLOC,
SectionKind::getDataRel());
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -325,8 +325,7 @@ void SymbolTableWriter::createSymtabShndx() {
MCContext &Ctx = Asm.getContext(); MCContext &Ctx = Asm.getContext();
const MCSectionELF *SymtabShndxSection = const MCSectionELF *SymtabShndxSection =
Ctx.getELFSection(".symtab_shndxr", ELF::SHT_SYMTAB_SHNDX, 0, Ctx.getELFSection(".symtab_shndxr", ELF::SHT_SYMTAB_SHNDX, 0, 4, "");
SectionKind::getReadOnly(), 4, "");
MCSectionData *SymtabShndxSD = MCSectionData *SymtabShndxSD =
&Asm.getOrCreateSectionData(*SymtabShndxSection); &Asm.getOrCreateSectionData(*SymtabShndxSection);
SymtabShndxSD->setAlignment(4); SymtabShndxSD->setAlignment(4);
@ -1151,7 +1150,6 @@ void ELFObjectWriter::CreateRelocationSections(MCAssembler &Asm,
const MCSectionELF *RelaSection = const MCSectionELF *RelaSection =
Ctx.getELFSection(RelaSectionName, hasRelocationAddend() ? Ctx.getELFSection(RelaSectionName, hasRelocationAddend() ?
ELF::SHT_RELA : ELF::SHT_REL, Flags, ELF::SHT_RELA : ELF::SHT_REL, Flags,
SectionKind::getReadOnly(),
EntrySize, Group); EntrySize, Group);
RelMap[&Section] = RelaSection; RelMap[&Section] = RelaSection;
Asm.getOrCreateSectionData(*RelaSection); Asm.getOrCreateSectionData(*RelaSection);
@ -1410,21 +1408,18 @@ void ELFObjectWriter::CreateMetadataSections(MCAssembler &Asm,
// We construct .shstrtab, .symtab and .strtab in this order to match gnu as. // We construct .shstrtab, .symtab and .strtab in this order to match gnu as.
const MCSectionELF *ShstrtabSection = const MCSectionELF *ShstrtabSection =
Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0, Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0);
SectionKind::getReadOnly());
MCSectionData &ShstrtabSD = Asm.getOrCreateSectionData(*ShstrtabSection); MCSectionData &ShstrtabSD = Asm.getOrCreateSectionData(*ShstrtabSection);
ShstrtabSD.setAlignment(1); ShstrtabSD.setAlignment(1);
const MCSectionELF *SymtabSection = const MCSectionELF *SymtabSection =
Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0, Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0,
SectionKind::getReadOnly(),
EntrySize, ""); EntrySize, "");
MCSectionData &SymtabSD = Asm.getOrCreateSectionData(*SymtabSection); MCSectionData &SymtabSD = Asm.getOrCreateSectionData(*SymtabSection);
SymtabSD.setAlignment(is64Bit() ? 8 : 4); SymtabSD.setAlignment(is64Bit() ? 8 : 4);
const MCSectionELF *StrtabSection; const MCSectionELF *StrtabSection;
StrtabSection = Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0, StrtabSection = Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
SectionKind::getReadOnly());
MCSectionData &StrtabSD = Asm.getOrCreateSectionData(*StrtabSection); MCSectionData &StrtabSD = Asm.getOrCreateSectionData(*StrtabSection);
StrtabSD.setAlignment(1); StrtabSD.setAlignment(1);
@ -1521,9 +1516,8 @@ void ELFObjectWriter::WriteSection(MCAssembler &Asm,
case ELF::SHT_RELA: { case ELF::SHT_RELA: {
const MCSectionELF *SymtabSection; const MCSectionELF *SymtabSection;
const MCSectionELF *InfoSection; const MCSectionELF *InfoSection;
SymtabSection = Asm.getContext().getELFSection(".symtab", ELF::SHT_SYMTAB, SymtabSection =
0, Asm.getContext().getELFSection(".symtab", ELF::SHT_SYMTAB, 0);
SectionKind::getReadOnly());
sh_link = SectionIndexMap.lookup(SymtabSection); sh_link = SectionIndexMap.lookup(SymtabSection);
assert(sh_link && ".symtab not found"); assert(sh_link && ".symtab not found");
@ -1534,8 +1528,7 @@ void ELFObjectWriter::WriteSection(MCAssembler &Asm,
Section.getGroup() ? Section.getGroup()->getName() : ""; Section.getGroup() ? Section.getGroup()->getName() : "";
InfoSection = Asm.getContext().getELFSection(SectionName, ELF::SHT_PROGBITS, InfoSection = Asm.getContext().getELFSection(SectionName, ELF::SHT_PROGBITS,
0, SectionKind::getReadOnly(), 0, 0, GroupName);
0, GroupName);
sh_info = SectionIndexMap.lookup(InfoSection); sh_info = SectionIndexMap.lookup(InfoSection);
break; break;
} }
@ -1579,18 +1572,14 @@ void ELFObjectWriter::WriteSection(MCAssembler &Asm,
Section.getType() == ELF::SHT_ARM_EXIDX) { Section.getType() == ELF::SHT_ARM_EXIDX) {
StringRef SecName(Section.getSectionName()); StringRef SecName(Section.getSectionName());
if (SecName == ".ARM.exidx") { if (SecName == ".ARM.exidx") {
sh_link = SectionIndexMap.lookup( sh_link = SectionIndexMap.lookup(Asm.getContext().getELFSection(
Asm.getContext().getELFSection(".text", ".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC));
ELF::SHT_PROGBITS,
ELF::SHF_EXECINSTR | ELF::SHF_ALLOC,
SectionKind::getText()));
} else if (SecName.startswith(".ARM.exidx")) { } else if (SecName.startswith(".ARM.exidx")) {
StringRef GroupName = StringRef GroupName =
Section.getGroup() ? Section.getGroup()->getName() : ""; Section.getGroup() ? Section.getGroup()->getName() : "";
sh_link = SectionIndexMap.lookup(Asm.getContext().getELFSection( sh_link = SectionIndexMap.lookup(Asm.getContext().getELFSection(
SecName.substr(sizeof(".ARM.exidx") - 1), ELF::SHT_PROGBITS, SecName.substr(sizeof(".ARM.exidx") - 1), ELF::SHT_PROGBITS,
ELF::SHF_EXECINSTR | ELF::SHF_ALLOC, SectionKind::getText(), 0, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC, 0, GroupName));
GroupName));
} }
} }

View File

@ -22,8 +22,7 @@ void MCAsmInfoELF::anchor() { }
const MCSection * const MCSection *
MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const { MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const {
return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS, return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS, 0);
0, SectionKind::getMetadata());
} }
MCAsmInfoELF::MCAsmInfoELF() { MCAsmInfoELF::MCAsmInfoELF() {

View File

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

View File

@ -259,11 +259,8 @@ void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
MCELF::SetType(SD, ELF::STT_OBJECT); MCELF::SetType(SD, ELF::STT_OBJECT);
if (MCELF::GetBinding(SD) == ELF_STB_Local) { if (MCELF::GetBinding(SD) == ELF_STB_Local) {
const MCSection *Section = getAssembler().getContext().getELFSection(".bss", const MCSection *Section = getAssembler().getContext().getELFSection(
ELF::SHT_NOBITS, ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
ELF::SHF_WRITE |
ELF::SHF_ALLOC,
SectionKind::getBSS());
AssignSection(Symbol, Section); AssignSection(Symbol, Section);
@ -318,8 +315,7 @@ void MCELFStreamer::EmitFileDirective(StringRef Filename) {
void MCELFStreamer::EmitIdent(StringRef IdentString) { void MCELFStreamer::EmitIdent(StringRef IdentString) {
const MCSection *Comment = getAssembler().getContext().getELFSection( const MCSection *Comment = getAssembler().getContext().getELFSection(
".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
SectionKind::getReadOnly(), 1, "");
PushSection(); PushSection();
SwitchSection(Comment); SwitchSection(Comment);
if (!SeenIdent) { if (!SeenIdent) {

View File

@ -416,83 +416,54 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
// ELF // ELF
BSSSection = BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
Ctx->getELFSection(".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
ELF::SHF_WRITE | ELF::SHF_ALLOC,
SectionKind::getBSS());
TextSection = TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
Ctx->getELFSection(".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
ELF::SHF_EXECINSTR |
ELF::SHF_ALLOC,
SectionKind::getText());
DataSection = DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
Ctx->getELFSection(".data", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
ELF::SHF_WRITE |ELF::SHF_ALLOC,
SectionKind::getDataRel());
ReadOnlySection = ReadOnlySection =
Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
ELF::SHF_ALLOC,
SectionKind::getReadOnly());
TLSDataSection = TLSDataSection =
Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS, Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
ELF::SHF_WRITE,
SectionKind::getThreadData());
TLSBSSSection = TLSBSSSection = Ctx->getELFSection(
Ctx->getELFSection(".tbss", ELF::SHT_NOBITS, ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
ELF::SHF_ALLOC | ELF::SHF_TLS |
ELF::SHF_WRITE,
SectionKind::getThreadBSS());
DataRelSection = DataRelSection = Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
ELF::SHF_ALLOC |ELF::SHF_WRITE,
SectionKind::getDataRel());
DataRelLocalSection = DataRelLocalSection = Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
ELF::SHF_ALLOC |ELF::SHF_WRITE,
SectionKind::getDataRelLocal());
DataRelROSection = DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
ELF::SHF_ALLOC |ELF::SHF_WRITE,
SectionKind::getReadOnlyWithRel());
DataRelROLocalSection = DataRelROLocalSection = Ctx->getELFSection(
Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS, ".data.rel.ro.local", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
ELF::SHF_ALLOC |ELF::SHF_WRITE,
SectionKind::getReadOnlyWithRelLocal());
MergeableConst4Section = MergeableConst4Section =
Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC |ELF::SHF_MERGE, ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
SectionKind::getMergeableConst4());
MergeableConst8Section = MergeableConst8Section =
Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC |ELF::SHF_MERGE, ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
SectionKind::getMergeableConst8());
MergeableConst16Section = MergeableConst16Section =
Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC |ELF::SHF_MERGE, ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
SectionKind::getMergeableConst16());
StaticCtorSection = StaticCtorSection = Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
ELF::SHF_ALLOC |ELF::SHF_WRITE,
SectionKind::getDataRel());
StaticDtorSection = StaticDtorSection = Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
ELF::SHF_ALLOC |ELF::SHF_WRITE,
SectionKind::getDataRel());
// Exception Handling Sections. // Exception Handling Sections.
@ -500,103 +471,68 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
// it contains relocatable pointers. In PIC mode, this is probably a big // it contains relocatable pointers. In PIC mode, this is probably a big
// runtime hit for C++ apps. Either the contents of the LSDA need to be // runtime hit for C++ apps. Either the contents of the LSDA need to be
// adjusted or this should be a data section. // adjusted or this should be a data section.
LSDASection = LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
ELF::SHF_ALLOC,
SectionKind::getReadOnly());
COFFDebugSymbolsSection = nullptr; COFFDebugSymbolsSection = nullptr;
// Debug Info Sections. // Debug Info Sections.
DwarfAbbrevSection = DwarfAbbrevSection =
Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata()); DwarfInfoSection = Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0);
DwarfInfoSection = DwarfLineSection = Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0);
Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, DwarfFrameSection = Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfLineSection =
Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
SectionKind::getMetadata());
DwarfFrameSection =
Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
SectionKind::getMetadata());
DwarfPubNamesSection = DwarfPubNamesSection =
Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfPubTypesSection = DwarfPubTypesSection =
Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfGnuPubNamesSection = DwarfGnuPubNamesSection =
Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfGnuPubTypesSection = DwarfGnuPubTypesSection =
Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfStrSection = DwarfStrSection =
Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS, Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
ELF::SHF_MERGE | ELF::SHF_STRINGS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
SectionKind::getMergeable1ByteCString()); DwarfLocSection = Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0);
DwarfLocSection =
Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
SectionKind::getMetadata());
DwarfARangesSection = DwarfARangesSection =
Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfRangesSection = DwarfRangesSection =
Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfMacroInfoSection = DwarfMacroInfoSection =
Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
// DWARF5 Experimental Debug Info // DWARF5 Experimental Debug Info
// Accelerator Tables // Accelerator Tables
DwarfAccelNamesSection = DwarfAccelNamesSection =
Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfAccelObjCSection = DwarfAccelObjCSection =
Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfAccelNamespaceSection = DwarfAccelNamespaceSection =
Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfAccelTypesSection = DwarfAccelTypesSection =
Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
// Fission Sections // Fission Sections
DwarfInfoDWOSection = DwarfInfoDWOSection =
Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfTypesDWOSection = DwarfTypesDWOSection =
Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfAbbrevDWOSection = DwarfAbbrevDWOSection =
Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfStrDWOSection = DwarfStrDWOSection =
Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS, Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
ELF::SHF_MERGE | ELF::SHF_STRINGS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
SectionKind::getMergeable1ByteCString());
DwarfLineDWOSection = DwarfLineDWOSection =
Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfLocDWOSection = DwarfLocDWOSection =
Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata());
DwarfStrOffDWOSection = DwarfStrOffDWOSection =
Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0, Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0);
SectionKind::getMetadata()); DwarfAddrSection = Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0);
DwarfAddrSection =
Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
SectionKind::getMetadata());
StackMapSection = StackMapSection =
Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
ELF::SHF_ALLOC,
SectionKind::getMetadata());
} }
@ -884,7 +820,7 @@ void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const { const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP, return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
SectionKind::getMetadata(), 0, utostr(Hash)); 0, utostr(Hash));
} }
void MCObjectFileInfo::InitEHFrameSection() { void MCObjectFileInfo::InitEHFrameSection() {
@ -898,9 +834,7 @@ void MCObjectFileInfo::InitEHFrameSection() {
SectionKind::getReadOnly()); SectionKind::getReadOnly());
else if (Env == IsELF) else if (Env == IsELF)
EHFrameSection = EHFrameSection =
Ctx->getELFSection(".eh_frame", EHSectionType, Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
EHSectionFlags,
SectionKind::getDataRel());
else else
EHFrameSection = EHFrameSection =
Ctx->getCOFFSection(".eh_frame", Ctx->getCOFFSection(".eh_frame",

View File

@ -199,8 +199,7 @@ bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
return true; return true;
} }
getStreamer().SwitchSection(getContext().getELFSection( getStreamer().SwitchSection(getContext().getELFSection(Section, Type, Flags),
Section, Type, Flags, Kind),
Subsection); Subsection);
return false; return false;
@ -269,40 +268,6 @@ bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
return false; return false;
} }
static SectionKind computeSectionKind(unsigned Flags, unsigned ElemSize) {
if (Flags & ELF::SHF_EXECINSTR)
return SectionKind::getText();
if (Flags & ELF::SHF_TLS)
return SectionKind::getThreadData();
if (Flags & ELF::SHF_MERGE) {
if (Flags & ELF::SHF_STRINGS) {
switch (ElemSize) {
default:
break;
case 1:
return SectionKind::getMergeable1ByteCString();
case 2:
return SectionKind::getMergeable2ByteCString();
case 4:
return SectionKind::getMergeable4ByteCString();
}
} else {
switch (ElemSize) {
default:
break;
case 4:
return SectionKind::getMergeableConst4();
case 8:
return SectionKind::getMergeableConst8();
case 16:
return SectionKind::getMergeableConst16();
}
}
}
return SectionKind::getDataRel();
}
static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) { static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
unsigned flags = 0; unsigned flags = 0;
@ -544,9 +509,8 @@ EndStmt:
} }
} }
SectionKind Kind = computeSectionKind(Flags, Size); const MCSection *ELFSection =
const MCSection *ELFSection = getContext().getELFSection( getContext().getELFSection(SectionName, Type, Flags, Size, GroupName);
SectionName, Type, Flags, Kind, Size, GroupName);
getStreamer().SwitchSection(ELFSection, Subsection); getStreamer().SwitchSection(ELFSection, Subsection);
if (getContext().getGenDwarfForAssembly()) { if (getContext().getGenDwarfForAssembly()) {
@ -697,9 +661,7 @@ bool ELFAsmParser::ParseDirectiveVersion(StringRef, SMLoc) {
Lex(); Lex();
const MCSection *Note = const MCSection *Note = getContext().getELFSection(".note", ELF::SHT_NOTE, 0);
getContext().getELFSection(".note", ELF::SHT_NOTE, 0,
SectionKind::getReadOnly());
getStreamer().PushSection(); getStreamer().PushSection();
getStreamer().SwitchSection(Note); getStreamer().SwitchSection(Note);

View File

@ -157,13 +157,3 @@ bool MCSectionELF::UseCodeAlign() const {
bool MCSectionELF::isVirtualSection() const { bool MCSectionELF::isVirtualSection() const {
return getType() == ELF::SHT_NOBITS; return getType() == ELF::SHT_NOBITS;
} }
unsigned MCSectionELF::DetermineEntrySize(SectionKind Kind) {
if (Kind.isMergeable1ByteCString()) return 1;
if (Kind.isMergeable2ByteCString()) return 2;
if (Kind.isMergeable4ByteCString()) return 4;
if (Kind.isMergeableConst4()) return 4;
if (Kind.isMergeableConst8()) return 8;
if (Kind.isMergeableConst16()) return 16;
return 0;
}

View File

@ -36,10 +36,7 @@ void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
} }
AttributesSection = AttributesSection =
getContext().getELFSection(".ARM.attributes", getContext().getELFSection(".ARM.attributes", ELF::SHT_ARM_ATTRIBUTES, 0);
ELF::SHT_ARM_ATTRIBUTES,
0,
SectionKind::getMetadata());
} }
const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference( const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(

View File

@ -958,11 +958,8 @@ void ARMTargetELFStreamer::finishAttributeSection() {
if (AttributeSection) { if (AttributeSection) {
Streamer.SwitchSection(AttributeSection); Streamer.SwitchSection(AttributeSection);
} else { } else {
AttributeSection = AttributeSection = Streamer.getContext().getELFSection(
Streamer.getContext().getELFSection(".ARM.attributes", ".ARM.attributes", ELF::SHT_ARM_ATTRIBUTES, 0);
ELF::SHT_ARM_ATTRIBUTES,
0,
SectionKind::getMetadata());
Streamer.SwitchSection(AttributeSection); Streamer.SwitchSection(AttributeSection);
// Format version // Format version
@ -1069,11 +1066,11 @@ inline void ARMELFStreamer::SwitchToEHSection(const char *Prefix,
// Get .ARM.extab or .ARM.exidx section // Get .ARM.extab or .ARM.exidx section
const MCSectionELF *EHSection = nullptr; const MCSectionELF *EHSection = nullptr;
if (const MCSymbol *Group = FnSection.getGroup()) { if (const MCSymbol *Group = FnSection.getGroup()) {
EHSection = getContext().getELFSection( EHSection =
EHSecName, Type, Flags | ELF::SHF_GROUP, Kind, getContext().getELFSection(EHSecName, Type, Flags | ELF::SHF_GROUP,
FnSection.getEntrySize(), Group->getName()); FnSection.getEntrySize(), Group->getName());
} else { } else {
EHSection = getContext().getELFSection(EHSecName, Type, Flags, Kind); EHSection = getContext().getELFSection(EHSecName, Type, Flags);
} }
assert(EHSection && "Failed to get the required EH section"); assert(EHSection && "Failed to get the required EH section");

View File

@ -33,14 +33,10 @@ void HexagonTargetObjectFile::Initialize(MCContext &Ctx,
TargetLoweringObjectFileELF::Initialize(Ctx, TM); TargetLoweringObjectFileELF::Initialize(Ctx, TM);
InitializeELF(TM.Options.UseInitArray); InitializeELF(TM.Options.UseInitArray);
SmallDataSection = SmallDataSection = getContext().getELFSection(
getContext().getELFSection(".sdata", ELF::SHT_PROGBITS, ".sdata", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
ELF::SHF_WRITE | ELF::SHF_ALLOC, SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
SectionKind::getDataRel()); ELF::SHF_WRITE | ELF::SHF_ALLOC);
SmallBSSSection =
getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
ELF::SHF_WRITE | ELF::SHF_ALLOC,
SectionKind::getBSS());
} }
// sdata/sbss support taken largely from the MIPS Backend. // sdata/sbss support taken largely from the MIPS Backend.

View File

@ -30,8 +30,7 @@ void MipsRegInfoRecord::EmitMipsOptionRecord() {
// 1-byte long nor fixed length but it matches the value GAS emits. // 1-byte long nor fixed length but it matches the value GAS emits.
const MCSectionELF *Sec = const MCSectionELF *Sec =
Context.getELFSection(".MIPS.options", ELF::SHT_MIPS_OPTIONS, Context.getELFSection(".MIPS.options", ELF::SHT_MIPS_OPTIONS,
ELF::SHF_ALLOC | ELF::SHF_MIPS_NOSTRIP, ELF::SHF_ALLOC | ELF::SHF_MIPS_NOSTRIP, 1, "");
SectionKind::getMetadata(), 1, "");
MCA.getOrCreateSectionData(*Sec).setAlignment(8); MCA.getOrCreateSectionData(*Sec).setAlignment(8);
Streamer->SwitchSection(Sec); Streamer->SwitchSection(Sec);
@ -47,9 +46,8 @@ void MipsRegInfoRecord::EmitMipsOptionRecord() {
Streamer->EmitIntValue(ri_cprmask[3], 4); Streamer->EmitIntValue(ri_cprmask[3], 4);
Streamer->EmitIntValue(ri_gp_value, 8); Streamer->EmitIntValue(ri_gp_value, 8);
} else { } else {
const MCSectionELF *Sec = const MCSectionELF *Sec = Context.getELFSection(
Context.getELFSection(".reginfo", ELF::SHT_MIPS_REGINFO, ELF::SHF_ALLOC, ".reginfo", ELF::SHT_MIPS_REGINFO, ELF::SHF_ALLOC, 24, "");
SectionKind::getMetadata(), 24, "");
MCA.getOrCreateSectionData(*Sec) MCA.getOrCreateSectionData(*Sec)
.setAlignment(MTS->getABI().IsN32() ? 8 : 4); .setAlignment(MTS->getABI().IsN32() ? 8 : 4);
Streamer->SwitchSection(Sec); Streamer->SwitchSection(Sec);

View File

@ -515,9 +515,8 @@ void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
MCContext &Context = MCA.getContext(); MCContext &Context = MCA.getContext();
MCStreamer &OS = getStreamer(); MCStreamer &OS = getStreamer();
const MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS, const MCSectionELF *Sec = Context.getELFSection(
ELF::SHF_ALLOC | ELF::SHT_REL, ".pdr", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHT_REL);
SectionKind::getMetadata());
const MCSymbolRefExpr *ExprRef = const MCSymbolRefExpr *ExprRef =
MCSymbolRefExpr::Create(Name, MCSymbolRefExpr::VK_None, Context); MCSymbolRefExpr::Create(Name, MCSymbolRefExpr::VK_None, Context);
@ -731,9 +730,8 @@ void MipsTargetELFStreamer::emitMipsAbiFlags() {
MCAssembler &MCA = getStreamer().getAssembler(); MCAssembler &MCA = getStreamer().getAssembler();
MCContext &Context = MCA.getContext(); MCContext &Context = MCA.getContext();
MCStreamer &OS = getStreamer(); MCStreamer &OS = getStreamer();
const MCSectionELF *Sec = const MCSectionELF *Sec = Context.getELFSection(
Context.getELFSection(".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
ELF::SHF_ALLOC, SectionKind::getMetadata(), 24, "");
MCSectionData &ABIShndxSD = MCA.getOrCreateSectionData(*Sec); MCSectionData &ABIShndxSD = MCA.getOrCreateSectionData(*Sec);
ABIShndxSD.setAlignment(8); ABIShndxSD.setAlignment(8);
OS.SwitchSection(Sec); OS.SwitchSection(Sec);

View File

@ -704,8 +704,8 @@ void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {
// Tell the assembler which ABI we are using // Tell the assembler which ABI we are using
std::string SectionName = std::string(".mdebug.") + getCurrentABIString(); std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
OutStreamer.SwitchSection(OutContext.getELFSection( OutStreamer.SwitchSection(
SectionName, ELF::SHT_PROGBITS, 0, SectionKind::getDataRel())); OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
// NaN: At the moment we only support: // NaN: At the moment we only support:
// 1. .nan legacy (default) // 1. .nan legacy (default)
@ -717,13 +717,11 @@ void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {
if (Subtarget->isABI_EABI()) { if (Subtarget->isABI_EABI()) {
if (Subtarget->isGP32bit()) if (Subtarget->isGP32bit())
OutStreamer.SwitchSection( OutStreamer.SwitchSection(OutContext.getELFSection(".gcc_compiled_long32",
OutContext.getELFSection(".gcc_compiled_long32", ELF::SHT_PROGBITS, 0, ELF::SHT_PROGBITS, 0));
SectionKind::getDataRel()));
else else
OutStreamer.SwitchSection( OutStreamer.SwitchSection(OutContext.getELFSection(".gcc_compiled_long64",
OutContext.getELFSection(".gcc_compiled_long64", ELF::SHT_PROGBITS, 0, ELF::SHT_PROGBITS, 0));
SectionKind::getDataRel()));
} }
getTargetStreamer().updateABIInfo(*Subtarget); getTargetStreamer().updateABIInfo(*Subtarget);
@ -945,7 +943,7 @@ void MipsAsmPrinter::EmitFPCallStub(
// //
const MCSectionELF *M = OutContext.getELFSection( const MCSectionELF *M = OutContext.getELFSection(
".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS, ".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_EXECINSTR, SectionKind::getText()); ELF::SHF_ALLOC | ELF::SHF_EXECINSTR);
OutStreamer.SwitchSection(M, nullptr); OutStreamer.SwitchSection(M, nullptr);
// //
// .align 2 // .align 2

View File

@ -39,15 +39,11 @@ void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
TargetLoweringObjectFileELF::Initialize(Ctx, TM); TargetLoweringObjectFileELF::Initialize(Ctx, TM);
InitializeELF(TM.Options.UseInitArray); InitializeELF(TM.Options.UseInitArray);
SmallDataSection = SmallDataSection = getContext().getELFSection(
getContext().getELFSection(".sdata", ELF::SHT_PROGBITS, ".sdata", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
ELF::SHF_WRITE |ELF::SHF_ALLOC,
SectionKind::getDataRel());
SmallBSSSection = SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
getContext().getELFSection(".sbss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
ELF::SHF_WRITE |ELF::SHF_ALLOC,
SectionKind::getBSS());
this->TM = &TM; this->TM = &TM;
} }

View File

@ -953,9 +953,8 @@ void PPCLinuxAsmPrinter::EmitStartOfAsmFile(Module &M) {
if (M.getPICLevel() == PICLevel::Small) if (M.getPICLevel() == PICLevel::Small)
return AsmPrinter::EmitStartOfAsmFile(M); return AsmPrinter::EmitStartOfAsmFile(M);
OutStreamer.SwitchSection(OutContext.getELFSection(".got2", OutStreamer.SwitchSection(OutContext.getELFSection(
ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC, ".got2", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC));
SectionKind::getReadOnly()));
MCSymbol *TOCSym = OutContext.GetOrCreateSymbol(Twine(".LTOC")); MCSymbol *TOCSym = OutContext.GetOrCreateSymbol(Twine(".LTOC"));
MCSymbol *CurrentPos = OutContext.CreateTempSymbol(); MCSymbol *CurrentPos = OutContext.CreateTempSymbol();
@ -1007,9 +1006,8 @@ void PPCLinuxAsmPrinter::EmitFunctionEntryLabel() {
// Emit an official procedure descriptor. // Emit an official procedure descriptor.
MCSectionSubPair Current = OutStreamer.getCurrentSection(); MCSectionSubPair Current = OutStreamer.getCurrentSection();
const MCSectionELF *Section = OutStreamer.getContext().getELFSection(".opd", const MCSectionELF *Section = OutStreamer.getContext().getELFSection(
ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC, ".opd", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
SectionKind::getReadOnly());
OutStreamer.SwitchSection(Section); OutStreamer.SwitchSection(Section);
OutStreamer.EmitLabel(CurrentFnSym); OutStreamer.EmitLabel(CurrentFnSym);
OutStreamer.EmitValueToAlignment(8); OutStreamer.EmitValueToAlignment(8);
@ -1047,13 +1045,11 @@ bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
const MCSectionELF *Section; const MCSectionELF *Section;
if (isPPC64) if (isPPC64)
Section = OutStreamer.getContext().getELFSection(".toc", Section = OutStreamer.getContext().getELFSection(
ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC, ".toc", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
SectionKind::getReadOnly()); else
else Section = OutStreamer.getContext().getELFSection(
Section = OutStreamer.getContext().getELFSection(".got2", ".got2", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC,
SectionKind::getReadOnly());
OutStreamer.SwitchSection(Section); OutStreamer.SwitchSection(Section);
for (MapVector<MCSymbol*, MCSymbol*>::iterator I = TOC.begin(), for (MapVector<MCSymbol*, MCSymbol*>::iterator I = TOC.begin(),

View File

@ -110,9 +110,8 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
EmitFunctionHeader(); EmitFunctionHeader();
MCContext &Context = getObjFileLowering().getContext(); MCContext &Context = getObjFileLowering().getContext();
const MCSectionELF *ConfigSection = Context.getELFSection(".AMDGPU.config", const MCSectionELF *ConfigSection =
ELF::SHT_PROGBITS, 0, Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0);
SectionKind::getReadOnly());
OutStreamer.SwitchSection(ConfigSection); OutStreamer.SwitchSection(ConfigSection);
const AMDGPUSubtarget &STM = TM.getSubtarget<AMDGPUSubtarget>(); const AMDGPUSubtarget &STM = TM.getSubtarget<AMDGPUSubtarget>();
@ -136,10 +135,8 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
EmitFunctionBody(); EmitFunctionBody();
if (isVerbose()) { if (isVerbose()) {
const MCSectionELF *CommentSection const MCSectionELF *CommentSection =
= Context.getELFSection(".AMDGPU.csdata", Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0);
ELF::SHT_PROGBITS, 0,
SectionKind::getReadOnly());
OutStreamer.SwitchSection(CommentSection); OutStreamer.SwitchSection(CommentSection);
if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) { if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) {
@ -165,9 +162,8 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
if (STM.dumpCode() && DisasmEnabled) { if (STM.dumpCode() && DisasmEnabled) {
OutStreamer.SwitchSection(Context.getELFSection(".AMDGPU.disasm", OutStreamer.SwitchSection(
ELF::SHT_NOTE, 0, Context.getELFSection(".AMDGPU.disasm", ELF::SHT_NOTE, 0));
SectionKind::getReadOnly()));
for (size_t i = 0; i < DisasmLines.size(); ++i) { for (size_t i = 0; i < DisasmLines.size(); ++i) {
std::string Comment(DisasmLineMaxLen - DisasmLines[i].size(), ' '); std::string Comment(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
@ -510,8 +506,8 @@ void AMDGPUAsmPrinter::EmitAmdKernelCodeT(const MachineFunction &MF,
header.wavefront_size = STM.getWavefrontSize(); header.wavefront_size = STM.getWavefrontSize();
const MCSectionELF *VersionSection = OutContext.getELFSection(".hsa.version", const MCSectionELF *VersionSection =
ELF::SHT_PROGBITS, 0, SectionKind::getReadOnly()); OutContext.getELFSection(".hsa.version", ELF::SHT_PROGBITS, 0);
OutStreamer.SwitchSection(VersionSection); OutStreamer.SwitchSection(VersionSection);
OutStreamer.EmitBytes(Twine("HSA Code Unit:" + OutStreamer.EmitBytes(Twine("HSA Code Unit:" +
Twine(header.hsail_version_major) + "." + Twine(header.hsail_version_major) + "." +

View File

@ -21,66 +21,43 @@ using namespace llvm;
void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){ void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
TargetLoweringObjectFileELF::Initialize(Ctx, TM); TargetLoweringObjectFileELF::Initialize(Ctx, TM);
BSSSection = BSSSection = Ctx.getELFSection(".dp.bss", ELF::SHT_NOBITS,
Ctx.getELFSection(".dp.bss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE |
ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::XCORE_SHF_DP_SECTION);
ELF::XCORE_SHF_DP_SECTION, BSSSectionLarge = Ctx.getELFSection(".dp.bss.large", ELF::SHT_NOBITS,
SectionKind::getBSS()); ELF::SHF_ALLOC | ELF::SHF_WRITE |
BSSSectionLarge = ELF::XCORE_SHF_DP_SECTION);
Ctx.getELFSection(".dp.bss.large", ELF::SHT_NOBITS, DataSection = Ctx.getELFSection(".dp.data", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_WRITE |
ELF::XCORE_SHF_DP_SECTION, ELF::XCORE_SHF_DP_SECTION);
SectionKind::getBSS()); DataSectionLarge = Ctx.getELFSection(".dp.data.large", ELF::SHT_PROGBITS,
DataSection = ELF::SHF_ALLOC | ELF::SHF_WRITE |
Ctx.getELFSection(".dp.data", ELF::SHT_PROGBITS, ELF::XCORE_SHF_DP_SECTION);
ELF::SHF_ALLOC | ELF::SHF_WRITE | DataRelROSection = Ctx.getELFSection(".dp.rodata", ELF::SHT_PROGBITS,
ELF::XCORE_SHF_DP_SECTION, ELF::SHF_ALLOC | ELF::SHF_WRITE |
SectionKind::getDataRel()); ELF::XCORE_SHF_DP_SECTION);
DataSectionLarge = DataRelROSectionLarge = Ctx.getELFSection(
Ctx.getELFSection(".dp.data.large", ELF::SHT_PROGBITS, ".dp.rodata.large", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::XCORE_SHF_DP_SECTION);
ELF::XCORE_SHF_DP_SECTION,
SectionKind::getDataRel());
DataRelROSection =
Ctx.getELFSection(".dp.rodata", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE |
ELF::XCORE_SHF_DP_SECTION,
SectionKind::getReadOnlyWithRel());
DataRelROSectionLarge =
Ctx.getELFSection(".dp.rodata.large", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE |
ELF::XCORE_SHF_DP_SECTION,
SectionKind::getReadOnlyWithRel());
ReadOnlySection = ReadOnlySection =
Ctx.getELFSection(".cp.rodata", ELF::SHT_PROGBITS, Ctx.getELFSection(".cp.rodata", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_ALLOC | ELF::XCORE_SHF_CP_SECTION);
ELF::XCORE_SHF_CP_SECTION,
SectionKind::getReadOnlyWithRel());
ReadOnlySectionLarge = ReadOnlySectionLarge =
Ctx.getELFSection(".cp.rodata.large", ELF::SHT_PROGBITS, Ctx.getELFSection(".cp.rodata.large", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_ALLOC | ELF::XCORE_SHF_CP_SECTION);
ELF::XCORE_SHF_CP_SECTION, MergeableConst4Section = Ctx.getELFSection(
SectionKind::getReadOnlyWithRel()); ".cp.rodata.cst4", ELF::SHT_PROGBITS,
MergeableConst4Section = ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::XCORE_SHF_CP_SECTION, 4, "");
Ctx.getELFSection(".cp.rodata.cst4", ELF::SHT_PROGBITS, MergeableConst8Section = Ctx.getELFSection(
ELF::SHF_ALLOC | ELF::SHF_MERGE | ".cp.rodata.cst8", ELF::SHT_PROGBITS,
ELF::XCORE_SHF_CP_SECTION, ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::XCORE_SHF_CP_SECTION, 8, "");
SectionKind::getMergeableConst4()); MergeableConst16Section = Ctx.getELFSection(
MergeableConst8Section = ".cp.rodata.cst16", ELF::SHT_PROGBITS,
Ctx.getELFSection(".cp.rodata.cst8", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::XCORE_SHF_CP_SECTION, 16, "");
ELF::SHF_ALLOC | ELF::SHF_MERGE |
ELF::XCORE_SHF_CP_SECTION,
SectionKind::getMergeableConst8());
MergeableConst16Section =
Ctx.getELFSection(".cp.rodata.cst16", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_MERGE |
ELF::XCORE_SHF_CP_SECTION,
SectionKind::getMergeableConst16());
CStringSection = CStringSection =
Ctx.getELFSection(".cp.rodata.string", ELF::SHT_PROGBITS, Ctx.getELFSection(".cp.rodata.string", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS |
ELF::XCORE_SHF_CP_SECTION, ELF::XCORE_SHF_CP_SECTION);
SectionKind::getReadOnlyWithRel());
// TextSection - see MObjectFileInfo.cpp // TextSection - see MObjectFileInfo.cpp
// StaticCtorSection - see MObjectFileInfo.cpp // StaticCtorSection - see MObjectFileInfo.cpp
// StaticDtorSection - see MObjectFileInfo.cpp // StaticDtorSection - see MObjectFileInfo.cpp
@ -128,7 +105,7 @@ XCoreTargetObjectFile::getExplicitSectionGlobal(const GlobalValue *GV,
if (IsCPRel && !Kind.isReadOnly()) if (IsCPRel && !Kind.isReadOnly())
report_fatal_error("Using .cp. section for writeable object."); report_fatal_error("Using .cp. section for writeable object.");
return getContext().getELFSection(SectionName, getXCoreSectionType(Kind), return getContext().getELFSection(SectionName, getXCoreSectionType(Kind),
getXCoreSectionFlags(Kind, IsCPRel), Kind); getXCoreSectionFlags(Kind, IsCPRel));
} }
const MCSection *XCoreTargetObjectFile:: const MCSection *XCoreTargetObjectFile::