diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/include/llvm/Object | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/include/llvm/Object')
15 files changed, 1097 insertions, 1097 deletions
diff --git a/contrib/libs/llvm12/include/llvm/Object/ArchiveWriter.h b/contrib/libs/llvm12/include/llvm/Object/ArchiveWriter.h index a2c582c480..f07fbede22 100644 --- a/contrib/libs/llvm12/include/llvm/Object/ArchiveWriter.h +++ b/contrib/libs/llvm12/include/llvm/Object/ArchiveWriter.h @@ -46,12 +46,12 @@ Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers, bool WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr); - -// writeArchiveToBuffer is similar to writeArchive but returns the Archive in a -// buffer instead of writing it out to a file. -Expected<std::unique_ptr<MemoryBuffer>> -writeArchiveToBuffer(ArrayRef<NewArchiveMember> NewMembers, bool WriteSymtab, - object::Archive::Kind Kind, bool Deterministic, bool Thin); + +// writeArchiveToBuffer is similar to writeArchive but returns the Archive in a +// buffer instead of writing it out to a file. +Expected<std::unique_ptr<MemoryBuffer>> +writeArchiveToBuffer(ArrayRef<NewArchiveMember> NewMembers, bool WriteSymtab, + object::Archive::Kind Kind, bool Deterministic, bool Thin); } #endif diff --git a/contrib/libs/llvm12/include/llvm/Object/Binary.h b/contrib/libs/llvm12/include/llvm/Object/Binary.h index 0b1ee8456b..70dc19e21b 100644 --- a/contrib/libs/llvm12/include/llvm/Object/Binary.h +++ b/contrib/libs/llvm12/include/llvm/Object/Binary.h @@ -98,8 +98,8 @@ public: Binary(const Binary &other) = delete; virtual ~Binary(); - virtual Error initContent() { return Error::success(); }; - + virtual Error initContent() { return Error::success(); }; + StringRef getData() const; StringRef getFileName() const; MemoryBufferRef getMemoryBufferRef() const; @@ -172,8 +172,8 @@ public: static Error checkOffset(MemoryBufferRef M, uintptr_t Addr, const uint64_t Size) { if (Addr + Size < Addr || Addr + Size < Size || - Addr + Size > reinterpret_cast<uintptr_t>(M.getBufferEnd()) || - Addr < reinterpret_cast<uintptr_t>(M.getBufferStart())) { + Addr + Size > reinterpret_cast<uintptr_t>(M.getBufferEnd()) || + Addr < reinterpret_cast<uintptr_t>(M.getBufferStart())) { return errorCodeToError(object_error::unexpected_eof); } return Error::success(); @@ -187,8 +187,8 @@ DEFINE_ISA_CONVERSION_FUNCTIONS(Binary, LLVMBinaryRef) /// /// @param Source The data to create the Binary from. Expected<std::unique_ptr<Binary>> createBinary(MemoryBufferRef Source, - LLVMContext *Context = nullptr, - bool InitContent = true); + LLVMContext *Context = nullptr, + bool InitContent = true); template <typename T> class OwningBinary { std::unique_ptr<T> Bin; @@ -238,9 +238,9 @@ template <typename T> const T* OwningBinary<T>::getBinary() const { return Bin.get(); } -Expected<OwningBinary<Binary>> createBinary(StringRef Path, - LLVMContext *Context = nullptr, - bool InitContent = true); +Expected<OwningBinary<Binary>> createBinary(StringRef Path, + LLVMContext *Context = nullptr, + bool InitContent = true); } // end namespace object diff --git a/contrib/libs/llvm12/include/llvm/Object/COFF.h b/contrib/libs/llvm12/include/llvm/Object/COFF.h index 816a078cfc..4c62889569 100644 --- a/contrib/libs/llvm12/include/llvm/Object/COFF.h +++ b/contrib/libs/llvm12/include/llvm/Object/COFF.h @@ -583,22 +583,22 @@ struct coff_tls_directory { uint32_t getAlignment() const { // Bit [20:24] contains section alignment. - uint32_t Shift = (Characteristics & COFF::IMAGE_SCN_ALIGN_MASK) >> 20; + uint32_t Shift = (Characteristics & COFF::IMAGE_SCN_ALIGN_MASK) >> 20; if (Shift > 0) return 1U << (Shift - 1); return 0; } - - void setAlignment(uint32_t Align) { - uint32_t AlignBits = 0; - if (Align) { - assert(llvm::isPowerOf2_32(Align) && "alignment is not a power of 2"); - assert(llvm::Log2_32(Align) <= 13 && "alignment requested is too large"); - AlignBits = (llvm::Log2_32(Align) + 1) << 20; - } - Characteristics = - (Characteristics & ~COFF::IMAGE_SCN_ALIGN_MASK) | AlignBits; - } + + void setAlignment(uint32_t Align) { + uint32_t AlignBits = 0; + if (Align) { + assert(llvm::isPowerOf2_32(Align) && "alignment is not a power of 2"); + assert(llvm::Log2_32(Align) <= 13 && "alignment requested is too large"); + AlignBits = (llvm::Log2_32(Align) + 1) << 20; + } + Characteristics = + (Characteristics & ~COFF::IMAGE_SCN_ALIGN_MASK) | AlignBits; + } }; using coff_tls_directory32 = coff_tls_directory<support::little32_t>; @@ -804,8 +804,8 @@ private: const coff_base_reloc_block_header *BaseRelocEnd; const debug_directory *DebugDirectoryBegin; const debug_directory *DebugDirectoryEnd; - const coff_tls_directory32 *TLSDirectory32; - const coff_tls_directory64 *TLSDirectory64; + const coff_tls_directory32 *TLSDirectory32; + const coff_tls_directory64 *TLSDirectory64; // Either coff_load_configuration32 or coff_load_configuration64. const void *LoadConfig = nullptr; @@ -825,7 +825,7 @@ private: Error initExportTablePtr(); Error initBaseRelocPtr(); Error initDebugDirectoryPtr(); - Error initTLSDirectoryPtr(); + Error initTLSDirectoryPtr(); Error initLoadConfigPtr(); public: @@ -997,13 +997,13 @@ public: return make_range(debug_directory_begin(), debug_directory_end()); } - const coff_tls_directory32 *getTLSDirectory32() const { - return TLSDirectory32; - } - const coff_tls_directory64 *getTLSDirectory64() const { - return TLSDirectory64; - } - + const coff_tls_directory32 *getTLSDirectory32() const { + return TLSDirectory32; + } + const coff_tls_directory64 *getTLSDirectory64() const { + return TLSDirectory64; + } + const dos_header *getDOSHeader() const { if (!PE32Header && !PE32PlusHeader) return nullptr; diff --git a/contrib/libs/llvm12/include/llvm/Object/ELF.h b/contrib/libs/llvm12/include/llvm/Object/ELF.h index 20e25a9ee2..e68397b898 100644 --- a/contrib/libs/llvm12/include/llvm/Object/ELF.h +++ b/contrib/libs/llvm12/include/llvm/Object/ELF.h @@ -37,43 +37,43 @@ namespace llvm { namespace object { -struct VerdAux { - unsigned Offset; - std::string Name; -}; - -struct VerDef { - unsigned Offset; - unsigned Version; - unsigned Flags; - unsigned Ndx; - unsigned Cnt; - unsigned Hash; - std::string Name; - std::vector<VerdAux> AuxV; -}; - -struct VernAux { - unsigned Hash; - unsigned Flags; - unsigned Other; - unsigned Offset; - std::string Name; -}; - -struct VerNeed { - unsigned Version; - unsigned Cnt; - unsigned Offset; - std::string File; - std::vector<VernAux> AuxV; -}; - -struct VersionEntry { - std::string Name; - bool IsVerDef; -}; - +struct VerdAux { + unsigned Offset; + std::string Name; +}; + +struct VerDef { + unsigned Offset; + unsigned Version; + unsigned Flags; + unsigned Ndx; + unsigned Cnt; + unsigned Hash; + std::string Name; + std::vector<VerdAux> AuxV; +}; + +struct VernAux { + unsigned Hash; + unsigned Flags; + unsigned Other; + unsigned Offset; + std::string Name; +}; + +struct VerNeed { + unsigned Version; + unsigned Cnt; + unsigned Offset; + std::string File; + std::vector<VernAux> AuxV; +}; + +struct VersionEntry { + std::string Name; + bool IsVerDef; +}; + StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type); uint32_t getELFRelativeRelocationType(uint32_t Machine); StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type); @@ -92,51 +92,51 @@ static inline Error createError(const Twine &Err) { return make_error<StringError>(Err, object_error::parse_failed); } -enum PPCInstrMasks : uint64_t { - PADDI_R12_NO_DISP = 0x0610000039800000, - PLD_R12_NO_DISP = 0x04100000E5800000, - MTCTR_R12 = 0x7D8903A6, - BCTR = 0x4E800420, -}; - +enum PPCInstrMasks : uint64_t { + PADDI_R12_NO_DISP = 0x0610000039800000, + PLD_R12_NO_DISP = 0x04100000E5800000, + MTCTR_R12 = 0x7D8903A6, + BCTR = 0x4E800420, +}; + template <class ELFT> class ELFFile; -template <class T> struct DataRegion { - // This constructor is used when we know the start and the size of a data - // region. We assume that Arr does not go past the end of the file. - DataRegion(ArrayRef<T> Arr) : First(Arr.data()), Size(Arr.size()) {} - - // Sometimes we only know the start of a data region. We still don't want to - // read past the end of the file, so we provide the end of a buffer. - DataRegion(const T *Data, const uint8_t *BufferEnd) - : First(Data), BufEnd(BufferEnd) {} - - Expected<T> operator[](uint64_t N) { - assert(Size || BufEnd); - if (Size) { - if (N >= *Size) - return createError( - "the index is greater than or equal to the number of entries (" + - Twine(*Size) + ")"); - } else { - const uint8_t *EntryStart = (const uint8_t *)First + N * sizeof(T); - if (EntryStart + sizeof(T) > BufEnd) - return createError("can't read past the end of the file"); - } - return *(First + N); - } - - const T *First; - Optional<uint64_t> Size = None; - const uint8_t *BufEnd = nullptr; -}; - +template <class T> struct DataRegion { + // This constructor is used when we know the start and the size of a data + // region. We assume that Arr does not go past the end of the file. + DataRegion(ArrayRef<T> Arr) : First(Arr.data()), Size(Arr.size()) {} + + // Sometimes we only know the start of a data region. We still don't want to + // read past the end of the file, so we provide the end of a buffer. + DataRegion(const T *Data, const uint8_t *BufferEnd) + : First(Data), BufEnd(BufferEnd) {} + + Expected<T> operator[](uint64_t N) { + assert(Size || BufEnd); + if (Size) { + if (N >= *Size) + return createError( + "the index is greater than or equal to the number of entries (" + + Twine(*Size) + ")"); + } else { + const uint8_t *EntryStart = (const uint8_t *)First + N * sizeof(T); + if (EntryStart + sizeof(T) > BufEnd) + return createError("can't read past the end of the file"); + } + return *(First + N); + } + + const T *First; + Optional<uint64_t> Size = None; + const uint8_t *BufEnd = nullptr; +}; + template <class ELFT> -std::string getSecIndexForError(const ELFFile<ELFT> &Obj, - const typename ELFT::Shdr &Sec) { - auto TableOrErr = Obj.sections(); +std::string getSecIndexForError(const ELFFile<ELFT> &Obj, + const typename ELFT::Shdr &Sec) { + auto TableOrErr = Obj.sections(); if (TableOrErr) - return "[index " + std::to_string(&Sec - &TableOrErr->front()) + "]"; + return "[index " + std::to_string(&Sec - &TableOrErr->front()) + "]"; // To make this helper be more convenient for error reporting purposes we // drop the error. But really it should never be triggered. Before this point, // our code should have called 'sections()' and reported a proper error on @@ -146,21 +146,21 @@ std::string getSecIndexForError(const ELFFile<ELFT> &Obj, } template <class ELFT> -static std::string describe(const ELFFile<ELFT> &Obj, - const typename ELFT::Shdr &Sec) { - unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front(); - return (object::getELFSectionTypeName(Obj.getHeader().e_machine, - Sec.sh_type) + - " section with index " + Twine(SecNdx)) - .str(); -} - -template <class ELFT> -std::string getPhdrIndexForError(const ELFFile<ELFT> &Obj, - const typename ELFT::Phdr &Phdr) { - auto Headers = Obj.program_headers(); +static std::string describe(const ELFFile<ELFT> &Obj, + const typename ELFT::Shdr &Sec) { + unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front(); + return (object::getELFSectionTypeName(Obj.getHeader().e_machine, + Sec.sh_type) + + " section with index " + Twine(SecNdx)) + .str(); +} + +template <class ELFT> +std::string getPhdrIndexForError(const ELFFile<ELFT> &Obj, + const typename ELFT::Phdr &Phdr) { + auto Headers = Obj.program_headers(); if (Headers) - return ("[index " + Twine(&Phdr - &Headers->front()) + "]").str(); + return ("[index " + Twine(&Phdr - &Headers->front()) + "]").str(); // See comment in the getSecIndexForError() above. llvm::consumeError(Headers.takeError()); return "[unknown index]"; @@ -183,7 +183,7 @@ public: using WarningHandler = llvm::function_ref<Error(const Twine &Msg)>; const uint8_t *base() const { return Buf.bytes_begin(); } - const uint8_t *end() const { return base() + getBufSize(); } + const uint8_t *end() const { return base() + getBufSize(); } size_t getBufSize() const { return Buf.size(); } @@ -193,39 +193,39 @@ private: ELFFile(StringRef Object); public: - const Elf_Ehdr &getHeader() const { - return *reinterpret_cast<const Elf_Ehdr *>(base()); + const Elf_Ehdr &getHeader() const { + return *reinterpret_cast<const Elf_Ehdr *>(base()); } template <typename T> Expected<const T *> getEntry(uint32_t Section, uint32_t Entry) const; template <typename T> - Expected<const T *> getEntry(const Elf_Shdr &Section, uint32_t Entry) const; + Expected<const T *> getEntry(const Elf_Shdr &Section, uint32_t Entry) const; - Expected<std::vector<VerDef>> - getVersionDefinitions(const Elf_Shdr &Sec) const; - Expected<std::vector<VerNeed>> getVersionDependencies( - const Elf_Shdr &Sec, - WarningHandler WarnHandler = &defaultWarningHandler) const; + Expected<std::vector<VerDef>> + getVersionDefinitions(const Elf_Shdr &Sec) const; + Expected<std::vector<VerNeed>> getVersionDependencies( + const Elf_Shdr &Sec, + WarningHandler WarnHandler = &defaultWarningHandler) const; Expected<StringRef> - getSymbolVersionByIndex(uint32_t SymbolVersionIndex, bool &IsDefault, - SmallVector<Optional<VersionEntry>, 0> &VersionMap, - Optional<bool> IsSymHidden) const; - - Expected<StringRef> - getStringTable(const Elf_Shdr &Section, + getSymbolVersionByIndex(uint32_t SymbolVersionIndex, bool &IsDefault, + SmallVector<Optional<VersionEntry>, 0> &VersionMap, + Optional<bool> IsSymHidden) const; + + Expected<StringRef> + getStringTable(const Elf_Shdr &Section, WarningHandler WarnHandler = &defaultWarningHandler) const; Expected<StringRef> getStringTableForSymtab(const Elf_Shdr &Section) const; Expected<StringRef> getStringTableForSymtab(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const; - Expected<StringRef> getLinkAsStrtab(const typename ELFT::Shdr &Sec) const; + Expected<StringRef> getLinkAsStrtab(const typename ELFT::Shdr &Sec) const; Expected<ArrayRef<Elf_Word>> getSHNDXTable(const Elf_Shdr &Section) const; Expected<ArrayRef<Elf_Word>> getSHNDXTable(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const; - Expected<uint64_t> getDynSymtabSize() const; - + Expected<uint64_t> getDynSymtabSize() const; + StringRef getRelocationTypeName(uint32_t Type) const; void getRelocationTypeName(uint32_t Type, SmallVectorImpl<char> &Result) const; @@ -235,21 +235,21 @@ public: std::string getDynamicTagAsString(uint64_t Type) const; /// Get the symbol for a given relocation. - Expected<const Elf_Sym *> getRelocationSymbol(const Elf_Rel &Rel, + Expected<const Elf_Sym *> getRelocationSymbol(const Elf_Rel &Rel, const Elf_Shdr *SymTab) const; - Expected<SmallVector<Optional<VersionEntry>, 0>> - loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const; - + Expected<SmallVector<Optional<VersionEntry>, 0>> + loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const; + static Expected<ELFFile> create(StringRef Object); bool isLE() const { - return getHeader().getDataEncoding() == ELF::ELFDATA2LSB; + return getHeader().getDataEncoding() == ELF::ELFDATA2LSB; } bool isMipsELF64() const { - return getHeader().e_machine == ELF::EM_MIPS && - getHeader().getFileClass() == ELF::ELFCLASS64; + return getHeader().e_machine == ELF::EM_MIPS && + getHeader().getFileClass() == ELF::ELFCLASS64; } bool isMips64EL() const { return isMipsELF64() && isLE(); } @@ -258,50 +258,50 @@ public: Expected<Elf_Dyn_Range> dynamicEntries() const; - Expected<const uint8_t *> - toMappedAddr(uint64_t VAddr, - WarningHandler WarnHandler = &defaultWarningHandler) const; + Expected<const uint8_t *> + toMappedAddr(uint64_t VAddr, + WarningHandler WarnHandler = &defaultWarningHandler) const; Expected<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const { if (!Sec) return makeArrayRef<Elf_Sym>(nullptr, nullptr); - return getSectionContentsAsArray<Elf_Sym>(*Sec); + return getSectionContentsAsArray<Elf_Sym>(*Sec); } - Expected<Elf_Rela_Range> relas(const Elf_Shdr &Sec) const { + Expected<Elf_Rela_Range> relas(const Elf_Shdr &Sec) const { return getSectionContentsAsArray<Elf_Rela>(Sec); } - Expected<Elf_Rel_Range> rels(const Elf_Shdr &Sec) const { + Expected<Elf_Rel_Range> rels(const Elf_Shdr &Sec) const { return getSectionContentsAsArray<Elf_Rel>(Sec); } - Expected<Elf_Relr_Range> relrs(const Elf_Shdr &Sec) const { + Expected<Elf_Relr_Range> relrs(const Elf_Shdr &Sec) const { return getSectionContentsAsArray<Elf_Relr>(Sec); } - std::vector<Elf_Rel> decode_relrs(Elf_Relr_Range relrs) const; + std::vector<Elf_Rel> decode_relrs(Elf_Relr_Range relrs) const; - Expected<std::vector<Elf_Rela>> android_relas(const Elf_Shdr &Sec) const; + Expected<std::vector<Elf_Rela>> android_relas(const Elf_Shdr &Sec) const; /// Iterate over program header table. Expected<Elf_Phdr_Range> program_headers() const { - if (getHeader().e_phnum && getHeader().e_phentsize != sizeof(Elf_Phdr)) + if (getHeader().e_phnum && getHeader().e_phentsize != sizeof(Elf_Phdr)) return createError("invalid e_phentsize: " + - Twine(getHeader().e_phentsize)); + Twine(getHeader().e_phentsize)); uint64_t HeadersSize = - (uint64_t)getHeader().e_phnum * getHeader().e_phentsize; - uint64_t PhOff = getHeader().e_phoff; + (uint64_t)getHeader().e_phnum * getHeader().e_phentsize; + uint64_t PhOff = getHeader().e_phoff; if (PhOff + HeadersSize < PhOff || PhOff + HeadersSize > getBufSize()) return createError("program headers are longer than binary of size " + Twine(getBufSize()) + ": e_phoff = 0x" + - Twine::utohexstr(getHeader().e_phoff) + - ", e_phnum = " + Twine(getHeader().e_phnum) + - ", e_phentsize = " + Twine(getHeader().e_phentsize)); + Twine::utohexstr(getHeader().e_phoff) + + ", e_phnum = " + Twine(getHeader().e_phnum) + + ", e_phentsize = " + Twine(getHeader().e_phentsize)); auto *Begin = reinterpret_cast<const Elf_Phdr *>(base() + PhOff); - return makeArrayRef(Begin, Begin + getHeader().e_phnum); + return makeArrayRef(Begin, Begin + getHeader().e_phnum); } /// Get an iterator over notes in a program header. @@ -315,9 +315,9 @@ public: assert(Phdr.p_type == ELF::PT_NOTE && "Phdr is not of type PT_NOTE"); ErrorAsOutParameter ErrAsOutParam(&Err); if (Phdr.p_offset + Phdr.p_filesz > getBufSize()) { - Err = - createError("invalid offset (0x" + Twine::utohexstr(Phdr.p_offset) + - ") or size (0x" + Twine::utohexstr(Phdr.p_filesz) + ")"); + Err = + createError("invalid offset (0x" + Twine::utohexstr(Phdr.p_offset) + + ") or size (0x" + Twine::utohexstr(Phdr.p_filesz) + ")"); return Elf_Note_Iterator(Err); } return Elf_Note_Iterator(base() + Phdr.p_offset, Phdr.p_filesz, Err); @@ -334,9 +334,9 @@ public: assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE"); ErrorAsOutParameter ErrAsOutParam(&Err); if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) { - Err = - createError("invalid offset (0x" + Twine::utohexstr(Shdr.sh_offset) + - ") or size (0x" + Twine::utohexstr(Shdr.sh_size) + ")"); + Err = + createError("invalid offset (0x" + Twine::utohexstr(Shdr.sh_offset) + + ") or size (0x" + Twine::utohexstr(Shdr.sh_size) + ")"); return Elf_Note_Iterator(Err); } return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size, Err); @@ -374,28 +374,28 @@ public: Expected<StringRef> getSectionStringTable( Elf_Shdr_Range Sections, WarningHandler WarnHandler = &defaultWarningHandler) const; - Expected<uint32_t> getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, - DataRegion<Elf_Word> ShndxTable) const; - Expected<const Elf_Shdr *> getSection(const Elf_Sym &Sym, + Expected<uint32_t> getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, + DataRegion<Elf_Word> ShndxTable) const; + Expected<const Elf_Shdr *> getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, - DataRegion<Elf_Word> ShndxTable) const; - Expected<const Elf_Shdr *> getSection(const Elf_Sym &Sym, + DataRegion<Elf_Word> ShndxTable) const; + Expected<const Elf_Shdr *> getSection(const Elf_Sym &Sym, Elf_Sym_Range Symtab, - DataRegion<Elf_Word> ShndxTable) const; + DataRegion<Elf_Word> ShndxTable) const; Expected<const Elf_Shdr *> getSection(uint32_t Index) const; Expected<const Elf_Sym *> getSymbol(const Elf_Shdr *Sec, uint32_t Index) const; Expected<StringRef> - getSectionName(const Elf_Shdr &Section, + getSectionName(const Elf_Shdr &Section, WarningHandler WarnHandler = &defaultWarningHandler) const; - Expected<StringRef> getSectionName(const Elf_Shdr &Section, + Expected<StringRef> getSectionName(const Elf_Shdr &Section, StringRef DotShstrtab) const; template <typename T> - Expected<ArrayRef<T>> getSectionContentsAsArray(const Elf_Shdr &Sec) const; - Expected<ArrayRef<uint8_t>> getSectionContents(const Elf_Shdr &Sec) const; - Expected<ArrayRef<uint8_t>> getSegmentContents(const Elf_Phdr &Phdr) const; + Expected<ArrayRef<T>> getSectionContentsAsArray(const Elf_Shdr &Sec) const; + Expected<ArrayRef<uint8_t>> getSectionContents(const Elf_Shdr &Sec) const; + Expected<ArrayRef<uint8_t>> getSegmentContents(const Elf_Phdr &Phdr) const; }; using ELF32LEFile = ELFFile<ELF32LE>; @@ -413,30 +413,30 @@ getSection(typename ELFT::ShdrRange Sections, uint32_t Index) { template <class ELFT> inline Expected<uint32_t> -getExtendedSymbolTableIndex(const typename ELFT::Sym &Sym, unsigned SymIndex, - DataRegion<typename ELFT::Word> ShndxTable) { - assert(Sym.st_shndx == ELF::SHN_XINDEX); - if (!ShndxTable.First) +getExtendedSymbolTableIndex(const typename ELFT::Sym &Sym, unsigned SymIndex, + DataRegion<typename ELFT::Word> ShndxTable) { + assert(Sym.st_shndx == ELF::SHN_XINDEX); + if (!ShndxTable.First) return createError( - "found an extended symbol index (" + Twine(SymIndex) + - "), but unable to locate the extended symbol index table"); - - Expected<typename ELFT::Word> TableOrErr = ShndxTable[SymIndex]; - if (!TableOrErr) - return createError("unable to read an extended symbol table at index " + - Twine(SymIndex) + ": " + - toString(TableOrErr.takeError())); - return *TableOrErr; + "found an extended symbol index (" + Twine(SymIndex) + + "), but unable to locate the extended symbol index table"); + + Expected<typename ELFT::Word> TableOrErr = ShndxTable[SymIndex]; + if (!TableOrErr) + return createError("unable to read an extended symbol table at index " + + Twine(SymIndex) + ": " + + toString(TableOrErr.takeError())); + return *TableOrErr; } template <class ELFT> Expected<uint32_t> -ELFFile<ELFT>::getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, - DataRegion<Elf_Word> ShndxTable) const { - uint32_t Index = Sym.st_shndx; +ELFFile<ELFT>::getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, + DataRegion<Elf_Word> ShndxTable) const { + uint32_t Index = Sym.st_shndx; if (Index == ELF::SHN_XINDEX) { - Expected<uint32_t> ErrorOrIndex = - getExtendedSymbolTableIndex<ELFT>(Sym, &Sym - Syms.begin(), ShndxTable); + Expected<uint32_t> ErrorOrIndex = + getExtendedSymbolTableIndex<ELFT>(Sym, &Sym - Syms.begin(), ShndxTable); if (!ErrorOrIndex) return ErrorOrIndex.takeError(); return *ErrorOrIndex; @@ -448,8 +448,8 @@ ELFFile<ELFT>::getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, template <class ELFT> Expected<const typename ELFT::Shdr *> -ELFFile<ELFT>::getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, - DataRegion<Elf_Word> ShndxTable) const { +ELFFile<ELFT>::getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, + DataRegion<Elf_Word> ShndxTable) const { auto SymsOrErr = symbols(SymTab); if (!SymsOrErr) return SymsOrErr.takeError(); @@ -458,8 +458,8 @@ ELFFile<ELFT>::getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, template <class ELFT> Expected<const typename ELFT::Shdr *> -ELFFile<ELFT>::getSection(const Elf_Sym &Sym, Elf_Sym_Range Symbols, - DataRegion<Elf_Word> ShndxTable) const { +ELFFile<ELFT>::getSection(const Elf_Sym &Sym, Elf_Sym_Range Symbols, + DataRegion<Elf_Word> ShndxTable) const { auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable); if (!IndexOrErr) return IndexOrErr.takeError(); @@ -479,7 +479,7 @@ ELFFile<ELFT>::getSymbol(const Elf_Shdr *Sec, uint32_t Index) const { Elf_Sym_Range Symbols = *SymsOrErr; if (Index >= Symbols.size()) return createError("unable to get symbol from section " + - getSecIndexForError(*this, *Sec) + + getSecIndexForError(*this, *Sec) + ": invalid symbol index (" + Twine(Index) + ")"); return &Symbols[Index]; } @@ -487,27 +487,27 @@ ELFFile<ELFT>::getSymbol(const Elf_Shdr *Sec, uint32_t Index) const { template <class ELFT> template <typename T> Expected<ArrayRef<T>> -ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr &Sec) const { - if (Sec.sh_entsize != sizeof(T) && sizeof(T) != 1) - return createError("section " + getSecIndexForError(*this, Sec) + - " has invalid sh_entsize: expected " + Twine(sizeof(T)) + - ", but got " + Twine(Sec.sh_entsize)); +ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr &Sec) const { + if (Sec.sh_entsize != sizeof(T) && sizeof(T) != 1) + return createError("section " + getSecIndexForError(*this, Sec) + + " has invalid sh_entsize: expected " + Twine(sizeof(T)) + + ", but got " + Twine(Sec.sh_entsize)); - uintX_t Offset = Sec.sh_offset; - uintX_t Size = Sec.sh_size; + uintX_t Offset = Sec.sh_offset; + uintX_t Size = Sec.sh_size; if (Size % sizeof(T)) - return createError("section " + getSecIndexForError(*this, Sec) + + return createError("section " + getSecIndexForError(*this, Sec) + " has an invalid sh_size (" + Twine(Size) + ") which is not a multiple of its sh_entsize (" + - Twine(Sec.sh_entsize) + ")"); + Twine(Sec.sh_entsize) + ")"); if (std::numeric_limits<uintX_t>::max() - Offset < Size) - return createError("section " + getSecIndexForError(*this, Sec) + + return createError("section " + getSecIndexForError(*this, Sec) + " has a sh_offset (0x" + Twine::utohexstr(Offset) + ") + sh_size (0x" + Twine::utohexstr(Size) + ") that cannot be represented"); if (Offset + Size > Buf.size()) - return createError("section " + getSecIndexForError(*this, Sec) + + return createError("section " + getSecIndexForError(*this, Sec) + " has a sh_offset (0x" + Twine::utohexstr(Offset) + ") + sh_size (0x" + Twine::utohexstr(Size) + ") that is greater than the file size (0x" + @@ -523,17 +523,17 @@ ELFFile<ELFT>::getSectionContentsAsArray(const Elf_Shdr &Sec) const { template <class ELFT> Expected<ArrayRef<uint8_t>> -ELFFile<ELFT>::getSegmentContents(const Elf_Phdr &Phdr) const { - uintX_t Offset = Phdr.p_offset; - uintX_t Size = Phdr.p_filesz; +ELFFile<ELFT>::getSegmentContents(const Elf_Phdr &Phdr) const { + uintX_t Offset = Phdr.p_offset; + uintX_t Size = Phdr.p_filesz; if (std::numeric_limits<uintX_t>::max() - Offset < Size) - return createError("program header " + getPhdrIndexForError(*this, Phdr) + + return createError("program header " + getPhdrIndexForError(*this, Phdr) + " has a p_offset (0x" + Twine::utohexstr(Offset) + ") + p_filesz (0x" + Twine::utohexstr(Size) + ") that cannot be represented"); if (Offset + Size > Buf.size()) - return createError("program header " + getPhdrIndexForError(*this, Phdr) + + return createError("program header " + getPhdrIndexForError(*this, Phdr) + " has a p_offset (0x" + Twine::utohexstr(Offset) + ") + p_filesz (0x" + Twine::utohexstr(Size) + ") that is greater than the file size (0x" + @@ -543,13 +543,13 @@ ELFFile<ELFT>::getSegmentContents(const Elf_Phdr &Phdr) const { template <class ELFT> Expected<ArrayRef<uint8_t>> -ELFFile<ELFT>::getSectionContents(const Elf_Shdr &Sec) const { +ELFFile<ELFT>::getSectionContents(const Elf_Shdr &Sec) const { return getSectionContentsAsArray<uint8_t>(Sec); } template <class ELFT> StringRef ELFFile<ELFT>::getRelocationTypeName(uint32_t Type) const { - return getELFRelocationTypeName(getHeader().e_machine, Type); + return getELFRelocationTypeName(getHeader().e_machine, Type); } template <class ELFT> @@ -585,61 +585,61 @@ void ELFFile<ELFT>::getRelocationTypeName(uint32_t Type, template <class ELFT> uint32_t ELFFile<ELFT>::getRelativeRelocationType() const { - return getELFRelativeRelocationType(getHeader().e_machine); -} - -template <class ELFT> -Expected<SmallVector<Optional<VersionEntry>, 0>> -ELFFile<ELFT>::loadVersionMap(const Elf_Shdr *VerNeedSec, - const Elf_Shdr *VerDefSec) const { - SmallVector<Optional<VersionEntry>, 0> VersionMap; - - // The first two version indexes are reserved. - // Index 0 is VER_NDX_LOCAL, index 1 is VER_NDX_GLOBAL. - VersionMap.push_back(VersionEntry()); - VersionMap.push_back(VersionEntry()); - - auto InsertEntry = [&](unsigned N, StringRef Version, bool IsVerdef) { - if (N >= VersionMap.size()) - VersionMap.resize(N + 1); - VersionMap[N] = {std::string(Version), IsVerdef}; - }; - - if (VerDefSec) { - Expected<std::vector<VerDef>> Defs = getVersionDefinitions(*VerDefSec); - if (!Defs) - return Defs.takeError(); - for (const VerDef &Def : *Defs) - InsertEntry(Def.Ndx & ELF::VERSYM_VERSION, Def.Name, true); - } - - if (VerNeedSec) { - Expected<std::vector<VerNeed>> Deps = getVersionDependencies(*VerNeedSec); - if (!Deps) - return Deps.takeError(); - for (const VerNeed &Dep : *Deps) - for (const VernAux &Aux : Dep.AuxV) - InsertEntry(Aux.Other & ELF::VERSYM_VERSION, Aux.Name, false); - } - - return VersionMap; + return getELFRelativeRelocationType(getHeader().e_machine); } template <class ELFT> +Expected<SmallVector<Optional<VersionEntry>, 0>> +ELFFile<ELFT>::loadVersionMap(const Elf_Shdr *VerNeedSec, + const Elf_Shdr *VerDefSec) const { + SmallVector<Optional<VersionEntry>, 0> VersionMap; + + // The first two version indexes are reserved. + // Index 0 is VER_NDX_LOCAL, index 1 is VER_NDX_GLOBAL. + VersionMap.push_back(VersionEntry()); + VersionMap.push_back(VersionEntry()); + + auto InsertEntry = [&](unsigned N, StringRef Version, bool IsVerdef) { + if (N >= VersionMap.size()) + VersionMap.resize(N + 1); + VersionMap[N] = {std::string(Version), IsVerdef}; + }; + + if (VerDefSec) { + Expected<std::vector<VerDef>> Defs = getVersionDefinitions(*VerDefSec); + if (!Defs) + return Defs.takeError(); + for (const VerDef &Def : *Defs) + InsertEntry(Def.Ndx & ELF::VERSYM_VERSION, Def.Name, true); + } + + if (VerNeedSec) { + Expected<std::vector<VerNeed>> Deps = getVersionDependencies(*VerNeedSec); + if (!Deps) + return Deps.takeError(); + for (const VerNeed &Dep : *Deps) + for (const VernAux &Aux : Dep.AuxV) + InsertEntry(Aux.Other & ELF::VERSYM_VERSION, Aux.Name, false); + } + + return VersionMap; +} + +template <class ELFT> Expected<const typename ELFT::Sym *> -ELFFile<ELFT>::getRelocationSymbol(const Elf_Rel &Rel, +ELFFile<ELFT>::getRelocationSymbol(const Elf_Rel &Rel, const Elf_Shdr *SymTab) const { - uint32_t Index = Rel.getSymbol(isMips64EL()); + uint32_t Index = Rel.getSymbol(isMips64EL()); if (Index == 0) return nullptr; - return getEntry<Elf_Sym>(*SymTab, Index); + return getEntry<Elf_Sym>(*SymTab, Index); } template <class ELFT> Expected<StringRef> ELFFile<ELFT>::getSectionStringTable(Elf_Shdr_Range Sections, WarningHandler WarnHandler) const { - uint32_t Index = getHeader().e_shstrndx; + uint32_t Index = getHeader().e_shstrndx; if (Index == ELF::SHN_XINDEX) { // If the section name string table section index is greater than // or equal to SHN_LORESERVE, then the actual index of the section name @@ -657,102 +657,102 @@ ELFFile<ELFT>::getSectionStringTable(Elf_Shdr_Range Sections, if (Index >= Sections.size()) return createError("section header string table index " + Twine(Index) + " does not exist"); - return getStringTable(Sections[Index], WarnHandler); -} - -/// This function finds the number of dynamic symbols using a GNU hash table. -/// -/// @param Table The GNU hash table for .dynsym. -template <class ELFT> -static Expected<uint64_t> -getDynSymtabSizeFromGnuHash(const typename ELFT::GnuHash &Table, - const void *BufEnd) { - using Elf_Word = typename ELFT::Word; - if (Table.nbuckets == 0) - return Table.symndx + 1; - uint64_t LastSymIdx = 0; - // Find the index of the first symbol in the last chain. - for (Elf_Word Val : Table.buckets()) - LastSymIdx = std::max(LastSymIdx, (uint64_t)Val); - const Elf_Word *It = - reinterpret_cast<const Elf_Word *>(Table.values(LastSymIdx).end()); - // Locate the end of the chain to find the last symbol index. - while (It < BufEnd && (*It & 1) == 0) { - ++LastSymIdx; - ++It; - } - if (It >= BufEnd) { - return createStringError( - object_error::parse_failed, - "no terminator found for GNU hash section before buffer end"); - } - return LastSymIdx + 1; -} - -/// This function determines the number of dynamic symbols. It reads section -/// headers first. If section headers are not available, the number of -/// symbols will be inferred by parsing dynamic hash tables. -template <class ELFT> -Expected<uint64_t> ELFFile<ELFT>::getDynSymtabSize() const { - // Read .dynsym section header first if available. - Expected<Elf_Shdr_Range> SectionsOrError = sections(); - if (!SectionsOrError) - return SectionsOrError.takeError(); - for (const Elf_Shdr &Sec : *SectionsOrError) { - if (Sec.sh_type == ELF::SHT_DYNSYM) { - if (Sec.sh_size % Sec.sh_entsize != 0) { - return createStringError(object_error::parse_failed, - "SHT_DYNSYM section has sh_size (" + - Twine(Sec.sh_size) + ") % sh_entsize (" + - Twine(Sec.sh_entsize) + ") that is not 0"); - } - return Sec.sh_size / Sec.sh_entsize; - } - } - - if (!SectionsOrError->empty()) { - // Section headers are available but .dynsym header is not found. - // Return 0 as .dynsym does not exist. - return 0; - } - - // Section headers do not exist. Falling back to infer - // upper bound of .dynsym from .gnu.hash and .hash. - Expected<Elf_Dyn_Range> DynTable = dynamicEntries(); - if (!DynTable) - return DynTable.takeError(); - llvm::Optional<uint64_t> ElfHash; - llvm::Optional<uint64_t> ElfGnuHash; - for (const Elf_Dyn &Entry : *DynTable) { - switch (Entry.d_tag) { - case ELF::DT_HASH: - ElfHash = Entry.d_un.d_ptr; - break; - case ELF::DT_GNU_HASH: - ElfGnuHash = Entry.d_un.d_ptr; - break; - } - } - if (ElfGnuHash) { - Expected<const uint8_t *> TablePtr = toMappedAddr(*ElfGnuHash); - if (!TablePtr) - return TablePtr.takeError(); - const Elf_GnuHash *Table = - reinterpret_cast<const Elf_GnuHash *>(TablePtr.get()); - return getDynSymtabSizeFromGnuHash<ELFT>(*Table, this->Buf.bytes_end()); - } - - // Search SYSV hash table to try to find the upper bound of dynsym. - if (ElfHash) { - Expected<const uint8_t *> TablePtr = toMappedAddr(*ElfHash); - if (!TablePtr) - return TablePtr.takeError(); - const Elf_Hash *Table = reinterpret_cast<const Elf_Hash *>(TablePtr.get()); - return Table->nchain; - } - return 0; + return getStringTable(Sections[Index], WarnHandler); } +/// This function finds the number of dynamic symbols using a GNU hash table. +/// +/// @param Table The GNU hash table for .dynsym. +template <class ELFT> +static Expected<uint64_t> +getDynSymtabSizeFromGnuHash(const typename ELFT::GnuHash &Table, + const void *BufEnd) { + using Elf_Word = typename ELFT::Word; + if (Table.nbuckets == 0) + return Table.symndx + 1; + uint64_t LastSymIdx = 0; + // Find the index of the first symbol in the last chain. + for (Elf_Word Val : Table.buckets()) + LastSymIdx = std::max(LastSymIdx, (uint64_t)Val); + const Elf_Word *It = + reinterpret_cast<const Elf_Word *>(Table.values(LastSymIdx).end()); + // Locate the end of the chain to find the last symbol index. + while (It < BufEnd && (*It & 1) == 0) { + ++LastSymIdx; + ++It; + } + if (It >= BufEnd) { + return createStringError( + object_error::parse_failed, + "no terminator found for GNU hash section before buffer end"); + } + return LastSymIdx + 1; +} + +/// This function determines the number of dynamic symbols. It reads section +/// headers first. If section headers are not available, the number of +/// symbols will be inferred by parsing dynamic hash tables. +template <class ELFT> +Expected<uint64_t> ELFFile<ELFT>::getDynSymtabSize() const { + // Read .dynsym section header first if available. + Expected<Elf_Shdr_Range> SectionsOrError = sections(); + if (!SectionsOrError) + return SectionsOrError.takeError(); + for (const Elf_Shdr &Sec : *SectionsOrError) { + if (Sec.sh_type == ELF::SHT_DYNSYM) { + if (Sec.sh_size % Sec.sh_entsize != 0) { + return createStringError(object_error::parse_failed, + "SHT_DYNSYM section has sh_size (" + + Twine(Sec.sh_size) + ") % sh_entsize (" + + Twine(Sec.sh_entsize) + ") that is not 0"); + } + return Sec.sh_size / Sec.sh_entsize; + } + } + + if (!SectionsOrError->empty()) { + // Section headers are available but .dynsym header is not found. + // Return 0 as .dynsym does not exist. + return 0; + } + + // Section headers do not exist. Falling back to infer + // upper bound of .dynsym from .gnu.hash and .hash. + Expected<Elf_Dyn_Range> DynTable = dynamicEntries(); + if (!DynTable) + return DynTable.takeError(); + llvm::Optional<uint64_t> ElfHash; + llvm::Optional<uint64_t> ElfGnuHash; + for (const Elf_Dyn &Entry : *DynTable) { + switch (Entry.d_tag) { + case ELF::DT_HASH: + ElfHash = Entry.d_un.d_ptr; + break; + case ELF::DT_GNU_HASH: + ElfGnuHash = Entry.d_un.d_ptr; + break; + } + } + if (ElfGnuHash) { + Expected<const uint8_t *> TablePtr = toMappedAddr(*ElfGnuHash); + if (!TablePtr) + return TablePtr.takeError(); + const Elf_GnuHash *Table = + reinterpret_cast<const Elf_GnuHash *>(TablePtr.get()); + return getDynSymtabSizeFromGnuHash<ELFT>(*Table, this->Buf.bytes_end()); + } + + // Search SYSV hash table to try to find the upper bound of dynsym. + if (ElfHash) { + Expected<const uint8_t *> TablePtr = toMappedAddr(*ElfHash); + if (!TablePtr) + return TablePtr.takeError(); + const Elf_Hash *Table = reinterpret_cast<const Elf_Hash *>(TablePtr.get()); + return Table->nchain; + } + return 0; +} + template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {} template <class ELFT> @@ -766,13 +766,13 @@ Expected<ELFFile<ELFT>> ELFFile<ELFT>::create(StringRef Object) { template <class ELFT> Expected<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const { - const uintX_t SectionTableOffset = getHeader().e_shoff; + const uintX_t SectionTableOffset = getHeader().e_shoff; if (SectionTableOffset == 0) return ArrayRef<Elf_Shdr>(); - if (getHeader().e_shentsize != sizeof(Elf_Shdr)) + if (getHeader().e_shentsize != sizeof(Elf_Shdr)) return createError("invalid e_shentsize in ELF header: " + - Twine(getHeader().e_shentsize)); + Twine(getHeader().e_shentsize)); const uint64_t FileSize = Buf.size(); if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize || @@ -789,7 +789,7 @@ Expected<typename ELFT::ShdrRange> ELFFile<ELFT>::sections() const { const Elf_Shdr *First = reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset); - uintX_t NumSections = getHeader().e_shnum; + uintX_t NumSections = getHeader().e_shnum; if (NumSections == 0) NumSections = First->sh_size; @@ -820,231 +820,231 @@ Expected<const T *> ELFFile<ELFT>::getEntry(uint32_t Section, auto SecOrErr = getSection(Section); if (!SecOrErr) return SecOrErr.takeError(); - return getEntry<T>(**SecOrErr, Entry); + return getEntry<T>(**SecOrErr, Entry); } template <class ELFT> template <typename T> -Expected<const T *> ELFFile<ELFT>::getEntry(const Elf_Shdr &Section, +Expected<const T *> ELFFile<ELFT>::getEntry(const Elf_Shdr &Section, uint32_t Entry) const { - Expected<ArrayRef<T>> EntriesOrErr = getSectionContentsAsArray<T>(Section); - if (!EntriesOrErr) - return EntriesOrErr.takeError(); - - ArrayRef<T> Arr = *EntriesOrErr; - if (Entry >= Arr.size()) - return createError( - "can't read an entry at 0x" + - Twine::utohexstr(Entry * static_cast<uint64_t>(sizeof(T))) + - ": it goes past the end of the section (0x" + - Twine::utohexstr(Section.sh_size) + ")"); - return &Arr[Entry]; -} - -template <typename ELFT> -Expected<StringRef> ELFFile<ELFT>::getSymbolVersionByIndex( - uint32_t SymbolVersionIndex, bool &IsDefault, - SmallVector<Optional<VersionEntry>, 0> &VersionMap, - Optional<bool> IsSymHidden) const { - size_t VersionIndex = SymbolVersionIndex & llvm::ELF::VERSYM_VERSION; - - // Special markers for unversioned symbols. - if (VersionIndex == llvm::ELF::VER_NDX_LOCAL || - VersionIndex == llvm::ELF::VER_NDX_GLOBAL) { - IsDefault = false; - return ""; - } - - // Lookup this symbol in the version table. - if (VersionIndex >= VersionMap.size() || !VersionMap[VersionIndex]) - return createError("SHT_GNU_versym section refers to a version index " + - Twine(VersionIndex) + " which is missing"); - - const VersionEntry &Entry = *VersionMap[VersionIndex]; - // A default version (@@) is only available for defined symbols. - if (!Entry.IsVerDef || IsSymHidden.getValueOr(false)) - IsDefault = false; - else - IsDefault = !(SymbolVersionIndex & llvm::ELF::VERSYM_HIDDEN); - return Entry.Name.c_str(); -} - -template <class ELFT> -Expected<std::vector<VerDef>> -ELFFile<ELFT>::getVersionDefinitions(const Elf_Shdr &Sec) const { - Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Sec); - if (!StrTabOrErr) - return StrTabOrErr.takeError(); - - Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec); - if (!ContentsOrErr) - return createError("cannot read content of " + describe(*this, Sec) + ": " + - toString(ContentsOrErr.takeError())); - - const uint8_t *Start = ContentsOrErr->data(); - const uint8_t *End = Start + ContentsOrErr->size(); - - auto ExtractNextAux = [&](const uint8_t *&VerdauxBuf, - unsigned VerDefNdx) -> Expected<VerdAux> { - if (VerdauxBuf + sizeof(Elf_Verdaux) > End) - return createError("invalid " + describe(*this, Sec) + - ": version definition " + Twine(VerDefNdx) + - " refers to an auxiliary entry that goes past the end " - "of the section"); - - auto *Verdaux = reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf); - VerdauxBuf += Verdaux->vda_next; - - VerdAux Aux; - Aux.Offset = VerdauxBuf - Start; - if (Verdaux->vda_name <= StrTabOrErr->size()) - Aux.Name = std::string(StrTabOrErr->drop_front(Verdaux->vda_name)); - else - Aux.Name = ("<invalid vda_name: " + Twine(Verdaux->vda_name) + ">").str(); - return Aux; - }; - - std::vector<VerDef> Ret; - const uint8_t *VerdefBuf = Start; - for (unsigned I = 1; I <= /*VerDefsNum=*/Sec.sh_info; ++I) { - if (VerdefBuf + sizeof(Elf_Verdef) > End) - return createError("invalid " + describe(*this, Sec) + - ": version definition " + Twine(I) + - " goes past the end of the section"); - - if (reinterpret_cast<uintptr_t>(VerdefBuf) % sizeof(uint32_t) != 0) - return createError( - "invalid " + describe(*this, Sec) + - ": found a misaligned version definition entry at offset 0x" + - Twine::utohexstr(VerdefBuf - Start)); - - unsigned Version = *reinterpret_cast<const Elf_Half *>(VerdefBuf); - if (Version != 1) - return createError("unable to dump " + describe(*this, Sec) + - ": version " + Twine(Version) + - " is not yet supported"); - - const Elf_Verdef *D = reinterpret_cast<const Elf_Verdef *>(VerdefBuf); - VerDef &VD = *Ret.emplace(Ret.end()); - VD.Offset = VerdefBuf - Start; - VD.Version = D->vd_version; - VD.Flags = D->vd_flags; - VD.Ndx = D->vd_ndx; - VD.Cnt = D->vd_cnt; - VD.Hash = D->vd_hash; - - const uint8_t *VerdauxBuf = VerdefBuf + D->vd_aux; - for (unsigned J = 0; J < D->vd_cnt; ++J) { - if (reinterpret_cast<uintptr_t>(VerdauxBuf) % sizeof(uint32_t) != 0) - return createError("invalid " + describe(*this, Sec) + - ": found a misaligned auxiliary entry at offset 0x" + - Twine::utohexstr(VerdauxBuf - Start)); - - Expected<VerdAux> AuxOrErr = ExtractNextAux(VerdauxBuf, I); - if (!AuxOrErr) - return AuxOrErr.takeError(); - - if (J == 0) - VD.Name = AuxOrErr->Name; - else - VD.AuxV.push_back(*AuxOrErr); - } - - VerdefBuf += D->vd_next; - } - - return Ret; -} - -template <class ELFT> -Expected<std::vector<VerNeed>> -ELFFile<ELFT>::getVersionDependencies(const Elf_Shdr &Sec, - WarningHandler WarnHandler) const { - StringRef StrTab; - Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Sec); - if (!StrTabOrErr) { - if (Error E = WarnHandler(toString(StrTabOrErr.takeError()))) - return std::move(E); - } else { - StrTab = *StrTabOrErr; - } - - Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec); - if (!ContentsOrErr) - return createError("cannot read content of " + describe(*this, Sec) + ": " + - toString(ContentsOrErr.takeError())); - - const uint8_t *Start = ContentsOrErr->data(); - const uint8_t *End = Start + ContentsOrErr->size(); - const uint8_t *VerneedBuf = Start; - - std::vector<VerNeed> Ret; - for (unsigned I = 1; I <= /*VerneedNum=*/Sec.sh_info; ++I) { - if (VerneedBuf + sizeof(Elf_Verdef) > End) - return createError("invalid " + describe(*this, Sec) + - ": version dependency " + Twine(I) + - " goes past the end of the section"); - - if (reinterpret_cast<uintptr_t>(VerneedBuf) % sizeof(uint32_t) != 0) - return createError( - "invalid " + describe(*this, Sec) + - ": found a misaligned version dependency entry at offset 0x" + - Twine::utohexstr(VerneedBuf - Start)); - - unsigned Version = *reinterpret_cast<const Elf_Half *>(VerneedBuf); - if (Version != 1) - return createError("unable to dump " + describe(*this, Sec) + - ": version " + Twine(Version) + - " is not yet supported"); - - const Elf_Verneed *Verneed = - reinterpret_cast<const Elf_Verneed *>(VerneedBuf); - - VerNeed &VN = *Ret.emplace(Ret.end()); - VN.Version = Verneed->vn_version; - VN.Cnt = Verneed->vn_cnt; - VN.Offset = VerneedBuf - Start; - - if (Verneed->vn_file < StrTab.size()) - VN.File = std::string(StrTab.drop_front(Verneed->vn_file)); - else - VN.File = ("<corrupt vn_file: " + Twine(Verneed->vn_file) + ">").str(); - - const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux; - for (unsigned J = 0; J < Verneed->vn_cnt; ++J) { - if (reinterpret_cast<uintptr_t>(VernauxBuf) % sizeof(uint32_t) != 0) - return createError("invalid " + describe(*this, Sec) + - ": found a misaligned auxiliary entry at offset 0x" + - Twine::utohexstr(VernauxBuf - Start)); - - if (VernauxBuf + sizeof(Elf_Vernaux) > End) - return createError( - "invalid " + describe(*this, Sec) + ": version dependency " + - Twine(I) + - " refers to an auxiliary entry that goes past the end " - "of the section"); - - const Elf_Vernaux *Vernaux = - reinterpret_cast<const Elf_Vernaux *>(VernauxBuf); - - VernAux &Aux = *VN.AuxV.emplace(VN.AuxV.end()); - Aux.Hash = Vernaux->vna_hash; - Aux.Flags = Vernaux->vna_flags; - Aux.Other = Vernaux->vna_other; - Aux.Offset = VernauxBuf - Start; - if (StrTab.size() <= Vernaux->vna_name) - Aux.Name = "<corrupt>"; - else - Aux.Name = std::string(StrTab.drop_front(Vernaux->vna_name)); - - VernauxBuf += Vernaux->vna_next; - } - VerneedBuf += Verneed->vn_next; - } - return Ret; + Expected<ArrayRef<T>> EntriesOrErr = getSectionContentsAsArray<T>(Section); + if (!EntriesOrErr) + return EntriesOrErr.takeError(); + + ArrayRef<T> Arr = *EntriesOrErr; + if (Entry >= Arr.size()) + return createError( + "can't read an entry at 0x" + + Twine::utohexstr(Entry * static_cast<uint64_t>(sizeof(T))) + + ": it goes past the end of the section (0x" + + Twine::utohexstr(Section.sh_size) + ")"); + return &Arr[Entry]; } +template <typename ELFT> +Expected<StringRef> ELFFile<ELFT>::getSymbolVersionByIndex( + uint32_t SymbolVersionIndex, bool &IsDefault, + SmallVector<Optional<VersionEntry>, 0> &VersionMap, + Optional<bool> IsSymHidden) const { + size_t VersionIndex = SymbolVersionIndex & llvm::ELF::VERSYM_VERSION; + + // Special markers for unversioned symbols. + if (VersionIndex == llvm::ELF::VER_NDX_LOCAL || + VersionIndex == llvm::ELF::VER_NDX_GLOBAL) { + IsDefault = false; + return ""; + } + + // Lookup this symbol in the version table. + if (VersionIndex >= VersionMap.size() || !VersionMap[VersionIndex]) + return createError("SHT_GNU_versym section refers to a version index " + + Twine(VersionIndex) + " which is missing"); + + const VersionEntry &Entry = *VersionMap[VersionIndex]; + // A default version (@@) is only available for defined symbols. + if (!Entry.IsVerDef || IsSymHidden.getValueOr(false)) + IsDefault = false; + else + IsDefault = !(SymbolVersionIndex & llvm::ELF::VERSYM_HIDDEN); + return Entry.Name.c_str(); +} + template <class ELFT> +Expected<std::vector<VerDef>> +ELFFile<ELFT>::getVersionDefinitions(const Elf_Shdr &Sec) const { + Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Sec); + if (!StrTabOrErr) + return StrTabOrErr.takeError(); + + Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec); + if (!ContentsOrErr) + return createError("cannot read content of " + describe(*this, Sec) + ": " + + toString(ContentsOrErr.takeError())); + + const uint8_t *Start = ContentsOrErr->data(); + const uint8_t *End = Start + ContentsOrErr->size(); + + auto ExtractNextAux = [&](const uint8_t *&VerdauxBuf, + unsigned VerDefNdx) -> Expected<VerdAux> { + if (VerdauxBuf + sizeof(Elf_Verdaux) > End) + return createError("invalid " + describe(*this, Sec) + + ": version definition " + Twine(VerDefNdx) + + " refers to an auxiliary entry that goes past the end " + "of the section"); + + auto *Verdaux = reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf); + VerdauxBuf += Verdaux->vda_next; + + VerdAux Aux; + Aux.Offset = VerdauxBuf - Start; + if (Verdaux->vda_name <= StrTabOrErr->size()) + Aux.Name = std::string(StrTabOrErr->drop_front(Verdaux->vda_name)); + else + Aux.Name = ("<invalid vda_name: " + Twine(Verdaux->vda_name) + ">").str(); + return Aux; + }; + + std::vector<VerDef> Ret; + const uint8_t *VerdefBuf = Start; + for (unsigned I = 1; I <= /*VerDefsNum=*/Sec.sh_info; ++I) { + if (VerdefBuf + sizeof(Elf_Verdef) > End) + return createError("invalid " + describe(*this, Sec) + + ": version definition " + Twine(I) + + " goes past the end of the section"); + + if (reinterpret_cast<uintptr_t>(VerdefBuf) % sizeof(uint32_t) != 0) + return createError( + "invalid " + describe(*this, Sec) + + ": found a misaligned version definition entry at offset 0x" + + Twine::utohexstr(VerdefBuf - Start)); + + unsigned Version = *reinterpret_cast<const Elf_Half *>(VerdefBuf); + if (Version != 1) + return createError("unable to dump " + describe(*this, Sec) + + ": version " + Twine(Version) + + " is not yet supported"); + + const Elf_Verdef *D = reinterpret_cast<const Elf_Verdef *>(VerdefBuf); + VerDef &VD = *Ret.emplace(Ret.end()); + VD.Offset = VerdefBuf - Start; + VD.Version = D->vd_version; + VD.Flags = D->vd_flags; + VD.Ndx = D->vd_ndx; + VD.Cnt = D->vd_cnt; + VD.Hash = D->vd_hash; + + const uint8_t *VerdauxBuf = VerdefBuf + D->vd_aux; + for (unsigned J = 0; J < D->vd_cnt; ++J) { + if (reinterpret_cast<uintptr_t>(VerdauxBuf) % sizeof(uint32_t) != 0) + return createError("invalid " + describe(*this, Sec) + + ": found a misaligned auxiliary entry at offset 0x" + + Twine::utohexstr(VerdauxBuf - Start)); + + Expected<VerdAux> AuxOrErr = ExtractNextAux(VerdauxBuf, I); + if (!AuxOrErr) + return AuxOrErr.takeError(); + + if (J == 0) + VD.Name = AuxOrErr->Name; + else + VD.AuxV.push_back(*AuxOrErr); + } + + VerdefBuf += D->vd_next; + } + + return Ret; +} + +template <class ELFT> +Expected<std::vector<VerNeed>> +ELFFile<ELFT>::getVersionDependencies(const Elf_Shdr &Sec, + WarningHandler WarnHandler) const { + StringRef StrTab; + Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Sec); + if (!StrTabOrErr) { + if (Error E = WarnHandler(toString(StrTabOrErr.takeError()))) + return std::move(E); + } else { + StrTab = *StrTabOrErr; + } + + Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec); + if (!ContentsOrErr) + return createError("cannot read content of " + describe(*this, Sec) + ": " + + toString(ContentsOrErr.takeError())); + + const uint8_t *Start = ContentsOrErr->data(); + const uint8_t *End = Start + ContentsOrErr->size(); + const uint8_t *VerneedBuf = Start; + + std::vector<VerNeed> Ret; + for (unsigned I = 1; I <= /*VerneedNum=*/Sec.sh_info; ++I) { + if (VerneedBuf + sizeof(Elf_Verdef) > End) + return createError("invalid " + describe(*this, Sec) + + ": version dependency " + Twine(I) + + " goes past the end of the section"); + + if (reinterpret_cast<uintptr_t>(VerneedBuf) % sizeof(uint32_t) != 0) + return createError( + "invalid " + describe(*this, Sec) + + ": found a misaligned version dependency entry at offset 0x" + + Twine::utohexstr(VerneedBuf - Start)); + + unsigned Version = *reinterpret_cast<const Elf_Half *>(VerneedBuf); + if (Version != 1) + return createError("unable to dump " + describe(*this, Sec) + + ": version " + Twine(Version) + + " is not yet supported"); + + const Elf_Verneed *Verneed = + reinterpret_cast<const Elf_Verneed *>(VerneedBuf); + + VerNeed &VN = *Ret.emplace(Ret.end()); + VN.Version = Verneed->vn_version; + VN.Cnt = Verneed->vn_cnt; + VN.Offset = VerneedBuf - Start; + + if (Verneed->vn_file < StrTab.size()) + VN.File = std::string(StrTab.drop_front(Verneed->vn_file)); + else + VN.File = ("<corrupt vn_file: " + Twine(Verneed->vn_file) + ">").str(); + + const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux; + for (unsigned J = 0; J < Verneed->vn_cnt; ++J) { + if (reinterpret_cast<uintptr_t>(VernauxBuf) % sizeof(uint32_t) != 0) + return createError("invalid " + describe(*this, Sec) + + ": found a misaligned auxiliary entry at offset 0x" + + Twine::utohexstr(VernauxBuf - Start)); + + if (VernauxBuf + sizeof(Elf_Vernaux) > End) + return createError( + "invalid " + describe(*this, Sec) + ": version dependency " + + Twine(I) + + " refers to an auxiliary entry that goes past the end " + "of the section"); + + const Elf_Vernaux *Vernaux = + reinterpret_cast<const Elf_Vernaux *>(VernauxBuf); + + VernAux &Aux = *VN.AuxV.emplace(VN.AuxV.end()); + Aux.Hash = Vernaux->vna_hash; + Aux.Flags = Vernaux->vna_flags; + Aux.Other = Vernaux->vna_other; + Aux.Offset = VernauxBuf - Start; + if (StrTab.size() <= Vernaux->vna_name) + Aux.Name = "<corrupt>"; + else + Aux.Name = std::string(StrTab.drop_front(Vernaux->vna_name)); + + VernauxBuf += Vernaux->vna_next; + } + VerneedBuf += Verneed->vn_next; + } + return Ret; +} + +template <class ELFT> Expected<const typename ELFT::Shdr *> ELFFile<ELFT>::getSection(uint32_t Index) const { auto TableOrErr = sections(); @@ -1055,14 +1055,14 @@ ELFFile<ELFT>::getSection(uint32_t Index) const { template <class ELFT> Expected<StringRef> -ELFFile<ELFT>::getStringTable(const Elf_Shdr &Section, +ELFFile<ELFT>::getStringTable(const Elf_Shdr &Section, WarningHandler WarnHandler) const { - if (Section.sh_type != ELF::SHT_STRTAB) + if (Section.sh_type != ELF::SHT_STRTAB) if (Error E = WarnHandler("invalid sh_type for string table section " + - getSecIndexForError(*this, Section) + + getSecIndexForError(*this, Section) + ": expected SHT_STRTAB, but got " + object::getELFSectionTypeName( - getHeader().e_machine, Section.sh_type))) + getHeader().e_machine, Section.sh_type))) return std::move(E); auto V = getSectionContentsAsArray<char>(Section); @@ -1071,10 +1071,10 @@ ELFFile<ELFT>::getStringTable(const Elf_Shdr &Section, ArrayRef<char> Data = *V; if (Data.empty()) return createError("SHT_STRTAB string table section " + - getSecIndexForError(*this, Section) + " is empty"); + getSecIndexForError(*this, Section) + " is empty"); if (Data.back() != '\0') return createError("SHT_STRTAB string table section " + - getSecIndexForError(*this, Section) + + getSecIndexForError(*this, Section) + " is non-null terminated"); return StringRef(Data.begin(), Data.size()); } @@ -1093,7 +1093,7 @@ Expected<ArrayRef<typename ELFT::Word>> ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const { assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX); - auto VOrErr = getSectionContentsAsArray<Elf_Word>(Section); + auto VOrErr = getSectionContentsAsArray<Elf_Word>(Section); if (!VOrErr) return VOrErr.takeError(); ArrayRef<Elf_Word> V = *VOrErr; @@ -1103,10 +1103,10 @@ ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section, const Elf_Shdr &SymTable = **SymTableOrErr; if (SymTable.sh_type != ELF::SHT_SYMTAB && SymTable.sh_type != ELF::SHT_DYNSYM) - return createError( - "SHT_SYMTAB_SHNDX section is linked with " + - object::getELFSectionTypeName(getHeader().e_machine, SymTable.sh_type) + - " section (expected SHT_SYMTAB/SHT_DYNSYM)"); + return createError( + "SHT_SYMTAB_SHNDX section is linked with " + + object::getELFSectionTypeName(getHeader().e_machine, SymTable.sh_type) + + " section (expected SHT_SYMTAB/SHT_DYNSYM)"); uint64_t Syms = SymTable.sh_size / sizeof(Elf_Sym); if (V.size() != Syms) @@ -1134,33 +1134,33 @@ ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec, if (Sec.sh_type != ELF::SHT_SYMTAB && Sec.sh_type != ELF::SHT_DYNSYM) return createError( "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM"); - Expected<const Elf_Shdr *> SectionOrErr = - object::getSection<ELFT>(Sections, Sec.sh_link); + Expected<const Elf_Shdr *> SectionOrErr = + object::getSection<ELFT>(Sections, Sec.sh_link); if (!SectionOrErr) return SectionOrErr.takeError(); - return getStringTable(**SectionOrErr); -} - -template <class ELFT> -Expected<StringRef> -ELFFile<ELFT>::getLinkAsStrtab(const typename ELFT::Shdr &Sec) const { - Expected<const typename ELFT::Shdr *> StrTabSecOrErr = - getSection(Sec.sh_link); - if (!StrTabSecOrErr) - return createError("invalid section linked to " + describe(*this, Sec) + - ": " + toString(StrTabSecOrErr.takeError())); - - Expected<StringRef> StrTabOrErr = getStringTable(**StrTabSecOrErr); - if (!StrTabOrErr) - return createError("invalid string table linked to " + - describe(*this, Sec) + ": " + - toString(StrTabOrErr.takeError())); - return *StrTabOrErr; + return getStringTable(**SectionOrErr); } template <class ELFT> Expected<StringRef> -ELFFile<ELFT>::getSectionName(const Elf_Shdr &Section, +ELFFile<ELFT>::getLinkAsStrtab(const typename ELFT::Shdr &Sec) const { + Expected<const typename ELFT::Shdr *> StrTabSecOrErr = + getSection(Sec.sh_link); + if (!StrTabSecOrErr) + return createError("invalid section linked to " + describe(*this, Sec) + + ": " + toString(StrTabSecOrErr.takeError())); + + Expected<StringRef> StrTabOrErr = getStringTable(**StrTabSecOrErr); + if (!StrTabOrErr) + return createError("invalid string table linked to " + + describe(*this, Sec) + ": " + + toString(StrTabOrErr.takeError())); + return *StrTabOrErr; +} + +template <class ELFT> +Expected<StringRef> +ELFFile<ELFT>::getSectionName(const Elf_Shdr &Section, WarningHandler WarnHandler) const { auto SectionsOrErr = sections(); if (!SectionsOrErr) @@ -1172,13 +1172,13 @@ ELFFile<ELFT>::getSectionName(const Elf_Shdr &Section, } template <class ELFT> -Expected<StringRef> ELFFile<ELFT>::getSectionName(const Elf_Shdr &Section, +Expected<StringRef> ELFFile<ELFT>::getSectionName(const Elf_Shdr &Section, StringRef DotShstrtab) const { - uint32_t Offset = Section.sh_name; + uint32_t Offset = Section.sh_name; if (Offset == 0) return StringRef(); if (Offset >= DotShstrtab.size()) - return createError("a section " + getSecIndexForError(*this, Section) + + return createError("a section " + getSecIndexForError(*this, Section) + " has an invalid sh_name (0x" + Twine::utohexstr(Offset) + ") offset which goes past the end of the " diff --git a/contrib/libs/llvm12/include/llvm/Object/ELFObjectFile.h b/contrib/libs/llvm12/include/llvm/Object/ELFObjectFile.h index 28c6ec9bfc..5b782f72d9 100644 --- a/contrib/libs/llvm12/include/llvm/Object/ELFObjectFile.h +++ b/contrib/libs/llvm12/include/llvm/Object/ELFObjectFile.h @@ -58,12 +58,12 @@ class ELFObjectFileBase : public ObjectFile { friend class ELFSectionRef; friend class ELFSymbolRef; - SubtargetFeatures getMIPSFeatures() const; - SubtargetFeatures getARMFeatures() const; - SubtargetFeatures getRISCVFeatures() const; - - StringRef getAMDGPUCPUName() const; - + SubtargetFeatures getMIPSFeatures() const; + SubtargetFeatures getARMFeatures() const; + SubtargetFeatures getRISCVFeatures() const; + + StringRef getAMDGPUCPUName() const; + protected: ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source); @@ -93,7 +93,7 @@ public: SubtargetFeatures getFeatures() const override; - Optional<StringRef> tryGetCPUName() const override; + Optional<StringRef> tryGetCPUName() const override; void setARMSubArch(Triple &TheTriple) const override; @@ -101,8 +101,8 @@ public: virtual uint16_t getEMachine() const = 0; - std::vector<std::pair<Optional<DataRefImpl>, uint64_t>> - getPltAddresses() const; + std::vector<std::pair<Optional<DataRefImpl>, uint64_t>> + getPltAddresses() const; }; class ELFSectionRef : public SectionRef { @@ -244,28 +244,28 @@ public: return SectionRef(toDRI(Sec), this); } - ELFSymbolRef toSymbolRef(const Elf_Shdr *SymTable, unsigned SymbolNum) const { - return ELFSymbolRef({toDRI(SymTable, SymbolNum), this}); - } - - bool IsContentValid() const { return ContentValid; } - + ELFSymbolRef toSymbolRef(const Elf_Shdr *SymTable, unsigned SymbolNum) const { + return ELFSymbolRef({toDRI(SymTable, SymbolNum), this}); + } + + bool IsContentValid() const { return ContentValid; } + private: ELFObjectFile(MemoryBufferRef Object, ELFFile<ELFT> EF, const Elf_Shdr *DotDynSymSec, const Elf_Shdr *DotSymtabSec, - const Elf_Shdr *DotSymtabShndxSec); - - bool ContentValid = false; + const Elf_Shdr *DotSymtabShndxSec); + bool ContentValid = false; + protected: ELFFile<ELFT> EF; const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section. const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section. - const Elf_Shdr *DotSymtabShndxSec = nullptr; // SHT_SYMTAB_SHNDX section. - - Error initContent() override; + const Elf_Shdr *DotSymtabShndxSec = nullptr; // SHT_SYMTAB_SHNDX section. + Error initContent() override; + void moveSymbolNext(DataRefImpl &Symb) const override; Expected<StringRef> getSymbolName(DataRefImpl Symb) const override; Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override; @@ -377,7 +377,7 @@ protected: for (const Elf_Shdr &Sec : *SectionsOrErr) { if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES || Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES) { - auto ErrorOrContents = EF.getSectionContents(Sec); + auto ErrorOrContents = EF.getSectionContents(Sec); if (!ErrorOrContents) return ErrorOrContents.takeError(); @@ -400,24 +400,24 @@ protected: public: ELFObjectFile(ELFObjectFile<ELFT> &&Other); - static Expected<ELFObjectFile<ELFT>> create(MemoryBufferRef Object, - bool InitContent = true); + static Expected<ELFObjectFile<ELFT>> create(MemoryBufferRef Object, + bool InitContent = true); const Elf_Rel *getRel(DataRefImpl Rel) const; const Elf_Rela *getRela(DataRefImpl Rela) const; - Expected<const Elf_Sym *> getSymbol(DataRefImpl Sym) const { - return EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b); - } - - /// Get the relocation section that contains \a Rel. - const Elf_Shdr *getRelSection(DataRefImpl Rel) const { - auto RelSecOrErr = EF.getSection(Rel.d.a); - if (!RelSecOrErr) - report_fatal_error(errorToErrorCode(RelSecOrErr.takeError()).message()); - return *RelSecOrErr; + Expected<const Elf_Sym *> getSymbol(DataRefImpl Sym) const { + return EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b); } + /// Get the relocation section that contains \a Rel. + const Elf_Shdr *getRelSection(DataRefImpl Rel) const { + auto RelSecOrErr = EF.getSection(Rel.d.a); + if (!RelSecOrErr) + report_fatal_error(errorToErrorCode(RelSecOrErr.takeError()).message()); + return *RelSecOrErr; + } + const Elf_Shdr *getSection(DataRefImpl Sec) const { return reinterpret_cast<const Elf_Shdr *>(Sec.p); } @@ -438,9 +438,9 @@ public: Triple::ArchType getArch() const override; Expected<uint64_t> getStartAddress() const override; - unsigned getPlatformFlags() const override { return EF.getHeader().e_flags; } + unsigned getPlatformFlags() const override { return EF.getHeader().e_flags; } - const ELFFile<ELFT> &getELFFile() const { return EF; } + const ELFFile<ELFT> &getELFFile() const { return EF; } bool isDyldType() const { return isDyldELFObject; } static bool classof(const Binary *v) { @@ -463,40 +463,40 @@ void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const { ++Sym.d.b; } -template <class ELFT> Error ELFObjectFile<ELFT>::initContent() { - auto SectionsOrErr = EF.sections(); - if (!SectionsOrErr) - return SectionsOrErr.takeError(); - - for (const Elf_Shdr &Sec : *SectionsOrErr) { - switch (Sec.sh_type) { - case ELF::SHT_DYNSYM: { - if (!DotDynSymSec) - DotDynSymSec = &Sec; - break; - } - case ELF::SHT_SYMTAB: { - if (!DotSymtabSec) - DotSymtabSec = &Sec; - break; - } - case ELF::SHT_SYMTAB_SHNDX: { - if (!DotSymtabShndxSec) - DotSymtabShndxSec = &Sec; - break; - } - } - } - - ContentValid = true; - return Error::success(); -} - +template <class ELFT> Error ELFObjectFile<ELFT>::initContent() { + auto SectionsOrErr = EF.sections(); + if (!SectionsOrErr) + return SectionsOrErr.takeError(); + + for (const Elf_Shdr &Sec : *SectionsOrErr) { + switch (Sec.sh_type) { + case ELF::SHT_DYNSYM: { + if (!DotDynSymSec) + DotDynSymSec = &Sec; + break; + } + case ELF::SHT_SYMTAB: { + if (!DotSymtabSec) + DotSymtabSec = &Sec; + break; + } + case ELF::SHT_SYMTAB_SHNDX: { + if (!DotSymtabShndxSec) + DotSymtabShndxSec = &Sec; + break; + } + } + } + + ContentValid = true; + return Error::success(); +} + template <class ELFT> Expected<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym); - if (!SymOrErr) - return SymOrErr.takeError(); + Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym); + if (!SymOrErr) + return SymOrErr.takeError(); auto SymTabOrErr = EF.getSection(Sym.d.a); if (!SymTabOrErr) return SymTabOrErr.takeError(); @@ -505,15 +505,15 @@ Expected<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const { if (!StrTabOrErr) return StrTabOrErr.takeError(); const Elf_Shdr *StringTableSec = *StrTabOrErr; - auto SymStrTabOrErr = EF.getStringTable(*StringTableSec); + auto SymStrTabOrErr = EF.getStringTable(*StringTableSec); if (!SymStrTabOrErr) return SymStrTabOrErr.takeError(); - Expected<StringRef> Name = (*SymOrErr)->getName(*SymStrTabOrErr); + Expected<StringRef> Name = (*SymOrErr)->getName(*SymStrTabOrErr); if (Name && !Name->empty()) return Name; // If the symbol name is empty use the section name. - if ((*SymOrErr)->getType() == ELF::STT_SECTION) { + if ((*SymOrErr)->getType() == ELF::STT_SECTION) { if (Expected<section_iterator> SecOrErr = getSymbolSection(Sym)) { consumeError(Name.takeError()); return (*SecOrErr)->getName(); @@ -539,18 +539,18 @@ uint64_t ELFObjectFile<ELFT>::getSectionOffset(DataRefImpl Sec) const { template <class ELFT> uint64_t ELFObjectFile<ELFT>::getSymbolValueImpl(DataRefImpl Symb) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); - if (!SymOrErr) - report_fatal_error(SymOrErr.takeError()); - - uint64_t Ret = (*SymOrErr)->st_value; - if ((*SymOrErr)->st_shndx == ELF::SHN_ABS) + Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); + if (!SymOrErr) + report_fatal_error(SymOrErr.takeError()); + + uint64_t Ret = (*SymOrErr)->st_value; + if ((*SymOrErr)->st_shndx == ELF::SHN_ABS) return Ret; - const Elf_Ehdr &Header = EF.getHeader(); + const Elf_Ehdr &Header = EF.getHeader(); // Clear the ARM/Thumb or microMIPS indicator flag. - if ((Header.e_machine == ELF::EM_ARM || Header.e_machine == ELF::EM_MIPS) && - (*SymOrErr)->getType() == ELF::STT_FUNC) + if ((Header.e_machine == ELF::EM_ARM || Header.e_machine == ELF::EM_MIPS) && + (*SymOrErr)->getType() == ELF::STT_FUNC) Ret &= ~1; return Ret; @@ -565,11 +565,11 @@ ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb) const { return SymbolValueOrErr.takeError(); uint64_t Result = *SymbolValueOrErr; - Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); - if (!SymOrErr) - return SymOrErr.takeError(); - - switch ((*SymOrErr)->st_shndx) { + Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); + if (!SymOrErr) + return SymOrErr.takeError(); + + switch ((*SymOrErr)->st_shndx) { case ELF::SHN_COMMON: case ELF::SHN_UNDEF: case ELF::SHN_ABS: @@ -580,19 +580,19 @@ ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb) const { if (!SymTabOrErr) return SymTabOrErr.takeError(); - if (EF.getHeader().e_type == ELF::ET_REL) { - ArrayRef<Elf_Word> ShndxTable; - if (DotSymtabShndxSec) { - // TODO: Test this error. - if (Expected<ArrayRef<Elf_Word>> ShndxTableOrErr = - EF.getSHNDXTable(*DotSymtabShndxSec)) - ShndxTable = *ShndxTableOrErr; - else - return ShndxTableOrErr.takeError(); - } - - Expected<const Elf_Shdr *> SectionOrErr = - EF.getSection(**SymOrErr, *SymTabOrErr, ShndxTable); + if (EF.getHeader().e_type == ELF::ET_REL) { + ArrayRef<Elf_Word> ShndxTable; + if (DotSymtabShndxSec) { + // TODO: Test this error. + if (Expected<ArrayRef<Elf_Word>> ShndxTableOrErr = + EF.getSHNDXTable(*DotSymtabShndxSec)) + ShndxTable = *ShndxTableOrErr; + else + return ShndxTableOrErr.takeError(); + } + + Expected<const Elf_Shdr *> SectionOrErr = + EF.getSection(**SymOrErr, *SymTabOrErr, ShndxTable); if (!SectionOrErr) return SectionOrErr.takeError(); const Elf_Shdr *Section = *SectionOrErr; @@ -605,68 +605,68 @@ ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb) const { template <class ELFT> uint32_t ELFObjectFile<ELFT>::getSymbolAlignment(DataRefImpl Symb) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); - if (!SymOrErr) - report_fatal_error(SymOrErr.takeError()); - if ((*SymOrErr)->st_shndx == ELF::SHN_COMMON) - return (*SymOrErr)->st_value; + Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); + if (!SymOrErr) + report_fatal_error(SymOrErr.takeError()); + if ((*SymOrErr)->st_shndx == ELF::SHN_COMMON) + return (*SymOrErr)->st_value; return 0; } template <class ELFT> uint16_t ELFObjectFile<ELFT>::getEMachine() const { - return EF.getHeader().e_machine; + return EF.getHeader().e_machine; } template <class ELFT> uint16_t ELFObjectFile<ELFT>::getEType() const { - return EF.getHeader().e_type; + return EF.getHeader().e_type; } template <class ELFT> uint64_t ELFObjectFile<ELFT>::getSymbolSize(DataRefImpl Sym) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym); - if (!SymOrErr) - report_fatal_error(SymOrErr.takeError()); - return (*SymOrErr)->st_size; + Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym); + if (!SymOrErr) + report_fatal_error(SymOrErr.takeError()); + return (*SymOrErr)->st_size; } template <class ELFT> uint64_t ELFObjectFile<ELFT>::getCommonSymbolSizeImpl(DataRefImpl Symb) const { - return getSymbolSize(Symb); + return getSymbolSize(Symb); } template <class ELFT> uint8_t ELFObjectFile<ELFT>::getSymbolBinding(DataRefImpl Symb) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); - if (!SymOrErr) - report_fatal_error(SymOrErr.takeError()); - return (*SymOrErr)->getBinding(); + Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); + if (!SymOrErr) + report_fatal_error(SymOrErr.takeError()); + return (*SymOrErr)->getBinding(); } template <class ELFT> uint8_t ELFObjectFile<ELFT>::getSymbolOther(DataRefImpl Symb) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); - if (!SymOrErr) - report_fatal_error(SymOrErr.takeError()); - return (*SymOrErr)->st_other; + Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); + if (!SymOrErr) + report_fatal_error(SymOrErr.takeError()); + return (*SymOrErr)->st_other; } template <class ELFT> uint8_t ELFObjectFile<ELFT>::getSymbolELFType(DataRefImpl Symb) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); - if (!SymOrErr) - report_fatal_error(SymOrErr.takeError()); - return (*SymOrErr)->getType(); + Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); + if (!SymOrErr) + report_fatal_error(SymOrErr.takeError()); + return (*SymOrErr)->getType(); } template <class ELFT> Expected<SymbolRef::Type> ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); - if (!SymOrErr) - return SymOrErr.takeError(); + Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); + if (!SymOrErr) + return SymOrErr.takeError(); - switch ((*SymOrErr)->getType()) { + switch ((*SymOrErr)->getType()) { case ELF::STT_NOTYPE: return SymbolRef::ST_Unknown; case ELF::STT_SECTION: @@ -686,11 +686,11 @@ ELFObjectFile<ELFT>::getSymbolType(DataRefImpl Symb) const { template <class ELFT> Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym); - if (!SymOrErr) - return SymOrErr.takeError(); + Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym); + if (!SymOrErr) + return SymOrErr.takeError(); - const Elf_Sym *ESym = *SymOrErr; + const Elf_Sym *ESym = *SymOrErr; uint32_t Result = SymbolRef::SF_None; if (ESym->getBinding() != ELF::STB_LOCAL) @@ -723,7 +723,7 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const { // TODO: Test this error. return SymbolsOrErr.takeError(); - if (EF.getHeader().e_machine == ELF::EM_ARM) { + if (EF.getHeader().e_machine == ELF::EM_ARM) { if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) { StringRef Name = *NameOrErr; if (Name.startswith("$d") || Name.startswith("$t") || @@ -756,17 +756,17 @@ template <class ELFT> Expected<section_iterator> ELFObjectFile<ELFT>::getSymbolSection(const Elf_Sym *ESym, const Elf_Shdr *SymTab) const { - ArrayRef<Elf_Word> ShndxTable; - if (DotSymtabShndxSec) { - // TODO: Test this error. - Expected<ArrayRef<Elf_Word>> ShndxTableOrErr = - EF.getSHNDXTable(*DotSymtabShndxSec); - if (!ShndxTableOrErr) - return ShndxTableOrErr.takeError(); - ShndxTable = *ShndxTableOrErr; - } - - auto ESecOrErr = EF.getSection(*ESym, SymTab, ShndxTable); + ArrayRef<Elf_Word> ShndxTable; + if (DotSymtabShndxSec) { + // TODO: Test this error. + Expected<ArrayRef<Elf_Word>> ShndxTableOrErr = + EF.getSHNDXTable(*DotSymtabShndxSec); + if (!ShndxTableOrErr) + return ShndxTableOrErr.takeError(); + ShndxTable = *ShndxTableOrErr; + } + + auto ESecOrErr = EF.getSection(*ESym, SymTab, ShndxTable); if (!ESecOrErr) return ESecOrErr.takeError(); @@ -782,14 +782,14 @@ ELFObjectFile<ELFT>::getSymbolSection(const Elf_Sym *ESym, template <class ELFT> Expected<section_iterator> ELFObjectFile<ELFT>::getSymbolSection(DataRefImpl Symb) const { - Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); - if (!SymOrErr) - return SymOrErr.takeError(); - + Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb); + if (!SymOrErr) + return SymOrErr.takeError(); + auto SymTabOrErr = EF.getSection(Symb.d.a); if (!SymTabOrErr) return SymTabOrErr.takeError(); - return getSymbolSection(*SymOrErr, *SymTabOrErr); + return getSymbolSection(*SymOrErr, *SymTabOrErr); } template <class ELFT> @@ -800,7 +800,7 @@ void ELFObjectFile<ELFT>::moveSectionNext(DataRefImpl &Sec) const { template <class ELFT> Expected<StringRef> ELFObjectFile<ELFT>::getSectionName(DataRefImpl Sec) const { - return EF.getSectionName(*getSection(Sec)); + return EF.getSectionName(*getSection(Sec)); } template <class ELFT> @@ -930,7 +930,7 @@ ELFObjectFile<ELFT>::section_rel_begin(DataRefImpl Sec) const { if (!SectionsOrErr) return relocation_iterator(RelocationRef()); uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin()); - RelData.d.a = (Sec.p - SHT) / EF.getHeader().e_shentsize; + RelData.d.a = (Sec.p - SHT) / EF.getHeader().e_shentsize; RelData.d.b = 0; return relocation_iterator(RelocationRef(RelData, this)); } @@ -957,7 +957,7 @@ ELFObjectFile<ELFT>::section_rel_end(DataRefImpl Sec) const { template <class ELFT> Expected<section_iterator> ELFObjectFile<ELFT>::getRelocatedSection(DataRefImpl Sec) const { - if (EF.getHeader().e_type != ELF::ET_REL) + if (EF.getHeader().e_type != ELF::ET_REL) return section_end(); const Elf_Shdr *EShdr = getSection(Sec); @@ -1016,7 +1016,7 @@ uint64_t ELFObjectFile<ELFT>::getRelocationType(DataRefImpl Rel) const { template <class ELFT> StringRef ELFObjectFile<ELFT>::getRelocationTypeName(uint32_t Type) const { - return getELFRelocationTypeName(EF.getHeader().e_machine, Type); + return getELFRelocationTypeName(EF.getHeader().e_machine, Type); } template <class ELFT> @@ -1056,34 +1056,34 @@ ELFObjectFile<ELFT>::getRela(DataRefImpl Rela) const { template <class ELFT> Expected<ELFObjectFile<ELFT>> -ELFObjectFile<ELFT>::create(MemoryBufferRef Object, bool InitContent) { +ELFObjectFile<ELFT>::create(MemoryBufferRef Object, bool InitContent) { auto EFOrErr = ELFFile<ELFT>::create(Object.getBuffer()); if (Error E = EFOrErr.takeError()) return std::move(E); - ELFObjectFile<ELFT> Obj = {Object, std::move(*EFOrErr), nullptr, nullptr, - nullptr}; - if (InitContent) - if (Error E = Obj.initContent()) - return std::move(E); - return std::move(Obj); + ELFObjectFile<ELFT> Obj = {Object, std::move(*EFOrErr), nullptr, nullptr, + nullptr}; + if (InitContent) + if (Error E = Obj.initContent()) + return std::move(E); + return std::move(Obj); } template <class ELFT> ELFObjectFile<ELFT>::ELFObjectFile(MemoryBufferRef Object, ELFFile<ELFT> EF, const Elf_Shdr *DotDynSymSec, const Elf_Shdr *DotSymtabSec, - const Elf_Shdr *DotSymtabShndx) + const Elf_Shdr *DotSymtabShndx) : ELFObjectFileBase( getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits), Object), EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec), - DotSymtabShndxSec(DotSymtabShndx) {} + DotSymtabShndxSec(DotSymtabShndx) {} template <class ELFT> ELFObjectFile<ELFT>::ELFObjectFile(ELFObjectFile<ELFT> &&Other) : ELFObjectFile(Other.Data, Other.EF, Other.DotDynSymSec, - Other.DotSymtabSec, Other.DotSymtabShndxSec) {} + Other.DotSymtabSec, Other.DotSymtabShndxSec) {} template <class ELFT> basic_symbol_iterator ELFObjectFile<ELFT>::symbol_begin() const { @@ -1145,9 +1145,9 @@ uint8_t ELFObjectFile<ELFT>::getBytesInAddress() const { template <class ELFT> StringRef ELFObjectFile<ELFT>::getFileFormatName() const { bool IsLittleEndian = ELFT::TargetEndianness == support::little; - switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { + switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { case ELF::ELFCLASS32: - switch (EF.getHeader().e_machine) { + switch (EF.getHeader().e_machine) { case ELF::EM_386: return "elf32-i386"; case ELF::EM_IAMCU: @@ -1167,11 +1167,11 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const { case ELF::EM_MSP430: return "elf32-msp430"; case ELF::EM_PPC: - return (IsLittleEndian ? "elf32-powerpcle" : "elf32-powerpc"); + return (IsLittleEndian ? "elf32-powerpcle" : "elf32-powerpc"); case ELF::EM_RISCV: return "elf32-littleriscv"; - case ELF::EM_CSKY: - return "elf32-csky"; + case ELF::EM_CSKY: + return "elf32-csky"; case ELF::EM_SPARC: case ELF::EM_SPARC32PLUS: return "elf32-sparc"; @@ -1181,7 +1181,7 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const { return "elf32-unknown"; } case ELF::ELFCLASS64: - switch (EF.getHeader().e_machine) { + switch (EF.getHeader().e_machine) { case ELF::EM_386: return "elf64-i386"; case ELF::EM_X86_64: @@ -1215,7 +1215,7 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const { template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const { bool IsLittleEndian = ELFT::TargetEndianness == support::little; - switch (EF.getHeader().e_machine) { + switch (EF.getHeader().e_machine) { case ELF::EM_386: case ELF::EM_IAMCU: return Triple::x86; @@ -1232,7 +1232,7 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const { case ELF::EM_LANAI: return Triple::lanai; case ELF::EM_MIPS: - switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { + switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { case ELF::ELFCLASS32: return IsLittleEndian ? Triple::mipsel : Triple::mips; case ELF::ELFCLASS64: @@ -1243,11 +1243,11 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const { case ELF::EM_MSP430: return Triple::msp430; case ELF::EM_PPC: - return IsLittleEndian ? Triple::ppcle : Triple::ppc; + return IsLittleEndian ? Triple::ppcle : Triple::ppc; case ELF::EM_PPC64: return IsLittleEndian ? Triple::ppc64le : Triple::ppc64; case ELF::EM_RISCV: - switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { + switch (EF.getHeader().e_ident[ELF::EI_CLASS]) { case ELF::ELFCLASS32: return Triple::riscv32; case ELF::ELFCLASS64: @@ -1268,7 +1268,7 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const { if (!IsLittleEndian) return Triple::UnknownArch; - unsigned MACH = EF.getHeader().e_flags & ELF::EF_AMDGPU_MACH; + unsigned MACH = EF.getHeader().e_flags & ELF::EF_AMDGPU_MACH; if (MACH >= ELF::EF_AMDGPU_MACH_R600_FIRST && MACH <= ELF::EF_AMDGPU_MACH_R600_LAST) return Triple::r600; @@ -1284,8 +1284,8 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const { case ELF::EM_VE: return Triple::ve; - case ELF::EM_CSKY: - return Triple::csky; + case ELF::EM_CSKY: + return Triple::csky; default: return Triple::UnknownArch; } @@ -1293,7 +1293,7 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const { template <class ELFT> Expected<uint64_t> ELFObjectFile<ELFT>::getStartAddress() const { - return EF.getHeader().e_entry; + return EF.getHeader().e_entry; } template <class ELFT> @@ -1303,7 +1303,7 @@ ELFObjectFile<ELFT>::getDynamicSymbolIterators() const { } template <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const { - return EF.getHeader().e_type == ELF::ET_REL; + return EF.getHeader().e_type == ELF::ET_REL; } } // end namespace object diff --git a/contrib/libs/llvm12/include/llvm/Object/ELFTypes.h b/contrib/libs/llvm12/include/llvm/Object/ELFTypes.h index 320dfaa573..06f06c9aca 100644 --- a/contrib/libs/llvm12/include/llvm/Object/ELFTypes.h +++ b/contrib/libs/llvm12/include/llvm/Object/ELFTypes.h @@ -114,34 +114,34 @@ using ELF64BE = ELFType<support::big, true>; using Elf_Word = typename ELFT::Word; \ using Elf_Sword = typename ELFT::Sword; \ using Elf_Xword = typename ELFT::Xword; \ - using Elf_Sxword = typename ELFT::Sxword; \ - using uintX_t = typename ELFT::uint; \ - using Elf_Ehdr = typename ELFT::Ehdr; \ - using Elf_Shdr = typename ELFT::Shdr; \ - using Elf_Sym = typename ELFT::Sym; \ - using Elf_Dyn = typename ELFT::Dyn; \ - using Elf_Phdr = typename ELFT::Phdr; \ - using Elf_Rel = typename ELFT::Rel; \ - using Elf_Rela = typename ELFT::Rela; \ - using Elf_Relr = typename ELFT::Relr; \ - using Elf_Verdef = typename ELFT::Verdef; \ - using Elf_Verdaux = typename ELFT::Verdaux; \ - using Elf_Verneed = typename ELFT::Verneed; \ - using Elf_Vernaux = typename ELFT::Vernaux; \ - using Elf_Versym = typename ELFT::Versym; \ - using Elf_Hash = typename ELFT::Hash; \ - using Elf_GnuHash = typename ELFT::GnuHash; \ - using Elf_Nhdr = typename ELFT::Nhdr; \ - using Elf_Note = typename ELFT::Note; \ - using Elf_Note_Iterator = typename ELFT::NoteIterator; \ - using Elf_CGProfile = typename ELFT::CGProfile; \ - using Elf_Dyn_Range = typename ELFT::DynRange; \ - using Elf_Shdr_Range = typename ELFT::ShdrRange; \ - using Elf_Sym_Range = typename ELFT::SymRange; \ - using Elf_Rel_Range = typename ELFT::RelRange; \ - using Elf_Rela_Range = typename ELFT::RelaRange; \ - using Elf_Relr_Range = typename ELFT::RelrRange; \ - using Elf_Phdr_Range = typename ELFT::PhdrRange; \ + using Elf_Sxword = typename ELFT::Sxword; \ + using uintX_t = typename ELFT::uint; \ + using Elf_Ehdr = typename ELFT::Ehdr; \ + using Elf_Shdr = typename ELFT::Shdr; \ + using Elf_Sym = typename ELFT::Sym; \ + using Elf_Dyn = typename ELFT::Dyn; \ + using Elf_Phdr = typename ELFT::Phdr; \ + using Elf_Rel = typename ELFT::Rel; \ + using Elf_Rela = typename ELFT::Rela; \ + using Elf_Relr = typename ELFT::Relr; \ + using Elf_Verdef = typename ELFT::Verdef; \ + using Elf_Verdaux = typename ELFT::Verdaux; \ + using Elf_Verneed = typename ELFT::Verneed; \ + using Elf_Vernaux = typename ELFT::Vernaux; \ + using Elf_Versym = typename ELFT::Versym; \ + using Elf_Hash = typename ELFT::Hash; \ + using Elf_GnuHash = typename ELFT::GnuHash; \ + using Elf_Nhdr = typename ELFT::Nhdr; \ + using Elf_Note = typename ELFT::Note; \ + using Elf_Note_Iterator = typename ELFT::NoteIterator; \ + using Elf_CGProfile = typename ELFT::CGProfile; \ + using Elf_Dyn_Range = typename ELFT::DynRange; \ + using Elf_Shdr_Range = typename ELFT::ShdrRange; \ + using Elf_Sym_Range = typename ELFT::SymRange; \ + using Elf_Rel_Range = typename ELFT::RelRange; \ + using Elf_Rela_Range = typename ELFT::RelaRange; \ + using Elf_Relr_Range = typename ELFT::RelrRange; \ + using Elf_Phdr_Range = typename ELFT::PhdrRange; \ #define LLVM_ELF_COMMA , #define LLVM_ELF_IMPORT_TYPES(E, W) \ diff --git a/contrib/libs/llvm12/include/llvm/Object/MachO.h b/contrib/libs/llvm12/include/llvm/Object/MachO.h index bbc0a233ee..4418f8fb75 100644 --- a/contrib/libs/llvm12/include/llvm/Object/MachO.h +++ b/contrib/libs/llvm12/include/llvm/Object/MachO.h @@ -622,7 +622,7 @@ public: case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator"; case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator"; case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator"; - case MachO::PLATFORM_DRIVERKIT: return "driverkit"; + case MachO::PLATFORM_DRIVERKIT: return "driverkit"; default: std::string ret; raw_string_ostream ss(ret); diff --git a/contrib/libs/llvm12/include/llvm/Object/MachOUniversal.h b/contrib/libs/llvm12/include/llvm/Object/MachOUniversal.h index 2f34b6a71b..5ba205404a 100644 --- a/contrib/libs/llvm12/include/llvm/Object/MachOUniversal.h +++ b/contrib/libs/llvm12/include/llvm/Object/MachOUniversal.h @@ -29,11 +29,11 @@ namespace llvm { class StringRef; -class Module; -class LLVMContext; +class Module; +class LLVMContext; namespace object { -class IRObjectFile; +class IRObjectFile; class MachOUniversalBinary : public Binary { virtual void anchor(); @@ -111,8 +111,8 @@ public: } Expected<std::unique_ptr<MachOObjectFile>> getAsObjectFile() const; - Expected<std::unique_ptr<IRObjectFile>> - getAsIRObject(LLVMContext &Ctx) const; + Expected<std::unique_ptr<IRObjectFile>> + getAsIRObject(LLVMContext &Ctx) const; Expected<std::unique_ptr<Archive>> getAsArchive() const; }; @@ -166,9 +166,9 @@ public: Expected<std::unique_ptr<MachOObjectFile>> getMachOObjectForArch(StringRef ArchName) const; - Expected<std::unique_ptr<IRObjectFile>> - getIRObjectForArch(StringRef ArchName, LLVMContext &Ctx) const; - + Expected<std::unique_ptr<IRObjectFile>> + getIRObjectForArch(StringRef ArchName, LLVMContext &Ctx) const; + Expected<std::unique_ptr<Archive>> getArchiveForArch(StringRef ArchName) const; }; diff --git a/contrib/libs/llvm12/include/llvm/Object/MachOUniversalWriter.h b/contrib/libs/llvm12/include/llvm/Object/MachOUniversalWriter.h index 0ff4beabc7..322ace8925 100644 --- a/contrib/libs/llvm12/include/llvm/Object/MachOUniversalWriter.h +++ b/contrib/libs/llvm12/include/llvm/Object/MachOUniversalWriter.h @@ -1,113 +1,113 @@ -#pragma once - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#endif - -//===- MachOUniversalWriter.h - 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 -// -//===----------------------------------------------------------------------===// -// -// Declares the Slice class and writeUniversalBinary function for writing a -// MachO universal binary file. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_OBJECT_MACHOUNIVERSALWRITER_H -#define LLVM_OBJECT_MACHOUNIVERSALWRITER_H - -#include "llvm/Object/Archive.h" -#include "llvm/Object/Binary.h" -#include "llvm/Object/MachO.h" - -namespace llvm { -class LLVMContext; - -namespace object { -class IRObjectFile; - -class Slice { - const Binary *B; - uint32_t CPUType; - uint32_t CPUSubType; - std::string ArchName; - - // P2Alignment field stores slice alignment values from universal - // binaries. This is also needed to order the slices so the total - // file size can be calculated before creating the output buffer. - uint32_t P2Alignment; - - Slice(const IRObjectFile &IRO, uint32_t CPUType, uint32_t CPUSubType, - std::string ArchName, uint32_t Align); - -public: - explicit Slice(const MachOObjectFile &O); - - Slice(const MachOObjectFile &O, uint32_t Align); - - /// This constructor takes pre-specified \param CPUType , \param CPUSubType , - /// \param ArchName , \param Align instead of inferring them from the archive - /// members. - Slice(const Archive &A, uint32_t CPUType, uint32_t CPUSubType, - std::string ArchName, uint32_t Align); - - static Expected<Slice> create(const Archive &A, - LLVMContext *LLVMCtx = nullptr); - - static Expected<Slice> create(const IRObjectFile &IRO, uint32_t Align); - - void setP2Alignment(uint32_t Align) { P2Alignment = Align; } - - const Binary *getBinary() const { return B; } - - uint32_t getCPUType() const { return CPUType; } - - uint32_t getCPUSubType() const { return CPUSubType; } - - uint32_t getP2Alignment() const { return P2Alignment; } - - uint64_t getCPUID() const { - return static_cast<uint64_t>(CPUType) << 32 | CPUSubType; - } - - std::string getArchString() const { - if (!ArchName.empty()) - return ArchName; - return ("unknown(" + Twine(CPUType) + "," + - Twine(CPUSubType & ~MachO::CPU_SUBTYPE_MASK) + ")") - .str(); - } - - friend bool operator<(const Slice &Lhs, const Slice &Rhs) { - if (Lhs.CPUType == Rhs.CPUType) - return Lhs.CPUSubType < Rhs.CPUSubType; - // force arm64-family to follow after all other slices for - // compatibility with cctools lipo - if (Lhs.CPUType == MachO::CPU_TYPE_ARM64) - return false; - if (Rhs.CPUType == MachO::CPU_TYPE_ARM64) - return true; - // Sort by alignment to minimize file size - return Lhs.P2Alignment < Rhs.P2Alignment; - } -}; - -Error writeUniversalBinary(ArrayRef<Slice> Slices, StringRef OutputFileName); - -Expected<std::unique_ptr<MemoryBuffer>> -writeUniversalBinaryToBuffer(ArrayRef<Slice> Slices); - -} // end namespace object - -} // end namespace llvm - -#endif // LLVM_OBJECT_MACHOUNIVERSALWRITER_H - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif +#pragma once + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif + +//===- MachOUniversalWriter.h - 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 +// +//===----------------------------------------------------------------------===// +// +// Declares the Slice class and writeUniversalBinary function for writing a +// MachO universal binary file. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECT_MACHOUNIVERSALWRITER_H +#define LLVM_OBJECT_MACHOUNIVERSALWRITER_H + +#include "llvm/Object/Archive.h" +#include "llvm/Object/Binary.h" +#include "llvm/Object/MachO.h" + +namespace llvm { +class LLVMContext; + +namespace object { +class IRObjectFile; + +class Slice { + const Binary *B; + uint32_t CPUType; + uint32_t CPUSubType; + std::string ArchName; + + // P2Alignment field stores slice alignment values from universal + // binaries. This is also needed to order the slices so the total + // file size can be calculated before creating the output buffer. + uint32_t P2Alignment; + + Slice(const IRObjectFile &IRO, uint32_t CPUType, uint32_t CPUSubType, + std::string ArchName, uint32_t Align); + +public: + explicit Slice(const MachOObjectFile &O); + + Slice(const MachOObjectFile &O, uint32_t Align); + + /// This constructor takes pre-specified \param CPUType , \param CPUSubType , + /// \param ArchName , \param Align instead of inferring them from the archive + /// members. + Slice(const Archive &A, uint32_t CPUType, uint32_t CPUSubType, + std::string ArchName, uint32_t Align); + + static Expected<Slice> create(const Archive &A, + LLVMContext *LLVMCtx = nullptr); + + static Expected<Slice> create(const IRObjectFile &IRO, uint32_t Align); + + void setP2Alignment(uint32_t Align) { P2Alignment = Align; } + + const Binary *getBinary() const { return B; } + + uint32_t getCPUType() const { return CPUType; } + + uint32_t getCPUSubType() const { return CPUSubType; } + + uint32_t getP2Alignment() const { return P2Alignment; } + + uint64_t getCPUID() const { + return static_cast<uint64_t>(CPUType) << 32 | CPUSubType; + } + + std::string getArchString() const { + if (!ArchName.empty()) + return ArchName; + return ("unknown(" + Twine(CPUType) + "," + + Twine(CPUSubType & ~MachO::CPU_SUBTYPE_MASK) + ")") + .str(); + } + + friend bool operator<(const Slice &Lhs, const Slice &Rhs) { + if (Lhs.CPUType == Rhs.CPUType) + return Lhs.CPUSubType < Rhs.CPUSubType; + // force arm64-family to follow after all other slices for + // compatibility with cctools lipo + if (Lhs.CPUType == MachO::CPU_TYPE_ARM64) + return false; + if (Rhs.CPUType == MachO::CPU_TYPE_ARM64) + return true; + // Sort by alignment to minimize file size + return Lhs.P2Alignment < Rhs.P2Alignment; + } +}; + +Error writeUniversalBinary(ArrayRef<Slice> Slices, StringRef OutputFileName); + +Expected<std::unique_ptr<MemoryBuffer>> +writeUniversalBinaryToBuffer(ArrayRef<Slice> Slices); + +} // end namespace object + +} // end namespace llvm + +#endif // LLVM_OBJECT_MACHOUNIVERSALWRITER_H + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif diff --git a/contrib/libs/llvm12/include/llvm/Object/ObjectFile.h b/contrib/libs/llvm12/include/llvm/Object/ObjectFile.h index 7f9ec78c1d..1bb4ae876e 100644 --- a/contrib/libs/llvm12/include/llvm/Object/ObjectFile.h +++ b/contrib/libs/llvm12/include/llvm/Object/ObjectFile.h @@ -334,7 +334,7 @@ public: virtual StringRef getFileFormatName() const = 0; virtual Triple::ArchType getArch() const = 0; virtual SubtargetFeatures getFeatures() const = 0; - virtual Optional<StringRef> tryGetCPUName() const { return None; }; + virtual Optional<StringRef> tryGetCPUName() const { return None; }; virtual void setARMSubArch(Triple &TheTriple) const { } virtual Expected<uint64_t> getStartAddress() const { return errorCodeToError(object_error::parse_failed); @@ -357,8 +357,8 @@ public: createObjectFile(StringRef ObjectPath); static Expected<std::unique_ptr<ObjectFile>> - createObjectFile(MemoryBufferRef Object, llvm::file_magic Type, - bool InitContent = true); + createObjectFile(MemoryBufferRef Object, llvm::file_magic Type, + bool InitContent = true); static Expected<std::unique_ptr<ObjectFile>> createObjectFile(MemoryBufferRef Object) { return createObjectFile(Object, llvm::file_magic::unknown); @@ -375,7 +375,7 @@ public: createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType); static Expected<std::unique_ptr<ObjectFile>> - createELFObjectFile(MemoryBufferRef Object, bool InitContent = true); + createELFObjectFile(MemoryBufferRef Object, bool InitContent = true); static Expected<std::unique_ptr<MachOObjectFile>> createMachOObjectFile(MemoryBufferRef Object, diff --git a/contrib/libs/llvm12/include/llvm/Object/RelocationResolver.h b/contrib/libs/llvm12/include/llvm/Object/RelocationResolver.h index d53f50e3e5..83a5f92c70 100644 --- a/contrib/libs/llvm12/include/llvm/Object/RelocationResolver.h +++ b/contrib/libs/llvm12/include/llvm/Object/RelocationResolver.h @@ -38,17 +38,17 @@ namespace llvm { namespace object { -using SupportsRelocation = bool (*)(uint64_t); -using RelocationResolver = uint64_t (*)(uint64_t Type, uint64_t Offset, - uint64_t S, uint64_t LocData, - int64_t Addend); +using SupportsRelocation = bool (*)(uint64_t); +using RelocationResolver = uint64_t (*)(uint64_t Type, uint64_t Offset, + uint64_t S, uint64_t LocData, + int64_t Addend); -std::pair<SupportsRelocation, RelocationResolver> +std::pair<SupportsRelocation, RelocationResolver> getRelocationResolver(const ObjectFile &Obj); -uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R, - uint64_t S, uint64_t LocData); - +uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R, + uint64_t S, uint64_t LocData); + } // end namespace object } // end namespace llvm diff --git a/contrib/libs/llvm12/include/llvm/Object/StackMapParser.h b/contrib/libs/llvm12/include/llvm/Object/StackMapParser.h index 4551e80bb2..52fd959d66 100644 --- a/contrib/libs/llvm12/include/llvm/Object/StackMapParser.h +++ b/contrib/libs/llvm12/include/llvm/Object/StackMapParser.h @@ -18,7 +18,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/iterator_range.h" -#include "llvm/Object/ELF.h" +#include "llvm/Object/ELF.h" #include "llvm/Support/Endian.h" #include <cassert> #include <cstddef> @@ -328,23 +328,23 @@ public: } } - /// Validates the header of the specified stack map section. - static Error validateHeader(ArrayRef<uint8_t> StackMapSection) { - // See the comment for StackMaps::emitStackmapHeader(). - if (StackMapSection.size() < 16) - return object::createError( - "the stack map section size (" + Twine(StackMapSection.size()) + - ") is less than the minimum possible size of its header (16)"); - - unsigned Version = StackMapSection[0]; - if (Version != 3) - return object::createError( - "the version (" + Twine(Version) + - ") of the stack map section is unsupported, the " - "supported version is 3"); - return Error::success(); - } - + /// Validates the header of the specified stack map section. + static Error validateHeader(ArrayRef<uint8_t> StackMapSection) { + // See the comment for StackMaps::emitStackmapHeader(). + if (StackMapSection.size() < 16) + return object::createError( + "the stack map section size (" + Twine(StackMapSection.size()) + + ") is less than the minimum possible size of its header (16)"); + + unsigned Version = StackMapSection[0]; + if (Version != 3) + return object::createError( + "the version (" + Twine(Version) + + ") of the stack map section is unsupported, the " + "supported version is 3"); + return Error::success(); + } + using function_iterator = AccessorIterator<FunctionAccessor>; using constant_iterator = AccessorIterator<ConstantAccessor>; using record_iterator = AccessorIterator<RecordAccessor>; diff --git a/contrib/libs/llvm12/include/llvm/Object/SymbolicFile.h b/contrib/libs/llvm12/include/llvm/Object/SymbolicFile.h index 928c0ad8b3..b538afa2ab 100644 --- a/contrib/libs/llvm12/include/llvm/Object/SymbolicFile.h +++ b/contrib/libs/llvm12/include/llvm/Object/SymbolicFile.h @@ -168,7 +168,7 @@ public: // construction aux. static Expected<std::unique_ptr<SymbolicFile>> createSymbolicFile(MemoryBufferRef Object, llvm::file_magic Type, - LLVMContext *Context, bool InitContent = true); + LLVMContext *Context, bool InitContent = true); static Expected<std::unique_ptr<SymbolicFile>> createSymbolicFile(MemoryBufferRef Object) { @@ -178,8 +178,8 @@ public: static bool classof(const Binary *v) { return v->isSymbolic(); } - - static bool isSymbolicFile(file_magic Type, const LLVMContext *Context); + + static bool isSymbolicFile(file_magic Type, const LLVMContext *Context); }; inline BasicSymbolRef::BasicSymbolRef(DataRefImpl SymbolP, diff --git a/contrib/libs/llvm12/include/llvm/Object/Wasm.h b/contrib/libs/llvm12/include/llvm/Object/Wasm.h index 80e3ddd109..ab1fbba6be 100644 --- a/contrib/libs/llvm12/include/llvm/Object/Wasm.h +++ b/contrib/libs/llvm12/include/llvm/Object/Wasm.h @@ -43,15 +43,15 @@ class WasmSymbol { public: WasmSymbol(const wasm::WasmSymbolInfo &Info, const wasm::WasmGlobalType *GlobalType, - const wasm::WasmTableType *TableType, + const wasm::WasmTableType *TableType, const wasm::WasmEventType *EventType, const wasm::WasmSignature *Signature) - : Info(Info), GlobalType(GlobalType), TableType(TableType), - EventType(EventType), Signature(Signature) {} + : Info(Info), GlobalType(GlobalType), TableType(TableType), + EventType(EventType), Signature(Signature) {} const wasm::WasmSymbolInfo &Info; const wasm::WasmGlobalType *GlobalType; - const wasm::WasmTableType *TableType; + const wasm::WasmTableType *TableType; const wasm::WasmEventType *EventType; const wasm::WasmSignature *Signature; @@ -59,8 +59,8 @@ public: return Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION; } - bool isTypeTable() const { return Info.Kind == wasm::WASM_SYMBOL_TYPE_TABLE; } - + bool isTypeTable() const { return Info.Kind == wasm::WASM_SYMBOL_TYPE_TABLE; } + bool isTypeData() const { return Info.Kind == wasm::WASM_SYMBOL_TYPE_DATA; } bool isTypeGlobal() const { @@ -116,7 +116,7 @@ struct WasmSection { uint32_t Type = 0; // Section type (See below) uint32_t Offset = 0; // Offset with in the file StringRef Name; // Section name (User-defined sections only) - uint32_t Comdat = UINT32_MAX; // From the "comdat info" section + uint32_t Comdat = UINT32_MAX; // From the "comdat info" section ArrayRef<uint8_t> Content; // Section content std::vector<wasm::WasmRelocation> Relocations; // Relocations for this section }; @@ -158,10 +158,10 @@ public: ArrayRef<wasm::WasmElemSegment> elements() const { return ElemSegments; } ArrayRef<WasmSegment> dataSegments() const { return DataSegments; } ArrayRef<wasm::WasmFunction> functions() const { return Functions; } - ArrayRef<wasm::WasmDebugName> debugNames() const { return DebugNames; } + ArrayRef<wasm::WasmDebugName> debugNames() const { return DebugNames; } uint32_t startFunction() const { return StartFunction; } uint32_t getNumImportedGlobals() const { return NumImportedGlobals; } - uint32_t getNumImportedTables() const { return NumImportedTables; } + uint32_t getNumImportedTables() const { return NumImportedTables; } uint32_t getNumImportedFunctions() const { return NumImportedFunctions; } uint32_t getNumImportedEvents() const { return NumImportedEvents; } uint32_t getNumSections() const { return Sections.size(); } @@ -227,13 +227,13 @@ private: bool isValidFunctionIndex(uint32_t Index) const; bool isDefinedFunctionIndex(uint32_t Index) const; bool isValidGlobalIndex(uint32_t Index) const; - bool isValidTableIndex(uint32_t Index) const; + bool isValidTableIndex(uint32_t Index) const; bool isDefinedGlobalIndex(uint32_t Index) const; - bool isDefinedTableIndex(uint32_t Index) const; + bool isDefinedTableIndex(uint32_t Index) const; bool isValidEventIndex(uint32_t Index) const; bool isDefinedEventIndex(uint32_t Index) const; bool isValidFunctionSymbol(uint32_t Index) const; - bool isValidTableSymbol(uint32_t Index) const; + bool isValidTableSymbol(uint32_t Index) const; bool isValidGlobalSymbol(uint32_t Index) const; bool isValidEventSymbol(uint32_t Index) const; bool isValidDataSymbol(uint32_t Index) const; @@ -293,22 +293,22 @@ private: llvm::Optional<size_t> DataCount; std::vector<wasm::WasmFunction> Functions; std::vector<WasmSymbol> Symbols; - std::vector<wasm::WasmDebugName> DebugNames; + std::vector<wasm::WasmDebugName> DebugNames; uint32_t StartFunction = -1; bool HasLinkingSection = false; bool HasDylinkSection = false; bool SeenCodeSection = false; - bool HasMemory64 = false; + bool HasMemory64 = false; wasm::WasmLinkingData LinkingData; uint32_t NumImportedGlobals = 0; - uint32_t NumImportedTables = 0; + uint32_t NumImportedTables = 0; uint32_t NumImportedFunctions = 0; uint32_t NumImportedEvents = 0; uint32_t CodeSection = 0; uint32_t DataSection = 0; uint32_t EventSection = 0; uint32_t GlobalSection = 0; - uint32_t TableSection = 0; + uint32_t TableSection = 0; }; class WasmSectionOrderChecker { diff --git a/contrib/libs/llvm12/include/llvm/Object/XCOFFObjectFile.h b/contrib/libs/llvm12/include/llvm/Object/XCOFFObjectFile.h index ba11d43c43..6104dc362c 100644 --- a/contrib/libs/llvm12/include/llvm/Object/XCOFFObjectFile.h +++ b/contrib/libs/llvm12/include/llvm/Object/XCOFFObjectFile.h @@ -20,8 +20,8 @@ #ifndef LLVM_OBJECT_XCOFFOBJECTFILE_H #define LLVM_OBJECT_XCOFFOBJECTFILE_H -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/BinaryFormat/XCOFF.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Endian.h" @@ -379,8 +379,8 @@ public: Expected<ArrayRef<XCOFFRelocation32>> relocations(const XCOFFSectionHeader32 &) const; - - static bool classof(const Binary *B) { return B->isXCOFF(); } + + static bool classof(const Binary *B) { return B->isXCOFF(); } }; // XCOFFObjectFile class XCOFFSymbolRef { @@ -402,103 +402,103 @@ public: bool isFunction() const; }; -class TBVectorExt { - friend class XCOFFTracebackTable; - - uint16_t Data; - uint32_t VecParmsInfo; - - TBVectorExt(StringRef TBvectorStrRef); - -public: - uint8_t getNumberOfVRSaved() const; - bool isVRSavedOnStack() const; - bool hasVarArgs() const; - uint8_t getNumberOfVectorParms() const; - bool hasVMXInstruction() const; - SmallString<32> getVectorParmsInfoString() const; -}; - -/// This class provides methods to extract traceback table data from a buffer. -/// The various accessors may reference the buffer provided via the constructor. - -class XCOFFTracebackTable { - const uint8_t *const TBPtr; - Optional<SmallString<32>> ParmsType; - Optional<uint32_t> TraceBackTableOffset; - Optional<uint32_t> HandlerMask; - Optional<uint32_t> NumOfCtlAnchors; - Optional<SmallVector<uint32_t, 8>> ControlledStorageInfoDisp; - Optional<StringRef> FunctionName; - Optional<uint8_t> AllocaRegister; - Optional<TBVectorExt> VecExt; - Optional<uint8_t> ExtensionTable; - - XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size, Error &Err); -public: - /// Parse an XCOFF Traceback Table from \a Ptr with \a Size bytes. - /// Returns an XCOFFTracebackTable upon successful parsing, otherwise an - /// Error is returned. - /// - /// \param[in] Ptr - /// A pointer that points just past the initial 4 bytes of zeros at the - /// beginning of an XCOFF Traceback Table. - /// - /// \param[in, out] Size - /// A pointer that points to the length of the XCOFF Traceback Table. - /// If the XCOFF Traceback Table is not parsed successfully or there are - /// extra bytes that are not recognized, \a Size will be updated to be the - /// size up to the end of the last successfully parsed field of the table. - static Expected<XCOFFTracebackTable> create(const uint8_t *Ptr, - uint64_t &Size); - uint8_t getVersion() const; - uint8_t getLanguageID() const; - - bool isGlobalLinkage() const; - bool isOutOfLineEpilogOrPrologue() const; - bool hasTraceBackTableOffset() const; - bool isInternalProcedure() const; - bool hasControlledStorage() const; - bool isTOCless() const; - bool isFloatingPointPresent() const; - bool isFloatingPointOperationLogOrAbortEnabled() const; - - bool isInterruptHandler() const; - bool isFuncNamePresent() const; - bool isAllocaUsed() const; - uint8_t getOnConditionDirective() const; - bool isCRSaved() const; - bool isLRSaved() const; - - bool isBackChainStored() const; - bool isFixup() const; - uint8_t getNumOfFPRsSaved() const; - - bool hasVectorInfo() const; - bool hasExtensionTable() const; - uint8_t getNumOfGPRsSaved() const; - - uint8_t getNumberOfFixedParms() const; - - uint8_t getNumberOfFPParms() const; - bool hasParmsOnStack() const; - - const Optional<SmallString<32>> &getParmsType() const { return ParmsType; } - const Optional<uint32_t> &getTraceBackTableOffset() const { - return TraceBackTableOffset; - } - const Optional<uint32_t> &getHandlerMask() const { return HandlerMask; } - const Optional<uint32_t> &getNumOfCtlAnchors() { return NumOfCtlAnchors; } - const Optional<SmallVector<uint32_t, 8>> &getControlledStorageInfoDisp() { - return ControlledStorageInfoDisp; - } - const Optional<StringRef> &getFunctionName() const { return FunctionName; } - const Optional<uint8_t> &getAllocaRegister() const { return AllocaRegister; } - const Optional<TBVectorExt> &getVectorExt() const { return VecExt; } - const Optional<uint8_t> &getExtensionTable() const { return ExtensionTable; } -}; - -bool doesXCOFFTracebackTableBegin(ArrayRef<uint8_t> Bytes); +class TBVectorExt { + friend class XCOFFTracebackTable; + + uint16_t Data; + uint32_t VecParmsInfo; + + TBVectorExt(StringRef TBvectorStrRef); + +public: + uint8_t getNumberOfVRSaved() const; + bool isVRSavedOnStack() const; + bool hasVarArgs() const; + uint8_t getNumberOfVectorParms() const; + bool hasVMXInstruction() const; + SmallString<32> getVectorParmsInfoString() const; +}; + +/// This class provides methods to extract traceback table data from a buffer. +/// The various accessors may reference the buffer provided via the constructor. + +class XCOFFTracebackTable { + const uint8_t *const TBPtr; + Optional<SmallString<32>> ParmsType; + Optional<uint32_t> TraceBackTableOffset; + Optional<uint32_t> HandlerMask; + Optional<uint32_t> NumOfCtlAnchors; + Optional<SmallVector<uint32_t, 8>> ControlledStorageInfoDisp; + Optional<StringRef> FunctionName; + Optional<uint8_t> AllocaRegister; + Optional<TBVectorExt> VecExt; + Optional<uint8_t> ExtensionTable; + + XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size, Error &Err); +public: + /// Parse an XCOFF Traceback Table from \a Ptr with \a Size bytes. + /// Returns an XCOFFTracebackTable upon successful parsing, otherwise an + /// Error is returned. + /// + /// \param[in] Ptr + /// A pointer that points just past the initial 4 bytes of zeros at the + /// beginning of an XCOFF Traceback Table. + /// + /// \param[in, out] Size + /// A pointer that points to the length of the XCOFF Traceback Table. + /// If the XCOFF Traceback Table is not parsed successfully or there are + /// extra bytes that are not recognized, \a Size will be updated to be the + /// size up to the end of the last successfully parsed field of the table. + static Expected<XCOFFTracebackTable> create(const uint8_t *Ptr, + uint64_t &Size); + uint8_t getVersion() const; + uint8_t getLanguageID() const; + + bool isGlobalLinkage() const; + bool isOutOfLineEpilogOrPrologue() const; + bool hasTraceBackTableOffset() const; + bool isInternalProcedure() const; + bool hasControlledStorage() const; + bool isTOCless() const; + bool isFloatingPointPresent() const; + bool isFloatingPointOperationLogOrAbortEnabled() const; + + bool isInterruptHandler() const; + bool isFuncNamePresent() const; + bool isAllocaUsed() const; + uint8_t getOnConditionDirective() const; + bool isCRSaved() const; + bool isLRSaved() const; + + bool isBackChainStored() const; + bool isFixup() const; + uint8_t getNumOfFPRsSaved() const; + + bool hasVectorInfo() const; + bool hasExtensionTable() const; + uint8_t getNumOfGPRsSaved() const; + + uint8_t getNumberOfFixedParms() const; + + uint8_t getNumberOfFPParms() const; + bool hasParmsOnStack() const; + + const Optional<SmallString<32>> &getParmsType() const { return ParmsType; } + const Optional<uint32_t> &getTraceBackTableOffset() const { + return TraceBackTableOffset; + } + const Optional<uint32_t> &getHandlerMask() const { return HandlerMask; } + const Optional<uint32_t> &getNumOfCtlAnchors() { return NumOfCtlAnchors; } + const Optional<SmallVector<uint32_t, 8>> &getControlledStorageInfoDisp() { + return ControlledStorageInfoDisp; + } + const Optional<StringRef> &getFunctionName() const { return FunctionName; } + const Optional<uint8_t> &getAllocaRegister() const { return AllocaRegister; } + const Optional<TBVectorExt> &getVectorExt() const { return VecExt; } + const Optional<uint8_t> &getExtensionTable() const { return ExtensionTable; } +}; + +bool doesXCOFFTracebackTableBegin(ArrayRef<uint8_t> Bytes); } // namespace object } // namespace llvm |