diff options
author | Sam Clegg <sbc@chromium.org> | 2017-12-14 21:10:03 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2017-12-14 21:10:03 +0000 |
commit | 4273998cf9013ce92c7bf1effafef76a65e31d0c (patch) | |
tree | 940a95fe5e68525d73669766b55dc1a7c9be7832 /llvm/lib/Object/WasmObjectFile.cpp | |
parent | ea244bf89b794802a0a5addeed74919a605f8636 (diff) | |
download | llvm-4273998cf9013ce92c7bf1effafef76a65e31d0c.zip llvm-4273998cf9013ce92c7bf1effafef76a65e31d0c.tar.gz llvm-4273998cf9013ce92c7bf1effafef76a65e31d0c.tar.bz2 |
[WebAssembly] Add support for init functions linking metadata
Summary:
This change lays the groundwork lowering of @llvm.global_ctors
and @llvm.global_dtors for the wasm object format. Some parts
of this patch are subset of: https://reviews.llvm.org/D40759
See https://github.com/WebAssembly/tool-conventions/issues/25
Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish
Differential Revision: https://reviews.llvm.org/D41208
llvm-svn: 320742
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 8d4c15a..677fccc 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -398,6 +398,21 @@ Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr, } break; } + case wasm::WASM_INIT_FUNCS: { + uint32_t Count = readVaruint32(Ptr); + LinkingData.InitFunctions.reserve(Count); + for (uint32_t i = 0; i < Count; i++) { + wasm::WasmInitFunc Init; + Init.Priority = readVaruint32(Ptr); + Init.FunctionIndex = readVaruint32(Ptr); + if (!isValidFunctionIndex(Init.FunctionIndex)) + return make_error<GenericBinaryError>("Invalid function index: " + + Twine(Init.FunctionIndex), + object_error::parse_failed); + LinkingData.InitFunctions.emplace_back(Init); + } + break; + } default: Ptr += Size; break; @@ -656,9 +671,13 @@ Error WasmObjectFile::parseExportSection(const uint8_t *Ptr, const uint8_t *End) return Error::success(); } +bool WasmObjectFile::isValidFunctionIndex(uint32_t Index) const { + return Index < FunctionTypes.size() + NumImportedFunctions; +} + Error WasmObjectFile::parseStartSection(const uint8_t *Ptr, const uint8_t *End) { StartFunction = readVaruint32(Ptr); - if (StartFunction >= FunctionTypes.size()) + if (!isValidFunctionIndex(StartFunction)) return make_error<GenericBinaryError>("Invalid start function", object_error::parse_failed); return Error::success(); |