summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-09-06 16:10:16 -0700
committerGitHub <noreply@github.com>2019-09-06 16:10:16 -0700
commitfefb75ef7f3b1cd6c8bf27dd6d288439c6ca7bc8 (patch)
tree279861742af4e2d4a1f15c5eea378022ce4c2973 /src
parent849ea2105919dbd65c003439fb8d16c55692c247 (diff)
downloadbinaryen-fefb75ef7f3b1cd6c8bf27dd6d288439c6ca7bc8.tar.gz
binaryen-fefb75ef7f3b1cd6c8bf27dd6d288439c6ca7bc8.tar.bz2
binaryen-fefb75ef7f3b1cd6c8bf27dd6d288439c6ca7bc8.zip
Properly handle fastcomp *wasm* safe heap (#2334)
Properly handle fastcomp wasm safe heap: emscripten_get_sbrk_ptr is an asm.js library function, which means it is inside the wasm after asm2wasm, and exported. Find it via the export.
Diffstat (limited to 'src')
-rw-r--r--src/passes/SafeHeap.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/passes/SafeHeap.cpp b/src/passes/SafeHeap.cpp
index d22ddea03..169c129b4 100644
--- a/src/passes/SafeHeap.cpp
+++ b/src/passes/SafeHeap.cpp
@@ -34,6 +34,7 @@ namespace wasm {
static const Name DYNAMICTOP_PTR_IMPORT("DYNAMICTOP_PTR");
static const Name GET_SBRK_PTR_IMPORT("emscripten_get_sbrk_ptr");
+static const Name GET_SBRK_PTR_EXPORT("_emscripten_get_sbrk_ptr");
static const Name SBRK("sbrk");
static const Name SEGFAULT_IMPORT("segfault");
static const Name ALIGNFAULT_IMPORT("alignfault");
@@ -119,12 +120,16 @@ struct SafeHeap : public Pass {
ImportInfo info(*module);
// Older emscripten imports env.DYNAMICTOP_PTR.
// Newer emscripten imports emscripten_get_sbrk_ptr(), which is later
- // optimized to have the number in the binary.
+ // optimized to have the number in the binary (or in the case of fastcomp,
+ // emscripten_get_sbrk_ptr is an asm.js library function so it is inside
+ // the wasm, and discoverable via an export).
if (auto* existing = info.getImportedGlobal(ENV, DYNAMICTOP_PTR_IMPORT)) {
dynamicTopPtr = existing->name;
} else if (auto* existing =
info.getImportedFunction(ENV, GET_SBRK_PTR_IMPORT)) {
getSbrkPtr = existing->name;
+ } else if (auto* existing = module->getExportOrNull(GET_SBRK_PTR_EXPORT)) {
+ getSbrkPtr = existing->value;
} else if (auto* existing = info.getImportedFunction(ENV, SBRK)) {
sbrk = existing->name;
} else {