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/tools | |
| parent | ea244bf89b794802a0a5addeed74919a605f8636 (diff) | |
| download | bcm5719-llvm-4273998cf9013ce92c7bf1effafef76a65e31d0c.tar.gz bcm5719-llvm-4273998cf9013ce92c7bf1effafef76a65e31d0c.zip | |
[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/tools')
| -rw-r--r-- | llvm/tools/obj2yaml/wasm2yaml.cpp | 8 | ||||
| -rw-r--r-- | llvm/tools/yaml2obj/yaml2wasm.cpp | 11 |
2 files changed, 17 insertions, 2 deletions
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp index 27398e5b00b..1bf8149493c 100644 --- a/llvm/tools/obj2yaml/wasm2yaml.cpp +++ b/llvm/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/llvm/tools/yaml2obj/yaml2wasm.cpp b/llvm/tools/yaml2obj/yaml2wasm.cpp index 3eae8727b60..792f7c108bc 100644 --- a/llvm/tools/yaml2obj/yaml2wasm.cpp +++ b/llvm/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; } |

