Index: lld/wasm/InputChunks.cpp =================================================================== --- lld/wasm/InputChunks.cpp +++ lld/wasm/InputChunks.cpp @@ -44,8 +44,10 @@ DEBUG(dbgs() << "write reloc: type=" << Reloc.Reloc.Type << " index=" << Reloc.Reloc.Index << " value=" << Reloc.Value << " offset=" << Reloc.Reloc.Offset << "\n"); + Buf += Reloc.Reloc.Offset; int64_t ExistingValue; + switch (Reloc.Reloc.Type) { case R_WEBASSEMBLY_TYPE_INDEX_LEB: case R_WEBASSEMBLY_FUNCTION_INDEX_LEB: @@ -74,19 +76,19 @@ } } -static void applyRelocations(uint8_t *Buf, ArrayRef Relocs) { - if (!Relocs.size()) +// Copy this input chunk to an mmap'ed output file. +void InputChunk::writeTo(uint8_t *Buf) const { + // Copy contents + memcpy(Buf + getOutputOffset(), data().data(), data().size()); + + // Apply relocations + if (OutRelocations.empty()) return; - DEBUG(dbgs() << "applyRelocations: count=" << Relocs.size() << "\n"); - for (const OutputRelocation &Reloc : Relocs) + DEBUG(dbgs() << "applyRelocations: count=" << OutRelocations.size() << "\n"); + for (const OutputRelocation &Reloc : OutRelocations) applyRelocation(Buf, Reloc); } -void InputChunk::writeTo(uint8_t *SectionStart) const { - memcpy(SectionStart + getOutputOffset(), data().data(), data().size()); - applyRelocations(SectionStart, OutRelocations); -} - // Populate OutRelocations based on the input relocations and offset within the // output section. Calculates the updated index and offset for each relocation // as well as the value to write out in the final binary.