summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-02-12 23:29:51 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-02-12 23:29:51 +0000
commitb6a812ebb10c074266d6e4f9d2e2405bf57e4788 (patch)
treea108b29b58d3e0b9b9bdf17a74d667d207a3cc10 /llvm/lib
parenta12fcb790fb3694c6fcdf14047be72283ae4a0ee (diff)
downloadbcm5719-llvm-b6a812ebb10c074266d6e4f9d2e2405bf57e4788.tar.gz
bcm5719-llvm-b6a812ebb10c074266d6e4f9d2e2405bf57e4788.zip
Add support for having multiple sections with the same name and comdat.
Using this in combination with -ffunction-sections allows LLVM to output a .o file with mulitple sections named .text. This saves space by avoiding long unique names of the form .text.<C++ mangled name>. llvm-svn: 228980
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp31
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp2
-rw-r--r--llvm/lib/MC/MCContext.cpp20
-rw-r--r--llvm/lib/MC/MCParser/ELFAsmParser.cpp14
-rw-r--r--llvm/lib/MC/MCSectionELF.cpp7
5 files changed, 51 insertions, 23 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 4f46e37d39c..8aa66531b3d 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -228,25 +228,25 @@ const MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
/// DataSections.
static StringRef getSectionPrefixForGlobal(SectionKind Kind) {
if (Kind.isText())
- return ".text.";
+ return ".text";
if (Kind.isReadOnly())
- return ".rodata.";
+ return ".rodata";
if (Kind.isBSS())
- return ".bss.";
+ return ".bss";
if (Kind.isThreadData())
- return ".tdata.";
+ return ".tdata";
if (Kind.isThreadBSS())
- return ".tbss.";
+ return ".tbss";
if (Kind.isDataNoRel())
- return ".data.";
+ return ".data";
if (Kind.isDataRelLocal())
- return ".data.rel.local.";
+ return ".data.rel.local";
if (Kind.isDataRel())
- return ".data.rel.";
+ return ".data.rel";
if (Kind.isReadOnlyWithRelLocal())
- return ".data.rel.ro.local.";
+ return ".data.rel.ro.local";
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
- return ".data.rel.ro.";
+ return ".data.rel.ro";
}
const MCSection *TargetLoweringObjectFileELF::
@@ -268,16 +268,19 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
StringRef Prefix = getSectionPrefixForGlobal(Kind);
SmallString<128> Name(Prefix);
- TM.getNameWithPrefix(Name, GV, Mang, true);
-
+ 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.str(), getELFSectionType(Name.str(), Kind), Flags, 0, Group);
+ return getContext().getELFSection(Name, getELFSectionType(Name, Kind),
+ Flags, 0, Group, !UniqueSectionNames);
}
if (Kind.isText()) return TextSection;
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 5bddb09393f..b4948e659fb 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1151,7 +1151,7 @@ ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
const MCSectionELF *RelaSection = Ctx.getELFSection(
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
- Flags, EntrySize, Group);
+ Flags, EntrySize, Group, true);
return &Asm.getOrCreateSectionData(*RelaSection);
}
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 35609893e28..721edd451ee 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -272,12 +272,13 @@ void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) {
const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
- StringRef Group) {
+ StringRef Group, bool Unique) {
// 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;
+ if (!IterBool.second && !Unique)
+ return Entry.second;
MCSymbol *GroupSym = nullptr;
if (!Group.empty())
@@ -292,15 +293,22 @@ const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
Kind = SectionKind::getReadOnly();
MCSectionELF *Result = new (*this)
- MCSectionELF(CachedName, Type, Flags, Kind, EntrySize, GroupSym);
- Entry.second = Result;
+ MCSectionELF(CachedName, Type, Flags, Kind, EntrySize, GroupSym, Unique);
+ if (!Unique)
+ Entry.second = Result;
return Result;
}
+const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
+ unsigned Flags, unsigned EntrySize,
+ StringRef Group) {
+ return getELFSection(Section, Type, Flags, EntrySize, Group, false);
+}
+
const MCSectionELF *MCContext::CreateELFGroupSection() {
MCSectionELF *Result =
- new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
- SectionKind::getReadOnly(), 4, nullptr);
+ new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
+ SectionKind::getReadOnly(), 4, nullptr, false);
return Result;
}
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 21c65ce0b83..7a120a105d2 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -378,6 +378,8 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
unsigned Flags = 0;
const MCExpr *Subsection = nullptr;
bool UseLastGroup = false;
+ StringRef UniqueStr;
+ bool Unique = false;
// Set the defaults first.
if (SectionName == ".fini" || SectionName == ".init" ||
@@ -462,6 +464,14 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
return TokError("Linkage must be 'comdat'");
}
}
+ if (getLexer().is(AsmToken::Comma)) {
+ Lex();
+ if (getParser().parseIdentifier(UniqueStr))
+ return TokError("expected identifier in directive");
+ if (UniqueStr != "unique")
+ return TokError("expected 'unique'");
+ Unique = true;
+ }
}
}
@@ -509,8 +519,8 @@ EndStmt:
}
}
- const MCSection *ELFSection =
- getContext().getELFSection(SectionName, Type, Flags, Size, GroupName);
+ const MCSection *ELFSection = getContext().getELFSection(
+ SectionName, Type, Flags, Size, GroupName, Unique);
getStreamer().SwitchSection(ELFSection, Subsection);
if (getContext().getGenDwarfForAssembly()) {
diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp
index fb364c87a03..da3868273a7 100644
--- a/llvm/lib/MC/MCSectionELF.cpp
+++ b/llvm/lib/MC/MCSectionELF.cpp
@@ -24,6 +24,9 @@ MCSectionELF::~MCSectionELF() {} // anchor.
bool MCSectionELF::ShouldOmitSectionDirective(StringRef Name,
const MCAsmInfo &MAI) const {
+ if (Unique)
+ return false;
+
// FIXME: Does .section .bss/.data/.text work everywhere??
if (Name == ".text" || Name == ".data" ||
(Name == ".bss" && !MAI.usesELFSectionDirectiveForBSS()))
@@ -144,6 +147,10 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
printName(OS, Group->getName());
OS << ",comdat";
}
+
+ if (Unique)
+ OS << ",unique";
+
OS << '\n';
if (Subsection)
OpenPOWER on IntegriCloud