summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/ELFChunk.h
blob: 5045a91a1ee4def302d421ceed2989d7ecf309ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//===- lib/ReaderWriter/ELF/ELFChunks.h ---------------------------------===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLD_READER_WRITER_ELF_CHUNKS_H_
#define LLD_READER_WRITER_ELF_CHUNKS_H_

#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileOutputBuffer.h"

namespace lld {
namespace elf {  

class ELFWriter;

/// \brief A chunk is a contiguous region of space
template<class ELFT>
class Chunk {
public:

  /// \brief Describes the type of Chunk
  enum Kind {
    K_ELFHeader, // ELF Header
    K_ELFProgramHeader, // Program Header
    K_ELFSegment, // Segment
    K_ELFSection, // Section
    K_ELFSectionHeader // Section header
  };
  Chunk(llvm::StringRef name, Kind kind)
    : _name(name)
    , _kind(kind)
    , _fsize(0)
    , _msize(0)
    , _align2(0)
    , _order(0)
    , _ordinal(1)
    , _start(0)
    , _fileoffset(0) {}
  virtual             ~Chunk() {}
  // Does the chunk occupy disk space
  virtual bool        occupiesNoDiskSpace() const {
    return false;
  }
  // The name of the chunk
  llvm::StringRef name() const { return _name; }
  // Kind of chunk
  Kind kind() const { return _kind; }
  uint64_t            fileSize() const { return _fsize; }
  uint64_t            align2() const { return _align2; }
  void                appendAtom() const;

  // The ordinal value of the chunk
  uint64_t            ordinal() const { return _ordinal;}
  void               setOrdinal(uint64_t newVal) { _ordinal = newVal;}
  // The order in which the chunk would appear in the output file
  uint64_t            order() const { return _order; }
  void               setOrder(uint32_t order) { _order = order; }
  // Output file offset of the chunk
  uint64_t            fileOffset() const { return _fileoffset; }
  void               setFileOffset(uint64_t offset) { _fileoffset = offset; }
  // Output start address of the chunk
  void               setVAddr(uint64_t start) { _start = start; }
  uint64_t            virtualAddr() const { return _start; }
  // Does the chunk occupy memory during execution ?
  uint64_t            memSize() const { return _msize; }
  void               setMemSize(uint64_t msize) { _msize = msize; }
  // Writer the chunk
  virtual void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) = 0;
  // Finalize the chunk before writing
  virtual void       finalize() = 0;

protected:
  llvm::StringRef _name;
  Kind _kind;
  uint64_t _fsize;
  uint64_t _msize;
  uint64_t _align2;
  uint32_t  _order;
  uint64_t _ordinal;
  uint64_t _start;
  uint64_t _fileoffset;
};

} // elf
} // lld

#endif // LLD_READER_WRITER_ELF_CHUNKS_H_
OpenPOWER on IntegriCloud