Index: test/wasm/Inputs/globals.yaml =================================================================== --- test/wasm/Inputs/globals.yaml +++ test/wasm/Inputs/globals.yaml @@ -34,7 +34,7 @@ Offset: 0x00000004 - Type: CUSTOM Name: linking - Version: 1 + Version: 2 SymbolTable: - Index: 0 Kind: GLOBAL Index: test/wasm/Inputs/undefined-globals.yaml =================================================================== --- test/wasm/Inputs/undefined-globals.yaml +++ test/wasm/Inputs/undefined-globals.yaml @@ -32,7 +32,7 @@ Offset: 0x00000004 - Type: CUSTOM Name: linking - Version: 1 + Version: 2 SymbolTable: - Index: 0 Kind: GLOBAL Index: test/wasm/locals-duplicate.test =================================================================== --- test/wasm/locals-duplicate.test +++ test/wasm/locals-duplicate.test @@ -382,7 +382,7 @@ ; RELOC-NEXT: Content: '0000000000000000' ; RELOC-NEXT: - Type: CUSTOM ; RELOC-NEXT: Name: linking -; RELOC-NEXT: Version: 1 +; RELOC-NEXT: Version: 2 ; RELOC-NEXT: SymbolTable: ; RELOC-NEXT: - Index: 0 ; RELOC-NEXT: Kind: FUNCTION @@ -516,15 +516,15 @@ ; RELOC-NEXT: SegmentInfo: ; RELOC-NEXT: - Index: 0 ; RELOC-NEXT: Name: .bss.colliding_global1 -; RELOC-NEXT: Alignment: 4 +; RELOC-NEXT: Alignment: 2 ; RELOC-NEXT: Flags: [ ] ; RELOC-NEXT: - Index: 1 ; RELOC-NEXT: Name: .bss.colliding_global2 -; RELOC-NEXT: Alignment: 4 +; RELOC-NEXT: Alignment: 2 ; RELOC-NEXT: Flags: [ ] ; RELOC-NEXT: - Index: 2 ; RELOC-NEXT: Name: .bss.colliding_global3 -; RELOC-NEXT: Alignment: 4 +; RELOC-NEXT: Alignment: 2 ; RELOC-NEXT: Flags: [ ] ; RELOC-NEXT: - Type: CUSTOM ; RELOC-NEXT: Name: name Index: test/wasm/many-functions.ll =================================================================== --- test/wasm/many-functions.ll +++ test/wasm/many-functions.ll @@ -815,7 +815,7 @@ ; CHECK-NEXT: Content: '01000000' ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking -; CHECK-NEXT: Version: 1 +; CHECK-NEXT: Version: 2 ; CHECK-NEXT: SymbolTable: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Kind: FUNCTION @@ -1482,9 +1482,9 @@ ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.g0 -; CHECK-NEXT: Alignment: 4 +; CHECK-NEXT: Alignment: 2 ; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .data.foo -; CHECK-NEXT: Alignment: 4 +; CHECK-NEXT: Alignment: 2 ; CHECK-NEXT: Flags: [ ] Index: test/wasm/relocatable.ll =================================================================== --- test/wasm/relocatable.ll +++ test/wasm/relocatable.ll @@ -157,7 +157,7 @@ ; CHECK-NEXT: Content: '616263' ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking -; CHECK-NEXT: Version: 1 +; CHECK-NEXT: Version: 2 ; CHECK-NEXT: SymbolTable: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Kind: FUNCTION @@ -232,27 +232,27 @@ ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .rodata.hello_str -; CHECK-NEXT: Alignment: 1 +; CHECK-NEXT: Alignment: 0 ; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Name: .data.func_addr1 -; CHECK-NEXT: Alignment: 4 +; CHECK-NEXT: Alignment: 2 ; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Name: .data.func_addr2 -; CHECK-NEXT: Alignment: 4 +; CHECK-NEXT: Alignment: 2 ; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 3 ; CHECK-NEXT: Name: .data.func_addr3 -; CHECK-NEXT: Alignment: 4 +; CHECK-NEXT: Alignment: 2 ; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 4 ; CHECK-NEXT: Name: .data.data_addr1 -; CHECK-NEXT: Alignment: 8 +; CHECK-NEXT: Alignment: 3 ; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: - Index: 5 ; CHECK-NEXT: Name: .rodata.data_comdat -; CHECK-NEXT: Alignment: 1 +; CHECK-NEXT: Alignment: 0 ; CHECK-NEXT: Flags: [ ] ; CHECK-NEXT: Comdats: ; CHECK-NEXT: - Name: func_comdat Index: test/wasm/stack-pointer.ll =================================================================== --- test/wasm/stack-pointer.ll +++ test/wasm/stack-pointer.ll @@ -50,7 +50,7 @@ ; CHECK-NEXT: Body: 23808080800041106B1A41000B ; CHECK-NEXT: - Type: CUSTOM ; CHECK-NEXT: Name: linking -; CHECK-NEXT: Version: 1 +; CHECK-NEXT: Version: 2 ; CHECK-NEXT: SymbolTable: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Kind: FUNCTION Index: test/wasm/weak-alias.ll =================================================================== --- test/wasm/weak-alias.ll +++ test/wasm/weak-alias.ll @@ -250,7 +250,7 @@ ; RELOC-NEXT: Body: 23808080800041106B220024808080800020004181808080003602081081808080002101200041106A24808080800020010B ; RELOC-NEXT: - Type: CUSTOM ; RELOC-NEXT: Name: linking -; RELOC-NEXT: Version: 1 +; RELOC-NEXT: Version: 2 ; RELOC-NEXT: SymbolTable: ; RELOC-NEXT: - Index: 0 ; RELOC-NEXT: Kind: FUNCTION Index: wasm/OutputSegment.h =================================================================== --- wasm/OutputSegment.h +++ wasm/OutputSegment.h @@ -26,7 +26,7 @@ void addInputSegment(InputSegment *InSeg) { Alignment = std::max(Alignment, InSeg->getAlignment()); InputSegments.push_back(InSeg); - Size = llvm::alignTo(Size, InSeg->getAlignment()); + Size = llvm::alignTo(Size, 1 << InSeg->getAlignment()); InSeg->OutputSeg = this; InSeg->OutputSegmentOffset = Size; Size += InSeg->getSize(); Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -477,7 +477,7 @@ raw_ostream &OS = Section->getStream(); writeUleb128(OS, MemSize, "MemSize"); - writeUleb128(OS, int(log2(MemAlign)), "MemAlign"); + writeUleb128(OS, MemAlign, "MemAlign"); writeUleb128(OS, IndirectFunctions.size(), "TableSize"); writeUleb128(OS, 0, "TableAlign"); writeUleb128(OS, 0, "Needed"); // TODO: Support "needed" shared libraries @@ -691,7 +691,7 @@ MemAlign = 0; for (OutputSegment *Seg : Segments) { MemAlign = std::max(MemAlign, Seg->Alignment); - MemoryPtr = alignTo(MemoryPtr, Seg->Alignment); + MemoryPtr = alignTo(MemoryPtr, 1 << Seg->Alignment); Seg->StartVA = MemoryPtr; log(formatv("mem: {0,-15} offset={1,-8} size={2,-8} align={3}", Seg->Name, MemoryPtr, Seg->Size, Seg->Alignment));