[llvm] [WebAssembly] Support multiple `.init_array` fragments when writing Wasm objects (PR #111008)

George Stagg via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 10:09:16 PST 2024


================
@@ -1769,6 +1769,11 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
       WS.setIndex(InvalidIndex);
       continue;
     }
+    // Contents of .init_array sections are handled elsewhere.
+    if (WS.isDefined() &&
+        WS.getSection().getName().starts_with(".init_array")) {
----------------
georgestagg wrote:

> What will happen though if there is a reference to the p_init symbol though, either within the object itself, or in some other object. Would this result in a relocation with against a non-existent symbol?

Looks like in both cases you get an error at link time:
```
wasm-ld: error: symbol.o: invalid data relocation: init1
```

I see, that's probably not ideal.

> In this example which is the symbol that lives in the `.init_array` section? I guess it would be __CTOR?

Yes. Though Rust mangles the name.

> What do you think about landing this PR without this part of the patch and then following up with another PR for e.g. "Handle symbols in init_array sections".

I think I'm OK with that, a fresh set of eyes on it in a new PR might be good in any case. I'll push a commit to remove this part of the PR.


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


More information about the llvm-commits mailing list