[lld] r314181 - Split MergeSyntheticSection into Merge{Tail, NoTail}Section.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 25 17:54:24 PDT 2017
Author: ruiu
Date: Mon Sep 25 17:54:24 2017
New Revision: 314181
URL: http://llvm.org/viewvc/llvm-project?rev=314181&view=rev
Log:
Split MergeSyntheticSection into Merge{Tail,NoTail}Section.
This patch alone is neutral in terms of code readability, but this
change makes a following patch easier to read.
Modified:
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/SyntheticSections.h
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=314181&r1=314180&r2=314181&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Sep 25 17:54:24 2017
@@ -2185,13 +2185,11 @@ void MergeSyntheticSection::addSection(M
Sections.push_back(MS);
}
-void MergeSyntheticSection::writeTo(uint8_t *Buf) { Builder.write(Buf); }
+size_t MergeSyntheticSection::getSize() const { return Builder.getSize(); }
-bool MergeSyntheticSection::shouldTailMerge() const {
- return (this->Flags & SHF_STRINGS) && Config->Optimize >= 2;
-}
+void MergeSyntheticSection::writeTo(uint8_t *Buf) { Builder.write(Buf); }
-void MergeSyntheticSection::finalizeTailMerge() {
+void MergeTailSection::finalizeContents() {
// Add all string pieces to the string table builder to create section
// contents.
for (MergeInputSection *Sec : Sections)
@@ -2211,7 +2209,7 @@ void MergeSyntheticSection::finalizeTail
Sec->Pieces[I].OutputOff = Builder.getOffset(Sec->getData(I));
}
-void MergeSyntheticSection::finalizeNoTailMerge() {
+void MergeNoTailSection::finalizeContents() {
// Add all string pieces to the string table builder to create section
// contents. Because we are not tail-optimizing, offsets of strings are
// fixed when they are added to the builder (string table builder contains
@@ -2224,15 +2222,16 @@ void MergeSyntheticSection::finalizeNoTa
Builder.finalizeInOrder();
}
-void MergeSyntheticSection::finalizeContents() {
- if (shouldTailMerge())
- finalizeTailMerge();
- else
- finalizeNoTailMerge();
+static MergeSyntheticSection *createMergeSynthetic(StringRef Name,
+ uint32_t Type,
+ uint64_t Flags,
+ uint32_t Alignment) {
+ bool ShouldTailMerge = (Flags & SHF_STRINGS) && Config->Optimize >= 2;
+ if (ShouldTailMerge)
+ return make<MergeTailSection>(Name, Type, Flags, Alignment);
+ return make<MergeNoTailSection>(Name, Type, Flags, Alignment);
}
-size_t MergeSyntheticSection::getSize() const { return Builder.getSize(); }
-
// This function decompresses compressed sections and scans over the input
// sections to create mergeable synthetic sections. It removes
// MergeInputSections from the input section array and adds new synthetic
@@ -2270,8 +2269,8 @@ void elf::decompressAndMergeSections() {
Sec->Alignment == Alignment;
});
if (I == MergeSections.end()) {
- MergeSyntheticSection *Syn = make<MergeSyntheticSection>(
- OutsecName, MS->Type, MS->Flags, Alignment);
+ MergeSyntheticSection *Syn =
+ createMergeSynthetic(OutsecName, MS->Type, MS->Flags, Alignment);
MergeSections.push_back(Syn);
I = std::prev(MergeSections.end());
S = Syn;
Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=314181&r1=314180&r2=314181&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Mon Sep 25 17:54:24 2017
@@ -661,22 +661,36 @@ public:
// with different attributes in a single output sections. To do that
// we put them into MergeSyntheticSection synthetic input sections which are
// attached to regular output sections.
-class MergeSyntheticSection final : public SyntheticSection {
+class MergeSyntheticSection : public SyntheticSection {
public:
- MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags,
- uint32_t Alignment);
void addSection(MergeInputSection *MS);
- void writeTo(uint8_t *Buf) override;
- void finalizeContents() override;
- bool shouldTailMerge() const;
size_t getSize() const override;
+ void writeTo(uint8_t *Buf) override;
-private:
- void finalizeTailMerge();
- void finalizeNoTailMerge();
+protected:
+ MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags,
+ uint32_t Alignment);
- llvm::StringTableBuilder Builder;
std::vector<MergeInputSection *> Sections;
+ llvm::StringTableBuilder Builder;
+};
+
+class MergeTailSection final : public MergeSyntheticSection {
+public:
+ MergeTailSection(StringRef Name, uint32_t Type, uint64_t Flags,
+ uint32_t Alignment)
+ : MergeSyntheticSection(Name, Type, Flags, Alignment) {}
+
+ void finalizeContents() override;
+};
+
+class MergeNoTailSection final : public MergeSyntheticSection {
+public:
+ MergeNoTailSection(StringRef Name, uint32_t Type, uint64_t Flags,
+ uint32_t Alignment)
+ : MergeSyntheticSection(Name, Type, Flags, Alignment) {}
+
+ void finalizeContents() override;
};
// .MIPS.abiflags section.
More information about the llvm-commits
mailing list