diff options
Diffstat (limited to 'llvm/tools/llvm-objcopy/Object.h')
-rw-r--r-- | llvm/tools/llvm-objcopy/Object.h | 65 |
1 files changed, 45 insertions, 20 deletions
diff --git a/llvm/tools/llvm-objcopy/Object.h b/llvm/tools/llvm-objcopy/Object.h index 27beafc0ce6..36bd65b8cf2 100644 --- a/llvm/tools/llvm-objcopy/Object.h +++ b/llvm/tools/llvm-objcopy/Object.h @@ -35,17 +35,17 @@ class SymbolTableSection; class RelocationSection; class DynamicRelocationSection; class GnuDebugLinkSection; +class GroupSection; class Segment; class Object; class SectionTableRef { -private: MutableArrayRef<std::unique_ptr<SectionBase>> Sections; public: using iterator = pointee_iterator<std::unique_ptr<SectionBase> *>; - SectionTableRef(MutableArrayRef<std::unique_ptr<SectionBase>> Secs) + explicit SectionTableRef(MutableArrayRef<std::unique_ptr<SectionBase>> Secs) : Sections(Secs) {} SectionTableRef(const SectionTableRef &) = default; @@ -71,6 +71,7 @@ public: virtual void visit(const RelocationSection &Sec) = 0; virtual void visit(const DynamicRelocationSection &Sec) = 0; virtual void visit(const GnuDebugLinkSection &Sec) = 0; + virtual void visit(const GroupSection &Sec) = 0; }; class SectionWriter : public SectionVisitor { @@ -87,6 +88,7 @@ public: virtual void visit(const SymbolTableSection &Sec) override = 0; virtual void visit(const RelocationSection &Sec) override = 0; virtual void visit(const GnuDebugLinkSection &Sec) override = 0; + virtual void visit(const GroupSection &Sec) override = 0; SectionWriter(FileOutputBuffer &Buf) : Out(Buf) {} }; @@ -102,6 +104,7 @@ public: void visit(const SymbolTableSection &Sec) override; void visit(const RelocationSection &Sec) override; void visit(const GnuDebugLinkSection &Sec) override; + void visit(const GroupSection &Sec) override; ELFSectionWriter(FileOutputBuffer &Buf) : SectionWriter(Buf) {} }; @@ -117,6 +120,8 @@ public: void visit(const SymbolTableSection &Sec) override; void visit(const RelocationSection &Sec) override; void visit(const GnuDebugLinkSection &Sec) override; + void visit(const GroupSection &Sec) override; + BinarySectionWriter(FileOutputBuffer &Buf) : SectionWriter(Buf) {} }; @@ -237,7 +242,7 @@ public: uint64_t OriginalOffset; Segment *ParentSegment = nullptr; - Segment(ArrayRef<uint8_t> Data) : Contents(Data) {} + explicit Segment(ArrayRef<uint8_t> Data) : Contents(Data) {} Segment() {} const SectionBase *firstSection() const { @@ -253,11 +258,10 @@ public: class Section : public SectionBase { MAKE_SEC_WRITER_FRIEND -private: ArrayRef<uint8_t> Contents; public: - Section(ArrayRef<uint8_t> Data) : Contents(Data) {} + explicit Section(ArrayRef<uint8_t> Data) : Contents(Data) {} void accept(SectionVisitor &Visitor) const override; }; @@ -265,7 +269,6 @@ public: class OwnedDataSection : public SectionBase { MAKE_SEC_WRITER_FRIEND -private: std::vector<uint8_t> Data; public: @@ -291,7 +294,6 @@ public: class StringTableSection : public SectionBase { MAKE_SEC_WRITER_FRIEND -private: StringTableBuilder StrTabBuilder; public: @@ -344,6 +346,7 @@ class SymbolTableSection : public SectionBase { MAKE_SEC_WRITER_FRIEND void setStrTab(StringTableSection *StrTab) { SymbolNames = StrTab; } + void assignIndices(); protected: std::vector<std::unique_ptr<Symbol>> Symbols; @@ -402,7 +405,6 @@ public: // that code between the two symbol table types. template <class SymTabType> class RelocSectionWithSymtabBase : public RelocationSectionBase { -private: SymTabType *Symbols = nullptr; void setSymTab(SymTabType *SymTab) { Symbols = SymTab; } @@ -419,7 +421,6 @@ class RelocationSection : public RelocSectionWithSymtabBase<SymbolTableSection> { MAKE_SEC_WRITER_FRIEND -private: std::vector<Relocation> Relocations; public: @@ -433,14 +434,37 @@ public: } }; -class SectionWithStrTab : public Section { -private: - const SectionBase *StrTab = nullptr; +// TODO: The way stripping and groups interact is complicated +// and still needs to be worked on. + +class GroupSection : public SectionBase { + MAKE_SEC_WRITER_FRIEND + // TODO: Contents is present in several classes of the hierarchy. + // This needs to be refactored to avoid duplication. + ArrayRef<uint8_t> Contents; + ELF::Elf32_Word FlagWord; + SmallVector<SectionBase *, 3> GroupMembers; + const SymbolTableSection *SymTab = nullptr; + const Symbol *Sym = nullptr; public: - SectionWithStrTab(ArrayRef<uint8_t> Data) : Section(Data) {} + explicit GroupSection(ArrayRef<uint8_t> Data) : Contents(Data) {} + + void initialize(SectionTableRef SecTable) override; + void accept(SectionVisitor &) const override; + void finalize() override; + + static bool classof(const SectionBase *S) { + return S->Type == ELF::SHT_GROUP; + } +}; +class SectionWithStrTab : public Section { + const SectionBase *StrTab = nullptr; void setStrTab(const SectionBase *StringTable) { StrTab = StringTable; } + +public: + explicit SectionWithStrTab(ArrayRef<uint8_t> Data) : Section(Data) {} void removeSectionReferences(const SectionBase *Sec) override; void initialize(SectionTableRef SecTable) override; void finalize() override; @@ -449,7 +473,8 @@ public: class DynamicSymbolTableSection : public SectionWithStrTab { public: - DynamicSymbolTableSection(ArrayRef<uint8_t> Data) : SectionWithStrTab(Data) {} + explicit DynamicSymbolTableSection(ArrayRef<uint8_t> Data) + : SectionWithStrTab(Data) {} static bool classof(const SectionBase *S) { return S->Type == ELF::SHT_DYNSYM; @@ -458,7 +483,7 @@ public: class DynamicSection : public SectionWithStrTab { public: - DynamicSection(ArrayRef<uint8_t> Data) : SectionWithStrTab(Data) {} + explicit DynamicSection(ArrayRef<uint8_t> Data) : SectionWithStrTab(Data) {} static bool classof(const SectionBase *S) { return S->Type == ELF::SHT_DYNAMIC; @@ -473,7 +498,7 @@ private: ArrayRef<uint8_t> Contents; public: - DynamicRelocationSection(ArrayRef<uint8_t> Data) : Contents(Data) {} + explicit DynamicRelocationSection(ArrayRef<uint8_t> Data) : Contents(Data) {} void accept(SectionVisitor &) const override; @@ -488,7 +513,6 @@ class GnuDebugLinkSection : public SectionBase { MAKE_SEC_WRITER_FRIEND private: - StringRef FileName; uint32_t CRC32; @@ -496,7 +520,7 @@ private: public: // If we add this section from an external source we can use this ctor. - GnuDebugLinkSection(StringRef File); + explicit GnuDebugLinkSection(StringRef File); void accept(SectionVisitor &Visitor) const override; }; @@ -506,10 +530,10 @@ public: virtual std::unique_ptr<Object> create() const = 0; }; -using object::OwningBinary; using object::Binary; using object::ELFFile; using object::ELFObjectFile; +using object::OwningBinary; template <class ELFT> class ELFBuilder { private: @@ -582,7 +606,8 @@ public: StringTableSection *SectionNames = nullptr; SymbolTableSection *SymbolTable = nullptr; - Object(std::shared_ptr<MemoryBuffer> Data) : OwnedData(Data) {} + explicit Object(std::shared_ptr<MemoryBuffer> Data) + : OwnedData(std::move(Data)) {} virtual ~Object() = default; void sortSections(); |