aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-09-29 14:17:14 -0700
committerHeejin Ahn <aheejin@gmail.com>2021-10-12 23:28:27 -0700
commit9261ee32dc41ae6f2ebf0608c3cec22daf5ec494 (patch)
tree27fdb5f2fe2dd381a9a12fc7f833d5aa915ce4ad /llvm/lib/Object/WasmObjectFile.cpp
parentfa6c5107c369be63c1923632d206e21a932f9870 (diff)
downloadllvm-9261ee32dc41ae6f2ebf0608c3cec22daf5ec494.zip
llvm-9261ee32dc41ae6f2ebf0608c3cec22daf5ec494.tar.gz
llvm-9261ee32dc41ae6f2ebf0608c3cec22daf5ec494.tar.bz2
[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
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index a6a4748..ed23c53 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -1124,6 +1124,9 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
}
case wasm::WASM_EXTERNAL_TAG:
NumImportedTags++;
+ if (readUint8(Ctx) != 0) // Reserved 'attribute' field
+ return make_error<GenericBinaryError>("invalid attribute",
+ object_error::parse_failed);
Im.SigIndex = readVaruint32(Ctx);
if (Im.SigIndex >= NumTypes)
return make_error<GenericBinaryError>("invalid tag type",
@@ -1203,8 +1206,7 @@ Error WasmObjectFile::parseTagSection(ReadContext &Ctx) {
Tags.reserve(Count);
uint32_t NumTypes = Signatures.size();
while (Count--) {
- char Attr = readUint8(Ctx); // Reserved 'attribute' field
- if (Attr != 0)
+ if (readUint8(Ctx) != 0) // Reserved 'attribute' field
return make_error<GenericBinaryError>("invalid attribute",
object_error::parse_failed);
uint32_t Type = readVaruint32(Ctx);