[PATCH] D41313: [WebAssembly] Move code for copying of data segment relocation. NFC.

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 17 09:52:57 PST 2017


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320948: [WebAssembly] Move code for copying of data segment relocation. NFC. (authored by sbc, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D41313

Files:
  lld/trunk/wasm/InputFiles.cpp
  lld/trunk/wasm/Writer.cpp


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<WasmRelocation> &To,
+                                 ArrayRef<WasmRelocation> 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<InputSegment>(&Seg, this));
+  for (const WasmSegment &S : WasmObj->dataSegments()) {
+    InputSegment *Seg = make<InputSegment>(&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);
-        }
-      }
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41313.127287.patch
Type: text/x-patch
Size: 1948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171217/4a0f9ebb/attachment.bin>


More information about the llvm-commits mailing list