Skip to content

Commit 83fc85c

Browse files
Remove shadowing "size" field from classes that inherit from SyntheticSection (#166323)
A field-named 'size' already available and perfectly usable via inheritance from InputSection, and these variables shadow it for no good reason. The only interesting change here is in PaddingSection, because a parent's field cannot be initialized via a constructor initializer list, setting it needs to be done inside the constructor body.
1 parent d163988 commit 83fc85c

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,9 +2747,9 @@ RelroPaddingSection::RelroPaddingSection(Ctx &ctx)
27472747
: SyntheticSection(ctx, ".relro_padding", SHT_NOBITS, SHF_ALLOC | SHF_WRITE,
27482748
1) {}
27492749

2750-
PaddingSection::PaddingSection(Ctx &ctx, uint64_t size, OutputSection *parent)
2751-
: SyntheticSection(ctx, ".padding", SHT_PROGBITS, SHF_ALLOC, 1),
2752-
size(size) {
2750+
PaddingSection::PaddingSection(Ctx &ctx, uint64_t amount, OutputSection *parent)
2751+
: SyntheticSection(ctx, ".padding", SHT_PROGBITS, SHF_ALLOC, 1) {
2752+
size = amount;
27532753
this->parent = parent;
27542754
}
27552755

lld/ELF/SyntheticSections.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ class EhFrameSection final : public SyntheticSection {
7878
// allocating one for each EhInputSection.
7979
llvm::DenseMap<size_t, CieRecord *> offsetToCie;
8080

81-
uint64_t size = 0;
82-
8381
template <llvm::endianness E> void addRecords(EhInputSection *s);
8482
template <class ELFT>
8583
void iterateFDEWithLSDAAux(EhInputSection &sec,
@@ -127,7 +125,6 @@ class GotSection final : public SyntheticSection {
127125
protected:
128126
size_t numEntries = 0;
129127
uint32_t tlsIndexOff = -1;
130-
uint64_t size = 0;
131128
struct AuthEntryInfo {
132129
size_t offset;
133130
bool isSymbolFunc;
@@ -182,7 +179,6 @@ class BssSection final : public SyntheticSection {
182179
static bool classof(const SectionBase *s) {
183180
return isa<SyntheticSection>(s) && cast<SyntheticSection>(s)->bss;
184181
}
185-
uint64_t size;
186182
};
187183

188184
class MipsGotSection final : public SyntheticSection {
@@ -312,8 +308,6 @@ class MipsGotSection final : public SyntheticSection {
312308
// Number of "Header" entries.
313309
static const unsigned headerEntriesNum = 2;
314310

315-
uint64_t size = 0;
316-
317311
// Symbol and addend.
318312
using GotEntry = std::pair<Symbol *, int64_t>;
319313

@@ -407,8 +401,6 @@ class StringTableSection final : public SyntheticSection {
407401
private:
408402
const bool dynamic;
409403

410-
uint64_t size = 0;
411-
412404
llvm::DenseMap<llvm::CachedHashStringRef, unsigned> stringMap;
413405
SmallVector<StringRef, 0> strings;
414406
};
@@ -475,7 +467,6 @@ template <class ELFT> class DynamicSection final : public SyntheticSection {
475467

476468
private:
477469
std::vector<std::pair<int32_t, uint64_t>> computeContents();
478-
uint64_t size = 0;
479470
};
480471

481472
class RelocationBaseSection : public SyntheticSection {
@@ -780,10 +771,8 @@ class RelroPaddingSection final : public SyntheticSection {
780771
};
781772

782773
class PaddingSection final : public SyntheticSection {
783-
uint64_t size;
784-
785774
public:
786-
PaddingSection(Ctx &ctx, uint64_t size, OutputSection *parent);
775+
PaddingSection(Ctx &ctx, uint64_t amount, OutputSection *parent);
787776
size_t getSize() const override { return size; }
788777
void writeTo(uint8_t *buf) override;
789778
};

0 commit comments

Comments
 (0)