2015-07-25 05:03:07 +08:00
|
|
|
//===- Chunks.h -----------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_CHUNKS_H
|
|
|
|
#define LLD_ELF_CHUNKS_H
|
|
|
|
|
|
|
|
#include "lld/Core/LLVM.h"
|
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf2 {
|
|
|
|
|
|
|
|
class Defined;
|
|
|
|
template <class ELFT> class ObjectFile;
|
|
|
|
|
2015-08-14 06:21:37 +08:00
|
|
|
// A chunk corresponding a section of an input file.
|
|
|
|
template <class ELFT> class SectionChunk {
|
|
|
|
typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
|
|
|
|
typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela;
|
|
|
|
typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
public:
|
2015-08-14 06:21:37 +08:00
|
|
|
SectionChunk(llvm::object::ELFFile<ELFT> *Obj, const Elf_Shdr *Header);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
// Returns the size of this chunk (even if this is a common or BSS.)
|
2015-08-14 06:21:37 +08:00
|
|
|
size_t getSize() const { return Header->sh_size; }
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
// Write this chunk to a mmap'ed file, assuming Buf is pointing to
|
2015-08-14 06:21:37 +08:00
|
|
|
// beginning of the output section.
|
|
|
|
void writeTo(uint8_t *Buf);
|
|
|
|
|
|
|
|
StringRef getSectionName() const;
|
|
|
|
const Elf_Shdr *getSectionHdr() const { return Header; }
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
// The writer sets and uses the addresses.
|
2015-08-13 23:54:36 +08:00
|
|
|
uint64_t getOutputSectionOff() { return OutputSectionOff; }
|
2015-07-25 05:03:07 +08:00
|
|
|
uint32_t getAlign() { return Align; }
|
2015-08-13 23:54:36 +08:00
|
|
|
void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; }
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-08-14 06:21:37 +08:00
|
|
|
private:
|
2015-08-13 23:54:36 +08:00
|
|
|
// The offset from beginning of the output sections this chunk was assigned
|
|
|
|
// to. The writer sets a value.
|
|
|
|
uint64_t OutputSectionOff = 0;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
// The alignment of this chunk. The writer uses the value.
|
|
|
|
uint32_t Align = 1;
|
|
|
|
|
|
|
|
// A file this chunk was created from.
|
|
|
|
llvm::object::ELFFile<ELFT> *Obj;
|
|
|
|
|
|
|
|
const Elf_Shdr *Header;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace elf2
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|