Index: test/wasm/call-indirect.ll =================================================================== --- test/wasm/call-indirect.ll +++ test/wasm/call-indirect.ll @@ -103,7 +103,6 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 8 -; CHECK-NEXT: DataAlignment: 0 ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name ; CHECK-NEXT: FunctionNames: Index: test/wasm/data-layout.ll =================================================================== --- test/wasm/data-layout.ll +++ test/wasm/data-layout.ll @@ -74,4 +74,3 @@ ; CHECK: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 35 -; CHECK-NEXT: DataAlignment: 0 Index: test/wasm/local-symbols.ll =================================================================== --- test/wasm/local-symbols.ll +++ test/wasm/local-symbols.ll @@ -80,7 +80,6 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 8 -; CHECK-NEXT: DataAlignment: 0 ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name ; CHECK-NEXT: FunctionNames: Index: test/wasm/relocatable.ll =================================================================== --- test/wasm/relocatable.ll +++ test/wasm/relocatable.ll @@ -133,7 +133,19 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 16 -; CHECK-NEXT: DataAlignment: 4 +; CHECK-NEXT: SegmentInfo: +; CHECK-NEXT: - Index: 0 +; CHECK-NEXT: Name: .rodata.hello_str +; CHECK-NEXT: Alignment: 1 +; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: - Index: 1 +; CHECK-NEXT: Name: .data.func_addr1 +; CHECK-NEXT: Alignment: 4 +; CHECK-NEXT: Flags: 0 +; CHECK-NEXT: - Index: 2 +; CHECK-NEXT: Name: .data.func_addr2 +; CHECK-NEXT: Alignment: 4 +; CHECK-NEXT: Flags: 0 ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name ; CHECK-NEXT: FunctionNames: Index: test/wasm/weak-alias-overide.ll =================================================================== --- test/wasm/weak-alias-overide.ll +++ test/wasm/weak-alias-overide.ll @@ -78,7 +78,6 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 0 -; CHECK-NEXT: DataAlignment: 0 ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name ; CHECK-NEXT: FunctionNames: Index: test/wasm/weak-alias.ll =================================================================== --- test/wasm/weak-alias.ll +++ test/wasm/weak-alias.ll @@ -70,7 +70,6 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 0 -; CHECK-NEXT: DataAlignment: 0 ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: name ; CHECK-NEXT: FunctionNames: Index: test/wasm/weak-external.ll =================================================================== --- test/wasm/weak-external.ll +++ test/wasm/weak-external.ll @@ -74,5 +74,4 @@ ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking ; CHECK-NEXT: DataSize: 0 -; CHECK-NEXT: DataAlignment: 0 ; CHECK-NEXT: ... Index: wasm/InputFiles.h =================================================================== --- wasm/InputFiles.h +++ wasm/InputFiles.h @@ -120,6 +120,7 @@ int32_t GlobalIndexOffset = 0; int32_t TableIndexOffset = 0; uint32_t DataOffset = 0; + uint32_t DataAlignment = 0; const WasmSection *CodeSection = nullptr; const WasmSection *DataSection = nullptr; Index: wasm/InputFiles.cpp =================================================================== --- wasm/InputFiles.cpp +++ wasm/InputFiles.cpp @@ -159,6 +159,9 @@ DataSection = &Section; } + for (const WasmSegment &Segment : WasmObj->dataSegments()) + DataAlignment = std::max(DataAlignment, Segment.Data.Alignment); + initializeSymbols(); } Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -105,7 +105,6 @@ uint64_t FileSize = 0; uint32_t DataSize = 0; - uint32_t DataAlignment = 1; uint32_t NumFunctions = 0; uint32_t NumGlobals = 0; uint32_t NumMemoryPages = 0; @@ -419,11 +418,18 @@ DataSizeSubSection.finalizeContents(); DataSizeSubSection.writeToStream(OS); - if (Config->Relocatable) { - SubSection DataAlignSubSection(WASM_DATA_ALIGNMENT); - writeUleb128(DataAlignSubSection.getStream(), DataAlignment, "data align"); - DataAlignSubSection.finalizeContents(); - DataAlignSubSection.writeToStream(OS); + if (NumDataSegments && Config->Relocatable) { + SubSection SubSection(WASM_SEGMENT_INFO); + writeUleb128(SubSection.getStream(), NumDataSegments, "num data segments"); + for (ObjectFile *File : Symtab->ObjectFiles) { + for (const object::WasmSegment &S: File->getWasmObj()->dataSegments()) { + writeStr(SubSection.getStream(), S.Data.Name, "segment name"); + writeUleb128(SubSection.getStream(), S.Data.Alignment, "alignment"); + writeUleb128(SubSection.getStream(), S.Data.Flags, "flags"); + } + } + SubSection.finalizeContents(); + SubSection.writeToStream(OS); } } @@ -503,12 +509,11 @@ } // Static data from input object files comes first - MemoryPtr = alignTo(MemoryPtr, DataAlignment); for (ObjectFile *File : Symtab->ObjectFiles) { const WasmObjectFile *WasmFile = File->getWasmObj(); uint32_t Size = WasmFile->linkingData().DataSize; if (Size) { - MemoryPtr = alignTo(MemoryPtr, WasmFile->linkingData().DataAlignment); + MemoryPtr = alignTo(MemoryPtr, File->DataAlignment); debugPrint("mem: [%s] offset=%#x size=%d\n", File->getName().str().c_str(), File->DataOffset, Size); File->DataOffset = MemoryPtr; @@ -583,9 +588,6 @@ for (ObjectFile *File : Symtab->ObjectFiles) { const WasmObjectFile *WasmFile = File->getWasmObj(); - DataAlignment = - std::max(DataAlignment, WasmFile->linkingData().DataAlignment); - // Function Index File->FunctionIndexOffset = FunctionImports.size() - File->NumFunctionImports() + NumFunctions;