LLVM: lib/Object/WasmObjectFile.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
28#include
29#include
30#include
31
32#define DEBUG_TYPE "wasm-object"
33
34using namespace llvm;
35using namespace object;
36
38 Out << "Name=" << Info.Name
45 }
47 Out << ", hidden";
48 } else {
49 Out << ", default";
50 }
51 Out << "]";
53 Out << ", ElemIndex=" << Info.ElementIndex;
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)
63#endif
64
68 auto ObjectFile = std::make_unique(Buffer, Err);
69 if (Err)
70 return std::move(Err);
71
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
81 if (Ctx.Ptr == Ctx.End)
83 return *Ctx.Ptr++;
84}
85
87 if (Ctx.Ptr + 4 > Ctx.End)
90 Ctx.Ptr += 4;
91 return Result;
92}
93
95 if (Ctx.Ptr + 4 > Ctx.End)
97 int32_t Result = 0;
98 memcpy(&Result, Ctx.Ptr, sizeof(Result));
99 Ctx.Ptr += sizeof(Result);
100 return Result;
101}
102
104 if (Ctx.Ptr + 8 > Ctx.End)
106 int64_t Result = 0;
107 memcpy(&Result, Ctx.Ptr, sizeof(Result));
108 Ctx.Ptr += sizeof(Result);
109 return Result;
110}
111
114 const char *Error = nullptr;
118 Ctx.Ptr += Count;
119 return Result;
120}
121
124 if (Ctx.Ptr + StringLen > Ctx.End)
127 StringRef(reinterpret_cast<const char *>(Ctx.Ptr), StringLen);
128 Ctx.Ptr += StringLen;
129 return Return;
130}
131
134 const char *Error = nullptr;
138 Ctx.Ptr += Count;
139 return Result;
140}
141
148
151 if (Result > INT32_MAX || Result < INT32_MIN)
153 return Result;
154}
155
158 if (Result > UINT32_MAX)
160 return Result;
161}
162
166
170
174
177
178
179 switch (Code) {
189 }
192 }
194}
195
198 auto Start = Ctx.Ptr;
199
205 break;
208 break;
211 break;
214 break;
217 break;
220 break;
221 }
222 default:
224 }
225
230 }
231
233 Ctx.Ptr = Start;
234 while (true) {
236 switch (Opcode) {
243 break;
246 break;
249 break;
256 break;
258 break;
259
260
261
267 break;
271 break;
273 break;
277 default:
279 Twine("invalid opcode in init_expr: ") + Twine(unsigned(Opcode)),
281 }
282 }
283 }
284
286}
287
296 if (PageSizeLog2 >= 32)
298 Result.PageSize = 1 << PageSizeLog2;
299 }
300 return Result;
301}
302
306 TableType.ElemType = ElemType;
308 return TableType;
309}
310
314 LLVM_DEBUG(dbgs() << "readSection type=" << Section.Type << "\n");
315
316
317 const uint8_t *PreSizePtr = Ctx.Ptr;
319 Section.HeaderSecSizeEncodingLen = Ctx.Ptr - PreSizePtr;
320 Section.Offset = Ctx.Ptr - Ctx.Start;
321 if (Size == 0)
324 if (Ctx.Ptr + Size > Ctx.End)
329 SectionCtx.Start = Ctx.Ptr;
330 SectionCtx.Ptr = Ctx.Ptr;
331 SectionCtx.End = Ctx.Ptr + Size;
332
333 Section.Name = readString(SectionCtx);
334
335 uint32_t SectionNameSize = SectionCtx.Ptr - SectionCtx.Start;
336 Ctx.Ptr += SectionNameSize;
337 Size -= SectionNameSize;
338 }
339
344 }
345
347 Ctx.Ptr += Size;
349}
350
355 if (Header.Magic != StringRef("\0asm", 4)) {
358 return;
359 }
360
363 Ctx.Ptr = Ctx.Start + 4;
365
366 if (Ctx.Ptr + 4 > Ctx.End) {
369 return;
370 }
371
375 Twine(Header.Version),
377 return;
378 }
379
381 while (Ctx.Ptr < Ctx.End) {
383 if ((Err = readSection(Sec, Ctx, Checker)))
384 return;
385 if ((Err = parseSection(Sec)))
386 return;
387
388 Sections.push_back(Sec);
389 }
390}
391
393 ReadContext Ctx;
395 Ctx.End = Ctx.Start + Sec.Content.size();
396 Ctx.Ptr = Ctx.Start;
397 switch (Sec.Type) {
399 return parseCustomSection(Sec, Ctx);
401 return parseTypeSection(Ctx);
403 return parseImportSection(Ctx);
405 return parseFunctionSection(Ctx);
407 return parseTableSection(Ctx);
409 return parseMemorySection(Ctx);
411 return parseTagSection(Ctx);
413 return parseGlobalSection(Ctx);
415 return parseExportSection(Ctx);
417 return parseStartSection(Ctx);
419 return parseElemSection(Ctx);
421 return parseCodeSection(Ctx);
423 return parseDataSection(Ctx);
425 return parseDataCountSection(Ctx);
426 default:
429 }
430}
431
432Error WasmObjectFile::parseDylinkSection(ReadContext &Ctx) {
433
434
435 HasDylinkSection = true;
441 while (Count--) {
443 }
444
445 if (Ctx.Ptr != Ctx.End)
449}
450
451Error WasmObjectFile::parseDylink0Section(ReadContext &Ctx) {
452
453
454 HasDylinkSection = true;
455
456 const uint8_t *OrigEnd = Ctx.End;
457 while (Ctx.Ptr < OrigEnd) {
458 Ctx.End = OrigEnd;
462 << "\n");
463 Ctx.End = Ctx.Ptr + Size;
465 switch (Type) {
471 break;
474 while (Count--) {
475 DylinkInfo.Needed.push_back(readString(Ctx));
476 }
477 break;
480 while (Count--) {
482 }
483 break;
484 }
487 while (Count--) {
488 DylinkInfo.ImportInfo.push_back(
490 }
491 break;
492 }
495 while (Count--) {
496 DylinkInfo.RuntimePath.push_back(readString(Ctx));
497 }
498 break;
499 }
500 default:
501 LLVM_DEBUG(dbgs() << "unknown dylink.0 sub-section: " << Type << "\n");
502 Ctx.Ptr += Size;
503 break;
504 }
505 if (Ctx.Ptr != Ctx.End) {
508 }
509 }
510
511 if (Ctx.Ptr != Ctx.End)
515}
516
517Error WasmObjectFile::parseNameSection(ReadContext &Ctx) {
518 llvm::DenseSet<uint64_t> SeenFunctions;
519 llvm::DenseSet<uint64_t> SeenGlobals;
520 llvm::DenseSet<uint64_t> SeenSegments;
521
522
523
524 bool PopulateSymbolTable = !HasLinkingSection && !HasDylinkSection;
525
526
527
528 if (PopulateSymbolTable)
529 Symbols.clear();
530
531 while (Ctx.Ptr < Ctx.End) {
534 const uint8_t *SubSectionEnd = Ctx.Ptr + Size;
535
536 switch (Type) {
541 while (Count--) {
545 wasm::WasmSymbolInfo Info{Name,
547 0,
548 std::nullopt,
549 std::nullopt,
550 std::nullopt,
551 { Index}};
552 const wasm::WasmSignature *Signature = nullptr;
553 const wasm::WasmGlobalType *GlobalType = nullptr;
554 const wasm::WasmTableType *TableType = nullptr;
556 if (!SeenFunctions.insert(Index).second)
559 if (!isValidFunctionIndex(Index) || Name.empty())
562
563 if (isDefinedFunctionIndex(Index)) {
564 wasm::WasmFunction &F = getDefinedFunction(Index);
566 Signature = &Signatures[F.SigIndex];
567 if (F.ExportName) {
568 Info.ExportName = F.ExportName;
570 } else {
572 }
573 } else {
575 }
577 if (!SeenGlobals.insert(Index).second)
580 if (!isValidGlobalIndex(Index) || Name.empty())
585 if (isDefinedGlobalIndex(Index)) {
586 GlobalType = &getDefinedGlobal(Index).Type;
587 } else {
589 }
590 } else {
591 if (!SeenSegments.insert(Index).second)
594 if (Index > DataSegments.size())
600 assert(Index < DataSegments.size());
601 Info.DataRef = wasm::WasmDataReference{
602 Index, 0, DataSegments[Index].Data.Content.size()};
603 }
604 DebugNames.push_back(wasm::WasmDebugName{nameType, Index, Name});
605 if (PopulateSymbolTable)
606 Symbols.emplace_back(Info, GlobalType, TableType, Signature);
607 }
608 break;
609 }
610
612 default:
613 Ctx.Ptr += Size;
614 break;
615 }
616 if (Ctx.Ptr != SubSectionEnd)
619 }
620
621 if (Ctx.Ptr != Ctx.End)
625}
626
627Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) {
628 HasLinkingSection = true;
629
633 "unexpected metadata version: " + Twine(LinkingData.Version) +
636 }
637
638 const uint8_t *OrigEnd = Ctx.End;
639 while (Ctx.Ptr < OrigEnd) {
640 Ctx.End = OrigEnd;
644 << "\n");
645 Ctx.End = Ctx.Ptr + Size;
646 switch (Type) {
648 if (Error Err = parseLinkingSectionSymtab(Ctx))
649 return Err;
650 break;
653 if (Count > DataSegments.size())
656 for (uint32_t I = 0; I < Count; I++) {
657 DataSegments[I].Data.Name = readString(Ctx);
659 DataSegments[I].Data.LinkingFlags = readVaruint32(Ctx);
660 }
661 break;
662 }
665 LinkingData.InitFunctions.reserve(Count);
666 for (uint32_t I = 0; I < Count; I++) {
667 wasm::WasmInitFunc Init;
670 if (!isValidFunctionSymbol(Init.Symbol))
674 LinkingData.InitFunctions.emplace_back(Init);
675 }
676 break;
677 }
679 if (Error Err = parseLinkingSectionComdat(Ctx))
680 return Err;
681 break;
682 default:
683 Ctx.Ptr += Size;
684 break;
685 }
686 if (Ctx.Ptr != Ctx.End)
689 }
690 if (Ctx.Ptr != OrigEnd)
694}
695
696Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
698
699
700 Symbols.clear();
701 Symbols.reserve(Count);
702 StringSet<> SymbolNames;
703
704 std::vector<wasm::WasmImport *> ImportedGlobals;
705 std::vector<wasm::WasmImport *> ImportedFunctions;
706 std::vector<wasm::WasmImport *> ImportedTags;
707 std::vector<wasm::WasmImport *> ImportedTables;
708 ImportedGlobals.reserve(Imports.size());
709 ImportedFunctions.reserve(Imports.size());
710 ImportedTags.reserve(Imports.size());
711 ImportedTables.reserve(Imports.size());
712 for (auto &I : Imports) {
714 ImportedFunctions.emplace_back(&I);
716 ImportedGlobals.emplace_back(&I);
718 ImportedTags.emplace_back(&I);
720 ImportedTables.emplace_back(&I);
721 }
722
723 while (Count--) {
724 wasm::WasmSymbolInfo Info;
725 const wasm::WasmSignature *Signature = nullptr;
726 const wasm::WasmGlobalType *GlobalType = nullptr;
727 const wasm::WasmTableType *TableType = nullptr;
728
732
733 switch (Info.Kind) {
736 if (!isValidFunctionIndex(Info.ElementIndex) ||
737 IsDefined != isDefinedFunctionIndex(Info.ElementIndex))
740 if (IsDefined) {
742 unsigned FuncIndex = Info.ElementIndex - NumImportedFunctions;
743 wasm::WasmFunction &Function = Functions[FuncIndex];
744 Signature = &Signatures[Function.SigIndex];
745 if (Function.SymbolName.empty())
747 } else {
748 wasm::WasmImport &Import = *ImportedFunctions[Info.ElementIndex];
752 } else {
754 }
755 Signature = &Signatures[Import.SigIndex];
757 }
758 break;
759
762 if (!isValidGlobalIndex(Info.ElementIndex) ||
763 IsDefined != isDefinedGlobalIndex(Info.ElementIndex))
770 if (IsDefined) {
772 unsigned GlobalIndex = Info.ElementIndex - NumImportedGlobals;
773 wasm::WasmGlobal &Global = Globals[GlobalIndex];
775 if (Global.SymbolName.empty())
777 } else {
778 wasm::WasmImport &Import = *ImportedGlobals[Info.ElementIndex];
782 } else {
784 }
785 GlobalType = &Import.Global;
787 }
788 break;
789
792 if (!isValidTableNumber(Info.ElementIndex) ||
793 IsDefined != isDefinedTableNumber(Info.ElementIndex))
800 if (IsDefined) {
802 unsigned TableNumber = Info.ElementIndex - NumImportedTables;
803 wasm::WasmTable &Table = Tables[TableNumber];
804 TableType = &Table.Type;
807 } else {
808 wasm::WasmImport &Import = *ImportedTables[Info.ElementIndex];
812 } else {
814 }
815 TableType = &Import.Table;
817 }
818 break;
819
822 if (IsDefined) {
827 if (static_cast<size_t>(Index) >= DataSegments.size())
829 "invalid data segment index: " + Twine(Index),
831 size_t SegmentSize = DataSegments[Index].Data.Content.size();
832 if (Offset > SegmentSize)
834 "invalid data symbol offset: `" + Info.Name +
835 "` (offset: " + Twine(Offset) +
836 " segment size: " + Twine(SegmentSize) + ")",
838 }
840 }
841 break;
842
847 "section symbols must have local binding",
850
851 StringRef SectionName = Sections[Info.ElementIndex].Name;
853 break;
854 }
855
858 if (!isValidTagIndex(Info.ElementIndex) ||
859 IsDefined != isDefinedTagIndex(Info.ElementIndex))
866 if (IsDefined) {
868 unsigned TagIndex = Info.ElementIndex - NumImportedTags;
869 wasm::WasmTag &Tag = Tags[TagIndex];
870 Signature = &Signatures[Tag.SigIndex];
871 if (Tag.SymbolName.empty())
872 Tag.SymbolName = Info.Name;
873
874 } else {
875 wasm::WasmImport &Import = *ImportedTags[Info.ElementIndex];
879 } else {
881 }
882 Signature = &Signatures[Import.SigIndex];
884 }
885 break;
886 }
887
888 default:
890 Twine(unsigned(Info.Kind)),
892 }
893
896 !SymbolNames.insert(Info.Name).second)
898 Twine(Info.Name),
900 Symbols.emplace_back(Info, GlobalType, TableType, Signature);
901 LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n");
902 }
903
905}
906
907Error WasmObjectFile::parseLinkingSectionComdat(ReadContext &Ctx) {
909 StringSet<> ComdatSet;
910 for (unsigned ComdatIndex = 0; ComdatIndex < ComdatCount; ++ComdatIndex) {
912 if (Name.empty() || !ComdatSet.insert(Name).second)
914 Twine(Name),
916 LinkingData.Comdats.emplace_back(Name);
918 if (Flags != 0)
921
923 while (EntryCount--) {
926 switch (Kind) {
927 default:
931 if (Index >= DataSegments.size())
934 if (DataSegments[Index].Data.Comdat != UINT32_MAX)
937 DataSegments[Index].Data.Comdat = ComdatIndex;
938 break;
940 if (!isDefinedFunctionIndex(Index))
943 if (getDefinedFunction(Index).Comdat != UINT32_MAX)
946 getDefinedFunction(Index).Comdat = ComdatIndex;
947 break;
949 if (Index >= Sections.size())
955 Sections[Index].Comdat = ComdatIndex;
956 break;
957 }
958 }
959 }
961}
962
963Error WasmObjectFile::parseProducersSection(ReadContext &Ctx) {
964 llvm::SmallSet<StringRef, 3> FieldsSeen;
966 for (size_t I = 0; I < Fields; ++I) {
967 StringRef FieldName = readString(Ctx);
968 if (!FieldsSeen.insert(FieldName).second)
970 "producers section does not have unique fields",
972 std::vector<std::pair<std::string, std::string>> *ProducerVec = nullptr;
973 if (FieldName == "language") {
974 ProducerVec = &ProducerInfo.Languages;
975 } else if (FieldName == "processed-by") {
976 ProducerVec = &ProducerInfo.Tools;
977 } else if (FieldName == "sdk") {
978 ProducerVec = &ProducerInfo.SDKs;
979 } else {
981 "producers section field is not named one of language, processed-by, "
982 "or sdk",
984 }
986 llvm::SmallSet<StringRef, 8> ProducersSeen;
987 for (size_t J = 0; J < ValueCount; ++J) {
990 if (!ProducersSeen.insert(Name).second) {
992 "producers section contains repeated producer",
994 }
995 ProducerVec->emplace_back(std::string(Name), std::string(Version));
996 }
997 }
998 if (Ctx.Ptr != Ctx.End)
1002}
1003
1004Error WasmObjectFile::parseTargetFeaturesSection(ReadContext &Ctx) {
1005 llvm::SmallSet<std::string, 8> FeaturesSeen;
1008 wasm::WasmFeatureEntry Feature;
1010 switch (Feature.Prefix) {
1013 break;
1014 default:
1017 }
1019 if (!FeaturesSeen.insert(Feature.Name).second)
1021 "target features section contains repeated feature \"" +
1022 Feature.Name + "\"",
1024 TargetFeatures.push_back(Feature);
1025 }
1026 if (Ctx.Ptr != Ctx.End)
1028 "target features section ended prematurely",
1031}
1032
1033Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) {
1035 if (SectionIndex >= Sections.size())
1038 WasmSection &Section = Sections[SectionIndex];
1040 uint32_t EndOffset = Section.Content.size();
1041 uint32_t PreviousOffset = 0;
1042 while (RelocCount--) {
1043 wasm::WasmRelocation Reloc = {};
1045 Reloc.Type = type;
1047 if (Reloc.Offset < PreviousOffset)
1050
1051 auto badReloc = [&](StringRef msg) {
1053 msg + ": " + Twine(Symbols[Reloc.Index].Info.Name),
1055 };
1056
1057 PreviousOffset = Reloc.Offset;
1059 switch (type) {
1060 case wasm::R_WASM_FUNCTION_INDEX_LEB:
1061 case wasm::R_WASM_FUNCTION_INDEX_I32:
1062 case wasm::R_WASM_TABLE_INDEX_SLEB:
1063 case wasm::R_WASM_TABLE_INDEX_SLEB64:
1064 case wasm::R_WASM_TABLE_INDEX_I32:
1065 case wasm::R_WASM_TABLE_INDEX_I64:
1066 case wasm::R_WASM_TABLE_INDEX_REL_SLEB:
1067 case wasm::R_WASM_TABLE_INDEX_REL_SLEB64:
1068 if (!isValidFunctionSymbol(Reloc.Index))
1069 return badReloc("invalid function relocation");
1070 break;
1071 case wasm::R_WASM_TABLE_NUMBER_LEB:
1072 if (!isValidTableSymbol(Reloc.Index))
1073 return badReloc("invalid table relocation");
1074 break;
1075 case wasm::R_WASM_TYPE_INDEX_LEB:
1076 if (Reloc.Index >= Signatures.size())
1077 return badReloc("invalid relocation type index");
1078 break;
1079 case wasm::R_WASM_GLOBAL_INDEX_LEB:
1080
1081
1082 if (!isValidGlobalSymbol(Reloc.Index) &&
1083 !isValidDataSymbol(Reloc.Index) &&
1084 !isValidFunctionSymbol(Reloc.Index))
1085 return badReloc("invalid global relocation");
1086 break;
1087 case wasm::R_WASM_GLOBAL_INDEX_I32:
1088 if (!isValidGlobalSymbol(Reloc.Index))
1089 return badReloc("invalid global relocation");
1090 break;
1091 case wasm::R_WASM_TAG_INDEX_LEB:
1092 if (!isValidTagSymbol(Reloc.Index))
1093 return badReloc("invalid tag relocation");
1094 break;
1095 case wasm::R_WASM_MEMORY_ADDR_LEB:
1096 case wasm::R_WASM_MEMORY_ADDR_SLEB:
1097 case wasm::R_WASM_MEMORY_ADDR_I32:
1098 case wasm::R_WASM_MEMORY_ADDR_REL_SLEB:
1099 case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB:
1100 case wasm::R_WASM_MEMORY_ADDR_LOCREL_I32:
1101 if (!isValidDataSymbol(Reloc.Index))
1102 return badReloc("invalid data relocation");
1104 break;
1105 case wasm::R_WASM_MEMORY_ADDR_LEB64:
1106 case wasm::R_WASM_MEMORY_ADDR_SLEB64:
1107 case wasm::R_WASM_MEMORY_ADDR_I64:
1108 case wasm::R_WASM_MEMORY_ADDR_REL_SLEB64:
1109 case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB64:
1110 if (!isValidDataSymbol(Reloc.Index))
1111 return badReloc("invalid data relocation");
1113 break;
1114 case wasm::R_WASM_FUNCTION_OFFSET_I32:
1115 if (!isValidFunctionSymbol(Reloc.Index))
1116 return badReloc("invalid function relocation");
1118 break;
1119 case wasm::R_WASM_FUNCTION_OFFSET_I64:
1120 if (!isValidFunctionSymbol(Reloc.Index))
1121 return badReloc("invalid function relocation");
1123 break;
1124 case wasm::R_WASM_SECTION_OFFSET_I32:
1125 if (!isValidSectionSymbol(Reloc.Index))
1126 return badReloc("invalid section relocation");
1128 break;
1129 default:
1131 Twine(type),
1133 }
1134
1135
1136
1137
1138 uint64_t Size = 5;
1139 if (Reloc.Type == wasm::R_WASM_MEMORY_ADDR_LEB64 ||
1140 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_SLEB64 ||
1141 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_REL_SLEB64)
1143 if (Reloc.Type == wasm::R_WASM_TABLE_INDEX_I32 ||
1144 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_I32 ||
1145 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_LOCREL_I32 ||
1146 Reloc.Type == wasm::R_WASM_SECTION_OFFSET_I32 ||
1147 Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I32 ||
1148 Reloc.Type == wasm::R_WASM_FUNCTION_INDEX_I32 ||
1149 Reloc.Type == wasm::R_WASM_GLOBAL_INDEX_I32)
1151 if (Reloc.Type == wasm::R_WASM_TABLE_INDEX_I64 ||
1152 Reloc.Type == wasm::R_WASM_MEMORY_ADDR_I64 ||
1153 Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I64)
1155 if (Reloc.Offset + Size > EndOffset)
1158
1159 Section.Relocations.push_back(Reloc);
1160 }
1161 if (Ctx.Ptr != Ctx.End)
1165}
1166
1167Error WasmObjectFile::parseCustomSection(WasmSection &Sec, ReadContext &Ctx) {
1168 if (Sec.Name == "dylink") {
1169 if (Error Err = parseDylinkSection(Ctx))
1170 return Err;
1171 } else if (Sec.Name == "dylink.0") {
1172 if (Error Err = parseDylink0Section(Ctx))
1173 return Err;
1174 } else if (Sec.Name == "name") {
1175 if (Error Err = parseNameSection(Ctx))
1176 return Err;
1177 } else if (Sec.Name == "linking") {
1178 if (Error Err = parseLinkingSection(Ctx))
1179 return Err;
1180 } else if (Sec.Name == "producers") {
1181 if (Error Err = parseProducersSection(Ctx))
1182 return Err;
1183 } else if (Sec.Name == "target_features") {
1184 if (Error Err = parseTargetFeaturesSection(Ctx))
1185 return Err;
1187 if (Error Err = parseRelocSection(Sec.Name, Ctx))
1188 return Err;
1189 }
1191}
1192
1193Error WasmObjectFile::parseTypeSection(ReadContext &Ctx) {
1194 auto parseFieldDef = [&]() {
1196 parseValType(Ctx, TypeCode);
1198 };
1199
1201 Signatures.reserve(Count);
1202 while (Count--) {
1203 wasm::WasmSignature Sig;
1206
1207
1209 if (RecSize == 0)
1212 Signatures.reserve(Signatures.size() + RecSize);
1213 Count += RecSize;
1215 Signatures.push_back(std::move(Sig));
1216 HasUnmodeledTypes = true;
1217 continue;
1218 }
1220
1221
1222
1225 if (Supers > 0) {
1226 if (Supers != 1)
1230 }
1232 }
1235 while (FieldCount--) {
1236 parseFieldDef();
1237 }
1239 parseFieldDef();
1240 } else {
1243 }
1245 Signatures.push_back(std::move(Sig));
1246 HasUnmodeledTypes = true;
1247 continue;
1248 }
1249
1252 while (ParamCount--) {
1253 uint32_t ParamType = readUint8(Ctx);
1255 }
1257 while (ReturnCount--) {
1260 }
1261
1262 Signatures.push_back(std::move(Sig));
1263 }
1264 if (Ctx.Ptr != Ctx.End)
1268}
1269
1270Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
1272 uint32_t NumTypes = Signatures.size();
1273 Imports.reserve(Count);
1274 for (uint32_t I = 0; I < Count; I++) {
1275 wasm::WasmImport Im;
1279 switch (Im.Kind) {
1281 NumImportedFunctions++;
1283 if (Im.SigIndex >= NumTypes)
1286 break;
1288 NumImportedGlobals++;
1291 break;
1295 HasMemory64 = true;
1296 break;
1299 NumImportedTables++;
1307 break;
1308 }
1310 NumImportedTags++;
1311 if (readUint8(Ctx) != 0)
1315 if (Im.SigIndex >= NumTypes)
1318 break;
1319 default:
1322 }
1323 Imports.push_back(Im);
1324 }
1325 if (Ctx.Ptr != Ctx.End)
1329}
1330
1331Error WasmObjectFile::parseFunctionSection(ReadContext &Ctx) {
1333 Functions.reserve(Count);
1334 uint32_t NumTypes = Signatures.size();
1335 while (Count--) {
1337 if (Type >= NumTypes)
1340 wasm::WasmFunction F;
1342 Functions.push_back(F);
1343 }
1344 if (Ctx.Ptr != Ctx.End)
1348}
1349
1350Error WasmObjectFile::parseTableSection(ReadContext &Ctx) {
1351 TableSection = Sections.size();
1353 Tables.reserve(Count);
1354 while (Count--) {
1355 wasm::WasmTable T;
1357 T.Index = NumImportedTables + Tables.size();
1358 Tables.push_back(T);
1359 auto ElemType = Tables.back().Type.ElemType;
1366 }
1367 }
1368 if (Ctx.Ptr != Ctx.End)
1372}
1373
1374Error WasmObjectFile::parseMemorySection(ReadContext &Ctx) {
1376 Memories.reserve(Count);
1377 while (Count--) {
1380 HasMemory64 = true;
1381 Memories.push_back(Limits);
1382 }
1383 if (Ctx.Ptr != Ctx.End)
1387}
1388
1389Error WasmObjectFile::parseTagSection(ReadContext &Ctx) {
1390 TagSection = Sections.size();
1392 Tags.reserve(Count);
1393 uint32_t NumTypes = Signatures.size();
1394 while (Count--) {
1395 if (readUint8(Ctx) != 0)
1399 if (Type >= NumTypes)
1402 wasm::WasmTag Tag;
1403 Tag.Index = NumImportedTags + Tags.size();
1406 Tags.push_back(Tag);
1407 }
1408
1409 if (Ctx.Ptr != Ctx.End)
1413}
1414
1415Error WasmObjectFile::parseGlobalSection(ReadContext &Ctx) {
1416 GlobalSection = Sections.size();
1417 const uint8_t *SectionStart = Ctx.Ptr;
1419 Globals.reserve(Count);
1420 while (Count--) {
1421 wasm::WasmGlobal Global;
1422 Global.Index = NumImportedGlobals + Globals.size();
1423 const uint8_t *GlobalStart = Ctx.Ptr;
1424 Global.Offset = static_cast<uint32_t>(GlobalStart - SectionStart);
1429 return Err;
1430 Global.Size = static_cast<uint32_t>(Ctx.Ptr - GlobalStart);
1431 Globals.push_back(Global);
1432 }
1433 if (Ctx.Ptr != Ctx.End)
1437}
1438
1439Error WasmObjectFile::parseExportSection(ReadContext &Ctx) {
1441 Exports.reserve(Count);
1442 Symbols.reserve(Count);
1443 for (uint32_t I = 0; I < Count; I++) {
1444 wasm::WasmExport Ex;
1448 const wasm::WasmSignature *Signature = nullptr;
1449 const wasm::WasmGlobalType *GlobalType = nullptr;
1450 const wasm::WasmTableType *TableType = nullptr;
1451 wasm::WasmSymbolInfo Info;
1453 Info.Flags = 0;
1454 switch (Ex.Kind) {
1456 if (!isValidFunctionIndex(Ex.Index))
1461 if (isDefinedFunctionIndex(Ex.Index)) {
1462 getDefinedFunction(Ex.Index).ExportName = Ex.Name;
1463 unsigned FuncIndex = Info.ElementIndex - NumImportedFunctions;
1464 wasm::WasmFunction &Function = Functions[FuncIndex];
1465 Signature = &Signatures[Function.SigIndex];
1466 }
1467
1468
1469
1470 break;
1471 }
1473 if (!isValidGlobalIndex(Ex.Index))
1477 uint64_t Offset = 0;
1478 if (isDefinedGlobalIndex(Ex.Index)) {
1479 auto Global = getDefinedGlobal(Ex.Index);
1480 if (.InitExpr.Extended) {
1481 auto Inst = Global.InitExpr.Inst;
1483 Offset = Inst.Value.Int32;
1485 Offset = Inst.Value.Int64;
1486 }
1487 }
1488 }
1489 Info.DataRef = wasm::WasmDataReference{0, Offset, 0};
1490 break;
1491 }
1493 if (!isValidTagIndex(Ex.Index))
1498 break;
1500 break;
1504 break;
1505 default:
1508 }
1509 Exports.push_back(Ex);
1511 Symbols.emplace_back(Info, GlobalType, TableType, Signature);
1512 LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n");
1513 }
1514 }
1515 if (Ctx.Ptr != Ctx.End)
1519}
1520
1521bool WasmObjectFile::isValidFunctionIndex(uint32_t Index) const {
1522 return Index < NumImportedFunctions + Functions.size();
1523}
1524
1525bool WasmObjectFile::isDefinedFunctionIndex(uint32_t Index) const {
1526 return Index >= NumImportedFunctions && isValidFunctionIndex(Index);
1527}
1528
1529bool WasmObjectFile::isValidGlobalIndex(uint32_t Index) const {
1530 return Index < NumImportedGlobals + Globals.size();
1531}
1532
1533bool WasmObjectFile::isValidTableNumber(uint32_t Index) const {
1534 return Index < NumImportedTables + Tables.size();
1535}
1536
1537bool WasmObjectFile::isDefinedGlobalIndex(uint32_t Index) const {
1538 return Index >= NumImportedGlobals && isValidGlobalIndex(Index);
1539}
1540
1541bool WasmObjectFile::isDefinedTableNumber(uint32_t Index) const {
1542 return Index >= NumImportedTables && isValidTableNumber(Index);
1543}
1544
1545bool WasmObjectFile::isValidTagIndex(uint32_t Index) const {
1546 return Index < NumImportedTags + Tags.size();
1547}
1548
1549bool WasmObjectFile::isDefinedTagIndex(uint32_t Index) const {
1550 return Index >= NumImportedTags && isValidTagIndex(Index);
1551}
1552
1553bool WasmObjectFile::isValidFunctionSymbol(uint32_t Index) const {
1554 return Index < Symbols.size() && Symbols[Index].isTypeFunction();
1555}
1556
1557bool WasmObjectFile::isValidTableSymbol(uint32_t Index) const {
1558 return Index < Symbols.size() && Symbols[Index].isTypeTable();
1559}
1560
1561bool WasmObjectFile::isValidGlobalSymbol(uint32_t Index) const {
1562 return Index < Symbols.size() && Symbols[Index].isTypeGlobal();
1563}
1564
1565bool WasmObjectFile::isValidTagSymbol(uint32_t Index) const {
1566 return Index < Symbols.size() && Symbols[Index].isTypeTag();
1567}
1568
1569bool WasmObjectFile::isValidDataSymbol(uint32_t Index) const {
1570 return Index < Symbols.size() && Symbols[Index].isTypeData();
1571}
1572
1573bool WasmObjectFile::isValidSectionSymbol(uint32_t Index) const {
1574 return Index < Symbols.size() && Symbols[Index].isTypeSection();
1575}
1576
1577wasm::WasmFunction &WasmObjectFile::getDefinedFunction(uint32_t Index) {
1578 assert(isDefinedFunctionIndex(Index));
1579 return Functions[Index - NumImportedFunctions];
1580}
1581
1582const wasm::WasmFunction &
1583WasmObjectFile::getDefinedFunction(uint32_t Index) const {
1584 assert(isDefinedFunctionIndex(Index));
1585 return Functions[Index - NumImportedFunctions];
1586}
1587
1588const wasm::WasmGlobal &WasmObjectFile::getDefinedGlobal(uint32_t Index) const {
1589 assert(isDefinedGlobalIndex(Index));
1590 return Globals[Index - NumImportedGlobals];
1591}
1592
1593wasm::WasmTag &WasmObjectFile::getDefinedTag(uint32_t Index) {
1594 assert(isDefinedTagIndex(Index));
1595 return Tags[Index - NumImportedTags];
1596}
1597
1598Error WasmObjectFile::parseStartSection(ReadContext &Ctx) {
1600 if (!isValidFunctionIndex(StartFunction))
1604}
1605
1606Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) {
1607 CodeSection = Sections.size();
1609 if (FunctionCount != Functions.size()) {
1612 }
1613
1614 for (uint32_t i = 0; i < FunctionCount; i++) {
1615 wasm::WasmFunction& Function = Functions[i];
1616 const uint8_t *FunctionStart = Ctx.Ptr;
1618 const uint8_t *FunctionEnd = Ctx.Ptr + Size;
1619
1620 Function.CodeOffset = Ctx.Ptr - FunctionStart;
1621 Function.Index = NumImportedFunctions + i;
1622 Function.CodeSectionOffset = FunctionStart - Ctx.Start;
1623 Function.Size = FunctionEnd - FunctionStart;
1624
1626 Function.Locals.reserve(NumLocalDecls);
1627 while (NumLocalDecls--) {
1628 wasm::WasmLocalDecl Decl;
1631 Function.Locals.push_back(Decl);
1632 }
1633
1634 uint32_t BodySize = FunctionEnd - Ctx.Ptr;
1635
1636 if (Ctx.Ptr + BodySize > Ctx.End) {
1639 }
1640 Function.Body = ArrayRef<uint8_t>(Ctx.Ptr, BodySize);
1641
1642 Function.Comdat = UINT32_MAX;
1643 Ctx.Ptr += BodySize;
1644 assert(Ctx.Ptr == FunctionEnd);
1645 }
1646 if (Ctx.Ptr != Ctx.End)
1650}
1651
1652Error WasmObjectFile::parseElemSection(ReadContext &Ctx) {
1654 ElemSegments.reserve(Count);
1655 while (Count--) {
1656 wasm::WasmElemSegment Segment;
1658
1662 if (Segment.Flags & ~SupportedFlags)
1665
1671 } else {
1673 }
1674 bool HasTableNumber =
1677 bool HasElemKind =
1680 bool HasElemType =
1683 bool HasInitExprs =
1685
1686 if (HasTableNumber)
1688 else
1690
1691 if (!isValidTableNumber(Segment.TableNumber))
1694
1699 } else {
1701 return Err;
1702 }
1703
1704 if (HasElemKind) {
1714 }
1715 } else {
1716 if (ElemKind != 0)
1720 }
1721 } else if (HasElemType) {
1723 Segment.ElemKind = ElemType;
1724 } else {
1726 }
1727
1729
1730 if (HasInitExprs) {
1731 while (NumElems--) {
1732 wasm::WasmInitExpr Expr;
1734 return Err;
1735 }
1736 } else {
1737 while (NumElems--) {
1739 }
1740 }
1741 ElemSegments.push_back(Segment);
1742 }
1743 if (Ctx.Ptr != Ctx.End)
1747}
1748
1749Error WasmObjectFile::parseDataSection(ReadContext &Ctx) {
1750 DataSection = Sections.size();
1752 if (DataCount && Count != *DataCount)
1754 "number of data segments does not match DataCount section");
1755 DataSegments.reserve(Count);
1756 while (Count--) {
1757 WasmSegment Segment;
1762 : 0;
1765 return Err;
1766 } else {
1770 }
1772 if (Size > (size_t)(Ctx.End - Ctx.Ptr))
1775 Segment.Data.Content = ArrayRef<uint8_t>(Ctx.Ptr, Size);
1776
1777
1782 Ctx.Ptr += Size;
1783 DataSegments.push_back(Segment);
1784 }
1785 if (Ctx.Ptr != Ctx.End)
1789}
1790
1791Error WasmObjectFile::parseDataCountSection(ReadContext &Ctx) {
1794}
1795
1797 return Header;
1798}
1799
1801
1805
1806 LLVM_DEBUG(dbgs() << "getSymbolFlags: ptr=" << &Sym << " " << Sym << "\n");
1817 return Result;
1818}
1819
1822 Ref.d.a = 1;
1823 Ref.d.b = 0;
1825}
1826
1829 Ref.d.a = 1;
1830 Ref.d.b = Symbols.size();
1832}
1833
1835 return Symbols[Symb.d.b];
1836}
1837
1841
1845
1848 if (!Sym.isDefined())
1849 return 0;
1851 if (!Sec)
1855 isDefinedFunctionIndex(Sym.Info.ElementIndex)) {
1856 return getDefinedFunction(Sym.Info.ElementIndex).CodeSectionOffset +
1857 SectionAddress;
1858 }
1860 isDefinedGlobalIndex(Sym.Info.ElementIndex)) {
1861 return getDefinedGlobal(Sym.Info.ElementIndex).Offset + SectionAddress;
1862 }
1863
1865}
1866
1875
1876
1887 } else {
1889 }
1890 }
1892 return 0;
1893 }
1895}
1896
1900
1905
1910
1933
1939
1941 Ref.d.a = getSymbolSectionIdImpl(Sym);
1943}
1944
1947 return getSymbolSectionIdImpl(Sym);
1948}
1949
1950uint32_t WasmObjectFile::getSymbolSectionIdImpl(const WasmSymbol &Sym) const {
1953 return CodeSection;
1955 return GlobalSection;
1957 return DataSection;
1961 return TagSection;
1963 return TableSection;
1964 default:
1966 }
1967}
1968
1972 return 0;
1979
1980
1981
1982 return 0;
1983}
1984
1986
1990 return S.Name;
1994}
1995
1997
1998
1999
2001 : Sections[Sec.d.a].Offset;
2002}
2003
2006}
2007
2012
2020
2024
2028
2032
2036
2038
2040
2046}
2047
2054}
2055
2057
2062
2065 if (Rel.Type == wasm::R_WASM_TYPE_INDEX_LEB)
2071}
2072
2075 return Rel.Type;
2076}
2077
2082
2083#define WASM_RELOC(name, value) \
2084 case wasm:📛 \
2085 Res = #name; \
2086 break;
2087
2088 switch (Rel.Type) {
2089#include "llvm/BinaryFormat/WasmRelocs.def"
2090 }
2091
2092#undef WASM_RELOC
2093
2094 Result.append(Res.begin(), Res.end());
2095}
2096
2102
2105 Ref.d.a = Sections.size();
2107}
2108
2110 return HasMemory64 ? 8 : 4;
2111}
2112
2114
2118
2122
2124
2126
2128 assert(Ref.d.a < Sections.size());
2129 return Sections[Ref.d.a];
2130}
2131
2136
2141
2144 assert(Ref.d.a < Sections.size());
2148}
2149
2150int WasmSectionOrderChecker::getSectionOrder(unsigned ID,
2152 switch (ID) {
2189 default:
2191 }
2192}
2193
2194
2195
2196
2198 [WASM_NUM_SEC_ORDERS][WASM_NUM_SEC_ORDERS] = {
2199
2200 {},
2201
2202 {WASM_SEC_ORDER_TYPE, WASM_SEC_ORDER_IMPORT},
2203
2204 {WASM_SEC_ORDER_IMPORT, WASM_SEC_ORDER_FUNCTION},
2205
2206 {WASM_SEC_ORDER_FUNCTION, WASM_SEC_ORDER_TABLE},
2207
2208 {WASM_SEC_ORDER_TABLE, WASM_SEC_ORDER_MEMORY},
2209
2210 {WASM_SEC_ORDER_MEMORY, WASM_SEC_ORDER_TAG},
2211
2212 {WASM_SEC_ORDER_TAG, WASM_SEC_ORDER_GLOBAL},
2213
2214 {WASM_SEC_ORDER_GLOBAL, WASM_SEC_ORDER_EXPORT},
2215
2216 {WASM_SEC_ORDER_EXPORT, WASM_SEC_ORDER_START},
2217
2218 {WASM_SEC_ORDER_START, WASM_SEC_ORDER_ELEM},
2219
2220 {WASM_SEC_ORDER_ELEM, WASM_SEC_ORDER_DATACOUNT},
2221
2222 {WASM_SEC_ORDER_DATACOUNT, WASM_SEC_ORDER_CODE},
2223
2224 {WASM_SEC_ORDER_CODE, WASM_SEC_ORDER_DATA},
2225
2226 {WASM_SEC_ORDER_DATA, WASM_SEC_ORDER_LINKING},
2227
2228
2229
2230 {WASM_SEC_ORDER_DYLINK, WASM_SEC_ORDER_TYPE},
2231
2232 {WASM_SEC_ORDER_LINKING, WASM_SEC_ORDER_RELOC, WASM_SEC_ORDER_NAME},
2233
2234 {},
2235
2236 {WASM_SEC_ORDER_NAME, WASM_SEC_ORDER_PRODUCERS},
2237
2238 {WASM_SEC_ORDER_PRODUCERS, WASM_SEC_ORDER_TARGET_FEATURES},
2239
2240 {WASM_SEC_ORDER_TARGET_FEATURES}};
2241
2244 int Order = getSectionOrder(ID, CustomSectionName);
2246 return true;
2247
2248
2250
2251
2253
2254 int Curr = Order;
2255 while (true) {
2256
2257 for (size_t I = 0;; ++I) {
2260 break;
2261 if (Checked[Next])
2262 continue;
2264 Checked[Next] = true;
2265 }
2266
2267 if (WorkList.empty())
2268 break;
2269
2270
2272 if (Seen[Curr])
2273 return false;
2274 }
2275
2276
2277 Seen[Order] = true;
2278 return true;
2279}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the DenseSet and SmallDenseSet classes.
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallSet class.
StringSet - A set-like wrapper for the StringMap.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static uint8_t readVaruint1(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:142
static Error readInitExpr(wasm::WasmInitExpr &Expr, WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:196
static int32_t readVarint32(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:149
static wasm::WasmTableType readTableType(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:303
static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:288
static uint64_t readVaruint64(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:167
static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, WasmSectionOrderChecker &Checker)
Definition WasmObjectFile.cpp:311
static int64_t readLEB128(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:132
static uint32_t readVaruint32(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:156
static uint32_t readUint32(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:86
static uint8_t readOpcode(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:171
static StringRef readString(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:122
static uint8_t readUint8(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:80
#define VARUINT1_MAX
Definition WasmObjectFile.cpp:78
static int32_t readFloat32(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:94
static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:112
static int64_t readFloat64(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:103
static wasm::ValType parseValType(WasmObjectFile::ReadContext &Ctx, uint32_t Code)
Definition WasmObjectFile.cpp:175
static int64_t readVarint64(WasmObjectFile::ReadContext &Ctx)
Definition WasmObjectFile.cpp:163
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
const unsigned char * bytes_begin() const
std::pair< typename Base::iterator, bool > insert(StringRef key)
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & StartsWith(StringLiteral S, T Value)
Manages the enabling and disabling of subtarget specific features.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Twine utohexstr(uint64_t Val)
std::pair< iterator, bool > insert(const ValueT &V)
This is a value type class that represents a single symbol in the list of symbols in the object file.
DataRefImpl getRawDataRefImpl() const
StringRef getData() const
friend class RelocationRef
static Expected< std::unique_ptr< WasmObjectFile > > createWasmObjectFile(MemoryBufferRef Object)
Definition WasmObjectFile.cpp:66
Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const
ObjectFile(unsigned int Type, MemoryBufferRef Source)
basic_symbol_iterator symbol_begin() const override
Definition WasmObjectFile.cpp:1820
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2048
void moveSymbolNext(DataRefImpl &Symb) const override
Definition WasmObjectFile.cpp:1800
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2021
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Definition WasmObjectFile.cpp:2058
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Definition WasmObjectFile.cpp:1912
uint64_t getWasmSymbolValue(const WasmSymbol &Sym) const
Definition WasmObjectFile.cpp:1867
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Definition WasmObjectFile.cpp:1897
bool isSectionText(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2029
bool isSectionBSS(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2037
basic_symbol_iterator symbol_end() const override
Definition WasmObjectFile.cpp:1827
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition WasmObjectFile.cpp:1802
section_iterator section_begin() const override
Definition WasmObjectFile.cpp:2097
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
Definition WasmObjectFile.cpp:2123
void moveRelocationNext(DataRefImpl &Rel) const override
Definition WasmObjectFile.cpp:2056
uint32_t getSymbolSectionId(SymbolRef Sym) const
Definition WasmObjectFile.cpp:1945
bool isSectionCompressed(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2025
bool isSectionVirtual(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2039
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
Definition WasmObjectFile.cpp:1906
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
Definition WasmObjectFile.cpp:2078
StringRef getFileFormatName() const override
Definition WasmObjectFile.cpp:2113
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
Definition WasmObjectFile.cpp:1842
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2041
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
Definition WasmObjectFile.cpp:2109
WasmObjectFile(MemoryBufferRef Object, Error &Err)
Definition WasmObjectFile.cpp:351
section_iterator section_end() const override
Definition WasmObjectFile.cpp:2103
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2014
uint64_t getSectionIndex(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2004
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Definition WasmObjectFile.cpp:1901
uint64_t getSectionSize(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2008
Triple::ArchType getArch() const override
Definition WasmObjectFile.cpp:2115
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition WasmObjectFile.cpp:2073
const WasmSection & getWasmSection(const SectionRef &Section) const
Definition WasmObjectFile.cpp:2133
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
Definition WasmObjectFile.cpp:1935
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Definition WasmObjectFile.cpp:2063
Expected< SubtargetFeatures > getFeatures() const override
Definition WasmObjectFile.cpp:2119
const wasm::WasmObjectHeader & getHeader() const
Definition WasmObjectFile.cpp:1796
void moveSectionNext(DataRefImpl &Sec) const override
Definition WasmObjectFile.cpp:1985
uint32_t getNumImportedFunctions() const
bool isSharedObject() const
Definition WasmObjectFile.cpp:2125
const wasm::WasmRelocation & getWasmRelocation(const RelocationRef &Ref) const
Definition WasmObjectFile.cpp:2138
uint32_t getSymbolSize(SymbolRef Sym) const
Definition WasmObjectFile.cpp:1969
ArrayRef< wasm::WasmFunction > functions() const
const WasmSymbol & getWasmSymbol(const DataRefImpl &Symb) const
Definition WasmObjectFile.cpp:1834
uint64_t getSectionAddress(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:1996
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Definition WasmObjectFile.cpp:1846
bool isSectionData(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:2033
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
Definition WasmObjectFile.cpp:1987
LLVM_ABI bool isValidSectionOrder(unsigned ID, StringRef CustomSectionName="")
Definition WasmObjectFile.cpp:2242
@ WASM_SEC_ORDER_TARGET_FEATURES
@ WASM_SEC_ORDER_PRODUCERS
@ WASM_SEC_ORDER_DATACOUNT
@ WASM_SEC_ORDER_FUNCTION
static LLVM_ABI int DisallowedPredecessors[WASM_NUM_SEC_ORDERS][WASM_NUM_SEC_ORDERS]
bool isTypeFunction() const
unsigned getBinding() const
LLVM_DUMP_METHOD void dump() const
Definition WasmObjectFile.cpp:62
bool isBindingWeak() const
wasm::WasmSymbolInfo Info
LLVM_ABI void print(raw_ostream &Out) const
Definition WasmObjectFile.cpp:37
bool isBindingLocal() const
bool isTypeGlobal() const
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
content_iterator< SectionRef > section_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
content_iterator< RelocationRef > relocation_iterator
uint32_t read32le(const void *P)
const unsigned WASM_SYMBOL_UNDEFINED
const unsigned WASM_SYMBOL_BINDING_GLOBAL
const uint32_t WasmMetadataVersion
const unsigned WASM_SYMBOL_BINDING_WEAK
const unsigned WASM_SYMBOL_BINDING_LOCAL
@ WASM_LIMITS_FLAG_HAS_MAX
@ WASM_LIMITS_FLAG_HAS_PAGE_SIZE
@ WASM_DATA_SEGMENT_IS_PASSIVE
@ WASM_DATA_SEGMENT_HAS_MEMINDEX
@ WASM_FEATURE_PREFIX_USED
@ WASM_FEATURE_PREFIX_DISALLOWED
@ WASM_SYMBOL_TYPE_GLOBAL
@ WASM_SYMBOL_TYPE_SECTION
@ WASM_SYMBOL_TYPE_FUNCTION
const uint32_t WasmVersion
const unsigned WASM_SYMBOL_BINDING_MASK
@ WASM_ELEM_SEGMENT_HAS_INIT_EXPRS
@ WASM_ELEM_SEGMENT_IS_DECLARATIVE
@ WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER
@ WASM_ELEM_SEGMENT_IS_PASSIVE
@ WASM_DYLINK_RUNTIME_PATH
@ WASM_DYLINK_EXPORT_INFO
@ WASM_DYLINK_IMPORT_INFO
@ WASM_OPCODE_ARRAY_NEW_FIXED
@ WASM_OPCODE_ARRAY_NEW_DEFAULT
@ WASM_OPCODE_STRUCT_NEW_DEFAULT
@ WASM_NAMES_DATA_SEGMENT
LLVM_ABI llvm::StringRef sectionTypeToString(uint32_t type)
const unsigned WASM_SYMBOL_EXPLICIT_NAME
const unsigned WASM_SYMBOL_ABSOLUTE
const unsigned WASM_ELEM_SEGMENT_MASK_HAS_ELEM_DESC
This is an optimization pass for GlobalISel generic memory operations.
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.
@ Import
Import information from summary.
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.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
const char * to_string(ThinOrFullLTOPhase Phase)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
@ Global
Append to llvm.global_dtors.
@ Ref
The access may reference the value stored in memory.
FunctionAddr VTableAddr Next
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
ArrayRef< uint8_t > Content
std::vector< wasm::WasmRelocation > Relocations
wasm::WasmDataSegment Data
ArrayRef< uint8_t > Content
std::vector< StringRef > Needed
std::vector< uint32_t > Functions
union llvm::wasm::WasmInitExprMVP::@021046217255127373215144224227277301132130072341 Value
SmallVector< ValType, 1 > Returns
SmallVector< ValType, 4 > Params
enum llvm::wasm::WasmSignature::@105325325225225371022120066125223151323055007017 Kind
WasmDataReference DataRef
struct llvm::object::DataRefImpl::@005117267142344013370254144343227032034000327225 d