summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-09-26 00:54:24 +0000
committerRui Ueyama <ruiu@google.com>2017-09-26 00:54:24 +0000
commite26b7aafe0e28ca2b07020f0bdd24f68230c5053 (patch)
tree69cef178663b207f6918d19572acd8bc855d3526
parentdada014781e8277ddc829e47aa337ab9792d8485 (diff)
downloadbcm5719-llvm-e26b7aafe0e28ca2b07020f0bdd24f68230c5053.tar.gz
bcm5719-llvm-e26b7aafe0e28ca2b07020f0bdd24f68230c5053.zip
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. llvm-svn: 314181
-rw-r--r--lld/ELF/SyntheticSections.cpp29
-rw-r--r--lld/ELF/SyntheticSections.h34
2 files changed, 38 insertions, 25 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 66b5351de4a..57d03ffdf16 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2185,13 +2185,11 @@ void MergeSyntheticSection::addSection(MergeInputSection *MS) {
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::finalizeTailMerge() {
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::finalizeNoTailMerge() {
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;
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 081d086d669..dbd0724eaea 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -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.
OpenPOWER on IntegriCloud