[llvm] [WebAssembly] Define `__funcref_call_table` in generated asm and objects (PR #180900)

Demetrius Kanios via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 23:22:57 PDT 2026


================
@@ -392,6 +392,22 @@ void WebAssemblyAsmPrinter::emitEndOfAsmFile(Module &M) {
   // emitDecls() is not called until now.
   emitDecls(M);
 
+  {
+    StringRef Name = "__funcref_call_table";
+    auto *Sym = static_cast<MCSymbolWasm *>(OutContext.lookupSymbol(Name));
+    if (Sym) {
+      if (!Sym->isFunctionTable())
+        OutContext.reportError(SMLoc(), "symbol is not a wasm funcref table");
+
+      if (Sym->isWeak()) {
+        OutStreamer->emitSymbolAttribute(Sym, MCSA_Weak);
+      }
+      if (!Sym->isDefined()) {
+        OutStreamer->emitLabel(Sym);
----------------
QuantumSegfault wrote:

`libc` doesn't make sense here.

Is `compiler-rt` linked in ALL invocations of `wasm-ld`? If not, then it's not a viable spot either.

So the only other option if we REALLY don't want to weak define the symbol in every relevant object is to have `lld` define it in a similar manner as `__indirect_function_table`. It just didn't seem necessary to complicate that when the definition of the table is nothing special (i.e. no non-default initialization of the table; just a simple, 1 element, `ref.null` initialized table).

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


More information about the llvm-commits mailing list