[llvm] r229541 - Add r228980 back.
Rafael Espindola
rafael.espindola at gmail.com
Tue Feb 17 12:48:01 PST 2015
Author: rafael
Date: Tue Feb 17 14:48:01 2015
New Revision: 229541
URL: http://llvm.org/viewvc/llvm-project?rev=229541&view=rev
Log:
Add r228980 back.
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>.
Modified:
llvm/trunk/include/llvm/CodeGen/CommandFlags.h
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/include/llvm/MC/MCSectionELF.h
llvm/trunk/include/llvm/Target/TargetMachine.h
llvm/trunk/include/llvm/Target/TargetOptions.h
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
llvm/trunk/lib/MC/MCSectionELF.cpp
Modified: llvm/trunk/include/llvm/CodeGen/CommandFlags.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/CommandFlags.h?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/CommandFlags.h (original)
+++ llvm/trunk/include/llvm/CodeGen/CommandFlags.h Tue Feb 17 14:48:01 2015
@@ -207,6 +207,10 @@ FunctionSections("function-sections",
cl::desc("Emit functions into separate sections"),
cl::init(false));
+cl::opt<bool> UniqueSectionNames("unique-section-names",
+ cl::desc("Give unique names to every section"),
+ cl::init(true));
+
cl::opt<llvm::JumpTable::JumpTableType>
JTableType("jump-table-type",
cl::desc("Choose the type of Jump-Instruction Table for jumptable."),
@@ -284,6 +288,7 @@ static inline TargetOptions InitTargetOp
Options.UseInitArray = !UseCtors;
Options.DataSections = DataSections;
Options.FunctionSections = FunctionSections;
+ Options.UniqueSectionNames = UniqueSectionNames;
Options.MCOptions = InitMCTargetOptionsFromFlags();
Options.JTType = JTableType;
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Tue Feb 17 14:48:01 2015
@@ -277,6 +277,10 @@ namespace llvm {
unsigned Flags, unsigned EntrySize,
StringRef Group);
+ const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ unsigned Flags, unsigned EntrySize,
+ StringRef Group, bool Unique);
+
void renameELFSection(const MCSectionELF *Section, StringRef Name);
const MCSectionELF *CreateELFGroupSection();
Modified: llvm/trunk/include/llvm/MC/MCSectionELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionELF.h Tue Feb 17 14:48:01 2015
@@ -39,6 +39,8 @@ class MCSectionELF : public MCSection {
/// below.
unsigned Flags;
+ bool Unique;
+
/// EntrySize - The size of each entry in this section. This size only
/// makes sense for sections that contain fixed-sized entries. If a
/// section does not contain fixed-sized entries 'EntrySize' will be 0.
@@ -48,10 +50,10 @@ class MCSectionELF : public MCSection {
private:
friend class MCContext;
- MCSectionELF(StringRef Section, unsigned type, unsigned flags,
- SectionKind K, unsigned entrySize, const MCSymbol *group)
- : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
- EntrySize(entrySize), Group(group) {}
+ MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
+ unsigned entrySize, const MCSymbol *group, bool Unique)
+ : MCSection(SV_ELF, K), SectionName(Section), Type(type), Flags(flags),
+ Unique(Unique), EntrySize(entrySize), Group(group) {}
~MCSectionELF();
void setSectionName(StringRef Name) { SectionName = Name; }
Modified: llvm/trunk/include/llvm/Target/TargetMachine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetMachine.h?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetMachine.h (original)
+++ llvm/trunk/include/llvm/Target/TargetMachine.h Tue Feb 17 14:48:01 2015
@@ -171,6 +171,8 @@ public:
return Options.MCOptions.AsmVerbose;
}
+ bool getUniqueSectionNames() const { return Options.UniqueSectionNames; }
+
/// Return true if data objects should be emitted into their own section,
/// corresponds to -fdata-sections.
bool getDataSections() const {
Modified: llvm/trunk/include/llvm/Target/TargetOptions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOptions.h?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetOptions.h (original)
+++ llvm/trunk/include/llvm/Target/TargetOptions.h Tue Feb 17 14:48:01 2015
@@ -78,8 +78,8 @@ namespace llvm {
EnableFastISel(false), PositionIndependentExecutable(false),
UseInitArray(false), DisableIntegratedAS(false),
CompressDebugSections(false), FunctionSections(false),
- DataSections(false), TrapUnreachable(false), TrapFuncName(),
- FloatABIType(FloatABI::Default),
+ DataSections(false), UniqueSectionNames(true), TrapUnreachable(false),
+ TrapFuncName(), FloatABIType(FloatABI::Default),
AllowFPOpFusion(FPOpFusion::Standard), JTType(JumpTable::Single),
FCFI(false), ThreadModel(ThreadModel::POSIX),
CFIType(CFIntegrity::Sub), CFIEnforcing(false), CFIFuncName() {}
@@ -198,6 +198,8 @@ namespace llvm {
/// Emit data into separate sections.
unsigned DataSections : 1;
+ unsigned UniqueSectionNames : 1;
+
/// Emit target-specific trap instruction for 'unreachable' IR instructions.
unsigned TrapUnreachable : 1;
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Tue Feb 17 14:48:01 2015
@@ -228,25 +228,25 @@ const MCSection *TargetLoweringObjectFil
/// 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
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;
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Tue Feb 17 14:48:01 2015
@@ -1151,7 +1151,7 @@ ELFObjectWriter::createRelocationSection
const MCSectionELF *RelaSection = Ctx.getELFSection(
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
- Flags, EntrySize, Group);
+ Flags, EntrySize, Group, true);
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=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Tue Feb 17 14:48:01 2015
@@ -272,12 +272,13 @@ void MCContext::renameELFSection(const M
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::getELFSec
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;
}
Modified: llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp Tue Feb 17 14:48:01 2015
@@ -378,6 +378,8 @@ bool ELFAsmParser::ParseSectionArguments
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
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()) {
Modified: llvm/trunk/lib/MC/MCSectionELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSectionELF.cpp?rev=229541&r1=229540&r2=229541&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSectionELF.cpp (original)
+++ llvm/trunk/lib/MC/MCSectionELF.cpp Tue Feb 17 14:48:01 2015
@@ -24,6 +24,9 @@ MCSectionELF::~MCSectionELF() {} // anch
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(
printName(OS, Group->getName());
OS << ",comdat";
}
+
+ if (Unique)
+ OS << ",unique";
+
OS << '\n';
if (Subsection)
More information about the llvm-commits
mailing list