1 //===- MipsELFDynamic.cpp -------------------------------------------------===//
2 //
3 // The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #include "MipsELFDynamic.h"
10
11 #include "MipsLDBackend.h"
12 #include <mcld/LD/ELFFileFormat.h>
13 #include <mcld/Target/GNULDBackend.h>
14
15 using namespace mcld;
16
17 // MIPS mandatory dynamic section entries
18 enum {
19 MIPS_RLD_VERSION = 0x70000001,
20 MIPS_FLAGS = 0x70000005,
21 MIPS_BASE_ADDRESS = 0x70000006,
22 MIPS_LOCAL_GOTNO = 0x7000000a,
23 MIPS_SYMTABNO = 0x70000011,
24 MIPS_GOTSYM = 0x70000013
25 };
26
MipsELFDynamic(const MipsGNULDBackend & pParent,const LinkerConfig & pConfig)27 MipsELFDynamic::MipsELFDynamic(const MipsGNULDBackend& pParent,
28 const LinkerConfig& pConfig)
29 : ELFDynamic(pParent, pConfig),
30 m_pParent(pParent)
31 {
32 }
33
~MipsELFDynamic()34 MipsELFDynamic::~MipsELFDynamic()
35 {
36 }
37
reserveTargetEntries(const ELFFileFormat & pFormat)38 void MipsELFDynamic::reserveTargetEntries(const ELFFileFormat& pFormat)
39 {
40 // reservePLTGOT
41 if (pFormat.hasGOT())
42 reserveOne(llvm::ELF::DT_PLTGOT);
43
44 reserveOne(MIPS_RLD_VERSION);
45 reserveOne(MIPS_FLAGS);
46 reserveOne(MIPS_BASE_ADDRESS);
47 reserveOne(MIPS_LOCAL_GOTNO);
48 reserveOne(MIPS_SYMTABNO);
49 reserveOne(MIPS_GOTSYM);
50 }
51
applyTargetEntries(const ELFFileFormat & pFormat)52 void MipsELFDynamic::applyTargetEntries(const ELFFileFormat& pFormat)
53 {
54 // applyPLTGOT
55 if (pFormat.hasGOT())
56 applyOne(llvm::ELF::DT_PLTGOT, pFormat.getGOT().addr());
57
58 applyOne(MIPS_RLD_VERSION, 1);
59 applyOne(MIPS_FLAGS, 0);
60 applyOne(MIPS_BASE_ADDRESS, 0);
61 applyOne(MIPS_LOCAL_GOTNO, getLocalGotNum(pFormat));
62 applyOne(MIPS_SYMTABNO, getSymTabNum(pFormat));
63 applyOne(MIPS_GOTSYM, getGotSym(pFormat));
64 }
65
getSymTabNum(const ELFFileFormat & pFormat) const66 size_t MipsELFDynamic::getSymTabNum(const ELFFileFormat& pFormat) const
67 {
68 if (!pFormat.hasDynSymTab())
69 return 0;
70
71 const LDSection& dynsym = pFormat.getDynSymTab();
72 return dynsym.size() / symbolSize();
73 }
74
getGotSym(const ELFFileFormat & pFormat) const75 size_t MipsELFDynamic::getGotSym(const ELFFileFormat& pFormat) const
76 {
77 if (!pFormat.hasGOT())
78 return 0;
79
80 return getSymTabNum(pFormat) - m_pParent.getGOT().getGlobalNum();
81 }
82
getLocalGotNum(const ELFFileFormat & pFormat) const83 size_t MipsELFDynamic::getLocalGotNum(const ELFFileFormat& pFormat) const
84 {
85 if (!pFormat.hasGOT())
86 return 0;
87
88 return m_pParent.getGOT().getLocalNum();
89 }
90