[lld] [lld][WebAssembly]: Restore non-pie dynamic-linking executable (PR #108146)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 07:53:57 PDT 2024


================
@@ -1467,15 +1469,29 @@ void Writer::createApplyDataRelocationsFunction() {
   {
     raw_string_ostream os(bodyContent);
     writeUleb128(os, 0, "num locals");
+    uint64_t off = os.tell();
     for (const OutputSegment *seg : segments)
       if (!config->sharedMemory || !seg->isTLS())
         for (const InputChunk *inSeg : seg->inputSegments)
           inSeg->generateRelocationCode(os);
 
+    if (off == os.tell()) {
+      LLVM_DEBUG(dbgs() << "skipping empty __wasm_apply_data_relocs\n");
+      return;
+    }
     writeU8(os, WASM_OPCODE_END, "END");
   }
 
-  createFunction(WasmSym::applyDataRelocs, bodyContent);
+  // __wasm_apply_data_relocs
+  // Function that applies relocations to data segment post-instantiation.
+  static WasmSignature nullSignature = {{}, {}};
+  auto def = symtab->addSyntheticFunction(
+      "__wasm_apply_data_relocs",
+      WASM_SYMBOL_VISIBILITY_DEFAULT | WASM_SYMBOL_EXPORTED,
+      make<SyntheticFunction>(nullSignature, "__wasm_apply_data_relocs"));
+  def->markLive();
+
+  createFunction(def, bodyContent);
----------------
sbc100 wrote:

This change seems to incorporate a couple of different things now.   Would you mind separating out the change to "Only create __wasm_apply_data_relocs conditionally".  That seems like it could land separately and is somewhat unrelated to fix at hand? 

Also, regarding the conditional creation of this symbol, what happens if somebody does `--export=__wasm_apply_data_relocs` or otherwise references this symbol, but we "skip" creating it?






https://github.com/llvm/llvm-project/pull/108146


More information about the llvm-commits mailing list