blob: d2561f82f4731d6978f00da31bd659712b32323a [file] [log] [blame]
Rafael Espindolabeee25e2015-08-14 14:12:54 +00001//===- Chunks.h -------------------------------------------------*- C++ -*-===//
Michael J. Spencer84487f12015-07-24 21:03:07 +00002//
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
16namespace lld {
17namespace elf2 {
18
19class Defined;
20template <class ELFT> class ObjectFile;
Michael J. Spencer84487f12015-07-24 21:03:07 +000021
Michael J. Spencer84487f12015-07-24 21:03:07 +000022// A chunk corresponding a section of an input file.
Rafael Espindola83b0dc62015-08-13 22:21:37 +000023template <class ELFT> class SectionChunk {
Michael J. Spencer84487f12015-07-24 21:03:07 +000024 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
28public:
29 SectionChunk(llvm::object::ELFFile<ELFT> *Obj, const Elf_Shdr *Header);
Rafael Espindola83b0dc62015-08-13 22:21:37 +000030
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 Espindola5d83ccd2015-08-13 19:18:30 +000038 StringRef getSectionName() const;
Michael J. Spencer8039dae22015-07-29 00:30:10 +000039 const Elf_Shdr *getSectionHdr() const { return Header; }
40
Rafael Espindola83b0dc62015-08-13 22:21:37 +000041 // 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. Spencer84487f12015-07-24 21:03:07 +000046private:
Rafael Espindola83b0dc62015-08-13 22:21:37 +000047 // 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. Spencer84487f12015-07-24 21:03:07 +000054 // A file this chunk was created from.
55 llvm::object::ELFFile<ELFT> *Obj;
56
57 const Elf_Shdr *Header;
Michael J. Spencer84487f12015-07-24 21:03:07 +000058};
59
60} // namespace elf2
61} // namespace lld
62
63#endif