Use short names for jumptable sections.

Also refactor code to remove some duplication.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230087 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-02-20 23:28:28 +00:00
parent bc051faae1
commit c093973970
2 changed files with 32 additions and 29 deletions

View File

@ -249,6 +249,27 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) {
return ".data.rel.ro";
}
static const MCSection *
getUniqueELFSection(MCContext &Ctx, const GlobalValue &GV, SectionKind Kind,
Mangler &Mang, const TargetMachine &TM, unsigned Flags) {
StringRef Prefix = getSectionPrefixForGlobal(Kind);
SmallString<128> Name(Prefix);
bool UniqueSectionNames = TM.getUniqueSectionNames();
if (UniqueSectionNames) {
Name.push_back('.');
TM.getNameWithPrefix(Name, &GV, Mang, true);
}
StringRef Group = "";
if (const Comdat *C = getELFComdat(&GV)) {
Flags |= ELF::SHF_GROUP;
Group = C->getName();
}
return Ctx.getELFSection(Name, getELFSectionType(Name, Kind), Flags, 0, Group,
!UniqueSectionNames);
}
const MCSection *TargetLoweringObjectFileELF::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler &Mang, const TargetMachine &TM) const {
@ -264,24 +285,8 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
EmitUniquedSection = TM.getDataSections();
}
if (EmitUniquedSection || GV->hasComdat()) {
StringRef Prefix = getSectionPrefixForGlobal(Kind);
SmallString<128> Name(Prefix);
bool UniqueSectionNames = TM.getUniqueSectionNames();
if (UniqueSectionNames) {
Name.push_back('.');
TM.getNameWithPrefix(Name, GV, Mang, true);
}
StringRef Group = "";
if (const Comdat *C = getELFComdat(GV)) {
Flags |= ELF::SHF_GROUP;
Group = C->getName();
}
return getContext().getELFSection(Name, getELFSectionType(Name, Kind),
Flags, 0, Group, !UniqueSectionNames);
}
if (EmitUniquedSection || GV->hasComdat())
return getUniqueELFSection(getContext(), *GV, Kind, Mang, TM, Flags);
if (Kind.isText()) return TextSection;
@ -346,17 +351,8 @@ const MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
if (!EmitUniqueSection)
return ReadOnlySection;
SmallString<128> Name(".rodata.");
TM.getNameWithPrefix(Name, &F, Mang, true);
unsigned Flags = ELF::SHF_ALLOC;
StringRef Group = "";
if (C) {
Flags |= ELF::SHF_GROUP;
Group = C->getName();
}
return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, Group);
return getUniqueELFSection(getContext(), F, SectionKind::getReadOnly(), Mang,
TM, ELF::SHF_ALLOC);
}
bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection(