Permalink
Browse files

Asm.js-style setjmp/longjmp support for wasm (#681)

This needs to export realloc as well, in addition to malloc and free
handled in #4469. To support asm.js style setjmp/longjmp, wasm
needs to export realloc as well, in addition to malloc and free
handled in #4469. saveSetjmp() uses realloc within it, and realloc is
not implemented in JS glue code.
  • Loading branch information...
aheejin committed Aug 26, 2016
1 parent 801baed commit 4a04fc609133313ab18ef49599f365d3587af55b
Showing with 23 additions and 6 deletions.
  1. +9 −6 src/wasm-linker.cpp
  2. +10 −0 test/dot_s/export_malloc_free.s
  3. +4 −0 test/dot_s/export_malloc_free.wast
View
@@ -213,18 +213,21 @@ void Linker::layout() {
}
}
// Export malloc and free whenever availble. JavsScript version of malloc has
// some issues and it cannot be called once _sbrk() is called.
// TODO This should get the list of exported functions from emcc.py - it has
// EXPORTED_FUNCTION metadata to keep track of this. Get the list of exported
// functions using a command-line argument from emcc.py and export all of
// them.
// Export malloc, realloc, and free whenever availble. JavsScript version of
// malloc has some issues and it cannot be called once _sbrk() is called, and
// JS glue code does not have realloc(). TODO This should get the list of
// exported functions from emcc.py - it has EXPORTED_FUNCTION metadata to keep
// track of this. Get the list of exported functions using a command-line
// argument from emcc.py and export all of them.
if (out.symbolInfo.implementedFunctions.count("malloc")) {
exportFunction("malloc", true);
}
if (out.symbolInfo.implementedFunctions.count("free")) {
exportFunction("free", true);
}
if (out.symbolInfo.implementedFunctions.count("realloc")) {
exportFunction("realloc", true);
}
// finalize function table
if (out.wasm.table.segments.size() > 0) {
@@ -27,3 +27,13 @@ free:
.endfunc
.Lfunc_end21:
.size free, .Lfunc_end21-free
.weak realloc
.type realloc,@function
realloc:
.param i32, i32
.result i32
i32.const $push0=, 0
.endfunc
.Lfunc_end22:
.size realloc, .Lfunc_end22-free
@@ -4,6 +4,7 @@
(export "main" $main)
(export "malloc" $malloc)
(export "free" $free)
(export "realloc" $realloc)
(func $main (result i32)
(i32.const 0)
)
@@ -12,5 +13,8 @@
)
(func $free (param $0 i32)
)
(func $realloc (param $0 i32) (param $1 i32) (result i32)
(i32.const 0)
)
)
;; METADATA: { "asmConsts": {},"staticBump": 12, "initializers": [] }

0 comments on commit 4a04fc6

Please sign in to comment.