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/tools/llvm-objcopy/ELF/Object.h | |
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/tools/llvm-objcopy/ELF/Object.h')
-rw-r--r-- | contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h | 276 |
1 files changed, 138 insertions, 138 deletions
diff --git a/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h b/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h index 0205c2d4f3..01caa5d42a 100644 --- a/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h +++ b/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h @@ -61,11 +61,11 @@ public: iterator end() const { return iterator(Sections.data() + Sections.size()); } size_t size() const { return Sections.size(); } - Expected<SectionBase *> getSection(uint32_t Index, Twine ErrMsg); + Expected<SectionBase *> getSection(uint32_t Index, Twine ErrMsg); template <class T> - Expected<T *> getSectionOfType(uint32_t Index, Twine IndexErrMsg, - Twine TypeErrMsg); + Expected<T *> getSectionOfType(uint32_t Index, Twine IndexErrMsg, + Twine TypeErrMsg); }; enum ElfType { ELFT_ELF32LE, ELFT_ELF64LE, ELFT_ELF32BE, ELFT_ELF64BE }; @@ -74,34 +74,34 @@ class SectionVisitor { public: virtual ~SectionVisitor() = default; - virtual Error visit(const Section &Sec) = 0; - virtual Error visit(const OwnedDataSection &Sec) = 0; - virtual Error visit(const StringTableSection &Sec) = 0; - virtual Error visit(const SymbolTableSection &Sec) = 0; - virtual Error visit(const RelocationSection &Sec) = 0; - virtual Error visit(const DynamicRelocationSection &Sec) = 0; - virtual Error visit(const GnuDebugLinkSection &Sec) = 0; - virtual Error visit(const GroupSection &Sec) = 0; - virtual Error visit(const SectionIndexSection &Sec) = 0; - virtual Error visit(const CompressedSection &Sec) = 0; - virtual Error visit(const DecompressedSection &Sec) = 0; + virtual Error visit(const Section &Sec) = 0; + virtual Error visit(const OwnedDataSection &Sec) = 0; + virtual Error visit(const StringTableSection &Sec) = 0; + virtual Error visit(const SymbolTableSection &Sec) = 0; + virtual Error visit(const RelocationSection &Sec) = 0; + virtual Error visit(const DynamicRelocationSection &Sec) = 0; + virtual Error visit(const GnuDebugLinkSection &Sec) = 0; + virtual Error visit(const GroupSection &Sec) = 0; + virtual Error visit(const SectionIndexSection &Sec) = 0; + virtual Error visit(const CompressedSection &Sec) = 0; + virtual Error visit(const DecompressedSection &Sec) = 0; }; class MutableSectionVisitor { public: virtual ~MutableSectionVisitor() = default; - virtual Error visit(Section &Sec) = 0; - virtual Error visit(OwnedDataSection &Sec) = 0; - virtual Error visit(StringTableSection &Sec) = 0; - virtual Error visit(SymbolTableSection &Sec) = 0; - virtual Error visit(RelocationSection &Sec) = 0; - virtual Error visit(DynamicRelocationSection &Sec) = 0; - virtual Error visit(GnuDebugLinkSection &Sec) = 0; - virtual Error visit(GroupSection &Sec) = 0; - virtual Error visit(SectionIndexSection &Sec) = 0; - virtual Error visit(CompressedSection &Sec) = 0; - virtual Error visit(DecompressedSection &Sec) = 0; + virtual Error visit(Section &Sec) = 0; + virtual Error visit(OwnedDataSection &Sec) = 0; + virtual Error visit(StringTableSection &Sec) = 0; + virtual Error visit(SymbolTableSection &Sec) = 0; + virtual Error visit(RelocationSection &Sec) = 0; + virtual Error visit(DynamicRelocationSection &Sec) = 0; + virtual Error visit(GnuDebugLinkSection &Sec) = 0; + virtual Error visit(GroupSection &Sec) = 0; + virtual Error visit(SectionIndexSection &Sec) = 0; + virtual Error visit(CompressedSection &Sec) = 0; + virtual Error visit(DecompressedSection &Sec) = 0; }; class SectionWriter : public SectionVisitor { @@ -111,17 +111,17 @@ protected: public: virtual ~SectionWriter() = default; - Error visit(const Section &Sec) override; - Error visit(const OwnedDataSection &Sec) override; - Error visit(const StringTableSection &Sec) override; - Error visit(const DynamicRelocationSection &Sec) override; - virtual Error visit(const SymbolTableSection &Sec) override = 0; - virtual Error visit(const RelocationSection &Sec) override = 0; - virtual Error visit(const GnuDebugLinkSection &Sec) override = 0; - virtual Error visit(const GroupSection &Sec) override = 0; - virtual Error visit(const SectionIndexSection &Sec) override = 0; - virtual Error visit(const CompressedSection &Sec) override = 0; - virtual Error visit(const DecompressedSection &Sec) override = 0; + Error visit(const Section &Sec) override; + Error visit(const OwnedDataSection &Sec) override; + Error visit(const StringTableSection &Sec) override; + Error visit(const DynamicRelocationSection &Sec) override; + virtual Error visit(const SymbolTableSection &Sec) override = 0; + virtual Error visit(const RelocationSection &Sec) override = 0; + virtual Error visit(const GnuDebugLinkSection &Sec) override = 0; + virtual Error visit(const GroupSection &Sec) override = 0; + virtual Error visit(const SectionIndexSection &Sec) override = 0; + virtual Error visit(const CompressedSection &Sec) override = 0; + virtual Error visit(const DecompressedSection &Sec) override = 0; explicit SectionWriter(Buffer &Buf) : Out(Buf) {} }; @@ -135,13 +135,13 @@ private: public: virtual ~ELFSectionWriter() {} - Error visit(const SymbolTableSection &Sec) override; - Error visit(const RelocationSection &Sec) override; - Error visit(const GnuDebugLinkSection &Sec) override; - Error visit(const GroupSection &Sec) override; - Error visit(const SectionIndexSection &Sec) override; - Error visit(const CompressedSection &Sec) override; - Error visit(const DecompressedSection &Sec) override; + Error visit(const SymbolTableSection &Sec) override; + Error visit(const RelocationSection &Sec) override; + Error visit(const GnuDebugLinkSection &Sec) override; + Error visit(const GroupSection &Sec) override; + Error visit(const SectionIndexSection &Sec) override; + Error visit(const CompressedSection &Sec) override; + Error visit(const DecompressedSection &Sec) override; explicit ELFSectionWriter(Buffer &Buf) : SectionWriter(Buf) {} }; @@ -155,17 +155,17 @@ private: using Elf_Xword = typename ELFT::Xword; public: - Error visit(Section &Sec) override; - Error visit(OwnedDataSection &Sec) override; - Error visit(StringTableSection &Sec) override; - Error visit(DynamicRelocationSection &Sec) override; - Error visit(SymbolTableSection &Sec) override; - Error visit(RelocationSection &Sec) override; - Error visit(GnuDebugLinkSection &Sec) override; - Error visit(GroupSection &Sec) override; - Error visit(SectionIndexSection &Sec) override; - Error visit(CompressedSection &Sec) override; - Error visit(DecompressedSection &Sec) override; + Error visit(Section &Sec) override; + Error visit(OwnedDataSection &Sec) override; + Error visit(StringTableSection &Sec) override; + Error visit(DynamicRelocationSection &Sec) override; + Error visit(SymbolTableSection &Sec) override; + Error visit(RelocationSection &Sec) override; + Error visit(GnuDebugLinkSection &Sec) override; + Error visit(GroupSection &Sec) override; + Error visit(SectionIndexSection &Sec) override; + Error visit(CompressedSection &Sec) override; + Error visit(DecompressedSection &Sec) override; }; #define MAKE_SEC_WRITER_FRIEND \ @@ -179,13 +179,13 @@ class BinarySectionWriter : public SectionWriter { public: virtual ~BinarySectionWriter() {} - Error visit(const SymbolTableSection &Sec) override; - Error visit(const RelocationSection &Sec) override; - Error visit(const GnuDebugLinkSection &Sec) override; - Error visit(const GroupSection &Sec) override; - Error visit(const SectionIndexSection &Sec) override; - Error visit(const CompressedSection &Sec) override; - Error visit(const DecompressedSection &Sec) override; + Error visit(const SymbolTableSection &Sec) override; + Error visit(const RelocationSection &Sec) override; + Error visit(const GnuDebugLinkSection &Sec) override; + Error visit(const GroupSection &Sec) override; + Error visit(const SectionIndexSection &Sec) override; + Error visit(const CompressedSection &Sec) override; + Error visit(const DecompressedSection &Sec) override; explicit BinarySectionWriter(Buffer &Buf) : SectionWriter(Buf) {} }; @@ -286,10 +286,10 @@ public: explicit IHexSectionWriterBase(Buffer &Buf) : BinarySectionWriter(Buf) {} uint64_t getBufferOffset() const { return Offset; } - Error visit(const Section &Sec) final; - Error visit(const OwnedDataSection &Sec) final; - Error visit(const StringTableSection &Sec) override; - Error visit(const DynamicRelocationSection &Sec) final; + Error visit(const Section &Sec) final; + Error visit(const OwnedDataSection &Sec) final; + Error visit(const StringTableSection &Sec) override; + Error visit(const DynamicRelocationSection &Sec) final; using BinarySectionWriter::visit; }; @@ -299,7 +299,7 @@ public: IHexSectionWriter(Buffer &Buf) : IHexSectionWriterBase(Buf) {} void writeData(uint8_t Type, uint16_t Addr, ArrayRef<uint8_t> Data) override; - Error visit(const StringTableSection &Sec) override; + Error visit(const StringTableSection &Sec) override; }; class Writer { @@ -330,7 +330,7 @@ private: void writePhdrs(); void writeShdrs(); - Error writeSectionData(); + Error writeSectionData(); void writeSegmentData(); void assignOffsets(); @@ -391,7 +391,7 @@ public: uint64_t HeaderOffset = 0; uint32_t Index = 0; - uint32_t OriginalIndex = 0; + uint32_t OriginalIndex = 0; uint64_t OriginalFlags = 0; uint64_t OriginalType = ELF::SHT_NULL; uint64_t OriginalOffset = std::numeric_limits<uint64_t>::max(); @@ -407,22 +407,22 @@ public: uint64_t Size = 0; uint64_t Type = ELF::SHT_NULL; ArrayRef<uint8_t> OriginalData; - bool HasSymbol = false; + bool HasSymbol = false; SectionBase() = default; SectionBase(const SectionBase &) = default; virtual ~SectionBase() = default; - virtual Error initialize(SectionTableRef SecTable); + virtual Error initialize(SectionTableRef SecTable); virtual void finalize(); // Remove references to these sections. The list of sections must be sorted. virtual Error removeSectionReferences(bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove); virtual Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove); - virtual Error accept(SectionVisitor &Visitor) const = 0; - virtual Error accept(MutableSectionVisitor &Visitor) = 0; + virtual Error accept(SectionVisitor &Visitor) const = 0; + virtual Error accept(MutableSectionVisitor &Visitor) = 0; virtual void markSymbols(); virtual void replaceSectionReferences(const DenseMap<SectionBase *, SectionBase *> &); @@ -436,9 +436,9 @@ private: bool operator()(const SectionBase *Lhs, const SectionBase *Rhs) const { // Some sections might have the same address if one of them is empty. To // fix this we can use the lexicographic ordering on ->Addr and the - // original index. + // original index. if (Lhs->OriginalOffset == Rhs->OriginalOffset) - return Lhs->OriginalIndex < Rhs->OriginalIndex; + return Lhs->OriginalIndex < Rhs->OriginalIndex; return Lhs->OriginalOffset < Rhs->OriginalOffset; } }; @@ -483,12 +483,12 @@ class Section : public SectionBase { public: explicit Section(ArrayRef<uint8_t> Data) : Contents(Data) {} - Error accept(SectionVisitor &Visitor) const override; - Error accept(MutableSectionVisitor &Visitor) override; - Error removeSectionReferences( - bool AllowBrokenLinks, + Error accept(SectionVisitor &Visitor) const override; + Error accept(MutableSectionVisitor &Visitor) override; + Error removeSectionReferences( + bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) override; - Error initialize(SectionTableRef SecTable) override; + Error initialize(SectionTableRef SecTable) override; void finalize() override; }; @@ -516,8 +516,8 @@ public: } void appendHexData(StringRef HexData); - Error accept(SectionVisitor &Sec) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &Sec) const override; + Error accept(MutableSectionVisitor &Visitor) override; }; class CompressedSection : public SectionBase { @@ -529,28 +529,28 @@ class CompressedSection : public SectionBase { SmallVector<char, 128> CompressedData; public: - static Expected<CompressedSection> - create(const SectionBase &Sec, DebugCompressionType CompressionType); - static Expected<CompressedSection> create(ArrayRef<uint8_t> CompressedData, - uint64_t DecompressedSize, - uint64_t DecompressedAlign); + static Expected<CompressedSection> + create(const SectionBase &Sec, DebugCompressionType CompressionType); + static Expected<CompressedSection> create(ArrayRef<uint8_t> CompressedData, + uint64_t DecompressedSize, + uint64_t DecompressedAlign); uint64_t getDecompressedSize() const { return DecompressedSize; } uint64_t getDecompressedAlign() const { return DecompressedAlign; } - Error accept(SectionVisitor &Visitor) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &Visitor) const override; + Error accept(MutableSectionVisitor &Visitor) override; static bool classof(const SectionBase *S) { return (S->OriginalFlags & ELF::SHF_COMPRESSED) || (StringRef(S->Name).startswith(".zdebug")); } - -private: - CompressedSection(const SectionBase &Sec, - DebugCompressionType CompressionType, Error &Err); - CompressedSection(ArrayRef<uint8_t> CompressedData, uint64_t DecompressedSize, - uint64_t DecompressedAlign); + +private: + CompressedSection(const SectionBase &Sec, + DebugCompressionType CompressionType, Error &Err); + CompressedSection(ArrayRef<uint8_t> CompressedData, uint64_t DecompressedSize, + uint64_t DecompressedAlign); }; class DecompressedSection : public SectionBase { @@ -566,8 +566,8 @@ public: Name = "." + Name.substr(2); } - Error accept(SectionVisitor &Visitor) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &Visitor) const override; + Error accept(MutableSectionVisitor &Visitor) override; }; // There are two types of string tables that can exist, dynamic and not dynamic. @@ -591,8 +591,8 @@ public: void addString(StringRef Name); uint32_t findIndex(StringRef Name) const; void prepareForLayout(); - Error accept(SectionVisitor &Visitor) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &Visitor) const override; + Error accept(MutableSectionVisitor &Visitor) override; static bool classof(const SectionBase *S) { if (S->OriginalFlags & ELF::SHF_ALLOC) @@ -649,18 +649,18 @@ public: virtual ~SectionIndexSection() {} void addIndex(uint32_t Index) { assert(Size > 0); - Indexes.push_back(Index); + Indexes.push_back(Index); } void reserve(size_t NumSymbols) { Indexes.reserve(NumSymbols); Size = NumSymbols * 4; - } + } void setSymTab(SymbolTableSection *SymTab) { Symbols = SymTab; } - Error initialize(SectionTableRef SecTable) override; + Error initialize(SectionTableRef SecTable) override; void finalize() override; - Error accept(SectionVisitor &Visitor) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &Visitor) const override; + Error accept(MutableSectionVisitor &Visitor) override; SectionIndexSection() { Name = ".symtab_shndx"; @@ -698,17 +698,17 @@ public: const SectionIndexSection *getShndxTable() const { return SectionIndexTable; } void fillShndxTable(); const SectionBase *getStrTab() const { return SymbolNames; } - Expected<const Symbol *> getSymbolByIndex(uint32_t Index) const; - Expected<Symbol *> getSymbolByIndex(uint32_t Index); + Expected<const Symbol *> getSymbolByIndex(uint32_t Index) const; + Expected<Symbol *> getSymbolByIndex(uint32_t Index); void updateSymbols(function_ref<void(Symbol &)> Callable); - Error removeSectionReferences( - bool AllowBrokenLinks, + Error removeSectionReferences( + bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) override; - Error initialize(SectionTableRef SecTable) override; + Error initialize(SectionTableRef SecTable) override; void finalize() override; - Error accept(SectionVisitor &Visitor) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &Visitor) const override; + Error accept(MutableSectionVisitor &Visitor) override; Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override; void replaceSectionReferences( const DenseMap<SectionBase *, SectionBase *> &FromTo) override; @@ -759,7 +759,7 @@ protected: SymTabType *Symbols = nullptr; public: - Error initialize(SectionTableRef SecTable) override; + Error initialize(SectionTableRef SecTable) override; void finalize() override; }; @@ -771,10 +771,10 @@ class RelocationSection public: void addRelocation(Relocation Rel) { Relocations.push_back(Rel); } - Error accept(SectionVisitor &Visitor) const override; - Error accept(MutableSectionVisitor &Visitor) override; - Error removeSectionReferences( - bool AllowBrokenLinks, + Error accept(SectionVisitor &Visitor) const override; + Error accept(MutableSectionVisitor &Visitor) override; + Error removeSectionReferences( + bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) override; Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override; void markSymbols() override; @@ -810,8 +810,8 @@ public: void setFlagWord(ELF::Elf32_Word W) { FlagWord = W; } void addMember(SectionBase *Sec) { GroupMembers.push_back(Sec); } - Error accept(SectionVisitor &) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &) const override; + Error accept(MutableSectionVisitor &Visitor) override; void finalize() override; Error removeSectionReferences( bool AllowBrokenLinks, @@ -855,8 +855,8 @@ private: public: explicit DynamicRelocationSection(ArrayRef<uint8_t> Data) : Contents(Data) {} - Error accept(SectionVisitor &) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &) const override; + Error accept(MutableSectionVisitor &Visitor) override; Error removeSectionReferences( bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) override; @@ -880,14 +880,14 @@ private: public: // If we add this section from an external source we can use this ctor. explicit GnuDebugLinkSection(StringRef File, uint32_t PrecomputedCRC); - Error accept(SectionVisitor &Visitor) const override; - Error accept(MutableSectionVisitor &Visitor) override; + Error accept(SectionVisitor &Visitor) const override; + Error accept(MutableSectionVisitor &Visitor) override; }; class Reader { public: virtual ~Reader(); - virtual Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const = 0; + virtual Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const = 0; }; using object::Binary; @@ -903,7 +903,7 @@ protected: void initHeaderSegment(); StringTableSection *addStrTab(); SymbolTableSection *addSymTab(StringTableSection *StrTab); - Error initSections(); + Error initSections(); public: BasicELFBuilder() : Obj(std::make_unique<Object>()) {} @@ -919,7 +919,7 @@ public: : BasicELFBuilder(), MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {} - Expected<std::unique_ptr<Object>> build(); + Expected<std::unique_ptr<Object>> build(); }; class IHexELFBuilder : public BasicELFBuilder { @@ -931,7 +931,7 @@ public: IHexELFBuilder(const std::vector<IHexRecord> &Records) : BasicELFBuilder(), Records(Records) {} - Expected<std::unique_ptr<Object>> build(); + Expected<std::unique_ptr<Object>> build(); }; template <class ELFT> class ELFBuilder { @@ -946,21 +946,21 @@ private: Optional<StringRef> ExtractPartition; void setParentSegment(Segment &Child); - Error readProgramHeaders(const ELFFile<ELFT> &HeadersFile); - Error initGroupSection(GroupSection *GroupSec); - Error initSymbolTable(SymbolTableSection *SymTab); - Error readSectionHeaders(); - Error readSections(bool EnsureSymtab); - Error findEhdrOffset(); - Expected<SectionBase &> makeSection(const Elf_Shdr &Shdr); + Error readProgramHeaders(const ELFFile<ELFT> &HeadersFile); + Error initGroupSection(GroupSection *GroupSec); + Error initSymbolTable(SymbolTableSection *SymTab); + Error readSectionHeaders(); + Error readSections(bool EnsureSymtab); + Error findEhdrOffset(); + Expected<SectionBase &> makeSection(const Elf_Shdr &Shdr); public: ELFBuilder(const ELFObjectFile<ELFT> &ElfObj, Object &Obj, Optional<StringRef> ExtractPartition) - : ElfFile(ElfObj.getELFFile()), Obj(Obj), + : ElfFile(ElfObj.getELFFile()), Obj(Obj), ExtractPartition(ExtractPartition) {} - Error build(bool EnsureSymtab); + Error build(bool EnsureSymtab); }; class BinaryReader : public Reader { @@ -970,7 +970,7 @@ class BinaryReader : public Reader { public: BinaryReader(MemoryBuffer *MB, const uint8_t NewSymbolVisibility) : MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {} - Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override; + Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override; }; class IHexReader : public Reader { @@ -992,7 +992,7 @@ class IHexReader : public Reader { public: IHexReader(MemoryBuffer *MB) : MemBuf(MB) {} - Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override; + Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override; }; class ELFReader : public Reader { @@ -1000,7 +1000,7 @@ class ELFReader : public Reader { Optional<StringRef> ExtractPartition; public: - Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override; + Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override; explicit ELFReader(Binary *B, Optional<StringRef> ExtractPartition) : Bin(B), ExtractPartition(ExtractPartition) {} }; @@ -1084,7 +1084,7 @@ public: Ptr->Index = Sections.size(); return *Ptr; } - Error addNewSymbolTable(); + Error addNewSymbolTable(); Segment &addSegment(ArrayRef<uint8_t> Data) { Segments.emplace_back(std::make_unique<Segment>(Data)); return *Segments.back(); |