Skip to content

Commit bf7f3dd

Browse files
committed
[ELF] Move outSecOff addition from InputSection::writeTo to the caller
Simplify the code a bit and improve consistency with SyntheticSection::writeTo.
1 parent 0542d15 commit bf7f3dd

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

lld/ELF/InputSection.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ void InputSectionBase::adjustSplitStackFunctionPrologues(uint8_t *buf,
12271227

12281228
template <class ELFT> void InputSection::writeTo(uint8_t *buf) {
12291229
if (auto *s = dyn_cast<SyntheticSection>(this)) {
1230-
s->writeTo(buf + outSecOff);
1230+
s->writeTo(buf);
12311231
return;
12321232
}
12331233

@@ -1236,38 +1236,37 @@ template <class ELFT> void InputSection::writeTo(uint8_t *buf) {
12361236
// If -r or --emit-relocs is given, then an InputSection
12371237
// may be a relocation section.
12381238
if (LLVM_UNLIKELY(type == SHT_RELA)) {
1239-
copyRelocations<ELFT>(buf + outSecOff, getDataAs<typename ELFT::Rela>());
1239+
copyRelocations<ELFT>(buf, getDataAs<typename ELFT::Rela>());
12401240
return;
12411241
}
12421242
if (LLVM_UNLIKELY(type == SHT_REL)) {
1243-
copyRelocations<ELFT>(buf + outSecOff, getDataAs<typename ELFT::Rel>());
1243+
copyRelocations<ELFT>(buf, getDataAs<typename ELFT::Rel>());
12441244
return;
12451245
}
12461246

12471247
// If -r is given, we may have a SHT_GROUP section.
12481248
if (LLVM_UNLIKELY(type == SHT_GROUP)) {
1249-
copyShtGroup<ELFT>(buf + outSecOff);
1249+
copyShtGroup<ELFT>(buf);
12501250
return;
12511251
}
12521252

12531253
// If this is a compressed section, uncompress section contents directly
12541254
// to the buffer.
12551255
if (uncompressedSize >= 0) {
12561256
size_t size = uncompressedSize;
1257-
if (Error e = zlib::uncompress(toStringRef(rawData),
1258-
(char *)(buf + outSecOff), size))
1257+
if (Error e = zlib::uncompress(toStringRef(rawData), (char *)buf, size))
12591258
fatal(toString(this) +
12601259
": uncompress failed: " + llvm::toString(std::move(e)));
1261-
uint8_t *bufEnd = buf + outSecOff + size;
1262-
relocate<ELFT>(buf + outSecOff, bufEnd);
1260+
uint8_t *bufEnd = buf + size;
1261+
relocate<ELFT>(buf, bufEnd);
12631262
return;
12641263
}
12651264

12661265
// Copy section contents from source object file to output file
12671266
// and then apply relocations.
1268-
memcpy(buf + outSecOff, data().data(), data().size());
1269-
uint8_t *bufEnd = buf + outSecOff + data().size();
1270-
relocate<ELFT>(buf + outSecOff, bufEnd);
1267+
memcpy(buf, data().data(), data().size());
1268+
uint8_t *bufEnd = buf + data().size();
1269+
relocate<ELFT>(buf, bufEnd);
12711270
}
12721271

12731272
void InputSection::replace(InputSection *other) {

lld/ELF/OutputSections.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ template <class ELFT> void OutputSection::writeTo(uint8_t *buf) {
355355

356356
parallelForEachN(0, sections.size(), [&](size_t i) {
357357
InputSection *isec = sections[i];
358-
isec->writeTo<ELFT>(buf);
358+
isec->writeTo<ELFT>(buf + isec->outSecOff);
359359

360360
// Fill gaps between sections.
361361
if (nonZeroFiller) {

0 commit comments

Comments
 (0)