Index: llvm/trunk/include/llvm/BinaryFormat/Wasm.h =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/Wasm.h +++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h @@ -40,6 +40,7 @@ uint32_t MemoryAlignment; // P2 alignment of memory uint32_t TableSize; // Table size in elements uint32_t TableAlignment; // P2 alignment of table + std::vector Needed; // Shared library depenedencies }; struct WasmExport { Index: llvm/trunk/include/llvm/Object/Wasm.h =================================================================== --- llvm/trunk/include/llvm/Object/Wasm.h +++ llvm/trunk/include/llvm/Object/Wasm.h @@ -201,6 +201,7 @@ Triple::ArchType getArch() const override; SubtargetFeatures getFeatures() const override; bool isRelocatableObject() const override; + bool isSharedObject() const; struct ReadContext { const uint8_t *Start; @@ -271,6 +272,7 @@ std::vector DebugNames; uint32_t StartFunction = -1; bool HasLinkingSection = false; + bool HasDylinkSection = false; wasm::WasmLinkingData LinkingData; uint32_t NumImportedGlobals = 0; uint32_t NumImportedFunctions = 0; Index: llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h =================================================================== --- llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h +++ llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h @@ -195,6 +195,7 @@ uint32_t MemoryAlignment; uint32_t TableSize; uint32_t TableAlignment; + std::vector Needed; }; struct NameSection : CustomSection { Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/lib/Object/WasmObjectFile.cpp @@ -319,6 +319,10 @@ DylinkInfo.MemoryAlignment = readVaruint32(Ctx); DylinkInfo.TableSize = readVaruint32(Ctx); DylinkInfo.TableAlignment = readVaruint32(Ctx); + uint32_t Count = readVaruint32(Ctx); + while (Count--) { + DylinkInfo.Needed.push_back(readString(Ctx)); + } if (Ctx.Ptr != Ctx.End) return make_error("dylink section ended prematurely", object_error::parse_failed); @@ -1405,6 +1409,8 @@ bool WasmObjectFile::isRelocatableObject() const { return HasLinkingSection; } +bool WasmObjectFile::isSharedObject() const { return HasDylinkSection; } + const WasmSection &WasmObjectFile::getWasmSection(DataRefImpl Ref) const { assert(Ref.d.a < Sections.size()); return Sections[Ref.d.a]; Index: llvm/trunk/lib/ObjectYAML/WasmYAML.cpp =================================================================== --- llvm/trunk/lib/ObjectYAML/WasmYAML.cpp +++ llvm/trunk/lib/ObjectYAML/WasmYAML.cpp @@ -55,6 +55,7 @@ IO.mapRequired("MemoryAlignment", Section.MemoryAlignment); IO.mapRequired("TableSize", Section.TableSize); IO.mapRequired("TableAlignment", Section.TableAlignment); + IO.mapRequired("Needed", Section.Needed); } static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) { Index: llvm/trunk/test/ObjectYAML/wasm/dylink_section.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/wasm/dylink_section.yaml +++ llvm/trunk/test/ObjectYAML/wasm/dylink_section.yaml @@ -10,6 +10,7 @@ MemoryAlignment: 2 TableSize: 1 TableAlignment: 0 + Needed: [ libfoo.so, libbar.so ] ... # CHECK: --- !WASM # CHECK: FileHeader: @@ -21,4 +22,7 @@ # CHECK: MemoryAlignment: 2 # CHECK: TableSize: 1 # CHECK: TableAlignment: 0 +# CHECK: Needed: +# CHECK: - libfoo.so +# CHECK: - libbar.so # CHECK: ... Index: llvm/trunk/tools/obj2yaml/wasm2yaml.cpp =================================================================== --- llvm/trunk/tools/obj2yaml/wasm2yaml.cpp +++ llvm/trunk/tools/obj2yaml/wasm2yaml.cpp @@ -60,6 +60,7 @@ DylinkSec->MemoryAlignment = Info.MemoryAlignment; DylinkSec->TableSize = Info.TableSize; DylinkSec->TableAlignment = Info.TableAlignment; + DylinkSec->Needed = Info.Needed; CustomSec = std::move(DylinkSec); } else if (WasmSec.Name == "name") { std::unique_ptr NameSec = Index: llvm/trunk/tools/yaml2obj/yaml2wasm.cpp =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2wasm.cpp +++ llvm/trunk/tools/yaml2obj/yaml2wasm.cpp @@ -140,6 +140,10 @@ encodeULEB128(Section.MemoryAlignment, OS); encodeULEB128(Section.TableSize, OS); encodeULEB128(Section.TableAlignment, OS); + encodeULEB128(Section.Needed.size(), OS); + for (StringRef Needed : Section.Needed) { + writeStringRef(Needed, OS); + } return 0; }