diff options
author | Sam Clegg <sbc@chromium.org> | 2017-06-20 04:04:59 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2017-06-20 04:04:59 +0000 |
commit | 1e975c1249b13777ee6b6ea38da2b1b5c9053deb (patch) | |
tree | 0abaa31e6c7ea09c2bc4635639a0cf577cd34e5d /lib/ObjectYAML | |
parent | 9c490091f2ff9286c76e9c490f05ff744a60b0c8 (diff) |
[WebAssembly] Add support for weak symbols in the binary format
This also introduces the updated format for the
"linking" section which can represent extra
symbol information. See:
https://github.com/WebAssembly/tool-conventions/pull/10
Differential Revision: https://reviews.llvm.org/D34019
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305769 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ObjectYAML')
-rw-r--r-- | lib/ObjectYAML/WasmYAML.cpp | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/lib/ObjectYAML/WasmYAML.cpp b/lib/ObjectYAML/WasmYAML.cpp index 353d027f4e1..65703c6cf68 100644 --- a/lib/ObjectYAML/WasmYAML.cpp +++ b/lib/ObjectYAML/WasmYAML.cpp @@ -47,14 +47,22 @@ static void commonSectionMapping(IO &IO, WasmYAML::Section &Section) { IO.mapOptional("Relocations", Section.Relocations); } +static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) { + commonSectionMapping(IO, Section); + IO.mapRequired("Name", Section.Name); + IO.mapOptional("FunctionNames", Section.FunctionNames); +} + +static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) { + commonSectionMapping(IO, Section); + IO.mapRequired("Name", Section.Name); + IO.mapRequired("SymbolInfo", Section.SymbolInfos); +} + static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) { commonSectionMapping(IO, Section); IO.mapRequired("Name", Section.Name); - if (Section.Name == "name") { - IO.mapOptional("FunctionNames", Section.FunctionNames); - } else { - IO.mapRequired("Payload", Section.Payload); - } + IO.mapRequired("Payload", Section.Payload); } static void sectionMapping(IO &IO, WasmYAML::TypeSection &Section) { @@ -121,11 +129,29 @@ void MappingTraits<std::unique_ptr<WasmYAML::Section>>::mapping( IO.mapRequired("Type", SectionType); switch (SectionType) { - case wasm::WASM_SEC_CUSTOM: - if (!IO.outputting()) - Section.reset(new WasmYAML::CustomSection()); - sectionMapping(IO, *cast<WasmYAML::CustomSection>(Section.get())); + case wasm::WASM_SEC_CUSTOM: { + StringRef SectionName; + if (IO.outputting()) { + auto CustomSection = cast<WasmYAML::CustomSection>(Section.get()); + SectionName = CustomSection->Name; + } else { + IO.mapRequired("Name", SectionName); + } + if (SectionName == "linking") { + if (!IO.outputting()) + Section.reset(new WasmYAML::LinkingSection()); + sectionMapping(IO, *cast<WasmYAML::LinkingSection>(Section.get())); + } else if (SectionName == "name") { + if (!IO.outputting()) + Section.reset(new WasmYAML::NameSection()); + sectionMapping(IO, *cast<WasmYAML::NameSection>(Section.get())); + } else { + if (!IO.outputting()) + Section.reset(new WasmYAML::CustomSection(SectionName)); + sectionMapping(IO, *cast<WasmYAML::CustomSection>(Section.get())); + } break; + } case wasm::WASM_SEC_TYPE: if (!IO.outputting()) Section.reset(new WasmYAML::TypeSection()); @@ -321,6 +347,12 @@ void MappingTraits<WasmYAML::DataSegment>::mapping( IO.mapRequired("Content", Segment.Content); } +void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO, + WasmYAML::SymbolInfo &Info) { + IO.mapRequired("Name", Info.Name); + IO.mapRequired("Flags", Info.Flags); +} + void ScalarEnumerationTraits<WasmYAML::ValueType>::enumeration( IO &IO, WasmYAML::ValueType &Type) { #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X); |