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

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 17:48:23 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);
----------------
sbc100 wrote:

An alternative solution here is to instead declare this table as undefined and rely on some external library (e.g. compiler-rt, libc, etc) to define it.  That is what we did for `__cpp_excection` and `__c_longjmp` tags which were previously defined weakly in each object.  See #159143 and #160959.

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


More information about the llvm-commits mailing list