summaryrefslogtreecommitdiff
path: root/include/mcld/LD/EhFrameHdr.h
blob: e9d87021bceba12dbf2da9061a49c255b379381a (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
//===- EhFrameHdr.h -------------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef MCLD_EHFRAMEHDR_H
#define MCLD_EHFRAMEHDR_H
#ifdef ENABLE_UNITTEST
#include <gtest.h>
#endif
#include <mcld/ADT/SizeTraits.h>
#include <cassert>

#include <mcld/LD/EhFrame.h>
namespace mcld {

class LDSection;
class MemoryArea;
class MemoryRegion;

/** \class EhFrameHdr
 *  \brief EhFrameHdr represents .eh_frame_hdr section.
 *
 *  @ref lsb core generic 4.1
 *  .eh_frame_hdr section format
 *  uint8_t : version
 *  uint8_t : eh_frame_ptr_enc
 *  uint8_t : fde_count_enc
 *  uint8_t : table_enc
 *  uint32_t : eh_frame_ptr
 *  uint32_t : fde_count
 *  __________________________ when fde_count > 0
 *  <uint32_t, uint32_t>+ : binary search table
 */
class EhFrameHdr
{
public:
  EhFrameHdr(LDSection& pEhFrameHdr, const LDSection& pEhFrame);

  ~EhFrameHdr();

  /// sizeOutput - base on the fde count to size output
  void sizeOutput();

  /// emitOutput - write out eh_frame_hdr
  template<size_t size>
  void emitOutput(MemoryArea& pOutput)
  { assert(false && "Call invalid EhFrameHdr::emitOutput"); }

private:
  /// computePCBegin - return the address of FDE's pc
  /// @ref binutils gold: ehframe.cc:222
  uint32_t computePCBegin(const EhFrame::FDE& pFDE, const MemoryRegion& pEhFrameRegion);

private:
  /// .eh_frame_hdr section
  LDSection& m_EhFrameHdr;

  /// eh_frame
  const LDSection& m_EhFrame;
};

//===----------------------------------------------------------------------===//
// Template Specification Functions
//===----------------------------------------------------------------------===//
/// emitOutput - write out eh_frame_hdr
template<>
void EhFrameHdr::emitOutput<32>(MemoryArea& pOutput);

template<>
void EhFrameHdr::emitOutput<64>(MemoryArea& pOutput);

} // namespace of mcld

#endif