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 | e1acb56f11946214ba2903e25c7cce3d9e5f7791 (patch) | |
tree | 116d9304faf586a507e28272bca84147a44a6f5e /tools | |
parent | 00bb3b5609d49633f5c456b414e80bc72da728aa (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320742 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/obj2yaml/wasm2yaml.cpp | 8 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2wasm.cpp | 11 |
2 files changed, 17 insertions, 2 deletions
diff --git a/tools/obj2yaml/wasm2yaml.cpp b/tools/obj2yaml/wasm2yaml.cpp index 27398e5b00b..1bf8149493c 100644 --- a/tools/obj2yaml/wasm2yaml.cpp +++ b/tools/obj2yaml/wasm2yaml.cpp @@ -80,11 +80,15 @@ std::unique_ptr<WasmYAML::CustomSection> WasmDumper::dumpCustomSection(const Was for (const object::SymbolRef& Sym: Obj.symbols()) { const object::WasmSymbol Symbol = Obj.getWasmSymbol(Sym); if (Symbol.Flags != 0) { - WasmYAML::SymbolInfo Info = { Symbol.Name, Symbol.Flags }; - LinkingSec->SymbolInfos.push_back(Info); + WasmYAML::SymbolInfo Info{Symbol.Name, Symbol.Flags}; + LinkingSec->SymbolInfos.emplace_back(Info); } } LinkingSec->DataSize = Obj.linkingData().DataSize; + for (const wasm::WasmInitFunc &Func : Obj.linkingData().InitFunctions) { + WasmYAML::InitFunction F{Func.Priority, Func.FunctionIndex}; + LinkingSec->InitFunctions.emplace_back(F); + } CustomSec = std::move(LinkingSec); } else { CustomSec = make_unique<WasmYAML::CustomSection>(WasmSec.Name); diff --git a/tools/yaml2obj/yaml2wasm.cpp b/tools/yaml2obj/yaml2wasm.cpp index 3eae8727b60..792f7c108bc 100644 --- a/tools/yaml2obj/yaml2wasm.cpp +++ b/tools/yaml2obj/yaml2wasm.cpp @@ -162,6 +162,17 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::LinkingSection &S } SubSection.Done(); } + + // INIT_FUNCS subsection + if (Section.InitFunctions.size()) { + encodeULEB128(wasm::WASM_INIT_FUNCS, OS); + encodeULEB128(Section.InitFunctions.size(), SubSection.GetStream()); + for (const WasmYAML::InitFunction &Func : Section.InitFunctions) { + encodeULEB128(Func.Priority, SubSection.GetStream()); + encodeULEB128(Func.FunctionIndex, SubSection.GetStream()); + } + SubSection.Done(); + } return 0; } |