blob: 3b9274cad1bda4379d6a4d9b1b1cc9d09bfa2196 [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;
Rafael Espindolac5c82912015-08-24 19:28:31 +000026 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
Michael J. Spencer84487f12015-07-24 21:03:07 +000027
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; }
Rafael Espindolac5c82912015-08-24 19:28:31 +000043 uintX_t getAlign() { return Header->sh_addralign; }
Rafael Espindola83b0dc62015-08-13 22:21:37 +000044 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
Michael J. Spencer84487f12015-07-24 21:03:07 +000051 // A file this chunk was created from.
52 llvm::object::ELFFile<ELFT> *Obj;
53
54 const Elf_Shdr *Header;
Michael J. Spencer84487f12015-07-24 21:03:07 +000055};
56
57} // namespace elf2
58} // namespace lld
59
60#endif