diff options
Diffstat (limited to 'lld/ELF/InputSection.h')
| -rw-r--r-- | lld/ELF/InputSection.h | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index bff9ec324d9b..1a5bc629d8b0 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -78,6 +78,12 @@ public: uint8_t partition = 1; uint32_t type; + + // The file which contains this section. For InputSectionBase, its dynamic + // type is usually ObjFile<ELFT>, but may be an InputFile of InternalKind + // (for a synthetic section). + InputFile *file; + StringRef name; // The 1-indexed partition that this section is assigned to by the garbage @@ -92,6 +98,7 @@ public: uint32_t link; uint32_t info; + Ctx &getCtx() const; OutputSection *getOutputSection(); const OutputSection *getOutputSection() const { return const_cast<SectionBase *>(this)->getOutputSection(); @@ -108,12 +115,12 @@ public: void markDead() { partition = 0; } protected: - constexpr SectionBase(Kind sectionKind, StringRef name, uint64_t flags, - uint32_t entsize, uint32_t addralign, uint32_t type, - uint32_t info, uint32_t link) + constexpr SectionBase(Kind sectionKind, InputFile *file, StringRef name, + uint64_t flags, uint32_t entsize, uint32_t addralign, + uint32_t type, uint32_t info, uint32_t link) : sectionKind(sectionKind), bss(false), keepUnique(false), type(type), - name(name), flags(flags), addralign(addralign), entsize(entsize), - link(link), info(info) {} + file(file), name(name), flags(flags), addralign(addralign), + entsize(entsize), link(link), info(info) {} }; struct SymbolAnchor { @@ -150,11 +157,6 @@ public: return s->kind() != Output && s->kind() != Class; } - // The file which contains this section. Its dynamic type is usually - // ObjFile<ELFT>, but may be an InputFile of InternalKind (for a synthetic - // section). - InputFile *file; - // Input sections are part of an output section. Special sections // like .eh_frame and merge sections are first combined into a // synthetic section that is then added to an output section. In all @@ -243,7 +245,7 @@ public: // Each section knows how to relocate itself. These functions apply // relocations, assuming that Buf points to this section's copy in // the mmap'ed output buffer. - template <class ELFT> void relocate(uint8_t *buf, uint8_t *bufEnd); + template <class ELFT> void relocate(Ctx &, uint8_t *buf, uint8_t *bufEnd); uint64_t getRelocTargetVA(Ctx &, const Relocation &r, uint64_t p) const; // The native ELF reloc data type is not very convenient to handle. @@ -276,8 +278,7 @@ public: // to relocation. See https://gcc.gnu.org/wiki/SplitStacks for more // information. template <typename ELFT> - void adjustSplitStackFunctionPrologues(uint8_t *buf, uint8_t *end); - + void adjustSplitStackFunctionPrologues(Ctx &, uint8_t *buf, uint8_t *end); template <typename T> llvm::ArrayRef<T> getDataAs() const { size_t s = content().size(); @@ -315,7 +316,7 @@ public: template <class ELFT> MergeInputSection(ObjFile<ELFT> &f, const typename ELFT::Shdr &header, StringRef name); - MergeInputSection(uint64_t flags, uint32_t type, uint64_t entsize, + MergeInputSection(Ctx &, uint64_t flags, uint32_t type, uint64_t entsize, ArrayRef<uint8_t> data, StringRef name); static bool classof(const SectionBase *s) { return s->kind() == Merge; } @@ -408,7 +409,7 @@ public: // Write this section to a mmap'ed file, assuming Buf is pointing to // beginning of the output section. - template <class ELFT> void writeTo(uint8_t *buf); + template <class ELFT> void writeTo(Ctx &, uint8_t *buf); OutputSection *getParent() const { return reinterpret_cast<OutputSection *>(parent); @@ -423,7 +424,7 @@ public: InputSectionBase *getRelocatedSection() const; template <class ELFT, class RelTy> - void relocateNonAlloc(uint8_t *buf, Relocs<RelTy> rels); + void relocateNonAlloc(Ctx &, uint8_t *buf, Relocs<RelTy> rels); // Points to the canonical section. If ICF folds two sections, repl pointer of // one section points to the other. @@ -438,10 +439,10 @@ public: static InputSection discarded; private: - template <class ELFT, class RelTy> void copyRelocations(uint8_t *buf); + template <class ELFT, class RelTy> void copyRelocations(Ctx &, uint8_t *buf); template <class ELFT, class RelTy, class RelIt> - void copyRelocations(uint8_t *buf, llvm::iterator_range<RelIt> rels); + void copyRelocations(Ctx &, uint8_t *buf, llvm::iterator_range<RelIt> rels); template <class ELFT> void copyShtGroup(uint8_t *buf); }; @@ -470,19 +471,21 @@ static_assert(sizeof(InputSection) <= 160, "InputSection is too big"); class SyntheticSection : public InputSection { public: - SyntheticSection(uint64_t flags, uint32_t type, uint32_t addralign, + Ctx &ctx; + SyntheticSection(Ctx &ctx, uint64_t flags, uint32_t type, uint32_t addralign, StringRef name) : InputSection(ctx.internalFile, flags, type, addralign, {}, name, - InputSectionBase::Synthetic) {} + InputSectionBase::Synthetic), + ctx(ctx) {} virtual ~SyntheticSection() = default; - virtual size_t getSize(Ctx &) const = 0; + virtual size_t getSize() const = 0; virtual bool updateAllocSize(Ctx &) { return false; } // If the section has the SHF_ALLOC flag and the size may be changed if // thunks are added, update the section size. - virtual bool isNeeded(Ctx &) const { return true; } - virtual void finalizeContents(Ctx &) {} - virtual void writeTo(Ctx &, uint8_t *buf) = 0; + virtual bool isNeeded() const { return true; } + virtual void finalizeContents() {} + virtual void writeTo(uint8_t *buf) = 0; static bool classof(const SectionBase *sec) { return sec->kind() == InputSectionBase::Synthetic; |
