aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/lib/Object
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/libs/llvm12/lib/Object
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/Object')
-rw-r--r--contrib/libs/llvm12/lib/Object/Archive.cpp4
-rw-r--r--contrib/libs/llvm12/lib/Object/ArchiveWriter.cpp222
-rw-r--r--contrib/libs/llvm12/lib/Object/Binary.cpp12
-rw-r--r--contrib/libs/llvm12/lib/Object/COFFObjectFile.cpp114
-rw-r--r--contrib/libs/llvm12/lib/Object/ELF.cpp80
-rw-r--r--contrib/libs/llvm12/lib/Object/ELFObjectFile.cpp284
-rw-r--r--contrib/libs/llvm12/lib/Object/MachOObjectFile.cpp66
-rw-r--r--contrib/libs/llvm12/lib/Object/MachOUniversal.cpp58
-rw-r--r--contrib/libs/llvm12/lib/Object/MachOUniversalWriter.cpp674
-rw-r--r--contrib/libs/llvm12/lib/Object/ObjectFile.cpp6
-rw-r--r--contrib/libs/llvm12/lib/Object/RelocationResolver.cpp366
-rw-r--r--contrib/libs/llvm12/lib/Object/SymbolSize.cpp2
-rw-r--r--contrib/libs/llvm12/lib/Object/SymbolicFile.cpp86
-rw-r--r--contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp476
-rw-r--r--contrib/libs/llvm12/lib/Object/XCOFFObjectFile.cpp600
-rw-r--r--contrib/libs/llvm12/lib/Object/ya.make20
16 files changed, 1535 insertions, 1535 deletions
diff --git a/contrib/libs/llvm12/lib/Object/Archive.cpp b/contrib/libs/llvm12/lib/Object/Archive.cpp
index 3883de192f..11c9de4455 100644
--- a/contrib/libs/llvm12/lib/Object/Archive.cpp
+++ b/contrib/libs/llvm12/lib/Object/Archive.cpp
@@ -38,8 +38,8 @@ using namespace llvm;
using namespace object;
using namespace llvm::support::endian;
-const char Magic[] = "!<arch>\n";
-const char ThinMagic[] = "!<thin>\n";
+const char Magic[] = "!<arch>\n";
+const char ThinMagic[] = "!<thin>\n";
void Archive::anchor() {}
diff --git a/contrib/libs/llvm12/lib/Object/ArchiveWriter.cpp b/contrib/libs/llvm12/lib/Object/ArchiveWriter.cpp
index ea3f3929b5..ce997464ca 100644
--- a/contrib/libs/llvm12/lib/Object/ArchiveWriter.cpp
+++ b/contrib/libs/llvm12/lib/Object/ArchiveWriter.cpp
@@ -26,7 +26,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/SmallVectorMemoryBuffer.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/raw_ostream.h"
@@ -286,12 +286,12 @@ static void printNBits(raw_ostream &Out, object::Archive::Kind Kind,
print<uint32_t>(Out, Kind, Val);
}
-static uint64_t computeSymbolTableSize(object::Archive::Kind Kind,
- uint64_t NumSyms, uint64_t OffsetSize,
- StringRef StringTable,
- uint32_t *Padding = nullptr) {
- assert((OffsetSize == 4 || OffsetSize == 8) && "Unsupported OffsetSize");
- uint64_t Size = OffsetSize; // Number of entries
+static uint64_t computeSymbolTableSize(object::Archive::Kind Kind,
+ uint64_t NumSyms, uint64_t OffsetSize,
+ StringRef StringTable,
+ uint32_t *Padding = nullptr) {
+ assert((OffsetSize == 4 || OffsetSize == 8) && "Unsupported OffsetSize");
+ uint64_t Size = OffsetSize; // Number of entries
if (isBSDLike(Kind))
Size += NumSyms * OffsetSize * 2; // Table
else
@@ -303,15 +303,15 @@ static uint64_t computeSymbolTableSize(object::Archive::Kind Kind,
// least 4-byte aligned for 32-bit content. Opt for the larger encoding
// uniformly.
// We do this for all bsd formats because it simplifies aligning members.
- uint32_t Pad = offsetToAlignment(Size, Align(isBSDLike(Kind) ? 8 : 2));
+ uint32_t Pad = offsetToAlignment(Size, Align(isBSDLike(Kind) ? 8 : 2));
Size += Pad;
- if (Padding)
- *Padding = Pad;
- return Size;
-}
+ if (Padding)
+ *Padding = Pad;
+ return Size;
+}
-static void writeSymbolTableHeader(raw_ostream &Out, object::Archive::Kind Kind,
- bool Deterministic, uint64_t Size) {
+static void writeSymbolTableHeader(raw_ostream &Out, object::Archive::Kind Kind,
+ bool Deterministic, uint64_t Size) {
if (isBSDLike(Kind)) {
const char *Name = is64BitKind(Kind) ? "__.SYMDEF_64" : "__.SYMDEF";
printBSDMemberHeader(Out, Out.tell(), Name, now(Deterministic), 0, 0, 0,
@@ -320,25 +320,25 @@ static void writeSymbolTableHeader(raw_ostream &Out, object::Archive::Kind Kind,
const char *Name = is64BitKind(Kind) ? "/SYM64" : "";
printGNUSmallMemberHeader(Out, Name, now(Deterministic), 0, 0, 0, Size);
}
-}
-
-static void writeSymbolTable(raw_ostream &Out, object::Archive::Kind Kind,
- bool Deterministic, ArrayRef<MemberData> Members,
- StringRef StringTable) {
- // We don't write a symbol table on an archive with no members -- except on
- // Darwin, where the linker will abort unless the archive has a symbol table.
- if (StringTable.empty() && !isDarwin(Kind))
- return;
-
- unsigned NumSyms = 0;
- for (const MemberData &M : Members)
- NumSyms += M.Symbols.size();
-
- uint64_t OffsetSize = is64BitKind(Kind) ? 8 : 4;
- uint32_t Pad;
- uint64_t Size = computeSymbolTableSize(Kind, NumSyms, OffsetSize, StringTable, &Pad);
- writeSymbolTableHeader(Out, Kind, Deterministic, Size);
-
+}
+
+static void writeSymbolTable(raw_ostream &Out, object::Archive::Kind Kind,
+ bool Deterministic, ArrayRef<MemberData> Members,
+ StringRef StringTable) {
+ // We don't write a symbol table on an archive with no members -- except on
+ // Darwin, where the linker will abort unless the archive has a symbol table.
+ if (StringTable.empty() && !isDarwin(Kind))
+ return;
+
+ unsigned NumSyms = 0;
+ for (const MemberData &M : Members)
+ NumSyms += M.Symbols.size();
+
+ uint64_t OffsetSize = is64BitKind(Kind) ? 8 : 4;
+ uint32_t Pad;
+ uint64_t Size = computeSymbolTableSize(Kind, NumSyms, OffsetSize, StringTable, &Pad);
+ writeSymbolTableHeader(Out, Kind, Deterministic, Size);
+
uint64_t Pos = Out.tell() + Size;
if (isBSDLike(Kind))
@@ -372,21 +372,21 @@ getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject) {
// reference to it, thus SymbolicFile should be destroyed first.
LLVMContext Context;
std::unique_ptr<object::SymbolicFile> Obj;
-
- const file_magic Type = identify_magic(Buf.getBuffer());
- // Treat unsupported file types as having no symbols.
- if (!object::SymbolicFile::isSymbolicFile(Type, &Context))
- return Ret;
- if (Type == file_magic::bitcode) {
+
+ const file_magic Type = identify_magic(Buf.getBuffer());
+ // Treat unsupported file types as having no symbols.
+ if (!object::SymbolicFile::isSymbolicFile(Type, &Context))
+ return Ret;
+ if (Type == file_magic::bitcode) {
auto ObjOrErr = object::SymbolicFile::createSymbolicFile(
Buf, file_magic::bitcode, &Context);
- if (!ObjOrErr)
- return ObjOrErr.takeError();
+ if (!ObjOrErr)
+ return ObjOrErr.takeError();
Obj = std::move(*ObjOrErr);
} else {
auto ObjOrErr = object::SymbolicFile::createSymbolicFile(Buf);
- if (!ObjOrErr)
- return ObjOrErr.takeError();
+ if (!ObjOrErr)
+ return ObjOrErr.takeError();
Obj = std::move(*ObjOrErr);
}
@@ -405,7 +405,7 @@ getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject) {
static Expected<std::vector<MemberData>>
computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
object::Archive::Kind Kind, bool Thin, bool Deterministic,
- bool NeedSymbols, ArrayRef<NewArchiveMember> NewMembers) {
+ bool NeedSymbols, ArrayRef<NewArchiveMember> NewMembers) {
static char PaddingData[8] = {'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'};
// This ignores the symbol table, but we only need the value mod 8 and the
@@ -506,17 +506,17 @@ computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
ModTime, Size);
Out.flush();
- std::vector<unsigned> Symbols;
- if (NeedSymbols) {
- Expected<std::vector<unsigned>> SymbolsOrErr =
- getSymbols(Buf, SymNames, HasObject);
- if (auto E = SymbolsOrErr.takeError())
- return std::move(E);
- Symbols = std::move(*SymbolsOrErr);
- }
+ std::vector<unsigned> Symbols;
+ if (NeedSymbols) {
+ Expected<std::vector<unsigned>> SymbolsOrErr =
+ getSymbols(Buf, SymNames, HasObject);
+ if (auto E = SymbolsOrErr.takeError())
+ return std::move(E);
+ Symbols = std::move(*SymbolsOrErr);
+ }
Pos += Header.size() + Data.size() + Padding.size();
- Ret.push_back({std::move(Symbols), std::move(Header), Data, Padding});
+ Ret.push_back({std::move(Symbols), std::move(Header), Data, Padding});
}
// If there are no symbols, emit an empty symbol table, to satisfy Solaris
// tools, older versions of which expect a symbol table in a non-empty
@@ -569,10 +569,10 @@ Expected<std::string> computeArchiveRelativePath(StringRef From, StringRef To) {
return std::string(Relative.str());
}
-static Error writeArchiveToStream(raw_ostream &Out,
- ArrayRef<NewArchiveMember> NewMembers,
- bool WriteSymtab, object::Archive::Kind Kind,
- bool Deterministic, bool Thin) {
+static Error writeArchiveToStream(raw_ostream &Out,
+ ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin) {
assert((!Thin || !isBSDLike(Kind)) && "Only the gnu format has a thin mode");
SmallString<0> SymNamesBuf;
@@ -580,9 +580,9 @@ static Error writeArchiveToStream(raw_ostream &Out,
SmallString<0> StringTableBuf;
raw_svector_ostream StringTable(StringTableBuf);
- Expected<std::vector<MemberData>> DataOrErr =
- computeMemberData(StringTable, SymNames, Kind, Thin, Deterministic,
- WriteSymtab, NewMembers);
+ Expected<std::vector<MemberData>> DataOrErr =
+ computeMemberData(StringTable, SymNames, Kind, Thin, Deterministic,
+ WriteSymtab, NewMembers);
if (Error E = DataOrErr.takeError())
return E;
std::vector<MemberData> &Data = *DataOrErr;
@@ -592,28 +592,28 @@ static Error writeArchiveToStream(raw_ostream &Out,
// We would like to detect if we need to switch to a 64-bit symbol table.
if (WriteSymtab) {
- uint64_t MaxOffset = 8; // For the file signature.
+ uint64_t MaxOffset = 8; // For the file signature.
uint64_t LastOffset = MaxOffset;
- uint64_t NumSyms = 0;
+ uint64_t NumSyms = 0;
for (const auto &M : Data) {
// Record the start of the member's offset
LastOffset = MaxOffset;
// Account for the size of each part associated with the member.
MaxOffset += M.Header.size() + M.Data.size() + M.Padding.size();
- NumSyms += M.Symbols.size();
+ NumSyms += M.Symbols.size();
}
- // We assume 32-bit offsets to see if 32-bit symbols are possible or not.
- uint64_t SymtabSize = computeSymbolTableSize(Kind, NumSyms, 4, SymNamesBuf);
- auto computeSymbolTableHeaderSize =
- [=] {
- SmallString<0> TmpBuf;
- raw_svector_ostream Tmp(TmpBuf);
- writeSymbolTableHeader(Tmp, Kind, Deterministic, SymtabSize);
- return TmpBuf.size();
- };
- LastOffset += computeSymbolTableHeaderSize() + SymtabSize;
-
+ // We assume 32-bit offsets to see if 32-bit symbols are possible or not.
+ uint64_t SymtabSize = computeSymbolTableSize(Kind, NumSyms, 4, SymNamesBuf);
+ auto computeSymbolTableHeaderSize =
+ [=] {
+ SmallString<0> TmpBuf;
+ raw_svector_ostream Tmp(TmpBuf);
+ writeSymbolTableHeader(Tmp, Kind, Deterministic, SymtabSize);
+ return TmpBuf.size();
+ };
+ LastOffset += computeSymbolTableHeaderSize() + SymtabSize;
+
// The SYM64 format is used when an archive's member offsets are larger than
// 32-bits can hold. The need for this shift in format is detected by
// writeArchive. To test this we need to generate a file with a member that
@@ -621,7 +621,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
// speed the test up we use this environment variable to pretend like the
// cutoff happens before 32-bits and instead happens at some much smaller
// value.
- uint64_t Sym64Threshold = 1ULL << 32;
+ uint64_t Sym64Threshold = 1ULL << 32;
const char *Sym64Env = std::getenv("SYM64_THRESHOLD");
if (Sym64Env)
StringRef(Sym64Env).getAsInteger(10, Sym64Threshold);
@@ -629,7 +629,7 @@ static Error writeArchiveToStream(raw_ostream &Out,
// If LastOffset isn't going to fit in a 32-bit varible we need to switch
// to 64-bit. Note that the file can be larger than 4GB as long as the last
// member starts before the 4GB offset.
- if (LastOffset >= Sym64Threshold) {
+ if (LastOffset >= Sym64Threshold) {
if (Kind == object::Archive::K_DARWIN)
Kind = object::Archive::K_DARWIN64;
else
@@ -649,26 +649,26 @@ static Error writeArchiveToStream(raw_ostream &Out,
Out << M.Header << M.Data << M.Padding;
Out.flush();
- return Error::success();
-}
-
-Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
- bool WriteSymtab, object::Archive::Kind Kind,
- bool Deterministic, bool Thin,
- std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
- Expected<sys::fs::TempFile> Temp =
- sys::fs::TempFile::create(ArcName + ".temp-archive-%%%%%%%.a");
- if (!Temp)
- return Temp.takeError();
- raw_fd_ostream Out(Temp->FD, false);
-
- if (Error E = writeArchiveToStream(Out, NewMembers, WriteSymtab, Kind,
- Deterministic, Thin)) {
- if (Error DiscardError = Temp->discard())
- return joinErrors(std::move(E), std::move(DiscardError));
- return E;
- }
-
+ return Error::success();
+}
+
+Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
+ Expected<sys::fs::TempFile> Temp =
+ sys::fs::TempFile::create(ArcName + ".temp-archive-%%%%%%%.a");
+ if (!Temp)
+ return Temp.takeError();
+ raw_fd_ostream Out(Temp->FD, false);
+
+ if (Error E = writeArchiveToStream(Out, NewMembers, WriteSymtab, Kind,
+ Deterministic, Thin)) {
+ if (Error DiscardError = Temp->discard())
+ return joinErrors(std::move(E), std::move(DiscardError));
+ return E;
+ }
+
// At this point, we no longer need whatever backing memory
// was used to generate the NewMembers. On Windows, this buffer
// could be a mapped view of the file we want to replace (if
@@ -684,19 +684,19 @@ Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
return Temp->keep(ArcName);
}
-Expected<std::unique_ptr<MemoryBuffer>>
-writeArchiveToBuffer(ArrayRef<NewArchiveMember> NewMembers, bool WriteSymtab,
- object::Archive::Kind Kind, bool Deterministic,
- bool Thin) {
- SmallVector<char, 0> ArchiveBufferVector;
- raw_svector_ostream ArchiveStream(ArchiveBufferVector);
-
- if (Error E = writeArchiveToStream(ArchiveStream, NewMembers, WriteSymtab,
- Kind, Deterministic, Thin))
- return std::move(E);
-
- return std::make_unique<SmallVectorMemoryBuffer>(
- std::move(ArchiveBufferVector));
-}
-
+Expected<std::unique_ptr<MemoryBuffer>>
+writeArchiveToBuffer(ArrayRef<NewArchiveMember> NewMembers, bool WriteSymtab,
+ object::Archive::Kind Kind, bool Deterministic,
+ bool Thin) {
+ SmallVector<char, 0> ArchiveBufferVector;
+ raw_svector_ostream ArchiveStream(ArchiveBufferVector);
+
+ if (Error E = writeArchiveToStream(ArchiveStream, NewMembers, WriteSymtab,
+ Kind, Deterministic, Thin))
+ return std::move(E);
+
+ return std::make_unique<SmallVectorMemoryBuffer>(
+ std::move(ArchiveBufferVector));
+}
+
} // namespace llvm
diff --git a/contrib/libs/llvm12/lib/Object/Binary.cpp b/contrib/libs/llvm12/lib/Object/Binary.cpp
index 5ed8bd9e79..e741cbba28 100644
--- a/contrib/libs/llvm12/lib/Object/Binary.cpp
+++ b/contrib/libs/llvm12/lib/Object/Binary.cpp
@@ -44,8 +44,8 @@ StringRef Binary::getFileName() const { return Data.getBufferIdentifier(); }
MemoryBufferRef Binary::getMemoryBufferRef() const { return Data; }
Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
- LLVMContext *Context,
- bool InitContent) {
+ LLVMContext *Context,
+ bool InitContent) {
file_magic Type = identify_magic(Buffer.getBuffer());
switch (Type) {
@@ -74,7 +74,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
case file_magic::xcoff_object_32:
case file_magic::xcoff_object_64:
case file_magic::wasm_object:
- return ObjectFile::createSymbolicFile(Buffer, Type, Context, InitContent);
+ return ObjectFile::createSymbolicFile(Buffer, Type, Context, InitContent);
case file_magic::macho_universal_binary:
return MachOUniversalBinary::create(Buffer);
case file_magic::windows_resource:
@@ -94,8 +94,8 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
llvm_unreachable("Unexpected Binary File Type");
}
-Expected<OwningBinary<Binary>>
-object::createBinary(StringRef Path, LLVMContext *Context, bool InitContent) {
+Expected<OwningBinary<Binary>>
+object::createBinary(StringRef Path, LLVMContext *Context, bool InitContent) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
/*RequiresNullTerminator=*/false);
@@ -104,7 +104,7 @@ object::createBinary(StringRef Path, LLVMContext *Context, bool InitContent) {
std::unique_ptr<MemoryBuffer> &Buffer = FileOrErr.get();
Expected<std::unique_ptr<Binary>> BinOrErr =
- createBinary(Buffer->getMemBufferRef(), Context, InitContent);
+ createBinary(Buffer->getMemBufferRef(), Context, InitContent);
if (!BinOrErr)
return BinOrErr.takeError();
std::unique_ptr<Binary> &Bin = BinOrErr.get();
diff --git a/contrib/libs/llvm12/lib/Object/COFFObjectFile.cpp b/contrib/libs/llvm12/lib/Object/COFFObjectFile.cpp
index 43601ed58d..6e9a8eb35d 100644
--- a/contrib/libs/llvm12/lib/Object/COFFObjectFile.cpp
+++ b/contrib/libs/llvm12/lib/Object/COFFObjectFile.cpp
@@ -28,7 +28,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include <algorithm>
#include <cassert>
-#include <cinttypes>
+#include <cinttypes>
#include <cstddef>
#include <cstring>
#include <limits>
@@ -57,7 +57,7 @@ static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size) {
template <typename T>
static Error getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr,
const uint64_t Size = sizeof(T)) {
- uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr);
+ uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr);
if (Error E = Binary::checkOffset(M, Addr, Size))
return E;
Obj = reinterpret_cast<const T *>(Addr);
@@ -103,11 +103,11 @@ const coff_symbol_type *COFFObjectFile::toSymb(DataRefImpl Ref) const {
const coff_symbol_type *Addr =
reinterpret_cast<const coff_symbol_type *>(Ref.p);
- assert(!checkOffset(Data, reinterpret_cast<uintptr_t>(Addr), sizeof(*Addr)));
+ assert(!checkOffset(Data, reinterpret_cast<uintptr_t>(Addr), sizeof(*Addr)));
#ifndef NDEBUG
// Verify that the symbol points to a valid entry in the symbol table.
- uintptr_t Offset =
- reinterpret_cast<uintptr_t>(Addr) - reinterpret_cast<uintptr_t>(base());
+ uintptr_t Offset =
+ reinterpret_cast<uintptr_t>(Addr) - reinterpret_cast<uintptr_t>(base());
assert((Offset - getPointerToSymbolTable()) % sizeof(coff_symbol_type) == 0 &&
"Symbol did not point to the beginning of a symbol");
@@ -124,8 +124,8 @@ const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const {
if (Addr < SectionTable || Addr >= (SectionTable + getNumberOfSections()))
report_fatal_error("Section was outside of section table.");
- uintptr_t Offset = reinterpret_cast<uintptr_t>(Addr) -
- reinterpret_cast<uintptr_t>(SectionTable);
+ uintptr_t Offset = reinterpret_cast<uintptr_t>(Addr) -
+ reinterpret_cast<uintptr_t>(SectionTable);
assert(Offset % sizeof(coff_section) == 0 &&
"Section did not point to the beginning of a section");
#endif
@@ -334,7 +334,7 @@ bool COFFObjectFile::isDebugSection(StringRef SectionName) const {
unsigned COFFObjectFile::getSectionID(SectionRef Sec) const {
uintptr_t Offset =
- Sec.getRawDataRefImpl().p - reinterpret_cast<uintptr_t>(SectionTable);
+ Sec.getRawDataRefImpl().p - reinterpret_cast<uintptr_t>(SectionTable);
assert((Offset % sizeof(coff_section)) == 0);
return (Offset / sizeof(coff_section)) + 1;
}
@@ -378,7 +378,7 @@ getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) {
// relocations.
begin++;
}
- if (auto E = Binary::checkOffset(M, reinterpret_cast<uintptr_t>(begin),
+ if (auto E = Binary::checkOffset(M, reinterpret_cast<uintptr_t>(begin),
sizeof(coff_relocation) * NumRelocs)) {
consumeError(std::move(E));
return nullptr;
@@ -469,8 +469,8 @@ Error COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const {
uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
if (SectionStart <= Addr && Addr < SectionEnd) {
uint32_t Offset = Addr - SectionStart;
- Res = reinterpret_cast<uintptr_t>(base()) + Section->PointerToRawData +
- Offset;
+ Res = reinterpret_cast<uintptr_t>(base()) + Section->PointerToRawData +
+ Offset;
return Error::success();
}
}
@@ -487,8 +487,8 @@ Error COFFObjectFile::getRvaAndSizeAsBytes(uint32_t RVA, uint32_t Size,
uint32_t OffsetIntoSection = RVA - SectionStart;
if (SectionStart <= RVA && OffsetIntoSection < Section->VirtualSize &&
Size <= Section->VirtualSize - OffsetIntoSection) {
- uintptr_t Begin = reinterpret_cast<uintptr_t>(base()) +
- Section->PointerToRawData + OffsetIntoSection;
+ uintptr_t Begin = reinterpret_cast<uintptr_t>(base()) +
+ Section->PointerToRawData + OffsetIntoSection;
Contents =
ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Begin), Size);
return Error::success();
@@ -652,38 +652,38 @@ Error COFFObjectFile::initDebugDirectoryPtr() {
return Error::success();
}
-Error COFFObjectFile::initTLSDirectoryPtr() {
- // Get the RVA of the TLS directory. Do nothing if it does not exist.
- const data_directory *DataEntry = getDataDirectory(COFF::TLS_TABLE);
- if (!DataEntry)
- return Error::success();
-
- // Do nothing if the RVA is NULL.
- if (DataEntry->RelativeVirtualAddress == 0)
- return Error::success();
-
- uint64_t DirSize =
- is64() ? sizeof(coff_tls_directory64) : sizeof(coff_tls_directory32);
-
- // Check that the size is correct.
- if (DataEntry->Size != DirSize)
- return createStringError(
- object_error::parse_failed,
- "TLS Directory size (%u) is not the expected size (%" PRIu64 ").",
- static_cast<uint32_t>(DataEntry->Size), DirSize);
-
- uintptr_t IntPtr = 0;
- if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
- return E;
-
- if (is64())
- TLSDirectory64 = reinterpret_cast<const coff_tls_directory64 *>(IntPtr);
- else
- TLSDirectory32 = reinterpret_cast<const coff_tls_directory32 *>(IntPtr);
-
- return Error::success();
-}
-
+Error COFFObjectFile::initTLSDirectoryPtr() {
+ // Get the RVA of the TLS directory. Do nothing if it does not exist.
+ const data_directory *DataEntry = getDataDirectory(COFF::TLS_TABLE);
+ if (!DataEntry)
+ return Error::success();
+
+ // Do nothing if the RVA is NULL.
+ if (DataEntry->RelativeVirtualAddress == 0)
+ return Error::success();
+
+ uint64_t DirSize =
+ is64() ? sizeof(coff_tls_directory64) : sizeof(coff_tls_directory32);
+
+ // Check that the size is correct.
+ if (DataEntry->Size != DirSize)
+ return createStringError(
+ object_error::parse_failed,
+ "TLS Directory size (%u) is not the expected size (%" PRIu64 ").",
+ static_cast<uint32_t>(DataEntry->Size), DirSize);
+
+ uintptr_t IntPtr = 0;
+ if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
+ return E;
+
+ if (is64())
+ TLSDirectory64 = reinterpret_cast<const coff_tls_directory64 *>(IntPtr);
+ else
+ TLSDirectory32 = reinterpret_cast<const coff_tls_directory32 *>(IntPtr);
+
+ return Error::success();
+}
+
Error COFFObjectFile::initLoadConfigPtr() {
// Get the RVA of the debug directory. Do nothing if it does not exist.
const data_directory *DataEntry = getDataDirectory(COFF::LOAD_CONFIG_TABLE);
@@ -717,8 +717,8 @@ COFFObjectFile::COFFObjectFile(MemoryBufferRef Object)
ImportDirectory(nullptr), DelayImportDirectory(nullptr),
NumberOfDelayImportDirectory(0), ExportDirectory(nullptr),
BaseRelocHeader(nullptr), BaseRelocEnd(nullptr),
- DebugDirectoryBegin(nullptr), DebugDirectoryEnd(nullptr),
- TLSDirectory32(nullptr), TLSDirectory64(nullptr) {}
+ DebugDirectoryBegin(nullptr), DebugDirectoryEnd(nullptr),
+ TLSDirectory32(nullptr), TLSDirectory64(nullptr) {}
Error COFFObjectFile::initialize() {
// Check that we at least have enough room for a header.
@@ -845,14 +845,14 @@ Error COFFObjectFile::initialize() {
if (Error E = initBaseRelocPtr())
return E;
- // Initialize the pointer to the debug directory.
+ // Initialize the pointer to the debug directory.
if (Error E = initDebugDirectoryPtr())
return E;
- // Initialize the pointer to the TLS directory.
- if (Error E = initTLSDirectoryPtr())
- return E;
-
+ // Initialize the pointer to the TLS directory.
+ if (Error E = initTLSDirectoryPtr())
+ return E;
+
if (Error E = initLoadConfigPtr())
return E;
@@ -1130,8 +1130,8 @@ Error COFFObjectFile::getSectionContents(const coff_section *Sec,
// The only thing that we need to verify is that the contents is contained
// within the file bounds. We don't need to make sure it doesn't cover other
// data, as there's nothing that says that is not allowed.
- uintptr_t ConStart =
- reinterpret_cast<uintptr_t>(base()) + Sec->PointerToRawData;
+ uintptr_t ConStart =
+ reinterpret_cast<uintptr_t>(base()) + Sec->PointerToRawData;
uint32_t SectionSize = getSectionSize(Sec);
if (Error E = checkOffset(Data, ConStart, SectionSize))
return E;
@@ -1791,9 +1791,9 @@ Error ResourceSectionRef::load(const COFFObjectFile *O, const SectionRef &S) {
Relocs.reserve(OrigRelocs.size());
for (const coff_relocation &R : OrigRelocs)
Relocs.push_back(&R);
- llvm::sort(Relocs, [](const coff_relocation *A, const coff_relocation *B) {
- return A->VirtualAddress < B->VirtualAddress;
- });
+ llvm::sort(Relocs, [](const coff_relocation *A, const coff_relocation *B) {
+ return A->VirtualAddress < B->VirtualAddress;
+ });
return Error::success();
}
diff --git a/contrib/libs/llvm12/lib/Object/ELF.cpp b/contrib/libs/llvm12/lib/Object/ELF.cpp
index 15d169f8c8..264f115ddb 100644
--- a/contrib/libs/llvm12/lib/Object/ELF.cpp
+++ b/contrib/libs/llvm12/lib/Object/ELF.cpp
@@ -152,13 +152,13 @@ StringRef llvm::object::getELFRelocationTypeName(uint32_t Machine,
break;
}
break;
- case ELF::EM_CSKY:
- switch (Type) {
-#include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
- default:
- break;
- }
- break;
+ case ELF::EM_CSKY:
+ switch (Type) {
+#include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
+ default:
+ break;
+ }
+ break;
default:
break;
}
@@ -201,8 +201,8 @@ uint32_t llvm::object::getELFRelativeRelocationType(uint32_t Machine) {
case ELF::EM_SPARC32PLUS:
case ELF::EM_SPARCV9:
return ELF::R_SPARC_RELATIVE;
- case ELF::EM_CSKY:
- return ELF::R_CKCORE_RELATIVE;
+ case ELF::EM_CSKY:
+ return ELF::R_CKCORE_RELATIVE;
case ELF::EM_AMDGPU:
break;
case ELF::EM_BPF:
@@ -276,7 +276,7 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_SYMPART);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_PART_EHDR);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_PART_PHDR);
- STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP);
+ STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP);
STRINGIFY_ENUM_CASE(ELF, SHT_GNU_ATTRIBUTES);
STRINGIFY_ENUM_CASE(ELF, SHT_GNU_HASH);
STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verdef);
@@ -288,7 +288,7 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
}
template <class ELFT>
-std::vector<typename ELFT::Rel>
+std::vector<typename ELFT::Rel>
ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
// This function decodes the contents of an SHT_RELR packed relocation
// section.
@@ -320,10 +320,10 @@ ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
// even means address, odd means bitmap.
// 2. Just a simple list of addresses is a valid encoding.
- Elf_Rel Rel;
- Rel.r_info = 0;
- Rel.setType(getRelativeRelocationType(), false);
- std::vector<Elf_Rel> Relocs;
+ Elf_Rel Rel;
+ Rel.r_info = 0;
+ Rel.setType(getRelativeRelocationType(), false);
+ std::vector<Elf_Rel> Relocs;
// Word type: uint32_t for Elf32, and uint64_t for Elf64.
typedef typename ELFT::uint Word;
@@ -340,8 +340,8 @@ ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
Word Entry = R;
if ((Entry&1) == 0) {
// Even entry: encodes the offset for next relocation.
- Rel.r_offset = Entry;
- Relocs.push_back(Rel);
+ Rel.r_offset = Entry;
+ Relocs.push_back(Rel);
// Set base offset for subsequent bitmap entries.
Base = Entry + WordSize;
continue;
@@ -352,8 +352,8 @@ ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
while (Entry != 0) {
Entry >>= 1;
if ((Entry&1) != 0) {
- Rel.r_offset = Offset;
- Relocs.push_back(Rel);
+ Rel.r_offset = Offset;
+ Relocs.push_back(Rel);
}
Offset += WordSize;
}
@@ -367,7 +367,7 @@ ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
template <class ELFT>
Expected<std::vector<typename ELFT::Rela>>
-ELFFile<ELFT>::android_relas(const Elf_Shdr &Sec) const {
+ELFFile<ELFT>::android_relas(const Elf_Shdr &Sec) const {
// This function reads relocations in Android's packed relocation format,
// which is based on SLEB128 and delta encoding.
Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
@@ -512,7 +512,7 @@ std::string ELFFile<ELFT>::getDynamicTagAsString(unsigned Arch,
template <class ELFT>
std::string ELFFile<ELFT>::getDynamicTagAsString(uint64_t Type) const {
- return getDynamicTagAsString(getHeader().e_machine, Type);
+ return getDynamicTagAsString(getHeader().e_machine, Type);
}
template <class ELFT>
@@ -542,7 +542,7 @@ Expected<typename ELFT::DynRange> ELFFile<ELFT>::dynamicEntries() const {
for (const Elf_Shdr &Sec : *SectionsOrError) {
if (Sec.sh_type == ELF::SHT_DYNAMIC) {
Expected<ArrayRef<Elf_Dyn>> DynOrError =
- getSectionContentsAsArray<Elf_Dyn>(Sec);
+ getSectionContentsAsArray<Elf_Dyn>(Sec);
if (!DynOrError)
return DynOrError.takeError();
Dyn = *DynOrError;
@@ -566,8 +566,8 @@ Expected<typename ELFT::DynRange> ELFFile<ELFT>::dynamicEntries() const {
}
template <class ELFT>
-Expected<const uint8_t *>
-ELFFile<ELFT>::toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler) const {
+Expected<const uint8_t *>
+ELFFile<ELFT>::toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler) const {
auto ProgramHeadersOrError = program_headers();
if (!ProgramHeadersOrError)
return ProgramHeadersOrError.takeError();
@@ -578,22 +578,22 @@ ELFFile<ELFT>::toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler) const {
if (Phdr.p_type == ELF::PT_LOAD)
LoadSegments.push_back(const_cast<Elf_Phdr *>(&Phdr));
- auto SortPred = [](const Elf_Phdr_Impl<ELFT> *A,
- const Elf_Phdr_Impl<ELFT> *B) {
- return A->p_vaddr < B->p_vaddr;
- };
- if (!llvm::is_sorted(LoadSegments, SortPred)) {
- if (Error E =
- WarnHandler("loadable segments are unsorted by virtual address"))
- return std::move(E);
- llvm::stable_sort(LoadSegments, SortPred);
- }
-
- const Elf_Phdr *const *I = llvm::upper_bound(
- LoadSegments, VAddr, [](uint64_t VAddr, const Elf_Phdr_Impl<ELFT> *Phdr) {
- return VAddr < Phdr->p_vaddr;
- });
-
+ auto SortPred = [](const Elf_Phdr_Impl<ELFT> *A,
+ const Elf_Phdr_Impl<ELFT> *B) {
+ return A->p_vaddr < B->p_vaddr;
+ };
+ if (!llvm::is_sorted(LoadSegments, SortPred)) {
+ if (Error E =
+ WarnHandler("loadable segments are unsorted by virtual address"))
+ return std::move(E);
+ llvm::stable_sort(LoadSegments, SortPred);
+ }
+
+ const Elf_Phdr *const *I = llvm::upper_bound(
+ LoadSegments, VAddr, [](uint64_t VAddr, const Elf_Phdr_Impl<ELFT> *Phdr) {
+ return VAddr < Phdr->p_vaddr;
+ });
+
if (I == LoadSegments.begin())
return createError("virtual address is not in any segment: 0x" +
Twine::utohexstr(VAddr));
diff --git a/contrib/libs/llvm12/lib/Object/ELFObjectFile.cpp b/contrib/libs/llvm12/lib/Object/ELFObjectFile.cpp
index 86b8d5e262..91871a6255 100644
--- a/contrib/libs/llvm12/lib/Object/ELFObjectFile.cpp
+++ b/contrib/libs/llvm12/lib/Object/ELFObjectFile.cpp
@@ -61,36 +61,36 @@ ELFObjectFileBase::ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
template <class ELFT>
static Expected<std::unique_ptr<ELFObjectFile<ELFT>>>
-createPtr(MemoryBufferRef Object, bool InitContent) {
- auto Ret = ELFObjectFile<ELFT>::create(Object, InitContent);
+createPtr(MemoryBufferRef Object, bool InitContent) {
+ auto Ret = ELFObjectFile<ELFT>::create(Object, InitContent);
if (Error E = Ret.takeError())
return std::move(E);
return std::make_unique<ELFObjectFile<ELFT>>(std::move(*Ret));
}
Expected<std::unique_ptr<ObjectFile>>
-ObjectFile::createELFObjectFile(MemoryBufferRef Obj, bool InitContent) {
+ObjectFile::createELFObjectFile(MemoryBufferRef Obj, bool InitContent) {
std::pair<unsigned char, unsigned char> Ident =
getElfArchType(Obj.getBuffer());
std::size_t MaxAlignment =
- 1ULL << countTrailingZeros(
- reinterpret_cast<uintptr_t>(Obj.getBufferStart()));
+ 1ULL << countTrailingZeros(
+ reinterpret_cast<uintptr_t>(Obj.getBufferStart()));
if (MaxAlignment < 2)
return createError("Insufficient alignment");
if (Ident.first == ELF::ELFCLASS32) {
if (Ident.second == ELF::ELFDATA2LSB)
- return createPtr<ELF32LE>(Obj, InitContent);
+ return createPtr<ELF32LE>(Obj, InitContent);
else if (Ident.second == ELF::ELFDATA2MSB)
- return createPtr<ELF32BE>(Obj, InitContent);
+ return createPtr<ELF32BE>(Obj, InitContent);
else
return createError("Invalid ELF data");
} else if (Ident.first == ELF::ELFCLASS64) {
if (Ident.second == ELF::ELFDATA2LSB)
- return createPtr<ELF64LE>(Obj, InitContent);
+ return createPtr<ELF64LE>(Obj, InitContent);
else if (Ident.second == ELF::ELFDATA2MSB)
- return createPtr<ELF64BE>(Obj, InitContent);
+ return createPtr<ELF64BE>(Obj, InitContent);
else
return createError("Invalid ELF data");
}
@@ -356,130 +356,130 @@ SubtargetFeatures ELFObjectFileBase::getFeatures() const {
}
}
-Optional<StringRef> ELFObjectFileBase::tryGetCPUName() const {
- switch (getEMachine()) {
- case ELF::EM_AMDGPU:
- return getAMDGPUCPUName();
- default:
- return None;
- }
-}
-
-StringRef ELFObjectFileBase::getAMDGPUCPUName() const {
- assert(getEMachine() == ELF::EM_AMDGPU);
- unsigned CPU = getPlatformFlags() & ELF::EF_AMDGPU_MACH;
-
- switch (CPU) {
- // Radeon HD 2000/3000 Series (R600).
- case ELF::EF_AMDGPU_MACH_R600_R600:
- return "r600";
- case ELF::EF_AMDGPU_MACH_R600_R630:
- return "r630";
- case ELF::EF_AMDGPU_MACH_R600_RS880:
- return "rs880";
- case ELF::EF_AMDGPU_MACH_R600_RV670:
- return "rv670";
-
- // Radeon HD 4000 Series (R700).
- case ELF::EF_AMDGPU_MACH_R600_RV710:
- return "rv710";
- case ELF::EF_AMDGPU_MACH_R600_RV730:
- return "rv730";
- case ELF::EF_AMDGPU_MACH_R600_RV770:
- return "rv770";
-
- // Radeon HD 5000 Series (Evergreen).
- case ELF::EF_AMDGPU_MACH_R600_CEDAR:
- return "cedar";
- case ELF::EF_AMDGPU_MACH_R600_CYPRESS:
- return "cypress";
- case ELF::EF_AMDGPU_MACH_R600_JUNIPER:
- return "juniper";
- case ELF::EF_AMDGPU_MACH_R600_REDWOOD:
- return "redwood";
- case ELF::EF_AMDGPU_MACH_R600_SUMO:
- return "sumo";
-
- // Radeon HD 6000 Series (Northern Islands).
- case ELF::EF_AMDGPU_MACH_R600_BARTS:
- return "barts";
- case ELF::EF_AMDGPU_MACH_R600_CAICOS:
- return "caicos";
- case ELF::EF_AMDGPU_MACH_R600_CAYMAN:
- return "cayman";
- case ELF::EF_AMDGPU_MACH_R600_TURKS:
- return "turks";
-
- // AMDGCN GFX6.
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX600:
- return "gfx600";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX601:
- return "gfx601";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX602:
- return "gfx602";
-
- // AMDGCN GFX7.
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX700:
- return "gfx700";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX701:
- return "gfx701";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX702:
- return "gfx702";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX703:
- return "gfx703";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX704:
- return "gfx704";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX705:
- return "gfx705";
-
- // AMDGCN GFX8.
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX801:
- return "gfx801";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX802:
- return "gfx802";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX803:
- return "gfx803";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX805:
- return "gfx805";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX810:
- return "gfx810";
-
- // AMDGCN GFX9.
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX900:
- return "gfx900";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX902:
- return "gfx902";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX904:
- return "gfx904";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX906:
- return "gfx906";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX908:
- return "gfx908";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX909:
- return "gfx909";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX90C:
- return "gfx90c";
-
- // AMDGCN GFX10.
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1010:
- return "gfx1010";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1011:
- return "gfx1011";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1012:
- return "gfx1012";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1030:
- return "gfx1030";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1031:
- return "gfx1031";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1032:
- return "gfx1032";
- case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1033:
- return "gfx1033";
- default:
- llvm_unreachable("Unknown EF_AMDGPU_MACH value");
- }
-}
-
+Optional<StringRef> ELFObjectFileBase::tryGetCPUName() const {
+ switch (getEMachine()) {
+ case ELF::EM_AMDGPU:
+ return getAMDGPUCPUName();
+ default:
+ return None;
+ }
+}
+
+StringRef ELFObjectFileBase::getAMDGPUCPUName() const {
+ assert(getEMachine() == ELF::EM_AMDGPU);
+ unsigned CPU = getPlatformFlags() & ELF::EF_AMDGPU_MACH;
+
+ switch (CPU) {
+ // Radeon HD 2000/3000 Series (R600).
+ case ELF::EF_AMDGPU_MACH_R600_R600:
+ return "r600";
+ case ELF::EF_AMDGPU_MACH_R600_R630:
+ return "r630";
+ case ELF::EF_AMDGPU_MACH_R600_RS880:
+ return "rs880";
+ case ELF::EF_AMDGPU_MACH_R600_RV670:
+ return "rv670";
+
+ // Radeon HD 4000 Series (R700).
+ case ELF::EF_AMDGPU_MACH_R600_RV710:
+ return "rv710";
+ case ELF::EF_AMDGPU_MACH_R600_RV730:
+ return "rv730";
+ case ELF::EF_AMDGPU_MACH_R600_RV770:
+ return "rv770";
+
+ // Radeon HD 5000 Series (Evergreen).
+ case ELF::EF_AMDGPU_MACH_R600_CEDAR:
+ return "cedar";
+ case ELF::EF_AMDGPU_MACH_R600_CYPRESS:
+ return "cypress";
+ case ELF::EF_AMDGPU_MACH_R600_JUNIPER:
+ return "juniper";
+ case ELF::EF_AMDGPU_MACH_R600_REDWOOD:
+ return "redwood";
+ case ELF::EF_AMDGPU_MACH_R600_SUMO:
+ return "sumo";
+
+ // Radeon HD 6000 Series (Northern Islands).
+ case ELF::EF_AMDGPU_MACH_R600_BARTS:
+ return "barts";
+ case ELF::EF_AMDGPU_MACH_R600_CAICOS:
+ return "caicos";
+ case ELF::EF_AMDGPU_MACH_R600_CAYMAN:
+ return "cayman";
+ case ELF::EF_AMDGPU_MACH_R600_TURKS:
+ return "turks";
+
+ // AMDGCN GFX6.
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX600:
+ return "gfx600";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX601:
+ return "gfx601";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX602:
+ return "gfx602";
+
+ // AMDGCN GFX7.
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX700:
+ return "gfx700";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX701:
+ return "gfx701";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX702:
+ return "gfx702";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX703:
+ return "gfx703";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX704:
+ return "gfx704";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX705:
+ return "gfx705";
+
+ // AMDGCN GFX8.
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX801:
+ return "gfx801";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX802:
+ return "gfx802";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX803:
+ return "gfx803";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX805:
+ return "gfx805";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX810:
+ return "gfx810";
+
+ // AMDGCN GFX9.
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX900:
+ return "gfx900";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX902:
+ return "gfx902";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX904:
+ return "gfx904";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX906:
+ return "gfx906";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX908:
+ return "gfx908";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX909:
+ return "gfx909";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX90C:
+ return "gfx90c";
+
+ // AMDGCN GFX10.
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1010:
+ return "gfx1010";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1011:
+ return "gfx1011";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1012:
+ return "gfx1012";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1030:
+ return "gfx1030";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1031:
+ return "gfx1031";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1032:
+ return "gfx1032";
+ case ELF::EF_AMDGPU_MACH_AMDGCN_GFX1033:
+ return "gfx1033";
+ default:
+ llvm_unreachable("Unknown EF_AMDGPU_MACH value");
+ }
+}
+
// FIXME Encode from a tablegen description or target parser.
void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
if (TheTriple.getSubArch() != Triple::NoSubArch)
@@ -565,7 +565,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
TheTriple.setArchName(Triple);
}
-std::vector<std::pair<Optional<DataRefImpl>, uint64_t>>
+std::vector<std::pair<Optional<DataRefImpl>, uint64_t>>
ELFObjectFileBase::getPltAddresses() const {
std::string Err;
const auto Triple = makeTriple();
@@ -623,18 +623,18 @@ ELFObjectFileBase::getPltAddresses() const {
GotToPlt.insert(std::make_pair(Entry.second, Entry.first));
// Find the relocations in the dynamic relocation table that point to
// locations in the GOT for which we know the corresponding PLT entry.
- std::vector<std::pair<Optional<DataRefImpl>, uint64_t>> Result;
+ std::vector<std::pair<Optional<DataRefImpl>, uint64_t>> Result;
for (const auto &Relocation : RelaPlt->relocations()) {
if (Relocation.getType() != JumpSlotReloc)
continue;
auto PltEntryIter = GotToPlt.find(Relocation.getOffset());
- if (PltEntryIter != GotToPlt.end()) {
- symbol_iterator Sym = Relocation.getSymbol();
- if (Sym == symbol_end())
- Result.emplace_back(None, PltEntryIter->second);
- else
- Result.emplace_back(Sym->getRawDataRefImpl(), PltEntryIter->second);
- }
+ if (PltEntryIter != GotToPlt.end()) {
+ symbol_iterator Sym = Relocation.getSymbol();
+ if (Sym == symbol_end())
+ Result.emplace_back(None, PltEntryIter->second);
+ else
+ Result.emplace_back(Sym->getRawDataRefImpl(), PltEntryIter->second);
+ }
}
return Result;
}
diff --git a/contrib/libs/llvm12/lib/Object/MachOObjectFile.cpp b/contrib/libs/llvm12/lib/Object/MachOObjectFile.cpp
index f9a538ed43..3022559262 100644
--- a/contrib/libs/llvm12/lib/Object/MachOObjectFile.cpp
+++ b/contrib/libs/llvm12/lib/Object/MachOObjectFile.cpp
@@ -1596,9 +1596,9 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
if ((Err = checkTwoLevelHintsCommand(*this, Load, I,
&TwoLevelHintsLoadCmd, Elements)))
return;
- } else if (Load.C.cmd == MachO::LC_IDENT) {
- // Note: LC_IDENT is ignored.
- continue;
+ } else if (Load.C.cmd == MachO::LC_IDENT) {
+ // Note: LC_IDENT is ignored.
+ continue;
} else if (isLoadCommandObsolete(Load.C.cmd)) {
Err = malformedError("load command " + Twine(I) + " for cmd value of: " +
Twine(Load.C.cmd) + " is obsolete and not "
@@ -2035,9 +2035,9 @@ bool MachOObjectFile::isSectionBSS(DataRefImpl Sec) const {
bool MachOObjectFile::isDebugSection(StringRef SectionName) const {
return SectionName.startswith("__debug") ||
- SectionName.startswith("__zdebug") ||
- SectionName.startswith("__apple") || SectionName == "__gdb_index" ||
- SectionName == "__swift_ast";
+ SectionName.startswith("__zdebug") ||
+ SectionName.startswith("__apple") || SectionName == "__gdb_index" ||
+ SectionName == "__swift_ast";
}
unsigned MachOObjectFile::getSectionID(SectionRef Sec) const {
@@ -2694,12 +2694,12 @@ Triple MachOObjectFile::getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
if (ArchFlag)
*ArchFlag = "arm64";
return Triple("arm64-apple-darwin");
- case MachO::CPU_SUBTYPE_ARM64E:
- if (McpuDefault)
- *McpuDefault = "apple-a12";
- if (ArchFlag)
- *ArchFlag = "arm64e";
- return Triple("arm64e-apple-darwin");
+ case MachO::CPU_SUBTYPE_ARM64E:
+ if (McpuDefault)
+ *McpuDefault = "apple-a12";
+ if (ArchFlag)
+ *ArchFlag = "arm64e";
+ return Triple("arm64e-apple-darwin");
default:
return Triple();
}
@@ -2743,32 +2743,32 @@ Triple MachOObjectFile::getHostArch() {
bool MachOObjectFile::isValidArch(StringRef ArchFlag) {
auto validArchs = getValidArchs();
- return llvm::is_contained(validArchs, ArchFlag);
+ return llvm::is_contained(validArchs, ArchFlag);
}
ArrayRef<StringRef> MachOObjectFile::getValidArchs() {
- static const std::array<StringRef, 18> ValidArchs = {{
- "i386",
- "x86_64",
- "x86_64h",
- "armv4t",
- "arm",
- "armv5e",
- "armv6",
- "armv6m",
- "armv7",
- "armv7em",
- "armv7k",
- "armv7m",
- "armv7s",
- "arm64",
- "arm64e",
- "arm64_32",
- "ppc",
- "ppc64",
+ static const std::array<StringRef, 18> ValidArchs = {{
+ "i386",
+ "x86_64",
+ "x86_64h",
+ "armv4t",
+ "arm",
+ "armv5e",
+ "armv6",
+ "armv6m",
+ "armv7",
+ "armv7em",
+ "armv7k",
+ "armv7m",
+ "armv7s",
+ "arm64",
+ "arm64e",
+ "arm64_32",
+ "ppc",
+ "ppc64",
}};
- return ValidArchs;
+ return ValidArchs;
}
Triple::ArchType MachOObjectFile::getArch() const {
diff --git a/contrib/libs/llvm12/lib/Object/MachOUniversal.cpp b/contrib/libs/llvm12/lib/Object/MachOUniversal.cpp
index 0433c78bce..f3ce005e6e 100644
--- a/contrib/libs/llvm12/lib/Object/MachOUniversal.cpp
+++ b/contrib/libs/llvm12/lib/Object/MachOUniversal.cpp
@@ -12,7 +12,7 @@
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/Archive.h"
-#include "llvm/Object/IRObjectFile.h"
+#include "llvm/Object/IRObjectFile.h"
#include "llvm/Object/MachO.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Casting.h"
@@ -81,25 +81,25 @@ MachOUniversalBinary::ObjectForArch::getAsObjectFile() const {
return ObjectFile::createMachOObjectFile(ObjBuffer, cputype, Index);
}
-Expected<std::unique_ptr<IRObjectFile>>
-MachOUniversalBinary::ObjectForArch::getAsIRObject(LLVMContext &Ctx) const {
- if (!Parent)
- report_fatal_error("MachOUniversalBinary::ObjectForArch::getAsIRObject() "
- "called when Parent is a nullptr");
-
- StringRef ParentData = Parent->getData();
- StringRef ObjectData;
- if (Parent->getMagic() == MachO::FAT_MAGIC) {
- ObjectData = ParentData.substr(Header.offset, Header.size);
- } else { // Parent->getMagic() == MachO::FAT_MAGIC_64
- ObjectData = ParentData.substr(Header64.offset, Header64.size);
- }
- StringRef ObjectName = Parent->getFileName();
- MemoryBufferRef ObjBuffer(ObjectData, ObjectName);
-
- return IRObjectFile::create(ObjBuffer, Ctx);
-}
-
+Expected<std::unique_ptr<IRObjectFile>>
+MachOUniversalBinary::ObjectForArch::getAsIRObject(LLVMContext &Ctx) const {
+ if (!Parent)
+ report_fatal_error("MachOUniversalBinary::ObjectForArch::getAsIRObject() "
+ "called when Parent is a nullptr");
+
+ StringRef ParentData = Parent->getData();
+ StringRef ObjectData;
+ if (Parent->getMagic() == MachO::FAT_MAGIC) {
+ ObjectData = ParentData.substr(Header.offset, Header.size);
+ } else { // Parent->getMagic() == MachO::FAT_MAGIC_64
+ ObjectData = ParentData.substr(Header64.offset, Header64.size);
+ }
+ StringRef ObjectName = Parent->getFileName();
+ MemoryBufferRef ObjBuffer(ObjectData, ObjectName);
+
+ return IRObjectFile::create(ObjBuffer, Ctx);
+}
+
Expected<std::unique_ptr<Archive>>
MachOUniversalBinary::ObjectForArch::getAsArchive() const {
if (!Parent)
@@ -254,15 +254,15 @@ MachOUniversalBinary::getMachOObjectForArch(StringRef ArchName) const {
return O->getAsObjectFile();
}
-Expected<std::unique_ptr<IRObjectFile>>
-MachOUniversalBinary::getIRObjectForArch(StringRef ArchName,
- LLVMContext &Ctx) const {
- Expected<ObjectForArch> O = getObjectForArch(ArchName);
- if (!O)
- return O.takeError();
- return O->getAsIRObject(Ctx);
-}
-
+Expected<std::unique_ptr<IRObjectFile>>
+MachOUniversalBinary::getIRObjectForArch(StringRef ArchName,
+ LLVMContext &Ctx) const {
+ Expected<ObjectForArch> O = getObjectForArch(ArchName);
+ if (!O)
+ return O.takeError();
+ return O->getAsIRObject(Ctx);
+}
+
Expected<std::unique_ptr<Archive>>
MachOUniversalBinary::getArchiveForArch(StringRef ArchName) const {
Expected<ObjectForArch> O = getObjectForArch(ArchName);
diff --git a/contrib/libs/llvm12/lib/Object/MachOUniversalWriter.cpp b/contrib/libs/llvm12/lib/Object/MachOUniversalWriter.cpp
index 45cb72bbbf..4bb467e56a 100644
--- a/contrib/libs/llvm12/lib/Object/MachOUniversalWriter.cpp
+++ b/contrib/libs/llvm12/lib/Object/MachOUniversalWriter.cpp
@@ -1,337 +1,337 @@
-//===- MachOUniversalWriter.cpp - MachO universal binary writer---*- C++-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Defines the Slice class and writeUniversalBinary function for writing a MachO
-// universal binary file.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Object/MachOUniversalWriter.h"
-#include "llvm/ADT/Triple.h"
-#include "llvm/Object/Archive.h"
-#include "llvm/Object/Binary.h"
-#include "llvm/Object/Error.h"
-#include "llvm/Object/IRObjectFile.h"
-#include "llvm/Object/MachO.h"
-#include "llvm/Object/MachOUniversal.h"
-#include "llvm/Support/SmallVectorMemoryBuffer.h"
-
-using namespace llvm;
-using namespace object;
-
-// For compatibility with cctools lipo, a file's alignment is calculated as the
-// minimum aligment of all segments. For object files, the file's alignment is
-// the maximum alignment of its sections.
-static uint32_t calculateFileAlignment(const MachOObjectFile &O) {
- uint32_t P2CurrentAlignment;
- uint32_t P2MinAlignment = MachOUniversalBinary::MaxSectionAlignment;
- const bool Is64Bit = O.is64Bit();
-
- for (const auto &LC : O.load_commands()) {
- if (LC.C.cmd != (Is64Bit ? MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT))
- continue;
- if (O.getHeader().filetype == MachO::MH_OBJECT) {
- unsigned NumberOfSections =
- (Is64Bit ? O.getSegment64LoadCommand(LC).nsects
- : O.getSegmentLoadCommand(LC).nsects);
- P2CurrentAlignment = NumberOfSections ? 2 : P2MinAlignment;
- for (unsigned SI = 0; SI < NumberOfSections; ++SI) {
- P2CurrentAlignment = std::max(P2CurrentAlignment,
- (Is64Bit ? O.getSection64(LC, SI).align
- : O.getSection(LC, SI).align));
- }
- } else {
- P2CurrentAlignment =
- countTrailingZeros(Is64Bit ? O.getSegment64LoadCommand(LC).vmaddr
- : O.getSegmentLoadCommand(LC).vmaddr);
- }
- P2MinAlignment = std::min(P2MinAlignment, P2CurrentAlignment);
- }
- // return a value >= 4 byte aligned, and less than MachO MaxSectionAlignment
- return std::max(
- static_cast<uint32_t>(2),
- std::min(P2MinAlignment, static_cast<uint32_t>(
- MachOUniversalBinary::MaxSectionAlignment)));
-}
-
-static uint32_t calculateAlignment(const MachOObjectFile &ObjectFile) {
- switch (ObjectFile.getHeader().cputype) {
- case MachO::CPU_TYPE_I386:
- case MachO::CPU_TYPE_X86_64:
- case MachO::CPU_TYPE_POWERPC:
- case MachO::CPU_TYPE_POWERPC64:
- return 12; // log2 value of page size(4k) for x86 and PPC
- case MachO::CPU_TYPE_ARM:
- case MachO::CPU_TYPE_ARM64:
- case MachO::CPU_TYPE_ARM64_32:
- return 14; // log2 value of page size(16k) for Darwin ARM
- default:
- return calculateFileAlignment(ObjectFile);
- }
-}
-
-Slice::Slice(const Archive &A, uint32_t CPUType, uint32_t CPUSubType,
- std::string ArchName, uint32_t Align)
- : B(&A), CPUType(CPUType), CPUSubType(CPUSubType),
- ArchName(std::move(ArchName)), P2Alignment(Align) {}
-
-Slice::Slice(const MachOObjectFile &O, uint32_t Align)
- : B(&O), CPUType(O.getHeader().cputype),
- CPUSubType(O.getHeader().cpusubtype),
- ArchName(std::string(O.getArchTriple().getArchName())),
- P2Alignment(Align) {}
-
-Slice::Slice(const IRObjectFile &IRO, uint32_t CPUType, uint32_t CPUSubType,
- std::string ArchName, uint32_t Align)
- : B(&IRO), CPUType(CPUType), CPUSubType(CPUSubType),
- ArchName(std::move(ArchName)), P2Alignment(Align) {}
-
-Slice::Slice(const MachOObjectFile &O) : Slice(O, calculateAlignment(O)) {}
-
-using MachoCPUTy = std::pair<unsigned, unsigned>;
-
-static Expected<MachoCPUTy> getMachoCPUFromTriple(Triple TT) {
- auto CPU = std::make_pair(MachO::getCPUType(TT), MachO::getCPUSubType(TT));
- if (!CPU.first) {
- return CPU.first.takeError();
- }
- if (!CPU.second) {
- return CPU.second.takeError();
- }
- return std::make_pair(*CPU.first, *CPU.second);
-}
-
-static Expected<MachoCPUTy> getMachoCPUFromTriple(StringRef TT) {
- return getMachoCPUFromTriple(Triple{TT});
-}
-
-Expected<Slice> Slice::create(const Archive &A, LLVMContext *LLVMCtx) {
- Error Err = Error::success();
- std::unique_ptr<MachOObjectFile> MFO = nullptr;
- std::unique_ptr<IRObjectFile> IRFO = nullptr;
- for (const Archive::Child &Child : A.children(Err)) {
- Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary(LLVMCtx);
- if (!ChildOrErr)
- return createFileError(A.getFileName(), ChildOrErr.takeError());
- Binary *Bin = ChildOrErr.get().get();
- if (Bin->isMachOUniversalBinary())
- return createStringError(std::errc::invalid_argument,
- ("archive member " + Bin->getFileName() +
- " is a fat file (not allowed in an archive)")
- .str()
- .c_str());
- if (Bin->isMachO()) {
- MachOObjectFile *O = cast<MachOObjectFile>(Bin);
- if (IRFO) {
- return createStringError(
- std::errc::invalid_argument,
- "archive member %s is a MachO, while previous archive member "
- "%s was an IR LLVM object",
- O->getFileName().str().c_str(), IRFO->getFileName().str().c_str());
- }
- if (MFO &&
- std::tie(MFO->getHeader().cputype, MFO->getHeader().cpusubtype) !=
- std::tie(O->getHeader().cputype, O->getHeader().cpusubtype)) {
- return createStringError(
- std::errc::invalid_argument,
- ("archive member " + O->getFileName() + " cputype (" +
- Twine(O->getHeader().cputype) + ") and cpusubtype(" +
- Twine(O->getHeader().cpusubtype) +
- ") does not match previous archive members cputype (" +
- Twine(MFO->getHeader().cputype) + ") and cpusubtype(" +
- Twine(MFO->getHeader().cpusubtype) +
- ") (all members must match) " + MFO->getFileName())
- .str()
- .c_str());
- }
- if (!MFO) {
- ChildOrErr.get().release();
- MFO.reset(O);
- }
- } else if (Bin->isIR()) {
- IRObjectFile *O = cast<IRObjectFile>(Bin);
- if (MFO) {
- return createStringError(std::errc::invalid_argument,
- "archive member '%s' is an LLVM IR object, "
- "while previous archive member "
- "'%s' was a MachO",
- O->getFileName().str().c_str(),
- MFO->getFileName().str().c_str());
- }
- if (IRFO) {
- Expected<MachoCPUTy> CPUO = getMachoCPUFromTriple(O->getTargetTriple());
- Expected<MachoCPUTy> CPUFO =
- getMachoCPUFromTriple(IRFO->getTargetTriple());
- if (!CPUO)
- return CPUO.takeError();
- if (!CPUFO)
- return CPUFO.takeError();
- if (*CPUO != *CPUFO) {
- return createStringError(
- std::errc::invalid_argument,
- ("archive member " + O->getFileName() + " cputype (" +
- Twine(CPUO->first) + ") and cpusubtype(" + Twine(CPUO->second) +
- ") does not match previous archive members cputype (" +
- Twine(CPUFO->first) + ") and cpusubtype(" +
- Twine(CPUFO->second) + ") (all members must match) " +
- IRFO->getFileName())
- .str()
- .c_str());
- }
- } else {
- ChildOrErr.get().release();
- IRFO.reset(O);
- }
- } else
- return createStringError(std::errc::invalid_argument,
- ("archive member " + Bin->getFileName() +
- " is neither a MachO file or an LLVM IR file "
- "(not allowed in an archive)")
- .str()
- .c_str());
- }
- if (Err)
- return createFileError(A.getFileName(), std::move(Err));
- if (!MFO && !IRFO)
- return createStringError(
- std::errc::invalid_argument,
- ("empty archive with no architecture specification: " +
- A.getFileName() + " (can't determine architecture for it)")
- .str()
- .c_str());
-
- if (MFO) {
- Slice ArchiveSlice(*(MFO.get()), MFO->is64Bit() ? 3 : 2);
- ArchiveSlice.B = &A;
- return ArchiveSlice;
- }
-
- // For IR objects
- Expected<Slice> ArchiveSliceOrErr = Slice::create(*IRFO, 0);
- if (!ArchiveSliceOrErr)
- return createFileError(A.getFileName(), ArchiveSliceOrErr.takeError());
- auto &ArchiveSlice = ArchiveSliceOrErr.get();
- ArchiveSlice.B = &A;
- return std::move(ArchiveSlice);
-}
-
-Expected<Slice> Slice::create(const IRObjectFile &IRO, uint32_t Align) {
- Expected<MachoCPUTy> CPUOrErr = getMachoCPUFromTriple(IRO.getTargetTriple());
- if (!CPUOrErr)
- return CPUOrErr.takeError();
- unsigned CPUType, CPUSubType;
- std::tie(CPUType, CPUSubType) = CPUOrErr.get();
- // We don't directly use the architecture name of the target triple T, as,
- // for instance, thumb is treated as ARM by the MachOUniversal object.
- std::string ArchName(
- MachOObjectFile::getArchTriple(CPUType, CPUSubType).getArchName());
- return Slice{IRO, CPUType, CPUSubType, std::move(ArchName), Align};
-}
-
-static Expected<SmallVector<MachO::fat_arch, 2>>
-buildFatArchList(ArrayRef<Slice> Slices) {
- SmallVector<MachO::fat_arch, 2> FatArchList;
- uint64_t Offset =
- sizeof(MachO::fat_header) + Slices.size() * sizeof(MachO::fat_arch);
-
- for (const auto &S : Slices) {
- Offset = alignTo(Offset, 1ull << S.getP2Alignment());
- if (Offset > UINT32_MAX)
- return createStringError(
- std::errc::invalid_argument,
- ("fat file too large to be created because the offset "
- "field in struct fat_arch is only 32-bits and the offset " +
- Twine(Offset) + " for " + S.getBinary()->getFileName() +
- " for architecture " + S.getArchString() + "exceeds that.")
- .str()
- .c_str());
-
- MachO::fat_arch FatArch;
- FatArch.cputype = S.getCPUType();
- FatArch.cpusubtype = S.getCPUSubType();
- FatArch.offset = Offset;
- FatArch.size = S.getBinary()->getMemoryBufferRef().getBufferSize();
- FatArch.align = S.getP2Alignment();
- Offset += FatArch.size;
- FatArchList.push_back(FatArch);
- }
- return FatArchList;
-}
-
-static Error writeUniversalBinaryToStream(ArrayRef<Slice> Slices,
- raw_ostream &Out) {
- MachO::fat_header FatHeader;
- FatHeader.magic = MachO::FAT_MAGIC;
- FatHeader.nfat_arch = Slices.size();
-
- Expected<SmallVector<MachO::fat_arch, 2>> FatArchListOrErr =
- buildFatArchList(Slices);
- if (!FatArchListOrErr)
- return FatArchListOrErr.takeError();
- SmallVector<MachO::fat_arch, 2> FatArchList = *FatArchListOrErr;
-
- if (sys::IsLittleEndianHost)
- MachO::swapStruct(FatHeader);
- Out.write(reinterpret_cast<const char *>(&FatHeader),
- sizeof(MachO::fat_header));
-
- if (sys::IsLittleEndianHost)
- for (MachO::fat_arch &FA : FatArchList)
- MachO::swapStruct(FA);
- Out.write(reinterpret_cast<const char *>(FatArchList.data()),
- sizeof(MachO::fat_arch) * FatArchList.size());
-
- if (sys::IsLittleEndianHost)
- for (MachO::fat_arch &FA : FatArchList)
- MachO::swapStruct(FA);
-
- size_t Offset =
- sizeof(MachO::fat_header) + sizeof(MachO::fat_arch) * FatArchList.size();
- for (size_t Index = 0, Size = Slices.size(); Index < Size; ++Index) {
- MemoryBufferRef BufferRef = Slices[Index].getBinary()->getMemoryBufferRef();
- assert((Offset <= FatArchList[Index].offset) && "Incorrect slice offset");
- Out.write_zeros(FatArchList[Index].offset - Offset);
- Out.write(BufferRef.getBufferStart(), BufferRef.getBufferSize());
- Offset = FatArchList[Index].offset + BufferRef.getBufferSize();
- }
-
- Out.flush();
- return Error::success();
-}
-
-Error object::writeUniversalBinary(ArrayRef<Slice> Slices,
- StringRef OutputFileName) {
- const bool IsExecutable = any_of(Slices, [](Slice S) {
- return sys::fs::can_execute(S.getBinary()->getFileName());
- });
- unsigned Mode = sys::fs::all_read | sys::fs::all_write;
- if (IsExecutable)
- Mode |= sys::fs::all_exe;
- Expected<sys::fs::TempFile> Temp = sys::fs::TempFile::create(
- OutputFileName + ".temp-universal-%%%%%%", Mode);
- if (!Temp)
- return Temp.takeError();
- raw_fd_ostream Out(Temp->FD, false);
- if (Error E = writeUniversalBinaryToStream(Slices, Out)) {
- if (Error DiscardError = Temp->discard())
- return joinErrors(std::move(E), std::move(DiscardError));
- return E;
- }
- return Temp->keep(OutputFileName);
-}
-
-Expected<std::unique_ptr<MemoryBuffer>>
-object::writeUniversalBinaryToBuffer(ArrayRef<Slice> Slices) {
- SmallVector<char, 0> Buffer;
- raw_svector_ostream Out(Buffer);
-
- if (Error E = writeUniversalBinaryToStream(Slices, Out))
- return std::move(E);
-
- return std::make_unique<SmallVectorMemoryBuffer>(std::move(Buffer));
-}
+//===- MachOUniversalWriter.cpp - MachO universal binary writer---*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines the Slice class and writeUniversalBinary function for writing a MachO
+// universal binary file.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Object/MachOUniversalWriter.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Object/Archive.h"
+#include "llvm/Object/Binary.h"
+#include "llvm/Object/Error.h"
+#include "llvm/Object/IRObjectFile.h"
+#include "llvm/Object/MachO.h"
+#include "llvm/Object/MachOUniversal.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
+
+using namespace llvm;
+using namespace object;
+
+// For compatibility with cctools lipo, a file's alignment is calculated as the
+// minimum aligment of all segments. For object files, the file's alignment is
+// the maximum alignment of its sections.
+static uint32_t calculateFileAlignment(const MachOObjectFile &O) {
+ uint32_t P2CurrentAlignment;
+ uint32_t P2MinAlignment = MachOUniversalBinary::MaxSectionAlignment;
+ const bool Is64Bit = O.is64Bit();
+
+ for (const auto &LC : O.load_commands()) {
+ if (LC.C.cmd != (Is64Bit ? MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT))
+ continue;
+ if (O.getHeader().filetype == MachO::MH_OBJECT) {
+ unsigned NumberOfSections =
+ (Is64Bit ? O.getSegment64LoadCommand(LC).nsects
+ : O.getSegmentLoadCommand(LC).nsects);
+ P2CurrentAlignment = NumberOfSections ? 2 : P2MinAlignment;
+ for (unsigned SI = 0; SI < NumberOfSections; ++SI) {
+ P2CurrentAlignment = std::max(P2CurrentAlignment,
+ (Is64Bit ? O.getSection64(LC, SI).align
+ : O.getSection(LC, SI).align));
+ }
+ } else {
+ P2CurrentAlignment =
+ countTrailingZeros(Is64Bit ? O.getSegment64LoadCommand(LC).vmaddr
+ : O.getSegmentLoadCommand(LC).vmaddr);
+ }
+ P2MinAlignment = std::min(P2MinAlignment, P2CurrentAlignment);
+ }
+ // return a value >= 4 byte aligned, and less than MachO MaxSectionAlignment
+ return std::max(
+ static_cast<uint32_t>(2),
+ std::min(P2MinAlignment, static_cast<uint32_t>(
+ MachOUniversalBinary::MaxSectionAlignment)));
+}
+
+static uint32_t calculateAlignment(const MachOObjectFile &ObjectFile) {
+ switch (ObjectFile.getHeader().cputype) {
+ case MachO::CPU_TYPE_I386:
+ case MachO::CPU_TYPE_X86_64:
+ case MachO::CPU_TYPE_POWERPC:
+ case MachO::CPU_TYPE_POWERPC64:
+ return 12; // log2 value of page size(4k) for x86 and PPC
+ case MachO::CPU_TYPE_ARM:
+ case MachO::CPU_TYPE_ARM64:
+ case MachO::CPU_TYPE_ARM64_32:
+ return 14; // log2 value of page size(16k) for Darwin ARM
+ default:
+ return calculateFileAlignment(ObjectFile);
+ }
+}
+
+Slice::Slice(const Archive &A, uint32_t CPUType, uint32_t CPUSubType,
+ std::string ArchName, uint32_t Align)
+ : B(&A), CPUType(CPUType), CPUSubType(CPUSubType),
+ ArchName(std::move(ArchName)), P2Alignment(Align) {}
+
+Slice::Slice(const MachOObjectFile &O, uint32_t Align)
+ : B(&O), CPUType(O.getHeader().cputype),
+ CPUSubType(O.getHeader().cpusubtype),
+ ArchName(std::string(O.getArchTriple().getArchName())),
+ P2Alignment(Align) {}
+
+Slice::Slice(const IRObjectFile &IRO, uint32_t CPUType, uint32_t CPUSubType,
+ std::string ArchName, uint32_t Align)
+ : B(&IRO), CPUType(CPUType), CPUSubType(CPUSubType),
+ ArchName(std::move(ArchName)), P2Alignment(Align) {}
+
+Slice::Slice(const MachOObjectFile &O) : Slice(O, calculateAlignment(O)) {}
+
+using MachoCPUTy = std::pair<unsigned, unsigned>;
+
+static Expected<MachoCPUTy> getMachoCPUFromTriple(Triple TT) {
+ auto CPU = std::make_pair(MachO::getCPUType(TT), MachO::getCPUSubType(TT));
+ if (!CPU.first) {
+ return CPU.first.takeError();
+ }
+ if (!CPU.second) {
+ return CPU.second.takeError();
+ }
+ return std::make_pair(*CPU.first, *CPU.second);
+}
+
+static Expected<MachoCPUTy> getMachoCPUFromTriple(StringRef TT) {
+ return getMachoCPUFromTriple(Triple{TT});
+}
+
+Expected<Slice> Slice::create(const Archive &A, LLVMContext *LLVMCtx) {
+ Error Err = Error::success();
+ std::unique_ptr<MachOObjectFile> MFO = nullptr;
+ std::unique_ptr<IRObjectFile> IRFO = nullptr;
+ for (const Archive::Child &Child : A.children(Err)) {
+ Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary(LLVMCtx);
+ if (!ChildOrErr)
+ return createFileError(A.getFileName(), ChildOrErr.takeError());
+ Binary *Bin = ChildOrErr.get().get();
+ if (Bin->isMachOUniversalBinary())
+ return createStringError(std::errc::invalid_argument,
+ ("archive member " + Bin->getFileName() +
+ " is a fat file (not allowed in an archive)")
+ .str()
+ .c_str());
+ if (Bin->isMachO()) {
+ MachOObjectFile *O = cast<MachOObjectFile>(Bin);
+ if (IRFO) {
+ return createStringError(
+ std::errc::invalid_argument,
+ "archive member %s is a MachO, while previous archive member "
+ "%s was an IR LLVM object",
+ O->getFileName().str().c_str(), IRFO->getFileName().str().c_str());
+ }
+ if (MFO &&
+ std::tie(MFO->getHeader().cputype, MFO->getHeader().cpusubtype) !=
+ std::tie(O->getHeader().cputype, O->getHeader().cpusubtype)) {
+ return createStringError(
+ std::errc::invalid_argument,
+ ("archive member " + O->getFileName() + " cputype (" +
+ Twine(O->getHeader().cputype) + ") and cpusubtype(" +
+ Twine(O->getHeader().cpusubtype) +
+ ") does not match previous archive members cputype (" +
+ Twine(MFO->getHeader().cputype) + ") and cpusubtype(" +
+ Twine(MFO->getHeader().cpusubtype) +
+ ") (all members must match) " + MFO->getFileName())
+ .str()
+ .c_str());
+ }
+ if (!MFO) {
+ ChildOrErr.get().release();
+ MFO.reset(O);
+ }
+ } else if (Bin->isIR()) {
+ IRObjectFile *O = cast<IRObjectFile>(Bin);
+ if (MFO) {
+ return createStringError(std::errc::invalid_argument,
+ "archive member '%s' is an LLVM IR object, "
+ "while previous archive member "
+ "'%s' was a MachO",
+ O->getFileName().str().c_str(),
+ MFO->getFileName().str().c_str());
+ }
+ if (IRFO) {
+ Expected<MachoCPUTy> CPUO = getMachoCPUFromTriple(O->getTargetTriple());
+ Expected<MachoCPUTy> CPUFO =
+ getMachoCPUFromTriple(IRFO->getTargetTriple());
+ if (!CPUO)
+ return CPUO.takeError();
+ if (!CPUFO)
+ return CPUFO.takeError();
+ if (*CPUO != *CPUFO) {
+ return createStringError(
+ std::errc::invalid_argument,
+ ("archive member " + O->getFileName() + " cputype (" +
+ Twine(CPUO->first) + ") and cpusubtype(" + Twine(CPUO->second) +
+ ") does not match previous archive members cputype (" +
+ Twine(CPUFO->first) + ") and cpusubtype(" +
+ Twine(CPUFO->second) + ") (all members must match) " +
+ IRFO->getFileName())
+ .str()
+ .c_str());
+ }
+ } else {
+ ChildOrErr.get().release();
+ IRFO.reset(O);
+ }
+ } else
+ return createStringError(std::errc::invalid_argument,
+ ("archive member " + Bin->getFileName() +
+ " is neither a MachO file or an LLVM IR file "
+ "(not allowed in an archive)")
+ .str()
+ .c_str());
+ }
+ if (Err)
+ return createFileError(A.getFileName(), std::move(Err));
+ if (!MFO && !IRFO)
+ return createStringError(
+ std::errc::invalid_argument,
+ ("empty archive with no architecture specification: " +
+ A.getFileName() + " (can't determine architecture for it)")
+ .str()
+ .c_str());
+
+ if (MFO) {
+ Slice ArchiveSlice(*(MFO.get()), MFO->is64Bit() ? 3 : 2);
+ ArchiveSlice.B = &A;
+ return ArchiveSlice;
+ }
+
+ // For IR objects
+ Expected<Slice> ArchiveSliceOrErr = Slice::create(*IRFO, 0);
+ if (!ArchiveSliceOrErr)
+ return createFileError(A.getFileName(), ArchiveSliceOrErr.takeError());
+ auto &ArchiveSlice = ArchiveSliceOrErr.get();
+ ArchiveSlice.B = &A;
+ return std::move(ArchiveSlice);
+}
+
+Expected<Slice> Slice::create(const IRObjectFile &IRO, uint32_t Align) {
+ Expected<MachoCPUTy> CPUOrErr = getMachoCPUFromTriple(IRO.getTargetTriple());
+ if (!CPUOrErr)
+ return CPUOrErr.takeError();
+ unsigned CPUType, CPUSubType;
+ std::tie(CPUType, CPUSubType) = CPUOrErr.get();
+ // We don't directly use the architecture name of the target triple T, as,
+ // for instance, thumb is treated as ARM by the MachOUniversal object.
+ std::string ArchName(
+ MachOObjectFile::getArchTriple(CPUType, CPUSubType).getArchName());
+ return Slice{IRO, CPUType, CPUSubType, std::move(ArchName), Align};
+}
+
+static Expected<SmallVector<MachO::fat_arch, 2>>
+buildFatArchList(ArrayRef<Slice> Slices) {
+ SmallVector<MachO::fat_arch, 2> FatArchList;
+ uint64_t Offset =
+ sizeof(MachO::fat_header) + Slices.size() * sizeof(MachO::fat_arch);
+
+ for (const auto &S : Slices) {
+ Offset = alignTo(Offset, 1ull << S.getP2Alignment());
+ if (Offset > UINT32_MAX)
+ return createStringError(
+ std::errc::invalid_argument,
+ ("fat file too large to be created because the offset "
+ "field in struct fat_arch is only 32-bits and the offset " +
+ Twine(Offset) + " for " + S.getBinary()->getFileName() +
+ " for architecture " + S.getArchString() + "exceeds that.")
+ .str()
+ .c_str());
+
+ MachO::fat_arch FatArch;
+ FatArch.cputype = S.getCPUType();
+ FatArch.cpusubtype = S.getCPUSubType();
+ FatArch.offset = Offset;
+ FatArch.size = S.getBinary()->getMemoryBufferRef().getBufferSize();
+ FatArch.align = S.getP2Alignment();
+ Offset += FatArch.size;
+ FatArchList.push_back(FatArch);
+ }
+ return FatArchList;
+}
+
+static Error writeUniversalBinaryToStream(ArrayRef<Slice> Slices,
+ raw_ostream &Out) {
+ MachO::fat_header FatHeader;
+ FatHeader.magic = MachO::FAT_MAGIC;
+ FatHeader.nfat_arch = Slices.size();
+
+ Expected<SmallVector<MachO::fat_arch, 2>> FatArchListOrErr =
+ buildFatArchList(Slices);
+ if (!FatArchListOrErr)
+ return FatArchListOrErr.takeError();
+ SmallVector<MachO::fat_arch, 2> FatArchList = *FatArchListOrErr;
+
+ if (sys::IsLittleEndianHost)
+ MachO::swapStruct(FatHeader);
+ Out.write(reinterpret_cast<const char *>(&FatHeader),
+ sizeof(MachO::fat_header));
+
+ if (sys::IsLittleEndianHost)
+ for (MachO::fat_arch &FA : FatArchList)
+ MachO::swapStruct(FA);
+ Out.write(reinterpret_cast<const char *>(FatArchList.data()),
+ sizeof(MachO::fat_arch) * FatArchList.size());
+
+ if (sys::IsLittleEndianHost)
+ for (MachO::fat_arch &FA : FatArchList)
+ MachO::swapStruct(FA);
+
+ size_t Offset =
+ sizeof(MachO::fat_header) + sizeof(MachO::fat_arch) * FatArchList.size();
+ for (size_t Index = 0, Size = Slices.size(); Index < Size; ++Index) {
+ MemoryBufferRef BufferRef = Slices[Index].getBinary()->getMemoryBufferRef();
+ assert((Offset <= FatArchList[Index].offset) && "Incorrect slice offset");
+ Out.write_zeros(FatArchList[Index].offset - Offset);
+ Out.write(BufferRef.getBufferStart(), BufferRef.getBufferSize());
+ Offset = FatArchList[Index].offset + BufferRef.getBufferSize();
+ }
+
+ Out.flush();
+ return Error::success();
+}
+
+Error object::writeUniversalBinary(ArrayRef<Slice> Slices,
+ StringRef OutputFileName) {
+ const bool IsExecutable = any_of(Slices, [](Slice S) {
+ return sys::fs::can_execute(S.getBinary()->getFileName());
+ });
+ unsigned Mode = sys::fs::all_read | sys::fs::all_write;
+ if (IsExecutable)
+ Mode |= sys::fs::all_exe;
+ Expected<sys::fs::TempFile> Temp = sys::fs::TempFile::create(
+ OutputFileName + ".temp-universal-%%%%%%", Mode);
+ if (!Temp)
+ return Temp.takeError();
+ raw_fd_ostream Out(Temp->FD, false);
+ if (Error E = writeUniversalBinaryToStream(Slices, Out)) {
+ if (Error DiscardError = Temp->discard())
+ return joinErrors(std::move(E), std::move(DiscardError));
+ return E;
+ }
+ return Temp->keep(OutputFileName);
+}
+
+Expected<std::unique_ptr<MemoryBuffer>>
+object::writeUniversalBinaryToBuffer(ArrayRef<Slice> Slices) {
+ SmallVector<char, 0> Buffer;
+ raw_svector_ostream Out(Buffer);
+
+ if (Error E = writeUniversalBinaryToStream(Slices, Out))
+ return std::move(E);
+
+ return std::make_unique<SmallVectorMemoryBuffer>(std::move(Buffer));
+}
diff --git a/contrib/libs/llvm12/lib/Object/ObjectFile.cpp b/contrib/libs/llvm12/lib/Object/ObjectFile.cpp
index c494f99045..cf09a66d9c 100644
--- a/contrib/libs/llvm12/lib/Object/ObjectFile.cpp
+++ b/contrib/libs/llvm12/lib/Object/ObjectFile.cpp
@@ -132,8 +132,8 @@ Triple ObjectFile::makeTriple() const {
}
Expected<std::unique_ptr<ObjectFile>>
-ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
- bool InitContent) {
+ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
+ bool InitContent) {
StringRef Data = Object.getBuffer();
if (Type == file_magic::unknown)
Type = identify_magic(Data);
@@ -155,7 +155,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
case file_magic::elf_executable:
case file_magic::elf_shared_object:
case file_magic::elf_core:
- return createELFObjectFile(Object, InitContent);
+ return createELFObjectFile(Object, InitContent);
case file_magic::macho_object:
case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib:
diff --git a/contrib/libs/llvm12/lib/Object/RelocationResolver.cpp b/contrib/libs/llvm12/lib/Object/RelocationResolver.cpp
index b6978b8c09..204577af72 100644
--- a/contrib/libs/llvm12/lib/Object/RelocationResolver.cpp
+++ b/contrib/libs/llvm12/lib/Object/RelocationResolver.cpp
@@ -39,21 +39,21 @@ static bool supportsX86_64(uint64_t Type) {
}
}
-static uint64_t resolveX86_64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveX86_64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t Addend) {
+ switch (Type) {
case ELF::R_X86_64_NONE:
- return LocData;
+ return LocData;
case ELF::R_X86_64_64:
case ELF::R_X86_64_DTPOFF32:
case ELF::R_X86_64_DTPOFF64:
- return S + Addend;
+ return S + Addend;
case ELF::R_X86_64_PC32:
case ELF::R_X86_64_PC64:
- return S + Addend - Offset;
+ return S + Addend - Offset;
case ELF::R_X86_64_32:
case ELF::R_X86_64_32S:
- return (S + Addend) & 0xFFFFFFFF;
+ return (S + Addend) & 0xFFFFFFFF;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -71,17 +71,17 @@ static bool supportsAArch64(uint64_t Type) {
}
}
-static uint64_t resolveAArch64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveAArch64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_AARCH64_ABS32:
- return (S + Addend) & 0xFFFFFFFF;
+ return (S + Addend) & 0xFFFFFFFF;
case ELF::R_AARCH64_ABS64:
- return S + Addend;
+ return S + Addend;
case ELF::R_AARCH64_PREL32:
- return (S + Addend - Offset) & 0xFFFFFFFF;
+ return (S + Addend - Offset) & 0xFFFFFFFF;
case ELF::R_AARCH64_PREL64:
- return S + Addend - Offset;
+ return S + Addend - Offset;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -97,13 +97,13 @@ static bool supportsBPF(uint64_t Type) {
}
}
-static uint64_t resolveBPF(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- switch (Type) {
+static uint64_t resolveBPF(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ switch (Type) {
case ELF::R_BPF_64_32:
- return (S + LocData) & 0xFFFFFFFF;
+ return (S + LocData) & 0xFFFFFFFF;
case ELF::R_BPF_64_64:
- return S + LocData;
+ return S + LocData;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -121,17 +121,17 @@ static bool supportsMips64(uint64_t Type) {
}
}
-static uint64_t resolveMips64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveMips64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_MIPS_32:
- return (S + Addend) & 0xFFFFFFFF;
+ return (S + Addend) & 0xFFFFFFFF;
case ELF::R_MIPS_64:
- return S + Addend;
+ return S + Addend;
case ELF::R_MIPS_TLS_DTPREL64:
- return S + Addend - 0x8000;
+ return S + Addend - 0x8000;
case ELF::R_MIPS_PC32:
- return S + Addend - Offset;
+ return S + Addend - Offset;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -147,13 +147,13 @@ static bool supportsMSP430(uint64_t Type) {
}
}
-static uint64_t resolveMSP430(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveMSP430(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_MSP430_32:
- return (S + Addend) & 0xFFFFFFFF;
+ return (S + Addend) & 0xFFFFFFFF;
case ELF::R_MSP430_16_BYTE:
- return (S + Addend) & 0xFFFF;
+ return (S + Addend) & 0xFFFF;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -171,17 +171,17 @@ static bool supportsPPC64(uint64_t Type) {
}
}
-static uint64_t resolvePPC64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolvePPC64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_PPC64_ADDR32:
- return (S + Addend) & 0xFFFFFFFF;
+ return (S + Addend) & 0xFFFFFFFF;
case ELF::R_PPC64_ADDR64:
- return S + Addend;
+ return S + Addend;
case ELF::R_PPC64_REL32:
- return (S + Addend - Offset) & 0xFFFFFFFF;
+ return (S + Addend - Offset) & 0xFFFFFFFF;
case ELF::R_PPC64_REL64:
- return S + Addend - Offset;
+ return S + Addend - Offset;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -197,13 +197,13 @@ static bool supportsSystemZ(uint64_t Type) {
}
}
-static uint64_t resolveSystemZ(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveSystemZ(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_390_32:
- return (S + Addend) & 0xFFFFFFFF;
+ return (S + Addend) & 0xFFFFFFFF;
case ELF::R_390_64:
- return S + Addend;
+ return S + Addend;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -221,14 +221,14 @@ static bool supportsSparc64(uint64_t Type) {
}
}
-static uint64_t resolveSparc64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveSparc64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_SPARC_32:
case ELF::R_SPARC_64:
case ELF::R_SPARC_UA32:
case ELF::R_SPARC_UA64:
- return S + Addend;
+ return S + Addend;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -244,12 +244,12 @@ static bool supportsAmdgpu(uint64_t Type) {
}
}
-static uint64_t resolveAmdgpu(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveAmdgpu(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_AMDGPU_ABS32:
case ELF::R_AMDGPU_ABS64:
- return S + Addend;
+ return S + Addend;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -266,15 +266,15 @@ static bool supportsX86(uint64_t Type) {
}
}
-static uint64_t resolveX86(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- switch (Type) {
+static uint64_t resolveX86(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ switch (Type) {
case ELF::R_386_NONE:
- return LocData;
+ return LocData;
case ELF::R_386_32:
- return S + LocData;
+ return S + LocData;
case ELF::R_386_PC32:
- return S - Offset + LocData;
+ return S - Offset + LocData;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -290,35 +290,35 @@ static bool supportsPPC32(uint64_t Type) {
}
}
-static uint64_t resolvePPC32(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolvePPC32(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_PPC_ADDR32:
- return (S + Addend) & 0xFFFFFFFF;
+ return (S + Addend) & 0xFFFFFFFF;
case ELF::R_PPC_REL32:
- return (S + Addend - Offset) & 0xFFFFFFFF;
+ return (S + Addend - Offset) & 0xFFFFFFFF;
}
llvm_unreachable("Invalid relocation type");
}
static bool supportsARM(uint64_t Type) {
- switch (Type) {
- case ELF::R_ARM_ABS32:
- case ELF::R_ARM_REL32:
- return true;
- default:
- return false;
- }
-}
-
-static uint64_t resolveARM(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- switch (Type) {
- case ELF::R_ARM_ABS32:
- return (S + LocData) & 0xFFFFFFFF;
- case ELF::R_ARM_REL32:
- return (S + LocData - Offset) & 0xFFFFFFFF;
- }
+ switch (Type) {
+ case ELF::R_ARM_ABS32:
+ case ELF::R_ARM_REL32:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static uint64_t resolveARM(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ switch (Type) {
+ case ELF::R_ARM_ABS32:
+ return (S + LocData) & 0xFFFFFFFF;
+ case ELF::R_ARM_REL32:
+ return (S + LocData - Offset) & 0xFFFFFFFF;
+ }
llvm_unreachable("Invalid relocation type");
}
@@ -332,13 +332,13 @@ static bool supportsAVR(uint64_t Type) {
}
}
-static uint64_t resolveAVR(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveAVR(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ switch (Type) {
case ELF::R_AVR_16:
- return (S + Addend) & 0xFFFF;
+ return (S + Addend) & 0xFFFF;
case ELF::R_AVR_32:
- return (S + Addend) & 0xFFFFFFFF;
+ return (S + Addend) & 0xFFFFFFFF;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -348,10 +348,10 @@ static bool supportsLanai(uint64_t Type) {
return Type == ELF::R_LANAI_32;
}
-static uint64_t resolveLanai(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- if (Type == ELF::R_LANAI_32)
- return (S + Addend) & 0xFFFFFFFF;
+static uint64_t resolveLanai(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ if (Type == ELF::R_LANAI_32)
+ return (S + Addend) & 0xFFFFFFFF;
llvm_unreachable("Invalid relocation type");
}
@@ -365,13 +365,13 @@ static bool supportsMips32(uint64_t Type) {
}
}
-static uint64_t resolveMips32(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
+static uint64_t resolveMips32(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
// FIXME: Take in account implicit addends to get correct results.
- if (Type == ELF::R_MIPS_32)
- return (S + LocData) & 0xFFFFFFFF;
- if (Type == ELF::R_MIPS_TLS_DTPREL32)
- return (S + LocData) & 0xFFFFFFFF;
+ if (Type == ELF::R_MIPS_32)
+ return (S + LocData) & 0xFFFFFFFF;
+ if (Type == ELF::R_MIPS_TLS_DTPREL32)
+ return (S + LocData) & 0xFFFFFFFF;
llvm_unreachable("Invalid relocation type");
}
@@ -385,21 +385,21 @@ static bool supportsSparc32(uint64_t Type) {
}
}
-static uint64_t resolveSparc32(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t Addend) {
- if (Type == ELF::R_SPARC_32 || Type == ELF::R_SPARC_UA32)
- return S + Addend;
- return LocData;
+static uint64_t resolveSparc32(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t Addend) {
+ if (Type == ELF::R_SPARC_32 || Type == ELF::R_SPARC_UA32)
+ return S + Addend;
+ return LocData;
}
static bool supportsHexagon(uint64_t Type) {
return Type == ELF::R_HEX_32;
}
-static uint64_t resolveHexagon(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t /*LocData*/, int64_t Addend) {
- if (Type == ELF::R_HEX_32)
- return S + Addend;
+static uint64_t resolveHexagon(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t /*LocData*/, int64_t Addend) {
+ if (Type == ELF::R_HEX_32)
+ return S + Addend;
llvm_unreachable("Invalid relocation type");
}
@@ -425,17 +425,17 @@ static bool supportsRISCV(uint64_t Type) {
}
}
-static uint64_t resolveRISCV(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t Addend) {
- int64_t RA = Addend;
- uint64_t A = LocData;
- switch (Type) {
+static uint64_t resolveRISCV(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t Addend) {
+ int64_t RA = Addend;
+ uint64_t A = LocData;
+ switch (Type) {
case ELF::R_RISCV_NONE:
- return LocData;
+ return LocData;
case ELF::R_RISCV_32:
return (S + RA) & 0xFFFFFFFF;
case ELF::R_RISCV_32_PCREL:
- return (S + RA - Offset) & 0xFFFFFFFF;
+ return (S + RA - Offset) & 0xFFFFFFFF;
case ELF::R_RISCV_64:
return S + RA;
case ELF::R_RISCV_SET6:
@@ -473,12 +473,12 @@ static bool supportsCOFFX86(uint64_t Type) {
}
}
-static uint64_t resolveCOFFX86(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- switch (Type) {
+static uint64_t resolveCOFFX86(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ switch (Type) {
case COFF::IMAGE_REL_I386_SECREL:
case COFF::IMAGE_REL_I386_DIR32:
- return (S + LocData) & 0xFFFFFFFF;
+ return (S + LocData) & 0xFFFFFFFF;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -494,13 +494,13 @@ static bool supportsCOFFX86_64(uint64_t Type) {
}
}
-static uint64_t resolveCOFFX86_64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- switch (Type) {
+static uint64_t resolveCOFFX86_64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ switch (Type) {
case COFF::IMAGE_REL_AMD64_SECREL:
- return (S + LocData) & 0xFFFFFFFF;
+ return (S + LocData) & 0xFFFFFFFF;
case COFF::IMAGE_REL_AMD64_ADDR64:
- return S + LocData;
+ return S + LocData;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -516,12 +516,12 @@ static bool supportsCOFFARM(uint64_t Type) {
}
}
-static uint64_t resolveCOFFARM(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- switch (Type) {
+static uint64_t resolveCOFFARM(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ switch (Type) {
case COFF::IMAGE_REL_ARM_SECREL:
case COFF::IMAGE_REL_ARM_ADDR32:
- return (S + LocData) & 0xFFFFFFFF;
+ return (S + LocData) & 0xFFFFFFFF;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -537,13 +537,13 @@ static bool supportsCOFFARM64(uint64_t Type) {
}
}
-static uint64_t resolveCOFFARM64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- switch (Type) {
+static uint64_t resolveCOFFARM64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ switch (Type) {
case COFF::IMAGE_REL_ARM64_SECREL:
- return (S + LocData) & 0xFFFFFFFF;
+ return (S + LocData) & 0xFFFFFFFF;
case COFF::IMAGE_REL_ARM64_ADDR64:
- return S + LocData;
+ return S + LocData;
default:
llvm_unreachable("Invalid relocation type");
}
@@ -553,9 +553,9 @@ static bool supportsMachOX86_64(uint64_t Type) {
return Type == MachO::X86_64_RELOC_UNSIGNED;
}
-static uint64_t resolveMachOX86_64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- if (Type == MachO::X86_64_RELOC_UNSIGNED)
+static uint64_t resolveMachOX86_64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ if (Type == MachO::X86_64_RELOC_UNSIGNED)
return S;
llvm_unreachable("Invalid relocation type");
}
@@ -574,7 +574,7 @@ static bool supportsWasm32(uint64_t Type) {
case wasm::R_WASM_SECTION_OFFSET_I32:
case wasm::R_WASM_EVENT_INDEX_LEB:
case wasm::R_WASM_GLOBAL_INDEX_I32:
- case wasm::R_WASM_TABLE_NUMBER_LEB:
+ case wasm::R_WASM_TABLE_NUMBER_LEB:
return true;
default:
return false;
@@ -586,18 +586,18 @@ static bool supportsWasm64(uint64_t Type) {
case wasm::R_WASM_MEMORY_ADDR_LEB64:
case wasm::R_WASM_MEMORY_ADDR_SLEB64:
case wasm::R_WASM_MEMORY_ADDR_I64:
- case wasm::R_WASM_TABLE_INDEX_SLEB64:
- case wasm::R_WASM_TABLE_INDEX_I64:
- case wasm::R_WASM_FUNCTION_OFFSET_I64:
+ case wasm::R_WASM_TABLE_INDEX_SLEB64:
+ case wasm::R_WASM_TABLE_INDEX_I64:
+ case wasm::R_WASM_FUNCTION_OFFSET_I64:
return true;
default:
return supportsWasm32(Type);
}
}
-static uint64_t resolveWasm32(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t /*Addend*/) {
- switch (Type) {
+static uint64_t resolveWasm32(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t /*Addend*/) {
+ switch (Type) {
case wasm::R_WASM_FUNCTION_INDEX_LEB:
case wasm::R_WASM_TABLE_INDEX_SLEB:
case wasm::R_WASM_TABLE_INDEX_I32:
@@ -610,31 +610,31 @@ static uint64_t resolveWasm32(uint64_t Type, uint64_t Offset, uint64_t S,
case wasm::R_WASM_SECTION_OFFSET_I32:
case wasm::R_WASM_EVENT_INDEX_LEB:
case wasm::R_WASM_GLOBAL_INDEX_I32:
- case wasm::R_WASM_TABLE_NUMBER_LEB:
+ case wasm::R_WASM_TABLE_NUMBER_LEB:
// For wasm section, its offset at 0 -- ignoring Value
- return LocData;
+ return LocData;
default:
llvm_unreachable("Invalid relocation type");
}
}
-static uint64_t resolveWasm64(uint64_t Type, uint64_t Offset, uint64_t S,
- uint64_t LocData, int64_t Addend) {
- switch (Type) {
+static uint64_t resolveWasm64(uint64_t Type, uint64_t Offset, uint64_t S,
+ uint64_t LocData, int64_t Addend) {
+ switch (Type) {
case wasm::R_WASM_MEMORY_ADDR_LEB64:
case wasm::R_WASM_MEMORY_ADDR_SLEB64:
case wasm::R_WASM_MEMORY_ADDR_I64:
- case wasm::R_WASM_TABLE_INDEX_SLEB64:
- case wasm::R_WASM_TABLE_INDEX_I64:
- case wasm::R_WASM_FUNCTION_OFFSET_I64:
+ case wasm::R_WASM_TABLE_INDEX_SLEB64:
+ case wasm::R_WASM_TABLE_INDEX_I64:
+ case wasm::R_WASM_FUNCTION_OFFSET_I64:
// For wasm section, its offset at 0 -- ignoring Value
- return LocData;
+ return LocData;
default:
- return resolveWasm32(Type, Offset, S, LocData, Addend);
+ return resolveWasm32(Type, Offset, S, LocData, Addend);
}
}
-std::pair<SupportsRelocation, RelocationResolver>
+std::pair<SupportsRelocation, RelocationResolver>
getRelocationResolver(const ObjectFile &Obj) {
if (Obj.isCOFF()) {
switch (Obj.getArch()) {
@@ -687,7 +687,7 @@ getRelocationResolver(const ObjectFile &Obj) {
switch (Obj.getArch()) {
case Triple::x86:
return {supportsX86, resolveX86};
- case Triple::ppcle:
+ case Triple::ppcle:
case Triple::ppc:
return {supportsPPC32, resolvePPC32};
case Triple::arm:
@@ -726,38 +726,38 @@ getRelocationResolver(const ObjectFile &Obj) {
llvm_unreachable("Invalid object file");
}
-uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R,
- uint64_t S, uint64_t LocData) {
- if (const ObjectFile *Obj = R.getObject()) {
- int64_t Addend = 0;
- if (Obj->isELF()) {
- auto GetRelSectionType = [&]() -> unsigned {
- if (auto *Elf32LEObj = dyn_cast<ELF32LEObjectFile>(Obj))
- return Elf32LEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
- if (auto *Elf64LEObj = dyn_cast<ELF64LEObjectFile>(Obj))
- return Elf64LEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
- if (auto *Elf32BEObj = dyn_cast<ELF32BEObjectFile>(Obj))
- return Elf32BEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
- auto *Elf64BEObj = cast<ELF64BEObjectFile>(Obj);
- return Elf64BEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
- };
-
- if (GetRelSectionType() == ELF::SHT_RELA)
- Addend = getELFAddend(R);
- }
-
- return Resolver(R.getType(), R.getOffset(), S, LocData, Addend);
- }
-
- // Sometimes the caller might want to use its own specific implementation of
- // the resolver function. E.g. this is used by LLD when it resolves debug
- // relocations and assumes that all of them have the same computation (S + A).
- // The relocation R has no owner object in this case and we don't need to
- // provide Type and Offset fields. It is also assumed the DataRefImpl.p
- // contains the addend, provided by the caller.
- return Resolver(/*Type=*/0, /*Offset=*/0, S, LocData,
- R.getRawDataRefImpl().p);
-}
-
+uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R,
+ uint64_t S, uint64_t LocData) {
+ if (const ObjectFile *Obj = R.getObject()) {
+ int64_t Addend = 0;
+ if (Obj->isELF()) {
+ auto GetRelSectionType = [&]() -> unsigned {
+ if (auto *Elf32LEObj = dyn_cast<ELF32LEObjectFile>(Obj))
+ return Elf32LEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
+ if (auto *Elf64LEObj = dyn_cast<ELF64LEObjectFile>(Obj))
+ return Elf64LEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
+ if (auto *Elf32BEObj = dyn_cast<ELF32BEObjectFile>(Obj))
+ return Elf32BEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
+ auto *Elf64BEObj = cast<ELF64BEObjectFile>(Obj);
+ return Elf64BEObj->getRelSection(R.getRawDataRefImpl())->sh_type;
+ };
+
+ if (GetRelSectionType() == ELF::SHT_RELA)
+ Addend = getELFAddend(R);
+ }
+
+ return Resolver(R.getType(), R.getOffset(), S, LocData, Addend);
+ }
+
+ // Sometimes the caller might want to use its own specific implementation of
+ // the resolver function. E.g. this is used by LLD when it resolves debug
+ // relocations and assumes that all of them have the same computation (S + A).
+ // The relocation R has no owner object in this case and we don't need to
+ // provide Type and Offset fields. It is also assumed the DataRefImpl.p
+ // contains the addend, provided by the caller.
+ return Resolver(/*Type=*/0, /*Offset=*/0, S, LocData,
+ R.getRawDataRefImpl().p);
+}
+
} // namespace object
} // namespace llvm
diff --git a/contrib/libs/llvm12/lib/Object/SymbolSize.cpp b/contrib/libs/llvm12/lib/Object/SymbolSize.cpp
index 15d3c1fe7d..97baabec08 100644
--- a/contrib/libs/llvm12/lib/Object/SymbolSize.cpp
+++ b/contrib/libs/llvm12/lib/Object/SymbolSize.cpp
@@ -48,7 +48,7 @@ llvm::object::computeSymbolSizes(const ObjectFile &O) {
if (const auto *E = dyn_cast<ELFObjectFileBase>(&O)) {
auto Syms = E->symbols();
- if (Syms.empty())
+ if (Syms.empty())
Syms = E->getDynamicSymbolIterators();
for (ELFSymbolRef Sym : Syms)
Ret.push_back({Sym, Sym.getSize()});
diff --git a/contrib/libs/llvm12/lib/Object/SymbolicFile.cpp b/contrib/libs/llvm12/lib/Object/SymbolicFile.cpp
index 5b35000565..34a2c5e1c1 100644
--- a/contrib/libs/llvm12/lib/Object/SymbolicFile.cpp
+++ b/contrib/libs/llvm12/lib/Object/SymbolicFile.cpp
@@ -36,19 +36,19 @@ SymbolicFile::~SymbolicFile() = default;
Expected<std::unique_ptr<SymbolicFile>>
SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
- LLVMContext *Context, bool InitContent) {
+ LLVMContext *Context, bool InitContent) {
StringRef Data = Object.getBuffer();
if (Type == file_magic::unknown)
Type = identify_magic(Data);
- if (!isSymbolicFile(Type, Context))
- return errorCodeToError(object_error::invalid_file_type);
-
+ if (!isSymbolicFile(Type, Context))
+ return errorCodeToError(object_error::invalid_file_type);
+
switch (Type) {
case file_magic::bitcode:
- // Context is guaranteed to be non-null here, because bitcode magic only
- // indicates a symbolic file when Context is non-null.
- return IRObjectFile::create(Object, *Context);
+ // Context is guaranteed to be non-null here, because bitcode magic only
+ // indicates a symbolic file when Context is non-null.
+ return IRObjectFile::create(Object, *Context);
case file_magic::elf:
case file_magic::elf_executable:
case file_magic::elf_shared_object:
@@ -67,14 +67,14 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
case file_magic::xcoff_object_32:
case file_magic::xcoff_object_64:
case file_magic::wasm_object:
- return ObjectFile::createObjectFile(Object, Type, InitContent);
+ return ObjectFile::createObjectFile(Object, Type, InitContent);
case file_magic::coff_import_library:
return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object));
case file_magic::elf_relocatable:
case file_magic::macho_object:
case file_magic::coff_object: {
Expected<std::unique_ptr<ObjectFile>> Obj =
- ObjectFile::createObjectFile(Object, Type, InitContent);
+ ObjectFile::createObjectFile(Object, Type, InitContent);
if (!Obj || !Context)
return std::move(Obj);
@@ -89,39 +89,39 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
*Context);
}
- default:
- llvm_unreachable("Unexpected Binary File Type");
+ default:
+ llvm_unreachable("Unexpected Binary File Type");
+ }
+}
+
+bool SymbolicFile::isSymbolicFile(file_magic Type, const LLVMContext *Context) {
+ switch (Type) {
+ case file_magic::bitcode:
+ return Context != nullptr;
+ case file_magic::elf:
+ case file_magic::elf_executable:
+ case file_magic::elf_shared_object:
+ case file_magic::elf_core:
+ case file_magic::macho_executable:
+ case file_magic::macho_fixed_virtual_memory_shared_lib:
+ case file_magic::macho_core:
+ case file_magic::macho_preload_executable:
+ case file_magic::macho_dynamically_linked_shared_lib:
+ case file_magic::macho_dynamic_linker:
+ case file_magic::macho_bundle:
+ case file_magic::macho_dynamically_linked_shared_lib_stub:
+ case file_magic::macho_dsym_companion:
+ case file_magic::macho_kext_bundle:
+ case file_magic::pecoff_executable:
+ case file_magic::xcoff_object_32:
+ case file_magic::xcoff_object_64:
+ case file_magic::wasm_object:
+ case file_magic::coff_import_library:
+ case file_magic::elf_relocatable:
+ case file_magic::macho_object:
+ case file_magic::coff_object:
+ return true;
+ default:
+ return false;
}
}
-
-bool SymbolicFile::isSymbolicFile(file_magic Type, const LLVMContext *Context) {
- switch (Type) {
- case file_magic::bitcode:
- return Context != nullptr;
- case file_magic::elf:
- case file_magic::elf_executable:
- case file_magic::elf_shared_object:
- case file_magic::elf_core:
- case file_magic::macho_executable:
- case file_magic::macho_fixed_virtual_memory_shared_lib:
- case file_magic::macho_core:
- case file_magic::macho_preload_executable:
- case file_magic::macho_dynamically_linked_shared_lib:
- case file_magic::macho_dynamic_linker:
- case file_magic::macho_bundle:
- case file_magic::macho_dynamically_linked_shared_lib_stub:
- case file_magic::macho_dsym_companion:
- case file_magic::macho_kext_bundle:
- case file_magic::pecoff_executable:
- case file_magic::xcoff_object_32:
- case file_magic::xcoff_object_64:
- case file_magic::wasm_object:
- case file_magic::coff_import_library:
- case file_magic::elf_relocatable:
- case file_magic::macho_object:
- case file_magic::coff_object:
- return true;
- default:
- return false;
- }
-}
diff --git a/contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp b/contrib/libs/llvm12/lib/Object/WasmObjectFile.cpp
index 52cb9abec8..40f468881e 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();
diff --git a/contrib/libs/llvm12/lib/Object/XCOFFObjectFile.cpp b/contrib/libs/llvm12/lib/Object/XCOFFObjectFile.cpp
index 5e3a6809bd..a16a458168 100644
--- a/contrib/libs/llvm12/lib/Object/XCOFFObjectFile.cpp
+++ b/contrib/libs/llvm12/lib/Object/XCOFFObjectFile.cpp
@@ -12,14 +12,14 @@
#include "llvm/Object/XCOFFObjectFile.h"
#include "llvm/MC/SubtargetFeature.h"
-#include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/DataExtractor.h"
#include <cstddef>
#include <cstring>
namespace llvm {
-
-using namespace XCOFF;
-
+
+using namespace XCOFF;
+
namespace object {
static const uint8_t FunctionSym = 0x20;
@@ -31,7 +31,7 @@ static const uint16_t NoRelMask = 0x0001;
template <typename T>
static Expected<const T *> getObject(MemoryBufferRef M, const void *Ptr,
const uint64_t Size = sizeof(T)) {
- uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr);
+ uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr);
if (Error E = Binary::checkOffset(M, Addr, Size))
return std::move(E);
return reinterpret_cast<const T *>(Addr);
@@ -283,7 +283,7 @@ XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const {
const uint8_t * ContentStart = base() + OffsetToRaw;
uint64_t SectionSize = getSectionSize(Sec);
- if (checkOffset(Data, reinterpret_cast<uintptr_t>(ContentStart), SectionSize))
+ if (checkOffset(Data, reinterpret_cast<uintptr_t>(ContentStart), SectionSize))
return make_error<BinaryError>();
return makeArrayRef(ContentStart,SectionSize);
@@ -655,8 +655,8 @@ XCOFFObjectFile::relocations(const XCOFFSectionHeader32 &Sec) const {
uint32_t NumRelocEntries = NumRelocEntriesOrErr.get();
- static_assert(
- sizeof(XCOFFRelocation32) == XCOFF::RelocationSerializationSize32, "");
+ static_assert(
+ sizeof(XCOFFRelocation32) == XCOFF::RelocationSerializationSize32, "");
auto RelocationOrErr =
getObject<XCOFFRelocation32>(Data, reinterpret_cast<void *>(RelocAddr),
NumRelocEntries * sizeof(XCOFFRelocation32));
@@ -839,297 +839,297 @@ bool XCOFFSymbolRef::isFunction() const {
template struct XCOFFSectionHeader<XCOFFSectionHeader32>;
template struct XCOFFSectionHeader<XCOFFSectionHeader64>;
-bool doesXCOFFTracebackTableBegin(ArrayRef<uint8_t> Bytes) {
- if (Bytes.size() < 4)
- return false;
-
- return support::endian::read32be(Bytes.data()) == 0;
-}
-
-TBVectorExt::TBVectorExt(StringRef TBvectorStrRef) {
- const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(TBvectorStrRef.data());
- Data = support::endian::read16be(Ptr);
- VecParmsInfo = support::endian::read32be(Ptr + 2);
-}
-
-#define GETVALUEWITHMASK(X) (Data & (TracebackTable::X))
-#define GETVALUEWITHMASKSHIFT(X, S) \
- ((Data & (TracebackTable::X)) >> (TracebackTable::S))
-uint8_t TBVectorExt::getNumberOfVRSaved() const {
- return GETVALUEWITHMASKSHIFT(NumberOfVRSavedMask, NumberOfVRSavedShift);
-}
-
-bool TBVectorExt::isVRSavedOnStack() const {
- return GETVALUEWITHMASK(IsVRSavedOnStackMask);
-}
-
-bool TBVectorExt::hasVarArgs() const {
- return GETVALUEWITHMASK(HasVarArgsMask);
-}
-uint8_t TBVectorExt::getNumberOfVectorParms() const {
- return GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask,
- NumberOfVectorParmsShift);
-}
-
-bool TBVectorExt::hasVMXInstruction() const {
- return GETVALUEWITHMASK(HasVMXInstructionMask);
-}
-#undef GETVALUEWITHMASK
-#undef GETVALUEWITHMASKSHIFT
-
-SmallString<32> TBVectorExt::getVectorParmsInfoString() const {
- SmallString<32> ParmsType;
- uint32_t Value = VecParmsInfo;
- for (uint8_t I = 0; I < getNumberOfVectorParms(); ++I) {
- if (I != 0)
- ParmsType += ", ";
- switch (Value & TracebackTable::ParmTypeMask) {
- case TracebackTable::ParmTypeIsVectorCharBit:
- ParmsType += "vc";
- break;
-
- case TracebackTable::ParmTypeIsVectorShortBit:
- ParmsType += "vs";
- break;
-
- case TracebackTable::ParmTypeIsVectorIntBit:
- ParmsType += "vi";
- break;
-
- case TracebackTable::ParmTypeIsVectorFloatBit:
- ParmsType += "vf";
- break;
- }
- Value <<= 2;
- }
- return ParmsType;
-}
-
-static SmallString<32> parseParmsTypeWithVecInfo(uint32_t Value,
- unsigned int ParmsNum) {
- SmallString<32> ParmsType;
- unsigned I = 0;
- bool Begin = false;
- while (I < ParmsNum || Value) {
- if (Begin)
- ParmsType += ", ";
- else
- Begin = true;
-
- switch (Value & TracebackTable::ParmTypeMask) {
- case TracebackTable::ParmTypeIsFixedBits:
- ParmsType += "i";
- ++I;
- break;
- case TracebackTable::ParmTypeIsVectorBits:
- ParmsType += "v";
- break;
- case TracebackTable::ParmTypeIsFloatingBits:
- ParmsType += "f";
- ++I;
- break;
- case TracebackTable::ParmTypeIsDoubleBits:
- ParmsType += "d";
- ++I;
- break;
- default:
- assert(false && "Unrecognized bits in ParmsType.");
- }
- Value <<= 2;
- }
- assert(I == ParmsNum &&
- "The total parameters number of fixed-point or floating-point "
- "parameters not equal to the number in the parameter type!");
- return ParmsType;
-}
-
-Expected<XCOFFTracebackTable> XCOFFTracebackTable::create(const uint8_t *Ptr,
- uint64_t &Size) {
- Error Err = Error::success();
- XCOFFTracebackTable TBT(Ptr, Size, Err);
- if (Err)
- return std::move(Err);
- return TBT;
-}
-
-XCOFFTracebackTable::XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size,
- Error &Err)
- : TBPtr(Ptr) {
- ErrorAsOutParameter EAO(&Err);
- DataExtractor DE(ArrayRef<uint8_t>(Ptr, Size), /*IsLittleEndian=*/false,
- /*AddressSize=*/0);
- DataExtractor::Cursor Cur(/*Offset=*/0);
-
- // Skip 8 bytes of mandatory fields.
- DE.getU64(Cur);
-
- // Begin to parse optional fields.
- if (Cur) {
- unsigned ParmNum = getNumberOfFixedParms() + getNumberOfFPParms();
-
- // As long as there are no "fixed-point" or floating-point parameters, this
- // field remains not present even when hasVectorInfo gives true and
- // indicates the presence of vector parameters.
- if (ParmNum > 0) {
- uint32_t ParamsTypeValue = DE.getU32(Cur);
- if (Cur)
- ParmsType = hasVectorInfo()
- ? parseParmsTypeWithVecInfo(ParamsTypeValue, ParmNum)
- : parseParmsType(ParamsTypeValue, ParmNum);
- }
- }
-
- if (Cur && hasTraceBackTableOffset())
- TraceBackTableOffset = DE.getU32(Cur);
-
- if (Cur && isInterruptHandler())
- HandlerMask = DE.getU32(Cur);
-
- if (Cur && hasControlledStorage()) {
- NumOfCtlAnchors = DE.getU32(Cur);
- if (Cur && NumOfCtlAnchors) {
- SmallVector<uint32_t, 8> Disp;
- Disp.reserve(NumOfCtlAnchors.getValue());
- for (uint32_t I = 0; I < NumOfCtlAnchors && Cur; ++I)
- Disp.push_back(DE.getU32(Cur));
- if (Cur)
- ControlledStorageInfoDisp = std::move(Disp);
- }
- }
-
- if (Cur && isFuncNamePresent()) {
- uint16_t FunctionNameLen = DE.getU16(Cur);
- if (Cur)
- FunctionName = DE.getBytes(Cur, FunctionNameLen);
- }
-
- if (Cur && isAllocaUsed())
- AllocaRegister = DE.getU8(Cur);
-
- if (Cur && hasVectorInfo()) {
- StringRef VectorExtRef = DE.getBytes(Cur, 6);
- if (Cur)
- VecExt = TBVectorExt(VectorExtRef);
- }
-
- if (Cur && hasExtensionTable())
- ExtensionTable = DE.getU8(Cur);
-
- if (!Cur)
- Err = Cur.takeError();
- Size = Cur.tell();
-}
-
-#define GETBITWITHMASK(P, X) \
- (support::endian::read32be(TBPtr + (P)) & (TracebackTable::X))
-#define GETBITWITHMASKSHIFT(P, X, S) \
- ((support::endian::read32be(TBPtr + (P)) & (TracebackTable::X)) >> \
- (TracebackTable::S))
-
-uint8_t XCOFFTracebackTable::getVersion() const {
- return GETBITWITHMASKSHIFT(0, VersionMask, VersionShift);
-}
-
-uint8_t XCOFFTracebackTable::getLanguageID() const {
- return GETBITWITHMASKSHIFT(0, LanguageIdMask, LanguageIdShift);
-}
-
-bool XCOFFTracebackTable::isGlobalLinkage() const {
- return GETBITWITHMASK(0, IsGlobaLinkageMask);
-}
-
-bool XCOFFTracebackTable::isOutOfLineEpilogOrPrologue() const {
- return GETBITWITHMASK(0, IsOutOfLineEpilogOrPrologueMask);
-}
-
-bool XCOFFTracebackTable::hasTraceBackTableOffset() const {
- return GETBITWITHMASK(0, HasTraceBackTableOffsetMask);
-}
-
-bool XCOFFTracebackTable::isInternalProcedure() const {
- return GETBITWITHMASK(0, IsInternalProcedureMask);
-}
-
-bool XCOFFTracebackTable::hasControlledStorage() const {
- return GETBITWITHMASK(0, HasControlledStorageMask);
-}
-
-bool XCOFFTracebackTable::isTOCless() const {
- return GETBITWITHMASK(0, IsTOClessMask);
-}
-
-bool XCOFFTracebackTable::isFloatingPointPresent() const {
- return GETBITWITHMASK(0, IsFloatingPointPresentMask);
-}
-
-bool XCOFFTracebackTable::isFloatingPointOperationLogOrAbortEnabled() const {
- return GETBITWITHMASK(0, IsFloatingPointOperationLogOrAbortEnabledMask);
-}
-
-bool XCOFFTracebackTable::isInterruptHandler() const {
- return GETBITWITHMASK(0, IsInterruptHandlerMask);
-}
-
-bool XCOFFTracebackTable::isFuncNamePresent() const {
- return GETBITWITHMASK(0, IsFunctionNamePresentMask);
-}
-
-bool XCOFFTracebackTable::isAllocaUsed() const {
- return GETBITWITHMASK(0, IsAllocaUsedMask);
-}
-
-uint8_t XCOFFTracebackTable::getOnConditionDirective() const {
- return GETBITWITHMASKSHIFT(0, OnConditionDirectiveMask,
- OnConditionDirectiveShift);
-}
-
-bool XCOFFTracebackTable::isCRSaved() const {
- return GETBITWITHMASK(0, IsCRSavedMask);
-}
-
-bool XCOFFTracebackTable::isLRSaved() const {
- return GETBITWITHMASK(0, IsLRSavedMask);
-}
-
-bool XCOFFTracebackTable::isBackChainStored() const {
- return GETBITWITHMASK(4, IsBackChainStoredMask);
-}
-
-bool XCOFFTracebackTable::isFixup() const {
- return GETBITWITHMASK(4, IsFixupMask);
-}
-
-uint8_t XCOFFTracebackTable::getNumOfFPRsSaved() const {
- return GETBITWITHMASKSHIFT(4, FPRSavedMask, FPRSavedShift);
-}
-
-bool XCOFFTracebackTable::hasExtensionTable() const {
- return GETBITWITHMASK(4, HasExtensionTableMask);
-}
-
-bool XCOFFTracebackTable::hasVectorInfo() const {
- return GETBITWITHMASK(4, HasVectorInfoMask);
-}
-
-uint8_t XCOFFTracebackTable::getNumOfGPRsSaved() const {
- return GETBITWITHMASKSHIFT(4, GPRSavedMask, GPRSavedShift);
-}
-
-uint8_t XCOFFTracebackTable::getNumberOfFixedParms() const {
- return GETBITWITHMASKSHIFT(4, NumberOfFixedParmsMask,
- NumberOfFixedParmsShift);
-}
-
-uint8_t XCOFFTracebackTable::getNumberOfFPParms() const {
- return GETBITWITHMASKSHIFT(4, NumberOfFloatingPointParmsMask,
- NumberOfFloatingPointParmsShift);
-}
-
-bool XCOFFTracebackTable::hasParmsOnStack() const {
- return GETBITWITHMASK(4, HasParmsOnStackMask);
-}
-
-#undef GETBITWITHMASK
-#undef GETBITWITHMASKSHIFT
+bool doesXCOFFTracebackTableBegin(ArrayRef<uint8_t> Bytes) {
+ if (Bytes.size() < 4)
+ return false;
+
+ return support::endian::read32be(Bytes.data()) == 0;
+}
+
+TBVectorExt::TBVectorExt(StringRef TBvectorStrRef) {
+ const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(TBvectorStrRef.data());
+ Data = support::endian::read16be(Ptr);
+ VecParmsInfo = support::endian::read32be(Ptr + 2);
+}
+
+#define GETVALUEWITHMASK(X) (Data & (TracebackTable::X))
+#define GETVALUEWITHMASKSHIFT(X, S) \
+ ((Data & (TracebackTable::X)) >> (TracebackTable::S))
+uint8_t TBVectorExt::getNumberOfVRSaved() const {
+ return GETVALUEWITHMASKSHIFT(NumberOfVRSavedMask, NumberOfVRSavedShift);
+}
+
+bool TBVectorExt::isVRSavedOnStack() const {
+ return GETVALUEWITHMASK(IsVRSavedOnStackMask);
+}
+
+bool TBVectorExt::hasVarArgs() const {
+ return GETVALUEWITHMASK(HasVarArgsMask);
+}
+uint8_t TBVectorExt::getNumberOfVectorParms() const {
+ return GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask,
+ NumberOfVectorParmsShift);
+}
+
+bool TBVectorExt::hasVMXInstruction() const {
+ return GETVALUEWITHMASK(HasVMXInstructionMask);
+}
+#undef GETVALUEWITHMASK
+#undef GETVALUEWITHMASKSHIFT
+
+SmallString<32> TBVectorExt::getVectorParmsInfoString() const {
+ SmallString<32> ParmsType;
+ uint32_t Value = VecParmsInfo;
+ for (uint8_t I = 0; I < getNumberOfVectorParms(); ++I) {
+ if (I != 0)
+ ParmsType += ", ";
+ switch (Value & TracebackTable::ParmTypeMask) {
+ case TracebackTable::ParmTypeIsVectorCharBit:
+ ParmsType += "vc";
+ break;
+
+ case TracebackTable::ParmTypeIsVectorShortBit:
+ ParmsType += "vs";
+ break;
+
+ case TracebackTable::ParmTypeIsVectorIntBit:
+ ParmsType += "vi";
+ break;
+
+ case TracebackTable::ParmTypeIsVectorFloatBit:
+ ParmsType += "vf";
+ break;
+ }
+ Value <<= 2;
+ }
+ return ParmsType;
+}
+
+static SmallString<32> parseParmsTypeWithVecInfo(uint32_t Value,
+ unsigned int ParmsNum) {
+ SmallString<32> ParmsType;
+ unsigned I = 0;
+ bool Begin = false;
+ while (I < ParmsNum || Value) {
+ if (Begin)
+ ParmsType += ", ";
+ else
+ Begin = true;
+
+ switch (Value & TracebackTable::ParmTypeMask) {
+ case TracebackTable::ParmTypeIsFixedBits:
+ ParmsType += "i";
+ ++I;
+ break;
+ case TracebackTable::ParmTypeIsVectorBits:
+ ParmsType += "v";
+ break;
+ case TracebackTable::ParmTypeIsFloatingBits:
+ ParmsType += "f";
+ ++I;
+ break;
+ case TracebackTable::ParmTypeIsDoubleBits:
+ ParmsType += "d";
+ ++I;
+ break;
+ default:
+ assert(false && "Unrecognized bits in ParmsType.");
+ }
+ Value <<= 2;
+ }
+ assert(I == ParmsNum &&
+ "The total parameters number of fixed-point or floating-point "
+ "parameters not equal to the number in the parameter type!");
+ return ParmsType;
+}
+
+Expected<XCOFFTracebackTable> XCOFFTracebackTable::create(const uint8_t *Ptr,
+ uint64_t &Size) {
+ Error Err = Error::success();
+ XCOFFTracebackTable TBT(Ptr, Size, Err);
+ if (Err)
+ return std::move(Err);
+ return TBT;
+}
+
+XCOFFTracebackTable::XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size,
+ Error &Err)
+ : TBPtr(Ptr) {
+ ErrorAsOutParameter EAO(&Err);
+ DataExtractor DE(ArrayRef<uint8_t>(Ptr, Size), /*IsLittleEndian=*/false,
+ /*AddressSize=*/0);
+ DataExtractor::Cursor Cur(/*Offset=*/0);
+
+ // Skip 8 bytes of mandatory fields.
+ DE.getU64(Cur);
+
+ // Begin to parse optional fields.
+ if (Cur) {
+ unsigned ParmNum = getNumberOfFixedParms() + getNumberOfFPParms();
+
+ // As long as there are no "fixed-point" or floating-point parameters, this
+ // field remains not present even when hasVectorInfo gives true and
+ // indicates the presence of vector parameters.
+ if (ParmNum > 0) {
+ uint32_t ParamsTypeValue = DE.getU32(Cur);
+ if (Cur)
+ ParmsType = hasVectorInfo()
+ ? parseParmsTypeWithVecInfo(ParamsTypeValue, ParmNum)
+ : parseParmsType(ParamsTypeValue, ParmNum);
+ }
+ }
+
+ if (Cur && hasTraceBackTableOffset())
+ TraceBackTableOffset = DE.getU32(Cur);
+
+ if (Cur && isInterruptHandler())
+ HandlerMask = DE.getU32(Cur);
+
+ if (Cur && hasControlledStorage()) {
+ NumOfCtlAnchors = DE.getU32(Cur);
+ if (Cur && NumOfCtlAnchors) {
+ SmallVector<uint32_t, 8> Disp;
+ Disp.reserve(NumOfCtlAnchors.getValue());
+ for (uint32_t I = 0; I < NumOfCtlAnchors && Cur; ++I)
+ Disp.push_back(DE.getU32(Cur));
+ if (Cur)
+ ControlledStorageInfoDisp = std::move(Disp);
+ }
+ }
+
+ if (Cur && isFuncNamePresent()) {
+ uint16_t FunctionNameLen = DE.getU16(Cur);
+ if (Cur)
+ FunctionName = DE.getBytes(Cur, FunctionNameLen);
+ }
+
+ if (Cur && isAllocaUsed())
+ AllocaRegister = DE.getU8(Cur);
+
+ if (Cur && hasVectorInfo()) {
+ StringRef VectorExtRef = DE.getBytes(Cur, 6);
+ if (Cur)
+ VecExt = TBVectorExt(VectorExtRef);
+ }
+
+ if (Cur && hasExtensionTable())
+ ExtensionTable = DE.getU8(Cur);
+
+ if (!Cur)
+ Err = Cur.takeError();
+ Size = Cur.tell();
+}
+
+#define GETBITWITHMASK(P, X) \
+ (support::endian::read32be(TBPtr + (P)) & (TracebackTable::X))
+#define GETBITWITHMASKSHIFT(P, X, S) \
+ ((support::endian::read32be(TBPtr + (P)) & (TracebackTable::X)) >> \
+ (TracebackTable::S))
+
+uint8_t XCOFFTracebackTable::getVersion() const {
+ return GETBITWITHMASKSHIFT(0, VersionMask, VersionShift);
+}
+
+uint8_t XCOFFTracebackTable::getLanguageID() const {
+ return GETBITWITHMASKSHIFT(0, LanguageIdMask, LanguageIdShift);
+}
+
+bool XCOFFTracebackTable::isGlobalLinkage() const {
+ return GETBITWITHMASK(0, IsGlobaLinkageMask);
+}
+
+bool XCOFFTracebackTable::isOutOfLineEpilogOrPrologue() const {
+ return GETBITWITHMASK(0, IsOutOfLineEpilogOrPrologueMask);
+}
+
+bool XCOFFTracebackTable::hasTraceBackTableOffset() const {
+ return GETBITWITHMASK(0, HasTraceBackTableOffsetMask);
+}
+
+bool XCOFFTracebackTable::isInternalProcedure() const {
+ return GETBITWITHMASK(0, IsInternalProcedureMask);
+}
+
+bool XCOFFTracebackTable::hasControlledStorage() const {
+ return GETBITWITHMASK(0, HasControlledStorageMask);
+}
+
+bool XCOFFTracebackTable::isTOCless() const {
+ return GETBITWITHMASK(0, IsTOClessMask);
+}
+
+bool XCOFFTracebackTable::isFloatingPointPresent() const {
+ return GETBITWITHMASK(0, IsFloatingPointPresentMask);
+}
+
+bool XCOFFTracebackTable::isFloatingPointOperationLogOrAbortEnabled() const {
+ return GETBITWITHMASK(0, IsFloatingPointOperationLogOrAbortEnabledMask);
+}
+
+bool XCOFFTracebackTable::isInterruptHandler() const {
+ return GETBITWITHMASK(0, IsInterruptHandlerMask);
+}
+
+bool XCOFFTracebackTable::isFuncNamePresent() const {
+ return GETBITWITHMASK(0, IsFunctionNamePresentMask);
+}
+
+bool XCOFFTracebackTable::isAllocaUsed() const {
+ return GETBITWITHMASK(0, IsAllocaUsedMask);
+}
+
+uint8_t XCOFFTracebackTable::getOnConditionDirective() const {
+ return GETBITWITHMASKSHIFT(0, OnConditionDirectiveMask,
+ OnConditionDirectiveShift);
+}
+
+bool XCOFFTracebackTable::isCRSaved() const {
+ return GETBITWITHMASK(0, IsCRSavedMask);
+}
+
+bool XCOFFTracebackTable::isLRSaved() const {
+ return GETBITWITHMASK(0, IsLRSavedMask);
+}
+
+bool XCOFFTracebackTable::isBackChainStored() const {
+ return GETBITWITHMASK(4, IsBackChainStoredMask);
+}
+
+bool XCOFFTracebackTable::isFixup() const {
+ return GETBITWITHMASK(4, IsFixupMask);
+}
+
+uint8_t XCOFFTracebackTable::getNumOfFPRsSaved() const {
+ return GETBITWITHMASKSHIFT(4, FPRSavedMask, FPRSavedShift);
+}
+
+bool XCOFFTracebackTable::hasExtensionTable() const {
+ return GETBITWITHMASK(4, HasExtensionTableMask);
+}
+
+bool XCOFFTracebackTable::hasVectorInfo() const {
+ return GETBITWITHMASK(4, HasVectorInfoMask);
+}
+
+uint8_t XCOFFTracebackTable::getNumOfGPRsSaved() const {
+ return GETBITWITHMASKSHIFT(4, GPRSavedMask, GPRSavedShift);
+}
+
+uint8_t XCOFFTracebackTable::getNumberOfFixedParms() const {
+ return GETBITWITHMASKSHIFT(4, NumberOfFixedParmsMask,
+ NumberOfFixedParmsShift);
+}
+
+uint8_t XCOFFTracebackTable::getNumberOfFPParms() const {
+ return GETBITWITHMASKSHIFT(4, NumberOfFloatingPointParmsMask,
+ NumberOfFloatingPointParmsShift);
+}
+
+bool XCOFFTracebackTable::hasParmsOnStack() const {
+ return GETBITWITHMASK(4, HasParmsOnStackMask);
+}
+
+#undef GETBITWITHMASK
+#undef GETBITWITHMASKSHIFT
} // namespace object
} // namespace llvm
diff --git a/contrib/libs/llvm12/lib/Object/ya.make b/contrib/libs/llvm12/lib/Object/ya.make
index 3d9da8deaa..3d746aaa36 100644
--- a/contrib/libs/llvm12/lib/Object/ya.make
+++ b/contrib/libs/llvm12/lib/Object/ya.make
@@ -12,15 +12,15 @@ LICENSE(Apache-2.0 WITH LLVM-exception)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
PEERDIR(
- contrib/libs/llvm12
- contrib/libs/llvm12/include
- contrib/libs/llvm12/lib/BinaryFormat
- contrib/libs/llvm12/lib/Bitcode/Reader
- contrib/libs/llvm12/lib/IR
- contrib/libs/llvm12/lib/MC
- contrib/libs/llvm12/lib/MC/MCParser
- contrib/libs/llvm12/lib/Support
- contrib/libs/llvm12/lib/TextAPI/MachO
+ contrib/libs/llvm12
+ contrib/libs/llvm12/include
+ contrib/libs/llvm12/lib/BinaryFormat
+ contrib/libs/llvm12/lib/Bitcode/Reader
+ contrib/libs/llvm12/lib/IR
+ contrib/libs/llvm12/lib/MC
+ contrib/libs/llvm12/lib/MC/MCParser
+ contrib/libs/llvm12/lib/Support
+ contrib/libs/llvm12/lib/TextAPI/MachO
)
ADDINCL(
@@ -46,7 +46,7 @@ SRCS(
IRSymtab.cpp
MachOObjectFile.cpp
MachOUniversal.cpp
- MachOUniversalWriter.cpp
+ MachOUniversalWriter.cpp
Minidump.cpp
ModuleSymbolTable.cpp
Object.cpp