diff options
author | Sam Clegg <sbc@chromium.org> | 2020-12-04 10:43:07 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-04 10:43:07 -0800 |
commit | 7f09ac527f59834fd5cca9311cb92ff28aad99d5 (patch) | |
tree | d16f5e3f3e66bdd7e17aeeebd7bc766ea64facdf /src | |
parent | bd9872ddf850bf177298a5274a15807e6227cd3d (diff) | |
download | binaryen-7f09ac527f59834fd5cca9311cb92ff28aad99d5.tar.gz binaryen-7f09ac527f59834fd5cca9311cb92ff28aad99d5.tar.bz2 binaryen-7f09ac527f59834fd5cca9311cb92ff28aad99d5.zip |
Don't apply SafeHeap to wasm start function (#3424)
In relocable code (MAIN/SIDE modules) we use the start function to run
`__wasm_init_memory` which loads the data segments into place. We
can't call get_sbkr pointer during that function because the sbrk
pointer itself lives in static data segment.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/SafeHeap.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/passes/SafeHeap.cpp b/src/passes/SafeHeap.cpp index ccfbfbf14..a0006c973 100644 --- a/src/passes/SafeHeap.cpp +++ b/src/passes/SafeHeap.cpp @@ -67,6 +67,10 @@ struct AccessInstrumenter : public WalkerPass<PostWalker<AccessInstrumenter>> { // If the getSbrkPtr function is implemented in the wasm, we must not // instrument that, as it would lead to infinite recursion of it calling // SAFE_HEAP_LOAD that calls it and so forth. + // As well as the getSbrkPtr function we also avoid instrumenting the + // module start function. This is because this function is used in + // shared memory builds to load the passive memory segments, which in + // turn means that value of sbrk() is not available. Name getSbrkPtr; bool isFunctionParallel() override { return true; } @@ -78,7 +82,8 @@ struct AccessInstrumenter : public WalkerPass<PostWalker<AccessInstrumenter>> { AccessInstrumenter(Name getSbrkPtr) : getSbrkPtr(getSbrkPtr) {} void visitLoad(Load* curr) { - if (getFunction()->name == getSbrkPtr || curr->type == Type::unreachable) { + if (getFunction()->name == getModule()->start || + getFunction()->name == getSbrkPtr || curr->type == Type::unreachable) { return; } Builder builder(*getModule()); @@ -89,7 +94,8 @@ struct AccessInstrumenter : public WalkerPass<PostWalker<AccessInstrumenter>> { } void visitStore(Store* curr) { - if (getFunction()->name == getSbrkPtr || curr->type == Type::unreachable) { + if (getFunction()->name == getModule()->start || + getFunction()->name == getSbrkPtr || curr->type == Type::unreachable) { return; } Builder builder(*getModule()); |