blob: 41a8cc138c2651c86291677d6d80c4c0322bffda [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
Michael J. Spencer84487f12015-07-24 21:03:07 +000019template <class ELFT> class ObjectFile;
Michael J. Spencer84487f12015-07-24 21:03:07 +000020
Michael J. Spencer84487f12015-07-24 21:03:07 +000021// A chunk corresponding a section of an input file.
Rafael Espindola83b0dc62015-08-13 22:21:37 +000022template <class ELFT> class SectionChunk {
Michael J. Spencer84487f12015-07-24 21:03:07 +000023 typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
24 typedef llvm::object::Elf_Rel_Impl<ELFT, true> Elf_Rela;
25 typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
26
27public:
28 SectionChunk(llvm::object::ELFFile<ELFT> *Obj, const Elf_Shdr *Header);
Rafael Espindola83b0dc62015-08-13 22:21:37 +000029
30 // Returns the size of this chunk (even if this is a common or BSS.)
31 size_t getSize() const { return Header->sh_size; }
32
33 // Write this chunk to a mmap'ed file, assuming Buf is pointing to
34 // beginning of the output section.
35 void writeTo(uint8_t *Buf);
36
Rafael Espindola5d83ccd2015-08-13 19:18:30 +000037 StringRef getSectionName() const;
Michael J. Spencer8039dae22015-07-29 00:30:10 +000038 const Elf_Shdr *getSectionHdr() const { return Header; }
39
Rafael Espindola83b0dc62015-08-13 22:21:37 +000040 // The writer sets and uses the addresses.
41 uint64_t getOutputSectionOff() { return OutputSectionOff; }
42 uint32_t getAlign() { return Align; }
43 void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; }
44
Michael J. Spencer84487f12015-07-24 21:03:07 +000045private:
Rafael Espindola83b0dc62015-08-13 22:21:37 +000046 // The offset from beginning of the output sections this chunk was assigned
47 // to. The writer sets a value.
48 uint64_t OutputSectionOff = 0;
49
50 // The alignment of this chunk. The writer uses the value.
51 uint32_t Align = 1;
52
Michael J. Spencer84487f12015-07-24 21:03:07 +000053 // A file this chunk was created from.
54 llvm::object::ELFFile<ELFT> *Obj;
55
56 const Elf_Shdr *Header;
Michael J. Spencer84487f12015-07-24 21:03:07 +000057};
58
59} // namespace elf2
60} // namespace lld
61
62#endif