Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Wasm: upgrade emscripten for an llvm and exception fixes. #8281

Merged
merged 4 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/how-to-build-WebAssembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Build WebAssembly on Windows ##

1. Install Emscripten by following the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html).
2. Follow the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#updating-the-sdk) to update Emscripten to 1.39.19 ```./emsdk install 1.39.19``` followed by ```./emsdk activate 1.39.19```
2. Follow the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#updating-the-sdk) to update Emscripten to 2.0.1 ```./emsdk install 2.0.0``` followed by ```./emsdk activate 2.0.0```
3. Install [Firefox](https://www.getfirefox.com) (for testing).
3. Get CoreRT set up by following the [Visual Studio instructions](how-to-build-and-run-ilcompiler-in-visual-studio.md).
4. Build the WebAssembly runtime by running ```build.cmd wasm``` from the repo root.
Expand Down
6 changes: 3 additions & 3 deletions eng/install-emscripten.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ git clone https://github.com/emscripten-core/emsdk.git

cd emsdk
rem checkout a known good version to avoid a random break when emscripten changes the top of tree.
git checkout dec8a63
git checkout c1f0ad9

powershell -NoProfile -NoLogo -ExecutionPolicy ByPass -command "& """%~dp0update-machine-certs.ps1""" %*"

rem Use the python that is downloaded to native-tools explicitly as its not on the path
call "%1"\..\native-tools\bin\python3 emsdk.py install 1.39.19
call "%1"\..\native-tools\bin\python3 emsdk.py install 2.0.0
if %errorlevel% NEQ 0 goto fail
call emsdk activate 1.39.19
call emsdk activate 2.0.0
if %errorlevel% NEQ 0 goto fail

exit /b 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2901,7 +2901,8 @@ private LLVMBasicBlockRef GetOrCreateLandingPad(ExceptionRegion tryRegion)
BuildFinallyFunclet(Module);
}

var exPtr = landingPadBuilder.BuildExtractValue(pad, 0, "ex");
// __cxa_begin catch to get the c++ exception object, must be paired with __cxa_end_catch (http://libcxxabi.llvm.org/spec.html)
var exPtr = landingPadBuilder.BuildCall(GetCxaBeginCatchFunction(), new LLVMValueRef[] { landingPadBuilder.BuildExtractValue(pad, 0, "ex") });

// unwrap managed, cast to 32bit pointer from 8bit personality signature pointer
var ex32Ptr = landingPadBuilder.BuildPointerCast(exPtr, LLVMTypeRef.CreatePointer(LLVMTypeRef.Int32, 0));
Expand Down Expand Up @@ -2953,6 +2954,8 @@ private LLVMBasicBlockRef GetOrCreateLandingPad(ExceptionRegion tryRegion)
landingPadBuilder.BuildCondBr(noCatch, secondPassBlock, foundCatchBlock);

landingPadBuilder.PositionAtEnd(foundCatchBlock);
// finished with the c++ exception
landingPadBuilder.BuildCall(GetCxaEndCatchFunction(), new LLVMValueRef[] { });

LLVMValueRef[] callCatchArgs = new LLVMValueRef[]
{
Expand Down Expand Up @@ -3026,6 +3029,26 @@ private LLVMBasicBlockRef GetOrCreateLandingPad(ExceptionRegion tryRegion)
return landingPad;
}

LLVMValueRef GetCxaBeginCatchFunction()
{
if (CxaBeginCatchFunction == default)
{
// takes the exception structure and returns the c++ exception, defined by emscripten
CxaBeginCatchFunction = Module.AddFunction("__cxa_begin_catch", LLVMTypeRef.CreateFunction(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0),
new LLVMTypeRef[] { LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0)}, false));
}
return CxaBeginCatchFunction;
}

LLVMValueRef GetCxaEndCatchFunction()
{
if (CxaEndCatchFunction == default)
{
CxaEndCatchFunction = Module.AddFunction("__cxa_end_catch", LLVMTypeRef.CreateFunction(LLVMTypeRef.Void, new LLVMTypeRef[] { }, false));
}
return CxaEndCatchFunction;
}

private void AddMethodReference(MethodDesc method)
{
_dependencies.Add(_compilation.NodeFactory.MethodEntrypoint(method));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public static void CompileMethod(WebAssemblyCodegenCompilation compilation, WebA
static LLVMValueRef DebugtrapFunction = default(LLVMValueRef);
static LLVMValueRef TrapFunction = default(LLVMValueRef);
static LLVMValueRef DoNothingFunction = default(LLVMValueRef);
static LLVMValueRef CxaBeginCatchFunction = default(LLVMValueRef);
static LLVMValueRef CxaEndCatchFunction = default(LLVMValueRef);
static LLVMValueRef RhpThrowEx = default(LLVMValueRef);
static LLVMValueRef RhpCallCatchFunclet = default(LLVMValueRef);
static LLVMValueRef LlvmCatchFunclet = default(LLVMValueRef);
Expand Down