diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-06-02 14:30:30 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2016-06-02 14:30:30 -0700 |
commit | d4dc216888d5028f41e6189e65001694e49a66c2 (patch) | |
tree | 35ac5962bedb07fa732b34b62f7b7c3d68280ce4 /test/dot_s/indirect-import.c | |
parent | d595e89003dc3636952de4c561679e3a077e6015 (diff) | |
download | binaryen-d4dc216888d5028f41e6189e65001694e49a66c2.tar.gz binaryen-d4dc216888d5028f41e6189e65001694e49a66c2.tar.bz2 binaryen-d4dc216888d5028f41e6189e65001694e49a66c2.zip |
Generate thunks for address-taken imports (#554)
Under emscripten, C code can take the address of a function implemented
in Javascript (which is exposed via an import in wasm). Because imports
do not have linear memory address in wasm, we need to generate a thunk
to be the target of the indirect call; it call the import directly.
This is facilited by a new .s directive (.functype) which declares the
types of functions which are declared but not defined.
Fixes https://github.com/WebAssembly/binaryen/issues/392
Diffstat (limited to 'test/dot_s/indirect-import.c')
-rw-r--r-- | test/dot_s/indirect-import.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/dot_s/indirect-import.c b/test/dot_s/indirect-import.c new file mode 100644 index 000000000..006424d84 --- /dev/null +++ b/test/dot_s/indirect-import.c @@ -0,0 +1,27 @@ +#include <stdint.h> + +struct big { + float a; + double b; + int32_t c; +}; + +float extern_fd(double); +void extern_vj(uint64_t); +void extern_v(void); +int32_t extern_ijidf(int64_t, int32_t, double, float); +void extern_struct(struct big); +struct big extern_sret(void); + +intptr_t bar() { + float (*fd)(double) = &extern_fd; + void (*vj)(uint64_t) = &extern_vj; + vj(1ULL); + void (*v)(void) = &extern_v; + v(); + int32_t (*ijidf)(int64_t, int32_t, double, float) = &extern_ijidf; + ijidf(1LL, 2, 3.0, 4.0f); + void (*vs)(struct big) = &extern_struct; + struct big (*s)(void) = &extern_sret; + return (intptr_t)fd; +} |