@@ -55,7 +55,7 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
55
55
StringRef name, Kind sectionKind)
56
56
: SectionBase(sectionKind, name, flags, entsize, alignment, type, info,
57
57
link),
58
- file(file), rawData (data) {
58
+ file(file), content_ (data.data()), size(data.size() ) {
59
59
// In order to reduce memory allocation, we assume that mergeable
60
60
// sections are smaller than 4 GiB, which is not an unreasonable
61
61
// assumption as of 2017.
@@ -111,9 +111,9 @@ size_t InputSectionBase::getSize() const {
111
111
template <class ELFT >
112
112
static void decompressAux (const InputSectionBase &sec, uint8_t *out,
113
113
size_t size) {
114
- auto *hdr =
115
- reinterpret_cast < const typename ELFT::Chdr * >(sec.content (). data ());
116
- auto compressed = sec. content () .slice (sizeof (typename ELFT::Chdr));
114
+ auto *hdr = reinterpret_cast < const typename ELFT::Chdr *>(sec. content_ );
115
+ auto compressed = ArrayRef< uint8_t >(sec.content_ , sec. compressedSize )
116
+ .slice (sizeof (typename ELFT::Chdr));
117
117
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
118
118
? compression::zlib::decompress (compressed, out, size)
119
119
: compression::zstd::decompress (compressed, out, size))
@@ -130,7 +130,7 @@ void InputSectionBase::decompress() const {
130
130
}
131
131
132
132
invokeELFT (decompressAux, *this , uncompressedBuf, size);
133
- rawData = makeArrayRef ( uncompressedBuf, size) ;
133
+ content_ = uncompressedBuf;
134
134
compressed = false ;
135
135
}
136
136
@@ -231,6 +231,7 @@ template <typename ELFT> void InputSectionBase::parseCompressedHeader() {
231
231
}
232
232
233
233
compressed = true ;
234
+ compressedSize = size;
234
235
size = hdr->ch_size ;
235
236
alignment = std::max<uint32_t >(hdr->ch_addralign , 1 );
236
237
}
@@ -1104,8 +1105,9 @@ template <class ELFT> void InputSection::writeTo(uint8_t *buf) {
1104
1105
// If this is a compressed section, uncompress section contents directly
1105
1106
// to the buffer.
1106
1107
if (compressed) {
1107
- auto *hdr = reinterpret_cast <const typename ELFT::Chdr *>(content ().data ());
1108
- auto compressed = content ().slice (sizeof (typename ELFT::Chdr));
1108
+ auto *hdr = reinterpret_cast <const typename ELFT::Chdr *>(content_);
1109
+ auto compressed = ArrayRef<uint8_t >(content_, compressedSize)
1110
+ .slice (sizeof (typename ELFT::Chdr));
1109
1111
size_t size = this ->size ;
1110
1112
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
1111
1113
? compression::zlib::decompress (compressed, buf, size)
0 commit comments