//===- InputSection.h -------------------------------------------*- C++ -*-===// // // The LLVM Linker // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef LLD_ELF_INPUT_SECTION_H #define LLD_ELF_INPUT_SECTION_H #include "lld/Core/LLVM.h" #include "llvm/Object/ELF.h" namespace lld { namespace elf2 { template class ObjectFile; template class OutputSection; template class PltSection; template class GotSection; // This corresponds to a section of an input file. template class InputSection { typedef typename llvm::object::ELFFile::Elf_Shdr Elf_Shdr; typedef typename llvm::object::ELFFile::Elf_Rela Elf_Rela; typedef typename llvm::object::ELFFile::Elf_Rel Elf_Rel; typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; typedef typename llvm::object::ELFFile::uintX_t uintX_t; public: InputSection(ObjectFile *F, const Elf_Shdr *Header); // Returns the size of this section (even if this is a common or BSS.) size_t getSize() const { return Header->sh_size; } // Write this section to a mmap'ed file, assuming Buf is pointing to // beginning of the output section. void writeTo(uint8_t *Buf, const OutputSection &BssSec, const PltSection &PltSec, const GotSection &GotSec); StringRef getSectionName() const; const Elf_Shdr *getSectionHdr() const { return Header; } const ObjectFile *getFile() const { return File; } // The writer sets and uses the addresses. uintX_t getOutputSectionOff() const { return OutputSectionOff; } uintX_t getAlign() { // The ELF spec states that a value of 0 means the section has no alignment // constraits. return std::max(Header->sh_addralign, 1); } void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; } void setOutputSection(OutputSection *O) { Out = O; } OutputSection *getOutputSection() const { return Out; } // Relocation sections that refer to this one. SmallVector RelocSections; private: template void relocate(uint8_t *Buf, llvm::iterator_range< const llvm::object::Elf_Rel_Impl *> Rels, const ObjectFile &File, uintX_t BaseAddr, const OutputSection &BssSec, const PltSection &PltSec, const GotSection &GotSec); // The offset from beginning of the output sections this section was assigned // to. The writer sets a value. uint64_t OutputSectionOff = 0; // The file this section is from. ObjectFile *File; OutputSection *Out = nullptr; const Elf_Shdr *Header; }; } // namespace elf2 } // namespace lld #endif