Skip to content

Commit 53b674e

Browse files
committed
[ELF] InputSectionBase: add bool compressed to avoid overloading size with compressed semantics
Rename uncompressedSize to size, to prepare for shrinking rawData+size from 3 words to 2 words.
1 parent 5fef791 commit 53b674e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lld/ELF/InputSection.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
103103
size_t InputSectionBase::getSize() const {
104104
if (auto *s = dyn_cast<SyntheticSection>(this))
105105
return s->getSize();
106-
if (uncompressedSize >= 0)
107-
return uncompressedSize;
106+
if (compressed)
107+
return size;
108108
return rawData.size() - bytesDropped;
109109
}
110110

@@ -121,7 +121,6 @@ static void decompressAux(const InputSectionBase &sec, uint8_t *out,
121121
}
122122

123123
void InputSectionBase::decompress() const {
124-
size_t size = uncompressedSize;
125124
uint8_t *uncompressedBuf;
126125
{
127126
static std::mutex mu;
@@ -131,7 +130,7 @@ void InputSectionBase::decompress() const {
131130

132131
invokeELFT(decompressAux, *this, uncompressedBuf, size);
133132
rawData = makeArrayRef(uncompressedBuf, size);
134-
uncompressedSize = -1;
133+
compressed = false;
135134
}
136135

137136
template <class ELFT> RelsOrRelas<ELFT> InputSectionBase::relsOrRelas() const {
@@ -230,7 +229,8 @@ template <typename ELFT> void InputSectionBase::parseCompressedHeader() {
230229
return;
231230
}
232231

233-
uncompressedSize = hdr->ch_size;
232+
compressed = true;
233+
size = hdr->ch_size;
234234
alignment = std::max<uint32_t>(hdr->ch_addralign, 1);
235235
}
236236

@@ -1102,10 +1102,10 @@ template <class ELFT> void InputSection::writeTo(uint8_t *buf) {
11021102

11031103
// If this is a compressed section, uncompress section contents directly
11041104
// to the buffer.
1105-
if (uncompressedSize >= 0) {
1105+
if (compressed) {
11061106
auto *hdr = reinterpret_cast<const typename ELFT::Chdr *>(rawData.data());
11071107
auto compressed = rawData.slice(sizeof(typename ELFT::Chdr));
1108-
size_t size = uncompressedSize;
1108+
size_t size = this->size;
11091109
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
11101110
? compression::zlib::decompress(compressed, buf, size)
11111111
: compression::zstd::decompress(compressed, buf, size))

lld/ELF/InputSection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class InputSectionBase : public SectionBase {
139139
// be reset to zero after uses.
140140
uint16_t bytesDropped = 0;
141141

142+
mutable bool compressed = false;
143+
142144
// Whether the section needs to be padded with a NOP filler due to
143145
// deleteFallThruJmpInsn.
144146
bool nopFiller = false;
@@ -163,7 +165,7 @@ class InputSectionBase : public SectionBase {
163165
}
164166

165167
ArrayRef<uint8_t> data() const {
166-
if (uncompressedSize >= 0)
168+
if (compressed)
167169
decompress();
168170
return rawData;
169171
}
@@ -240,7 +242,7 @@ class InputSectionBase : public SectionBase {
240242
// or -1 if rawData is not compressed (either because the section wasn't
241243
// compressed in the first place, or because we ended up uncompressing it).
242244
// Since the feature is not used often, this is usually -1.
243-
mutable int64_t uncompressedSize = -1;
245+
mutable int64_t size = -1;
244246
};
245247

246248
// SectionPiece represents a piece of splittable section contents.

0 commit comments

Comments
 (0)