-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export Table from standalone wasm modules #9907
Comments
We already have a linker flag for that: -Wl,--export-table. However we currently have whitelist of supported linker flags, we should probably switch the balcklist instead. |
We went back and forth on the blacklist/whitelist issue I think, and I don't remember the details... maybe it's simplest to just add that to the current whitelist? |
On my side the |
Seems I am still unable to use Have not seen |
Just an FYI, with the latest version of Emscripten (1.40.1), I don't need to adjust the emcc.py file anymore. |
Yes @Rochet2 is your issue something different? Does For normal mode (non-standalone) we always create the table in JS and import it into the wasm module. We don't support anyother mode that I know of. |
@sbc100 Here is a full example. The C file: #include <stdlib.h>
int foo() {
return 42;
}
int bar() {
return 9001;
}
__attribute__((used))
int main() {
int (*indirectly_called)() = rand()%2 == 0 ? &foo : &bar;
indirectly_called();
return 0;
} Command used to build: docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emcc example.c -o example.wasm -Os -Wl,--export-table,--no-entry,--export,malloc -s ALLOW_MEMORY_GROWTH=1 -s STANDALONE_WASM The generated (module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(type $t2 (func (param i32)))
(import "env" "emscripten_notify_memory_growth" (func $env.emscripten_notify_memory_growth (type $t2)))
;;;; <A bunch of functions here>
(table $T0 3 3 funcref)
(memory $memory 256 32768)
(global $g0 (mut i32) (i32.const 5244592))
(export "memory" (memory 0))
(export "__original_main" (func $__original_main))
(export "malloc" (func $malloc))
(elem $e0 (i32.const 1) $f6 $f2)
(data $d0 (i32.const 1552) "\b0\06P")) As you may see, both flags were used and the table is not exported even if one exists. Here is the version output: docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emcc --version
emcc (Emscripten gcc/clang-like replacement) 2.0.0 (d81f400831a22f04901ab149f29d3caf77979bf6)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
I tested your code on my side and the optimization flag seems to be the issue. If I change it from -Os to -O1 I see the following:
It now has an export for |
Great :) Trying to append If I feel like there are a few issues bundled in here. |
To tell it that you want the table to be allowed to grow, include the |
Thanks for clarifying. |
OK, so I see two issues here we could fix.
|
It looks like metadce removes the table export, as it sees it isn't used. We should probably rethink how metadce works with standalone mode, as this has come up before. As a workaround for now, though, building with |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
In standalone wasm modules we don't import the memory or the table. We do export the memory by default, but not the table.
Should we always export it, or optionally perhaps?
The text was updated successfully, but these errors were encountered: