diff --git a/lld/test/wasm/data-layout.ll b/lld/test/wasm/data-layout.ll --- a/lld/test/wasm/data-layout.ll +++ b/lld/test/wasm/data-layout.ll @@ -26,19 +26,19 @@ ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66608 +; CHECK-NEXT: Value: 66624 ; CHECK-NEXT: - Index: 1 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1071 +; CHECK-NEXT: Value: 1080 ; CHECK-NEXT: - Index: 2 ; CHECK-NEXT: Type: I32 ; CHECK-NEXT: Mutable: false ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66608 +; CHECK-NEXT: Value: 66624 ; CHECK: - Type: DATA ; CHECK-NEXT: Segments: @@ -47,19 +47,19 @@ ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST ; CHECK-NEXT: Value: 1024 -; CHECK-NEXT: Content: '0100000000000000000000000000000003000000000000002804000024040000' -; CHECK-NEXT: - SectionOffset: 45 +; CHECK-NEXT: Content: 68656C6C6F0A00 +; CHECK-NEXT: - SectionOffset: 20 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1056 -; CHECK-NEXT: Content: '0000000000000000' -; CHECK-NEXT: - SectionOffset: 59 +; CHECK-NEXT: Value: 1040 +; CHECK-NEXT: Content: '0100000000000000000000000000000003000000000000000004000034040000' +; CHECK-NEXT: - SectionOffset: 58 ; CHECK-NEXT: InitFlags: 0 ; CHECK-NEXT: Offset: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 1064 -; CHECK-NEXT: Content: 68656C6C6F0A00 +; CHECK-NEXT: Value: 1072 +; CHECK-NEXT: Content: '0000000000000000' ; CHECK-NEXT: - Type: CUSTOM @@ -92,10 +92,10 @@ ; RELOC-NEXT: Relocations: ; RELOC-NEXT: - Type: R_WASM_MEMORY_ADDR_I32 ; RELOC-NEXT: Index: 3 -; RELOC-NEXT: Offset: 0x00000018 +; RELOC-NEXT: Offset: 0x00000024 ; RELOC-NEXT: - Type: R_WASM_MEMORY_ADDR_I32 ; RELOC-NEXT: Index: 4 -; RELOC-NEXT: Offset: 0x0000002E +; RELOC-NEXT: Offset: 0x0000002D ; RELOC-NEXT: Addend: 4 ; RELOC-NEXT: Segments: ; RELOC-NEXT: - SectionOffset: 6 @@ -103,60 +103,60 @@ ; RELOC-NEXT: Offset: ; RELOC-NEXT: Opcode: I32_CONST ; RELOC-NEXT: Value: 0 +; RELOC-NEXT: Content: 68656C6C6F0A00 +; RELOC-NEXT: - SectionOffset: 18 +; RELOC-NEXT: InitFlags: 0 +; RELOC-NEXT: Offset: +; RELOC-NEXT: Opcode: I32_CONST +; RELOC-NEXT: Value: 8 ; RELOC-NEXT: Content: '01000000' -; RELOC-NEXT: - SectionOffset: 15 +; RELOC-NEXT: - SectionOffset: 27 ; RELOC-NEXT: InitFlags: 0 ; RELOC-NEXT: Offset: ; RELOC-NEXT: Opcode: I32_CONST ; RELOC-NEXT: Value: 16 ; RELOC-NEXT: Content: '03000000' -; RELOC-NEXT: - SectionOffset: 24 +; RELOC-NEXT: - SectionOffset: 36 ; RELOC-NEXT: InitFlags: 0 ; RELOC-NEXT: Offset: ; RELOC-NEXT: Opcode: I32_CONST ; RELOC-NEXT: Value: 24 -; RELOC-NEXT: Content: '28000000' -; RELOC-NEXT: - SectionOffset: 33 +; RELOC-NEXT: Content: '00000000' +; RELOC-NEXT: - SectionOffset: 45 ; RELOC-NEXT: InitFlags: 0 ; RELOC-NEXT: Offset: ; RELOC-NEXT: Opcode: I32_CONST ; RELOC-NEXT: Value: 28 -; RELOC-NEXT: Content: '0000000000000000' -; RELOC-NEXT: - SectionOffset: 46 -; RELOC-NEXT: InitFlags: 0 -; RELOC-NEXT: Offset: -; RELOC-NEXT: Opcode: I32_CONST -; RELOC-NEXT: Value: 36 -; RELOC-NEXT: Content: '20000000' -; RELOC-NEXT: - SectionOffset: 55 +; RELOC-NEXT: Content: '24000000' +; RELOC-NEXT: - SectionOffset: 54 ; RELOC-NEXT: InitFlags: 0 ; RELOC-NEXT: Offset: ; RELOC-NEXT: Opcode: I32_CONST -; RELOC-NEXT: Value: 40 -; RELOC-NEXT: Content: 68656C6C6F0A00 +; RELOC-NEXT: Value: 32 +; RELOC-NEXT: Content: '0000000000000000' ; RELOC: SymbolTable: ; RELOC-NEXT: - Index: 0 ; RELOC-NEXT: Kind: DATA ; RELOC-NEXT: Name: foo ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: Segment: 0 +; RELOC-NEXT: Segment: 1 ; RELOC-NEXT: Size: 4 ; RELOC-NEXT: - Index: 1 ; RELOC-NEXT: Kind: DATA ; RELOC-NEXT: Name: aligned_bar ; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; RELOC-NEXT: Segment: 1 +; RELOC-NEXT: Segment: 2 ; RELOC-NEXT: Size: 4 ; RELOC-NEXT: - Index: 2 ; RELOC-NEXT: Kind: DATA ; RELOC-NEXT: Name: external_ref ; RELOC-NEXT: Flags: [ ] -; RELOC-NEXT: Segment: 2 +; RELOC-NEXT: Segment: 3 ; RELOC-NEXT: Size: 4 ; RELOC-NEXT: - Index: 3 ; RELOC-NEXT: Kind: DATA ; RELOC-NEXT: Name: hello_str ; RELOC-NEXT: Flags: [ ] -; RELOC-NEXT: Segment: 5 +; RELOC-NEXT: Segment: 0 ; RELOC-NEXT: Size: 7 diff --git a/lld/test/wasm/data-segment-merging.ll b/lld/test/wasm/data-segment-merging.ll --- a/lld/test/wasm/data-segment-merging.ll +++ b/lld/test/wasm/data-segment-merging.ll @@ -19,11 +19,11 @@ ; MERGE-NEXT: - SectionOffset: 7 ; MERGE-NEXT: InitFlags: 0 ; MERGE-NEXT: Offset: -; MERGE: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000 -; MERGE-NEXT: - SectionOffset: 41 +; MERGE: Content: 636F6E7374616E74000000002B +; MERGE-NEXT: - SectionOffset: 26 ; MERGE-NEXT: InitFlags: 0 ; MERGE-NEXT: Offset: -; MERGE: Content: 636F6E7374616E74000000002B +; MERGE: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000 ; MERGE-NEXT: - Type: CUSTOM ; MERGE-NEXT: Name: name ; MERGE-NEXT: FunctionNames: @@ -40,27 +40,27 @@ ; SEPARATE-NEXT: - SectionOffset: 7 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: -; SEPARATE: Content: 68656C6C6F00 -; SEPARATE-NEXT: - SectionOffset: 19 +; SEPARATE: Content: 636F6E7374616E7400 +; SEPARATE-NEXT: - SectionOffset: 22 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: -; SEPARATE: Content: 676F6F6462796500 -; SEPARATE-NEXT: - SectionOffset: 33 +; SEPARATE: Content: 2B +; SEPARATE-NEXT: - SectionOffset: 29 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: -; SEPARATE: Content: '776861746576657200' -; SEPARATE-NEXT: - SectionOffset: 48 +; SEPARATE: Content: 68656C6C6F00 +; SEPARATE-NEXT: - SectionOffset: 41 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: -; SEPARATE: Content: 2A000000 -; SEPARATE-NEXT: - SectionOffset: 58 +; SEPARATE: Content: 676F6F6462796500 +; SEPARATE-NEXT: - SectionOffset: 55 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: -; SEPARATE: Content: 636F6E7374616E7400 -; SEPARATE-NEXT: - SectionOffset: 73 +; SEPARATE: Content: '776861746576657200' +; SEPARATE-NEXT: - SectionOffset: 70 ; SEPARATE-NEXT: InitFlags: 0 ; SEPARATE-NEXT: Offset: -; SEPARATE: Content: 2B +; SEPARATE: Content: 2A000000 ; SEPARATE-NEXT: - Type: CUSTOM ; SEPARATE-NEXT: Name: name ; SEPARATE-NEXT: FunctionNames: @@ -77,10 +77,10 @@ ; PASSIVE-MERGE-NEXT: Segments: ; PASSIVE-MERGE-NEXT: - SectionOffset: 3 ; PASSIVE-MERGE-NEXT: InitFlags: 1 -; PASSIVE-MERGE-NEXT: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000 -; PASSIVE-MERGE-NEXT: - SectionOffset: 33 -; PASSIVE-MERGE-NEXT: InitFlags: 1 ; PASSIVE-MERGE-NEXT: Content: 636F6E7374616E74000000002B +; PASSIVE-MERGE-NEXT: - SectionOffset: 18 +; PASSIVE-MERGE-NEXT: InitFlags: 1 +; PASSIVE-MERGE-NEXT: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000 ; PASSIVE-MERGE-NEXT: - Type: CUSTOM ; PASSIVE-MERGE-NEXT: Name: name ; PASSIVE-MERGE-NEXT: FunctionNames: @@ -100,22 +100,22 @@ ; PASSIVE-SEPARATE-NEXT: Segments: ; PASSIVE-SEPARATE-NEXT: - SectionOffset: 3 ; PASSIVE-SEPARATE-NEXT: InitFlags: 1 +; PASSIVE-SEPARATE-NEXT: Content: 636F6E7374616E7400 +; PASSIVE-SEPARATE-NEXT: - SectionOffset: 14 +; PASSIVE-SEPARATE-NEXT: InitFlags: 1 +; PASSIVE-SEPARATE-NEXT: Content: 2B +; PASSIVE-SEPARATE-NEXT: - SectionOffset: 17 +; PASSIVE-SEPARATE-NEXT: InitFlags: 1 ; PASSIVE-SEPARATE-NEXT: Content: 68656C6C6F00 -; PASSIVE-SEPARATE-NEXT: - SectionOffset: 11 +; PASSIVE-SEPARATE-NEXT: - SectionOffset: 25 ; PASSIVE-SEPARATE-NEXT: InitFlags: 1 ; PASSIVE-SEPARATE-NEXT: Content: 676F6F6462796500 -; PASSIVE-SEPARATE-NEXT: - SectionOffset: 21 +; PASSIVE-SEPARATE-NEXT: - SectionOffset: 35 ; PASSIVE-SEPARATE-NEXT: InitFlags: 1 ; PASSIVE-SEPARATE-NEXT: Content: '776861746576657200' -; PASSIVE-SEPARATE-NEXT: - SectionOffset: 32 +; PASSIVE-SEPARATE-NEXT: - SectionOffset: 46 ; PASSIVE-SEPARATE-NEXT: InitFlags: 1 ; PASSIVE-SEPARATE-NEXT: Content: 2A000000 -; PASSIVE-SEPARATE-NEXT: - SectionOffset: 38 -; PASSIVE-SEPARATE-NEXT: InitFlags: 1 -; PASSIVE-SEPARATE-NEXT: Content: 636F6E7374616E7400 -; PASSIVE-SEPARATE-NEXT: - SectionOffset: 49 -; PASSIVE-SEPARATE-NEXT: InitFlags: 1 -; PASSIVE-SEPARATE-NEXT: Content: 2B ; PASSIVE-SEPARATE-NEXT: - Type: CUSTOM ; PASSIVE-SEPARATE-NEXT: Name: name ; PASSIVE-SEPARATE-NEXT: FunctionNames: diff --git a/lld/test/wasm/data-segments.ll b/lld/test/wasm/data-segments.ll --- a/lld/test/wasm/data-segments.ll +++ b/lld/test/wasm/data-segments.ll @@ -37,20 +37,20 @@ ; ACTIVE-NEXT: Offset: ; ACTIVE-NEXT: Opcode: I32_CONST ; ACTIVE-NEXT: Value: 1024 -; ACTIVE-NEXT: Content: 68656C6C6F00676F6F646279650000002A000000 -; ACTIVE-NEXT: - SectionOffset: 34 +; ACTIVE-NEXT: Content: 636F6E7374616E74000000002B +; ACTIVE-NEXT: - SectionOffset: 26 ; ACTIVE-NEXT: InitFlags: 0 ; ACTIVE-NEXT: Offset: ; ACTIVE-NEXT: Opcode: I32_CONST -; ACTIVE-NEXT: Value: 1044 -; ACTIVE-NEXT: Content: '0000000000 -; ACTIVE-SAME: 0000000000' -; ACTIVE-NEXT: - SectionOffset: 10041 +; ACTIVE-NEXT: Value: 1040 +; ACTIVE-NEXT: Content: 68656C6C6F00676F6F646279650000002A000000 +; ACTIVE-NEXT: - SectionOffset: 53 ; ACTIVE-NEXT: InitFlags: 0 ; ACTIVE-NEXT: Offset: ; ACTIVE-NEXT: Opcode: I32_CONST -; ACTIVE-NEXT: Value: 11044 -; ACTIVE-NEXT: Content: 636F6E7374616E74000000002B +; ACTIVE-NEXT: Value: 1060 +; ACTIVE-NEXT: Content: '0000000000 +; ACTIVE-SAME: 0000000000' ; ACTIVE-NEXT: - Type: CUSTOM ; ACTIVE-NEXT: Name: name ; ACTIVE-NEXT: FunctionNames: @@ -66,7 +66,7 @@ ; PASSIVE-NEXT: Body: 0B ; PASSIVE-NEXT: - Index: 1 ; PASSIVE-NEXT: Locals: [] -; PASSIVE-NEXT: Body: 41B4D60041004101FE480200044041B4D6004101427FFE0102001A0541800841004114FC08000041940841004190CE00FC08010041A4D6004100410DFC08020041B4D6004102FE17020041B4D600417FFE0002001A0BFC0900FC0901FC09020B +; PASSIVE-NEXT: Body: 41B4D60041004101FE480200044041B4D6004101427FFE0102001A054180084100410DFC08000041900841004114FC08010041A40841004190CE00FC08020041B4D6004102FE17020041B4D600417FFE0002001A0BFC0900FC0901FC09020B ; PASSIVE-NEXT: - Index: 2 ; PASSIVE-NEXT: Locals: [] ; PASSIVE-NEXT: Body: 0B @@ -74,14 +74,14 @@ ; PASSIVE-NEXT: Segments: ; PASSIVE-NEXT: - SectionOffset: 3 ; PASSIVE-NEXT: InitFlags: 1 +; PASSIVE-NEXT: Content: 636F6E7374616E74000000002B +; PASSIVE-NEXT: - SectionOffset: 18 +; PASSIVE-NEXT: InitFlags: 1 ; PASSIVE-NEXT: Content: 68656C6C6F00676F6F646279650000002A000000 -; PASSIVE-NEXT: - SectionOffset: 26 +; PASSIVE-NEXT: - SectionOffset: 41 ; PASSIVE-NEXT: InitFlags: 1 ; PASSIVE-NEXT: Content: '0000000000 ; PASSIVE-SAME: 0000000000' -; PASSIVE-NEXT: - SectionOffset: 10028 -; PASSIVE-NEXT: InitFlags: 1 -; PASSIVE-NEXT: Content: 636F6E7374616E74000000002B ; PASSIVE-NEXT: - Type: CUSTOM ; PASSIVE-NEXT: Name: name ; PASSIVE-NEXT: FunctionNames: @@ -89,5 +89,5 @@ ; PASSIVE-NEXT: Name: __wasm_call_ctors ; PASSIVE-NEXT: - Index: 1 ; PASSIVE-NEXT: Name: __wasm_init_memory -; PASSIVE-NEXT: - Index: 2 -; PASSIVE-NEXT: Name: __wasm_init_tls +; PASSIVE-NEXT: - Index: 2 +; PASSIVE-NEXT: Name: __wasm_init_tls diff --git a/lld/test/wasm/reloc-addend.ll b/lld/test/wasm/reloc-addend.ll --- a/lld/test/wasm/reloc-addend.ll +++ b/lld/test/wasm/reloc-addend.ll @@ -12,8 +12,8 @@ @bar = hidden local_unnamed_addr global i32* getelementptr inbounds ([76 x i32], [76 x i32]* @foo, i32 0, i32 16), align 4 ; CHECK: - Type: DATA -; CHECK-NEXT: Relocations: +; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_I32 ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: Offset: 0x0000013D +; CHECK-NEXT: Offset: 0x00000006 ; CHECK-NEXT: Addend: 64 diff --git a/lld/test/wasm/relocatable.ll b/lld/test/wasm/relocatable.ll --- a/lld/test/wasm/relocatable.ll +++ b/lld/test/wasm/relocatable.ll @@ -113,21 +113,21 @@ ; CHECK-NEXT: Body: 1081808080001A1082808080001A41010B ; CHECK-NEXT: - Index: 5 ; CHECK-NEXT: Locals: -; CHECK-NEXT: Body: 419C808080000B +; CHECK-NEXT: Body: 4187808080000B ; NORMAL-NEXT: - Type: DATA ; NORMAL-NEXT: Relocations: ; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32 ; NORMAL-NEXT: Index: 3 -; NORMAL-NEXT: Offset: 0x00000012 +; NORMAL-NEXT: Offset: 0x0000001A ; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32 ; NORMAL-NEXT: Index: 4 -; NORMAL-NEXT: Offset: 0x0000001B +; NORMAL-NEXT: Offset: 0x00000023 ; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32 ; NORMAL-NEXT: Index: 5 -; NORMAL-NEXT: Offset: 0x00000024 +; NORMAL-NEXT: Offset: 0x0000002C ; NORMAL-NEXT: - Type: R_WASM_MEMORY_ADDR_I32 ; NORMAL-NEXT: Index: 12 -; NORMAL-NEXT: Offset: 0x0000002D +; NORMAL-NEXT: Offset: 0x00000035 ; NORMAL-NEXT: Segments: ; NORMAL-NEXT: - SectionOffset: 6 ; NORMAL-NEXT: InitFlags: 0 @@ -139,32 +139,32 @@ ; NORMAL-NEXT: InitFlags: 0 ; NORMAL-NEXT: Offset: ; NORMAL-NEXT: Opcode: I32_CONST -; NORMAL-NEXT: Value: 8 -; NORMAL-NEXT: Content: '01000000' -; NORMAL-NEXT: - SectionOffset: 27 +; NORMAL-NEXT: Value: 7 +; NORMAL-NEXT: Content: '616263' +; NORMAL-NEXT: - SectionOffset: 26 ; NORMAL-NEXT: InitFlags: 0 ; NORMAL-NEXT: Offset: ; NORMAL-NEXT: Opcode: I32_CONST ; NORMAL-NEXT: Value: 12 -; NORMAL-NEXT: Content: '02000000' -; NORMAL-NEXT: - SectionOffset: 36 +; NORMAL-NEXT: Content: '01000000' +; NORMAL-NEXT: - SectionOffset: 35 ; NORMAL-NEXT: InitFlags: 0 ; NORMAL-NEXT: Offset: ; NORMAL-NEXT: Opcode: I32_CONST ; NORMAL-NEXT: Value: 16 -; NORMAL-NEXT: Content: '03000000' -; NORMAL-NEXT: - SectionOffset: 45 +; NORMAL-NEXT: Content: '02000000' +; NORMAL-NEXT: - SectionOffset: 44 ; NORMAL-NEXT: InitFlags: 0 ; NORMAL-NEXT: Offset: ; NORMAL-NEXT: Opcode: I32_CONST -; NORMAL-NEXT: Value: 24 -; NORMAL-NEXT: Content: '00000000' -; NORMAL-NEXT: - SectionOffset: 54 +; NORMAL-NEXT: Value: 20 +; NORMAL-NEXT: Content: '03000000' +; NORMAL-NEXT: - SectionOffset: 53 ; NORMAL-NEXT: InitFlags: 0 ; NORMAL-NEXT: Offset: ; NORMAL-NEXT: Opcode: I32_CONST -; NORMAL-NEXT: Value: 28 -; NORMAL-NEXT: Content: '616263' +; NORMAL-NEXT: Value: 24 +; NORMAL-NEXT: Content: '00000000' ; NORMAL-NEXT: - Type: CUSTOM ; NORMAL-NEXT: Name: linking ; NORMAL-NEXT: Version: 2 @@ -209,31 +209,31 @@ ; NORMAL-NEXT: Kind: DATA ; NORMAL-NEXT: Name: data_comdat ; NORMAL-NEXT: Flags: [ BINDING_WEAK ] -; NORMAL-NEXT: Segment: 5 +; NORMAL-NEXT: Segment: 1 ; NORMAL-NEXT: Size: 3 ; NORMAL-NEXT: - Index: 8 ; NORMAL-NEXT: Kind: DATA ; NORMAL-NEXT: Name: func_addr1 ; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; NORMAL-NEXT: Segment: 1 +; NORMAL-NEXT: Segment: 2 ; NORMAL-NEXT: Size: 4 ; NORMAL-NEXT: - Index: 9 ; NORMAL-NEXT: Kind: DATA ; NORMAL-NEXT: Name: func_addr2 ; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; NORMAL-NEXT: Segment: 2 +; NORMAL-NEXT: Segment: 3 ; NORMAL-NEXT: Size: 4 ; NORMAL-NEXT: - Index: 10 ; NORMAL-NEXT: Kind: DATA ; NORMAL-NEXT: Name: func_addr3 ; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; NORMAL-NEXT: Segment: 3 +; NORMAL-NEXT: Segment: 4 ; NORMAL-NEXT: Size: 4 ; NORMAL-NEXT: - Index: 11 ; NORMAL-NEXT: Kind: DATA ; NORMAL-NEXT: Name: data_addr1 ; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ] -; NORMAL-NEXT: Segment: 4 +; NORMAL-NEXT: Segment: 5 ; NORMAL-NEXT: Size: 4 ; NORMAL-NEXT: - Index: 12 ; NORMAL-NEXT: Kind: DATA @@ -245,32 +245,32 @@ ; NORMAL-NEXT: Alignment: 0 ; NORMAL-NEXT: Flags: [ ] ; NORMAL-NEXT: - Index: 1 +; NORMAL-NEXT: Name: .rodata.data_comdat +; NORMAL-NEXT: Alignment: 0 +; NORMAL-NEXT: Flags: [ ] +; NORMAL-NEXT: - Index: 2 ; NORMAL-NEXT: Name: .data.func_addr1 ; NORMAL-NEXT: Alignment: 2 ; NORMAL-NEXT: Flags: [ ] -; NORMAL-NEXT: - Index: 2 +; NORMAL-NEXT: - Index: 3 ; NORMAL-NEXT: Name: .data.func_addr2 ; NORMAL-NEXT: Alignment: 2 ; NORMAL-NEXT: Flags: [ ] -; NORMAL-NEXT: - Index: 3 +; NORMAL-NEXT: - Index: 4 ; NORMAL-NEXT: Name: .data.func_addr3 ; NORMAL-NEXT: Alignment: 2 ; NORMAL-NEXT: Flags: [ ] -; NORMAL-NEXT: - Index: 4 +; NORMAL-NEXT: - Index: 5 ; NORMAL-NEXT: Name: .data.data_addr1 ; NORMAL-NEXT: Alignment: 3 ; NORMAL-NEXT: Flags: [ ] -; NORMAL-NEXT: - Index: 5 -; NORMAL-NEXT: Name: .rodata.data_comdat -; NORMAL-NEXT: Alignment: 0 -; NORMAL-NEXT: Flags: [ ] ; NORMAL-NEXT: Comdats: ; NORMAL-NEXT: - Name: func_comdat ; NORMAL-NEXT: Entries: ; NORMAL-NEXT: - Kind: FUNCTION ; NORMAL-NEXT: Index: 5 ; NORMAL-NEXT: - Kind: DATA -; NORMAL-NEXT: Index: 5 +; NORMAL-NEXT: Index: 1 ; NORMAL-NEXT: - Type: CUSTOM ; NORMAL-NEXT: Name: name ; NORMAL-NEXT: FunctionNames: diff --git a/lld/test/wasm/tls-align.ll b/lld/test/wasm/tls-align.ll --- a/lld/test/wasm/tls-align.ll +++ b/lld/test/wasm/tls-align.ll @@ -24,7 +24,7 @@ ; CHECK-NEXT: Mutable: true ; CHECK-NEXT: InitExpr: ; CHECK-NEXT: Opcode: I32_CONST -; CHECK-NEXT: Value: 66608 +; CHECK-NEXT: Value: 66592 ; __tls_base ; CHECK-NEXT: - Index: 1 diff --git a/lld/test/wasm/tls.ll b/lld/test/wasm/tls.ll --- a/lld/test/wasm/tls.ll +++ b/lld/test/wasm/tls.ll @@ -66,7 +66,7 @@ ; Skip __wasm_call_ctors and __wasm_init_memory ; CHECK: - Index: 2 ; CHECK-NEXT: Locals: [] -; CHECK-NEXT: Body: 20002401200041004108FC0801000B +; CHECK-NEXT: Body: 20002401200041004108FC0800000B ; Expected body of __wasm_init_tls: ; local.get 0 diff --git a/lld/wasm/OutputSegment.h b/lld/wasm/OutputSegment.h --- a/lld/wasm/OutputSegment.h +++ b/lld/wasm/OutputSegment.h @@ -20,7 +20,7 @@ class OutputSegment { public: - OutputSegment(StringRef n, uint32_t index) : name(n), index(index) {} + OutputSegment(StringRef n) : name(n) {} void addInputSegment(InputSegment *inSeg) { alignment = std::max(alignment, inSeg->getAlignment()); @@ -32,7 +32,7 @@ } StringRef name; - const uint32_t index; + uint32_t index = 0; uint32_t initFlags = 0; uint32_t sectionOffset = 0; uint32_t alignment = 0; diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -263,7 +263,6 @@ memoryPtr += 4; } - // TODO: Add .bss space here. if (WasmSym::dataEnd) WasmSym::dataEnd->setVirtualAddress(memoryPtr); @@ -667,7 +666,7 @@ OutputSegment *&s = segmentMap[name]; if (s == nullptr) { LLVM_DEBUG(dbgs() << "new segment: " << name << "\n"); - s = make(name, segments.size()); + s = make(name); if (config->sharedMemory || name == ".tdata") s->initFlags = WASM_SEGMENT_IS_PASSIVE; segments.push_back(s); @@ -676,6 +675,24 @@ LLVM_DEBUG(dbgs() << "added data: " << name << ": " << s->size << "\n"); } } + + // Sort segments by type, placing .bss last + std::stable_sort(segments.begin(), segments.end(), + [](const OutputSegment *a, const OutputSegment *b) { + for (auto &name : {".rodata", ".data", ".tdata", ".bss"}) { + bool matchA = a->name.startswith(name); + bool matchB = b->name.startswith(name); + if (matchA && !matchB) + return true; + if (matchB) + return false; + } + llvm_unreachable("Unexpected segment name"); + }); + + for (size_t i = 0; i < segments.size(); ++i) { + segments[i]->index = i; + } } static void createFunction(DefinedFunction *func, StringRef bodyContent) {