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