diff options
| author | shadchin <[email protected]> | 2022-02-10 16:44:39 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:39 +0300 |
| commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
| tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp | |
| parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp')
| -rw-r--r-- | contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp | 476 |
1 files changed, 238 insertions, 238 deletions
diff --git a/contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp b/contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp index 52cb9abec8e..40f468881ed 100644 --- a/contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp +++ b/contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp @@ -187,19 +187,19 @@ static Error readInitExpr(wasm::WasmInitExpr &Expr, case wasm::WASM_OPCODE_REF_NULL: { wasm::ValType Ty = static_cast<wasm::ValType>(readULEB128(Ctx)); if (Ty != wasm::ValType::EXTERNREF) { - return make_error<GenericBinaryError>("invalid type for ref.null", + return make_error<GenericBinaryError>("invalid type for ref.null", object_error::parse_failed); } break; } default: - return make_error<GenericBinaryError>("invalid opcode in init_expr", + return make_error<GenericBinaryError>("invalid opcode in init_expr", object_error::parse_failed); } uint8_t EndOpcode = readOpcode(Ctx); if (EndOpcode != wasm::WASM_OPCODE_END) { - return make_error<GenericBinaryError>("invalid init_expr", + return make_error<GenericBinaryError>("invalid init_expr", object_error::parse_failed); } return Error::success(); @@ -214,11 +214,11 @@ static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) { return Result; } -static wasm::WasmTableType readTableType(WasmObjectFile::ReadContext &Ctx) { - wasm::WasmTableType TableType; - TableType.ElemType = readUint8(Ctx); - TableType.Limits = readLimits(Ctx); - return TableType; +static wasm::WasmTableType readTableType(WasmObjectFile::ReadContext &Ctx) { + wasm::WasmTableType TableType; + TableType.ElemType = readUint8(Ctx); + TableType.Limits = readLimits(Ctx); + return TableType; } static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, @@ -228,10 +228,10 @@ static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, LLVM_DEBUG(dbgs() << "readSection type=" << Section.Type << "\n"); uint32_t Size = readVaruint32(Ctx); if (Size == 0) - return make_error<StringError>("zero length section", + return make_error<StringError>("zero length section", object_error::parse_failed); if (Ctx.Ptr + Size > Ctx.End) - return make_error<StringError>("section too large", + return make_error<StringError>("section too large", object_error::parse_failed); if (Section.Type == wasm::WASM_SEC_CUSTOM) { WasmObjectFile::ReadContext SectionCtx; @@ -247,7 +247,7 @@ static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, } if (!Checker.isValidSectionOrder(Section.Type, Section.Name)) { - return make_error<StringError>("out of order section type: " + + return make_error<StringError>("out of order section type: " + llvm::to_string(Section.Type), object_error::parse_failed); } @@ -262,8 +262,8 @@ WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err) ErrorAsOutParameter ErrAsOutParam(&Err); Header.Magic = getData().substr(0, 4); if (Header.Magic != StringRef("\0asm", 4)) { - Err = make_error<StringError>("invalid magic number", - object_error::parse_failed); + Err = make_error<StringError>("invalid magic number", + object_error::parse_failed); return; } @@ -273,15 +273,15 @@ WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err) Ctx.End = Ctx.Start + getData().size(); if (Ctx.Ptr + 4 > Ctx.End) { - Err = make_error<StringError>("missing version number", + Err = make_error<StringError>("missing version number", object_error::parse_failed); return; } Header.Version = readUint32(Ctx); if (Header.Version != wasm::WasmVersion) { - Err = make_error<StringError>("invalid version number: " + - Twine(Header.Version), + Err = make_error<StringError>("invalid version number: " + + Twine(Header.Version), object_error::parse_failed); return; } @@ -334,7 +334,7 @@ Error WasmObjectFile::parseSection(WasmSection &Sec) { return parseDataCountSection(Ctx); default: return make_error<GenericBinaryError>( - "invalid section type: " + Twine(Sec.Type), object_error::parse_failed); + "invalid section type: " + Twine(Sec.Type), object_error::parse_failed); } } @@ -356,11 +356,11 @@ Error WasmObjectFile::parseDylinkSection(ReadContext &Ctx) { } Error WasmObjectFile::parseNameSection(ReadContext &Ctx) { - llvm::DenseSet<uint64_t> SeenFunctions; - llvm::DenseSet<uint64_t> SeenGlobals; - llvm::DenseSet<uint64_t> SeenSegments; + llvm::DenseSet<uint64_t> SeenFunctions; + llvm::DenseSet<uint64_t> SeenGlobals; + llvm::DenseSet<uint64_t> SeenSegments; if (FunctionTypes.size() && !SeenCodeSection) { - return make_error<GenericBinaryError>("names must come after code section", + return make_error<GenericBinaryError>("names must come after code section", object_error::parse_failed); } @@ -369,42 +369,42 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) { uint32_t Size = readVaruint32(Ctx); const uint8_t *SubSectionEnd = Ctx.Ptr + Size; switch (Type) { - case wasm::WASM_NAMES_FUNCTION: - case wasm::WASM_NAMES_GLOBAL: - case wasm::WASM_NAMES_DATA_SEGMENT: { + case wasm::WASM_NAMES_FUNCTION: + case wasm::WASM_NAMES_GLOBAL: + case wasm::WASM_NAMES_DATA_SEGMENT: { uint32_t Count = readVaruint32(Ctx); while (Count--) { uint32_t Index = readVaruint32(Ctx); StringRef Name = readString(Ctx); - wasm::NameType nameType = wasm::NameType::FUNCTION; - if (Type == wasm::WASM_NAMES_FUNCTION) { - if (!SeenFunctions.insert(Index).second) - return make_error<GenericBinaryError>( - "function named more than once", object_error::parse_failed); - if (!isValidFunctionIndex(Index) || Name.empty()) - return make_error<GenericBinaryError>("invalid name entry", - object_error::parse_failed); - - if (isDefinedFunctionIndex(Index)) - getDefinedFunction(Index).DebugName = Name; - } else if (Type == wasm::WASM_NAMES_GLOBAL) { - nameType = wasm::NameType::GLOBAL; - if (!SeenGlobals.insert(Index).second) - return make_error<GenericBinaryError>("global named more than once", - object_error::parse_failed); - if (!isValidGlobalIndex(Index) || Name.empty()) - return make_error<GenericBinaryError>("invalid name entry", - object_error::parse_failed); - } else { - nameType = wasm::NameType::DATA_SEGMENT; - if (!SeenSegments.insert(Index).second) - return make_error<GenericBinaryError>( - "segment named more than once", object_error::parse_failed); - if (Index > DataSegments.size()) - return make_error<GenericBinaryError>("invalid named data segment", - object_error::parse_failed); - } - DebugNames.push_back(wasm::WasmDebugName{nameType, Index, Name}); + wasm::NameType nameType = wasm::NameType::FUNCTION; + if (Type == wasm::WASM_NAMES_FUNCTION) { + if (!SeenFunctions.insert(Index).second) + return make_error<GenericBinaryError>( + "function named more than once", object_error::parse_failed); + if (!isValidFunctionIndex(Index) || Name.empty()) + return make_error<GenericBinaryError>("invalid name entry", + object_error::parse_failed); + + if (isDefinedFunctionIndex(Index)) + getDefinedFunction(Index).DebugName = Name; + } else if (Type == wasm::WASM_NAMES_GLOBAL) { + nameType = wasm::NameType::GLOBAL; + if (!SeenGlobals.insert(Index).second) + return make_error<GenericBinaryError>("global named more than once", + object_error::parse_failed); + if (!isValidGlobalIndex(Index) || Name.empty()) + return make_error<GenericBinaryError>("invalid name entry", + object_error::parse_failed); + } else { + nameType = wasm::NameType::DATA_SEGMENT; + if (!SeenSegments.insert(Index).second) + return make_error<GenericBinaryError>( + "segment named more than once", object_error::parse_failed); + if (Index > DataSegments.size()) + return make_error<GenericBinaryError>("invalid named data segment", + object_error::parse_failed); + } + DebugNames.push_back(wasm::WasmDebugName{nameType, Index, Name}); } break; } @@ -416,11 +416,11 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) { } if (Ctx.Ptr != SubSectionEnd) return make_error<GenericBinaryError>( - "name sub-section ended prematurely", object_error::parse_failed); + "name sub-section ended prematurely", object_error::parse_failed); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("name section ended prematurely", + return make_error<GenericBinaryError>("name section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -429,14 +429,14 @@ Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) { HasLinkingSection = true; if (FunctionTypes.size() && !SeenCodeSection) { return make_error<GenericBinaryError>( - "linking data must come after code section", + "linking data must come after code section", object_error::parse_failed); } LinkingData.Version = readVaruint32(Ctx); if (LinkingData.Version != wasm::WasmMetadataVersion) { return make_error<GenericBinaryError>( - "unexpected metadata version: " + Twine(LinkingData.Version) + + "unexpected metadata version: " + Twine(LinkingData.Version) + " (Expected: " + Twine(wasm::WasmMetadataVersion) + ")", object_error::parse_failed); } @@ -457,7 +457,7 @@ Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) { case wasm::WASM_SEGMENT_INFO: { uint32_t Count = readVaruint32(Ctx); if (Count > DataSegments.size()) - return make_error<GenericBinaryError>("too many segment names", + return make_error<GenericBinaryError>("too many segment names", object_error::parse_failed); for (uint32_t I = 0; I < Count; I++) { DataSegments[I].Data.Name = readString(Ctx); @@ -474,7 +474,7 @@ Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) { Init.Priority = readVaruint32(Ctx); Init.Symbol = readVaruint32(Ctx); if (!isValidFunctionSymbol(Init.Symbol)) - return make_error<GenericBinaryError>("invalid function symbol: " + + return make_error<GenericBinaryError>("invalid function symbol: " + Twine(Init.Symbol), object_error::parse_failed); LinkingData.InitFunctions.emplace_back(Init); @@ -491,10 +491,10 @@ Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) { } if (Ctx.Ptr != Ctx.End) return make_error<GenericBinaryError>( - "linking sub-section ended prematurely", object_error::parse_failed); + "linking sub-section ended prematurely", object_error::parse_failed); } if (Ctx.Ptr != OrigEnd) - return make_error<GenericBinaryError>("linking section ended prematurely", + return make_error<GenericBinaryError>("linking section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -508,11 +508,11 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { std::vector<wasm::WasmImport *> ImportedGlobals; std::vector<wasm::WasmImport *> ImportedFunctions; std::vector<wasm::WasmImport *> ImportedEvents; - std::vector<wasm::WasmImport *> ImportedTables; + std::vector<wasm::WasmImport *> ImportedTables; ImportedGlobals.reserve(Imports.size()); ImportedFunctions.reserve(Imports.size()); ImportedEvents.reserve(Imports.size()); - ImportedTables.reserve(Imports.size()); + ImportedTables.reserve(Imports.size()); for (auto &I : Imports) { if (I.Kind == wasm::WASM_EXTERNAL_FUNCTION) ImportedFunctions.emplace_back(&I); @@ -520,15 +520,15 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { ImportedGlobals.emplace_back(&I); else if (I.Kind == wasm::WASM_EXTERNAL_EVENT) ImportedEvents.emplace_back(&I); - else if (I.Kind == wasm::WASM_EXTERNAL_TABLE) - ImportedTables.emplace_back(&I); + else if (I.Kind == wasm::WASM_EXTERNAL_TABLE) + ImportedTables.emplace_back(&I); } while (Count--) { wasm::WasmSymbolInfo Info; const wasm::WasmSignature *Signature = nullptr; const wasm::WasmGlobalType *GlobalType = nullptr; - const wasm::WasmTableType *TableType = nullptr; + const wasm::WasmTableType *TableType = nullptr; const wasm::WasmEventType *EventType = nullptr; Info.Kind = readUint8(Ctx); @@ -596,38 +596,38 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { } break; - case wasm::WASM_SYMBOL_TYPE_TABLE: - Info.ElementIndex = readVaruint32(Ctx); - if (!isValidTableIndex(Info.ElementIndex) || - IsDefined != isDefinedTableIndex(Info.ElementIndex)) - return make_error<GenericBinaryError>("invalid table symbol index", - object_error::parse_failed); - if (!IsDefined && (Info.Flags & wasm::WASM_SYMBOL_BINDING_MASK) == - wasm::WASM_SYMBOL_BINDING_WEAK) - return make_error<GenericBinaryError>("undefined weak table symbol", - object_error::parse_failed); - if (IsDefined) { - Info.Name = readString(Ctx); - unsigned TableIndex = Info.ElementIndex - NumImportedTables; - wasm::WasmTable &Table = Tables[TableIndex]; - TableType = &Table.Type; - if (Table.SymbolName.empty()) - Table.SymbolName = Info.Name; - } else { - wasm::WasmImport &Import = *ImportedTables[Info.ElementIndex]; - if ((Info.Flags & wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0) { - Info.Name = readString(Ctx); - Info.ImportName = Import.Field; - } else { - Info.Name = Import.Field; - } - TableType = &Import.Table; - if (!Import.Module.empty()) { - Info.ImportModule = Import.Module; - } - } - break; - + case wasm::WASM_SYMBOL_TYPE_TABLE: + Info.ElementIndex = readVaruint32(Ctx); + if (!isValidTableIndex(Info.ElementIndex) || + IsDefined != isDefinedTableIndex(Info.ElementIndex)) + return make_error<GenericBinaryError>("invalid table symbol index", + object_error::parse_failed); + if (!IsDefined && (Info.Flags & wasm::WASM_SYMBOL_BINDING_MASK) == + wasm::WASM_SYMBOL_BINDING_WEAK) + return make_error<GenericBinaryError>("undefined weak table symbol", + object_error::parse_failed); + if (IsDefined) { + Info.Name = readString(Ctx); + unsigned TableIndex = Info.ElementIndex - NumImportedTables; + wasm::WasmTable &Table = Tables[TableIndex]; + TableType = &Table.Type; + if (Table.SymbolName.empty()) + Table.SymbolName = Info.Name; + } else { + wasm::WasmImport &Import = *ImportedTables[Info.ElementIndex]; + if ((Info.Flags & wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0) { + Info.Name = readString(Ctx); + Info.ImportName = Import.Field; + } else { + Info.Name = Import.Field; + } + TableType = &Import.Table; + if (!Import.Module.empty()) { + Info.ImportModule = Import.Module; + } + } + break; + case wasm::WASM_SYMBOL_TYPE_DATA: Info.Name = readString(Ctx); if (IsDefined) { @@ -648,7 +648,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { if ((Info.Flags & wasm::WASM_SYMBOL_BINDING_MASK) != wasm::WASM_SYMBOL_BINDING_LOCAL) return make_error<GenericBinaryError>( - "section symbols must have local binding", + "section symbols must have local binding", object_error::parse_failed); Info.ElementIndex = readVaruint32(Ctx); // Use somewhat unique section name as symbol name. @@ -694,20 +694,20 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { } default: - return make_error<GenericBinaryError>("invalid symbol type: " + - Twine(unsigned(Info.Kind)), + return make_error<GenericBinaryError>("invalid symbol type: " + + Twine(unsigned(Info.Kind)), object_error::parse_failed); } if ((Info.Flags & wasm::WASM_SYMBOL_BINDING_MASK) != wasm::WASM_SYMBOL_BINDING_LOCAL && !SymbolNames.insert(Info.Name).second) - return make_error<GenericBinaryError>("duplicate symbol name " + + return make_error<GenericBinaryError>("duplicate symbol name " + Twine(Info.Name), object_error::parse_failed); LinkingData.SymbolTable.emplace_back(Info); - Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType, TableType, - EventType, Signature); + Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType, TableType, + EventType, Signature); LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n"); } @@ -720,13 +720,13 @@ Error WasmObjectFile::parseLinkingSectionComdat(ReadContext &Ctx) { for (unsigned ComdatIndex = 0; ComdatIndex < ComdatCount; ++ComdatIndex) { StringRef Name = readString(Ctx); if (Name.empty() || !ComdatSet.insert(Name).second) - return make_error<GenericBinaryError>("bad/duplicate COMDAT name " + + return make_error<GenericBinaryError>("bad/duplicate COMDAT name " + Twine(Name), object_error::parse_failed); LinkingData.Comdats.emplace_back(Name); uint32_t Flags = readVaruint32(Ctx); if (Flags != 0) - return make_error<GenericBinaryError>("unsupported COMDAT flags", + return make_error<GenericBinaryError>("unsupported COMDAT flags", object_error::parse_failed); uint32_t EntryCount = readVaruint32(Ctx); @@ -735,14 +735,14 @@ Error WasmObjectFile::parseLinkingSectionComdat(ReadContext &Ctx) { unsigned Index = readVaruint32(Ctx); switch (Kind) { default: - return make_error<GenericBinaryError>("invalid COMDAT entry type", + return make_error<GenericBinaryError>("invalid COMDAT entry type", object_error::parse_failed); case wasm::WASM_COMDAT_DATA: if (Index >= DataSegments.size()) return make_error<GenericBinaryError>( "COMDAT data index out of range", object_error::parse_failed); if (DataSegments[Index].Data.Comdat != UINT32_MAX) - return make_error<GenericBinaryError>("data segment in two COMDATs", + return make_error<GenericBinaryError>("data segment in two COMDATs", object_error::parse_failed); DataSegments[Index].Data.Comdat = ComdatIndex; break; @@ -751,19 +751,19 @@ Error WasmObjectFile::parseLinkingSectionComdat(ReadContext &Ctx) { return make_error<GenericBinaryError>( "COMDAT function index out of range", object_error::parse_failed); if (getDefinedFunction(Index).Comdat != UINT32_MAX) - return make_error<GenericBinaryError>("function in two COMDATs", + return make_error<GenericBinaryError>("function in two COMDATs", object_error::parse_failed); getDefinedFunction(Index).Comdat = ComdatIndex; break; - case wasm::WASM_COMDAT_SECTION: - if (Index >= Sections.size()) - return make_error<GenericBinaryError>( - "COMDAT section index out of range", object_error::parse_failed); - if (Sections[Index].Type != wasm::WASM_SEC_CUSTOM) - return make_error<GenericBinaryError>( - "non-custom section in a COMDAT", object_error::parse_failed); - Sections[Index].Comdat = ComdatIndex; - break; + case wasm::WASM_COMDAT_SECTION: + if (Index >= Sections.size()) + return make_error<GenericBinaryError>( + "COMDAT section index out of range", object_error::parse_failed); + if (Sections[Index].Type != wasm::WASM_SEC_CUSTOM) + return make_error<GenericBinaryError>( + "non-custom section in a COMDAT", object_error::parse_failed); + Sections[Index].Comdat = ComdatIndex; + break; } } } @@ -777,7 +777,7 @@ Error WasmObjectFile::parseProducersSection(ReadContext &Ctx) { StringRef FieldName = readString(Ctx); if (!FieldsSeen.insert(FieldName).second) return make_error<GenericBinaryError>( - "producers section does not have unique fields", + "producers section does not have unique fields", object_error::parse_failed); std::vector<std::pair<std::string, std::string>> *ProducerVec = nullptr; if (FieldName == "language") { @@ -788,7 +788,7 @@ Error WasmObjectFile::parseProducersSection(ReadContext &Ctx) { ProducerVec = &ProducerInfo.SDKs; } else { return make_error<GenericBinaryError>( - "producers section field is not named one of language, processed-by, " + "producers section field is not named one of language, processed-by, " "or sdk", object_error::parse_failed); } @@ -799,14 +799,14 @@ Error WasmObjectFile::parseProducersSection(ReadContext &Ctx) { StringRef Version = readString(Ctx); if (!ProducersSeen.insert(Name).second) { return make_error<GenericBinaryError>( - "producers section contains repeated producer", + "producers section contains repeated producer", object_error::parse_failed); } ProducerVec->emplace_back(std::string(Name), std::string(Version)); } } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("producers section ended prematurely", + return make_error<GenericBinaryError>("producers section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -823,20 +823,20 @@ Error WasmObjectFile::parseTargetFeaturesSection(ReadContext &Ctx) { case wasm::WASM_FEATURE_PREFIX_DISALLOWED: break; default: - return make_error<GenericBinaryError>("unknown feature policy prefix", + return make_error<GenericBinaryError>("unknown feature policy prefix", object_error::parse_failed); } Feature.Name = std::string(readString(Ctx)); if (!FeaturesSeen.insert(Feature.Name).second) return make_error<GenericBinaryError>( - "target features section contains repeated feature \"" + + "target features section contains repeated feature \"" + Feature.Name + "\"", object_error::parse_failed); TargetFeatures.push_back(Feature); } if (Ctx.Ptr != Ctx.End) return make_error<GenericBinaryError>( - "target features section ended prematurely", + "target features section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -844,7 +844,7 @@ Error WasmObjectFile::parseTargetFeaturesSection(ReadContext &Ctx) { Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { uint32_t SectionIndex = readVaruint32(Ctx); if (SectionIndex >= Sections.size()) - return make_error<GenericBinaryError>("invalid section index", + return make_error<GenericBinaryError>("invalid section index", object_error::parse_failed); WasmSection &Section = Sections[SectionIndex]; uint32_t RelocCount = readVaruint32(Ctx); @@ -852,33 +852,33 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { uint32_t PreviousOffset = 0; while (RelocCount--) { wasm::WasmRelocation Reloc = {}; - uint32_t type = readVaruint32(Ctx); - Reloc.Type = type; + uint32_t type = readVaruint32(Ctx); + Reloc.Type = type; Reloc.Offset = readVaruint32(Ctx); if (Reloc.Offset < PreviousOffset) - return make_error<GenericBinaryError>("relocations not in offset order", + return make_error<GenericBinaryError>("relocations not in offset order", object_error::parse_failed); PreviousOffset = Reloc.Offset; Reloc.Index = readVaruint32(Ctx); - switch (type) { + switch (type) { case wasm::R_WASM_FUNCTION_INDEX_LEB: case wasm::R_WASM_TABLE_INDEX_SLEB: - case wasm::R_WASM_TABLE_INDEX_SLEB64: + case wasm::R_WASM_TABLE_INDEX_SLEB64: case wasm::R_WASM_TABLE_INDEX_I32: - case wasm::R_WASM_TABLE_INDEX_I64: + case wasm::R_WASM_TABLE_INDEX_I64: case wasm::R_WASM_TABLE_INDEX_REL_SLEB: if (!isValidFunctionSymbol(Reloc.Index)) - return make_error<GenericBinaryError>( - "invalid relocation function index", object_error::parse_failed); - break; - case wasm::R_WASM_TABLE_NUMBER_LEB: - if (!isValidTableSymbol(Reloc.Index)) - return make_error<GenericBinaryError>("invalid relocation table index", + return make_error<GenericBinaryError>( + "invalid relocation function index", object_error::parse_failed); + break; + case wasm::R_WASM_TABLE_NUMBER_LEB: + if (!isValidTableSymbol(Reloc.Index)) + return make_error<GenericBinaryError>("invalid relocation table index", object_error::parse_failed); break; case wasm::R_WASM_TYPE_INDEX_LEB: if (Reloc.Index >= Signatures.size()) - return make_error<GenericBinaryError>("invalid relocation type index", + return make_error<GenericBinaryError>("invalid relocation type index", object_error::parse_failed); break; case wasm::R_WASM_GLOBAL_INDEX_LEB: @@ -887,26 +887,26 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { if (!isValidGlobalSymbol(Reloc.Index) && !isValidDataSymbol(Reloc.Index) && !isValidFunctionSymbol(Reloc.Index)) - return make_error<GenericBinaryError>("invalid relocation global index", + return make_error<GenericBinaryError>("invalid relocation global index", object_error::parse_failed); break; case wasm::R_WASM_GLOBAL_INDEX_I32: if (!isValidGlobalSymbol(Reloc.Index)) - return make_error<GenericBinaryError>("invalid relocation global index", + return make_error<GenericBinaryError>("invalid relocation global index", object_error::parse_failed); break; case wasm::R_WASM_EVENT_INDEX_LEB: if (!isValidEventSymbol(Reloc.Index)) - return make_error<GenericBinaryError>("invalid relocation event index", + return make_error<GenericBinaryError>("invalid relocation event index", object_error::parse_failed); break; case wasm::R_WASM_MEMORY_ADDR_LEB: case wasm::R_WASM_MEMORY_ADDR_SLEB: case wasm::R_WASM_MEMORY_ADDR_I32: case wasm::R_WASM_MEMORY_ADDR_REL_SLEB: - case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB: + case wasm::R_WASM_MEMORY_ADDR_TLS_SLEB: if (!isValidDataSymbol(Reloc.Index)) - return make_error<GenericBinaryError>("invalid relocation data index", + return make_error<GenericBinaryError>("invalid relocation data index", object_error::parse_failed); Reloc.Addend = readVarint32(Ctx); break; @@ -915,31 +915,31 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { case wasm::R_WASM_MEMORY_ADDR_I64: case wasm::R_WASM_MEMORY_ADDR_REL_SLEB64: if (!isValidDataSymbol(Reloc.Index)) - return make_error<GenericBinaryError>("invalid relocation data index", + return make_error<GenericBinaryError>("invalid relocation data index", object_error::parse_failed); Reloc.Addend = readVarint64(Ctx); break; case wasm::R_WASM_FUNCTION_OFFSET_I32: if (!isValidFunctionSymbol(Reloc.Index)) - return make_error<GenericBinaryError>( - "invalid relocation function index", object_error::parse_failed); + return make_error<GenericBinaryError>( + "invalid relocation function index", object_error::parse_failed); Reloc.Addend = readVarint32(Ctx); break; - case wasm::R_WASM_FUNCTION_OFFSET_I64: - if (!isValidFunctionSymbol(Reloc.Index)) - return make_error<GenericBinaryError>( - "invalid relocation function index", object_error::parse_failed); - Reloc.Addend = readVarint64(Ctx); - break; + case wasm::R_WASM_FUNCTION_OFFSET_I64: + if (!isValidFunctionSymbol(Reloc.Index)) + return make_error<GenericBinaryError>( + "invalid relocation function index", object_error::parse_failed); + Reloc.Addend = readVarint64(Ctx); + break; case wasm::R_WASM_SECTION_OFFSET_I32: if (!isValidSectionSymbol(Reloc.Index)) - return make_error<GenericBinaryError>( - "invalid relocation section index", object_error::parse_failed); + return make_error<GenericBinaryError>( + "invalid relocation section index", object_error::parse_failed); Reloc.Addend = readVarint32(Ctx); break; default: - return make_error<GenericBinaryError>("invalid relocation type: " + - Twine(type), + return make_error<GenericBinaryError>("invalid relocation type: " + + Twine(type), object_error::parse_failed); } @@ -957,18 +957,18 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I32 || Reloc.Type == wasm::R_WASM_GLOBAL_INDEX_I32) Size = 4; - if (Reloc.Type == wasm::R_WASM_TABLE_INDEX_I64 || - Reloc.Type == wasm::R_WASM_MEMORY_ADDR_I64 || - Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I64) + if (Reloc.Type == wasm::R_WASM_TABLE_INDEX_I64 || + Reloc.Type == wasm::R_WASM_MEMORY_ADDR_I64 || + Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I64) Size = 8; if (Reloc.Offset + Size > EndOffset) - return make_error<GenericBinaryError>("invalid relocation offset", + return make_error<GenericBinaryError>("invalid relocation offset", object_error::parse_failed); Section.Relocations.push_back(Reloc); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("reloc section ended prematurely", + return make_error<GenericBinaryError>("reloc section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1003,7 +1003,7 @@ Error WasmObjectFile::parseTypeSection(ReadContext &Ctx) { wasm::WasmSignature Sig; uint8_t Form = readUint8(Ctx); if (Form != wasm::WASM_TYPE_FUNC) { - return make_error<GenericBinaryError>("invalid signature type", + return make_error<GenericBinaryError>("invalid signature type", object_error::parse_failed); } uint32_t ParamCount = readVaruint32(Ctx); @@ -1020,7 +1020,7 @@ Error WasmObjectFile::parseTypeSection(ReadContext &Ctx) { Signatures.push_back(std::move(Sig)); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("type section ended prematurely", + return make_error<GenericBinaryError>("type section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1045,32 +1045,32 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) { break; case wasm::WASM_EXTERNAL_MEMORY: Im.Memory = readLimits(Ctx); - if (Im.Memory.Flags & wasm::WASM_LIMITS_FLAG_IS_64) - HasMemory64 = true; + if (Im.Memory.Flags & wasm::WASM_LIMITS_FLAG_IS_64) + HasMemory64 = true; break; - case wasm::WASM_EXTERNAL_TABLE: { - Im.Table = readTableType(Ctx); - NumImportedTables++; - auto ElemType = Im.Table.ElemType; - if (ElemType != wasm::WASM_TYPE_FUNCREF && - ElemType != wasm::WASM_TYPE_EXTERNREF) - return make_error<GenericBinaryError>("invalid table element type", + case wasm::WASM_EXTERNAL_TABLE: { + Im.Table = readTableType(Ctx); + NumImportedTables++; + auto ElemType = Im.Table.ElemType; + if (ElemType != wasm::WASM_TYPE_FUNCREF && + ElemType != wasm::WASM_TYPE_EXTERNREF) + return make_error<GenericBinaryError>("invalid table element type", object_error::parse_failed); break; - } + } case wasm::WASM_EXTERNAL_EVENT: NumImportedEvents++; Im.Event.Attribute = readVarint32(Ctx); Im.Event.SigIndex = readVarint32(Ctx); break; default: - return make_error<GenericBinaryError>("unexpected import kind", + return make_error<GenericBinaryError>("unexpected import kind", object_error::parse_failed); } Imports.push_back(Im); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("import section ended prematurely", + return make_error<GenericBinaryError>("import section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1083,34 +1083,34 @@ Error WasmObjectFile::parseFunctionSection(ReadContext &Ctx) { while (Count--) { uint32_t Type = readVaruint32(Ctx); if (Type >= NumTypes) - return make_error<GenericBinaryError>("invalid function type", + return make_error<GenericBinaryError>("invalid function type", object_error::parse_failed); FunctionTypes.push_back(Type); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("function section ended prematurely", + return make_error<GenericBinaryError>("function section ended prematurely", object_error::parse_failed); return Error::success(); } Error WasmObjectFile::parseTableSection(ReadContext &Ctx) { - TableSection = Sections.size(); + TableSection = Sections.size(); uint32_t Count = readVaruint32(Ctx); Tables.reserve(Count); while (Count--) { - wasm::WasmTable T; - T.Type = readTableType(Ctx); - T.Index = NumImportedTables + Tables.size(); - Tables.push_back(T); - auto ElemType = Tables.back().Type.ElemType; - if (ElemType != wasm::WASM_TYPE_FUNCREF && - ElemType != wasm::WASM_TYPE_EXTERNREF) { - return make_error<GenericBinaryError>("invalid table element type", + wasm::WasmTable T; + T.Type = readTableType(Ctx); + T.Index = NumImportedTables + Tables.size(); + Tables.push_back(T); + auto ElemType = Tables.back().Type.ElemType; + if (ElemType != wasm::WASM_TYPE_FUNCREF && + ElemType != wasm::WASM_TYPE_EXTERNREF) { + return make_error<GenericBinaryError>("invalid table element type", object_error::parse_failed); } } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("table section ended prematurely", + return make_error<GenericBinaryError>("table section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1119,13 +1119,13 @@ Error WasmObjectFile::parseMemorySection(ReadContext &Ctx) { uint32_t Count = readVaruint32(Ctx); Memories.reserve(Count); while (Count--) { - auto Limits = readLimits(Ctx); - if (Limits.Flags & wasm::WASM_LIMITS_FLAG_IS_64) - HasMemory64 = true; - Memories.push_back(Limits); + auto Limits = readLimits(Ctx); + if (Limits.Flags & wasm::WASM_LIMITS_FLAG_IS_64) + HasMemory64 = true; + Memories.push_back(Limits); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("memory section ended prematurely", + return make_error<GenericBinaryError>("memory section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1143,7 +1143,7 @@ Error WasmObjectFile::parseEventSection(ReadContext &Ctx) { } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("event section ended prematurely", + return make_error<GenericBinaryError>("event section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1162,7 +1162,7 @@ Error WasmObjectFile::parseGlobalSection(ReadContext &Ctx) { Globals.push_back(Global); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("global section ended prematurely", + return make_error<GenericBinaryError>("global section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1179,31 +1179,31 @@ Error WasmObjectFile::parseExportSection(ReadContext &Ctx) { case wasm::WASM_EXTERNAL_FUNCTION: if (!isDefinedFunctionIndex(Ex.Index)) - return make_error<GenericBinaryError>("invalid function export", + return make_error<GenericBinaryError>("invalid function export", object_error::parse_failed); getDefinedFunction(Ex.Index).ExportName = Ex.Name; break; case wasm::WASM_EXTERNAL_GLOBAL: if (!isValidGlobalIndex(Ex.Index)) - return make_error<GenericBinaryError>("invalid global export", + return make_error<GenericBinaryError>("invalid global export", object_error::parse_failed); break; case wasm::WASM_EXTERNAL_EVENT: if (!isValidEventIndex(Ex.Index)) - return make_error<GenericBinaryError>("invalid event export", + return make_error<GenericBinaryError>("invalid event export", object_error::parse_failed); break; case wasm::WASM_EXTERNAL_MEMORY: case wasm::WASM_EXTERNAL_TABLE: break; default: - return make_error<GenericBinaryError>("unexpected export kind", + return make_error<GenericBinaryError>("unexpected export kind", object_error::parse_failed); } Exports.push_back(Ex); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("export section ended prematurely", + return make_error<GenericBinaryError>("export section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1220,18 +1220,18 @@ bool WasmObjectFile::isValidGlobalIndex(uint32_t Index) const { return Index < NumImportedGlobals + Globals.size(); } -bool WasmObjectFile::isValidTableIndex(uint32_t Index) const { - return Index < NumImportedTables + Tables.size(); -} - +bool WasmObjectFile::isValidTableIndex(uint32_t Index) const { + return Index < NumImportedTables + Tables.size(); +} + bool WasmObjectFile::isDefinedGlobalIndex(uint32_t Index) const { return Index >= NumImportedGlobals && isValidGlobalIndex(Index); } -bool WasmObjectFile::isDefinedTableIndex(uint32_t Index) const { - return Index >= NumImportedTables && isValidTableIndex(Index); -} - +bool WasmObjectFile::isDefinedTableIndex(uint32_t Index) const { + return Index >= NumImportedTables && isValidTableIndex(Index); +} + bool WasmObjectFile::isValidEventIndex(uint32_t Index) const { return Index < NumImportedEvents + Events.size(); } @@ -1244,10 +1244,10 @@ bool WasmObjectFile::isValidFunctionSymbol(uint32_t Index) const { return Index < Symbols.size() && Symbols[Index].isTypeFunction(); } -bool WasmObjectFile::isValidTableSymbol(uint32_t Index) const { - return Index < Symbols.size() && Symbols[Index].isTypeTable(); -} - +bool WasmObjectFile::isValidTableSymbol(uint32_t Index) const { + return Index < Symbols.size() && Symbols[Index].isTypeTable(); +} + bool WasmObjectFile::isValidGlobalSymbol(uint32_t Index) const { return Index < Symbols.size() && Symbols[Index].isTypeGlobal(); } @@ -1288,7 +1288,7 @@ wasm::WasmEvent &WasmObjectFile::getDefinedEvent(uint32_t Index) { Error WasmObjectFile::parseStartSection(ReadContext &Ctx) { StartFunction = readVaruint32(Ctx); if (!isValidFunctionIndex(StartFunction)) - return make_error<GenericBinaryError>("invalid start function", + return make_error<GenericBinaryError>("invalid start function", object_error::parse_failed); return Error::success(); } @@ -1298,7 +1298,7 @@ Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) { CodeSection = Sections.size(); uint32_t FunctionCount = readVaruint32(Ctx); if (FunctionCount != FunctionTypes.size()) { - return make_error<GenericBinaryError>("invalid function count", + return make_error<GenericBinaryError>("invalid function count", object_error::parse_failed); } @@ -1330,7 +1330,7 @@ Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) { assert(Ctx.Ptr == FunctionEnd); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("code section ended prematurely", + return make_error<GenericBinaryError>("code section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1342,7 +1342,7 @@ Error WasmObjectFile::parseElemSection(ReadContext &Ctx) { wasm::WasmElemSegment Segment; Segment.TableIndex = readVaruint32(Ctx); if (Segment.TableIndex != 0) { - return make_error<GenericBinaryError>("invalid TableIndex", + return make_error<GenericBinaryError>("invalid TableIndex", object_error::parse_failed); } if (Error Err = readInitExpr(Segment.Offset, Ctx)) @@ -1354,7 +1354,7 @@ Error WasmObjectFile::parseElemSection(ReadContext &Ctx) { ElemSegments.push_back(Segment); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("elem section ended prematurely", + return make_error<GenericBinaryError>("elem section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1364,16 +1364,16 @@ Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { uint32_t Count = readVaruint32(Ctx); if (DataCount && Count != DataCount.getValue()) return make_error<GenericBinaryError>( - "number of data segments does not match DataCount section"); + "number of data segments does not match DataCount section"); DataSegments.reserve(Count); while (Count--) { WasmSegment Segment; Segment.Data.InitFlags = readVaruint32(Ctx); - Segment.Data.MemoryIndex = - (Segment.Data.InitFlags & wasm::WASM_DATA_SEGMENT_HAS_MEMINDEX) - ? readVaruint32(Ctx) - : 0; - if ((Segment.Data.InitFlags & wasm::WASM_DATA_SEGMENT_IS_PASSIVE) == 0) { + Segment.Data.MemoryIndex = + (Segment.Data.InitFlags & wasm::WASM_DATA_SEGMENT_HAS_MEMINDEX) + ? readVaruint32(Ctx) + : 0; + if ((Segment.Data.InitFlags & wasm::WASM_DATA_SEGMENT_IS_PASSIVE) == 0) { if (Error Err = readInitExpr(Segment.Data.Offset, Ctx)) return Err; } else { @@ -1382,7 +1382,7 @@ Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { } uint32_t Size = readVaruint32(Ctx); if (Size > (size_t)(Ctx.End - Ctx.Ptr)) - return make_error<GenericBinaryError>("invalid segment size", + return make_error<GenericBinaryError>("invalid segment size", object_error::parse_failed); Segment.Data.Content = ArrayRef<uint8_t>(Ctx.Ptr, Size); // The rest of these Data fields are set later, when reading in the linking @@ -1395,7 +1395,7 @@ Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { DataSegments.push_back(Segment); } if (Ctx.Ptr != Ctx.End) - return make_error<GenericBinaryError>("data section ended prematurely", + return make_error<GenericBinaryError>("data section ended prematurely", object_error::parse_failed); return Error::success(); } @@ -1469,7 +1469,7 @@ uint64_t WasmObjectFile::getWasmSymbolValue(const WasmSymbol &Sym) const { case wasm::WASM_SYMBOL_TYPE_FUNCTION: case wasm::WASM_SYMBOL_TYPE_GLOBAL: case wasm::WASM_SYMBOL_TYPE_EVENT: - case wasm::WASM_SYMBOL_TYPE_TABLE: + case wasm::WASM_SYMBOL_TYPE_TABLE: return Sym.Info.ElementIndex; case wasm::WASM_SYMBOL_TYPE_DATA: { // The value of a data symbol is the segment offset, plus the symbol @@ -1519,11 +1519,11 @@ WasmObjectFile::getSymbolType(DataRefImpl Symb) const { return SymbolRef::ST_Debug; case wasm::WASM_SYMBOL_TYPE_EVENT: return SymbolRef::ST_Other; - case wasm::WASM_SYMBOL_TYPE_TABLE: - return SymbolRef::ST_Other; + case wasm::WASM_SYMBOL_TYPE_TABLE: + return SymbolRef::ST_Other; } - llvm_unreachable("unknown WasmSymbol::SymbolType"); + llvm_unreachable("unknown WasmSymbol::SymbolType"); return SymbolRef::ST_Other; } @@ -1555,10 +1555,10 @@ uint32_t WasmObjectFile::getSymbolSectionIdImpl(const WasmSymbol &Sym) const { return Sym.Info.ElementIndex; case wasm::WASM_SYMBOL_TYPE_EVENT: return EventSection; - case wasm::WASM_SYMBOL_TYPE_TABLE: - return TableSection; + case wasm::WASM_SYMBOL_TYPE_TABLE: + return TableSection; default: - llvm_unreachable("unknown WasmSymbol::SymbolType"); + llvm_unreachable("unknown WasmSymbol::SymbolType"); } } @@ -1698,15 +1698,15 @@ section_iterator WasmObjectFile::section_end() const { return section_iterator(SectionRef(Ref, this)); } -uint8_t WasmObjectFile::getBytesInAddress() const { - return HasMemory64 ? 8 : 4; -} +uint8_t WasmObjectFile::getBytesInAddress() const { + return HasMemory64 ? 8 : 4; +} StringRef WasmObjectFile::getFileFormatName() const { return "WASM"; } -Triple::ArchType WasmObjectFile::getArch() const { - return HasMemory64 ? Triple::wasm64 : Triple::wasm32; -} +Triple::ArchType WasmObjectFile::getArch() const { + return HasMemory64 ? Triple::wasm64 : Triple::wasm32; +} SubtargetFeatures WasmObjectFile::getFeatures() const { return SubtargetFeatures(); |
