llvm.org GIT mirror llvm / fa82617
[WebAssembly] Update MC for bulk memory Summary: Rename MemoryIndex to InitFlags and implement logic for determining data segment layout in ObjectYAML and MC. Also adds a "passive" flag for the .section assembler directive although this cannot be assembled yet because the assembler does not support data sections. Reviewers: sbc100, aardappel, aheejin, dschuff Subscribers: jgravelle-google, hiraditya, sunfish, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57938 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354397 91177308-0d34-0410-b5e6-96231b3b80d8 Thomas Lively 6 months ago
31 changed file(s) with 227 addition(s) and 83 deletion(s). Raw diff Collapse all Expand all
130130 };
131131
132132 struct WasmDataSegment {
133 uint32_t MemoryIndex;
134 WasmInitExpr Offset;
133 uint32_t InitFlags;
134 uint32_t MemoryIndex; // present if InitFlags & WASM_SEGMENT_HAS_MEMINDEX
135 WasmInitExpr Offset; // present if InitFlags & WASM_SEGMENT_IS_PASSIVE == 0
135136 ArrayRef Content;
136137 StringRef Name; // from the "segment info" section
137138 uint32_t Alignment;
138 uint32_t Flags;
139 uint32_t LinkerFlags;
139140 uint32_t Comdat; // from the "comdat info" section
140141 };
141142
246247 WASM_LIMITS_FLAG_IS_SHARED = 0x2,
247248 };
248249
250 enum : unsigned {
251 WASM_SEGMENT_IS_PASSIVE = 0x01,
252 WASM_SEGMENT_HAS_MEMINDEX = 0x02,
253 };
254
249255 // Kind codes used in the custom "name" section
250256 enum : unsigned {
251257 WASM_NAMES_FUNCTION = 0x1,
4141 // segment
4242 uint32_t SegmentIndex = 0;
4343
44 // Whether this data segment is passive
45 bool IsPassive = false;
46
4447 friend class MCContext;
4548 MCSectionWasm(StringRef Section, SectionKind K, const MCSymbolWasm *group,
4649 unsigned UniqueID, MCSymbol *Begin)
7477 uint32_t getSegmentIndex() const { return SegmentIndex; }
7578 void setSegmentIndex(uint32_t Index) { SegmentIndex = Index; }
7679
80 bool getPassive() const {
81 assert(isWasmData());
82 return IsPassive;
83 }
84 void setPassive(bool V = true) {
85 assert(isWasmData());
86 IsPassive = V;
87 }
7788 static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
7889 };
7990
110110 };
111111
112112 struct DataSegment {
113 uint32_t SectionOffset;
114 uint32_t InitFlags;
113115 uint32_t MemoryIndex;
114 uint32_t SectionOffset;
115116 wasm::WasmInitExpr Offset;
116117 yaml::BinaryRef Content;
117118 };
16921692 Group = C->getName();
16931693 }
16941694
1695 return getContext().getWasmSection(Name, Kind, Group,
1696 MCContext::GenericSectionID);
1695 MCSectionWasm* Section =
1696 getContext().getWasmSection(Name, Kind, Group,
1697 MCContext::GenericSectionID);
1698
1699 if (TM.Options.ThreadModel != ThreadModel::Single)
1700 Section->setPassive();
1701
1702 return Section;
16971703 }
16981704
16991705 static MCSectionWasm *selectWasmSectionForGlobal(
17221728 UniqueID = *NextUniqueID;
17231729 (*NextUniqueID)++;
17241730 }
1725 return Ctx.getWasmSection(Name, Kind, Group, UniqueID);
1731
1732 MCSectionWasm* Section = Ctx.getWasmSection(Name, Kind, Group, UniqueID);
1733 if (Section->isWasmData() && TM.Options.ThreadModel != ThreadModel::Single)
1734 Section->setPassive();
1735
1736 return Section;
17261737 }
17271738
17281739 MCSection *TargetLoweringObjectFileWasm::SelectSectionForGlobal(
8080 return false;
8181 }
8282
83 bool parseSectionFlags(StringRef FlagStr, bool &Passive) {
84 SmallVector Flags;
85 // If there are no flags, keep Flags empty
86 FlagStr.split(Flags, ",", -1, false);
87 for (auto &Flag : Flags) {
88 if (Flag == "passive")
89 Passive = true;
90 else
91 return error("Expected section flags, instead got: ", Lexer->getTok());
92 }
93 return false;
94 }
95
8396 bool parseSectionDirective(StringRef, SMLoc) {
8497 StringRef Name;
8598 if (Parser->parseIdentifier(Name))
8699 return TokError("expected identifier in directive");
87 // FIXME: currently requiring this very fixed format.
88 if (expect(AsmToken::Comma, ",") || expect(AsmToken::String, "string") ||
89 expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") ||
100
101 if (expect(AsmToken::Comma, ","))
102 return true;
103
104 if (Lexer->isNot(AsmToken::String))
105 return error("expected string in directive, instead got: ", Lexer->getTok());
106
107 SectionKind Kind = StringSwitch(Name)
108 .StartsWith(".data", SectionKind::getData())
109 .StartsWith(".rodata", SectionKind::getReadOnly())
110 .StartsWith(".text", SectionKind::getText())
111 .StartsWith(".custom_section", SectionKind::getMetadata());
112
113 MCSectionWasm* Section = getContext().getWasmSection(Name, Kind);
114
115 // Update section flags if present in this .section directive
116 bool Passive = false;
117 if (parseSectionFlags(getTok().getStringContents(), Passive))
118 return true;
119
120 if (Passive) {
121 if (!Section->isWasmData())
122 return Parser->Error(getTok().getLoc(),
123 "Only data sections can be passive");
124 Section->setPassive();
125 }
126
127 Lex();
128
129 if (expect(AsmToken::Comma, ",") || expect(AsmToken::At, "@") ||
90130 expect(AsmToken::EndOfStatement, "eol"))
91131 return true;
92132 // This is done automatically by the assembler for text sections currently,
6161 printName(OS, getSectionName());
6262 OS << ",\"";
6363
64 // TODO: Print section flags.
64 if (IsPassive)
65 OS << "passive";
6566
6667 OS << '"';
6768
105105 struct WasmDataSegment {
106106 MCSectionWasm *Section;
107107 StringRef Name;
108 uint32_t InitFlags;
108109 uint32_t Offset;
109110 uint32_t Alignment;
110 uint32_t Flags;
111 uint32_t LinkerFlags;
111112 SmallVector Data;
112113 };
113114
898899 encodeULEB128(DataSegments.size(), W.OS); // count
899900
900901 for (const WasmDataSegment &Segment : DataSegments) {
901 encodeULEB128(0, W.OS); // memory index
902 W.OS << char(wasm::WASM_OPCODE_I32_CONST);
903 encodeSLEB128(Segment.Offset, W.OS); // offset
904 W.OS << char(wasm::WASM_OPCODE_END);
902 encodeULEB128(Segment.InitFlags, W.OS); // flags
903 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
904 encodeULEB128(0, W.OS); // memory index
905 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
906 W.OS << char(wasm::WASM_OPCODE_I32_CONST);
907 encodeSLEB128(Segment.Offset, W.OS); // offset
908 W.OS << char(wasm::WASM_OPCODE_END);
909 }
905910 encodeULEB128(Segment.Data.size(), W.OS); // size
906911 Segment.Section->setSectionOffset(W.OS.tell() - Section.ContentsOffset);
907912 W.OS << Segment.Data; // data
10121017 for (const WasmDataSegment &Segment : DataSegments) {
10131018 writeString(Segment.Name);
10141019 encodeULEB128(Segment.Alignment, W.OS);
1015 encodeULEB128(Segment.Flags, W.OS);
1020 encodeULEB128(Segment.LinkerFlags, W.OS);
10161021 }
10171022 endSection(SubSection);
10181023 }
12521257 DataSegments.emplace_back();
12531258 WasmDataSegment &Segment = DataSegments.back();
12541259 Segment.Name = SectionName;
1260 Segment.InitFlags = Section.getPassive() ? wasm::WASM_SEGMENT_IS_PASSIVE : 0;
12551261 Segment.Offset = DataSize;
12561262 Segment.Section = &Section;
12571263 addData(Segment.Data, Section);
12581264 Segment.Alignment = Log2_32(Section.getAlignment());
1259 Segment.Flags = 0;
1265 Segment.LinkerFlags = 0;
12601266 DataSize += Segment.Data.size();
12611267 Section.setSegmentIndex(SegmentIndex);
12621268
420420 for (uint32_t I = 0; I < Count; I++) {
421421 DataSegments[I].Data.Name = readString(Ctx);
422422 DataSegments[I].Data.Alignment = readVaruint32(Ctx);
423 DataSegments[I].Data.Flags = readVaruint32(Ctx);
423 DataSegments[I].Data.LinkerFlags = readVaruint32(Ctx);
424424 }
425425 break;
426426 }
11631163 DataSegments.reserve(Count);
11641164 while (Count--) {
11651165 WasmSegment Segment;
1166 Segment.Data.MemoryIndex = readVaruint32(Ctx);
1167 if (Error Err = readInitExpr(Segment.Data.Offset, Ctx))
1168 return Err;
1166 Segment.Data.InitFlags = readVaruint32(Ctx);
1167 Segment.Data.MemoryIndex = (Segment.Data.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
1168 ? readVaruint32(Ctx) : 0;
1169 if ((Segment.Data.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
1170 if (Error Err = readInitExpr(Segment.Data.Offset, Ctx))
1171 return Err;
1172 } else {
1173 Segment.Data.Offset.Opcode = wasm::WASM_OPCODE_I32_CONST;
1174 Segment.Data.Offset.Value.Int32 = 0;
1175 }
11691176 uint32_t Size = readVaruint32(Ctx);
11701177 if (Size > (size_t)(Ctx.End - Ctx.Ptr))
11711178 return make_error("Invalid segment size",
11741181 // The rest of these Data fields are set later, when reading in the linking
11751182 // metadata section.
11761183 Segment.Data.Alignment = 0;
1177 Segment.Data.Flags = 0;
1184 Segment.Data.LinkerFlags = 0;
11781185 Segment.Data.Comdat = UINT32_MAX;
11791186 Segment.SectionOffset = Ctx.Ptr - Ctx.Start;
11801187 Ctx.Ptr += Size;
402402 void MappingTraits::mapping(
403403 IO &IO, WasmYAML::DataSegment &Segment) {
404404 IO.mapOptional("SectionOffset", Segment.SectionOffset);
405 IO.mapRequired("MemoryIndex", Segment.MemoryIndex);
406 IO.mapRequired("Offset", Segment.Offset);
405 IO.mapRequired("InitFlags", Segment.InitFlags);
406 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX) {
407 IO.mapRequired("MemoryIndex", Segment.MemoryIndex);
408 } else {
409 Segment.MemoryIndex = 0;
410 }
411 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
412 IO.mapRequired("Offset", Segment.Offset);
413 } else {
414 Segment.Offset.Opcode = wasm::WASM_OPCODE_I32_CONST;
415 Segment.Offset.Value.Int32 = 0;
416 }
407417 IO.mapRequired("Content", Segment.Content);
408418 }
409419
3838 #include "llvm/Support/Debug.h"
3939 #include "llvm/Support/TargetRegistry.h"
4040 #include "llvm/Support/raw_ostream.h"
41
4142 using namespace llvm;
4243
4344 #define DEBUG_TYPE "asm-printer"
None ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s
0 ; RUN: llc < %s -thread-model=single -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefixes=CHECK,SINGLE
1 ; RUN: llc < %s -thread-model=posix -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefixes=CHECK,THREADS
12
23 ; Test that globals assemble as expected.
34
190191
191192 ; Constant global.
192193 ; CHECK: .type rom,@object{{$}}
193 ; CHECK: .section .rodata.rom,
194 ; SINGLE: .section .rodata.rom,""
195 ; THREADS: .section .rodata.rom,"passive"
194196 ; CHECK: .globl rom{{$}}
195197 ; CHECK: .p2align 4{{$}}
196198 ; CHECK: rom:
203205 ; CHECK-NEXT: .skip 8
204206 ; CHECK-NEXT: .size array, 8
205207 ; CHECK: .type pointer_to_array,@object
206 ; CHECK-NEXT: .section .rodata.pointer_to_array,
208 ; SINGLE-NEXT: .section .rodata.pointer_to_array,""
209 ; THREADS-NEXT: .section .rodata.pointer_to_array,"passive"
207210 ; CHECK-NEXT: .globl pointer_to_array
208211 ; CHECK-NEXT: .p2align 2
209212 ; CHECK-NEXT: pointer_to_array:
None ; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFONAME
1 ; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=VTABLE
2 ; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFO
0 ; RUN: llc < %s -asm-verbose=false -thread-model=single -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFONAME
1 ; RUN: llc < %s -asm-verbose=false -thread-model=single -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=VTABLE
2 ; RUN: llc < %s -asm-verbose=false -thread-model=single -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFO
33
44 ; Test that simple vtables assemble as expected.
55 ;
None ; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
0 ; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s
11
22 target triple = "wasm32-unknown-unknown"
33
1111 ; CHECK: - Type: DATA
1212 ; CHECK-NEXT: Segments:
1313 ; CHECK-NEXT: - SectionOffset: 6
14 ; CHECK-NEXT: MemoryIndex: 0
14 ; CHECK-NEXT: InitFlags: 0
1515 ; CHECK-NEXT: Offset:
1616 ; CHECK-NEXT: Opcode: I32_CONST
1717 ; CHECK-NEXT: Value: 0
1818 ; CHECK-NEXT: Content: '00000000'
1919 ; CHECK-NEXT: - SectionOffset: 15
20 ; CHECK-NEXT: MemoryIndex: 0
20 ; CHECK-NEXT: InitFlags: 0
2121 ; CHECK-NEXT: Offset:
2222 ; CHECK-NEXT: Opcode: I32_CONST
2323 ; CHECK-NEXT: Value: 4
2424 ; CHECK-NEXT: Content: '00000000'
2525 ; CHECK-NEXT: - SectionOffset: 24
26 ; CHECK-NEXT: MemoryIndex: 0
26 ; CHECK-NEXT: InitFlags: 0
2727 ; CHECK-NEXT: Offset:
2828 ; CHECK-NEXT: Opcode: I32_CONST
2929 ; CHECK-NEXT: Value: 8
3030 ; CHECK-NEXT: Content: ''
3131 ; CHECK-NEXT: - SectionOffset: 29
32 ; CHECK-NEXT: MemoryIndex: 0
32 ; CHECK-NEXT: InitFlags: 0
3333 ; CHECK-NEXT: Offset:
3434 ; CHECK-NEXT: Opcode: I32_CONST
3535 ; CHECK-NEXT: Value: 8
None ; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
0 ; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s
11
22 target triple = "wasm32-unknown-unknown"
33
6767 ; CHECK-NEXT: - Type: DATA
6868 ; CHECK-NEXT: Segments:
6969 ; CHECK-NEXT: - SectionOffset: 6
70 ; CHECK-NEXT: MemoryIndex: 0
70 ; CHECK-NEXT: InitFlags: 0
7171 ; CHECK-NEXT: Offset:
7272 ; CHECK-NEXT: Opcode: I32_CONST
7373 ; CHECK-NEXT: Value: 0
None ; RUN: llc -filetype=obj %s -o - | llvm-readobj -r -s -symbols | FileCheck %s
0 ; RUN: llc -filetype=obj -thread-model=single %s -o - | llvm-readobj -r -s -symbols | FileCheck %s
11
22 ; CHECK: Format: WASM
33 ; CHECK-NEXT:Arch: wasm32
None ; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
0 ; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s
11
22 target triple = "wasm32-unknown-unknown"
33
1212 ; CHECK: - Type: DATA
1313 ; CHECK-NEXT: Segments:
1414 ; CHECK-NEXT: - SectionOffset: 6
15 ; CHECK-NEXT: MemoryIndex: 0
16 ; CHECK-NEXT: Offset:
15 ; CHECK-NEXT: InitFlags: 0
16 ; CHECK-NEXT: Offset:
1717 ; CHECK-NEXT: Opcode: I32_CONST
1818 ; CHECK-NEXT: Value: 0
1919 ; CHECK-NEXT: Content: '08000000'
2020 ; CHECK-NEXT: - SectionOffset: 15
21 ; CHECK-NEXT: MemoryIndex: 0
22 ; CHECK-NEXT: Offset:
21 ; CHECK-NEXT: InitFlags: 0
22 ; CHECK-NEXT: Offset:
2323 ; CHECK-NEXT: Opcode: I32_CONST
2424 ; CHECK-NEXT: Value: 8
2525 ; CHECK-NEXT: Content: '01000000030000000700000000000000'
2626 ; CHECK-NEXT: - SectionOffset: 36
27 ; CHECK-NEXT: MemoryIndex: 0
28 ; CHECK-NEXT: Offset:
27 ; CHECK-NEXT: InitFlags: 0
28 ; CHECK-NEXT: Offset:
2929 ; CHECK-NEXT: Opcode: I32_CONST
3030 ; CHECK-NEXT: Value: 24
3131 ; CHECK-NEXT: Content: '08000000'
None ; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
0 ; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s
11
22 target triple = "wasm32-unknown-unknown"
33
1616 ; CHECK-NEXT: Offset: 0x00000013
1717 ; CHECK-NEXT: Segments:
1818 ; CHECK-NEXT: - SectionOffset: 6
19 ; CHECK-NEXT: MemoryIndex: 0
19 ; CHECK-NEXT: InitFlags: 0
2020 ; CHECK-NEXT: Offset:
2121 ; CHECK-NEXT: Opcode: I32_CONST
2222 ; CHECK-NEXT: Value: 0
2323 ; CHECK-NEXT: Content: '0700000000000000'
2424 ; CHECK-NEXT: - SectionOffset: 19
25 ; CHECK-NEXT: MemoryIndex: 0
26 ; CHECK-NEXT: Offset:
25 ; CHECK-NEXT: InitFlags: 0
26 ; CHECK-NEXT: Offset:
2727 ; CHECK-NEXT: Opcode: I32_CONST
2828 ; CHECK-NEXT: Value: 8
2929 ; CHECK-NEXT: Content: '00000000'
None ; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
0 ; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s
11
22 target triple = "wasm32-unknown-unknown"
33
None ; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
0 ; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s
11
22 target triple = "wasm32-unknown-unknown"
33
102102 ; CHECK-NEXT: - Type: DATA
103103 ; CHECK-NEXT: Segments:
104104 ; CHECK-NEXT: - SectionOffset: 6
105 ; CHECK-NEXT: MemoryIndex: 0
106 ; CHECK-NEXT: Offset:
105 ; CHECK-NEXT: InitFlags: 0
106 ; CHECK-NEXT: Offset:
107107 ; CHECK-NEXT: Opcode: I32_CONST
108108 ; CHECK-NEXT: Value: 0
109109 ; CHECK-NEXT: Content: '01040000'
0 ; RUN: llc -filetype=obj %s -thread-model=single -o - | obj2yaml | FileCheck %s --check-prefix=SINGLE
1 ; RUN: llc -filetype=obj %s -thread-model=posix -o - | obj2yaml | FileCheck %s --check-prefix=THREADS
2
3 ; Test that setting thread-model=posix causes data segments to be
4 ; emitted as passive segments (i.e. have InitFlags set to 1).
5
6 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
7 target triple = "wasm32-unknown-unknown"
8
9 @str = private unnamed_addr constant [7 x i8] c"Hello!\00", align 1
10
11 ; SINGLE: - Type: DATA
12 ; SINGLE-NEXT: Segments:
13 ; SINGLE-NEXT: - SectionOffset: 6
14 ; SINGLE-NEXT: InitFlags: 0
15 ; SINGLE-NEXT: Offset:
16 ; SINGLE-NEXT: Opcode: I32_CONST
17 ; SINGLE-NEXT: Value: 0
18 ; SINGLE-NEXT: Content: 48656C6C6F2100
19
20 ; THREADS: - Type: DATA
21 ; THREADS-NEXT: Segments:
22 ; THREADS-NEXT: - SectionOffset: 3
23 ; THREADS-NEXT: InitFlags: 1
24 ; THREADS-NEXT: Content: 48656C6C6F2100
None ; RUN: llc -O0 -filetype=obj %s -o - | llvm-readobj -r -expand-relocs | FileCheck %s
0 ; RUN: llc -O0 -filetype=obj -thread-model=single %s -o - | llvm-readobj -r -expand-relocs | FileCheck %s
11
22 target triple = "wasm32-unknown-unknown"
33
None ; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
0 ; RUN: llc -filetype=obj -thread-model=single %s -o - | obj2yaml | FileCheck %s
11
22 target triple = "wasm32-unknown-unknown"
33
1818 ; CHECK-NEXT: Offset: 0x00000025
1919 ; CHECK-NEXT: Segments:
2020 ; CHECK-NEXT: - SectionOffset: 6
21 ; CHECK-NEXT: MemoryIndex: 0
22 ; CHECK-NEXT: Offset:
21 ; CHECK-NEXT: InitFlags: 0
22 ; CHECK-NEXT: Offset:
2323 ; CHECK-NEXT: Opcode: I32_CONST
2424 ; CHECK-NEXT: Value: 0
2525 ; CHECK-NEXT: Content: 68656C6C6F00
2626 ; CHECK-NEXT: - SectionOffset: 17
27 ; CHECK-NEXT: MemoryIndex: 0
28 ; CHECK-NEXT: Offset:
27 ; CHECK-NEXT: InitFlags: 0
28 ; CHECK-NEXT: Offset:
2929 ; CHECK-NEXT: Opcode: I32_CONST
3030 ; CHECK-NEXT: Value: 6
3131 ; CHECK-NEXT: Content: 776F726C6400
3232 ; CHECK-NEXT: - SectionOffset: 28
33 ; CHECK-NEXT: MemoryIndex: 0
34 ; CHECK-NEXT: Offset:
33 ; CHECK-NEXT: InitFlags: 0
34 ; CHECK-NEXT: Offset:
3535 ; CHECK-NEXT: Opcode: I32_CONST
3636 ; CHECK-NEXT: Value: 16
3737 ; CHECK-NEXT: Content: '00000000'
3838 ; CHECK-NEXT: - SectionOffset: 37
39 ; CHECK-NEXT: MemoryIndex: 0
40 ; CHECK-NEXT: Offset:
39 ; CHECK-NEXT: InitFlags: 0
40 ; CHECK-NEXT: Offset:
4141 ; CHECK-NEXT: Opcode: I32_CONST
4242 ; CHECK-NEXT: Value: 24
4343 ; CHECK-NEXT: Content: '06000000'
None ; RUN: llc -filetype=obj -wasm-keep-registers %s -o %t.o
0 ; RUN: llc -filetype=obj -thread-model=single -wasm-keep-registers %s -o %t.o
11 ; RUN: obj2yaml %t.o | FileCheck %s
22 ; RUN: llvm-objdump -t %t.o | FileCheck --check-prefix=CHECK-SYMS %s
33
118118 ; CHECK-NEXT: Offset: 0x00000018
119119 ; CHECK-NEXT: Segments:
120120 ; CHECK-NEXT: - SectionOffset: 6
121 ; CHECK-NEXT: MemoryIndex: 0
121 ; CHECK-NEXT: InitFlags: 0
122122 ; CHECK-NEXT: Offset:
123123 ; CHECK-NEXT: Opcode: I32_CONST
124124 ; CHECK-NEXT: Value: 0
125125 ; CHECK-NEXT: Content: '07000000'
126126 ; CHECK-NEXT: - SectionOffset: 15
127 ; CHECK-NEXT: MemoryIndex: 0
127 ; CHECK-NEXT: InitFlags: 0
128128 ; CHECK-NEXT: Offset:
129129 ; CHECK-NEXT: Opcode: I32_CONST
130130 ; CHECK-NEXT: Value: 8
131131 ; CHECK-NEXT: Content: '01000000'
132132 ; CHECK-NEXT: - SectionOffset: 24
133 ; CHECK-NEXT: MemoryIndex: 0
133 ; CHECK-NEXT: InitFlags: 0
134134 ; CHECK-NEXT: Offset:
135135 ; CHECK-NEXT: Opcode: I32_CONST
136136 ; CHECK-NEXT: Value: 16
77 - Initial: 0x00000003
88 - Type: DATA
99 Segments:
10 - MemoryIndex: 0
10 - InitFlags: 0
1111 Offset:
1212 Opcode: I32_CONST
1313 Value: 4
1414 Content: '10001000'
15 - InitFlags: 1
16 Content: '01010101'
17 - InitFlags: 2
18 MemoryIndex: 0
19 Offset:
20 Opcode: I32_CONST
21 Value: 8
22 Content: '00110011'
1523 Relocations:
1624 - Type: R_WASM_MEMORY_ADDR_I32
1725 Index: 0
4856 # CHECK-NEXT: Offset: 0x00000006
4957 # CHECK-NEXT: Addend: -6
5058 # CHECK-NEXT: Segments:
51 # CHECK-NEXT: - SectionOffset: 6
52 # CHECK-NEXT: MemoryIndex: 0
59 # CHECK-NEXT: - SectionOffset: 6
60 # CHECK-NEXT: InitFlags: 0
5361 # CHECK-NEXT: Offset:
54 # CHECK-NEXT: Opcode: I32_CONST
55 # CHECK-NEXT: Value: 4
56 # CHECK-NEXT: Content: '10001000'
62 # CHECK-NEXT: Opcode: I32_CONST
63 # CHECK-NEXT: Value: 4
64 # CHECK-NEXT: Content: '10001000'
65 # CHECK-NEXT: - SectionOffset: 12
66 # CHECK-NEXT: InitFlags: 1
67 # CHECK-NEXT: Content: '01010101'
68 # CHECK-NEXT: - SectionOffset: 22
69 # CHECK-NEXT: InitFlags: 2
70 # CHECK-NEXT: MemoryIndex: 0
71 # CHECK-NEXT: Offset:
72 # CHECK-NEXT: Opcode: I32_CONST
73 # CHECK-NEXT: Value: 8
74 # CHECK-NEXT: Content: '00110011'
5775 # CHECK-NEXT: - Type: CUSTOM
1616 SigIndex: 0
1717 - Type: DATA
1818 Segments:
19 - MemoryIndex: 0
19 - InitFlags: 0
2020 Offset:
2121 Opcode: I32_CONST
2222 Value: 4
2323 Content: '10001000'
24 - MemoryIndex: 0
24 - InitFlags: 0
2525 Offset:
2626 Opcode: I32_CONST
2727 Value: 8
2929 - Type: DATA
3030 Segments:
3131 - SectionOffset: 6
32 MemoryIndex: 0
32 InitFlags: 0
3333 Offset:
3434 Opcode: I32_CONST
3535 Value: 0
None ; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown -o %t.o %s
0 ; RUN: llc -filetype=obj -thread-model=single -mtriple=wasm32-unknown-unknown -o %t.o %s
11 ; RUN: llvm-nm %t.o | FileCheck %s
22
33 @foo = internal global i32 1, align 4
3535 - Type: DATA
3636 Segments:
3737 - SectionOffset: 6
38 MemoryIndex: 0
38 InitFlags: 0
3939 Offset:
4040 Opcode: I32_CONST
4141 Value: 0
None ; RUN: llc -mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s
0 ; RUN: llc -thread-model=single -mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s
11
22 @foo = external global i32, align 4
33 @bar = global i32* @foo, align 4
9292 SegmentInfo.Name = Segment.Data.Name;
9393 SegmentInfo.Index = SegmentIndex;
9494 SegmentInfo.Alignment = Segment.Data.Alignment;
95 SegmentInfo.Flags = Segment.Data.Flags;
95 SegmentInfo.Flags = Segment.Data.LinkerFlags;
9696 LinkingSec->SegmentInfos.push_back(SegmentInfo);
9797 }
9898 if (Segment.Data.Comdat != UINT32_MAX) {
333333 for (const object::WasmSegment &Segment : Obj.dataSegments()) {
334334 WasmYAML::DataSegment Seg;
335335 Seg.SectionOffset = Segment.SectionOffset;
336 Seg.InitFlags = Segment.Data.InitFlags;
336337 Seg.MemoryIndex = Segment.Data.MemoryIndex;
337338 Seg.Offset = Segment.Data.Offset;
338339 Seg.Content = yaml::BinaryRef(Segment.Data.Content);
486486 WasmYAML::DataSection &Section) {
487487 encodeULEB128(Section.Segments.size(), OS);
488488 for (auto &Segment : Section.Segments) {
489 encodeULEB128(Segment.MemoryIndex, OS);
490 writeInitExpr(Segment.Offset, OS);
489 encodeULEB128(Segment.InitFlags, OS);
490 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
491 encodeULEB128(Segment.MemoryIndex, OS);
492 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0)
493 writeInitExpr(Segment.Offset, OS);
491494 encodeULEB128(Segment.Content.binary_size(), OS);
492495 Segment.Content.writeAsBinary(OS);
493496 }