Index: llvm/trunk/include/llvm/BinaryFormat/Wasm.h =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/Wasm.h +++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h @@ -98,6 +98,8 @@ WasmInitExpr Offset; ArrayRef Content; StringRef Name; + uint32_t Alignment; + uint32_t Flags; }; struct WasmElemSegment { @@ -115,7 +117,6 @@ struct WasmLinkingData { uint32_t DataSize; - uint32_t DataAlignment; }; enum : unsigned { @@ -185,7 +186,7 @@ WASM_SYMBOL_INFO = 0x2, WASM_DATA_SIZE = 0x3, WASM_DATA_ALIGNMENT = 0x4, - WASM_SEGMENT_NAMES = 0x5, + WASM_SEGMENT_INFO = 0x5, }; const unsigned WASM_SYMBOL_BINDING_MASK = 0x3; Index: llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h =================================================================== --- llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h +++ llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h @@ -109,6 +109,13 @@ StringRef Name; }; +struct SegmentInfo { + uint32_t Index; + StringRef Name; + uint32_t Alignment; + uint32_t Flags; +}; + struct Signature { uint32_t Index; SignatureForm Form = wasm::WASM_TYPE_FUNC; @@ -161,9 +168,8 @@ } uint32_t DataSize; - uint32_t DataAlignment; std::vector SymbolInfos; - std::vector SegmentNames; + std::vector SegmentInfos; }; struct TypeSection : Section { @@ -298,6 +304,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo) namespace llvm { @@ -355,6 +362,10 @@ static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry); }; +template <> struct MappingTraits { + static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo); +}; + template <> struct MappingTraits { static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl); }; Index: llvm/trunk/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/WasmObjectWriter.cpp +++ llvm/trunk/lib/MC/WasmObjectWriter.cpp @@ -104,6 +104,8 @@ MCSectionWasm *Section; StringRef Name; uint32_t Offset; + uint32_t Alignment; + uint32_t Flags; SmallVector Data; }; @@ -282,7 +284,6 @@ void writeDataRelocSection(); void writeLinkingMetaDataSection( ArrayRef Segments, uint32_t DataSize, - uint32_t DataAlignment, SmallVector, 4> SymbolFlags, bool HasStackPointer, uint32_t StackPointerGlobal); @@ -499,11 +500,11 @@ } static void addData(SmallVectorImpl &DataBytes, - MCSectionWasm &DataSection, uint32_t &DataAlignment) { - DataBytes.resize(alignTo(DataBytes.size(), DataSection.getAlignment())); - DataAlignment = std::max(DataAlignment, DataSection.getAlignment()); + MCSectionWasm &DataSection) { DEBUG(errs() << "addData: " << DataSection.getSectionName() << "\n"); + DataBytes.resize(alignTo(DataBytes.size(), DataSection.getAlignment())); + for (const MCFragment &Frag : DataSection) { if (Frag.hasInstructions()) report_fatal_error("only data supported in data sections"); @@ -914,7 +915,6 @@ void WasmObjectWriter::writeLinkingMetaDataSection( ArrayRef Segments, uint32_t DataSize, - uint32_t DataAlignment, SmallVector, 4> SymbolFlags, bool HasStackPointer, uint32_t StackPointerGlobal) { SectionBookkeeping Section; @@ -941,17 +941,16 @@ startSection(SubSection, wasm::WASM_DATA_SIZE); encodeULEB128(DataSize, getStream()); endSection(SubSection); - - startSection(SubSection, wasm::WASM_DATA_ALIGNMENT); - encodeULEB128(DataAlignment, getStream()); - endSection(SubSection); } if (Segments.size()) { - startSection(SubSection, wasm::WASM_SEGMENT_NAMES); + startSection(SubSection, wasm::WASM_SEGMENT_INFO); encodeULEB128(Segments.size(), getStream()); - for (const WasmDataSegment &Segment : Segments) + for (const WasmDataSegment &Segment : Segments) { writeString(Segment.Name); + encodeULEB128(Segment.Alignment, getStream()); + encodeULEB128(Segment.Flags, getStream()); + } endSection(SubSection); } @@ -998,7 +997,6 @@ SmallPtrSet IsAddressTaken; unsigned NumFuncImports = 0; SmallVector DataSegments; - uint32_t DataAlignment = 1; uint32_t StackPointerGlobal = 0; uint32_t DataSize = 0; bool HasStackPointer = false; @@ -1144,7 +1142,9 @@ Segment.Name = Section.getSectionName(); Segment.Offset = DataSize; Segment.Section = &Section; - addData(Segment.Data, Section, DataAlignment); + addData(Segment.Data, Section); + Segment.Alignment = Section.getAlignment(); + Segment.Flags = 0; DataSize += Segment.Data.size(); Section.setMemoryOffset(Segment.Offset); } @@ -1308,8 +1308,8 @@ writeNameSection(Functions, Imports, NumFuncImports); writeCodeRelocSection(); writeDataRelocSection(); - writeLinkingMetaDataSection(DataSegments, DataSize, DataAlignment, - SymbolFlags, HasStackPointer, StackPointerGlobal); + writeLinkingMetaDataSection(DataSegments, DataSize, SymbolFlags, + HasStackPointer, StackPointerGlobal); // TODO: Translate the .comment section to the output. // TODO: Translate debug sections to the output. Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/lib/Object/WasmObjectFile.cpp @@ -193,7 +193,6 @@ WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err) : ObjectFile(Binary::ID_Wasm, Buffer) { - LinkingData.DataAlignment = 0; LinkingData.DataSize = 0; ErrorAsOutParameter ErrAsOutParam(&Err); @@ -385,16 +384,16 @@ case wasm::WASM_DATA_SIZE: LinkingData.DataSize = readVaruint32(Ptr); break; - case wasm::WASM_DATA_ALIGNMENT: - LinkingData.DataAlignment = readVaruint32(Ptr); - break; - case wasm::WASM_SEGMENT_NAMES: { + case wasm::WASM_SEGMENT_INFO: { uint32_t Count = readVaruint32(Ptr); if (Count > DataSegments.size()) return make_error("Too many segment names", object_error::parse_failed); - for (uint32_t i = 0; i < Count; i++) + for (uint32_t i = 0; i < Count; i++) { DataSegments[i].Data.Name = readString(Ptr); + DataSegments[i].Data.Alignment = readVaruint32(Ptr); + DataSegments[i].Data.Flags = readVaruint32(Ptr); + } break; } case wasm::WASM_STACK_POINTER: @@ -734,6 +733,8 @@ return Err; uint32_t Size = readVaruint32(Ptr); Segment.Data.Content = ArrayRef(Ptr, Size); + Segment.Data.Alignment = 0; + Segment.Data.Flags = 0; Segment.SectionOffset = Ptr - Start; Ptr += Size; DataSegments.push_back(Segment); Index: llvm/trunk/lib/ObjectYAML/WasmYAML.cpp =================================================================== --- llvm/trunk/lib/ObjectYAML/WasmYAML.cpp +++ llvm/trunk/lib/ObjectYAML/WasmYAML.cpp @@ -58,9 +58,8 @@ commonSectionMapping(IO, Section); IO.mapRequired("Name", Section.Name); IO.mapRequired("DataSize", Section.DataSize); - IO.mapRequired("DataAlignment", Section.DataAlignment); IO.mapOptional("SymbolInfo", Section.SymbolInfos); - IO.mapOptional("SegmentNames", Section.SegmentNames); + IO.mapOptional("SegmentInfo", Section.SegmentInfos); } static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) { @@ -266,6 +265,14 @@ IO.mapRequired("Name", NameEntry.Name); } +void MappingTraits::mapping( + IO &IO, WasmYAML::SegmentInfo &SegmentInfo) { + IO.mapRequired("Index", SegmentInfo.Index); + IO.mapRequired("Name", SegmentInfo.Name); + IO.mapRequired("Alignment", SegmentInfo.Alignment); + IO.mapRequired("Flags", SegmentInfo.Flags); +} + void MappingTraits::mapping( IO &IO, WasmYAML::LocalDecl &LocalDecl) { IO.mapRequired("Type", LocalDecl.Type); Index: llvm/trunk/test/MC/WebAssembly/array-fill.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/array-fill.ll +++ llvm/trunk/test/MC/WebAssembly/array-fill.ll @@ -15,8 +15,9 @@ ; CHECK: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 2 -; CHECK-NEXT: DataAlignment: 1 -; CHECK-NEXT: SegmentNames: +; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data +; CHECK-NEXT: Alignment: 1 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: ... Index: llvm/trunk/test/MC/WebAssembly/bss.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/bss.ll +++ llvm/trunk/test/MC/WebAssembly/bss.ll @@ -13,8 +13,9 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 4 -; CHECK-NEXT: DataAlignment: 4 -; CHECK-NEXT: SegmentNames: +; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .bss.g0 +; CHECK-NEXT: Alignment: 4 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: ... Index: llvm/trunk/test/MC/WebAssembly/explicit-sections.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/explicit-sections.ll +++ llvm/trunk/test/MC/WebAssembly/explicit-sections.ll @@ -67,12 +67,17 @@ ; CHECK: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 28 -; CHECK-NEXT: DataAlignment: 8 -; CHECK-NEXT: SegmentNames: +; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.global0 +; CHECK-NEXT: Alignment: 8 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .sec1 +; CHECK-NEXT: Alignment: 8 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Name: .sec2 +; CHECK-NEXT: Alignment: 8 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: ... Index: llvm/trunk/test/MC/WebAssembly/unnamed-data.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/unnamed-data.ll +++ llvm/trunk/test/MC/WebAssembly/unnamed-data.ll @@ -79,19 +79,26 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 28 -; CHECK-NEXT: DataAlignment: 8 ; CHECK-NEXT: SymbolInfo: ; CHECK-NEXT: - Name: .L.str1 ; CHECK-NEXT: Flags: 2 ; CHECK-NEXT: - Name: .L.str2 ; CHECK-NEXT: Flags: 2 -; CHECK-NEXT: SegmentNames: +; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .rodata..L.str1 +; CHECK-NEXT: Alignment: 1 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .rodata..L.str2 +; CHECK-NEXT: Alignment: 1 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Name: .data.a +; CHECK-NEXT: Alignment: 8 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Name: .data.b +; CHECK-NEXT: Alignment: 8 +; CHECK-NEXT: Flags: 0 ; CHECK_NEXT: ... Index: llvm/trunk/test/MC/WebAssembly/weak-alias.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/weak-alias.ll +++ llvm/trunk/test/MC/WebAssembly/weak-alias.ll @@ -101,17 +101,20 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 12 -; CHECK-NEXT: DataAlignment: 8 ; CHECK-NEXT: SymbolInfo: ; CHECK-NEXT: - Name: foo_alias ; CHECK-NEXT: Flags: 1 ; CHECK-NEXT: - Name: bar_alias ; CHECK-NEXT: Flags: 1 -; CHECK-NEXT: SegmentNames: +; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.bar +; CHECK-NEXT: Alignment: 8 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .data.bar_alias_address +; CHECK-NEXT: Alignment: 8 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: ... ; CHECK-SYMS: SYMBOL TABLE: Index: llvm/trunk/test/MC/WebAssembly/weak.ll =================================================================== --- llvm/trunk/test/MC/WebAssembly/weak.ll +++ llvm/trunk/test/MC/WebAssembly/weak.ll @@ -27,7 +27,6 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 0 -; CHECK-NEXT: DataAlignment: 0 ; CHECK-NEXT: SymbolInfo: ; CHECK-NEXT: - Name: weak_external_data ; CHECK-NEXT: Flags: 1 Index: llvm/trunk/test/ObjectYAML/wasm/weak_symbols.yaml =================================================================== --- llvm/trunk/test/ObjectYAML/wasm/weak_symbols.yaml +++ llvm/trunk/test/ObjectYAML/wasm/weak_symbols.yaml @@ -27,7 +27,6 @@ - Type: CUSTOM Name: linking DataSize: 10 - DataAlignment: 2 SymbolInfo: - Name: function_export Flags: 1 @@ -49,7 +48,6 @@ # CHECK: - Type: CUSTOM # CHECK: Name: linking # CHECK: DataSize: 10 -# CHECK: DataAlignment: 2 # CHECK: SymbolInfo: # CHECK: - Name: function_export # CHECK: Flags: 1 Index: llvm/trunk/test/tools/llvm-nm/wasm/exports.yaml =================================================================== --- llvm/trunk/test/tools/llvm-nm/wasm/exports.yaml +++ llvm/trunk/test/tools/llvm-nm/wasm/exports.yaml @@ -53,7 +53,6 @@ - Type: CUSTOM Name: "linking" DataSize: 0 - DataAlignment: 0 # CHECK: 00000400 D bar # CHECK-NEXT: U fimport Index: llvm/trunk/test/tools/llvm-nm/wasm/imports.yaml =================================================================== --- llvm/trunk/test/tools/llvm-nm/wasm/imports.yaml +++ llvm/trunk/test/tools/llvm-nm/wasm/imports.yaml @@ -23,7 +23,6 @@ - Type: CUSTOM Name: "linking" DataSize: 0 - DataAlignment: 0 # CHECK: U bar # CHECK: U foo Index: llvm/trunk/test/tools/llvm-nm/wasm/weak-symbols.yaml =================================================================== --- llvm/trunk/test/tools/llvm-nm/wasm/weak-symbols.yaml +++ llvm/trunk/test/tools/llvm-nm/wasm/weak-symbols.yaml @@ -53,7 +53,6 @@ - Type: CUSTOM Name: linking DataSize: 0 - DataAlignment: 2 SymbolInfo: - Name: weak_global_func Flags: 1 Index: llvm/trunk/test/tools/llvm-readobj/sections.test =================================================================== --- llvm/trunk/test/tools/llvm-readobj/sections.test +++ llvm/trunk/test/tools/llvm-readobj/sections.test @@ -568,6 +568,5 @@ WASM-NEXT: Offset: 257 WASM-NEXT: Name: linking WASM-NEXT: DataSize: 13 -WASM-NEXT: DataAlignment: 1 WASM-NEXT: } WASM-NEXT: ] Index: llvm/trunk/tools/llvm-readobj/WasmDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/WasmDumper.cpp +++ llvm/trunk/tools/llvm-readobj/WasmDumper.cpp @@ -156,8 +156,6 @@ if (WasmSec.Name == "linking") { const wasm::WasmLinkingData &LinkingData = Obj->linkingData(); W.printNumber("DataSize", LinkingData.DataSize); - if (LinkingData.DataAlignment) - W.printNumber("DataAlignment", LinkingData.DataAlignment); } break; case wasm::WASM_SEC_DATA: { Index: llvm/trunk/tools/obj2yaml/wasm2yaml.cpp =================================================================== --- llvm/trunk/tools/obj2yaml/wasm2yaml.cpp +++ llvm/trunk/tools/obj2yaml/wasm2yaml.cpp @@ -68,10 +68,12 @@ size_t Index = 0; for (const object::WasmSegment &Segment : Obj.dataSegments()) { if (!Segment.Data.Name.empty()) { - WasmYAML::NameEntry NameEntry; - NameEntry.Name = Segment.Data.Name; - NameEntry.Index = Index; - LinkingSec->SegmentNames.push_back(NameEntry); + WasmYAML::SegmentInfo SegmentInfo; + SegmentInfo.Name = Segment.Data.Name; + SegmentInfo.Index = Index; + SegmentInfo.Alignment = Segment.Data.Alignment; + SegmentInfo.Flags = Segment.Data.Flags; + LinkingSec->SegmentInfos.push_back(SegmentInfo); } Index++; } @@ -83,7 +85,6 @@ } } LinkingSec->DataSize = Obj.linkingData().DataSize; - LinkingSec->DataAlignment = Obj.linkingData().DataAlignment; CustomSec = std::move(LinkingSec); } else { CustomSec = make_unique(WasmSec.Name); Index: llvm/trunk/tools/yaml2obj/yaml2wasm.cpp =================================================================== --- llvm/trunk/tools/yaml2obj/yaml2wasm.cpp +++ llvm/trunk/tools/yaml2obj/yaml2wasm.cpp @@ -140,11 +140,6 @@ encodeULEB128(Section.DataSize, SubSection.GetStream()); SubSection.Done(); - // DATA_ALIGNMENT subsection - encodeULEB128(wasm::WASM_DATA_ALIGNMENT, OS); - encodeULEB128(Section.DataAlignment, SubSection.GetStream()); - SubSection.Done(); - // SYMBOL_INFO subsection if (Section.SymbolInfos.size()) { encodeULEB128(wasm::WASM_SYMBOL_INFO, OS); @@ -159,12 +154,14 @@ } // SEGMENT_NAMES subsection - if (Section.SegmentNames.size()) { - encodeULEB128(wasm::WASM_SEGMENT_NAMES, OS); - encodeULEB128(Section.SegmentNames.size(), SubSection.GetStream()); - for (const WasmYAML::NameEntry &NameEntry : Section.SegmentNames) { - encodeULEB128(NameEntry.Index, SubSection.GetStream()); - writeStringRef(NameEntry.Name, SubSection.GetStream()); + if (Section.SegmentInfos.size()) { + encodeULEB128(wasm::WASM_SEGMENT_INFO, OS); + encodeULEB128(Section.SegmentInfos.size(), SubSection.GetStream()); + for (const WasmYAML::SegmentInfo &SegmentInfo : Section.SegmentInfos) { + encodeULEB128(SegmentInfo.Index, SubSection.GetStream()); + writeStringRef(SegmentInfo.Name, SubSection.GetStream()); + encodeULEB128(SegmentInfo.Alignment, SubSection.GetStream()); + encodeULEB128(SegmentInfo.Flags, SubSection.GetStream()); } SubSection.Done(); }