Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
WasmObjectFile.cpp
Go to the documentation of this file.
1//===- WasmObjectFile.cpp - Wasm object file implementation ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/ADT/ArrayRef.h"
10#include "llvm/ADT/DenseSet.h"
11#include "llvm/ADT/SmallSet.h"
12#include "llvm/ADT/StringRef.h"
13#include "llvm/ADT/StringSet.h"
14#include "llvm/ADT/StringSwitch.h"
15#include "llvm/BinaryFormat/Wasm.h"
16#include "llvm/Object/Binary.h"
17#include "llvm/Object/Error.h"
18#include "llvm/Object/ObjectFile.h"
19#include "llvm/Object/SymbolicFile.h"
20#include "llvm/Object/Wasm.h"
21#include "llvm/Support/Endian.h"
22#include "llvm/Support/Error.h"
23#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/LEB128.h"
25#include "llvm/Support/ScopedPrinter.h"
26#include "llvm/TargetParser/SubtargetFeature.h"
27#include "llvm/TargetParser/Triple.h"
28#include <cassert>
29#include <cstdint>
30#include <cstring>
31
32#define DEBUG_TYPE "wasm-object"
33
34using namespacellvm;
35using namespaceobject;
36
37voidWasmSymbol::print(raw_ostream &Out) const{
38 Out <<"Name=" <<Info.Name
39 <<", Kind=" <<toString(wasm::WasmSymbolType(Info.Kind)) <<", Flags=0x"
40 <<Twine::utohexstr(Info.Flags) <<" [";
41switch (getBinding()) {
42casewasm::WASM_SYMBOL_BINDING_GLOBAL: Out <<"global";break;
43casewasm::WASM_SYMBOL_BINDING_LOCAL: Out <<"local";break;
44casewasm::WASM_SYMBOL_BINDING_WEAK: Out <<"weak";break;
45 }
46if (isHidden()) {
47 Out <<", hidden";
48 }else {
49 Out <<", default";
50 }
51 Out <<"]";
52if (!isTypeData()) {
53 Out <<", ElemIndex=" <<Info.ElementIndex;
54 }elseif (isDefined()) {
55 Out <<", Segment=" <<Info.DataRef.Segment;
56 Out <<", Offset=" <<Info.DataRef.Offset;
57 Out <<", Size=" <<Info.DataRef.Size;
58 }
59}
60
61#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
62LLVM_DUMP_METHODvoidWasmSymbol::dump() const{print(dbgs()); }
63#endif
64
65Expected<std::unique_ptr<WasmObjectFile>>
66ObjectFile::createWasmObjectFile(MemoryBufferRef Buffer) {
67Error Err =Error::success();
68autoObjectFile = std::make_unique<WasmObjectFile>(Buffer, Err);
69if (Err)
70return std::move(Err);
71
72return std::move(ObjectFile);
73}
74
75#define VARINT7_MAX ((1 << 7) - 1)
76#define VARINT7_MIN (-(1 << 7))
77#define VARUINT7_MAX (1 << 7)
78#define VARUINT1_MAX (1)
79
80staticuint8_treadUint8(WasmObjectFile::ReadContext &Ctx) {
81if (Ctx.Ptr == Ctx.End)
82report_fatal_error("EOF while reading uint8");
83return *Ctx.Ptr++;
84}
85
86staticuint32_treadUint32(WasmObjectFile::ReadContext &Ctx) {
87if (Ctx.Ptr + 4 > Ctx.End)
88report_fatal_error("EOF while reading uint32");
89uint32_t Result =support::endian::read32le(Ctx.Ptr);
90 Ctx.Ptr += 4;
91return Result;
92}
93
94static int32_treadFloat32(WasmObjectFile::ReadContext &Ctx) {
95if (Ctx.Ptr + 4 > Ctx.End)
96report_fatal_error("EOF while reading float64");
97 int32_t Result = 0;
98 memcpy(&Result, Ctx.Ptr,sizeof(Result));
99 Ctx.Ptr +=sizeof(Result);
100return Result;
101}
102
103static int64_treadFloat64(WasmObjectFile::ReadContext &Ctx) {
104if (Ctx.Ptr + 8 > Ctx.End)
105report_fatal_error("EOF while reading float64");
106 int64_t Result = 0;
107 memcpy(&Result, Ctx.Ptr,sizeof(Result));
108 Ctx.Ptr +=sizeof(Result);
109return Result;
110}
111
112staticuint64_treadULEB128(WasmObjectFile::ReadContext &Ctx) {
113unsigned Count;
114constchar *Error =nullptr;
115uint64_t Result =decodeULEB128(Ctx.Ptr, &Count, Ctx.End, &Error);
116if (Error)
117report_fatal_error(Error);
118 Ctx.Ptr += Count;
119return Result;
120}
121
122staticStringRefreadString(WasmObjectFile::ReadContext &Ctx) {
123uint32_t StringLen =readULEB128(Ctx);
124if (Ctx.Ptr + StringLen > Ctx.End)
125report_fatal_error("EOF while reading string");
126StringRef Return =
127StringRef(reinterpret_cast<constchar *>(Ctx.Ptr), StringLen);
128 Ctx.Ptr += StringLen;
129return Return;
130}
131
132static int64_treadLEB128(WasmObjectFile::ReadContext &Ctx) {
133unsigned Count;
134constchar *Error =nullptr;
135uint64_t Result =decodeSLEB128(Ctx.Ptr, &Count, Ctx.End, &Error);
136if (Error)
137report_fatal_error(Error);
138 Ctx.Ptr += Count;
139return Result;
140}
141
142staticuint8_treadVaruint1(WasmObjectFile::ReadContext &Ctx) {
143 int64_t Result =readLEB128(Ctx);
144if (Result >VARUINT1_MAX || Result < 0)
145report_fatal_error("LEB is outside Varuint1 range");
146return Result;
147}
148
149static int32_treadVarint32(WasmObjectFile::ReadContext &Ctx) {
150 int64_t Result =readLEB128(Ctx);
151if (Result > INT32_MAX || Result < INT32_MIN)
152report_fatal_error("LEB is outside Varint32 range");
153return Result;
154}
155
156staticuint32_treadVaruint32(WasmObjectFile::ReadContext &Ctx) {
157uint64_t Result =readULEB128(Ctx);
158if (Result > UINT32_MAX)
159report_fatal_error("LEB is outside Varuint32 range");
160return Result;
161}
162
163static int64_treadVarint64(WasmObjectFile::ReadContext &Ctx) {
164returnreadLEB128(Ctx);
165}
166
167staticuint64_treadVaruint64(WasmObjectFile::ReadContext &Ctx) {
168returnreadULEB128(Ctx);
169}
170
171staticuint8_treadOpcode(WasmObjectFile::ReadContext &Ctx) {
172returnreadUint8(Ctx);
173}
174
175staticwasm::ValTypeparseValType(WasmObjectFile::ReadContext &Ctx,
176uint32_t Code) {
177// only directly encoded FUNCREF/EXTERNREF/EXNREF are supported
178// (not ref null func, ref null extern, or ref null exn)
179switch (Code) {
180casewasm::WASM_TYPE_I32:
181casewasm::WASM_TYPE_I64:
182casewasm::WASM_TYPE_F32:
183casewasm::WASM_TYPE_F64:
184casewasm::WASM_TYPE_V128:
185casewasm::WASM_TYPE_FUNCREF:
186casewasm::WASM_TYPE_EXTERNREF:
187casewasm::WASM_TYPE_EXNREF:
188returnwasm::ValType(Code);
189 }
190if (Code ==wasm::WASM_TYPE_NULLABLE || Code ==wasm::WASM_TYPE_NONNULLABLE) {
191/* Discard HeapType */readVarint64(Ctx);
192 }
193returnwasm::ValType(wasm::ValType::OTHERREF);
194}
195
196staticErrorreadInitExpr(wasm::WasmInitExpr &Expr,
197WasmObjectFile::ReadContext &Ctx) {
198auto Start = Ctx.Ptr;
199
200 Expr.Extended =false;
201 Expr.Inst.Opcode =readOpcode(Ctx);
202switch (Expr.Inst.Opcode) {
203casewasm::WASM_OPCODE_I32_CONST:
204 Expr.Inst.Value.Int32 =readVarint32(Ctx);
205break;
206casewasm::WASM_OPCODE_I64_CONST:
207 Expr.Inst.Value.Int64 =readVarint64(Ctx);
208break;
209casewasm::WASM_OPCODE_F32_CONST:
210 Expr.Inst.Value.Float32 =readFloat32(Ctx);
211break;
212casewasm::WASM_OPCODE_F64_CONST:
213 Expr.Inst.Value.Float64 =readFloat64(Ctx);
214break;
215casewasm::WASM_OPCODE_GLOBAL_GET:
216 Expr.Inst.Value.Global =readULEB128(Ctx);
217break;
218casewasm::WASM_OPCODE_REF_NULL: {
219/* Discard type */parseValType(Ctx,readVaruint32(Ctx));
220break;
221 }
222default:
223 Expr.Extended =true;
224 }
225
226if (!Expr.Extended) {
227uint8_t EndOpcode =readOpcode(Ctx);
228if (EndOpcode !=wasm::WASM_OPCODE_END)
229 Expr.Extended =true;
230 }
231
232if (Expr.Extended) {
233 Ctx.Ptr = Start;
234while (true) {
235uint8_t Opcode =readOpcode(Ctx);
236switch (Opcode) {
237casewasm::WASM_OPCODE_I32_CONST:
238casewasm::WASM_OPCODE_GLOBAL_GET:
239casewasm::WASM_OPCODE_REF_NULL:
240casewasm::WASM_OPCODE_REF_FUNC:
241casewasm::WASM_OPCODE_I64_CONST:
242readULEB128(Ctx);
243break;
244casewasm::WASM_OPCODE_F32_CONST:
245readFloat32(Ctx);
246break;
247casewasm::WASM_OPCODE_F64_CONST:
248readFloat64(Ctx);
249break;
250casewasm::WASM_OPCODE_I32_ADD:
251casewasm::WASM_OPCODE_I32_SUB:
252casewasm::WASM_OPCODE_I32_MUL:
253casewasm::WASM_OPCODE_I64_ADD:
254casewasm::WASM_OPCODE_I64_SUB:
255casewasm::WASM_OPCODE_I64_MUL:
256break;
257casewasm::WASM_OPCODE_GC_PREFIX:
258break;
259// The GC opcodes are in a separate (prefixed space). This flat switch
260// structure works as long as there is no overlap between the GC and
261// general opcodes used in init exprs.
262casewasm::WASM_OPCODE_STRUCT_NEW:
263casewasm::WASM_OPCODE_STRUCT_NEW_DEFAULT:
264casewasm::WASM_OPCODE_ARRAY_NEW:
265casewasm::WASM_OPCODE_ARRAY_NEW_DEFAULT:
266readULEB128(Ctx);// heap type index
267break;
268casewasm::WASM_OPCODE_ARRAY_NEW_FIXED:
269readULEB128(Ctx);// heap type index
270readULEB128(Ctx);// array size
271break;
272casewasm::WASM_OPCODE_REF_I31:
273break;
274casewasm::WASM_OPCODE_END:
275 Expr.Body =ArrayRef<uint8_t>(Start, Ctx.Ptr - Start);
276returnError::success();
277default:
278return make_error<GenericBinaryError>(
279Twine("invalid opcode in init_expr: ") +Twine(unsigned(Opcode)),
280object_error::parse_failed);
281 }
282 }
283 }
284
285returnError::success();
286}
287
288staticwasm::WasmLimitsreadLimits(WasmObjectFile::ReadContext &Ctx) {
289wasm::WasmLimits Result;
290 Result.Flags =readVaruint32(Ctx);
291 Result.Minimum =readVaruint64(Ctx);
292if (Result.Flags &wasm::WASM_LIMITS_FLAG_HAS_MAX)
293 Result.Maximum =readVaruint64(Ctx);
294return Result;
295}
296
297staticwasm::WasmTableTypereadTableType(WasmObjectFile::ReadContext &Ctx) {
298wasm::WasmTableType TableType;
299auto ElemType =parseValType(Ctx,readVaruint32(Ctx));
300 TableType.ElemType = ElemType;
301 TableType.Limits =readLimits(Ctx);
302return TableType;
303}
304
305staticErrorreadSection(WasmSection &Section,WasmObjectFile::ReadContext &Ctx,
306WasmSectionOrderChecker &Checker) {
307 Section.Type =readUint8(Ctx);
308LLVM_DEBUG(dbgs() <<"readSection type=" << Section.Type <<"\n");
309// When reading the section's size, store the size of the LEB used to encode
310// it. This allows objcopy/strip to reproduce the binary identically.
311constuint8_t *PreSizePtr = Ctx.Ptr;
312uint32_tSize =readVaruint32(Ctx);
313 Section.HeaderSecSizeEncodingLen = Ctx.Ptr - PreSizePtr;
314 Section.Offset = Ctx.Ptr - Ctx.Start;
315if (Size == 0)
316return make_error<StringError>("zero length section",
317object_error::parse_failed);
318if (Ctx.Ptr +Size > Ctx.End)
319return make_error<StringError>("section too large",
320object_error::parse_failed);
321if (Section.Type ==wasm::WASM_SEC_CUSTOM) {
322WasmObjectFile::ReadContext SectionCtx;
323 SectionCtx.Start = Ctx.Ptr;
324 SectionCtx.Ptr = Ctx.Ptr;
325 SectionCtx.End = Ctx.Ptr +Size;
326
327 Section.Name =readString(SectionCtx);
328
329uint32_t SectionNameSize = SectionCtx.Ptr - SectionCtx.Start;
330 Ctx.Ptr += SectionNameSize;
331Size -= SectionNameSize;
332 }
333
334if (!Checker.isValidSectionOrder(Section.Type, Section.Name)) {
335return make_error<StringError>("out of order section type: " +
336llvm::to_string(Section.Type),
337object_error::parse_failed);
338 }
339
340 Section.Content =ArrayRef<uint8_t>(Ctx.Ptr,Size);
341 Ctx.Ptr +=Size;
342returnError::success();
343}
344
345WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer,Error &Err)
346 :ObjectFile(Binary::ID_Wasm, Buffer) {
347ErrorAsOutParameter ErrAsOutParam(Err);
348 Header.Magic =getData().substr(0, 4);
349if (Header.Magic !=StringRef("\0asm", 4)) {
350 Err = make_error<StringError>("invalid magic number",
351object_error::parse_failed);
352return;
353 }
354
355ReadContext Ctx;
356 Ctx.Start =getData().bytes_begin();
357 Ctx.Ptr = Ctx.Start + 4;
358 Ctx.End = Ctx.Start +getData().size();
359
360if (Ctx.Ptr + 4 > Ctx.End) {
361 Err = make_error<StringError>("missing version number",
362object_error::parse_failed);
363return;
364 }
365
366 Header.Version =readUint32(Ctx);
367if (Header.Version !=wasm::WasmVersion) {
368 Err = make_error<StringError>("invalid version number: " +
369Twine(Header.Version),
370object_error::parse_failed);
371return;
372 }
373
374WasmSectionOrderChecker Checker;
375while (Ctx.Ptr < Ctx.End) {
376WasmSection Sec;
377if ((Err =readSection(Sec, Ctx, Checker)))
378return;
379if ((Err = parseSection(Sec)))
380return;
381
382 Sections.push_back(Sec);
383 }
384}
385
386Error WasmObjectFile::parseSection(WasmSection &Sec) {
387 ReadContext Ctx;
388 Ctx.Start = Sec.Content.data();
389 Ctx.End = Ctx.Start + Sec.Content.size();
390 Ctx.Ptr = Ctx.Start;
391switch (Sec.Type) {
392casewasm::WASM_SEC_CUSTOM:
393return parseCustomSection(Sec, Ctx);
394casewasm::WASM_SEC_TYPE:
395return parseTypeSection(Ctx);
396casewasm::WASM_SEC_IMPORT:
397return parseImportSection(Ctx);
398casewasm::WASM_SEC_FUNCTION:
399return parseFunctionSection(Ctx);
400casewasm::WASM_SEC_TABLE:
401return parseTableSection(Ctx);
402casewasm::WASM_SEC_MEMORY:
403return parseMemorySection(Ctx);
404casewasm::WASM_SEC_TAG:
405return parseTagSection(Ctx);
406casewasm::WASM_SEC_GLOBAL:
407return parseGlobalSection(Ctx);
408casewasm::WASM_SEC_EXPORT:
409return parseExportSection(Ctx);
410casewasm::WASM_SEC_START:
411return parseStartSection(Ctx);
412casewasm::WASM_SEC_ELEM:
413return parseElemSection(Ctx);
414casewasm::WASM_SEC_CODE:
415return parseCodeSection(Ctx);
416casewasm::WASM_SEC_DATA:
417return parseDataSection(Ctx);
418casewasm::WASM_SEC_DATACOUNT:
419return parseDataCountSection(Ctx);
420default:
421return make_error<GenericBinaryError>(
422"invalid section type: " +Twine(Sec.Type),object_error::parse_failed);
423 }
424}
425
426Error WasmObjectFile::parseDylinkSection(ReadContext &Ctx) {
427// Legacy "dylink" section support.
428// See parseDylink0Section for the current "dylink.0" section parsing.
429 HasDylinkSection =true;
430 DylinkInfo.MemorySize =readVaruint32(Ctx);
431 DylinkInfo.MemoryAlignment =readVaruint32(Ctx);
432 DylinkInfo.TableSize =readVaruint32(Ctx);
433 DylinkInfo.TableAlignment =readVaruint32(Ctx);
434uint32_t Count =readVaruint32(Ctx);
435while (Count--) {
436 DylinkInfo.Needed.push_back(readString(Ctx));
437 }
438
439if (Ctx.Ptr != Ctx.End)
440return make_error<GenericBinaryError>("dylink section ended prematurely",
441object_error::parse_failed);
442returnError::success();
443}
444
445Error WasmObjectFile::parseDylink0Section(ReadContext &Ctx) {
446// See
447// https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md
448 HasDylinkSection =true;
449
450constuint8_t *OrigEnd = Ctx.End;
451while (Ctx.Ptr < OrigEnd) {
452 Ctx.End = OrigEnd;
453uint8_tType =readUint8(Ctx);
454uint32_tSize =readVaruint32(Ctx);
455LLVM_DEBUG(dbgs() <<"readSubsection type=" <<int(Type) <<" size=" <<Size
456 <<"\n");
457 Ctx.End = Ctx.Ptr +Size;
458uint32_t Count;
459switch (Type) {
460casewasm::WASM_DYLINK_MEM_INFO:
461 DylinkInfo.MemorySize =readVaruint32(Ctx);
462 DylinkInfo.MemoryAlignment =readVaruint32(Ctx);
463 DylinkInfo.TableSize =readVaruint32(Ctx);
464 DylinkInfo.TableAlignment =readVaruint32(Ctx);
465break;
466casewasm::WASM_DYLINK_NEEDED:
467 Count =readVaruint32(Ctx);
468while (Count--) {
469 DylinkInfo.Needed.push_back(readString(Ctx));
470 }
471break;
472casewasm::WASM_DYLINK_EXPORT_INFO: {
473uint32_t Count =readVaruint32(Ctx);
474while (Count--) {
475 DylinkInfo.ExportInfo.push_back({readString(Ctx),readVaruint32(Ctx)});
476 }
477break;
478 }
479casewasm::WASM_DYLINK_IMPORT_INFO: {
480uint32_t Count =readVaruint32(Ctx);
481while (Count--) {
482 DylinkInfo.ImportInfo.push_back(
483 {readString(Ctx),readString(Ctx),readVaruint32(Ctx)});
484 }
485break;
486 }
487default:
488LLVM_DEBUG(dbgs() <<"unknown dylink.0 sub-section: " <<Type <<"\n");
489 Ctx.Ptr +=Size;
490break;
491 }
492if (Ctx.Ptr != Ctx.End) {
493return make_error<GenericBinaryError>(
494"dylink.0 sub-section ended prematurely",object_error::parse_failed);
495 }
496 }
497
498if (Ctx.Ptr != Ctx.End)
499return make_error<GenericBinaryError>("dylink.0 section ended prematurely",
500object_error::parse_failed);
501returnError::success();
502}
503
504Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
505llvm::DenseSet<uint64_t> SeenFunctions;
506llvm::DenseSet<uint64_t> SeenGlobals;
507llvm::DenseSet<uint64_t> SeenSegments;
508
509// If we have linking section (symbol table) or if we are parsing a DSO
510// then we don't use the name section for symbol information.
511bool PopulateSymbolTable = !HasLinkingSection && !HasDylinkSection;
512
513// If we are using the name section for symbol information then it will
514// supersede any symbols created by the export section.
515if (PopulateSymbolTable)
516 Symbols.clear();
517
518while (Ctx.Ptr < Ctx.End) {
519uint8_tType =readUint8(Ctx);
520uint32_tSize =readVaruint32(Ctx);
521constuint8_t *SubSectionEnd = Ctx.Ptr +Size;
522
523switch (Type) {
524casewasm::WASM_NAMES_FUNCTION:
525casewasm::WASM_NAMES_GLOBAL:
526casewasm::WASM_NAMES_DATA_SEGMENT: {
527uint32_t Count =readVaruint32(Ctx);
528while (Count--) {
529uint32_tIndex =readVaruint32(Ctx);
530StringRefName =readString(Ctx);
531wasm::NameType nameType =wasm::NameType::FUNCTION;
532wasm::WasmSymbolInfoInfo{Name,
533/*Kind */wasm::WASM_SYMBOL_TYPE_FUNCTION,
534/* Flags */ 0,
535/* ImportModule */ std::nullopt,
536/* ImportName */ std::nullopt,
537/* ExportName */ std::nullopt,
538 {/* ElementIndex */Index}};
539constwasm::WasmSignature *Signature =nullptr;
540constwasm::WasmGlobalType *GlobalType =nullptr;
541constwasm::WasmTableType *TableType =nullptr;
542if (Type ==wasm::WASM_NAMES_FUNCTION) {
543if (!SeenFunctions.insert(Index).second)
544return make_error<GenericBinaryError>(
545"function named more than once",object_error::parse_failed);
546if (!isValidFunctionIndex(Index) ||Name.empty())
547return make_error<GenericBinaryError>("invalid function name entry",
548object_error::parse_failed);
549
550if (isDefinedFunctionIndex(Index)) {
551wasm::WasmFunction &F = getDefinedFunction(Index);
552F.DebugName =Name;
553 Signature = &Signatures[F.SigIndex];
554if (F.ExportName) {
555Info.ExportName =F.ExportName;
556Info.Flags |=wasm::WASM_SYMBOL_BINDING_GLOBAL;
557 }else {
558Info.Flags |=wasm::WASM_SYMBOL_BINDING_LOCAL;
559 }
560 }else {
561Info.Flags |=wasm::WASM_SYMBOL_UNDEFINED;
562 }
563 }elseif (Type ==wasm::WASM_NAMES_GLOBAL) {
564if (!SeenGlobals.insert(Index).second)
565return make_error<GenericBinaryError>("global named more than once",
566object_error::parse_failed);
567if (!isValidGlobalIndex(Index) ||Name.empty())
568return make_error<GenericBinaryError>("invalid global name entry",
569object_error::parse_failed);
570 nameType =wasm::NameType::GLOBAL;
571Info.Kind =wasm::WASM_SYMBOL_TYPE_GLOBAL;
572if (isDefinedGlobalIndex(Index)) {
573 GlobalType = &getDefinedGlobal(Index).Type;
574 }else {
575Info.Flags |=wasm::WASM_SYMBOL_UNDEFINED;
576 }
577 }else {
578if (!SeenSegments.insert(Index).second)
579return make_error<GenericBinaryError>(
580"segment named more than once",object_error::parse_failed);
581if (Index > DataSegments.size())
582return make_error<GenericBinaryError>("invalid data segment name entry",
583object_error::parse_failed);
584 nameType =wasm::NameType::DATA_SEGMENT;
585Info.Kind =wasm::WASM_SYMBOL_TYPE_DATA;
586Info.Flags |=wasm::WASM_SYMBOL_BINDING_LOCAL;
587assert(Index < DataSegments.size());
588Info.DataRef =wasm::WasmDataReference{
589Index, 0, DataSegments[Index].Data.Content.size()};
590 }
591 DebugNames.push_back(wasm::WasmDebugName{nameType,Index,Name});
592if (PopulateSymbolTable)
593 Symbols.emplace_back(Info, GlobalType, TableType, Signature);
594 }
595break;
596 }
597// Ignore local names for now
598casewasm::WASM_NAMES_LOCAL:
599default:
600 Ctx.Ptr +=Size;
601break;
602 }
603if (Ctx.Ptr != SubSectionEnd)
604return make_error<GenericBinaryError>(
605"name sub-section ended prematurely",object_error::parse_failed);
606 }
607
608if (Ctx.Ptr != Ctx.End)
609return make_error<GenericBinaryError>("name section ended prematurely",
610object_error::parse_failed);
611returnError::success();
612}
613
614Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) {
615 HasLinkingSection =true;
616
617 LinkingData.Version =readVaruint32(Ctx);
618if (LinkingData.Version !=wasm::WasmMetadataVersion) {
619return make_error<GenericBinaryError>(
620"unexpected metadata version: " +Twine(LinkingData.Version) +
621" (Expected: " +Twine(wasm::WasmMetadataVersion) +")",
622object_error::parse_failed);
623 }
624
625constuint8_t *OrigEnd = Ctx.End;
626while (Ctx.Ptr < OrigEnd) {
627 Ctx.End = OrigEnd;
628uint8_tType =readUint8(Ctx);
629uint32_tSize =readVaruint32(Ctx);
630LLVM_DEBUG(dbgs() <<"readSubsection type=" <<int(Type) <<" size=" <<Size
631 <<"\n");
632 Ctx.End = Ctx.Ptr +Size;
633switch (Type) {
634casewasm::WASM_SYMBOL_TABLE:
635if (Error Err = parseLinkingSectionSymtab(Ctx))
636return Err;
637break;
638casewasm::WASM_SEGMENT_INFO: {
639uint32_t Count =readVaruint32(Ctx);
640if (Count > DataSegments.size())
641return make_error<GenericBinaryError>("too many segment names",
642object_error::parse_failed);
643for (uint32_tI = 0;I < Count;I++) {
644 DataSegments[I].Data.Name =readString(Ctx);
645 DataSegments[I].Data.Alignment =readVaruint32(Ctx);
646 DataSegments[I].Data.LinkingFlags =readVaruint32(Ctx);
647 }
648break;
649 }
650casewasm::WASM_INIT_FUNCS: {
651uint32_t Count =readVaruint32(Ctx);
652 LinkingData.InitFunctions.reserve(Count);
653for (uint32_tI = 0;I < Count;I++) {
654wasm::WasmInitFuncInit;
655Init.Priority =readVaruint32(Ctx);
656Init.Symbol =readVaruint32(Ctx);
657if (!isValidFunctionSymbol(Init.Symbol))
658return make_error<GenericBinaryError>("invalid function symbol: " +
659Twine(Init.Symbol),
660object_error::parse_failed);
661 LinkingData.InitFunctions.emplace_back(Init);
662 }
663break;
664 }
665casewasm::WASM_COMDAT_INFO:
666if (Error Err = parseLinkingSectionComdat(Ctx))
667return Err;
668break;
669default:
670 Ctx.Ptr +=Size;
671break;
672 }
673if (Ctx.Ptr != Ctx.End)
674return make_error<GenericBinaryError>(
675"linking sub-section ended prematurely",object_error::parse_failed);
676 }
677if (Ctx.Ptr != OrigEnd)
678return make_error<GenericBinaryError>("linking section ended prematurely",
679object_error::parse_failed);
680returnError::success();
681}
682
683Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
684uint32_t Count =readVaruint32(Ctx);
685// Clear out any symbol information that was derived from the exports
686// section.
687 Symbols.clear();
688 Symbols.reserve(Count);
689StringSet<> SymbolNames;
690
691 std::vector<wasm::WasmImport *> ImportedGlobals;
692 std::vector<wasm::WasmImport *> ImportedFunctions;
693 std::vector<wasm::WasmImport *> ImportedTags;
694 std::vector<wasm::WasmImport *> ImportedTables;
695 ImportedGlobals.reserve(Imports.size());
696 ImportedFunctions.reserve(Imports.size());
697 ImportedTags.reserve(Imports.size());
698 ImportedTables.reserve(Imports.size());
699for (auto &I : Imports) {
700if (I.Kind ==wasm::WASM_EXTERNAL_FUNCTION)
701 ImportedFunctions.emplace_back(&I);
702elseif (I.Kind ==wasm::WASM_EXTERNAL_GLOBAL)
703 ImportedGlobals.emplace_back(&I);
704elseif (I.Kind ==wasm::WASM_EXTERNAL_TAG)
705 ImportedTags.emplace_back(&I);
706elseif (I.Kind ==wasm::WASM_EXTERNAL_TABLE)
707 ImportedTables.emplace_back(&I);
708 }
709
710while (Count--) {
711wasm::WasmSymbolInfoInfo;
712constwasm::WasmSignature *Signature =nullptr;
713constwasm::WasmGlobalType *GlobalType =nullptr;
714constwasm::WasmTableType *TableType =nullptr;
715
716Info.Kind =readUint8(Ctx);
717Info.Flags =readVaruint32(Ctx);
718bool IsDefined = (Info.Flags &wasm::WASM_SYMBOL_UNDEFINED) == 0;
719
720switch (Info.Kind) {
721casewasm::WASM_SYMBOL_TYPE_FUNCTION:
722Info.ElementIndex =readVaruint32(Ctx);
723if (!isValidFunctionIndex(Info.ElementIndex) ||
724 IsDefined != isDefinedFunctionIndex(Info.ElementIndex))
725return make_error<GenericBinaryError>("invalid function symbol index",
726object_error::parse_failed);
727if (IsDefined) {
728Info.Name =readString(Ctx);
729unsigned FuncIndex =Info.ElementIndex - NumImportedFunctions;
730wasm::WasmFunction &Function = Functions[FuncIndex];
731 Signature = &Signatures[Function.SigIndex];
732if (Function.SymbolName.empty())
733Function.SymbolName =Info.Name;
734 }else {
735wasm::WasmImport &Import = *ImportedFunctions[Info.ElementIndex];
736if ((Info.Flags &wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0) {
737Info.Name =readString(Ctx);
738Info.ImportName =Import.Field;
739 }else {
740Info.Name =Import.Field;
741 }
742 Signature = &Signatures[Import.SigIndex];
743Info.ImportModule =Import.Module;
744 }
745break;
746
747casewasm::WASM_SYMBOL_TYPE_GLOBAL:
748Info.ElementIndex =readVaruint32(Ctx);
749if (!isValidGlobalIndex(Info.ElementIndex) ||
750 IsDefined != isDefinedGlobalIndex(Info.ElementIndex))
751return make_error<GenericBinaryError>("invalid global symbol index",
752object_error::parse_failed);
753if (!IsDefined && (Info.Flags &wasm::WASM_SYMBOL_BINDING_MASK) ==
754wasm::WASM_SYMBOL_BINDING_WEAK)
755return make_error<GenericBinaryError>("undefined weak global symbol",
756object_error::parse_failed);
757if (IsDefined) {
758Info.Name =readString(Ctx);
759unsigned GlobalIndex =Info.ElementIndex - NumImportedGlobals;
760wasm::WasmGlobal &Global = Globals[GlobalIndex];
761 GlobalType = &Global.Type;
762if (Global.SymbolName.empty())
763Global.SymbolName =Info.Name;
764 }else {
765wasm::WasmImport &Import = *ImportedGlobals[Info.ElementIndex];
766if ((Info.Flags &wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0) {
767Info.Name =readString(Ctx);
768Info.ImportName =Import.Field;
769 }else {
770Info.Name =Import.Field;
771 }
772 GlobalType = &Import.Global;
773Info.ImportModule =Import.Module;
774 }
775break;
776
777casewasm::WASM_SYMBOL_TYPE_TABLE:
778Info.ElementIndex =readVaruint32(Ctx);
779if (!isValidTableNumber(Info.ElementIndex) ||
780 IsDefined != isDefinedTableNumber(Info.ElementIndex))
781return make_error<GenericBinaryError>("invalid table symbol index",
782object_error::parse_failed);
783if (!IsDefined && (Info.Flags &wasm::WASM_SYMBOL_BINDING_MASK) ==
784wasm::WASM_SYMBOL_BINDING_WEAK)
785return make_error<GenericBinaryError>("undefined weak table symbol",
786object_error::parse_failed);
787if (IsDefined) {
788Info.Name =readString(Ctx);
789unsigned TableNumber =Info.ElementIndex - NumImportedTables;
790wasm::WasmTable &Table = Tables[TableNumber];
791 TableType = &Table.Type;
792if (Table.SymbolName.empty())
793 Table.SymbolName =Info.Name;
794 }else {
795wasm::WasmImport &Import = *ImportedTables[Info.ElementIndex];
796if ((Info.Flags &wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0) {
797Info.Name =readString(Ctx);
798Info.ImportName =Import.Field;
799 }else {
800Info.Name =Import.Field;
801 }
802 TableType = &Import.Table;
803Info.ImportModule =Import.Module;
804 }
805break;
806
807casewasm::WASM_SYMBOL_TYPE_DATA:
808Info.Name =readString(Ctx);
809if (IsDefined) {
810autoIndex =readVaruint32(Ctx);
811autoOffset =readVaruint64(Ctx);
812autoSize =readVaruint64(Ctx);
813if (!(Info.Flags &wasm::WASM_SYMBOL_ABSOLUTE)) {
814if (static_cast<size_t>(Index) >= DataSegments.size())
815return make_error<GenericBinaryError>(
816"invalid data segment index: " +Twine(Index),
817object_error::parse_failed);
818size_t SegmentSize = DataSegments[Index].Data.Content.size();
819if (Offset > SegmentSize)
820return make_error<GenericBinaryError>(
821"invalid data symbol offset: `" +Info.Name +
822"` (offset: " +Twine(Offset) +
823" segment size: " +Twine(SegmentSize) +")",
824object_error::parse_failed);
825 }
826Info.DataRef =wasm::WasmDataReference{Index,Offset,Size};
827 }
828break;
829
830casewasm::WASM_SYMBOL_TYPE_SECTION: {
831if ((Info.Flags &wasm::WASM_SYMBOL_BINDING_MASK) !=
832wasm::WASM_SYMBOL_BINDING_LOCAL)
833return make_error<GenericBinaryError>(
834"section symbols must have local binding",
835object_error::parse_failed);
836Info.ElementIndex =readVaruint32(Ctx);
837// Use somewhat unique section name as symbol name.
838StringRefSectionName = Sections[Info.ElementIndex].Name;
839Info.Name =SectionName;
840break;
841 }
842
843casewasm::WASM_SYMBOL_TYPE_TAG: {
844Info.ElementIndex =readVaruint32(Ctx);
845if (!isValidTagIndex(Info.ElementIndex) ||
846 IsDefined != isDefinedTagIndex(Info.ElementIndex))
847return make_error<GenericBinaryError>("invalid tag symbol index",
848object_error::parse_failed);
849if (!IsDefined && (Info.Flags &wasm::WASM_SYMBOL_BINDING_MASK) ==
850wasm::WASM_SYMBOL_BINDING_WEAK)
851return make_error<GenericBinaryError>("undefined weak global symbol",
852object_error::parse_failed);
853if (IsDefined) {
854Info.Name =readString(Ctx);
855unsigned TagIndex =Info.ElementIndex - NumImportedTags;
856wasm::WasmTag &Tag = Tags[TagIndex];
857 Signature = &Signatures[Tag.SigIndex];
858if (Tag.SymbolName.empty())
859Tag.SymbolName =Info.Name;
860
861 }else {
862wasm::WasmImport &Import = *ImportedTags[Info.ElementIndex];
863if ((Info.Flags &wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0) {
864Info.Name =readString(Ctx);
865Info.ImportName =Import.Field;
866 }else {
867Info.Name =Import.Field;
868 }
869 Signature = &Signatures[Import.SigIndex];
870Info.ImportModule =Import.Module;
871 }
872break;
873 }
874
875default:
876return make_error<GenericBinaryError>("invalid symbol type: " +
877Twine(unsigned(Info.Kind)),
878object_error::parse_failed);
879 }
880
881if ((Info.Flags &wasm::WASM_SYMBOL_BINDING_MASK) !=
882wasm::WASM_SYMBOL_BINDING_LOCAL &&
883 !SymbolNames.insert(Info.Name).second)
884return make_error<GenericBinaryError>("duplicate symbol name " +
885Twine(Info.Name),
886object_error::parse_failed);
887 Symbols.emplace_back(Info, GlobalType, TableType, Signature);
888LLVM_DEBUG(dbgs() <<"Adding symbol: " << Symbols.back() <<"\n");
889 }
890
891returnError::success();
892}
893
894Error WasmObjectFile::parseLinkingSectionComdat(ReadContext &Ctx) {
895uint32_t ComdatCount =readVaruint32(Ctx);
896StringSet<> ComdatSet;
897for (unsigned ComdatIndex = 0; ComdatIndex < ComdatCount; ++ComdatIndex) {
898StringRefName =readString(Ctx);
899if (Name.empty() || !ComdatSet.insert(Name).second)
900return make_error<GenericBinaryError>("bad/duplicate COMDAT name " +
901Twine(Name),
902object_error::parse_failed);
903 LinkingData.Comdats.emplace_back(Name);
904uint32_tFlags =readVaruint32(Ctx);
905if (Flags != 0)
906return make_error<GenericBinaryError>("unsupported COMDAT flags",
907object_error::parse_failed);
908
909uint32_t EntryCount =readVaruint32(Ctx);
910while (EntryCount--) {
911unsignedKind =readVaruint32(Ctx);
912unsignedIndex =readVaruint32(Ctx);
913switch (Kind) {
914default:
915return make_error<GenericBinaryError>("invalid COMDAT entry type",
916object_error::parse_failed);
917casewasm::WASM_COMDAT_DATA:
918if (Index >= DataSegments.size())
919return make_error<GenericBinaryError>(
920"COMDAT data index out of range",object_error::parse_failed);
921if (DataSegments[Index].Data.Comdat != UINT32_MAX)
922return make_error<GenericBinaryError>("data segment in two COMDATs",
923object_error::parse_failed);
924 DataSegments[Index].Data.Comdat = ComdatIndex;
925break;
926casewasm::WASM_COMDAT_FUNCTION:
927if (!isDefinedFunctionIndex(Index))
928return make_error<GenericBinaryError>(
929"COMDAT function index out of range",object_error::parse_failed);
930if (getDefinedFunction(Index).Comdat != UINT32_MAX)
931return make_error<GenericBinaryError>("function in two COMDATs",
932object_error::parse_failed);
933 getDefinedFunction(Index).Comdat = ComdatIndex;
934break;
935casewasm::WASM_COMDAT_SECTION:
936if (Index >= Sections.size())
937return make_error<GenericBinaryError>(
938"COMDAT section index out of range",object_error::parse_failed);
939if (Sections[Index].Type !=wasm::WASM_SEC_CUSTOM)
940return make_error<GenericBinaryError>(
941"non-custom section in a COMDAT",object_error::parse_failed);
942 Sections[Index].Comdat = ComdatIndex;
943break;
944 }
945 }
946 }
947returnError::success();
948}
949
950Error WasmObjectFile::parseProducersSection(ReadContext &Ctx) {
951llvm::SmallSet<StringRef, 3> FieldsSeen;
952uint32_t Fields =readVaruint32(Ctx);
953for (size_tI = 0;I < Fields; ++I) {
954StringRef FieldName =readString(Ctx);
955if (!FieldsSeen.insert(FieldName).second)
956return make_error<GenericBinaryError>(
957"producers section does not have unique fields",
958object_error::parse_failed);
959 std::vector<std::pair<std::string, std::string>> *ProducerVec =nullptr;
960if (FieldName =="language") {
961 ProducerVec = &ProducerInfo.Languages;
962 }elseif (FieldName =="processed-by") {
963 ProducerVec = &ProducerInfo.Tools;
964 }elseif (FieldName =="sdk") {
965 ProducerVec = &ProducerInfo.SDKs;
966 }else {
967return make_error<GenericBinaryError>(
968"producers section field is not named one of language, processed-by, "
969"or sdk",
970object_error::parse_failed);
971 }
972uint32_t ValueCount =readVaruint32(Ctx);
973llvm::SmallSet<StringRef, 8> ProducersSeen;
974for (size_t J = 0; J < ValueCount; ++J) {
975StringRefName =readString(Ctx);
976StringRefVersion =readString(Ctx);
977if (!ProducersSeen.insert(Name).second) {
978return make_error<GenericBinaryError>(
979"producers section contains repeated producer",
980object_error::parse_failed);
981 }
982 ProducerVec->emplace_back(std::string(Name), std::string(Version));
983 }
984 }
985if (Ctx.Ptr != Ctx.End)
986return make_error<GenericBinaryError>("producers section ended prematurely",
987object_error::parse_failed);
988returnError::success();
989}
990
991Error WasmObjectFile::parseTargetFeaturesSection(ReadContext &Ctx) {
992llvm::SmallSet<std::string, 8> FeaturesSeen;
993uint32_tFeatureCount =readVaruint32(Ctx);
994for (size_tI = 0;I <FeatureCount; ++I) {
995wasm::WasmFeatureEntry Feature;
996 Feature.Prefix =readUint8(Ctx);
997switch (Feature.Prefix) {
998casewasm::WASM_FEATURE_PREFIX_USED:
999casewasm::WASM_FEATURE_PREFIX_DISALLOWED:
1000break;
1001default:
1002return make_error<GenericBinaryError>("unknown feature policy prefix",
1003object_error::parse_failed);
1004 }
1005 Feature.Name = std::string(readString(Ctx));
1006if (!FeaturesSeen.insert(Feature.Name).second)
1007return make_error<GenericBinaryError>(
1008"target features section contains repeated feature \"" +
1009 Feature.Name +"\"",
1010object_error::parse_failed);
1011 TargetFeatures.push_back(Feature);
1012 }
1013if (Ctx.Ptr != Ctx.End)
1014return make_error<GenericBinaryError>(
1015"target features section ended prematurely",
1016object_error::parse_failed);
1017returnError::success();
1018}
1019
1020Error WasmObjectFile::parseRelocSection(StringRefName, ReadContext &Ctx) {
1021uint32_t SectionIndex =readVaruint32(Ctx);
1022if (SectionIndex >= Sections.size())
1023return make_error<GenericBinaryError>("invalid section index",
1024object_error::parse_failed);
1025WasmSection &Section = Sections[SectionIndex];
1026uint32_t RelocCount =readVaruint32(Ctx);
1027uint32_t EndOffset =Section.Content.size();
1028uint32_t PreviousOffset = 0;
1029while (RelocCount--) {
1030wasm::WasmRelocation Reloc = {};
1031uint32_t type =readVaruint32(Ctx);
1032 Reloc.Type = type;
1033 Reloc.Offset =readVaruint32(Ctx);
1034if (Reloc.Offset < PreviousOffset)
1035return make_error<GenericBinaryError>("relocations not in offset order",
1036object_error::parse_failed);
1037
1038auto badReloc = [&](StringRef msg) {
1039return make_error<GenericBinaryError>(
1040 msg +": " +Twine(Symbols[Reloc.Index].Info.Name),
1041object_error::parse_failed);
1042 };
1043
1044 PreviousOffset = Reloc.Offset;
1045 Reloc.Index =readVaruint32(Ctx);
1046switch (type) {
1047case wasm::R_WASM_FUNCTION_INDEX_LEB:
1048case wasm::R_WASM_FUNCTION_INDEX_I32:
1049case wasm::R_WASM_TABLE_INDEX_SLEB:
1050case wasm::R_WASM_TABLE_INDEX_SLEB64:
1051case wasm::R_WASM_TABLE_INDEX_I32:
1052case wasm::R_WASM_TABLE_INDEX_I64:
1053case wasm::R_WASM_TABLE_INDEX_REL_SLEB:
1054case wasm::R_WASM_TABLE_INDEX_REL_SLEB64:
1055if (!isValidFunctionSymbol(Reloc.Index))
1056return badReloc("invalid function relocation");
1057break;
1058case wasm::R_WASM_TABLE_NUMBER_LEB:
1059if (!isValidTableSymbol(Reloc.Index))
1060return badReloc("invalid table relocation");
1061break;
1062case wasm::R_WASM_TYPE_INDEX_LEB:
1063if (Reloc.Index >= Signatures.size())
1064return badReloc("invalid relocation type index");
1065break;
1066case wasm::R_WASM_GLOBAL_INDEX_LEB:
1067// R_WASM_GLOBAL_INDEX_LEB are can be used against function and data
1068// symbols to refer to their GOT entries.
1069if (!isValidGlobalSymbol(Reloc.Index) &&
1070 !isValidDataSymbol(Reloc.Index) &&
1071 !isValidFunctionSymbol(Reloc.Index))
1072return badReloc("invalid global relocation");
1073break;
1074case wasm::R_WASM_GLOBAL_INDEX_I32:
1075if (!isValidGlobalSymbol(Reloc.Index))
1076return badReloc("invalid global relocation");
1077break;
1078case wasm::R_WASM_TAG_INDEX_LEB:
1079if (!isValidTagSymbol(Reloc.Index))
1080return badReloc("invalid tag relocation");
1081break;
1082case wasm::R_WASM_MEMORY_ADDR_LEB:
1083case wasm::R_WASM_MEMORY_ADDR_SLEB:
1084case wasm::R_WASM_MEMORY_ADDR_I32:
1085case wasm::R_WASM_MEMORY_ADDR_REL_SLEB:
1086case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB:
1087case wasm::R_WASM_MEMORY_ADDR_LOCREL_I32:
1088if (!isValidDataSymbol(Reloc.Index))
1089return badReloc("invalid data relocation");
1090 Reloc.Addend =readVarint32(Ctx);
1091break;
1092case wasm::R_WASM_MEMORY_ADDR_LEB64:
1093case wasm::R_WASM_MEMORY_ADDR_SLEB64:
1094case wasm::R_WASM_MEMORY_ADDR_I64:
1095case wasm::R_WASM_MEMORY_ADDR_REL_SLEB64:
1096case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB64:
1097if (!isValidDataSymbol(Reloc.Index))
1098return badReloc("invalid data relocation");
1099 Reloc.Addend =readVarint64(Ctx);
1100break;
1101case wasm::R_WASM_FUNCTION_OFFSET_I32:
1102if (!isValidFunctionSymbol(Reloc.Index))
1103return badReloc("invalid function relocation");
1104 Reloc.Addend =readVarint32(Ctx);
1105break;
1106case wasm::R_WASM_FUNCTION_OFFSET_I64:
1107if (!isValidFunctionSymbol(Reloc.Index))
1108return badReloc("invalid function relocation");
1109 Reloc.Addend =readVarint64(Ctx);
1110break;
1111case wasm::R_WASM_SECTION_OFFSET_I32:
1112if (!isValidSectionSymbol(Reloc.Index))
1113return badReloc("invalid section relocation");
1114 Reloc.Addend =readVarint32(Ctx);
1115break;
1116default:
1117return make_error<GenericBinaryError>("invalid relocation type: " +
1118Twine(type),
1119object_error::parse_failed);
1120 }
1121
1122// Relocations must fit inside the section, and must appear in order. They
1123// also shouldn't overlap a function/element boundary, but we don't bother
1124// to check that.
1125uint64_tSize = 5;
1126if (Reloc.Type == wasm::R_WASM_MEMORY_ADDR_LEB64 ||
1127 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_SLEB64 ||
1128 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_REL_SLEB64)
1129Size = 10;
1130if (Reloc.Type == wasm::R_WASM_TABLE_INDEX_I32 ||
1131 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_I32 ||
1132 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_LOCREL_I32 ||
1133 Reloc.Type == wasm::R_WASM_SECTION_OFFSET_I32 ||
1134 Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I32 ||
1135 Reloc.Type == wasm::R_WASM_FUNCTION_INDEX_I32 ||
1136 Reloc.Type == wasm::R_WASM_GLOBAL_INDEX_I32)
1137Size = 4;
1138if (Reloc.Type == wasm::R_WASM_TABLE_INDEX_I64 ||
1139 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_I64 ||
1140 Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I64)
1141Size = 8;
1142if (Reloc.Offset +Size > EndOffset)
1143return make_error<GenericBinaryError>("invalid relocation offset",
1144object_error::parse_failed);
1145
1146Section.Relocations.push_back(Reloc);
1147 }
1148if (Ctx.Ptr != Ctx.End)
1149return make_error<GenericBinaryError>("reloc section ended prematurely",
1150object_error::parse_failed);
1151returnError::success();
1152}
1153
1154Error WasmObjectFile::parseCustomSection(WasmSection &Sec, ReadContext &Ctx) {
1155if (Sec.Name =="dylink") {
1156if (Error Err = parseDylinkSection(Ctx))
1157return Err;
1158 }elseif (Sec.Name =="dylink.0") {
1159if (Error Err = parseDylink0Section(Ctx))
1160return Err;
1161 }elseif (Sec.Name =="name") {
1162if (Error Err = parseNameSection(Ctx))
1163return Err;
1164 }elseif (Sec.Name =="linking") {
1165if (Error Err = parseLinkingSection(Ctx))
1166return Err;
1167 }elseif (Sec.Name =="producers") {
1168if (Error Err = parseProducersSection(Ctx))
1169return Err;
1170 }elseif (Sec.Name =="target_features") {
1171if (Error Err = parseTargetFeaturesSection(Ctx))
1172return Err;
1173 }elseif (Sec.Name.starts_with("reloc.")) {
1174if (Error Err = parseRelocSection(Sec.Name, Ctx))
1175return Err;
1176 }
1177returnError::success();
1178}
1179
1180Error WasmObjectFile::parseTypeSection(ReadContext &Ctx) {
1181auto parseFieldDef = [&]() {
1182uint32_t TypeCode =readVaruint32((Ctx));
1183/* Discard StorageType */parseValType(Ctx, TypeCode);
1184/* Discard Mutability */readVaruint32(Ctx);
1185 };
1186
1187uint32_t Count =readVaruint32(Ctx);
1188 Signatures.reserve(Count);
1189while (Count--) {
1190wasm::WasmSignature Sig;
1191uint8_tForm =readUint8(Ctx);
1192if (Form ==wasm::WASM_TYPE_REC) {
1193// Rec groups expand the type index space (beyond what was declared at
1194// the top of the section, and also consume one element in that space.
1195uint32_t RecSize =readVaruint32(Ctx);
1196if (RecSize == 0)
1197return make_error<GenericBinaryError>("Rec group size cannot be 0",
1198object_error::parse_failed);
1199 Signatures.reserve(Signatures.size() + RecSize);
1200 Count += RecSize;
1201 Sig.Kind =wasm::WasmSignature::Placeholder;
1202 Signatures.push_back(std::move(Sig));
1203 HasUnmodeledTypes =true;
1204continue;
1205 }
1206if (Form !=wasm::WASM_TYPE_FUNC) {
1207// Currently LLVM only models function types, and not other composite
1208// types. Here we parse the type declarations just enough to skip past
1209// them in the binary.
1210if (Form ==wasm::WASM_TYPE_SUB || Form ==wasm::WASM_TYPE_SUB_FINAL) {
1211uint32_t Supers =readVaruint32(Ctx);
1212if (Supers > 0) {
1213if (Supers != 1)
1214return make_error<GenericBinaryError>(
1215"Invalid number of supertypes",object_error::parse_failed);
1216/* Discard SuperIndex */readVaruint32(Ctx);
1217 }
1218Form =readVaruint32(Ctx);
1219 }
1220if (Form ==wasm::WASM_TYPE_STRUCT) {
1221uint32_t FieldCount =readVaruint32(Ctx);
1222while (FieldCount--) {
1223 parseFieldDef();
1224 }
1225 }elseif (Form ==wasm::WASM_TYPE_ARRAY) {
1226 parseFieldDef();
1227 }else {
1228return make_error<GenericBinaryError>("bad form",
1229object_error::parse_failed);
1230 }
1231 Sig.Kind =wasm::WasmSignature::Placeholder;
1232 Signatures.push_back(std::move(Sig));
1233 HasUnmodeledTypes =true;
1234continue;
1235 }
1236
1237uint32_t ParamCount =readVaruint32(Ctx);
1238 Sig.Params.reserve(ParamCount);
1239while (ParamCount--) {
1240uint32_t ParamType =readUint8(Ctx);
1241 Sig.Params.push_back(parseValType(Ctx, ParamType));
1242 }
1243uint32_t ReturnCount =readVaruint32(Ctx);
1244while (ReturnCount--) {
1245uint32_tReturnType =readUint8(Ctx);
1246 Sig.Returns.push_back(parseValType(Ctx, ReturnType));
1247 }
1248
1249 Signatures.push_back(std::move(Sig));
1250 }
1251if (Ctx.Ptr != Ctx.End)
1252return make_error<GenericBinaryError>("type section ended prematurely",
1253object_error::parse_failed);
1254returnError::success();
1255}
1256
1257Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
1258uint32_t Count =readVaruint32(Ctx);
1259uint32_t NumTypes = Signatures.size();
1260 Imports.reserve(Count);
1261for (uint32_tI = 0;I < Count;I++) {
1262wasm::WasmImport Im;
1263 Im.Module =readString(Ctx);
1264 Im.Field =readString(Ctx);
1265 Im.Kind =readUint8(Ctx);
1266switch (Im.Kind) {
1267casewasm::WASM_EXTERNAL_FUNCTION:
1268 NumImportedFunctions++;
1269 Im.SigIndex =readVaruint32(Ctx);
1270if (Im.SigIndex >= NumTypes)
1271return make_error<GenericBinaryError>("invalid function type",
1272object_error::parse_failed);
1273break;
1274casewasm::WASM_EXTERNAL_GLOBAL:
1275 NumImportedGlobals++;
1276 Im.Global.Type =readUint8(Ctx);
1277 Im.Global.Mutable =readVaruint1(Ctx);
1278break;
1279casewasm::WASM_EXTERNAL_MEMORY:
1280 Im.Memory =readLimits(Ctx);
1281if (Im.Memory.Flags &wasm::WASM_LIMITS_FLAG_IS_64)
1282 HasMemory64 =true;
1283break;
1284casewasm::WASM_EXTERNAL_TABLE: {
1285 Im.Table =readTableType(Ctx);
1286 NumImportedTables++;
1287auto ElemType = Im.Table.ElemType;
1288if (ElemType !=wasm::ValType::FUNCREF &&
1289 ElemType !=wasm::ValType::EXTERNREF &&
1290 ElemType !=wasm::ValType::EXNREF &&
1291 ElemType !=wasm::ValType::OTHERREF)
1292return make_error<GenericBinaryError>("invalid table element type",
1293object_error::parse_failed);
1294break;
1295 }
1296casewasm::WASM_EXTERNAL_TAG:
1297 NumImportedTags++;
1298if (readUint8(Ctx) != 0)// Reserved 'attribute' field
1299return make_error<GenericBinaryError>("invalid attribute",
1300object_error::parse_failed);
1301 Im.SigIndex =readVaruint32(Ctx);
1302if (Im.SigIndex >= NumTypes)
1303return make_error<GenericBinaryError>("invalid tag type",
1304object_error::parse_failed);
1305break;
1306default:
1307return make_error<GenericBinaryError>("unexpected import kind",
1308object_error::parse_failed);
1309 }
1310 Imports.push_back(Im);
1311 }
1312if (Ctx.Ptr != Ctx.End)
1313return make_error<GenericBinaryError>("import section ended prematurely",
1314object_error::parse_failed);
1315returnError::success();
1316}
1317
1318Error WasmObjectFile::parseFunctionSection(ReadContext &Ctx) {
1319uint32_t Count =readVaruint32(Ctx);
1320 Functions.reserve(Count);
1321uint32_t NumTypes = Signatures.size();
1322while (Count--) {
1323uint32_tType =readVaruint32(Ctx);
1324if (Type >= NumTypes)
1325return make_error<GenericBinaryError>("invalid function type",
1326object_error::parse_failed);
1327wasm::WasmFunctionF;
1328F.SigIndex =Type;
1329 Functions.push_back(F);
1330 }
1331if (Ctx.Ptr != Ctx.End)
1332return make_error<GenericBinaryError>("function section ended prematurely",
1333object_error::parse_failed);
1334returnError::success();
1335}
1336
1337Error WasmObjectFile::parseTableSection(ReadContext &Ctx) {
1338 TableSection = Sections.size();
1339uint32_t Count =readVaruint32(Ctx);
1340 Tables.reserve(Count);
1341while (Count--) {
1342wasm::WasmTableT;
1343T.Type =readTableType(Ctx);
1344T.Index = NumImportedTables + Tables.size();
1345 Tables.push_back(T);
1346auto ElemType = Tables.back().Type.ElemType;
1347if (ElemType !=wasm::ValType::FUNCREF &&
1348 ElemType !=wasm::ValType::EXTERNREF &&
1349 ElemType !=wasm::ValType::EXNREF &&
1350 ElemType !=wasm::ValType::OTHERREF) {
1351return make_error<GenericBinaryError>("invalid table element type",
1352object_error::parse_failed);
1353 }
1354 }
1355if (Ctx.Ptr != Ctx.End)
1356return make_error<GenericBinaryError>("table section ended prematurely",
1357object_error::parse_failed);
1358returnError::success();
1359}
1360
1361Error WasmObjectFile::parseMemorySection(ReadContext &Ctx) {
1362uint32_t Count =readVaruint32(Ctx);
1363 Memories.reserve(Count);
1364while (Count--) {
1365auto Limits =readLimits(Ctx);
1366if (Limits.Flags &wasm::WASM_LIMITS_FLAG_IS_64)
1367 HasMemory64 =true;
1368 Memories.push_back(Limits);
1369 }
1370if (Ctx.Ptr != Ctx.End)
1371return make_error<GenericBinaryError>("memory section ended prematurely",
1372object_error::parse_failed);
1373returnError::success();
1374}
1375
1376Error WasmObjectFile::parseTagSection(ReadContext &Ctx) {
1377 TagSection = Sections.size();
1378uint32_t Count =readVaruint32(Ctx);
1379 Tags.reserve(Count);
1380uint32_t NumTypes = Signatures.size();
1381while (Count--) {
1382if (readUint8(Ctx) != 0)// Reserved 'attribute' field
1383return make_error<GenericBinaryError>("invalid attribute",
1384object_error::parse_failed);
1385uint32_tType =readVaruint32(Ctx);
1386if (Type >= NumTypes)
1387return make_error<GenericBinaryError>("invalid tag type",
1388object_error::parse_failed);
1389wasm::WasmTagTag;
1390Tag.Index = NumImportedTags + Tags.size();
1391Tag.SigIndex =Type;
1392 Signatures[Type].Kind =wasm::WasmSignature::Tag;
1393 Tags.push_back(Tag);
1394 }
1395
1396if (Ctx.Ptr != Ctx.End)
1397return make_error<GenericBinaryError>("tag section ended prematurely",
1398object_error::parse_failed);
1399returnError::success();
1400}
1401
1402Error WasmObjectFile::parseGlobalSection(ReadContext &Ctx) {
1403 GlobalSection = Sections.size();
1404constuint8_t *SectionStart = Ctx.Ptr;
1405uint32_t Count =readVaruint32(Ctx);
1406 Globals.reserve(Count);
1407while (Count--) {
1408wasm::WasmGlobalGlobal;
1409Global.Index = NumImportedGlobals + Globals.size();
1410constuint8_t *GlobalStart = Ctx.Ptr;
1411Global.Offset =static_cast<uint32_t>(GlobalStart - SectionStart);
1412auto GlobalOpcode =readVaruint32(Ctx);
1413Global.Type.Type = (uint8_t)parseValType(Ctx, GlobalOpcode);
1414Global.Type.Mutable =readVaruint1(Ctx);
1415if (Error Err =readInitExpr(Global.InitExpr, Ctx))
1416return Err;
1417Global.Size =static_cast<uint32_t>(Ctx.Ptr - GlobalStart);
1418 Globals.push_back(Global);
1419 }
1420if (Ctx.Ptr != Ctx.End)
1421return make_error<GenericBinaryError>("global section ended prematurely",
1422object_error::parse_failed);
1423returnError::success();
1424}
1425
1426Error WasmObjectFile::parseExportSection(ReadContext &Ctx) {
1427uint32_t Count =readVaruint32(Ctx);
1428 Exports.reserve(Count);
1429 Symbols.reserve(Count);
1430for (uint32_tI = 0;I < Count;I++) {
1431wasm::WasmExport Ex;
1432 Ex.Name =readString(Ctx);
1433 Ex.Kind =readUint8(Ctx);
1434 Ex.Index =readVaruint32(Ctx);
1435constwasm::WasmSignature *Signature =nullptr;
1436constwasm::WasmGlobalType *GlobalType =nullptr;
1437constwasm::WasmTableType *TableType =nullptr;
1438wasm::WasmSymbolInfoInfo;
1439Info.Name = Ex.Name;
1440Info.Flags = 0;
1441switch (Ex.Kind) {
1442casewasm::WASM_EXTERNAL_FUNCTION: {
1443if (!isValidFunctionIndex(Ex.Index))
1444return make_error<GenericBinaryError>("invalid function export",
1445object_error::parse_failed);
1446Info.Kind =wasm::WASM_SYMBOL_TYPE_FUNCTION;
1447Info.ElementIndex = Ex.Index;
1448if (isDefinedFunctionIndex(Ex.Index)) {
1449 getDefinedFunction(Ex.Index).ExportName = Ex.Name;
1450unsigned FuncIndex =Info.ElementIndex - NumImportedFunctions;
1451wasm::WasmFunction &Function = Functions[FuncIndex];
1452 Signature = &Signatures[Function.SigIndex];
1453 }
1454// Else the function is imported. LLVM object files don't use this
1455// pattern and we still treat this as an undefined symbol, but we want to
1456// parse it without crashing.
1457break;
1458 }
1459casewasm::WASM_EXTERNAL_GLOBAL: {
1460if (!isValidGlobalIndex(Ex.Index))
1461return make_error<GenericBinaryError>("invalid global export",
1462object_error::parse_failed);
1463Info.Kind =wasm::WASM_SYMBOL_TYPE_DATA;
1464uint64_tOffset = 0;
1465if (isDefinedGlobalIndex(Ex.Index)) {
1466autoGlobal = getDefinedGlobal(Ex.Index);
1467if (!Global.InitExpr.Extended) {
1468auto Inst =Global.InitExpr.Inst;
1469if (Inst.Opcode ==wasm::WASM_OPCODE_I32_CONST) {
1470Offset = Inst.Value.Int32;
1471 }elseif (Inst.Opcode ==wasm::WASM_OPCODE_I64_CONST) {
1472Offset = Inst.Value.Int64;
1473 }
1474 }
1475 }
1476Info.DataRef =wasm::WasmDataReference{0,Offset, 0};
1477break;
1478 }
1479casewasm::WASM_EXTERNAL_TAG:
1480if (!isValidTagIndex(Ex.Index))
1481return make_error<GenericBinaryError>("invalid tag export",
1482object_error::parse_failed);
1483Info.Kind =wasm::WASM_SYMBOL_TYPE_TAG;
1484Info.ElementIndex = Ex.Index;
1485break;
1486casewasm::WASM_EXTERNAL_MEMORY:
1487break;
1488casewasm::WASM_EXTERNAL_TABLE:
1489Info.Kind =wasm::WASM_SYMBOL_TYPE_TABLE;
1490Info.ElementIndex = Ex.Index;
1491break;
1492default:
1493return make_error<GenericBinaryError>("unexpected export kind",
1494object_error::parse_failed);
1495 }
1496 Exports.push_back(Ex);
1497if (Ex.Kind !=wasm::WASM_EXTERNAL_MEMORY) {
1498 Symbols.emplace_back(Info, GlobalType, TableType, Signature);
1499LLVM_DEBUG(dbgs() <<"Adding symbol: " << Symbols.back() <<"\n");
1500 }
1501 }
1502if (Ctx.Ptr != Ctx.End)
1503return make_error<GenericBinaryError>("export section ended prematurely",
1504object_error::parse_failed);
1505returnError::success();
1506}
1507
1508bool WasmObjectFile::isValidFunctionIndex(uint32_t Index) const{
1509returnIndex < NumImportedFunctions + Functions.size();
1510}
1511
1512bool WasmObjectFile::isDefinedFunctionIndex(uint32_t Index) const{
1513returnIndex >= NumImportedFunctions && isValidFunctionIndex(Index);
1514}
1515
1516bool WasmObjectFile::isValidGlobalIndex(uint32_t Index) const{
1517returnIndex < NumImportedGlobals + Globals.size();
1518}
1519
1520bool WasmObjectFile::isValidTableNumber(uint32_t Index) const{
1521returnIndex < NumImportedTables + Tables.size();
1522}
1523
1524bool WasmObjectFile::isDefinedGlobalIndex(uint32_t Index) const{
1525returnIndex >= NumImportedGlobals && isValidGlobalIndex(Index);
1526}
1527
1528bool WasmObjectFile::isDefinedTableNumber(uint32_t Index) const{
1529returnIndex >= NumImportedTables && isValidTableNumber(Index);
1530}
1531
1532bool WasmObjectFile::isValidTagIndex(uint32_t Index) const{
1533returnIndex < NumImportedTags + Tags.size();
1534}
1535
1536bool WasmObjectFile::isDefinedTagIndex(uint32_t Index) const{
1537returnIndex >= NumImportedTags && isValidTagIndex(Index);
1538}
1539
1540bool WasmObjectFile::isValidFunctionSymbol(uint32_t Index) const{
1541returnIndex < Symbols.size() && Symbols[Index].isTypeFunction();
1542}
1543
1544bool WasmObjectFile::isValidTableSymbol(uint32_t Index) const{
1545returnIndex < Symbols.size() && Symbols[Index].isTypeTable();
1546}
1547
1548bool WasmObjectFile::isValidGlobalSymbol(uint32_t Index) const{
1549returnIndex < Symbols.size() && Symbols[Index].isTypeGlobal();
1550}
1551
1552bool WasmObjectFile::isValidTagSymbol(uint32_t Index) const{
1553returnIndex < Symbols.size() && Symbols[Index].isTypeTag();
1554}
1555
1556bool WasmObjectFile::isValidDataSymbol(uint32_t Index) const{
1557returnIndex < Symbols.size() && Symbols[Index].isTypeData();
1558}
1559
1560bool WasmObjectFile::isValidSectionSymbol(uint32_t Index) const{
1561returnIndex < Symbols.size() && Symbols[Index].isTypeSection();
1562}
1563
1564wasm::WasmFunction &WasmObjectFile::getDefinedFunction(uint32_t Index) {
1565assert(isDefinedFunctionIndex(Index));
1566return Functions[Index - NumImportedFunctions];
1567}
1568
1569constwasm::WasmFunction &
1570WasmObjectFile::getDefinedFunction(uint32_t Index) const{
1571assert(isDefinedFunctionIndex(Index));
1572return Functions[Index - NumImportedFunctions];
1573}
1574
1575constwasm::WasmGlobal &WasmObjectFile::getDefinedGlobal(uint32_t Index) const{
1576assert(isDefinedGlobalIndex(Index));
1577return Globals[Index - NumImportedGlobals];
1578}
1579
1580wasm::WasmTag &WasmObjectFile::getDefinedTag(uint32_t Index) {
1581assert(isDefinedTagIndex(Index));
1582return Tags[Index - NumImportedTags];
1583}
1584
1585Error WasmObjectFile::parseStartSection(ReadContext &Ctx) {
1586 StartFunction =readVaruint32(Ctx);
1587if (!isValidFunctionIndex(StartFunction))
1588return make_error<GenericBinaryError>("invalid start function",
1589object_error::parse_failed);
1590returnError::success();
1591}
1592
1593Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) {
1594 CodeSection = Sections.size();
1595uint32_t FunctionCount =readVaruint32(Ctx);
1596if (FunctionCount != Functions.size()) {
1597return make_error<GenericBinaryError>("invalid function count",
1598object_error::parse_failed);
1599 }
1600
1601for (uint32_t i = 0; i < FunctionCount; i++) {
1602wasm::WasmFunction&Function = Functions[i];
1603constuint8_t *FunctionStart = Ctx.Ptr;
1604uint32_tSize =readVaruint32(Ctx);
1605constuint8_t *FunctionEnd = Ctx.Ptr +Size;
1606
1607Function.CodeOffset = Ctx.Ptr - FunctionStart;
1608Function.Index = NumImportedFunctions + i;
1609Function.CodeSectionOffset = FunctionStart - Ctx.Start;
1610Function.Size = FunctionEnd - FunctionStart;
1611
1612uint32_t NumLocalDecls =readVaruint32(Ctx);
1613Function.Locals.reserve(NumLocalDecls);
1614while (NumLocalDecls--) {
1615wasm::WasmLocalDecl Decl;
1616 Decl.Count =readVaruint32(Ctx);
1617 Decl.Type =readUint8(Ctx);
1618Function.Locals.push_back(Decl);
1619 }
1620
1621uint32_t BodySize = FunctionEnd - Ctx.Ptr;
1622// Ensure that Function is within Ctx's buffer.
1623if (Ctx.Ptr + BodySize > Ctx.End) {
1624return make_error<GenericBinaryError>("Function extends beyond buffer",
1625object_error::parse_failed);
1626 }
1627Function.Body =ArrayRef<uint8_t>(Ctx.Ptr, BodySize);
1628// This will be set later when reading in the linking metadata section.
1629Function.Comdat = UINT32_MAX;
1630 Ctx.Ptr += BodySize;
1631assert(Ctx.Ptr == FunctionEnd);
1632 }
1633if (Ctx.Ptr != Ctx.End)
1634return make_error<GenericBinaryError>("code section ended prematurely",
1635object_error::parse_failed);
1636returnError::success();
1637}
1638
1639Error WasmObjectFile::parseElemSection(ReadContext &Ctx) {
1640uint32_t Count =readVaruint32(Ctx);
1641 ElemSegments.reserve(Count);
1642while (Count--) {
1643wasm::WasmElemSegment Segment;
1644 Segment.Flags =readVaruint32(Ctx);
1645
1646uint32_t SupportedFlags =wasm::WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER |
1647wasm::WASM_ELEM_SEGMENT_IS_PASSIVE |
1648wasm::WASM_ELEM_SEGMENT_HAS_INIT_EXPRS;
1649if (Segment.Flags & ~SupportedFlags)
1650return make_error<GenericBinaryError>(
1651"Unsupported flags for element segment",object_error::parse_failed);
1652
1653wasm::ElemSegmentModeMode;
1654if ((Segment.Flags &wasm::WASM_ELEM_SEGMENT_IS_PASSIVE) == 0) {
1655Mode =wasm::ElemSegmentMode::Active;
1656 }elseif (Segment.Flags &wasm::WASM_ELEM_SEGMENT_IS_DECLARATIVE) {
1657Mode =wasm::ElemSegmentMode::Declarative;
1658 }else {
1659Mode =wasm::ElemSegmentMode::Passive;
1660 }
1661bool HasTableNumber =
1662Mode ==wasm::ElemSegmentMode::Active &&
1663 (Segment.Flags &wasm::WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER);
1664bool HasElemKind =
1665 (Segment.Flags &wasm::WASM_ELEM_SEGMENT_MASK_HAS_ELEM_DESC) &&
1666 !(Segment.Flags &wasm::WASM_ELEM_SEGMENT_HAS_INIT_EXPRS);
1667bool HasElemType =
1668 (Segment.Flags &wasm::WASM_ELEM_SEGMENT_MASK_HAS_ELEM_DESC) &&
1669 (Segment.Flags &wasm::WASM_ELEM_SEGMENT_HAS_INIT_EXPRS);
1670bool HasInitExprs =
1671 (Segment.Flags &wasm::WASM_ELEM_SEGMENT_HAS_INIT_EXPRS);
1672
1673if (HasTableNumber)
1674 Segment.TableNumber =readVaruint32(Ctx);
1675else
1676 Segment.TableNumber = 0;
1677
1678if (!isValidTableNumber(Segment.TableNumber))
1679return make_error<GenericBinaryError>("invalid TableNumber",
1680object_error::parse_failed);
1681
1682if (Mode !=wasm::ElemSegmentMode::Active) {
1683 Segment.Offset.Extended =false;
1684 Segment.Offset.Inst.Opcode =wasm::WASM_OPCODE_I32_CONST;
1685 Segment.Offset.Inst.Value.Int32 = 0;
1686 }else {
1687if (Error Err =readInitExpr(Segment.Offset, Ctx))
1688return Err;
1689 }
1690
1691if (HasElemKind) {
1692auto ElemKind =readVaruint32(Ctx);
1693if (Segment.Flags &wasm::WASM_ELEM_SEGMENT_HAS_INIT_EXPRS) {
1694 Segment.ElemKind =parseValType(Ctx, ElemKind);
1695if (Segment.ElemKind !=wasm::ValType::FUNCREF &&
1696 Segment.ElemKind !=wasm::ValType::EXTERNREF &&
1697 Segment.ElemKind !=wasm::ValType::EXNREF &&
1698 Segment.ElemKind !=wasm::ValType::OTHERREF) {
1699return make_error<GenericBinaryError>("invalid elem type",
1700object_error::parse_failed);
1701 }
1702 }else {
1703if (ElemKind != 0)
1704return make_error<GenericBinaryError>("invalid elem type",
1705object_error::parse_failed);
1706 Segment.ElemKind =wasm::ValType::FUNCREF;
1707 }
1708 }elseif (HasElemType) {
1709auto ElemType =parseValType(Ctx,readVaruint32(Ctx));
1710 Segment.ElemKind = ElemType;
1711 }else {
1712 Segment.ElemKind =wasm::ValType::FUNCREF;
1713 }
1714
1715uint32_t NumElems =readVaruint32(Ctx);
1716
1717if (HasInitExprs) {
1718while (NumElems--) {
1719wasm::WasmInitExpr Expr;
1720if (Error Err =readInitExpr(Expr, Ctx))
1721return Err;
1722 }
1723 }else {
1724while (NumElems--) {
1725 Segment.Functions.push_back(readVaruint32(Ctx));
1726 }
1727 }
1728 ElemSegments.push_back(Segment);
1729 }
1730if (Ctx.Ptr != Ctx.End)
1731return make_error<GenericBinaryError>("elem section ended prematurely",
1732object_error::parse_failed);
1733returnError::success();
1734}
1735
1736Error WasmObjectFile::parseDataSection(ReadContext &Ctx) {
1737 DataSection = Sections.size();
1738uint32_t Count =readVaruint32(Ctx);
1739if (DataCount && Count != *DataCount)
1740return make_error<GenericBinaryError>(
1741"number of data segments does not match DataCount section");
1742 DataSegments.reserve(Count);
1743while (Count--) {
1744WasmSegment Segment;
1745 Segment.Data.InitFlags =readVaruint32(Ctx);
1746 Segment.Data.MemoryIndex =
1747 (Segment.Data.InitFlags &wasm::WASM_DATA_SEGMENT_HAS_MEMINDEX)
1748 ?readVaruint32(Ctx)
1749 : 0;
1750if ((Segment.Data.InitFlags &wasm::WASM_DATA_SEGMENT_IS_PASSIVE) == 0) {
1751if (Error Err =readInitExpr(Segment.Data.Offset, Ctx))
1752return Err;
1753 }else {
1754 Segment.Data.Offset.Extended =false;
1755 Segment.Data.Offset.Inst.Opcode =wasm::WASM_OPCODE_I32_CONST;
1756 Segment.Data.Offset.Inst.Value.Int32 = 0;
1757 }
1758uint32_tSize =readVaruint32(Ctx);
1759if (Size > (size_t)(Ctx.End - Ctx.Ptr))
1760return make_error<GenericBinaryError>("invalid segment size",
1761object_error::parse_failed);
1762 Segment.Data.Content =ArrayRef<uint8_t>(Ctx.Ptr,Size);
1763// The rest of these Data fields are set later, when reading in the linking
1764// metadata section.
1765 Segment.Data.Alignment = 0;
1766 Segment.Data.LinkingFlags = 0;
1767 Segment.Data.Comdat = UINT32_MAX;
1768 Segment.SectionOffset = Ctx.Ptr - Ctx.Start;
1769 Ctx.Ptr +=Size;
1770 DataSegments.push_back(Segment);
1771 }
1772if (Ctx.Ptr != Ctx.End)
1773return make_error<GenericBinaryError>("data section ended prematurely",
1774object_error::parse_failed);
1775returnError::success();
1776}
1777
1778Error WasmObjectFile::parseDataCountSection(ReadContext &Ctx) {
1779 DataCount =readVaruint32(Ctx);
1780returnError::success();
1781}
1782
1783constwasm::WasmObjectHeader &WasmObjectFile::getHeader() const{
1784return Header;
1785}
1786
1787voidWasmObjectFile::moveSymbolNext(DataRefImpl &Symb) const{ Symb.d.b++; }
1788
1789Expected<uint32_t>WasmObjectFile::getSymbolFlags(DataRefImpl Symb) const{
1790uint32_t Result =SymbolRef::SF_None;
1791constWasmSymbol &Sym =getWasmSymbol(Symb);
1792
1793LLVM_DEBUG(dbgs() <<"getSymbolFlags: ptr=" << &Sym <<" " <<Sym <<"\n");
1794if (Sym.isBindingWeak())
1795 Result |=SymbolRef::SF_Weak;
1796if (!Sym.isBindingLocal())
1797 Result |=SymbolRef::SF_Global;
1798if (Sym.isHidden())
1799 Result |=SymbolRef::SF_Hidden;
1800if (!Sym.isDefined())
1801 Result |=SymbolRef::SF_Undefined;
1802if (Sym.isTypeFunction())
1803 Result |=SymbolRef::SF_Executable;
1804return Result;
1805}
1806
1807basic_symbol_iteratorWasmObjectFile::symbol_begin() const{
1808DataRefImplRef;
1809Ref.d.a = 1;// Arbitrary non-zero value so that Ref.p is non-null
1810Ref.d.b = 0;// Symbol index
1811returnBasicSymbolRef(Ref,this);
1812}
1813
1814basic_symbol_iteratorWasmObjectFile::symbol_end() const{
1815DataRefImplRef;
1816Ref.d.a = 1;// Arbitrary non-zero value so that Ref.p is non-null
1817Ref.d.b = Symbols.size();// Symbol index
1818returnBasicSymbolRef(Ref,this);
1819}
1820
1821constWasmSymbol &WasmObjectFile::getWasmSymbol(constDataRefImpl &Symb) const{
1822return Symbols[Symb.d.b];
1823}
1824
1825constWasmSymbol &WasmObjectFile::getWasmSymbol(constSymbolRef &Symb) const{
1826returngetWasmSymbol(Symb.getRawDataRefImpl());
1827}
1828
1829Expected<StringRef>WasmObjectFile::getSymbolName(DataRefImpl Symb) const{
1830returngetWasmSymbol(Symb).Info.Name;
1831}
1832
1833Expected<uint64_t>WasmObjectFile::getSymbolAddress(DataRefImpl Symb) const{
1834auto &Sym =getWasmSymbol(Symb);
1835if (!Sym.isDefined())
1836return 0;
1837Expected<section_iterator> Sec =getSymbolSection(Symb);
1838if (!Sec)
1839return Sec.takeError();
1840uint32_t SectionAddress =getSectionAddress(Sec.get()->getRawDataRefImpl());
1841if (Sym.Info.Kind ==wasm::WASM_SYMBOL_TYPE_FUNCTION &&
1842 isDefinedFunctionIndex(Sym.Info.ElementIndex)) {
1843return getDefinedFunction(Sym.Info.ElementIndex).CodeSectionOffset +
1844 SectionAddress;
1845 }
1846if (Sym.Info.Kind ==wasm::WASM_SYMBOL_TYPE_GLOBAL &&
1847 isDefinedGlobalIndex(Sym.Info.ElementIndex)) {
1848return getDefinedGlobal(Sym.Info.ElementIndex).Offset + SectionAddress;
1849 }
1850
1851returngetSymbolValue(Symb);
1852}
1853
1854uint64_tWasmObjectFile::getWasmSymbolValue(constWasmSymbol &Sym) const{
1855switch (Sym.Info.Kind) {
1856casewasm::WASM_SYMBOL_TYPE_FUNCTION:
1857casewasm::WASM_SYMBOL_TYPE_GLOBAL:
1858casewasm::WASM_SYMBOL_TYPE_TAG:
1859casewasm::WASM_SYMBOL_TYPE_TABLE:
1860returnSym.Info.ElementIndex;
1861casewasm::WASM_SYMBOL_TYPE_DATA: {
1862// The value of a data symbol is the segment offset, plus the symbol
1863// offset within the segment.
1864uint32_t SegmentIndex =Sym.Info.DataRef.Segment;
1865constwasm::WasmDataSegment &Segment = DataSegments[SegmentIndex].Data;
1866if (Segment.Offset.Extended) {
1867llvm_unreachable("extended init exprs not supported");
1868 }elseif (Segment.Offset.Inst.Opcode ==wasm::WASM_OPCODE_I32_CONST) {
1869return Segment.Offset.Inst.Value.Int32 +Sym.Info.DataRef.Offset;
1870 }elseif (Segment.Offset.Inst.Opcode ==wasm::WASM_OPCODE_I64_CONST) {
1871return Segment.Offset.Inst.Value.Int64 +Sym.Info.DataRef.Offset;
1872 }elseif (Segment.Offset.Inst.Opcode ==wasm::WASM_OPCODE_GLOBAL_GET) {
1873returnSym.Info.DataRef.Offset;
1874 }else {
1875llvm_unreachable("unknown init expr opcode");
1876 }
1877 }
1878casewasm::WASM_SYMBOL_TYPE_SECTION:
1879return 0;
1880 }
1881llvm_unreachable("invalid symbol type");
1882}
1883
1884uint64_tWasmObjectFile::getSymbolValueImpl(DataRefImpl Symb) const{
1885returngetWasmSymbolValue(getWasmSymbol(Symb));
1886}
1887
1888uint32_tWasmObjectFile::getSymbolAlignment(DataRefImpl Symb) const{
1889llvm_unreachable("not yet implemented");
1890return 0;
1891}
1892
1893uint64_tWasmObjectFile::getCommonSymbolSizeImpl(DataRefImpl Symb) const{
1894llvm_unreachable("not yet implemented");
1895return 0;
1896}
1897
1898Expected<SymbolRef::Type>
1899WasmObjectFile::getSymbolType(DataRefImpl Symb) const{
1900constWasmSymbol &Sym =getWasmSymbol(Symb);
1901
1902switch (Sym.Info.Kind) {
1903casewasm::WASM_SYMBOL_TYPE_FUNCTION:
1904returnSymbolRef::ST_Function;
1905casewasm::WASM_SYMBOL_TYPE_GLOBAL:
1906returnSymbolRef::ST_Other;
1907casewasm::WASM_SYMBOL_TYPE_DATA:
1908returnSymbolRef::ST_Data;
1909casewasm::WASM_SYMBOL_TYPE_SECTION:
1910returnSymbolRef::ST_Debug;
1911casewasm::WASM_SYMBOL_TYPE_TAG:
1912returnSymbolRef::ST_Other;
1913casewasm::WASM_SYMBOL_TYPE_TABLE:
1914returnSymbolRef::ST_Other;
1915 }
1916
1917llvm_unreachable("unknown WasmSymbol::SymbolType");
1918returnSymbolRef::ST_Other;
1919}
1920
1921Expected<section_iterator>
1922WasmObjectFile::getSymbolSection(DataRefImpl Symb) const{
1923constWasmSymbol &Sym =getWasmSymbol(Symb);
1924if (Sym.isUndefined())
1925returnsection_end();
1926
1927DataRefImplRef;
1928Ref.d.a = getSymbolSectionIdImpl(Sym);
1929returnsection_iterator(SectionRef(Ref,this));
1930}
1931
1932uint32_tWasmObjectFile::getSymbolSectionId(SymbolRef Symb) const{
1933constWasmSymbol &Sym =getWasmSymbol(Symb);
1934return getSymbolSectionIdImpl(Sym);
1935}
1936
1937uint32_t WasmObjectFile::getSymbolSectionIdImpl(constWasmSymbol &Sym) const{
1938switch (Sym.Info.Kind) {
1939casewasm::WASM_SYMBOL_TYPE_FUNCTION:
1940return CodeSection;
1941casewasm::WASM_SYMBOL_TYPE_GLOBAL:
1942return GlobalSection;
1943casewasm::WASM_SYMBOL_TYPE_DATA:
1944return DataSection;
1945casewasm::WASM_SYMBOL_TYPE_SECTION:
1946returnSym.Info.ElementIndex;
1947casewasm::WASM_SYMBOL_TYPE_TAG:
1948return TagSection;
1949casewasm::WASM_SYMBOL_TYPE_TABLE:
1950return TableSection;
1951default:
1952llvm_unreachable("unknown WasmSymbol::SymbolType");
1953 }
1954}
1955
1956uint32_tWasmObjectFile::getSymbolSize(SymbolRef Symb) const{
1957constWasmSymbol &Sym =getWasmSymbol(Symb);
1958if (!Sym.isDefined())
1959return 0;
1960if (Sym.isTypeGlobal())
1961return getDefinedGlobal(Sym.Info.ElementIndex).Size;
1962if (Sym.isTypeData())
1963returnSym.Info.DataRef.Size;
1964if (Sym.isTypeFunction())
1965returnfunctions()[Sym.Info.ElementIndex -getNumImportedFunctions()].Size;
1966// Currently symbol size is only tracked for data segments and functions. In
1967// principle we could also track size (e.g. binary size) for tables, globals
1968// and element segments etc too.
1969return 0;
1970}
1971
1972voidWasmObjectFile::moveSectionNext(DataRefImpl &Sec) const{ Sec.d.a++; }
1973
1974Expected<StringRef>WasmObjectFile::getSectionName(DataRefImpl Sec) const{
1975constWasmSection &S = Sections[Sec.d.a];
1976if (S.Type ==wasm::WASM_SEC_CUSTOM)
1977return S.Name;
1978if (S.Type >wasm::WASM_SEC_LAST_KNOWN)
1979returncreateStringError(object_error::invalid_section_index,"");
1980returnwasm::sectionTypeToString(S.Type);
1981}
1982
1983uint64_tWasmObjectFile::getSectionAddress(DataRefImpl Sec) const{
1984// For object files, use 0 for section addresses, and section offsets for
1985// symbol addresses. For linked files, use file offsets.
1986// See also getSymbolAddress.
1987returnisRelocatableObject() ||isSharedObject() ? 0
1988 : Sections[Sec.d.a].Offset;
1989}
1990
1991uint64_tWasmObjectFile::getSectionIndex(DataRefImpl Sec) const{
1992return Sec.d.a;
1993}
1994
1995uint64_tWasmObjectFile::getSectionSize(DataRefImpl Sec) const{
1996constWasmSection &S = Sections[Sec.d.a];
1997return S.Content.size();
1998}
1999
2000Expected<ArrayRef<uint8_t>>
2001WasmObjectFile::getSectionContents(DataRefImpl Sec) const{
2002constWasmSection &S = Sections[Sec.d.a];
2003// This will never fail since wasm sections can never be empty (user-sections
2004// must have a name and non-user sections each have a defined structure).
2005return S.Content;
2006}
2007
2008uint64_tWasmObjectFile::getSectionAlignment(DataRefImpl Sec) const{
2009return 1;
2010}
2011
2012boolWasmObjectFile::isSectionCompressed(DataRefImpl Sec) const{
2013returnfalse;
2014}
2015
2016boolWasmObjectFile::isSectionText(DataRefImpl Sec) const{
2017returngetWasmSection(Sec).Type ==wasm::WASM_SEC_CODE;
2018}
2019
2020boolWasmObjectFile::isSectionData(DataRefImpl Sec) const{
2021returngetWasmSection(Sec).Type ==wasm::WASM_SEC_DATA;
2022}
2023
2024boolWasmObjectFile::isSectionBSS(DataRefImpl Sec) const{returnfalse; }
2025
2026boolWasmObjectFile::isSectionVirtual(DataRefImpl Sec) const{returnfalse; }
2027
2028relocation_iteratorWasmObjectFile::section_rel_begin(DataRefImplRef) const{
2029DataRefImpl RelocRef;
2030 RelocRef.d.a =Ref.d.a;
2031 RelocRef.d.b = 0;
2032returnrelocation_iterator(RelocationRef(RelocRef,this));
2033}
2034
2035relocation_iteratorWasmObjectFile::section_rel_end(DataRefImplRef) const{
2036constWasmSection &Sec =getWasmSection(Ref);
2037DataRefImpl RelocRef;
2038 RelocRef.d.a =Ref.d.a;
2039 RelocRef.d.b = Sec.Relocations.size();
2040returnrelocation_iterator(RelocationRef(RelocRef,this));
2041}
2042
2043voidWasmObjectFile::moveRelocationNext(DataRefImpl &Rel) const{ Rel.d.b++; }
2044
2045uint64_tWasmObjectFile::getRelocationOffset(DataRefImplRef) const{
2046constwasm::WasmRelocation &Rel =getWasmRelocation(Ref);
2047return Rel.Offset;
2048}
2049
2050symbol_iteratorWasmObjectFile::getRelocationSymbol(DataRefImplRef) const{
2051constwasm::WasmRelocation &Rel =getWasmRelocation(Ref);
2052if (Rel.Type == wasm::R_WASM_TYPE_INDEX_LEB)
2053returnsymbol_end();
2054DataRefImplSym;
2055Sym.d.a = 1;
2056Sym.d.b = Rel.Index;
2057returnsymbol_iterator(SymbolRef(Sym,this));
2058}
2059
2060uint64_tWasmObjectFile::getRelocationType(DataRefImplRef) const{
2061constwasm::WasmRelocation &Rel =getWasmRelocation(Ref);
2062return Rel.Type;
2063}
2064
2065voidWasmObjectFile::getRelocationTypeName(
2066DataRefImplRef,SmallVectorImpl<char> &Result) const{
2067constwasm::WasmRelocation &Rel =getWasmRelocation(Ref);
2068StringRef Res ="Unknown";
2069
2070#define WASM_RELOC(name, value) \
2071 case wasm::name: \
2072 Res = #name; \
2073 break;
2074
2075switch (Rel.Type) {
2076#include "llvm/BinaryFormat/WasmRelocs.def"
2077 }
2078
2079#undef WASM_RELOC
2080
2081 Result.append(Res.begin(), Res.end());
2082}
2083
2084section_iteratorWasmObjectFile::section_begin() const{
2085DataRefImplRef;
2086Ref.d.a = 0;
2087returnsection_iterator(SectionRef(Ref,this));
2088}
2089
2090section_iteratorWasmObjectFile::section_end() const{
2091DataRefImplRef;
2092Ref.d.a = Sections.size();
2093returnsection_iterator(SectionRef(Ref,this));
2094}
2095
2096uint8_tWasmObjectFile::getBytesInAddress() const{
2097return HasMemory64 ? 8 : 4;
2098}
2099
2100StringRefWasmObjectFile::getFileFormatName() const{return"WASM"; }
2101
2102Triple::ArchTypeWasmObjectFile::getArch() const{
2103return HasMemory64 ?Triple::wasm64 :Triple::wasm32;
2104}
2105
2106Expected<SubtargetFeatures>WasmObjectFile::getFeatures() const{
2107returnSubtargetFeatures();
2108}
2109
2110boolWasmObjectFile::isRelocatableObject() const{return HasLinkingSection; }
2111
2112boolWasmObjectFile::isSharedObject() const{return HasDylinkSection; }
2113
2114constWasmSection &WasmObjectFile::getWasmSection(DataRefImplRef) const{
2115assert(Ref.d.a < Sections.size());
2116return Sections[Ref.d.a];
2117}
2118
2119constWasmSection &
2120WasmObjectFile::getWasmSection(constSectionRef &Section) const{
2121returngetWasmSection(Section.getRawDataRefImpl());
2122}
2123
2124constwasm::WasmRelocation &
2125WasmObjectFile::getWasmRelocation(constRelocationRef &Ref) const{
2126returngetWasmRelocation(Ref.getRawDataRefImpl());
2127}
2128
2129constwasm::WasmRelocation &
2130WasmObjectFile::getWasmRelocation(DataRefImplRef) const{
2131assert(Ref.d.a < Sections.size());
2132constWasmSection &Sec = Sections[Ref.d.a];
2133assert(Ref.d.b < Sec.Relocations.size());
2134return Sec.Relocations[Ref.d.b];
2135}
2136
2137int WasmSectionOrderChecker::getSectionOrder(unsignedID,
2138StringRef CustomSectionName) {
2139switch (ID) {
2140casewasm::WASM_SEC_CUSTOM:
2141returnStringSwitch<unsigned>(CustomSectionName)
2142 .Case("dylink",WASM_SEC_ORDER_DYLINK)
2143 .Case("dylink.0",WASM_SEC_ORDER_DYLINK)
2144 .Case("linking",WASM_SEC_ORDER_LINKING)
2145 .StartsWith("reloc.",WASM_SEC_ORDER_RELOC)
2146 .Case("name",WASM_SEC_ORDER_NAME)
2147 .Case("producers",WASM_SEC_ORDER_PRODUCERS)
2148 .Case("target_features",WASM_SEC_ORDER_TARGET_FEATURES)
2149 .Default(WASM_SEC_ORDER_NONE);
2150casewasm::WASM_SEC_TYPE:
2151returnWASM_SEC_ORDER_TYPE;
2152casewasm::WASM_SEC_IMPORT:
2153returnWASM_SEC_ORDER_IMPORT;
2154casewasm::WASM_SEC_FUNCTION:
2155returnWASM_SEC_ORDER_FUNCTION;
2156casewasm::WASM_SEC_TABLE:
2157returnWASM_SEC_ORDER_TABLE;
2158casewasm::WASM_SEC_MEMORY:
2159returnWASM_SEC_ORDER_MEMORY;
2160casewasm::WASM_SEC_GLOBAL:
2161returnWASM_SEC_ORDER_GLOBAL;
2162casewasm::WASM_SEC_EXPORT:
2163returnWASM_SEC_ORDER_EXPORT;
2164casewasm::WASM_SEC_START:
2165returnWASM_SEC_ORDER_START;
2166casewasm::WASM_SEC_ELEM:
2167returnWASM_SEC_ORDER_ELEM;
2168casewasm::WASM_SEC_CODE:
2169returnWASM_SEC_ORDER_CODE;
2170casewasm::WASM_SEC_DATA:
2171returnWASM_SEC_ORDER_DATA;
2172casewasm::WASM_SEC_DATACOUNT:
2173returnWASM_SEC_ORDER_DATACOUNT;
2174casewasm::WASM_SEC_TAG:
2175returnWASM_SEC_ORDER_TAG;
2176default:
2177returnWASM_SEC_ORDER_NONE;
2178 }
2179}
2180
2181// Represents the edges in a directed graph where any node B reachable from node
2182// A is not allowed to appear before A in the section ordering, but may appear
2183// afterward.
2184intWasmSectionOrderChecker::DisallowedPredecessors
2185 [WASM_NUM_SEC_ORDERS][WASM_NUM_SEC_ORDERS] = {
2186// WASM_SEC_ORDER_NONE
2187 {},
2188// WASM_SEC_ORDER_TYPE
2189 {WASM_SEC_ORDER_TYPE, WASM_SEC_ORDER_IMPORT},
2190// WASM_SEC_ORDER_IMPORT
2191 {WASM_SEC_ORDER_IMPORT, WASM_SEC_ORDER_FUNCTION},
2192// WASM_SEC_ORDER_FUNCTION
2193 {WASM_SEC_ORDER_FUNCTION, WASM_SEC_ORDER_TABLE},
2194// WASM_SEC_ORDER_TABLE
2195 {WASM_SEC_ORDER_TABLE, WASM_SEC_ORDER_MEMORY},
2196// WASM_SEC_ORDER_MEMORY
2197 {WASM_SEC_ORDER_MEMORY, WASM_SEC_ORDER_TAG},
2198// WASM_SEC_ORDER_TAG
2199 {WASM_SEC_ORDER_TAG, WASM_SEC_ORDER_GLOBAL},
2200// WASM_SEC_ORDER_GLOBAL
2201 {WASM_SEC_ORDER_GLOBAL, WASM_SEC_ORDER_EXPORT},
2202// WASM_SEC_ORDER_EXPORT
2203 {WASM_SEC_ORDER_EXPORT, WASM_SEC_ORDER_START},
2204// WASM_SEC_ORDER_START
2205 {WASM_SEC_ORDER_START, WASM_SEC_ORDER_ELEM},
2206// WASM_SEC_ORDER_ELEM
2207 {WASM_SEC_ORDER_ELEM, WASM_SEC_ORDER_DATACOUNT},
2208// WASM_SEC_ORDER_DATACOUNT
2209 {WASM_SEC_ORDER_DATACOUNT, WASM_SEC_ORDER_CODE},
2210// WASM_SEC_ORDER_CODE
2211 {WASM_SEC_ORDER_CODE, WASM_SEC_ORDER_DATA},
2212// WASM_SEC_ORDER_DATA
2213 {WASM_SEC_ORDER_DATA, WASM_SEC_ORDER_LINKING},
2214
2215// Custom Sections
2216// WASM_SEC_ORDER_DYLINK
2217 {WASM_SEC_ORDER_DYLINK, WASM_SEC_ORDER_TYPE},
2218// WASM_SEC_ORDER_LINKING
2219 {WASM_SEC_ORDER_LINKING, WASM_SEC_ORDER_RELOC, WASM_SEC_ORDER_NAME},
2220// WASM_SEC_ORDER_RELOC (can be repeated)
2221 {},
2222// WASM_SEC_ORDER_NAME
2223 {WASM_SEC_ORDER_NAME, WASM_SEC_ORDER_PRODUCERS},
2224// WASM_SEC_ORDER_PRODUCERS
2225 {WASM_SEC_ORDER_PRODUCERS, WASM_SEC_ORDER_TARGET_FEATURES},
2226// WASM_SEC_ORDER_TARGET_FEATURES
2227 {WASM_SEC_ORDER_TARGET_FEATURES}};
2228
2229boolWasmSectionOrderChecker::isValidSectionOrder(unsignedID,
2230StringRef CustomSectionName) {
2231int Order = getSectionOrder(ID, CustomSectionName);
2232if (Order ==WASM_SEC_ORDER_NONE)
2233returntrue;
2234
2235// Disallowed predecessors we need to check for
2236SmallVector<int, WASM_NUM_SEC_ORDERS> WorkList;
2237
2238// Keep track of completed checks to avoid repeating work
2239bool Checked[WASM_NUM_SEC_ORDERS] = {};
2240
2241int Curr = Order;
2242while (true) {
2243// Add new disallowed predecessors to work list
2244for (size_tI = 0;; ++I) {
2245int Next =DisallowedPredecessors[Curr][I];
2246if (Next ==WASM_SEC_ORDER_NONE)
2247break;
2248if (Checked[Next])
2249continue;
2250 WorkList.push_back(Next);
2251 Checked[Next] =true;
2252 }
2253
2254if (WorkList.empty())
2255break;
2256
2257// Consider next disallowed predecessor
2258 Curr = WorkList.pop_back_val();
2259if (Seen[Curr])
2260returnfalse;
2261 }
2262
2263// Have not seen any disallowed predecessors
2264 Seen[Order] =true;
2265returntrue;
2266}
ArrayRef.h
Wasm.h
Binary.h
Info
Analysis containing CSE Info
Definition:CSEInfo.cpp:27
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition:Compiler.h:622
LLVM_DEBUG
#define LLVM_DEBUG(...)
Definition:Debug.h:106
DenseSet.h
This file defines the DenseSet and SmallDenseSet classes.
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
Sym
Symbol * Sym
Definition:ELF_riscv.cpp:479
Endian.h
LEB128.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
ObjectFile.h
Wasm.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ScopedPrinter.h
SmallSet.h
This file defines the SmallSet class.
StringRef.h
StringSet.h
StringSet - A set-like wrapper for the StringMap.
StringSwitch.h
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
SubtargetFeature.h
SymbolicFile.h
Triple.h
readVaruint1
static uint8_t readVaruint1(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:142
readInitExpr
static Error readInitExpr(wasm::WasmInitExpr &Expr, WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:196
readVarint32
static int32_t readVarint32(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:149
readTableType
static wasm::WasmTableType readTableType(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:297
readLimits
static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:288
readVaruint64
static uint64_t readVaruint64(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:167
readSection
static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, WasmSectionOrderChecker &Checker)
Definition:WasmObjectFile.cpp:305
readLEB128
static int64_t readLEB128(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:132
readVaruint32
static uint32_t readVaruint32(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:156
readUint32
static uint32_t readUint32(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:86
readOpcode
static uint8_t readOpcode(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:171
readString
static StringRef readString(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:122
readUint8
static uint8_t readUint8(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:80
VARUINT1_MAX
#define VARUINT1_MAX
Definition:WasmObjectFile.cpp:78
readFloat32
static int32_t readFloat32(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:94
readULEB128
static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:112
readFloat64
static int64_t readFloat64(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:103
parseValType
static wasm::ValType parseValType(WasmObjectFile::ReadContext &Ctx, uint32_t Code)
Definition:WasmObjectFile.cpp:175
readVarint64
static int64_t readVarint64(WasmObjectFile::ReadContext &Ctx)
Definition:WasmObjectFile.cpp:163
T
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::ArrayRef::data
const T * data() const
Definition:ArrayRef.h:165
llvm::Comdat
Definition:Comdat.h:33
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition:DenseSet.h:278
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition:Error.h:1130
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition:Error.h:608
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition:Error.h:578
llvm::Function
Definition:Function.h:63
llvm::Function::empty
bool empty() const
Definition:Function.h:859
llvm::Init
Definition:Record.h:285
llvm::MemoryBufferRef
Definition:MemoryBufferRef.h:22
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition:SmallSet.h:132
llvm::SmallSet::insert
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition:SmallSet.h:181
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorImpl::pop_back_val
T pop_back_val()
Definition:SmallVector.h:673
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition:SmallVector.h:663
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::substr
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition:StringRef.h:571
llvm::StringRef::starts_with
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition:StringRef.h:265
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::StringRef::begin
iterator begin() const
Definition:StringRef.h:116
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition:StringRef.h:150
llvm::StringRef::end
iterator end() const
Definition:StringRef.h:118
llvm::StringRef::bytes_begin
const unsigned char * bytes_begin() const
Definition:StringRef.h:128
llvm::StringSet
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition:StringSet.h:23
llvm::StringSet::insert
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition:StringSet.h:38
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition:StringSwitch.h:44
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition:StringSwitch.h:69
llvm::StringSwitch::Default
R Default(T Value)
Definition:StringSwitch.h:182
llvm::StringSwitch::StartsWith
StringSwitch & StartsWith(StringLiteral S, T Value)
Definition:StringSwitch.h:83
llvm::SubtargetFeatures
Manages the enabling and disabling of subtarget specific features.
Definition:SubtargetFeature.h:174
llvm::Triple::ArchType
ArchType
Definition:Triple.h:46
llvm::Triple::wasm32
@ wasm32
Definition:Triple.h:103
llvm::Triple::wasm64
@ wasm64
Definition:Triple.h:104
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::Twine::utohexstr
static Twine utohexstr(const uint64_t &Val)
Definition:Twine.h:416
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition:DenseSet.h:213
llvm::object::BasicSymbolRef
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition:SymbolicFile.h:103
llvm::object::BasicSymbolRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition:SymbolicFile.h:210
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition:SymbolicFile.h:111
llvm::object::BasicSymbolRef::SF_Hidden
@ SF_Hidden
Definition:SymbolicFile.h:120
llvm::object::BasicSymbolRef::SF_Executable
@ SF_Executable
Definition:SymbolicFile.h:122
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition:SymbolicFile.h:112
llvm::object::BasicSymbolRef::SF_Undefined
@ SF_Undefined
Definition:SymbolicFile.h:110
llvm::object::BasicSymbolRef::SF_None
@ SF_None
Definition:SymbolicFile.h:109
llvm::object::Binary
Definition:Binary.h:32
llvm::object::Binary::Data
MemoryBufferRef Data
Definition:Binary.h:37
llvm::object::Binary::getData
StringRef getData() const
Definition:Binary.cpp:39
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition:ObjectFile.h:229
llvm::object::ObjectFile::RelocationRef
friend class RelocationRef
Definition:ObjectFile.h:287
llvm::object::ObjectFile::SymbolRef
friend class SymbolRef
Definition:ObjectFile.h:247
llvm::object::ObjectFile::SectionRef
friend class SectionRef
Definition:ObjectFile.h:261
llvm::object::ObjectFile::createWasmObjectFile
static Expected< std::unique_ptr< WasmObjectFile > > createWasmObjectFile(MemoryBufferRef Object)
Definition:WasmObjectFile.cpp:66
llvm::object::ObjectFile::getSymbolValue
Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const
Definition:ObjectFile.cpp:56
llvm::object::RelocationRef
This is a value type class that represents a single relocation in the list of relocations in the obje...
Definition:ObjectFile.h:52
llvm::object::SectionRef
This is a value type class that represents a single section in the list of sections in the object fil...
Definition:ObjectFile.h:81
llvm::object::SymbolRef
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition:ObjectFile.h:168
llvm::object::SymbolRef::ST_Other
@ ST_Other
Definition:ObjectFile.h:174
llvm::object::SymbolRef::ST_Function
@ ST_Function
Definition:ObjectFile.h:178
llvm::object::SymbolRef::ST_Data
@ ST_Data
Definition:ObjectFile.h:175
llvm::object::SymbolRef::ST_Debug
@ ST_Debug
Definition:ObjectFile.h:176
llvm::object::WasmObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition:WasmObjectFile.cpp:1807
llvm::object::WasmObjectFile::section_rel_end
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2035
llvm::object::WasmObjectFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition:WasmObjectFile.cpp:1787
llvm::object::WasmObjectFile::getSectionAlignment
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2008
llvm::object::WasmObjectFile::getRelocationOffset
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Definition:WasmObjectFile.cpp:2045
llvm::object::WasmObjectFile::getSymbolType
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Definition:WasmObjectFile.cpp:1899
llvm::object::WasmObjectFile::getWasmSymbolValue
uint64_t getWasmSymbolValue(const WasmSymbol &Sym) const
Definition:WasmObjectFile.cpp:1854
llvm::object::WasmObjectFile::getSymbolValueImpl
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Definition:WasmObjectFile.cpp:1884
llvm::object::WasmObjectFile::isSectionText
bool isSectionText(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2016
llvm::object::WasmObjectFile::isSectionBSS
bool isSectionBSS(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2024
llvm::object::WasmObjectFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition:WasmObjectFile.cpp:1814
llvm::object::WasmObjectFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition:WasmObjectFile.cpp:1789
llvm::object::WasmObjectFile::section_begin
section_iterator section_begin() const override
Definition:WasmObjectFile.cpp:2084
llvm::object::WasmObjectFile::isRelocatableObject
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
Definition:WasmObjectFile.cpp:2110
llvm::object::WasmObjectFile::moveRelocationNext
void moveRelocationNext(DataRefImpl &Rel) const override
Definition:WasmObjectFile.cpp:2043
llvm::object::WasmObjectFile::getSymbolSectionId
uint32_t getSymbolSectionId(SymbolRef Sym) const
Definition:WasmObjectFile.cpp:1932
llvm::object::WasmObjectFile::isSectionCompressed
bool isSectionCompressed(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2012
llvm::object::WasmObjectFile::isSectionVirtual
bool isSectionVirtual(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2026
llvm::object::WasmObjectFile::getCommonSymbolSizeImpl
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
Definition:WasmObjectFile.cpp:1893
llvm::object::WasmObjectFile::getRelocationTypeName
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
Definition:WasmObjectFile.cpp:2065
llvm::object::WasmObjectFile::getFileFormatName
StringRef getFileFormatName() const override
Definition:WasmObjectFile.cpp:2100
llvm::object::WasmObjectFile::getSymbolName
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
Definition:WasmObjectFile.cpp:1829
llvm::object::WasmObjectFile::section_rel_begin
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2028
llvm::object::WasmObjectFile::getBytesInAddress
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
Definition:WasmObjectFile.cpp:2096
llvm::object::WasmObjectFile::WasmObjectFile
WasmObjectFile(MemoryBufferRef Object, Error &Err)
Definition:WasmObjectFile.cpp:345
llvm::object::WasmObjectFile::section_end
section_iterator section_end() const override
Definition:WasmObjectFile.cpp:2090
llvm::object::WasmObjectFile::getSectionContents
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2001
llvm::object::WasmObjectFile::getSectionIndex
uint64_t getSectionIndex(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:1991
llvm::object::WasmObjectFile::getSymbolAlignment
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Definition:WasmObjectFile.cpp:1888
llvm::object::WasmObjectFile::getSectionSize
uint64_t getSectionSize(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:1995
llvm::object::WasmObjectFile::getArch
Triple::ArchType getArch() const override
Definition:WasmObjectFile.cpp:2102
llvm::object::WasmObjectFile::getRelocationType
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition:WasmObjectFile.cpp:2060
llvm::object::WasmObjectFile::getWasmSection
const WasmSection & getWasmSection(const SectionRef &Section) const
Definition:WasmObjectFile.cpp:2120
llvm::object::WasmObjectFile::getSymbolSection
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
Definition:WasmObjectFile.cpp:1922
llvm::object::WasmObjectFile::getRelocationSymbol
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Definition:WasmObjectFile.cpp:2050
llvm::object::WasmObjectFile::getFeatures
Expected< SubtargetFeatures > getFeatures() const override
Definition:WasmObjectFile.cpp:2106
llvm::object::WasmObjectFile::getHeader
const wasm::WasmObjectHeader & getHeader() const
Definition:WasmObjectFile.cpp:1783
llvm::object::WasmObjectFile::moveSectionNext
void moveSectionNext(DataRefImpl &Sec) const override
Definition:WasmObjectFile.cpp:1972
llvm::object::WasmObjectFile::getNumImportedFunctions
uint32_t getNumImportedFunctions() const
Definition:Wasm.h:160
llvm::object::WasmObjectFile::isSharedObject
bool isSharedObject() const
Definition:WasmObjectFile.cpp:2112
llvm::object::WasmObjectFile::getWasmRelocation
const wasm::WasmRelocation & getWasmRelocation(const RelocationRef &Ref) const
Definition:WasmObjectFile.cpp:2125
llvm::object::WasmObjectFile::getSymbolSize
uint32_t getSymbolSize(SymbolRef Sym) const
Definition:WasmObjectFile.cpp:1956
llvm::object::WasmObjectFile::functions
ArrayRef< wasm::WasmFunction > functions() const
Definition:Wasm.h:155
llvm::object::WasmObjectFile::getWasmSymbol
const WasmSymbol & getWasmSymbol(const DataRefImpl &Symb) const
Definition:WasmObjectFile.cpp:1821
llvm::object::WasmObjectFile::getSectionAddress
uint64_t getSectionAddress(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:1983
llvm::object::WasmObjectFile::getSymbolAddress
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Definition:WasmObjectFile.cpp:1833
llvm::object::WasmObjectFile::isSectionData
bool isSectionData(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:2020
llvm::object::WasmObjectFile::getSectionName
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
Definition:WasmObjectFile.cpp:1974
llvm::object::WasmSectionOrderChecker
Definition:Wasm.h:313
llvm::object::WasmSectionOrderChecker::isValidSectionOrder
bool isValidSectionOrder(unsigned ID, StringRef CustomSectionName="")
Definition:WasmObjectFile.cpp:2229
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_TYPE
@ WASM_SEC_ORDER_TYPE
Definition:Wasm.h:321
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_TARGET_FEATURES
@ WASM_SEC_ORDER_TARGET_FEATURES
Definition:Wasm.h:348
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_NONE
@ WASM_SEC_ORDER_NONE
Definition:Wasm.h:318
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_MEMORY
@ WASM_SEC_ORDER_MEMORY
Definition:Wasm.h:325
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_PRODUCERS
@ WASM_SEC_ORDER_PRODUCERS
Definition:Wasm.h:346
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_CODE
@ WASM_SEC_ORDER_CODE
Definition:Wasm.h:332
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_START
@ WASM_SEC_ORDER_START
Definition:Wasm.h:329
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_RELOC
@ WASM_SEC_ORDER_RELOC
Definition:Wasm.h:341
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_NAME
@ WASM_SEC_ORDER_NAME
Definition:Wasm.h:344
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_DYLINK
@ WASM_SEC_ORDER_DYLINK
Definition:Wasm.h:337
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_LINKING
@ WASM_SEC_ORDER_LINKING
Definition:Wasm.h:339
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_DATA
@ WASM_SEC_ORDER_DATA
Definition:Wasm.h:333
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_TABLE
@ WASM_SEC_ORDER_TABLE
Definition:Wasm.h:324
llvm::object::WasmSectionOrderChecker::WASM_NUM_SEC_ORDERS
@ WASM_NUM_SEC_ORDERS
Definition:Wasm.h:351
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_ELEM
@ WASM_SEC_ORDER_ELEM
Definition:Wasm.h:330
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_GLOBAL
@ WASM_SEC_ORDER_GLOBAL
Definition:Wasm.h:327
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_EXPORT
@ WASM_SEC_ORDER_EXPORT
Definition:Wasm.h:328
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_TAG
@ WASM_SEC_ORDER_TAG
Definition:Wasm.h:326
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_IMPORT
@ WASM_SEC_ORDER_IMPORT
Definition:Wasm.h:322
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_DATACOUNT
@ WASM_SEC_ORDER_DATACOUNT
Definition:Wasm.h:331
llvm::object::WasmSectionOrderChecker::WASM_SEC_ORDER_FUNCTION
@ WASM_SEC_ORDER_FUNCTION
Definition:Wasm.h:323
llvm::object::WasmSectionOrderChecker::DisallowedPredecessors
static int DisallowedPredecessors[WASM_NUM_SEC_ORDERS][WASM_NUM_SEC_ORDERS]
Definition:Wasm.h:356
llvm::object::WasmSymbol
Definition:Wasm.h:35
llvm::object::WasmSymbol::getBinding
unsigned getBinding() const
Definition:Wasm.h:89
llvm::object::WasmSymbol::dump
LLVM_DUMP_METHOD void dump() const
Definition:WasmObjectFile.cpp:62
llvm::object::WasmSymbol::isTypeData
bool isTypeData() const
Definition:Wasm.h:59
llvm::object::WasmSymbol::isHidden
bool isHidden() const
Definition:Wasm.h:93
llvm::object::WasmSymbol::Info
wasm::WasmSymbolInfo Info
Definition:Wasm.h:48
llvm::object::WasmSymbol::print
void print(raw_ostream &Out) const
Definition:WasmObjectFile.cpp:37
llvm::object::WasmSymbol::isDefined
bool isDefined() const
Definition:Wasm.h:71
llvm::object::content_iterator
Definition:SymbolicFile.h:69
llvm::object::symbol_iterator
Definition:ObjectFile.h:208
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
uint32_t
uint64_t
uint8_t
unsigned
Error.h
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
Error.h
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition:ARMBuildAttributes.h:82
llvm::ARM::WinEH::ReturnType
ReturnType
Definition:ARMWinEH.h:25
llvm::TailPredication::Mode
Mode
Definition:ARMTargetTransformInfo.h:43
llvm::dwarf::Index
Index
Definition:Dwarf.h:882
llvm::dwarf::Form
Form
Definition:Dwarf.h:130
llvm::object::Kind
Kind
Definition:COFFModuleDefinition.cpp:31
llvm::object::object_error::invalid_section_index
@ invalid_section_index
llvm::object::object_error::parse_failed
@ parse_failed
llvm::object::section_iterator
content_iterator< SectionRef > section_iterator
Definition:ObjectFile.h:47
llvm::object::relocation_iterator
content_iterator< RelocationRef > relocation_iterator
Definition:ObjectFile.h:77
llvm::omp::RTLDependInfoFields::Flags
@ Flags
llvm::support::endian::read32le
uint32_t read32le(const void *P)
Definition:Endian.h:425
llvm::wasm::WASM_OPCODE_I64_ADD
@ WASM_OPCODE_I64_ADD
Definition:Wasm.h:109
llvm::wasm::WASM_OPCODE_I32_SUB
@ WASM_OPCODE_I32_SUB
Definition:Wasm.h:107
llvm::wasm::WASM_OPCODE_F64_CONST
@ WASM_OPCODE_F64_CONST
Definition:Wasm.h:105
llvm::wasm::WASM_OPCODE_END
@ WASM_OPCODE_END
Definition:Wasm.h:93
llvm::wasm::WASM_OPCODE_I64_MUL
@ WASM_OPCODE_I64_MUL
Definition:Wasm.h:111
llvm::wasm::WASM_OPCODE_REF_NULL
@ WASM_OPCODE_REF_NULL
Definition:Wasm.h:112
llvm::wasm::WASM_OPCODE_GC_PREFIX
@ WASM_OPCODE_GC_PREFIX
Definition:Wasm.h:114
llvm::wasm::WASM_OPCODE_REF_FUNC
@ WASM_OPCODE_REF_FUNC
Definition:Wasm.h:113
llvm::wasm::WASM_OPCODE_F32_CONST
@ WASM_OPCODE_F32_CONST
Definition:Wasm.h:104
llvm::wasm::WASM_OPCODE_GLOBAL_GET
@ WASM_OPCODE_GLOBAL_GET
Definition:Wasm.h:98
llvm::wasm::WASM_OPCODE_I64_SUB
@ WASM_OPCODE_I64_SUB
Definition:Wasm.h:110
llvm::wasm::WASM_OPCODE_I32_MUL
@ WASM_OPCODE_I32_MUL
Definition:Wasm.h:108
llvm::wasm::WASM_OPCODE_I32_ADD
@ WASM_OPCODE_I32_ADD
Definition:Wasm.h:106
llvm::wasm::WASM_OPCODE_I64_CONST
@ WASM_OPCODE_I64_CONST
Definition:Wasm.h:103
llvm::wasm::WASM_OPCODE_I32_CONST
@ WASM_OPCODE_I32_CONST
Definition:Wasm.h:102
llvm::wasm::WASM_SYMBOL_UNDEFINED
const unsigned WASM_SYMBOL_UNDEFINED
Definition:Wasm.h:243
llvm::wasm::WASM_TYPE_ARRAY
@ WASM_TYPE_ARRAY
Definition:Wasm.h:74
llvm::wasm::WASM_TYPE_NULLABLE
@ WASM_TYPE_NULLABLE
Definition:Wasm.h:72
llvm::wasm::WASM_TYPE_I64
@ WASM_TYPE_I64
Definition:Wasm.h:55
llvm::wasm::WASM_TYPE_F64
@ WASM_TYPE_F64
Definition:Wasm.h:57
llvm::wasm::WASM_TYPE_FUNCREF
@ WASM_TYPE_FUNCREF
Definition:Wasm.h:63
llvm::wasm::WASM_TYPE_REC
@ WASM_TYPE_REC
Definition:Wasm.h:78
llvm::wasm::WASM_TYPE_EXTERNREF
@ WASM_TYPE_EXTERNREF
Definition:Wasm.h:64
llvm::wasm::WASM_TYPE_SUB
@ WASM_TYPE_SUB
Definition:Wasm.h:76
llvm::wasm::WASM_TYPE_FUNC
@ WASM_TYPE_FUNC
Definition:Wasm.h:73
llvm::wasm::WASM_TYPE_STRUCT
@ WASM_TYPE_STRUCT
Definition:Wasm.h:75
llvm::wasm::WASM_TYPE_NONNULLABLE
@ WASM_TYPE_NONNULLABLE
Definition:Wasm.h:71
llvm::wasm::WASM_TYPE_I32
@ WASM_TYPE_I32
Definition:Wasm.h:54
llvm::wasm::WASM_TYPE_F32
@ WASM_TYPE_F32
Definition:Wasm.h:56
llvm::wasm::WASM_TYPE_V128
@ WASM_TYPE_V128
Definition:Wasm.h:58
llvm::wasm::WASM_TYPE_SUB_FINAL
@ WASM_TYPE_SUB_FINAL
Definition:Wasm.h:77
llvm::wasm::WASM_TYPE_EXNREF
@ WASM_TYPE_EXNREF
Definition:Wasm.h:65
llvm::wasm::ValType
ValType
Definition:Wasm.h:264
llvm::wasm::ValType::OTHERREF
@ OTHERREF
llvm::wasm::ValType::EXNREF
@ EXNREF
llvm::wasm::ValType::EXTERNREF
@ EXTERNREF
llvm::wasm::ValType::FUNCREF
@ FUNCREF
llvm::wasm::WASM_ELEM_SEGMENT_HAS_INIT_EXPRS
@ WASM_ELEM_SEGMENT_HAS_INIT_EXPRS
Definition:Wasm.h:171
llvm::wasm::WASM_ELEM_SEGMENT_IS_DECLARATIVE
@ WASM_ELEM_SEGMENT_IS_DECLARATIVE
Definition:Wasm.h:169
llvm::wasm::WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER
@ WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER
Definition:Wasm.h:170
llvm::wasm::WASM_ELEM_SEGMENT_IS_PASSIVE
@ WASM_ELEM_SEGMENT_IS_PASSIVE
Definition:Wasm.h:168
llvm::wasm::WASM_EXTERNAL_TABLE
@ WASM_EXTERNAL_TABLE
Definition:Wasm.h:85
llvm::wasm::WASM_EXTERNAL_FUNCTION
@ WASM_EXTERNAL_FUNCTION
Definition:Wasm.h:84
llvm::wasm::WASM_EXTERNAL_TAG
@ WASM_EXTERNAL_TAG
Definition:Wasm.h:88
llvm::wasm::WASM_EXTERNAL_MEMORY
@ WASM_EXTERNAL_MEMORY
Definition:Wasm.h:86
llvm::wasm::WASM_EXTERNAL_GLOBAL
@ WASM_EXTERNAL_GLOBAL
Definition:Wasm.h:87
llvm::wasm::WASM_SYMBOL_BINDING_GLOBAL
const unsigned WASM_SYMBOL_BINDING_GLOBAL
Definition:Wasm.h:238
llvm::wasm::WasmMetadataVersion
const uint32_t WasmMetadataVersion
Definition:Wasm.h:30
llvm::wasm::WASM_SYMBOL_BINDING_WEAK
const unsigned WASM_SYMBOL_BINDING_WEAK
Definition:Wasm.h:239
llvm::wasm::WASM_SYMBOL_BINDING_LOCAL
const unsigned WASM_SYMBOL_BINDING_LOCAL
Definition:Wasm.h:240
llvm::wasm::WASM_NAMES_LOCAL
@ WASM_NAMES_LOCAL
Definition:Wasm.h:185
llvm::wasm::WASM_NAMES_DATA_SEGMENT
@ WASM_NAMES_DATA_SEGMENT
Definition:Wasm.h:187
llvm::wasm::WASM_NAMES_GLOBAL
@ WASM_NAMES_GLOBAL
Definition:Wasm.h:186
llvm::wasm::WASM_NAMES_FUNCTION
@ WASM_NAMES_FUNCTION
Definition:Wasm.h:184
llvm::wasm::WasmSymbolType
WasmSymbolType
Definition:Wasm.h:215
llvm::wasm::WASM_SYMBOL_TYPE_GLOBAL
@ WASM_SYMBOL_TYPE_GLOBAL
Definition:Wasm.h:218
llvm::wasm::WASM_SYMBOL_TYPE_DATA
@ WASM_SYMBOL_TYPE_DATA
Definition:Wasm.h:217
llvm::wasm::WASM_SYMBOL_TYPE_TAG
@ WASM_SYMBOL_TYPE_TAG
Definition:Wasm.h:220
llvm::wasm::WASM_SYMBOL_TYPE_TABLE
@ WASM_SYMBOL_TYPE_TABLE
Definition:Wasm.h:221
llvm::wasm::WASM_SYMBOL_TYPE_SECTION
@ WASM_SYMBOL_TYPE_SECTION
Definition:Wasm.h:219
llvm::wasm::WASM_SYMBOL_TYPE_FUNCTION
@ WASM_SYMBOL_TYPE_FUNCTION
Definition:Wasm.h:216
llvm::wasm::WasmVersion
const uint32_t WasmVersion
Definition:Wasm.h:28
llvm::wasm::WASM_SEC_CODE
@ WASM_SEC_CODE
Definition:Wasm.h:45
llvm::wasm::WASM_SEC_MEMORY
@ WASM_SEC_MEMORY
Definition:Wasm.h:40
llvm::wasm::WASM_SEC_IMPORT
@ WASM_SEC_IMPORT
Definition:Wasm.h:37
llvm::wasm::WASM_SEC_EXPORT
@ WASM_SEC_EXPORT
Definition:Wasm.h:42
llvm::wasm::WASM_SEC_DATACOUNT
@ WASM_SEC_DATACOUNT
Definition:Wasm.h:47
llvm::wasm::WASM_SEC_LAST_KNOWN
@ WASM_SEC_LAST_KNOWN
Definition:Wasm.h:49
llvm::wasm::WASM_SEC_CUSTOM
@ WASM_SEC_CUSTOM
Definition:Wasm.h:35
llvm::wasm::WASM_SEC_FUNCTION
@ WASM_SEC_FUNCTION
Definition:Wasm.h:38
llvm::wasm::WASM_SEC_ELEM
@ WASM_SEC_ELEM
Definition:Wasm.h:44
llvm::wasm::WASM_SEC_START
@ WASM_SEC_START
Definition:Wasm.h:43
llvm::wasm::WASM_SEC_TABLE
@ WASM_SEC_TABLE
Definition:Wasm.h:39
llvm::wasm::WASM_SEC_TYPE
@ WASM_SEC_TYPE
Definition:Wasm.h:36
llvm::wasm::WASM_SEC_TAG
@ WASM_SEC_TAG
Definition:Wasm.h:48
llvm::wasm::WASM_SEC_GLOBAL
@ WASM_SEC_GLOBAL
Definition:Wasm.h:41
llvm::wasm::WASM_SEC_DATA
@ WASM_SEC_DATA
Definition:Wasm.h:46
llvm::wasm::ElemSegmentMode
ElemSegmentMode
Definition:Wasm.h:420
llvm::wasm::ElemSegmentMode::Active
@ Active
llvm::wasm::ElemSegmentMode::Declarative
@ Declarative
llvm::wasm::ElemSegmentMode::Passive
@ Passive
llvm::wasm::WASM_OPCODE_ARRAY_NEW_FIXED
@ WASM_OPCODE_ARRAY_NEW_FIXED
Definition:Wasm.h:123
llvm::wasm::WASM_OPCODE_REF_I31
@ WASM_OPCODE_REF_I31
Definition:Wasm.h:124
llvm::wasm::WASM_OPCODE_ARRAY_NEW_DEFAULT
@ WASM_OPCODE_ARRAY_NEW_DEFAULT
Definition:Wasm.h:122
llvm::wasm::WASM_OPCODE_STRUCT_NEW
@ WASM_OPCODE_STRUCT_NEW
Definition:Wasm.h:119
llvm::wasm::WASM_OPCODE_STRUCT_NEW_DEFAULT
@ WASM_OPCODE_STRUCT_NEW_DEFAULT
Definition:Wasm.h:120
llvm::wasm::WASM_OPCODE_ARRAY_NEW
@ WASM_OPCODE_ARRAY_NEW
Definition:Wasm.h:121
llvm::wasm::WASM_SYMBOL_BINDING_MASK
const unsigned WASM_SYMBOL_BINDING_MASK
Definition:Wasm.h:235
llvm::wasm::WASM_LIMITS_FLAG_HAS_MAX
@ WASM_LIMITS_FLAG_HAS_MAX
Definition:Wasm.h:157
llvm::wasm::WASM_LIMITS_FLAG_IS_64
@ WASM_LIMITS_FLAG_IS_64
Definition:Wasm.h:159
llvm::wasm::NameType
NameType
Definition:Wasm.h:475
llvm::wasm::NameType::DATA_SEGMENT
@ DATA_SEGMENT
llvm::wasm::NameType::FUNCTION
@ FUNCTION
llvm::wasm::NameType::GLOBAL
@ GLOBAL
llvm::wasm::WASM_DATA_SEGMENT_IS_PASSIVE
@ WASM_DATA_SEGMENT_IS_PASSIVE
Definition:Wasm.h:163
llvm::wasm::WASM_DATA_SEGMENT_HAS_MEMINDEX
@ WASM_DATA_SEGMENT_HAS_MEMINDEX
Definition:Wasm.h:164
llvm::wasm::sectionTypeToString
llvm::StringRef sectionTypeToString(uint32_t type)
Definition:Wasm.cpp:41
llvm::wasm::WASM_COMDAT_SECTION
@ WASM_COMDAT_SECTION
Definition:Wasm.h:211
llvm::wasm::WASM_COMDAT_FUNCTION
@ WASM_COMDAT_FUNCTION
Definition:Wasm.h:209
llvm::wasm::WASM_COMDAT_DATA
@ WASM_COMDAT_DATA
Definition:Wasm.h:208
llvm::wasm::WASM_SYMBOL_EXPLICIT_NAME
const unsigned WASM_SYMBOL_EXPLICIT_NAME
Definition:Wasm.h:245
llvm::wasm::WASM_FEATURE_PREFIX_USED
@ WASM_FEATURE_PREFIX_USED
Definition:Wasm.h:177
llvm::wasm::WASM_FEATURE_PREFIX_DISALLOWED
@ WASM_FEATURE_PREFIX_DISALLOWED
Definition:Wasm.h:178
llvm::wasm::WASM_SYMBOL_ABSOLUTE
const unsigned WASM_SYMBOL_ABSOLUTE
Definition:Wasm.h:248
llvm::wasm::WASM_DYLINK_NEEDED
@ WASM_DYLINK_NEEDED
Definition:Wasm.h:201
llvm::wasm::WASM_DYLINK_MEM_INFO
@ WASM_DYLINK_MEM_INFO
Definition:Wasm.h:200
llvm::wasm::WASM_DYLINK_EXPORT_INFO
@ WASM_DYLINK_EXPORT_INFO
Definition:Wasm.h:202
llvm::wasm::WASM_DYLINK_IMPORT_INFO
@ WASM_DYLINK_IMPORT_INFO
Definition:Wasm.h:203
llvm::wasm::WASM_INIT_FUNCS
@ WASM_INIT_FUNCS
Definition:Wasm.h:193
llvm::wasm::WASM_COMDAT_INFO
@ WASM_COMDAT_INFO
Definition:Wasm.h:194
llvm::wasm::WASM_SEGMENT_INFO
@ WASM_SEGMENT_INFO
Definition:Wasm.h:192
llvm::wasm::WASM_SYMBOL_TABLE
@ WASM_SYMBOL_TABLE
Definition:Wasm.h:195
llvm::wasm::WASM_ELEM_SEGMENT_MASK_HAS_ELEM_DESC
const unsigned WASM_ELEM_SEGMENT_MASK_HAS_ELEM_DESC
Definition:Wasm.h:173
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::to_string
std::string to_string(const T &Value)
Definition:ScopedPrinter.h:85
llvm::FeatureCount
@ FeatureCount
Definition:MLRegAllocPriorityAdvisor.cpp:89
llvm::decodeULEB128
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
Definition:LEB128.h:131
llvm::PassSummaryAction::Import
@ Import
Import information from summary.
llvm::decodeSLEB128
int64_t decodeSLEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a SLEB128 value.
Definition:LEB128.h:165
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition:Error.h:1291
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::AsanDtorKind::Global
@ Global
Append to llvm.global_dtors.
llvm::ModRefInfo::Ref
@ Ref
The access may reference the value stored in memory.
llvm::HighlightColor::Tag
@ Tag
llvm::toString
const char * toString(DWARFSectionKind Kind)
Definition:DWARFUnitIndex.h:67
llvm::Version
@ Version
Definition:PGOCtxProfWriter.h:22
llvm::SectionName
Definition:DWARFSection.h:21
llvm::object::WasmObjectFile::ReadContext
Definition:Wasm.h:219
llvm::object::WasmObjectFile::ReadContext::End
const uint8_t * End
Definition:Wasm.h:222
llvm::object::WasmObjectFile::ReadContext::Start
const uint8_t * Start
Definition:Wasm.h:220
llvm::object::WasmObjectFile::ReadContext::Ptr
const uint8_t * Ptr
Definition:Wasm.h:221
llvm::object::WasmSection
Definition:Wasm.h:108
llvm::object::WasmSection::Content
ArrayRef< uint8_t > Content
Definition:Wasm.h:115
llvm::object::WasmSection::Name
StringRef Name
Definition:Wasm.h:113
llvm::object::WasmSection::Relocations
std::vector< wasm::WasmRelocation > Relocations
Definition:Wasm.h:116
llvm::object::WasmSection::Type
uint32_t Type
Definition:Wasm.h:111
llvm::object::WasmSegment
Definition:Wasm.h:121
llvm::object::WasmSegment::Data
wasm::WasmDataSegment Data
Definition:Wasm.h:123
llvm::object::WasmSegment::SectionOffset
uint32_t SectionOffset
Definition:Wasm.h:122
llvm::wasm::WasmDataReference
Definition:Wasm.h:438
llvm::wasm::WasmDataReference::Size
uint64_t Size
Definition:Wasm.h:441
llvm::wasm::WasmDataReference::Segment
uint32_t Segment
Definition:Wasm.h:439
llvm::wasm::WasmDataReference::Offset
uint64_t Offset
Definition:Wasm.h:440
llvm::wasm::WasmDataSegment
Definition:Wasm.h:404
llvm::wasm::WasmDataSegment::MemoryIndex
uint32_t MemoryIndex
Definition:Wasm.h:407
llvm::wasm::WasmDataSegment::LinkingFlags
uint32_t LinkingFlags
Definition:Wasm.h:414
llvm::wasm::WasmDataSegment::Content
ArrayRef< uint8_t > Content
Definition:Wasm.h:411
llvm::wasm::WasmDataSegment::Alignment
uint32_t Alignment
Definition:Wasm.h:413
llvm::wasm::WasmDataSegment::InitFlags
uint32_t InitFlags
Definition:Wasm.h:405
llvm::wasm::WasmDataSegment::Comdat
uint32_t Comdat
Definition:Wasm.h:415
llvm::wasm::WasmDataSegment::Offset
WasmInitExpr Offset
Definition:Wasm.h:409
llvm::wasm::WasmDebugName
Definition:Wasm.h:481
llvm::wasm::WasmDylinkInfo::MemoryAlignment
uint32_t MemoryAlignment
Definition:Wasm.h:291
llvm::wasm::WasmDylinkInfo::Needed
std::vector< StringRef > Needed
Definition:Wasm.h:294
llvm::wasm::WasmDylinkInfo::TableSize
uint32_t TableSize
Definition:Wasm.h:292
llvm::wasm::WasmDylinkInfo::ExportInfo
std::vector< WasmDylinkExportInfo > ExportInfo
Definition:Wasm.h:296
llvm::wasm::WasmDylinkInfo::ImportInfo
std::vector< WasmDylinkImportInfo > ImportInfo
Definition:Wasm.h:295
llvm::wasm::WasmDylinkInfo::TableAlignment
uint32_t TableAlignment
Definition:Wasm.h:293
llvm::wasm::WasmDylinkInfo::MemorySize
uint32_t MemorySize
Definition:Wasm.h:290
llvm::wasm::WasmElemSegment
Definition:Wasm.h:428
llvm::wasm::WasmElemSegment::Offset
WasmInitExpr Offset
Definition:Wasm.h:432
llvm::wasm::WasmElemSegment::Functions
std::vector< uint32_t > Functions
Definition:Wasm.h:433
llvm::wasm::WasmElemSegment::Flags
uint32_t Flags
Definition:Wasm.h:429
llvm::wasm::WasmElemSegment::TableNumber
uint32_t TableNumber
Definition:Wasm.h:430
llvm::wasm::WasmElemSegment::ElemKind
ValType ElemKind
Definition:Wasm.h:431
llvm::wasm::WasmExport
Definition:Wasm.h:310
llvm::wasm::WasmExport::Name
StringRef Name
Definition:Wasm.h:311
llvm::wasm::WasmExport::Kind
uint8_t Kind
Definition:Wasm.h:312
llvm::wasm::WasmExport::Index
uint32_t Index
Definition:Wasm.h:313
llvm::wasm::WasmFeatureEntry
Definition:Wasm.h:305
llvm::wasm::WasmFeatureEntry::Prefix
uint8_t Prefix
Definition:Wasm.h:306
llvm::wasm::WasmFeatureEntry::Name
std::string Name
Definition:Wasm.h:307
llvm::wasm::WasmFunction
Definition:Wasm.h:390
llvm::wasm::WasmFunction::ExportName
std::optional< StringRef > ExportName
Definition:Wasm.h:398
llvm::wasm::WasmFunction::Comdat
uint32_t Comdat
Definition:Wasm.h:401
llvm::wasm::WasmFunction::CodeSectionOffset
uint32_t CodeSectionOffset
Definition:Wasm.h:395
llvm::wasm::WasmGlobalType
Definition:Wasm.h:353
llvm::wasm::WasmGlobalType::Mutable
bool Mutable
Definition:Wasm.h:355
llvm::wasm::WasmGlobalType::Type
uint8_t Type
Definition:Wasm.h:354
llvm::wasm::WasmGlobal
Definition:Wasm.h:358
llvm::wasm::WasmGlobal::Offset
uint32_t Offset
Definition:Wasm.h:363
llvm::wasm::WasmGlobal::Type
WasmGlobalType Type
Definition:Wasm.h:360
llvm::wasm::WasmGlobal::Size
uint32_t Size
Definition:Wasm.h:364
llvm::wasm::WasmImport
Definition:Wasm.h:373
llvm::wasm::WasmImport::Memory
WasmLimits Memory
Definition:Wasm.h:381
llvm::wasm::WasmImport::Kind
uint8_t Kind
Definition:Wasm.h:376
llvm::wasm::WasmImport::Field
StringRef Field
Definition:Wasm.h:375
llvm::wasm::WasmImport::Global
WasmGlobalType Global
Definition:Wasm.h:379
llvm::wasm::WasmImport::Module
StringRef Module
Definition:Wasm.h:374
llvm::wasm::WasmImport::SigIndex
uint32_t SigIndex
Definition:Wasm.h:378
llvm::wasm::WasmImport::Table
WasmTableType Table
Definition:Wasm.h:380
llvm::wasm::WasmInitExprMVP::Int32
int32_t Int32
Definition:Wasm.h:336
llvm::wasm::WasmInitExprMVP::Opcode
uint8_t Opcode
Definition:Wasm.h:334
llvm::wasm::WasmInitExprMVP::Float32
uint32_t Float32
Definition:Wasm.h:338
llvm::wasm::WasmInitExprMVP::Int64
int64_t Int64
Definition:Wasm.h:337
llvm::wasm::WasmInitExprMVP::Global
uint32_t Global
Definition:Wasm.h:340
llvm::wasm::WasmInitExprMVP::Value
union llvm::wasm::WasmInitExprMVP::@187 Value
llvm::wasm::WasmInitExprMVP::Float64
uint64_t Float64
Definition:Wasm.h:339
llvm::wasm::WasmInitExpr
Definition:Wasm.h:346
llvm::wasm::WasmInitExpr::Extended
uint8_t Extended
Definition:Wasm.h:347
llvm::wasm::WasmInitExpr::Inst
WasmInitExprMVP Inst
Definition:Wasm.h:349
llvm::wasm::WasmInitExpr::Body
ArrayRef< uint8_t > Body
Definition:Wasm.h:350
llvm::wasm::WasmInitFunc
Definition:Wasm.h:451
llvm::wasm::WasmLimits
Definition:Wasm.h:316
llvm::wasm::WasmLimits::Flags
uint8_t Flags
Definition:Wasm.h:317
llvm::wasm::WasmLinkingData::InitFunctions
std::vector< WasmInitFunc > InitFunctions
Definition:Wasm.h:490
llvm::wasm::WasmLinkingData::Version
uint32_t Version
Definition:Wasm.h:489
llvm::wasm::WasmLinkingData::Comdats
std::vector< StringRef > Comdats
Definition:Wasm.h:491
llvm::wasm::WasmLocalDecl
Definition:Wasm.h:385
llvm::wasm::WasmLocalDecl::Count
uint32_t Count
Definition:Wasm.h:387
llvm::wasm::WasmLocalDecl::Type
uint8_t Type
Definition:Wasm.h:386
llvm::wasm::WasmObjectHeader
Definition:Wasm.h:258
llvm::wasm::WasmObjectHeader::Magic
StringRef Magic
Definition:Wasm.h:259
llvm::wasm::WasmObjectHeader::Version
uint32_t Version
Definition:Wasm.h:260
llvm::wasm::WasmProducerInfo::SDKs
std::vector< std::pair< std::string, std::string > > SDKs
Definition:Wasm.h:302
llvm::wasm::WasmProducerInfo::Languages
std::vector< std::pair< std::string, std::string > > Languages
Definition:Wasm.h:300
llvm::wasm::WasmProducerInfo::Tools
std::vector< std::pair< std::string, std::string > > Tools
Definition:Wasm.h:301
llvm::wasm::WasmRelocation
Definition:Wasm.h:444
llvm::wasm::WasmRelocation::Addend
int64_t Addend
Definition:Wasm.h:448
llvm::wasm::WasmRelocation::Type
uint8_t Type
Definition:Wasm.h:445
llvm::wasm::WasmRelocation::Offset
uint64_t Offset
Definition:Wasm.h:447
llvm::wasm::WasmRelocation::Index
uint32_t Index
Definition:Wasm.h:446
llvm::wasm::WasmSignature
Definition:Wasm.h:498
llvm::wasm::WasmSignature::Tag
@ Tag
Definition:Wasm.h:504
llvm::wasm::WasmSignature::Placeholder
@ Placeholder
Definition:Wasm.h:504
llvm::wasm::WasmSignature::Returns
SmallVector< ValType, 1 > Returns
Definition:Wasm.h:499
llvm::wasm::WasmSignature::Params
SmallVector< ValType, 4 > Params
Definition:Wasm.h:500
llvm::wasm::WasmSignature::Kind
enum llvm::wasm::WasmSignature::@192 Kind
llvm::wasm::WasmSymbolInfo
Definition:Wasm.h:456
llvm::wasm::WasmSymbolInfo::Flags
uint32_t Flags
Definition:Wasm.h:459
llvm::wasm::WasmSymbolInfo::DataRef
WasmDataReference DataRef
Definition:Wasm.h:471
llvm::wasm::WasmSymbolInfo::Name
StringRef Name
Definition:Wasm.h:457
llvm::wasm::WasmSymbolInfo::Kind
uint8_t Kind
Definition:Wasm.h:458
llvm::wasm::WasmSymbolInfo::ElementIndex
uint32_t ElementIndex
Definition:Wasm.h:469
llvm::wasm::WasmTableType
Definition:Wasm.h:322
llvm::wasm::WasmTableType::ElemType
ValType ElemType
Definition:Wasm.h:323
llvm::wasm::WasmTableType::Limits
WasmLimits Limits
Definition:Wasm.h:324
llvm::wasm::WasmTable
Definition:Wasm.h:327
llvm::wasm::WasmTable::Type
WasmTableType Type
Definition:Wasm.h:329
llvm::wasm::WasmTable::SymbolName
StringRef SymbolName
Definition:Wasm.h:330
llvm::wasm::WasmTag
Definition:Wasm.h:367
llvm::object::DataRefImpl
Definition:SymbolicFile.h:35
llvm::object::DataRefImpl::b
uint32_t b
Definition:SymbolicFile.h:39
llvm::object::DataRefImpl::d
struct llvm::object::DataRefImpl::@370 d
llvm::object::DataRefImpl::a
uint32_t a
Definition:SymbolicFile.h:39

Generated on Fri Jul 18 2025 11:46:02 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp