Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 1 | //===- MipsLA25Stub.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 | //===----------------------------------------------------------------------===// |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 9 | #include "mcld/LD/ResolveInfo.h" |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 10 | #include "MipsLA25Stub.h" |
| 11 | #include "MipsLDBackend.h" |
| 12 | |
| 13 | namespace { |
| 14 | |
| 15 | const uint32_t STUB[] = { |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 16 | 0x3c190000, // lui $25,%hi(func) |
| 17 | 0x08000000, // j func |
| 18 | 0x27390000, // add $25,$25,%lo(func) |
| 19 | 0x00000000 // nop |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 20 | }; |
| 21 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 22 | } // anonymous namespace |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 23 | |
| 24 | namespace mcld { |
| 25 | |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | // MipsLA25Stub |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
| 30 | MipsLA25Stub::MipsLA25Stub(const MipsGNULDBackend& pTarget) |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 31 | : m_Target(pTarget), |
| 32 | m_Name("MipsLA25_Prototype"), |
| 33 | m_pData(STUB), |
| 34 | m_Size(sizeof(STUB)) { |
Stephen Hines | cfcb224 | 2016-03-08 00:18:09 -0800 | [diff] [blame^] | 35 | addFixup(0, 0x0, llvm::ELF::R_MIPS_HI16); |
| 36 | addFixup(4, 0x0, llvm::ELF::R_MIPS_26); |
| 37 | addFixup(8, 0x0, llvm::ELF::R_MIPS_LO16); |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | MipsLA25Stub::MipsLA25Stub(const MipsGNULDBackend& pTarget, |
| 41 | const uint32_t* pData, |
| 42 | size_t pSize, |
| 43 | const_fixup_iterator pBegin, |
| 44 | const_fixup_iterator pEnd) |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 45 | : m_Target(pTarget), m_Name("pic"), m_pData(pData), m_Size(pSize) { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 46 | for (const_fixup_iterator it = pBegin, ie = pEnd; it != ie; ++it) |
| 47 | addFixup(**it); |
| 48 | } |
| 49 | |
| 50 | bool MipsLA25Stub::isMyDuty(const Relocation& pReloc, |
| 51 | uint64_t pSource, |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 52 | uint64_t pTargetSymValue) const { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 53 | if (llvm::ELF::R_MIPS_26 != pReloc.type()) |
| 54 | return false; |
| 55 | |
| 56 | const ResolveInfo* rsym = pReloc.symInfo(); |
| 57 | |
| 58 | if (!rsym->isDefine()) |
| 59 | return false; |
| 60 | |
| 61 | if (rsym->isDyn() || rsym->isUndef()) |
| 62 | return false; |
| 63 | |
| 64 | if (!m_Target.hasNonPICBranch(rsym)) |
| 65 | return false; |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 70 | const std::string& MipsLA25Stub::name() const { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 71 | return m_Name; |
| 72 | } |
| 73 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 74 | const uint8_t* MipsLA25Stub::getContent() const { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 75 | return reinterpret_cast<const uint8_t*>(m_pData); |
| 76 | } |
| 77 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 78 | size_t MipsLA25Stub::size() const { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 79 | return m_Size; |
| 80 | } |
| 81 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 82 | size_t MipsLA25Stub::alignment() const { |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 83 | return 4; |
| 84 | } |
| 85 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 86 | Stub* MipsLA25Stub::doClone() { |
| 87 | return new MipsLA25Stub( |
| 88 | m_Target, m_pData, m_Size, fixup_begin(), fixup_end()); |
Stephen Hines | f33f6de | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 91 | } // namespace mcld |