1 //===- HexagonGOTPLT.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 "HexagonGOTPLT.h"
10 #include "HexagonPLT.h"
11 
12 #include <llvm/Support/Casting.h>
13 
14 #include <mcld/LD/LDSection.h>
15 #include <mcld/LD/LDFileFormat.h>
16 #include <mcld/Support/MsgHandling.h>
17 
18 namespace mcld {
19 
20 //===----------------------------------------------------------------------===//
21 // HexagonGOTPLT
22 //===----------------------------------------------------------------------===//
HexagonGOTPLT(LDSection & pSection)23 HexagonGOTPLT::HexagonGOTPLT(LDSection& pSection)
24   : HexagonGOT(pSection)
25 {
26   // Skip GOT0 entries
27   for (size_t i = 0; i < HexagonGOTPLT0Num; ++i) {
28     create();
29   }
30   pSection.setAlign(8);
31 }
32 
~HexagonGOTPLT()33 HexagonGOTPLT::~HexagonGOTPLT()
34 {
35 }
36 
37 // Check if we really have GOT PLT entries ?
hasGOT1() const38 bool HexagonGOTPLT::hasGOT1() const
39 {
40   return (m_SectionData->size() > HexagonGOTPLT0Num);
41 }
42 
applyGOT0(uint64_t pAddress)43 void HexagonGOTPLT::applyGOT0(uint64_t pAddress)
44 {
45   llvm::cast<HexagonGOTEntry>
46     (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
47 }
48 
applyAllGOTPLT(const HexagonPLT & pPLT)49 void HexagonGOTPLT::applyAllGOTPLT(const HexagonPLT& pPLT)
50 {
51   iterator it = begin();
52   // skip GOT0
53   for (size_t i = 0; i < HexagonGOTPLT0Num; ++i)
54     ++it;
55   // Set the initial value of the GOT entry to the address
56   // of PLT0, the stub calculates the index of the caller directly from
57   // the address where the call arised
58   for (; it != end() ; ++it) {
59     llvm::cast<HexagonGOTEntry>(*it).setValue(pPLT.addr());
60   }
61 }
62 
63 }
64