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
This commit is contained in:
Rui Ueyama 2017-09-26 00:54:24 +00:00
parent dada014781
commit e26b7aafe0
2 changed files with 39 additions and 26 deletions

View File

@ -2185,13 +2185,11 @@ void MergeSyntheticSection::addSection(MergeInputSection *MS) {
Sections.push_back(MS);
}
size_t MergeSyntheticSection::getSize() const { return Builder.getSize(); }
void MergeSyntheticSection::writeTo(uint8_t *Buf) { Builder.write(Buf); }
bool MergeSyntheticSection::shouldTailMerge() const {
return (this->Flags & SHF_STRINGS) && Config->Optimize >= 2;
}
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;

View File

@ -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:
void addSection(MergeInputSection *MS);
size_t getSize() const override;
void writeTo(uint8_t *Buf) override;
protected:
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;
private:
void finalizeTailMerge();
void finalizeNoTailMerge();
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.