summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-linker.cpp15
-rw-r--r--test/dot_s/export_malloc_free.s10
-rw-r--r--test/dot_s/export_malloc_free.wast4
3 files changed, 23 insertions, 6 deletions
diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp
index 2c9a4cd4d..b1160e94a 100644
--- a/src/wasm-linker.cpp
+++ b/src/wasm-linker.cpp
@@ -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) {
diff --git a/test/dot_s/export_malloc_free.s b/test/dot_s/export_malloc_free.s
index 0158811a4..2ace10db9 100644
--- a/test/dot_s/export_malloc_free.s
+++ b/test/dot_s/export_malloc_free.s
@@ -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
diff --git a/test/dot_s/export_malloc_free.wast b/test/dot_s/export_malloc_free.wast
index e3c2f3d6f..465049e16 100644
--- a/test/dot_s/export_malloc_free.wast
+++ b/test/dot_s/export_malloc_free.wast
@@ -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": [] }