[llvm] [WebAssembly] Define `__funcref_call_table` in generated asm and objects (PR #180900)
Demetrius Kanios via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 12:47:25 PDT 2026
QuantumSegfault wrote:
> How are the size and contents of this table determinted?
It is always a default (null) initialized, single-element table. It's always exactly the same.
Which is why weakly defined per-object is ideal.
And it's used in the backend in such a way that we can't rely on any particular library being linked in. i.e. This should work without issues
```ll
; bin/llc -filetype=obj -mattr=+reference-types -o - test.ll
target triple = "wasm32-unknown-unknown"
define void @call_callback(ptr addrspace(20) %callback) {
entry:
call addrspace(20) void %callback()
ret void
}
```
But `-filetype=obj` errors out: `LLVM ERROR: undefined table symbol cannot be weak`. But to get an idea (with the default `asm` file type)
```s
.file "test.ll"
.tabletype __funcref_call_table, funcref, 1
.functype call_callback (funcref) -> ()
.section .text.call_callback,"",@
.globl call_callback # -- Begin function call_callback
.type call_callback, at function
call_callback: # @call_callback
.functype call_callback (funcref) -> ()
# %bb.0: # %entry
i32.const 0
local.get 0
table.set __funcref_call_table
i32.const 0
call_indirect __funcref_call_table, () -> ()
i32.const 0
ref.null_func
table.set __funcref_call_table
# fallthrough-return
end_function
```
https://github.com/llvm/llvm-project/pull/180900
More information about the llvm-commits
mailing list