Index: lld/trunk/wasm/InputFiles.cpp =================================================================== --- lld/trunk/wasm/InputFiles.cpp +++ lld/trunk/wasm/InputFiles.cpp @@ -139,6 +139,14 @@ return nullptr; } +static void copyRelocationsRange(std::vector &To, + ArrayRef From, size_t Start, + size_t End) { + for (const WasmRelocation &R : From) + if (R.Offset >= Start && R.Offset < End) + To.push_back(R); +} + void ObjFile::initializeSymbols() { Symbols.reserve(WasmObj->getNumberOfSymbols()); @@ -156,8 +164,13 @@ FunctionSymbols.resize(FunctionImports + WasmObj->functions().size()); GlobalSymbols.resize(GlobalImports + WasmObj->globals().size()); - for (const WasmSegment &Seg : WasmObj->dataSegments()) - Segments.emplace_back(make(&Seg, this)); + for (const WasmSegment &S : WasmObj->dataSegments()) { + InputSegment *Seg = make(&S, this); + copyRelocationsRange(Seg->Relocations, DataSection->Relocations, + Seg->getInputSectionOffset(), + Seg->getInputSectionOffset() + Seg->getSize()); + Segments.emplace_back(Seg); + } // Populate `FunctionSymbols` and `GlobalSymbols` based on the WasmSymbols // in the object Index: lld/trunk/wasm/Writer.cpp =================================================================== --- lld/trunk/wasm/Writer.cpp +++ lld/trunk/wasm/Writer.cpp @@ -646,12 +646,6 @@ } S->addInputSegment(Segment); DEBUG(dbgs() << "added data: " << Name << ": " << S->Size << "\n"); - for (const WasmRelocation &R : File->DataSection->Relocations) { - if (R.Offset >= Segment->getInputSectionOffset() && - R.Offset < Segment->getInputSectionOffset() + Segment->getSize()) { - Segment->Relocations.push_back(R); - } - } } } }