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