Home | History | Annotate | Download | only in X86
      1 //===- X86GOTPLT.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 "X86GOTPLT.h"
     10 #include "X86PLT.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 // X86_32GOTPLT
     22 //===----------------------------------------------------------------------===//
     23 X86_32GOTPLT::X86_32GOTPLT(LDSection& pSection)
     24   : X86_32GOT(pSection)
     25 {
     26   // Create GOT0 entries
     27   reserve(X86GOTPLT0Num);
     28 
     29   // Skip GOT0 entries
     30   for (size_t i = 0; i < X86GOTPLT0Num; ++i) {
     31     consume();
     32   }
     33 }
     34 
     35 X86_32GOTPLT::~X86_32GOTPLT()
     36 {
     37 }
     38 
     39 bool X86_32GOTPLT::hasGOT1() const
     40 {
     41   return (m_SectionData->size() > X86GOTPLT0Num);
     42 }
     43 
     44 void X86_32GOTPLT::applyGOT0(uint64_t pAddress)
     45 {
     46   llvm::cast<X86_32GOTEntry>
     47     (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
     48 }
     49 
     50 void X86_32GOTPLT::applyAllGOTPLT(const X86PLT& pPLT)
     51 {
     52   iterator it = begin();
     53   // skip GOT0
     54   for (size_t i = 0; i < X86GOTPLT0Num; ++i)
     55     ++it;
     56   // address of corresponding plt entry
     57   uint64_t plt_addr = pPLT.addr() + pPLT.getPLT0Size();
     58   for (; it != end() ; ++it) {
     59     llvm::cast<X86_32GOTEntry>(*it).setValue(plt_addr + 6);
     60     plt_addr += pPLT.getPLT1Size();
     61   }
     62 }
     63 
     64 //===----------------------------------------------------------------------===//
     65 // X86_64GOTPLT
     66 //===----------------------------------------------------------------------===//
     67 X86_64GOTPLT::X86_64GOTPLT(LDSection& pSection)
     68   : X86_64GOT(pSection)
     69 {
     70   // Create GOT0 entries
     71   reserve(X86GOTPLT0Num);
     72 
     73   // Skip GOT0 entries
     74   for (size_t i = 0; i < X86GOTPLT0Num; ++i) {
     75     consume();
     76   }
     77 }
     78 
     79 X86_64GOTPLT::~X86_64GOTPLT()
     80 {
     81 }
     82 
     83 bool X86_64GOTPLT::hasGOT1() const
     84 {
     85   return (m_SectionData->size() > X86GOTPLT0Num);
     86 }
     87 
     88 void X86_64GOTPLT::applyGOT0(uint64_t pAddress)
     89 {
     90   llvm::cast<X86_64GOTEntry>
     91     (*(m_SectionData->getFragmentList().begin())).setValue(pAddress);
     92 }
     93 
     94 void X86_64GOTPLT::applyAllGOTPLT(const X86PLT& pPLT)
     95 {
     96   iterator it = begin();
     97   // skip GOT0
     98   for (size_t i = 0; i < X86GOTPLT0Num; ++i)
     99     ++it;
    100   // address of corresponding plt entry
    101   uint64_t plt_addr = pPLT.addr() + pPLT.getPLT0Size();
    102   for (; it != end() ; ++it) {
    103     llvm::cast<X86_64GOTEntry>(*it).setValue(plt_addr + 6);
    104     plt_addr += pPLT.getPLT1Size();
    105   }
    106 }
    107 
    108 } //end mcld namespace
    109