When compiling C or C++ to web assembly (clang/llvm/binaryen) undefined functions are imported from "env".
For example
extern "C" int afunc();
int main() {
return afunc();
}
compiles to
(module
(type $FUNCSIG$i (func (result i32)))
(import "env" "afunc" (func $afunc (result i32)))
(table 0 anyfunc)
(memory $0 1)
(export "memory" (memory $0))
(export "main" (func $main))
(func $main (result i32)
(call $afunc)
)
)
I guess the line (import "env" "afunc" (func $afunc (result i32)))
means that it tries to request the function afunc
from the host environment. However, I found no documentation that the host environment should be named env
.
Is it possible to exert some control over these host imports? Specifically,
- can I rename it to something other than
env
? - is it possible to disable this behavior so that I get a linker error when a function is not defined (maybe unless it is a function known to be available in the host)?