From f61676a18aca95bb435a3c2873812c8a4f9bed8b Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sun, 17 Dec 2017 17:52:01 +0000 Subject: [PATCH] [WebAssembly] Move code for copying of data segment relocation. NFC. This is a preparetory change for function gc which also requires relocations to be copied in ranges like this. Differential Revision: https://reviews.llvm.org/D41313 llvm-svn: 320948 --- lld/wasm/InputFiles.cpp | 17 +++++++++++++++-- lld/wasm/Writer.cpp | 6 ------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 993149532484..e7463da39db9 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -139,6 +139,14 @@ InputSegment *ObjFile::getSegment(const WasmSymbol &WasmSym) { 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 @@ void ObjFile::initializeSymbols() { 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 diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index 17f0bc46014c..61ac54a3e4b3 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -646,12 +646,6 @@ void Writer::createOutputSegments() { } 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); - } - } } } } -- 2.34.1