Skip to content

Commit

Permalink
Fix overflow with optimized WASM code by ensuring that globals are in…
Browse files Browse the repository at this point in the history
…itialized. (envoyproxy#25)
  • Loading branch information
jplevyak authored Feb 21, 2019
1 parent 34802ac commit d3a53ef
Show file tree
Hide file tree
Showing 7 changed files with 31,809 additions and 94,909 deletions.
4 changes: 1 addition & 3 deletions source/extensions/common/wasm/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,10 @@ bool Context::isSsl() { return decoder_callbacks_->connection()->ssl() != nullpt
// Calls into the WASM code.
//
void Context::onStart() {
wasm_->wasmVm()->start(this);
if (wasm_->onStart_) {
wasm_->onStart_(this);
return;
}
// Fall back to any start or main() function.
wasm_->wasmVm()->start(this);
}

void Context::onConfigure(absl::string_view configuration) {
Expand Down
10 changes: 9 additions & 1 deletion source/extensions/common/wasm/wavm/wavm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,16 @@ bool Wavm::initialize(const std::string& code, absl::string_view name, bool allo

void Wavm::start(Context* context) {
auto f = getStartFunction(moduleInstance_);
if (!f)
if (f) {
CALL_WITH_CONTEXT(invokeFunctionChecked(context_, f, {}), context);
}
if (emscriptenInstance_) {
Emscripten::initializeGlobals(context_, irModule_, moduleInstance_);
}
f = asFunctionNullable(getInstanceExport(moduleInstance_, "main"));
if (!f) {
f = asFunctionNullable(getInstanceExport(moduleInstance_, "_main"));
}
if (f) {
CALL_WITH_CONTEXT(invokeFunctionChecked(context_, f, {}), context);
}
Expand Down
6 changes: 1 addition & 5 deletions test/extensions/filters/http/wasm/test_data/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ API=../../../../../../api/wasm/cpp

EMSCRIPTEN_OPT=-s WASM=1 -s EMIT_EMSCRIPTEN_METADATA=1

# Note that optimizations are disabled, because optimized WASM module
# throws wavm.integerDivideByZeroOrOverflow, possibly due to an issue
# with getFunctionWavm() templates and/or their usage.
#CXXFLAGS=--std=c++14 -O3 -g3
CXXFLAGS=--std=c++14 -g3
CXXFLAGS=--std=c++14 -O3 -g3

all: headers.wasm async_call.wasm

Expand Down
Binary file modified test/extensions/filters/http/wasm/test_data/async_call.wasm
Binary file not shown.
68,387 changes: 16,784 additions & 51,603 deletions test/extensions/filters/http/wasm/test_data/async_call.wat

Large diffs are not rendered by default.

Binary file modified test/extensions/filters/http/wasm/test_data/headers.wasm
Binary file not shown.
58,311 changes: 15,014 additions & 43,297 deletions test/extensions/filters/http/wasm/test_data/headers.wat

Large diffs are not rendered by default.

0 comments on commit d3a53ef

Please sign in to comment.