32 #include <system_error> 34 #define DEBUG_TYPE "wasm-object" 52 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 59 auto ObjectFile = llvm::make_unique<WasmObjectFile>(Buffer, Err);
61 return std::move(Err);
66 #define VARINT7_MAX ((1 << 7) - 1) 67 #define VARINT7_MIN (-(1 << 7)) 68 #define VARUINT7_MAX (1 << 7) 69 #define VARUINT1_MAX (1) 71 static uint8_t
readUint8(WasmObjectFile::ReadContext &Ctx) {
72 if (Ctx.Ptr == Ctx.End)
78 if (Ctx.Ptr + 4 > Ctx.End)
85 static int32_t
readFloat32(WasmObjectFile::ReadContext &Ctx) {
86 if (Ctx.Ptr + 4 > Ctx.End)
89 memcpy(&Result, Ctx.Ptr,
sizeof(Result));
90 Ctx.Ptr +=
sizeof(Result);
94 static int64_t
readFloat64(WasmObjectFile::ReadContext &Ctx) {
95 if (Ctx.Ptr + 8 > Ctx.End)
98 memcpy(&Result, Ctx.Ptr,
sizeof(Result));
99 Ctx.Ptr +=
sizeof(Result);
105 const char *
Error =
nullptr;
106 uint64_t Result =
decodeULEB128(Ctx.Ptr, &Count, Ctx.End, &Error);
115 if (Ctx.Ptr + StringLen > Ctx.End)
118 StringRef(reinterpret_cast<const char *>(Ctx.Ptr), StringLen);
119 Ctx.Ptr += StringLen;
123 static int64_t
readLEB128(WasmObjectFile::ReadContext &Ctx) {
125 const char *
Error =
nullptr;
126 uint64_t Result =
decodeSLEB128(Ctx.Ptr, &Count, Ctx.End, &Error);
142 if (result > INT32_MAX || result < INT32_MIN)
149 if (result > UINT32_MAX)
158 static uint8_t
readOpcode(WasmObjectFile::ReadContext &Ctx) {
163 WasmObjectFile::ReadContext &Ctx) {
183 return make_error<GenericBinaryError>(
"Invalid opcode in init_expr",
189 return make_error<GenericBinaryError>(
"Invalid init_expr",
212 WasmSectionOrderChecker &Checker) {
213 Section.Offset = Ctx.Ptr - Ctx.Start;
215 LLVM_DEBUG(
dbgs() <<
"readSection type=" << Section.Type <<
"\n");
218 return make_error<StringError>(
"Zero length section",
220 if (Ctx.Ptr + Size > Ctx.End)
221 return make_error<StringError>(
"Section too large",
224 WasmObjectFile::ReadContext SectionCtx;
225 SectionCtx.Start = Ctx.Ptr;
226 SectionCtx.Ptr = Ctx.Ptr;
227 SectionCtx.End = Ctx.Ptr +
Size;
231 uint32_t SectionNameSize = SectionCtx.Ptr - SectionCtx.Start;
232 Ctx.Ptr += SectionNameSize;
233 Size -= SectionNameSize;
236 if (!Checker.isValidSectionOrder(Section.Type, Section.Name)) {
237 return make_error<StringError>(
"Out of order section type: " +
258 Ctx.
Start = getPtr(0);
262 if (Ctx.
Ptr + 4 > Ctx.
End) {
263 Err = make_error<StringError>(
"Missing version number",
270 Err = make_error<StringError>(
"Bad version number",
277 while (Ctx.
Ptr < Ctx.
End) {
280 if ((Err = parseSection(Sec)))
283 Sections.push_back(Sec);
294 return parseCustomSection(Sec, Ctx);
296 return parseTypeSection(Ctx);
298 return parseImportSection(Ctx);
300 return parseFunctionSection(Ctx);
302 return parseTableSection(Ctx);
304 return parseMemorySection(Ctx);
306 return parseGlobalSection(Ctx);
308 return parseEventSection(Ctx);
310 return parseExportSection(Ctx);
312 return parseStartSection(Ctx);
314 return parseElemSection(Ctx);
316 return parseCodeSection(Ctx);
318 return parseDataSection(Ctx);
320 return make_error<GenericBinaryError>(
"Bad section type",
336 return make_error<GenericBinaryError>(
"dylink section ended prematurely",
343 if (Functions.size() != FunctionTypes.size()) {
344 return make_error<GenericBinaryError>(
"Names must come after code section",
348 while (Ctx.
Ptr < Ctx.
End) {
351 const uint8_t *SubSectionEnd = Ctx.
Ptr +
Size;
357 if (!Seen.
insert(Index).second)
358 return make_error<GenericBinaryError>(
"Function named more than once",
361 if (!isValidFunctionIndex(Index) || Name.
empty())
362 return make_error<GenericBinaryError>(
"Invalid name entry",
365 if (isDefinedFunctionIndex(Index))
376 if (Ctx.
Ptr != SubSectionEnd)
377 return make_error<GenericBinaryError>(
382 return make_error<GenericBinaryError>(
"Name section ended prematurely",
388 HasLinkingSection =
true;
389 if (Functions.size() != FunctionTypes.size()) {
390 return make_error<GenericBinaryError>(
391 "Linking data must come after code section",
397 return make_error<GenericBinaryError>(
398 "Unexpected metadata version: " +
Twine(LinkingData.
Version) +
403 const uint8_t *OrigEnd = Ctx.
End;
404 while (Ctx.
Ptr < OrigEnd) {
408 LLVM_DEBUG(
dbgs() <<
"readSubsection type=" <<
int(Type) <<
" size=" << Size
413 if (
Error Err = parseLinkingSectionSymtab(Ctx))
418 if (Count > DataSegments.size())
419 return make_error<GenericBinaryError>(
"Too many segment names",
421 for (
uint32_t i = 0; i < Count; i++) {
431 for (
uint32_t i = 0; i < Count; i++) {
435 if (!isValidFunctionSymbol(Init.
Symbol))
436 return make_error<GenericBinaryError>(
"Invalid function symbol: " +
444 if (
Error Err = parseLinkingSectionComdat(Ctx))
452 return make_error<GenericBinaryError>(
455 if (Ctx.
Ptr != OrigEnd)
456 return make_error<GenericBinaryError>(
"Linking section ended prematurely",
464 Symbols.reserve(Count);
467 std::vector<wasm::WasmImport *> ImportedGlobals;
468 std::vector<wasm::WasmImport *> ImportedFunctions;
469 std::vector<wasm::WasmImport *> ImportedEvents;
470 ImportedGlobals.reserve(Imports.size());
471 ImportedFunctions.reserve(Imports.size());
472 ImportedEvents.reserve(Imports.size());
473 for (
auto &
I : Imports) {
475 ImportedFunctions.emplace_back(&
I);
477 ImportedGlobals.emplace_back(&
I);
479 ImportedEvents.emplace_back(&
I);
497 return make_error<GenericBinaryError>(
"invalid function symbol index",
501 unsigned FuncIndex = Info.
ElementIndex - NumImportedFunctions;
502 Signature = &Signatures[FunctionTypes[FuncIndex]];
512 Signature = &Signatures[Import.
SigIndex];
522 return make_error<GenericBinaryError>(
"invalid global symbol index",
526 return make_error<GenericBinaryError>(
"undefined weak global symbol",
530 unsigned GlobalIndex = Info.
ElementIndex - NumImportedGlobals;
532 GlobalType = &Global.
Type;
541 GlobalType = &Import.
Global;
551 if (Index >= DataSegments.size())
552 return make_error<GenericBinaryError>(
"invalid data symbol index",
556 if (Offset + Size > DataSegments[Index].
Data.Content.size())
557 return make_error<GenericBinaryError>(
"invalid data symbol offset",
566 return make_error<GenericBinaryError>(
567 "Section symbols must have local binding",
580 return make_error<GenericBinaryError>(
"invalid event symbol index",
584 return make_error<GenericBinaryError>(
"undefined weak global symbol",
588 unsigned EventIndex = Info.
ElementIndex - NumImportedEvents;
591 EventType = &Event.
Type;
601 EventType = &Import.
Event;
602 Signature = &Signatures[EventType->
SigIndex];
610 return make_error<GenericBinaryError>(
"Invalid symbol type",
617 return make_error<GenericBinaryError>(
"Duplicate symbol name " +
621 Symbols.emplace_back(LinkingData.
SymbolTable.back(), GlobalType, EventType,
623 LLVM_DEBUG(
dbgs() <<
"Adding symbol: " << Symbols.back() <<
"\n");
632 for (
unsigned ComdatIndex = 0; ComdatIndex < ComdatCount; ++ComdatIndex) {
634 if (Name.
empty() || !ComdatSet.
insert(Name).second)
635 return make_error<GenericBinaryError>(
"Bad/duplicate COMDAT name " +
638 LinkingData.
Comdats.emplace_back(Name);
641 return make_error<GenericBinaryError>(
"Unsupported COMDAT flags",
645 while (EntryCount--) {
650 return make_error<GenericBinaryError>(
"Invalid COMDAT entry type",
653 if (Index >= DataSegments.size())
654 return make_error<GenericBinaryError>(
656 if (DataSegments[Index].
Data.Comdat != UINT32_MAX)
657 return make_error<GenericBinaryError>(
"Data segment in two COMDATs",
659 DataSegments[
Index].Data.Comdat = ComdatIndex;
662 if (!isDefinedFunctionIndex(Index))
663 return make_error<GenericBinaryError>(
665 if (getDefinedFunction(Index).
Comdat != UINT32_MAX)
666 return make_error<GenericBinaryError>(
"Function in two COMDATs",
668 getDefinedFunction(Index).
Comdat = ComdatIndex;
678 if (SectionIndex >= Sections.size())
679 return make_error<GenericBinaryError>(
"Invalid section index",
685 while (RelocCount--) {
689 if (Reloc.
Offset < PreviousOffset)
690 return make_error<GenericBinaryError>(
"Relocations not in offset order",
692 PreviousOffset = Reloc.
Offset;
694 switch (Reloc.
Type) {
695 case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
696 case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB:
697 case wasm::R_WEBASSEMBLY_TABLE_INDEX_I32:
698 if (!isValidFunctionSymbol(Reloc.
Index))
699 return make_error<GenericBinaryError>(
"Bad relocation function index",
702 case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB:
703 if (Reloc.
Index >= Signatures.size())
704 return make_error<GenericBinaryError>(
"Bad relocation type index",
707 case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
708 if (!isValidGlobalSymbol(Reloc.
Index))
709 return make_error<GenericBinaryError>(
"Bad relocation global index",
712 case wasm::R_WEBASSEMBLY_EVENT_INDEX_LEB:
713 if (!isValidEventSymbol(Reloc.
Index))
714 return make_error<GenericBinaryError>(
"Bad relocation event index",
717 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
718 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
719 case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
720 if (!isValidDataSymbol(Reloc.
Index))
721 return make_error<GenericBinaryError>(
"Bad relocation data index",
725 case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
726 if (!isValidFunctionSymbol(Reloc.
Index))
727 return make_error<GenericBinaryError>(
"Bad relocation function index",
731 case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32:
732 if (!isValidSectionSymbol(Reloc.
Index))
733 return make_error<GenericBinaryError>(
"Bad relocation section index",
738 return make_error<GenericBinaryError>(
"Bad relocation type: " +
747 if (Reloc.
Type == wasm::R_WEBASSEMBLY_TABLE_INDEX_I32 ||
748 Reloc.
Type == wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32 ||
749 Reloc.
Type == wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32 ||
750 Reloc.
Type == wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32)
752 if (Reloc.
Offset + Size > EndOffset)
753 return make_error<GenericBinaryError>(
"Bad relocation offset",
759 return make_error<GenericBinaryError>(
"Reloc section ended prematurely",
765 if (Sec.
Name ==
"dylink") {
766 if (
Error Err = parseDylinkSection(Ctx))
768 }
else if (Sec.
Name ==
"name") {
769 if (
Error Err = parseNameSection(Ctx))
771 }
else if (Sec.
Name ==
"linking") {
772 if (
Error Err = parseLinkingSection(Ctx))
775 if (
Error Err = parseRelocSection(Sec.
Name, Ctx))
783 Signatures.reserve(Count);
788 return make_error<GenericBinaryError>(
"Invalid signature type",
793 while (ParamCount--) {
799 if (ReturnCount != 1) {
800 return make_error<GenericBinaryError>(
805 Signatures.push_back(std::move(Sig));
808 return make_error<GenericBinaryError>(
"Type section ended prematurely",
815 Imports.reserve(Count);
816 for (
uint32_t i = 0; i < Count; i++) {
823 NumImportedFunctions++;
827 NumImportedGlobals++;
837 return make_error<GenericBinaryError>(
"Invalid table element type",
846 return make_error<GenericBinaryError>(
"Unexpected import kind",
849 Imports.push_back(Im);
852 return make_error<GenericBinaryError>(
"Import section ended prematurely",
859 FunctionTypes.reserve(Count);
860 uint32_t NumTypes = Signatures.size();
863 if (Type >= NumTypes)
864 return make_error<GenericBinaryError>(
"Invalid function type",
866 FunctionTypes.push_back(Type);
869 return make_error<GenericBinaryError>(
"Function section ended prematurely",
876 Tables.reserve(Count);
880 return make_error<GenericBinaryError>(
"Invalid table element type",
885 return make_error<GenericBinaryError>(
"Table section ended prematurely",
892 Memories.reserve(Count);
897 return make_error<GenericBinaryError>(
"Memory section ended prematurely",
903 GlobalSection = Sections.size();
905 Globals.reserve(Count);
908 Global.
Index = NumImportedGlobals + Globals.size();
913 Globals.push_back(Global);
916 return make_error<GenericBinaryError>(
"Global section ended prematurely",
922 EventSection = Sections.size();
924 Events.reserve(Count);
927 Event.
Index = NumImportedEvents + Events.size();
930 Events.push_back(Event);
934 return make_error<GenericBinaryError>(
"Event section ended prematurely",
941 Exports.reserve(Count);
942 for (
uint32_t i = 0; i < Count; i++) {
949 if (!isValidFunctionIndex(Ex.
Index))
950 return make_error<GenericBinaryError>(
"Invalid function export",
954 if (!isValidGlobalIndex(Ex.
Index))
955 return make_error<GenericBinaryError>(
"Invalid global export",
959 if (!isValidEventIndex(Ex.
Index))
960 return make_error<GenericBinaryError>(
"Invalid event export",
967 return make_error<GenericBinaryError>(
"Unexpected export kind",
970 Exports.push_back(Ex);
973 return make_error<GenericBinaryError>(
"Export section ended prematurely",
978 bool WasmObjectFile::isValidFunctionIndex(
uint32_t Index)
const {
979 return Index < NumImportedFunctions + FunctionTypes.size();
982 bool WasmObjectFile::isDefinedFunctionIndex(
uint32_t Index)
const {
983 return Index >= NumImportedFunctions && isValidFunctionIndex(Index);
986 bool WasmObjectFile::isValidGlobalIndex(
uint32_t Index)
const {
987 return Index < NumImportedGlobals + Globals.size();
990 bool WasmObjectFile::isDefinedGlobalIndex(
uint32_t Index)
const {
991 return Index >= NumImportedGlobals && isValidGlobalIndex(Index);
994 bool WasmObjectFile::isValidEventIndex(
uint32_t Index)
const {
995 return Index < NumImportedEvents + Events.size();
998 bool WasmObjectFile::isDefinedEventIndex(
uint32_t Index)
const {
999 return Index >= NumImportedEvents && isValidEventIndex(Index);
1002 bool WasmObjectFile::isValidFunctionSymbol(
uint32_t Index)
const {
1003 return Index < Symbols.size() && Symbols[
Index].isTypeFunction();
1006 bool WasmObjectFile::isValidGlobalSymbol(
uint32_t Index)
const {
1007 return Index < Symbols.size() && Symbols[
Index].isTypeGlobal();
1010 bool WasmObjectFile::isValidEventSymbol(
uint32_t Index)
const {
1011 return Index < Symbols.size() && Symbols[
Index].isTypeEvent();
1014 bool WasmObjectFile::isValidDataSymbol(
uint32_t Index)
const {
1015 return Index < Symbols.size() && Symbols[
Index].isTypeData();
1018 bool WasmObjectFile::isValidSectionSymbol(
uint32_t Index)
const {
1019 return Index < Symbols.size() && Symbols[
Index].isTypeSection();
1023 assert(isDefinedFunctionIndex(Index));
1024 return Functions[Index - NumImportedFunctions];
1028 assert(isDefinedGlobalIndex(Index));
1029 return Globals[Index - NumImportedGlobals];
1033 assert(isDefinedEventIndex(Index));
1034 return Events[Index - NumImportedEvents];
1039 if (!isValidFunctionIndex(StartFunction))
1040 return make_error<GenericBinaryError>(
"Invalid start function",
1046 CodeSection = Sections.size();
1048 if (FunctionCount != FunctionTypes.size()) {
1049 return make_error<GenericBinaryError>(
"Invalid function count",
1053 while (FunctionCount--) {
1055 const uint8_t *FunctionStart = Ctx.
Ptr;
1057 const uint8_t *FunctionEnd = Ctx.
Ptr +
Size;
1060 Function.
Index = NumImportedFunctions + Functions.size();
1062 Function.
Size = FunctionEnd - FunctionStart;
1065 Function.
Locals.reserve(NumLocalDecls);
1066 while (NumLocalDecls--) {
1070 Function.
Locals.push_back(Decl);
1076 Function.
Comdat = UINT32_MAX;
1077 Ctx.
Ptr += BodySize;
1079 Functions.push_back(Function);
1082 return make_error<GenericBinaryError>(
"Code section ended prematurely",
1089 ElemSegments.reserve(Count);
1094 return make_error<GenericBinaryError>(
"Invalid TableIndex",
1100 while (NumElems--) {
1103 ElemSegments.push_back(Segment);
1106 return make_error<GenericBinaryError>(
"Elem section ended prematurely",
1112 DataSection = Sections.size();
1114 DataSegments.reserve(Count);
1121 if (Size > (
size_t)(Ctx.
End - Ctx.
Ptr))
1122 return make_error<GenericBinaryError>(
"Invalid segment size",
1132 DataSegments.push_back(Segment);
1135 return make_error<GenericBinaryError>(
"Data section ended prematurely",
1140 const uint8_t *WasmObjectFile::getPtr(
size_t Offset)
const {
1154 LLVM_DEBUG(
dbgs() <<
"getSymbolFlags: ptr=" << &Sym <<
" " << Sym <<
"\n");
1176 Ref.
d.
a = Symbols.size();
1181 return Symbols[Symb.
d.
a];
1260 Ref.
d.
a = CodeSection;
1263 Ref.
d.
a = GlobalSection;
1266 Ref.
d.
a = DataSection;
1272 Ref.
d.
a = EventSection;
1286 case wasm::WASM_SEC_##X: \ 1309 return std::error_code();
1330 return std::error_code();
1357 RelocRef.
d.
a = Ref.
d.
a;
1365 RelocRef.
d.
a = Ref.
d.
a;
1379 if (Rel.
Type == wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB)
1397 #define WASM_RELOC(name, value) \ 1403 #include "llvm/BinaryFormat/WasmRelocs.def" 1419 Ref.
d.
a = Sections.size();
1439 return Sections[Ref.
d.
a];
1456 assert(Ref.
d.
b < Sec.Relocations.size());
1457 return Sec.Relocations[Ref.
d.
b];
1460 int WasmSectionOrderChecker::getSectionOrder(
unsigned ID,
1465 .Case(
"dylink", WASM_SEC_ORDER_DYLINK)
1466 .
Case(
"linking", WASM_SEC_ORDER_LINKING)
1468 .
Case(
"name", WASM_SEC_ORDER_NAME)
1469 .
Case(
"producers", WASM_SEC_ORDER_PRODUCERS)
1472 return WASM_SEC_ORDER_TYPE;
1474 return WASM_SEC_ORDER_IMPORT;
1476 return WASM_SEC_ORDER_FUNCTION;
1478 return WASM_SEC_ORDER_TABLE;
1480 return WASM_SEC_ORDER_MEMORY;
1482 return WASM_SEC_ORDER_GLOBAL;
1484 return WASM_SEC_ORDER_EXPORT;
1486 return WASM_SEC_ORDER_START;
1488 return WASM_SEC_ORDER_ELEM;
1490 return WASM_SEC_ORDER_CODE;
1492 return WASM_SEC_ORDER_DATA;
1494 return WASM_SEC_ORDER_DATACOUNT;
1496 return WASM_SEC_ORDER_EVENT;
1504 int Order = getSectionOrder(ID, CustomSectionName);
1509 bool IsValid = (LastOrder == Order && Order == WASM_SEC_ORDER_RELOC) ||
bool isSectionText(DataRefImpl Sec) const override
uint64_t getRelocationType(DataRefImpl Rel) const override
static int64_t readFloat64(WasmObjectFile::ReadContext &Ctx)
std::vector< WasmInitFunc > InitFunctions
uint64_t getSectionAddress(DataRefImpl Sec) const override
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
StringRef getFileFormatName() const override
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
uint64_t getSectionSize(DataRefImpl Sec) const override
static Error readInitExpr(wasm::WasmInitExpr &Expr, WasmObjectFile::ReadContext &Ctx)
section_iterator section_begin() const override
const unsigned WASM_SYMBOL_BINDING_LOCAL
const WasmSymbol & getWasmSymbol(const DataRefImpl &Symb) const
Implements a dense probed hash-table based set.
void push_back(const T &Elt)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
const uint32_t WasmMetadataVersion
This class is the base class for all object file types.
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override
SmallVector< wasm::ValType, 1 > Returns
void reserve(size_type N)
std::vector< StringRef > Comdats
std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const override
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
static uint8_t readOpcode(WasmObjectFile::ReadContext &Ctx)
static int64_t readVarint64(WasmObjectFile::ReadContext &Ctx)
const unsigned WASM_SYMBOL_UNDEFINED
std::vector< wasm::WasmRelocation > Relocations
static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, WasmSectionOrderChecker &Checker)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
std::string toString(Error E)
Write all error messages (if any) in E to a string.
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
DataRefImpl getRawDataRefImpl() const
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.
This is a value type class that represents a single relocation in the list of relocations in the obje...
The access may reference the value stored in memory.
Tagged union holding either a T or a Error.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
union llvm::wasm::WasmInitExpr::@143 Value
const uint32_t WasmVersion
bool isValidSectionOrder(unsigned ID, StringRef CustomSectionName="")
ArrayRef< uint8_t > Content
static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx)
content_iterator< SectionRef > section_iterator
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
wasm::WasmDataSegment Data
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
bool isSectionBitcode(DataRefImpl Sec) const override
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Triple::ArchType getArch() const override
uint64_t getSectionIndex(DataRefImpl Sec) const override
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
struct llvm::object::DataRefImpl::@282 d
Analysis containing CSE Info
void moveSectionNext(DataRefImpl &Sec) const override
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
std::vector< uint32_t > Functions
static uint32_t readVaruint32(WasmObjectFile::ReadContext &Ctx)
A switch()-like statement whose cases are string literals.
bool isBindingLocal() const
static int32_t readFloat32(WasmObjectFile::ReadContext &Ctx)
Import information from summary.
LLVM_DUMP_METHOD void dump() const
ArrayRef< uint8_t > Content
The instances of the Type class are immutable: once they are created, they are never changed...
uint64_t getWasmSymbolValue(const WasmSymbol &Sym) const
size_t size() const
size - Get the array size.
bool isSharedObject() const
static uint32_t readUint32(WasmObjectFile::ReadContext &Ctx)
std::pair< iterator, bool > insert(const ValueT &V)
section_iterator section_end() const override
const unsigned WASM_SYMBOL_BINDING_WEAK
uint32_t CodeSectionOffset
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.
const wasm::WasmRelocation & getWasmRelocation(const RelocationRef &Ref) const
uint64_t getSectionAlignment(DataRefImpl Sec) const override
bool isSectionBSS(DataRefImpl Sec) const override
DataRefImpl getRawDataRefImpl() const
bool isSectionData(DataRefImpl Sec) const override
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & StartsWith(StringLiteral S, T Value)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::pair< typename base::iterator, bool > insert(StringRef Key)
basic_symbol_iterator symbol_begin() const override
static Expected< std::unique_ptr< WasmObjectFile > > createWasmObjectFile(MemoryBufferRef Object)
SubtargetFeatures getFeatures() const override
std::vector< StringRef > Needed
bool isSectionCompressed(DataRefImpl Sec) const override
static ErrorSuccess success()
Create a success value.
static uint8_t readVaruint1(WasmObjectFile::ReadContext &Ctx)
friend class RelocationRef
void moveSymbolNext(DataRefImpl &Symb) const override
const unsigned WASM_SYMBOL_EXPLICIT_NAME
uint64_t getSymbolValue(DataRefImpl Symb) const
const wasm::WasmSymbolInfo & Info
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
static uint8_t readUint8(WasmObjectFile::ReadContext &Ctx)
bool isTypeFunction() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static StringRef readString(WasmObjectFile::ReadContext &Ctx)
Manages the enabling and disabling of subtarget specific features.
const wasm::WasmObjectHeader & getHeader() const
static int32_t readVarint32(WasmObjectFile::ReadContext &Ctx)
Helper for Errors used as out-parameters.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
This is a value type class that represents a single symbol in the list of symbols in the object file...
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static int64_t readLEB128(WasmObjectFile::ReadContext &Ctx)
const unsigned WASM_SYMBOL_BINDING_MASK
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
void moveRelocationNext(DataRefImpl &Rel) const override
uint32_t read32le(const void *P)
This is a value type class that represents a single symbol in the list of symbols in the object file...
static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx)
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
const std::string to_string(const T &Value)
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static wasm::WasmTable readTable(WasmObjectFile::ReadContext &Ctx)
WasmDataReference DataRef
Lightweight error class with error context and mandatory checking.
content_iterator< RelocationRef > relocation_iterator
StringSet - A wrapper for StringMap that provides set-like functionality.
This class implements an extremely fast bulk output stream that can only output to a stream...
const WasmSection & getWasmSection(const SectionRef &Section) const
StringRef - Represent a constant reference to a string, i.e.
bool isSectionVirtual(DataRefImpl Sec) const override
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
uint32_t getSymbolFlags(DataRefImpl Symb) const override
std::vector< WasmSymbolInfo > SymbolTable
std::vector< WasmLocalDecl > Locals
SmallVector< wasm::ValType, 4 > Params
bool isBindingWeak() const
StringRef getData() const
relocation_iterator section_rel_end(DataRefImpl Sec) const override
DataRefImpl getRawDataRefImpl() const
This is a value type class that represents a single section in the list of sections in the object fil...
WasmObjectFile(MemoryBufferRef Object, Error &Err)
void print(raw_ostream &Out) const
basic_symbol_iterator symbol_end() const override