32 #include <system_error> 34 #define DEBUG_TYPE "wasm-object" 52 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 59 auto ObjectFile = std::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: " +
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 parseDataCountSection(Ctx);
322 return make_error<GenericBinaryError>(
329 HasDylinkSection =
true;
339 return make_error<GenericBinaryError>(
"dylink section ended prematurely",
346 if (FunctionTypes.size() && !SeenCodeSection) {
347 return make_error<GenericBinaryError>(
"Names must come after code section",
351 while (Ctx.
Ptr < Ctx.
End) {
354 const uint8_t *SubSectionEnd = Ctx.
Ptr +
Size;
360 if (!Seen.
insert(Index).second)
361 return make_error<GenericBinaryError>(
"Function named more than once",
364 if (!isValidFunctionIndex(Index) || Name.
empty())
365 return make_error<GenericBinaryError>(
"Invalid name entry",
368 if (isDefinedFunctionIndex(Index))
379 if (Ctx.
Ptr != SubSectionEnd)
380 return make_error<GenericBinaryError>(
385 return make_error<GenericBinaryError>(
"Name section ended prematurely",
391 HasLinkingSection =
true;
392 if (FunctionTypes.size() && !SeenCodeSection) {
393 return make_error<GenericBinaryError>(
394 "Linking data must come after code section",
400 return make_error<GenericBinaryError>(
401 "Unexpected metadata version: " +
Twine(LinkingData.
Version) +
406 const uint8_t *OrigEnd = Ctx.
End;
407 while (Ctx.
Ptr < OrigEnd) {
411 LLVM_DEBUG(
dbgs() <<
"readSubsection type=" <<
int(Type) <<
" size=" << Size
416 if (
Error Err = parseLinkingSectionSymtab(Ctx))
421 if (Count > DataSegments.size())
422 return make_error<GenericBinaryError>(
"Too many segment names",
438 if (!isValidFunctionSymbol(Init.
Symbol))
439 return make_error<GenericBinaryError>(
"Invalid function symbol: " +
447 if (
Error Err = parseLinkingSectionComdat(Ctx))
455 return make_error<GenericBinaryError>(
458 if (Ctx.
Ptr != OrigEnd)
459 return make_error<GenericBinaryError>(
"Linking section ended prematurely",
467 Symbols.reserve(Count);
470 std::vector<wasm::WasmImport *> ImportedGlobals;
471 std::vector<wasm::WasmImport *> ImportedFunctions;
472 std::vector<wasm::WasmImport *> ImportedEvents;
473 ImportedGlobals.reserve(Imports.size());
474 ImportedFunctions.reserve(Imports.size());
475 ImportedEvents.reserve(Imports.size());
476 for (
auto &
I : Imports) {
478 ImportedFunctions.emplace_back(&
I);
480 ImportedGlobals.emplace_back(&
I);
482 ImportedEvents.emplace_back(&
I);
500 return make_error<GenericBinaryError>(
"invalid function symbol index",
504 unsigned FuncIndex = Info.
ElementIndex - NumImportedFunctions;
505 Signature = &Signatures[FunctionTypes[FuncIndex]];
515 Signature = &Signatures[Import.
SigIndex];
525 return make_error<GenericBinaryError>(
"invalid global symbol index",
529 return make_error<GenericBinaryError>(
"undefined weak global symbol",
533 unsigned GlobalIndex = Info.
ElementIndex - NumImportedGlobals;
535 GlobalType = &Global.
Type;
544 GlobalType = &Import.
Global;
554 if (Index >= DataSegments.size())
555 return make_error<GenericBinaryError>(
"invalid data symbol index",
559 if (Offset + Size > DataSegments[Index].
Data.Content.size())
560 return make_error<GenericBinaryError>(
"invalid data symbol offset",
569 return make_error<GenericBinaryError>(
570 "Section symbols must have local binding",
583 return make_error<GenericBinaryError>(
"invalid event symbol index",
587 return make_error<GenericBinaryError>(
"undefined weak global symbol",
591 unsigned EventIndex = Info.
ElementIndex - NumImportedEvents;
594 EventType = &Event.
Type;
604 EventType = &Import.
Event;
605 Signature = &Signatures[EventType->
SigIndex];
613 return make_error<GenericBinaryError>(
"Invalid symbol type",
620 return make_error<GenericBinaryError>(
"Duplicate symbol name " +
624 Symbols.emplace_back(LinkingData.
SymbolTable.back(), GlobalType, EventType,
626 LLVM_DEBUG(
dbgs() <<
"Adding symbol: " << Symbols.back() <<
"\n");
635 for (
unsigned ComdatIndex = 0; ComdatIndex < ComdatCount; ++ComdatIndex) {
637 if (Name.
empty() || !ComdatSet.
insert(Name).second)
638 return make_error<GenericBinaryError>(
"Bad/duplicate COMDAT name " +
641 LinkingData.
Comdats.emplace_back(Name);
644 return make_error<GenericBinaryError>(
"Unsupported COMDAT flags",
648 while (EntryCount--) {
653 return make_error<GenericBinaryError>(
"Invalid COMDAT entry type",
656 if (Index >= DataSegments.size())
657 return make_error<GenericBinaryError>(
659 if (DataSegments[Index].
Data.Comdat != UINT32_MAX)
660 return make_error<GenericBinaryError>(
"Data segment in two COMDATs",
662 DataSegments[
Index].Data.Comdat = ComdatIndex;
665 if (!isDefinedFunctionIndex(Index))
666 return make_error<GenericBinaryError>(
668 if (getDefinedFunction(Index).
Comdat != UINT32_MAX)
669 return make_error<GenericBinaryError>(
"Function in two COMDATs",
671 getDefinedFunction(Index).
Comdat = ComdatIndex;
682 for (
size_t I = 0;
I < Fields; ++
I) {
684 if (!FieldsSeen.
insert(FieldName).second)
685 return make_error<GenericBinaryError>(
686 "Producers section does not have unique fields",
688 std::vector<std::pair<std::string, std::string>> *ProducerVec =
nullptr;
689 if (FieldName ==
"language") {
691 }
else if (FieldName ==
"processed-by") {
692 ProducerVec = &ProducerInfo.
Tools;
693 }
else if (FieldName ==
"sdk") {
694 ProducerVec = &ProducerInfo.
SDKs;
696 return make_error<GenericBinaryError>(
697 "Producers section field is not named one of language, processed-by, " 703 for (
size_t J = 0; J < ValueCount; ++J) {
706 if (!ProducersSeen.
insert(Name).second) {
707 return make_error<GenericBinaryError>(
708 "Producers section contains repeated producer",
711 ProducerVec->emplace_back(Name, Version);
715 return make_error<GenericBinaryError>(
"Producers section ended prematurely",
723 for (
size_t I = 0;
I < FeatureCount; ++
I) {
732 return make_error<GenericBinaryError>(
"Unknown feature policy prefix",
736 if (!FeaturesSeen.
insert(Feature.
Name).second)
737 return make_error<GenericBinaryError>(
738 "Target features section contains repeated feature \"" +
741 TargetFeatures.push_back(Feature);
744 return make_error<GenericBinaryError>(
745 "Target features section ended prematurely",
752 if (SectionIndex >= Sections.size())
753 return make_error<GenericBinaryError>(
"Invalid section index",
759 while (RelocCount--) {
763 if (Reloc.
Offset < PreviousOffset)
764 return make_error<GenericBinaryError>(
"Relocations not in offset order",
766 PreviousOffset = Reloc.
Offset;
768 switch (Reloc.
Type) {
769 case wasm::R_WASM_FUNCTION_INDEX_LEB:
770 case wasm::R_WASM_TABLE_INDEX_SLEB:
771 case wasm::R_WASM_TABLE_INDEX_I32:
772 case wasm::R_WASM_TABLE_INDEX_REL_SLEB:
773 if (!isValidFunctionSymbol(Reloc.
Index))
774 return make_error<GenericBinaryError>(
"Bad relocation function index",
777 case wasm::R_WASM_TYPE_INDEX_LEB:
778 if (Reloc.
Index >= Signatures.size())
779 return make_error<GenericBinaryError>(
"Bad relocation type index",
782 case wasm::R_WASM_GLOBAL_INDEX_LEB:
785 if (!isValidGlobalSymbol(Reloc.
Index) &&
786 !isValidDataSymbol(Reloc.
Index) &&
787 !isValidFunctionSymbol(Reloc.
Index))
788 return make_error<GenericBinaryError>(
"Bad relocation global index",
791 case wasm::R_WASM_EVENT_INDEX_LEB:
792 if (!isValidEventSymbol(Reloc.
Index))
793 return make_error<GenericBinaryError>(
"Bad relocation event index",
796 case wasm::R_WASM_MEMORY_ADDR_LEB:
797 case wasm::R_WASM_MEMORY_ADDR_SLEB:
798 case wasm::R_WASM_MEMORY_ADDR_I32:
799 case wasm::R_WASM_MEMORY_ADDR_REL_SLEB:
800 if (!isValidDataSymbol(Reloc.
Index))
801 return make_error<GenericBinaryError>(
"Bad relocation data index",
805 case wasm::R_WASM_FUNCTION_OFFSET_I32:
806 if (!isValidFunctionSymbol(Reloc.
Index))
807 return make_error<GenericBinaryError>(
"Bad relocation function index",
811 case wasm::R_WASM_SECTION_OFFSET_I32:
812 if (!isValidSectionSymbol(Reloc.
Index))
813 return make_error<GenericBinaryError>(
"Bad relocation section index",
818 return make_error<GenericBinaryError>(
"Bad relocation type: " +
827 if (Reloc.
Type == wasm::R_WASM_TABLE_INDEX_I32 ||
828 Reloc.
Type == wasm::R_WASM_MEMORY_ADDR_I32 ||
829 Reloc.
Type == wasm::R_WASM_SECTION_OFFSET_I32 ||
830 Reloc.
Type == wasm::R_WASM_FUNCTION_OFFSET_I32)
832 if (Reloc.
Offset + Size > EndOffset)
833 return make_error<GenericBinaryError>(
"Bad relocation offset",
839 return make_error<GenericBinaryError>(
"Reloc section ended prematurely",
845 if (Sec.
Name ==
"dylink") {
846 if (
Error Err = parseDylinkSection(Ctx))
848 }
else if (Sec.
Name ==
"name") {
849 if (
Error Err = parseNameSection(Ctx))
851 }
else if (Sec.
Name ==
"linking") {
852 if (
Error Err = parseLinkingSection(Ctx))
854 }
else if (Sec.
Name ==
"producers") {
855 if (
Error Err = parseProducersSection(Ctx))
857 }
else if (Sec.
Name ==
"target_features") {
858 if (
Error Err = parseTargetFeaturesSection(Ctx))
861 if (
Error Err = parseRelocSection(Sec.
Name, Ctx))
869 Signatures.reserve(Count);
874 return make_error<GenericBinaryError>(
"Invalid signature type",
879 while (ParamCount--) {
884 while (ReturnCount--) {
888 Signatures.push_back(std::move(Sig));
891 return make_error<GenericBinaryError>(
"Type section ended prematurely",
898 Imports.reserve(Count);
906 NumImportedFunctions++;
910 NumImportedGlobals++;
920 return make_error<GenericBinaryError>(
"Invalid table element type",
929 return make_error<GenericBinaryError>(
"Unexpected import kind",
932 Imports.push_back(Im);
935 return make_error<GenericBinaryError>(
"Import section ended prematurely",
942 FunctionTypes.reserve(Count);
943 Functions.resize(Count);
944 uint32_t NumTypes = Signatures.size();
947 if (Type >= NumTypes)
948 return make_error<GenericBinaryError>(
"Invalid function type",
950 FunctionTypes.push_back(Type);
953 return make_error<GenericBinaryError>(
"Function section ended prematurely",
960 Tables.reserve(Count);
964 return make_error<GenericBinaryError>(
"Invalid table element type",
969 return make_error<GenericBinaryError>(
"Table section ended prematurely",
976 Memories.reserve(Count);
981 return make_error<GenericBinaryError>(
"Memory section ended prematurely",
987 GlobalSection = Sections.size();
989 Globals.reserve(Count);
992 Global.
Index = NumImportedGlobals + Globals.size();
997 Globals.push_back(Global);
1000 return make_error<GenericBinaryError>(
"Global section ended prematurely",
1006 EventSection = Sections.size();
1008 Events.reserve(Count);
1011 Event.
Index = NumImportedEvents + Events.size();
1014 Events.push_back(Event);
1018 return make_error<GenericBinaryError>(
"Event section ended prematurely",
1025 Exports.reserve(Count);
1034 if (!isDefinedFunctionIndex(Ex.
Index))
1035 return make_error<GenericBinaryError>(
"Invalid function export",
1040 if (!isValidGlobalIndex(Ex.
Index))
1041 return make_error<GenericBinaryError>(
"Invalid global export",
1045 if (!isValidEventIndex(Ex.
Index))
1046 return make_error<GenericBinaryError>(
"Invalid event export",
1053 return make_error<GenericBinaryError>(
"Unexpected export kind",
1056 Exports.push_back(Ex);
1059 return make_error<GenericBinaryError>(
"Export section ended prematurely",
1064 bool WasmObjectFile::isValidFunctionIndex(
uint32_t Index)
const {
1065 return Index < NumImportedFunctions + FunctionTypes.size();
1068 bool WasmObjectFile::isDefinedFunctionIndex(
uint32_t Index)
const {
1069 return Index >= NumImportedFunctions && isValidFunctionIndex(Index);
1072 bool WasmObjectFile::isValidGlobalIndex(
uint32_t Index)
const {
1073 return Index < NumImportedGlobals + Globals.size();
1076 bool WasmObjectFile::isDefinedGlobalIndex(
uint32_t Index)
const {
1077 return Index >= NumImportedGlobals && isValidGlobalIndex(Index);
1080 bool WasmObjectFile::isValidEventIndex(
uint32_t Index)
const {
1081 return Index < NumImportedEvents + Events.size();
1084 bool WasmObjectFile::isDefinedEventIndex(
uint32_t Index)
const {
1085 return Index >= NumImportedEvents && isValidEventIndex(Index);
1088 bool WasmObjectFile::isValidFunctionSymbol(
uint32_t Index)
const {
1089 return Index < Symbols.size() && Symbols[
Index].isTypeFunction();
1092 bool WasmObjectFile::isValidGlobalSymbol(
uint32_t Index)
const {
1093 return Index < Symbols.size() && Symbols[
Index].isTypeGlobal();
1096 bool WasmObjectFile::isValidEventSymbol(
uint32_t Index)
const {
1097 return Index < Symbols.size() && Symbols[
Index].isTypeEvent();
1100 bool WasmObjectFile::isValidDataSymbol(
uint32_t Index)
const {
1101 return Index < Symbols.size() && Symbols[
Index].isTypeData();
1104 bool WasmObjectFile::isValidSectionSymbol(
uint32_t Index)
const {
1105 return Index < Symbols.size() && Symbols[
Index].isTypeSection();
1109 assert(isDefinedFunctionIndex(Index));
1110 return Functions[Index - NumImportedFunctions];
1114 WasmObjectFile::getDefinedFunction(
uint32_t Index)
const {
1115 assert(isDefinedFunctionIndex(Index));
1116 return Functions[Index - NumImportedFunctions];
1120 assert(isDefinedGlobalIndex(Index));
1121 return Globals[Index - NumImportedGlobals];
1125 assert(isDefinedEventIndex(Index));
1126 return Events[Index - NumImportedEvents];
1131 if (!isValidFunctionIndex(StartFunction))
1132 return make_error<GenericBinaryError>(
"Invalid start function",
1138 SeenCodeSection =
true;
1139 CodeSection = Sections.size();
1141 if (FunctionCount != FunctionTypes.size()) {
1142 return make_error<GenericBinaryError>(
"Invalid function count",
1146 for (
uint32_t i = 0; i < FunctionCount; i++) {
1148 const uint8_t *FunctionStart = Ctx.
Ptr;
1150 const uint8_t *FunctionEnd = Ctx.
Ptr +
Size;
1153 Function.
Index = NumImportedFunctions + i;
1155 Function.
Size = FunctionEnd - FunctionStart;
1158 Function.
Locals.reserve(NumLocalDecls);
1159 while (NumLocalDecls--) {
1163 Function.
Locals.push_back(Decl);
1169 Function.
Comdat = UINT32_MAX;
1170 Ctx.
Ptr += BodySize;
1174 return make_error<GenericBinaryError>(
"Code section ended prematurely",
1181 ElemSegments.reserve(Count);
1186 return make_error<GenericBinaryError>(
"Invalid TableIndex",
1192 while (NumElems--) {
1195 ElemSegments.push_back(Segment);
1198 return make_error<GenericBinaryError>(
"Elem section ended prematurely",
1204 DataSection = Sections.size();
1206 if (DataCount && Count != DataCount.
getValue())
1207 return make_error<GenericBinaryError>(
1208 "Number of data segments does not match DataCount section");
1209 DataSegments.reserve(Count);
1223 if (Size > (
size_t)(Ctx.
End - Ctx.
Ptr))
1224 return make_error<GenericBinaryError>(
"Invalid segment size",
1234 DataSegments.push_back(Segment);
1237 return make_error<GenericBinaryError>(
"Data section ended prematurely",
1257 LLVM_DEBUG(
dbgs() <<
"getSymbolFlags: ptr=" << &Sym <<
" " << Sym <<
"\n");
1281 Ref.
d.
b = Symbols.size();
1286 return Symbols[Symb.
d.
b];
1300 isDefinedFunctionIndex(Sym.Info.ElementIndex))
1370 Ref.
d.
a = CodeSection;
1373 Ref.
d.
a = GlobalSection;
1376 Ref.
d.
a = DataSection;
1382 Ref.
d.
a = EventSection;
1395 case wasm::WASM_SEC_##X: \ 1462 RelocRef.
d.
a = Ref.
d.
a;
1470 RelocRef.
d.
a = Ref.
d.
a;
1484 if (Rel.
Type == wasm::R_WASM_TYPE_INDEX_LEB)
1502 #define WASM_RELOC(name, value) \ 1508 #include "llvm/BinaryFormat/WasmRelocs.def" 1524 Ref.
d.
a = Sections.size();
1544 return Sections[Ref.
d.
a];
1561 assert(Ref.
d.
b < Sec.Relocations.size());
1562 return Sec.Relocations[Ref.
d.
b];
1565 int WasmSectionOrderChecker::getSectionOrder(
unsigned ID,
1570 .Case(
"dylink", WASM_SEC_ORDER_DYLINK)
1571 .
Case(
"linking", WASM_SEC_ORDER_LINKING)
1573 .
Case(
"name", WASM_SEC_ORDER_NAME)
1574 .
Case(
"producers", WASM_SEC_ORDER_PRODUCERS)
1575 .
Case(
"target_features", WASM_SEC_ORDER_TARGET_FEATURES)
1576 .
Default(WASM_SEC_ORDER_NONE);
1578 return WASM_SEC_ORDER_TYPE;
1580 return WASM_SEC_ORDER_IMPORT;
1582 return WASM_SEC_ORDER_FUNCTION;
1584 return WASM_SEC_ORDER_TABLE;
1586 return WASM_SEC_ORDER_MEMORY;
1588 return WASM_SEC_ORDER_GLOBAL;
1590 return WASM_SEC_ORDER_EXPORT;
1592 return WASM_SEC_ORDER_START;
1594 return WASM_SEC_ORDER_ELEM;
1596 return WASM_SEC_ORDER_CODE;
1598 return WASM_SEC_ORDER_DATA;
1600 return WASM_SEC_ORDER_DATACOUNT;
1602 return WASM_SEC_ORDER_EVENT;
1604 return WASM_SEC_ORDER_NONE;
1613 {WASM_SEC_ORDER_TYPE, WASM_SEC_ORDER_IMPORT},
1614 {WASM_SEC_ORDER_IMPORT, WASM_SEC_ORDER_FUNCTION},
1615 {WASM_SEC_ORDER_FUNCTION, WASM_SEC_ORDER_TABLE},
1616 {WASM_SEC_ORDER_TABLE, WASM_SEC_ORDER_MEMORY},
1617 {WASM_SEC_ORDER_MEMORY, WASM_SEC_ORDER_GLOBAL},
1618 {WASM_SEC_ORDER_GLOBAL, WASM_SEC_ORDER_EVENT},
1619 {WASM_SEC_ORDER_EVENT, WASM_SEC_ORDER_EXPORT},
1620 {WASM_SEC_ORDER_EXPORT, WASM_SEC_ORDER_START},
1621 {WASM_SEC_ORDER_START, WASM_SEC_ORDER_ELEM},
1622 {WASM_SEC_ORDER_ELEM, WASM_SEC_ORDER_DATACOUNT},
1623 {WASM_SEC_ORDER_DATACOUNT, WASM_SEC_ORDER_CODE},
1624 {WASM_SEC_ORDER_CODE, WASM_SEC_ORDER_DATA},
1625 {WASM_SEC_ORDER_DATA, WASM_SEC_ORDER_LINKING},
1628 {WASM_SEC_ORDER_DYLINK, WASM_SEC_ORDER_TYPE},
1629 {WASM_SEC_ORDER_LINKING, WASM_SEC_ORDER_RELOC, WASM_SEC_ORDER_NAME},
1631 {WASM_SEC_ORDER_NAME, WASM_SEC_ORDER_PRODUCERS},
1632 {WASM_SEC_ORDER_PRODUCERS, WASM_SEC_ORDER_TARGET_FEATURES},
1633 {WASM_SEC_ORDER_TARGET_FEATURES}
1638 int Order = getSectionOrder(ID, CustomSectionName);
1639 if (Order == WASM_SEC_ORDER_NONE)
1646 bool Checked[WASM_NUM_SEC_ORDERS] = {};
1651 for (
size_t I = 0;; ++
I) {
1652 int Next = DisallowedPredecessors[Curr][
I];
1653 if (Next == WASM_SEC_ORDER_NONE)
1658 Checked[Next] =
true;
1661 if (WorkList.
empty())
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.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
const WasmSymbol & getWasmSymbol(const DataRefImpl &Symb) const
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
void push_back(const T &Elt)
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
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::vector< std::pair< std::string, std::string > > Languages
StringSwitch & StartsWith(StringLiteral S, T Value)
void reserve(size_type N)
std::vector< StringRef > Comdats
StringSwitch & Case(StringLiteral S, T Value)
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
static uint8_t readOpcode(WasmObjectFile::ReadContext &Ctx)
static int DisallowedPredecessors[WASM_NUM_SEC_ORDERS][WASM_NUM_SEC_ORDERS]
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)
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.
LLVM_NODISCARD R Default(T Value)
SmallVector< ValType, 1 > Returns
Tagged union holding either a T or a Error.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
const uint32_t WasmVersion
bool isValidSectionOrder(unsigned ID, StringRef CustomSectionName="")
SmallVector< ValType, 4 > Params
ArrayRef< uint8_t > Content
static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx)
content_iterator< SectionRef > section_iterator
union llvm::wasm::WasmInitExpr::@151 Value
wasm::WasmDataSegment Data
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
const T & getValue() const LLVM_LVALUE_FUNCTION
LLVM_NODISCARD size_t size() const
size - Get the string size.
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
Analysis containing CSE Info
struct llvm::object::DataRefImpl::@292 d
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)
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
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
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
bool isSectionBSS(DataRefImpl Sec) const override
DataRefImpl getRawDataRefImpl() const
std::vector< std::pair< std::string, std::string > > SDKs
bool isSectionData(DataRefImpl Sec) const override
#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
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
uint64_t getSymbolValue(DataRefImpl Symb) const
LLVM_NODISCARD T pop_back_val()
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.
std::vector< std::pair< std::string, std::string > > Tools
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.
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.
const unsigned char * bytes_begin() const
static int64_t readLEB128(WasmObjectFile::ReadContext &Ctx)
LLVM_NODISCARD bool empty() const
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
bool isBindingWeak() const
StringRef getData() const
relocation_iterator section_rel_end(DataRefImpl Sec) const override
DataRefImpl getRawDataRefImpl() const
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
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