| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 1 | //===- Chunks.cpp ---------------------------------------------------------===// |
| 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 | #include "Chunks.h" |
| Rafael Espindola | 192e1fa | 2015-08-06 15:08:23 +0000 | [diff] [blame] | 11 | #include "Error.h" |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 12 | |
| 13 | using namespace llvm; |
| 14 | using namespace llvm::ELF; |
| 15 | |
| 16 | using namespace lld; |
| 17 | using namespace lld::elf2; |
| 18 | |
| 19 | template <class ELFT> |
| 20 | SectionChunk<ELFT>::SectionChunk(object::ELFFile<ELFT> *Obj, |
| 21 | const Elf_Shdr *Header) |
| Rafael Espindola | e7a00e3 | 2015-08-05 13:55:34 +0000 | [diff] [blame] | 22 | : Obj(Obj), Header(Header) { |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 23 | Align = Header->sh_addralign; |
| 24 | } |
| 25 | |
| 26 | template <class ELFT> void SectionChunk<ELFT>::writeTo(uint8_t *Buf) { |
| 27 | if (Header->sh_type == SHT_NOBITS) |
| 28 | return; |
| 29 | // Copy section contents from source object file to output file. |
| 30 | ArrayRef<uint8_t> Data = *Obj->getSectionContents(Header); |
| Rafael Espindola | 674b5d5 | 2015-08-13 15:54:36 +0000 | [diff] [blame] | 31 | memcpy(Buf + OutputSectionOff, Data.data(), Data.size()); |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 32 | |
| 33 | // FIXME: Relocations |
| 34 | } |
| 35 | |
| Rafael Espindola | 5d83ccd | 2015-08-13 19:18:30 +0000 | [diff] [blame^] | 36 | template <class ELFT> StringRef SectionChunk<ELFT>::getSectionName() const { |
| 37 | ErrorOr<StringRef> Name = Obj->getSectionName(Header); |
| 38 | error(Name); |
| 39 | return *Name; |
| 40 | } |
| 41 | |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 42 | namespace lld { |
| 43 | namespace elf2 { |
| 44 | template class SectionChunk<object::ELF32LE>; |
| 45 | template class SectionChunk<object::ELF32BE>; |
| 46 | template class SectionChunk<object::ELF64LE>; |
| 47 | template class SectionChunk<object::ELF64BE>; |
| 48 | } |
| 49 | } |