Rafael Espindola | beee25e | 2015-08-14 14:12:54 +0000 | [diff] [blame] | 1 | //===- Chunks.h -------------------------------------------------*- C++ -*-===// |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLD_ELF_CHUNKS_H |
| 11 | #define LLD_ELF_CHUNKS_H |
| 12 | |
| 13 | #include "lld/Core/LLVM.h" |
| 14 | #include "llvm/Object/ELF.h" |
| 15 | |
| 16 | namespace lld { |
| 17 | namespace elf2 { |
| 18 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 19 | template <class ELFT> class ObjectFile; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 20 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 21 | // A chunk corresponding a section of an input file. |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 22 | template <class ELFT> class SectionChunk { |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 23 | typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr; |
| 24 | typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela; |
| 25 | typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel; |
| 26 | |
| 27 | public: |
| 28 | SectionChunk(llvm::object::ELFFile<ELFT> *Obj, const Elf_Shdr *Header); |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 29 | |
| 30 | // Returns the size of this chunk (even if this is a common or BSS.) |
| 31 | size_t getSize() const { return Header->sh_size; } |
| 32 | |
| 33 | // Write this chunk to a mmap'ed file, assuming Buf is pointing to |
| 34 | // beginning of the output section. |
| 35 | void writeTo(uint8_t *Buf); |
| 36 | |
Rafael Espindola | 5d83ccd | 2015-08-13 19:18:30 +0000 | [diff] [blame] | 37 | StringRef getSectionName() const; |
Michael J. Spencer | 8039dae2 | 2015-07-29 00:30:10 +0000 | [diff] [blame] | 38 | const Elf_Shdr *getSectionHdr() const { return Header; } |
| 39 | |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 40 | // The writer sets and uses the addresses. |
| 41 | uint64_t getOutputSectionOff() { return OutputSectionOff; } |
| 42 | uint32_t getAlign() { return Align; } |
| 43 | void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; } |
| 44 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 45 | private: |
Rafael Espindola | 83b0dc6 | 2015-08-13 22:21:37 +0000 | [diff] [blame] | 46 | // The offset from beginning of the output sections this chunk was assigned |
| 47 | // to. The writer sets a value. |
| 48 | uint64_t OutputSectionOff = 0; |
| 49 | |
| 50 | // The alignment of this chunk. The writer uses the value. |
| 51 | uint32_t Align = 1; |
| 52 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 53 | // A file this chunk was created from. |
| 54 | llvm::object::ELFFile<ELFT> *Obj; |
| 55 | |
| 56 | const Elf_Shdr *Header; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | } // namespace elf2 |
| 60 | } // namespace lld |
| 61 | |
| 62 | #endif |