[WebAssembly] Make EH work with dynamic linking
authorHeejin Ahn <aheejin@gmail.com>
Wed, 29 Sep 2021 21:17:14 +0000 (14:17 -0700)
committerHeejin Ahn <aheejin@gmail.com>
Wed, 13 Oct 2021 06:28:27 +0000 (23:28 -0700)
commit9261ee32dc41ae6f2ebf0608c3cec22daf5ec494
tree27fdb5f2fe2dd381a9a12fc7f833d5aa915ce4ad
parentfa6c5107c369be63c1923632d206e21a932f9870
[WebAssembly] Make EH work with dynamic linking

This makes Wasm EH work with dynamic linking. So far we were only able
to handle destructors, which do not use any tags or LSDA info.

1. This uses `TargetExternalSymbol` for `GCC_except_tableN` symbols,
   which points to the address of per-function LSDA info. It is more
   convenient to use than `MCSymbol` because it can take additional
   target flags.

2. When lowering `wasm_lsda` intrinsic, if PIC is enabled, make the
   symbol relative to `__memory_base` and generate the `add` node. If
   PIC is disabled, continue to use the absolute address.

3. Make tag symbols (`__cpp_exception` and `__c_longjmp`) undefined in
   the backend, because it is hard to make it work with dynamic
   linking's loading order. Instead, we make all tag symbols undefined
   in the LLVM backend and import it from JS.

4. Add support for undefined tags to the linker.

Companion patches:
- https://github.com/WebAssembly/binaryen/pull/4223
- https://github.com/emscripten-core/emscripten/pull/15266

Reviewed By: sbc100

Differential Revision: https://reviews.llvm.org/D111388
17 files changed:
lld/test/wasm/Inputs/tag-section1.ll
lld/test/wasm/Inputs/tag-section2.ll
lld/test/wasm/tag-section.ll
lld/wasm/InputFiles.cpp
lld/wasm/SymbolTable.cpp
lld/wasm/SymbolTable.h
lld/wasm/Symbols.cpp
lld/wasm/Symbols.h
lld/wasm/SyntheticSections.cpp
lld/wasm/SyntheticSections.h
llvm/lib/CodeGen/AsmPrinter/WasmException.cpp
llvm/lib/Object/WasmObjectFile.cpp
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
llvm/test/CodeGen/WebAssembly/eh-lsda.ll