2015-07-24 21:03:07 +00:00
|
|
|
//===- Chunks.cpp ---------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Chunks.h"
|
2015-08-06 15:08:23 +00:00
|
|
|
#include "Error.h"
|
2015-07-24 21:03:07 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::ELF;
|
|
|
|
|
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::elf2;
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
SectionChunk<ELFT>::SectionChunk(object::ELFFile<ELFT> *Obj,
|
|
|
|
const Elf_Shdr *Header)
|
2015-08-05 13:55:34 +00:00
|
|
|
: Obj(Obj), Header(Header) {
|
2015-07-24 21:03:07 +00:00
|
|
|
// Initialize SectionName.
|
|
|
|
ErrorOr<StringRef> Name = Obj->getSectionName(Header);
|
|
|
|
error(Name);
|
|
|
|
SectionName = *Name;
|
|
|
|
|
|
|
|
Align = Header->sh_addralign;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> void SectionChunk<ELFT>::writeTo(uint8_t *Buf) {
|
|
|
|
if (Header->sh_type == SHT_NOBITS)
|
|
|
|
return;
|
|
|
|
// Copy section contents from source object file to output file.
|
|
|
|
ArrayRef<uint8_t> Data = *Obj->getSectionContents(Header);
|
2015-08-13 15:54:36 +00:00
|
|
|
memcpy(Buf + OutputSectionOff, Data.data(), Data.size());
|
2015-07-24 21:03:07 +00:00
|
|
|
|
|
|
|
// FIXME: Relocations
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf2 {
|
|
|
|
template class SectionChunk<object::ELF32LE>;
|
|
|
|
template class SectionChunk<object::ELF32BE>;
|
|
|
|
template class SectionChunk<object::ELF64LE>;
|
|
|
|
template class SectionChunk<object::ELF64BE>;
|
|
|
|
}
|
|
|
|
}
|