Jim Grosbach | 06594e1 | 2012-01-16 23:50:58 +0000 | [diff] [blame] | 1 | //===-- RuntimeDyldELF.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-===// |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Implementation of ELF support for the MC-JIT runtime dynamic linker. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Andrew Kaylor | adc7056 | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 14 | #include "RuntimeDyldELF.h" |
| 15 | #include "JITRegistrar.h" |
| 16 | #include "ObjectImageCommon.h" |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/IntervalMap.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
| 19 | #include "llvm/ADT/StringRef.h" |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Triple.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/ExecutionEngine/ObjectBuffer.h" |
| 22 | #include "llvm/ExecutionEngine/ObjectImage.h" |
Michael J. Spencer | 126973b | 2013-08-08 22:27:13 +0000 | [diff] [blame] | 23 | #include "llvm/Object/ELFObjectFile.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/Object/ObjectFile.h" |
| 25 | #include "llvm/Support/ELF.h" |
Lang Hames | 173c69f | 2014-01-08 04:09:09 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MemoryBuffer.h" |
| 27 | |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 28 | using namespace llvm; |
| 29 | using namespace llvm::object; |
| 30 | |
Chandler Carruth | f58e376 | 2014-04-22 03:04:17 +0000 | [diff] [blame] | 31 | #define DEBUG_TYPE "dyld" |
| 32 | |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 33 | namespace { |
| 34 | |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 35 | static inline std::error_code check(std::error_code Err) { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 36 | if (Err) { |
| 37 | report_fatal_error(Err.message()); |
| 38 | } |
| 39 | return Err; |
| 40 | } |
| 41 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 42 | template <class ELFT> class DyldELFObject : public ELFObjectFile<ELFT> { |
Rafael Espindola | 035b416 | 2013-04-17 21:20:55 +0000 | [diff] [blame] | 43 | LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 44 | |
Michael J. Spencer | 1a79161 | 2013-01-15 07:44:25 +0000 | [diff] [blame] | 45 | typedef Elf_Shdr_Impl<ELFT> Elf_Shdr; |
| 46 | typedef Elf_Sym_Impl<ELFT> Elf_Sym; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 47 | typedef Elf_Rel_Impl<ELFT, false> Elf_Rel; |
| 48 | typedef Elf_Rel_Impl<ELFT, true> Elf_Rela; |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 49 | |
Michael J. Spencer | 1a79161 | 2013-01-15 07:44:25 +0000 | [diff] [blame] | 50 | typedef Elf_Ehdr_Impl<ELFT> Elf_Ehdr; |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 51 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 52 | typedef typename ELFDataTypeTypedefHelper<ELFT>::value_type addr_type; |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 53 | |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 54 | std::unique_ptr<ObjectFile> UnderlyingFile; |
| 55 | |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 56 | public: |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 57 | DyldELFObject(std::unique_ptr<ObjectFile> UnderlyingFile, |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 58 | MemoryBuffer *Wrapper, std::error_code &ec); |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 59 | |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 60 | DyldELFObject(MemoryBuffer *Wrapper, std::error_code &ec); |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 61 | |
| 62 | void updateSectionAddress(const SectionRef &Sec, uint64_t Addr); |
| 63 | void updateSymbolAddress(const SymbolRef &Sym, uint64_t Addr); |
| 64 | |
Andrew Kaylor | 5c01090 | 2012-07-27 17:52:42 +0000 | [diff] [blame] | 65 | // Methods for type inquiry through isa, cast and dyn_cast |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 66 | static inline bool classof(const Binary *v) { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 67 | return (isa<ELFObjectFile<ELFT>>(v) && |
| 68 | classof(cast<ELFObjectFile<ELFT>>(v))); |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 69 | } |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 70 | static inline bool classof(const ELFObjectFile<ELFT> *v) { |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 71 | return v->isDyldType(); |
| 72 | } |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 75 | template <class ELFT> class ELFObjectImage : public ObjectImageCommon { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 76 | bool Registered; |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 77 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 78 | public: |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 79 | ELFObjectImage(ObjectBuffer *Input, std::unique_ptr<DyldELFObject<ELFT>> Obj) |
| 80 | : ObjectImageCommon(Input, std::move(Obj)), Registered(false) {} |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 81 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 82 | virtual ~ELFObjectImage() { |
| 83 | if (Registered) |
| 84 | deregisterWithDebugger(); |
| 85 | } |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 86 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 87 | // Subclasses can override these methods to update the image with loaded |
| 88 | // addresses for sections and common symbols |
| 89 | void updateSectionAddress(const SectionRef &Sec, uint64_t Addr) override { |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 90 | static_cast<DyldELFObject<ELFT>*>(getObjectFile()) |
| 91 | ->updateSectionAddress(Sec, Addr); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 92 | } |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 93 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 94 | void updateSymbolAddress(const SymbolRef &Sym, uint64_t Addr) override { |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 95 | static_cast<DyldELFObject<ELFT>*>(getObjectFile()) |
| 96 | ->updateSymbolAddress(Sym, Addr); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 97 | } |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 98 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 99 | void registerWithDebugger() override { |
| 100 | JITRegistrar::getGDBRegistrar().registerObject(*Buffer); |
| 101 | Registered = true; |
| 102 | } |
| 103 | void deregisterWithDebugger() override { |
| 104 | JITRegistrar::getGDBRegistrar().deregisterObject(*Buffer); |
| 105 | } |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
Andrew Kaylor | adc7056 | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 108 | // The MemoryBuffer passed into this constructor is just a wrapper around the |
| 109 | // actual memory. Ultimately, the Binary parent class will take ownership of |
| 110 | // this MemoryBuffer object but not the underlying memory. |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 111 | template <class ELFT> |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 112 | DyldELFObject<ELFT>::DyldELFObject(MemoryBuffer *Wrapper, std::error_code &ec) |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 113 | : ELFObjectFile<ELFT>(Wrapper, ec) { |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 114 | this->isDyldELFObject = true; |
| 115 | } |
| 116 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 117 | template <class ELFT> |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 118 | DyldELFObject<ELFT>::DyldELFObject(std::unique_ptr<ObjectFile> UnderlyingFile, |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 119 | MemoryBuffer *Wrapper, std::error_code &ec) |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 120 | : ELFObjectFile<ELFT>(Wrapper, ec), |
| 121 | UnderlyingFile(std::move(UnderlyingFile)) { |
| 122 | this->isDyldELFObject = true; |
| 123 | } |
| 124 | |
| 125 | template <class ELFT> |
Michael J. Spencer | 1a79161 | 2013-01-15 07:44:25 +0000 | [diff] [blame] | 126 | void DyldELFObject<ELFT>::updateSectionAddress(const SectionRef &Sec, |
| 127 | uint64_t Addr) { |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 128 | DataRefImpl ShdrRef = Sec.getRawDataRefImpl(); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 129 | Elf_Shdr *shdr = |
| 130 | const_cast<Elf_Shdr *>(reinterpret_cast<const Elf_Shdr *>(ShdrRef.p)); |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 131 | |
| 132 | // This assumes the address passed in matches the target address bitness |
| 133 | // The template-based type cast handles everything else. |
| 134 | shdr->sh_addr = static_cast<addr_type>(Addr); |
| 135 | } |
| 136 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 137 | template <class ELFT> |
Michael J. Spencer | 1a79161 | 2013-01-15 07:44:25 +0000 | [diff] [blame] | 138 | void DyldELFObject<ELFT>::updateSymbolAddress(const SymbolRef &SymRef, |
| 139 | uint64_t Addr) { |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 140 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 141 | Elf_Sym *sym = const_cast<Elf_Sym *>( |
| 142 | ELFObjectFile<ELFT>::getSymbol(SymRef.getRawDataRefImpl())); |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 143 | |
| 144 | // This assumes the address passed in matches the target address bitness |
| 145 | // The template-based type cast handles everything else. |
| 146 | sym->st_value = static_cast<addr_type>(Addr); |
| 147 | } |
| 148 | |
| 149 | } // namespace |
| 150 | |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 151 | namespace llvm { |
| 152 | |
Andrew Kaylor | 7bb1344 | 2013-10-11 21:25:48 +0000 | [diff] [blame] | 153 | void RuntimeDyldELF::registerEHFrames() { |
| 154 | if (!MemMgr) |
| 155 | return; |
| 156 | for (int i = 0, e = UnregisteredEHFrameSections.size(); i != e; ++i) { |
| 157 | SID EHFrameSID = UnregisteredEHFrameSections[i]; |
| 158 | uint8_t *EHFrameAddr = Sections[EHFrameSID].Address; |
| 159 | uint64_t EHFrameLoadAddr = Sections[EHFrameSID].LoadAddress; |
| 160 | size_t EHFrameSize = Sections[EHFrameSID].Size; |
| 161 | MemMgr->registerEHFrames(EHFrameAddr, EHFrameLoadAddr, EHFrameSize); |
Andrew Kaylor | c442a76 | 2013-10-16 00:14:21 +0000 | [diff] [blame] | 162 | RegisteredEHFrameSections.push_back(EHFrameSID); |
Rafael Espindola | fa5942b | 2013-05-05 20:43:10 +0000 | [diff] [blame] | 163 | } |
Andrew Kaylor | 7bb1344 | 2013-10-11 21:25:48 +0000 | [diff] [blame] | 164 | UnregisteredEHFrameSections.clear(); |
Rafael Espindola | fa5942b | 2013-05-05 20:43:10 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Andrew Kaylor | c442a76 | 2013-10-16 00:14:21 +0000 | [diff] [blame] | 167 | void RuntimeDyldELF::deregisterEHFrames() { |
| 168 | if (!MemMgr) |
| 169 | return; |
| 170 | for (int i = 0, e = RegisteredEHFrameSections.size(); i != e; ++i) { |
| 171 | SID EHFrameSID = RegisteredEHFrameSections[i]; |
| 172 | uint8_t *EHFrameAddr = Sections[EHFrameSID].Address; |
| 173 | uint64_t EHFrameLoadAddr = Sections[EHFrameSID].LoadAddress; |
| 174 | size_t EHFrameSize = Sections[EHFrameSID].Size; |
| 175 | MemMgr->deregisterEHFrames(EHFrameAddr, EHFrameLoadAddr, EHFrameSize); |
| 176 | } |
| 177 | RegisteredEHFrameSections.clear(); |
| 178 | } |
| 179 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 180 | ObjectImage * |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 181 | RuntimeDyldELF::createObjectImageFromFile(std::unique_ptr<object::ObjectFile> ObjFile) { |
Lang Hames | 173c69f | 2014-01-08 04:09:09 +0000 | [diff] [blame] | 182 | if (!ObjFile) |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 183 | return nullptr; |
Lang Hames | 173c69f | 2014-01-08 04:09:09 +0000 | [diff] [blame] | 184 | |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 185 | std::error_code ec; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 186 | MemoryBuffer *Buffer = |
| 187 | MemoryBuffer::getMemBuffer(ObjFile->getData(), "", false); |
Lang Hames | 173c69f | 2014-01-08 04:09:09 +0000 | [diff] [blame] | 188 | |
| 189 | if (ObjFile->getBytesInAddress() == 4 && ObjFile->isLittleEndian()) { |
Reid Kleckner | 7aeb905 | 2014-04-29 23:54:52 +0000 | [diff] [blame] | 190 | auto Obj = |
| 191 | llvm::make_unique<DyldELFObject<ELFType<support::little, 2, false>>>( |
| 192 | std::move(ObjFile), Buffer, ec); |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 193 | return new ELFObjectImage<ELFType<support::little, 2, false>>( |
| 194 | nullptr, std::move(Obj)); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 195 | } else if (ObjFile->getBytesInAddress() == 4 && !ObjFile->isLittleEndian()) { |
Reid Kleckner | 7aeb905 | 2014-04-29 23:54:52 +0000 | [diff] [blame] | 196 | auto Obj = |
| 197 | llvm::make_unique<DyldELFObject<ELFType<support::big, 2, false>>>( |
| 198 | std::move(ObjFile), Buffer, ec); |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 199 | return new ELFObjectImage<ELFType<support::big, 2, false>>(nullptr, std::move(Obj)); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 200 | } else if (ObjFile->getBytesInAddress() == 8 && !ObjFile->isLittleEndian()) { |
Reid Kleckner | 7aeb905 | 2014-04-29 23:54:52 +0000 | [diff] [blame] | 201 | auto Obj = llvm::make_unique<DyldELFObject<ELFType<support::big, 2, true>>>( |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 202 | std::move(ObjFile), Buffer, ec); |
| 203 | return new ELFObjectImage<ELFType<support::big, 2, true>>(nullptr, |
| 204 | std::move(Obj)); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 205 | } else if (ObjFile->getBytesInAddress() == 8 && ObjFile->isLittleEndian()) { |
Reid Kleckner | 7aeb905 | 2014-04-29 23:54:52 +0000 | [diff] [blame] | 206 | auto Obj = |
| 207 | llvm::make_unique<DyldELFObject<ELFType<support::little, 2, true>>>( |
| 208 | std::move(ObjFile), Buffer, ec); |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 209 | return new ELFObjectImage<ELFType<support::little, 2, true>>( |
| 210 | nullptr, std::move(Obj)); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 211 | } else |
Lang Hames | 173c69f | 2014-01-08 04:09:09 +0000 | [diff] [blame] | 212 | llvm_unreachable("Unexpected ELF format"); |
| 213 | } |
| 214 | |
Andrew Kaylor | adc7056 | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 215 | ObjectImage *RuntimeDyldELF::createObjectImage(ObjectBuffer *Buffer) { |
| 216 | if (Buffer->getBufferSize() < ELF::EI_NIDENT) |
| 217 | llvm_unreachable("Unexpected ELF object size"); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 218 | std::pair<unsigned char, unsigned char> Ident = |
| 219 | std::make_pair((uint8_t)Buffer->getBufferStart()[ELF::EI_CLASS], |
| 220 | (uint8_t)Buffer->getBufferStart()[ELF::EI_DATA]); |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 221 | std::error_code ec; |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 222 | |
| 223 | if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB) { |
Reid Kleckner | 7aeb905 | 2014-04-29 23:54:52 +0000 | [diff] [blame] | 224 | auto Obj = |
| 225 | llvm::make_unique<DyldELFObject<ELFType<support::little, 4, false>>>( |
| 226 | Buffer->getMemBuffer(), ec); |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 227 | return new ELFObjectImage<ELFType<support::little, 4, false>>( |
| 228 | Buffer, std::move(Obj)); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 229 | } else if (Ident.first == ELF::ELFCLASS32 && |
| 230 | Ident.second == ELF::ELFDATA2MSB) { |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 231 | auto Obj = |
Reid Kleckner | 7aeb905 | 2014-04-29 23:54:52 +0000 | [diff] [blame] | 232 | llvm::make_unique<DyldELFObject<ELFType<support::big, 4, false>>>( |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 233 | Buffer->getMemBuffer(), ec); |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 234 | return new ELFObjectImage<ELFType<support::big, 4, false>>(Buffer, |
| 235 | std::move(Obj)); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 236 | } else if (Ident.first == ELF::ELFCLASS64 && |
| 237 | Ident.second == ELF::ELFDATA2MSB) { |
Reid Kleckner | 7aeb905 | 2014-04-29 23:54:52 +0000 | [diff] [blame] | 238 | auto Obj = llvm::make_unique<DyldELFObject<ELFType<support::big, 8, true>>>( |
| 239 | Buffer->getMemBuffer(), ec); |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 240 | return new ELFObjectImage<ELFType<support::big, 8, true>>(Buffer, std::move(Obj)); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 241 | } else if (Ident.first == ELF::ELFCLASS64 && |
| 242 | Ident.second == ELF::ELFDATA2LSB) { |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 243 | auto Obj = |
Reid Kleckner | 7aeb905 | 2014-04-29 23:54:52 +0000 | [diff] [blame] | 244 | llvm::make_unique<DyldELFObject<ELFType<support::little, 8, true>>>( |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 245 | Buffer->getMemBuffer(), ec); |
David Blaikie | 7a1e775 | 2014-04-29 21:52:46 +0000 | [diff] [blame] | 246 | return new ELFObjectImage<ELFType<support::little, 8, true>>(Buffer, std::move(Obj)); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 247 | } else |
Preston Gurd | cc31af9 | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 248 | llvm_unreachable("Unexpected ELF format"); |
| 249 | } |
| 250 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 251 | RuntimeDyldELF::~RuntimeDyldELF() {} |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 252 | |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 253 | void RuntimeDyldELF::resolveX86_64Relocation(const SectionEntry &Section, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 254 | uint64_t Offset, uint64_t Value, |
| 255 | uint32_t Type, int64_t Addend, |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 256 | uint64_t SymOffset) { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 257 | switch (Type) { |
| 258 | default: |
| 259 | llvm_unreachable("Relocation type not implemented yet!"); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 260 | break; |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 261 | case ELF::R_X86_64_64: { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 262 | uint64_t *Target = reinterpret_cast<uint64_t *>(Section.Address + Offset); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 263 | *Target = Value + Addend; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 264 | DEBUG(dbgs() << "Writing " << format("%p", (Value + Addend)) << " at " |
| 265 | << format("%p\n", Target)); |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 266 | break; |
| 267 | } |
| 268 | case ELF::R_X86_64_32: |
| 269 | case ELF::R_X86_64_32S: { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 270 | Value += Addend; |
Andrew Kaylor | 8e87a75 | 2012-07-27 20:30:12 +0000 | [diff] [blame] | 271 | assert((Type == ELF::R_X86_64_32 && (Value <= UINT32_MAX)) || |
Michael J. Spencer | bae14ce | 2013-01-04 20:36:28 +0000 | [diff] [blame] | 272 | (Type == ELF::R_X86_64_32S && |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 273 | ((int64_t)Value <= INT32_MAX && (int64_t)Value >= INT32_MIN))); |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 274 | uint32_t TruncatedAddr = (Value & 0xFFFFFFFF); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 275 | uint32_t *Target = reinterpret_cast<uint32_t *>(Section.Address + Offset); |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 276 | *Target = TruncatedAddr; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 277 | DEBUG(dbgs() << "Writing " << format("%p", TruncatedAddr) << " at " |
| 278 | << format("%p\n", Target)); |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 279 | break; |
| 280 | } |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 281 | case ELF::R_X86_64_GOTPCREL: { |
| 282 | // findGOTEntry returns the 'G + GOT' part of the relocation calculation |
| 283 | // based on the load/target address of the GOT (not the current/local addr). |
| 284 | uint64_t GOTAddr = findGOTEntry(Value, SymOffset); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 285 | uint32_t *Target = reinterpret_cast<uint32_t *>(Section.Address + Offset); |
| 286 | uint64_t FinalAddress = Section.LoadAddress + Offset; |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 287 | // The processRelocationRef method combines the symbol offset and the addend |
| 288 | // and in most cases that's what we want. For this relocation type, we need |
| 289 | // the raw addend, so we subtract the symbol offset to get it. |
| 290 | int64_t RealOffset = GOTAddr + Addend - SymOffset - FinalAddress; |
| 291 | assert(RealOffset <= INT32_MAX && RealOffset >= INT32_MIN); |
| 292 | int32_t TruncOffset = (RealOffset & 0xFFFFFFFF); |
| 293 | *Target = TruncOffset; |
| 294 | break; |
| 295 | } |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 296 | case ELF::R_X86_64_PC32: { |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 297 | // Get the placeholder value from the generated object since |
| 298 | // a previous relocation attempt may have overwritten the loaded version |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 299 | uint32_t *Placeholder = |
| 300 | reinterpret_cast<uint32_t *>(Section.ObjAddress + Offset); |
| 301 | uint32_t *Target = reinterpret_cast<uint32_t *>(Section.Address + Offset); |
| 302 | uint64_t FinalAddress = Section.LoadAddress + Offset; |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 303 | int64_t RealOffset = *Placeholder + Value + Addend - FinalAddress; |
Andrew Kaylor | 8e87a75 | 2012-07-27 20:30:12 +0000 | [diff] [blame] | 304 | assert(RealOffset <= INT32_MAX && RealOffset >= INT32_MIN); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 305 | int32_t TruncOffset = (RealOffset & 0xFFFFFFFF); |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 306 | *Target = TruncOffset; |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 307 | break; |
| 308 | } |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 309 | case ELF::R_X86_64_PC64: { |
| 310 | // Get the placeholder value from the generated object since |
| 311 | // a previous relocation attempt may have overwritten the loaded version |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 312 | uint64_t *Placeholder = |
| 313 | reinterpret_cast<uint64_t *>(Section.ObjAddress + Offset); |
| 314 | uint64_t *Target = reinterpret_cast<uint64_t *>(Section.Address + Offset); |
| 315 | uint64_t FinalAddress = Section.LoadAddress + Offset; |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 316 | *Target = *Placeholder + Value + Addend - FinalAddress; |
| 317 | break; |
| 318 | } |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 322 | void RuntimeDyldELF::resolveX86Relocation(const SectionEntry &Section, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 323 | uint64_t Offset, uint32_t Value, |
| 324 | uint32_t Type, int32_t Addend) { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 325 | switch (Type) { |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 326 | case ELF::R_386_32: { |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 327 | // Get the placeholder value from the generated object since |
| 328 | // a previous relocation attempt may have overwritten the loaded version |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 329 | uint32_t *Placeholder = |
| 330 | reinterpret_cast<uint32_t *>(Section.ObjAddress + Offset); |
| 331 | uint32_t *Target = reinterpret_cast<uint32_t *>(Section.Address + Offset); |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 332 | *Target = *Placeholder + Value + Addend; |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 333 | break; |
| 334 | } |
| 335 | case ELF::R_386_PC32: { |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 336 | // Get the placeholder value from the generated object since |
| 337 | // a previous relocation attempt may have overwritten the loaded version |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 338 | uint32_t *Placeholder = |
| 339 | reinterpret_cast<uint32_t *>(Section.ObjAddress + Offset); |
| 340 | uint32_t *Target = reinterpret_cast<uint32_t *>(Section.Address + Offset); |
| 341 | uint32_t FinalAddress = ((Section.LoadAddress + Offset) & 0xFFFFFFFF); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 342 | uint32_t RealOffset = *Placeholder + Value + Addend - FinalAddress; |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 343 | *Target = RealOffset; |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 344 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 345 | } |
| 346 | default: |
| 347 | // There are other relocation types, but it appears these are the |
| 348 | // only ones currently used by the LLVM ELF object writer |
| 349 | llvm_unreachable("Relocation type not implemented yet!"); |
| 350 | break; |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Tim Northover | fa1b2f8 | 2013-05-04 20:13:59 +0000 | [diff] [blame] | 354 | void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 355 | uint64_t Offset, uint64_t Value, |
| 356 | uint32_t Type, int64_t Addend) { |
| 357 | uint32_t *TargetPtr = reinterpret_cast<uint32_t *>(Section.Address + Offset); |
Tim Northover | fa1b2f8 | 2013-05-04 20:13:59 +0000 | [diff] [blame] | 358 | uint64_t FinalAddress = Section.LoadAddress + Offset; |
| 359 | |
| 360 | DEBUG(dbgs() << "resolveAArch64Relocation, LocalAddress: 0x" |
| 361 | << format("%llx", Section.Address + Offset) |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 362 | << " FinalAddress: 0x" << format("%llx", FinalAddress) |
| 363 | << " Value: 0x" << format("%llx", Value) << " Type: 0x" |
| 364 | << format("%x", Type) << " Addend: 0x" << format("%llx", Addend) |
Tim Northover | fa1b2f8 | 2013-05-04 20:13:59 +0000 | [diff] [blame] | 365 | << "\n"); |
| 366 | |
| 367 | switch (Type) { |
| 368 | default: |
| 369 | llvm_unreachable("Relocation type not implemented yet!"); |
| 370 | break; |
Tim Northover | b23d8db | 2013-05-04 20:14:14 +0000 | [diff] [blame] | 371 | case ELF::R_AARCH64_ABS64: { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 372 | uint64_t *TargetPtr = |
| 373 | reinterpret_cast<uint64_t *>(Section.Address + Offset); |
Tim Northover | b23d8db | 2013-05-04 20:14:14 +0000 | [diff] [blame] | 374 | *TargetPtr = Value + Addend; |
| 375 | break; |
| 376 | } |
Tim Northover | 5959ea3 | 2013-05-19 15:39:03 +0000 | [diff] [blame] | 377 | case ELF::R_AARCH64_PREL32: { |
Tim Northover | fa1b2f8 | 2013-05-04 20:13:59 +0000 | [diff] [blame] | 378 | uint64_t Result = Value + Addend - FinalAddress; |
Michael J. Spencer | 126973b | 2013-08-08 22:27:13 +0000 | [diff] [blame] | 379 | assert(static_cast<int64_t>(Result) >= INT32_MIN && |
Tim Northover | fa1b2f8 | 2013-05-04 20:13:59 +0000 | [diff] [blame] | 380 | static_cast<int64_t>(Result) <= UINT32_MAX); |
| 381 | *TargetPtr = static_cast<uint32_t>(Result & 0xffffffffU); |
| 382 | break; |
| 383 | } |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 384 | case ELF::R_AARCH64_CALL26: // fallthrough |
| 385 | case ELF::R_AARCH64_JUMP26: { |
| 386 | // Operation: S+A-P. Set Call or B immediate value to bits fff_fffc of the |
| 387 | // calculation. |
| 388 | uint64_t BranchImm = Value + Addend - FinalAddress; |
| 389 | |
| 390 | // "Check that -2^27 <= result < 2^27". |
Michael J. Spencer | 126973b | 2013-08-08 22:27:13 +0000 | [diff] [blame] | 391 | assert(-(1LL << 27) <= static_cast<int64_t>(BranchImm) && |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 392 | static_cast<int64_t>(BranchImm) < (1LL << 27)); |
Tim Northover | 5959ea3 | 2013-05-19 15:39:03 +0000 | [diff] [blame] | 393 | |
| 394 | // AArch64 code is emitted with .rela relocations. The data already in any |
| 395 | // bits affected by the relocation on entry is garbage. |
| 396 | *TargetPtr &= 0xfc000000U; |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 397 | // Immediate goes in bits 25:0 of B and BL. |
| 398 | *TargetPtr |= static_cast<uint32_t>(BranchImm & 0xffffffcU) >> 2; |
| 399 | break; |
| 400 | } |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 401 | case ELF::R_AARCH64_MOVW_UABS_G3: { |
| 402 | uint64_t Result = Value + Addend; |
Tim Northover | 5959ea3 | 2013-05-19 15:39:03 +0000 | [diff] [blame] | 403 | |
| 404 | // AArch64 code is emitted with .rela relocations. The data already in any |
| 405 | // bits affected by the relocation on entry is garbage. |
Tim Northover | ca8a007 | 2013-07-25 12:42:52 +0000 | [diff] [blame] | 406 | *TargetPtr &= 0xffe0001fU; |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 407 | // Immediate goes in bits 20:5 of MOVZ/MOVK instruction |
| 408 | *TargetPtr |= Result >> (48 - 5); |
Tim Northover | 8625fd8 | 2013-07-01 19:23:10 +0000 | [diff] [blame] | 409 | // Shift must be "lsl #48", in bits 22:21 |
| 410 | assert((*TargetPtr >> 21 & 0x3) == 3 && "invalid shift for relocation"); |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 411 | break; |
| 412 | } |
| 413 | case ELF::R_AARCH64_MOVW_UABS_G2_NC: { |
| 414 | uint64_t Result = Value + Addend; |
Tim Northover | 5959ea3 | 2013-05-19 15:39:03 +0000 | [diff] [blame] | 415 | |
Tim Northover | 5959ea3 | 2013-05-19 15:39:03 +0000 | [diff] [blame] | 416 | // AArch64 code is emitted with .rela relocations. The data already in any |
| 417 | // bits affected by the relocation on entry is garbage. |
Tim Northover | ca8a007 | 2013-07-25 12:42:52 +0000 | [diff] [blame] | 418 | *TargetPtr &= 0xffe0001fU; |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 419 | // Immediate goes in bits 20:5 of MOVZ/MOVK instruction |
| 420 | *TargetPtr |= ((Result & 0xffff00000000ULL) >> (32 - 5)); |
Tim Northover | 8625fd8 | 2013-07-01 19:23:10 +0000 | [diff] [blame] | 421 | // Shift must be "lsl #32", in bits 22:21 |
| 422 | assert((*TargetPtr >> 21 & 0x3) == 2 && "invalid shift for relocation"); |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 423 | break; |
| 424 | } |
| 425 | case ELF::R_AARCH64_MOVW_UABS_G1_NC: { |
| 426 | uint64_t Result = Value + Addend; |
Tim Northover | 5959ea3 | 2013-05-19 15:39:03 +0000 | [diff] [blame] | 427 | |
| 428 | // AArch64 code is emitted with .rela relocations. The data already in any |
| 429 | // bits affected by the relocation on entry is garbage. |
Tim Northover | ca8a007 | 2013-07-25 12:42:52 +0000 | [diff] [blame] | 430 | *TargetPtr &= 0xffe0001fU; |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 431 | // Immediate goes in bits 20:5 of MOVZ/MOVK instruction |
| 432 | *TargetPtr |= ((Result & 0xffff0000U) >> (16 - 5)); |
Tim Northover | 8625fd8 | 2013-07-01 19:23:10 +0000 | [diff] [blame] | 433 | // Shift must be "lsl #16", in bits 22:2 |
| 434 | assert((*TargetPtr >> 21 & 0x3) == 1 && "invalid shift for relocation"); |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 435 | break; |
| 436 | } |
| 437 | case ELF::R_AARCH64_MOVW_UABS_G0_NC: { |
| 438 | uint64_t Result = Value + Addend; |
Tim Northover | 5959ea3 | 2013-05-19 15:39:03 +0000 | [diff] [blame] | 439 | |
| 440 | // AArch64 code is emitted with .rela relocations. The data already in any |
| 441 | // bits affected by the relocation on entry is garbage. |
Tim Northover | ca8a007 | 2013-07-25 12:42:52 +0000 | [diff] [blame] | 442 | *TargetPtr &= 0xffe0001fU; |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 443 | // Immediate goes in bits 20:5 of MOVZ/MOVK instruction |
| 444 | *TargetPtr |= ((Result & 0xffffU) << 5); |
Tim Northover | 8625fd8 | 2013-07-01 19:23:10 +0000 | [diff] [blame] | 445 | // Shift must be "lsl #0", in bits 22:21. |
| 446 | assert((*TargetPtr >> 21 & 0x3) == 0 && "invalid shift for relocation"); |
Tim Northover | 4d01c1e | 2013-05-04 20:14:04 +0000 | [diff] [blame] | 447 | break; |
| 448 | } |
Bradley Smith | 9d80849 | 2014-02-11 12:59:09 +0000 | [diff] [blame] | 449 | case ELF::R_AARCH64_ADR_PREL_PG_HI21: { |
| 450 | // Operation: Page(S+A) - Page(P) |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 451 | uint64_t Result = |
| 452 | ((Value + Addend) & ~0xfffULL) - (FinalAddress & ~0xfffULL); |
Bradley Smith | 9d80849 | 2014-02-11 12:59:09 +0000 | [diff] [blame] | 453 | |
| 454 | // Check that -2^32 <= X < 2^32 |
| 455 | assert(static_cast<int64_t>(Result) >= (-1LL << 32) && |
| 456 | static_cast<int64_t>(Result) < (1LL << 32) && |
| 457 | "overflow check failed for relocation"); |
| 458 | |
| 459 | // AArch64 code is emitted with .rela relocations. The data already in any |
| 460 | // bits affected by the relocation on entry is garbage. |
| 461 | *TargetPtr &= 0x9f00001fU; |
| 462 | // Immediate goes in bits 30:29 + 5:23 of ADRP instruction, taken |
| 463 | // from bits 32:12 of X. |
| 464 | *TargetPtr |= ((Result & 0x3000U) << (29 - 12)); |
| 465 | *TargetPtr |= ((Result & 0x1ffffc000ULL) >> (14 - 5)); |
| 466 | break; |
| 467 | } |
| 468 | case ELF::R_AARCH64_LDST32_ABS_LO12_NC: { |
| 469 | // Operation: S + A |
| 470 | uint64_t Result = Value + Addend; |
| 471 | |
| 472 | // AArch64 code is emitted with .rela relocations. The data already in any |
| 473 | // bits affected by the relocation on entry is garbage. |
| 474 | *TargetPtr &= 0xffc003ffU; |
| 475 | // Immediate goes in bits 21:10 of LD/ST instruction, taken |
| 476 | // from bits 11:2 of X |
| 477 | *TargetPtr |= ((Result & 0xffc) << (10 - 2)); |
| 478 | break; |
| 479 | } |
| 480 | case ELF::R_AARCH64_LDST64_ABS_LO12_NC: { |
| 481 | // Operation: S + A |
| 482 | uint64_t Result = Value + Addend; |
| 483 | |
| 484 | // AArch64 code is emitted with .rela relocations. The data already in any |
| 485 | // bits affected by the relocation on entry is garbage. |
| 486 | *TargetPtr &= 0xffc003ffU; |
| 487 | // Immediate goes in bits 21:10 of LD/ST instruction, taken |
| 488 | // from bits 11:3 of X |
| 489 | *TargetPtr |= ((Result & 0xff8) << (10 - 3)); |
| 490 | break; |
| 491 | } |
Tim Northover | fa1b2f8 | 2013-05-04 20:13:59 +0000 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 495 | void RuntimeDyldELF::resolveARMRelocation(const SectionEntry &Section, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 496 | uint64_t Offset, uint32_t Value, |
| 497 | uint32_t Type, int32_t Addend) { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 498 | // TODO: Add Thumb relocations. |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 499 | uint32_t *Placeholder = |
| 500 | reinterpret_cast<uint32_t *>(Section.ObjAddress + Offset); |
| 501 | uint32_t *TargetPtr = (uint32_t *)(Section.Address + Offset); |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 502 | uint32_t FinalAddress = ((Section.LoadAddress + Offset) & 0xFFFFFFFF); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 503 | Value += Addend; |
| 504 | |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 505 | DEBUG(dbgs() << "resolveARMRelocation, LocalAddress: " |
| 506 | << Section.Address + Offset |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 507 | << " FinalAddress: " << format("%p", FinalAddress) << " Value: " |
| 508 | << format("%x", Value) << " Type: " << format("%x", Type) |
| 509 | << " Addend: " << format("%x", Addend) << "\n"); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 510 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 511 | switch (Type) { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 512 | default: |
| 513 | llvm_unreachable("Not implemented relocation type!"); |
| 514 | |
Renato Golin | 8cea6e8 | 2014-01-29 11:50:56 +0000 | [diff] [blame] | 515 | case ELF::R_ARM_NONE: |
| 516 | break; |
Michael J. Spencer | bae14ce | 2013-01-04 20:36:28 +0000 | [diff] [blame] | 517 | // Write a 32bit value to relocation address, taking into account the |
Tim Northover | 471cbb7 | 2012-10-03 16:29:42 +0000 | [diff] [blame] | 518 | // implicit addend encoded in the target. |
Renato Golin | 8cea6e8 | 2014-01-29 11:50:56 +0000 | [diff] [blame] | 519 | case ELF::R_ARM_PREL31: |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 520 | case ELF::R_ARM_TARGET1: |
| 521 | case ELF::R_ARM_ABS32: |
| 522 | *TargetPtr = *Placeholder + Value; |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 523 | break; |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 524 | // Write first 16 bit of 32 bit value to the mov instruction. |
| 525 | // Last 4 bit should be shifted. |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 526 | case ELF::R_ARM_MOVW_ABS_NC: |
Tim Northover | 471cbb7 | 2012-10-03 16:29:42 +0000 | [diff] [blame] | 527 | // We are not expecting any other addend in the relocation address. |
Michael J. Spencer | bae14ce | 2013-01-04 20:36:28 +0000 | [diff] [blame] | 528 | // Using 0x000F0FFF because MOVW has its 16 bit immediate split into 2 |
Tim Northover | 471cbb7 | 2012-10-03 16:29:42 +0000 | [diff] [blame] | 529 | // non-contiguous fields. |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 530 | assert((*Placeholder & 0x000F0FFF) == 0); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 531 | Value = Value & 0xFFFF; |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 532 | *TargetPtr = *Placeholder | (Value & 0xFFF); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 533 | *TargetPtr |= ((Value >> 12) & 0xF) << 16; |
| 534 | break; |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 535 | // Write last 16 bit of 32 bit value to the mov instruction. |
| 536 | // Last 4 bit should be shifted. |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 537 | case ELF::R_ARM_MOVT_ABS: |
Tim Northover | 471cbb7 | 2012-10-03 16:29:42 +0000 | [diff] [blame] | 538 | // We are not expecting any other addend in the relocation address. |
| 539 | // Use 0x000F0FFF for the same reason as R_ARM_MOVW_ABS_NC. |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 540 | assert((*Placeholder & 0x000F0FFF) == 0); |
| 541 | |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 542 | Value = (Value >> 16) & 0xFFFF; |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 543 | *TargetPtr = *Placeholder | (Value & 0xFFF); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 544 | *TargetPtr |= ((Value >> 12) & 0xF) << 16; |
| 545 | break; |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 546 | // Write 24 bit relative value to the branch instruction. |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 547 | case ELF::R_ARM_PC24: // Fall through. |
| 548 | case ELF::R_ARM_CALL: // Fall through. |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 549 | case ELF::R_ARM_JUMP24: { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 550 | int32_t RelValue = static_cast<int32_t>(Value - FinalAddress - 8); |
| 551 | RelValue = (RelValue & 0x03FFFFFC) >> 2; |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 552 | assert((*TargetPtr & 0xFFFFFF) == 0xFFFFFE); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 553 | *TargetPtr &= 0xFF000000; |
| 554 | *TargetPtr |= RelValue; |
| 555 | break; |
| 556 | } |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 557 | case ELF::R_ARM_PRIVATE_0: |
| 558 | // This relocation is reserved by the ARM ELF ABI for internal use. We |
| 559 | // appropriate it here to act as an R_ARM_ABS32 without any addend for use |
| 560 | // in the stubs created during JIT (which can't put an addend into the |
| 561 | // original object file). |
| 562 | *TargetPtr = Value; |
| 563 | break; |
| 564 | } |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 567 | void RuntimeDyldELF::resolveMIPSRelocation(const SectionEntry &Section, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 568 | uint64_t Offset, uint32_t Value, |
| 569 | uint32_t Type, int32_t Addend) { |
| 570 | uint32_t *Placeholder = |
| 571 | reinterpret_cast<uint32_t *>(Section.ObjAddress + Offset); |
| 572 | uint32_t *TargetPtr = (uint32_t *)(Section.Address + Offset); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 573 | Value += Addend; |
| 574 | |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 575 | DEBUG(dbgs() << "resolveMipselocation, LocalAddress: " |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 576 | << Section.Address + Offset << " FinalAddress: " |
| 577 | << format("%p", Section.LoadAddress + Offset) << " Value: " |
| 578 | << format("%x", Value) << " Type: " << format("%x", Type) |
| 579 | << " Addend: " << format("%x", Addend) << "\n"); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 580 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 581 | switch (Type) { |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 582 | default: |
| 583 | llvm_unreachable("Not implemented relocation type!"); |
| 584 | break; |
| 585 | case ELF::R_MIPS_32: |
Akira Hatanaka | 2e23624 | 2013-07-24 01:58:40 +0000 | [diff] [blame] | 586 | *TargetPtr = Value + (*Placeholder); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 587 | break; |
| 588 | case ELF::R_MIPS_26: |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 589 | *TargetPtr = ((*Placeholder) & 0xfc000000) | ((Value & 0x0fffffff) >> 2); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 590 | break; |
| 591 | case ELF::R_MIPS_HI16: |
| 592 | // Get the higher 16-bits. Also add 1 if bit 15 is 1. |
Akira Hatanaka | 2e23624 | 2013-07-24 01:58:40 +0000 | [diff] [blame] | 593 | Value += ((*Placeholder) & 0x0000ffff) << 16; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 594 | *TargetPtr = |
| 595 | ((*Placeholder) & 0xffff0000) | (((Value + 0x8000) >> 16) & 0xffff); |
Akira Hatanaka | 2e23624 | 2013-07-24 01:58:40 +0000 | [diff] [blame] | 596 | break; |
| 597 | case ELF::R_MIPS_LO16: |
| 598 | Value += ((*Placeholder) & 0x0000ffff); |
| 599 | *TargetPtr = ((*Placeholder) & 0xffff0000) | (Value & 0xffff); |
| 600 | break; |
| 601 | case ELF::R_MIPS_UNUSED1: |
| 602 | // Similar to ELF::R_ARM_PRIVATE_0, R_MIPS_UNUSED1 and R_MIPS_UNUSED2 |
| 603 | // are used for internal JIT purpose. These relocations are similar to |
| 604 | // R_MIPS_HI16 and R_MIPS_LO16, but they do not take any addend into |
| 605 | // account. |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 606 | *TargetPtr = |
| 607 | ((*TargetPtr) & 0xffff0000) | (((Value + 0x8000) >> 16) & 0xffff); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 608 | break; |
Akira Hatanaka | 2e23624 | 2013-07-24 01:58:40 +0000 | [diff] [blame] | 609 | case ELF::R_MIPS_UNUSED2: |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 610 | *TargetPtr = ((*TargetPtr) & 0xffff0000) | (Value & 0xffff); |
| 611 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 612 | } |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 615 | // Return the .TOC. section address to R_PPC64_TOC relocations. |
| 616 | uint64_t RuntimeDyldELF::findPPC64TOC() const { |
| 617 | // The TOC consists of sections .got, .toc, .tocbss, .plt in that |
| 618 | // order. The TOC starts where the first of these sections starts. |
| 619 | SectionList::const_iterator it = Sections.begin(); |
| 620 | SectionList::const_iterator ite = Sections.end(); |
| 621 | for (; it != ite; ++it) { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 622 | if (it->Name == ".got" || it->Name == ".toc" || it->Name == ".tocbss" || |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 623 | it->Name == ".plt") |
| 624 | break; |
| 625 | } |
| 626 | if (it == ite) { |
| 627 | // This may happen for |
| 628 | // * references to TOC base base (sym@toc, .odp relocation) without |
| 629 | // a .toc directive. |
| 630 | // In this case just use the first section (which is usually |
| 631 | // the .odp) since the code won't reference the .toc base |
| 632 | // directly. |
| 633 | it = Sections.begin(); |
| 634 | } |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 635 | assert(it != ite); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 636 | // Per the ppc64-elf-linux ABI, The TOC base is TOC value plus 0x8000 |
| 637 | // thus permitting a full 64 Kbytes segment. |
| 638 | return it->LoadAddress + 0x8000; |
| 639 | } |
| 640 | |
| 641 | // Returns the sections and offset associated with the ODP entry referenced |
| 642 | // by Symbol. |
| 643 | void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj, |
| 644 | ObjSectionToIDMap &LocalSections, |
| 645 | RelocationValueRef &Rel) { |
| 646 | // Get the ELF symbol value (st_value) to compare with Relocation offset in |
| 647 | // .opd entries |
Rafael Espindola | 5e812af | 2014-01-30 02:49:50 +0000 | [diff] [blame] | 648 | for (section_iterator si = Obj.begin_sections(), se = Obj.end_sections(); |
| 649 | si != se; ++si) { |
Rafael Espindola | a61f1e9 | 2013-06-03 19:37:34 +0000 | [diff] [blame] | 650 | section_iterator RelSecI = si->getRelocatedSection(); |
| 651 | if (RelSecI == Obj.end_sections()) |
| 652 | continue; |
| 653 | |
| 654 | StringRef RelSectionName; |
| 655 | check(RelSecI->getName(RelSectionName)); |
| 656 | if (RelSectionName != ".opd") |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 657 | continue; |
| 658 | |
Rafael Espindola | b5155a5 | 2014-02-10 20:24:04 +0000 | [diff] [blame] | 659 | for (relocation_iterator i = si->relocation_begin(), |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 660 | e = si->relocation_end(); |
| 661 | i != e;) { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 662 | // The R_PPC64_ADDR64 relocation indicates the first field |
| 663 | // of a .opd entry |
| 664 | uint64_t TypeFunc; |
| 665 | check(i->getType(TypeFunc)); |
| 666 | if (TypeFunc != ELF::R_PPC64_ADDR64) { |
Rafael Espindola | 5e812af | 2014-01-30 02:49:50 +0000 | [diff] [blame] | 667 | ++i; |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 668 | continue; |
| 669 | } |
| 670 | |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 671 | uint64_t TargetSymbolOffset; |
Rafael Espindola | 806f006 | 2013-06-05 01:33:53 +0000 | [diff] [blame] | 672 | symbol_iterator TargetSymbol = i->getSymbol(); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 673 | check(i->getOffset(TargetSymbolOffset)); |
Rafael Espindola | 0d15f73 | 2013-05-09 03:39:05 +0000 | [diff] [blame] | 674 | int64_t Addend; |
| 675 | check(getELFRelocationAddend(*i, Addend)); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 676 | |
Rafael Espindola | 5e812af | 2014-01-30 02:49:50 +0000 | [diff] [blame] | 677 | ++i; |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 678 | if (i == e) |
| 679 | break; |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 680 | |
| 681 | // Just check if following relocation is a R_PPC64_TOC |
| 682 | uint64_t TypeTOC; |
| 683 | check(i->getType(TypeTOC)); |
| 684 | if (TypeTOC != ELF::R_PPC64_TOC) |
| 685 | continue; |
| 686 | |
| 687 | // Finally compares the Symbol value and the target symbol offset |
| 688 | // to check if this .opd entry refers to the symbol the relocation |
| 689 | // points to. |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 690 | if (Rel.Addend != (int64_t)TargetSymbolOffset) |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 691 | continue; |
| 692 | |
| 693 | section_iterator tsi(Obj.end_sections()); |
Rafael Espindola | 806f006 | 2013-06-05 01:33:53 +0000 | [diff] [blame] | 694 | check(TargetSymbol->getSection(tsi)); |
Lang Hames | 9b2dc93 | 2014-02-18 21:46:39 +0000 | [diff] [blame] | 695 | bool IsCode = false; |
| 696 | tsi->isText(IsCode); |
| 697 | Rel.SectionID = findOrEmitSection(Obj, (*tsi), IsCode, LocalSections); |
Rafael Espindola | 0d15f73 | 2013-05-09 03:39:05 +0000 | [diff] [blame] | 698 | Rel.Addend = (intptr_t)Addend; |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 699 | return; |
| 700 | } |
| 701 | } |
| 702 | llvm_unreachable("Attempting to get address of ODP entry!"); |
| 703 | } |
| 704 | |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 705 | // Relocation masks following the #lo(value), #hi(value), #ha(value), |
| 706 | // #higher(value), #highera(value), #highest(value), and #highesta(value) |
| 707 | // macros defined in section 4.5.1. Relocation Types of the PPC-elf64abi |
| 708 | // document. |
| 709 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 710 | static inline uint16_t applyPPClo(uint64_t value) { return value & 0xffff; } |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 711 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 712 | static inline uint16_t applyPPChi(uint64_t value) { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 713 | return (value >> 16) & 0xffff; |
| 714 | } |
| 715 | |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 716 | static inline uint16_t applyPPCha (uint64_t value) { |
| 717 | return ((value + 0x8000) >> 16) & 0xffff; |
| 718 | } |
| 719 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 720 | static inline uint16_t applyPPChigher(uint64_t value) { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 721 | return (value >> 32) & 0xffff; |
| 722 | } |
| 723 | |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 724 | static inline uint16_t applyPPChighera (uint64_t value) { |
| 725 | return ((value + 0x8000) >> 32) & 0xffff; |
| 726 | } |
| 727 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 728 | static inline uint16_t applyPPChighest(uint64_t value) { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 729 | return (value >> 48) & 0xffff; |
| 730 | } |
| 731 | |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 732 | static inline uint16_t applyPPChighesta (uint64_t value) { |
| 733 | return ((value + 0x8000) >> 48) & 0xffff; |
| 734 | } |
| 735 | |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 736 | void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 737 | uint64_t Offset, uint64_t Value, |
| 738 | uint32_t Type, int64_t Addend) { |
| 739 | uint8_t *LocalAddress = Section.Address + Offset; |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 740 | switch (Type) { |
| 741 | default: |
| 742 | llvm_unreachable("Relocation type not implemented yet!"); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 743 | break; |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 744 | case ELF::R_PPC64_ADDR16: |
| 745 | writeInt16BE(LocalAddress, applyPPClo(Value + Addend)); |
| 746 | break; |
| 747 | case ELF::R_PPC64_ADDR16_DS: |
| 748 | writeInt16BE(LocalAddress, applyPPClo(Value + Addend) & ~3); |
| 749 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 750 | case ELF::R_PPC64_ADDR16_LO: |
| 751 | writeInt16BE(LocalAddress, applyPPClo(Value + Addend)); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 752 | break; |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 753 | case ELF::R_PPC64_ADDR16_LO_DS: |
| 754 | writeInt16BE(LocalAddress, applyPPClo(Value + Addend) & ~3); |
| 755 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 756 | case ELF::R_PPC64_ADDR16_HI: |
| 757 | writeInt16BE(LocalAddress, applyPPChi(Value + Addend)); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 758 | break; |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 759 | case ELF::R_PPC64_ADDR16_HA: |
| 760 | writeInt16BE(LocalAddress, applyPPCha(Value + Addend)); |
| 761 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 762 | case ELF::R_PPC64_ADDR16_HIGHER: |
| 763 | writeInt16BE(LocalAddress, applyPPChigher(Value + Addend)); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 764 | break; |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 765 | case ELF::R_PPC64_ADDR16_HIGHERA: |
| 766 | writeInt16BE(LocalAddress, applyPPChighera(Value + Addend)); |
| 767 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 768 | case ELF::R_PPC64_ADDR16_HIGHEST: |
| 769 | writeInt16BE(LocalAddress, applyPPChighest(Value + Addend)); |
| 770 | break; |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 771 | case ELF::R_PPC64_ADDR16_HIGHESTA: |
| 772 | writeInt16BE(LocalAddress, applyPPChighesta(Value + Addend)); |
| 773 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 774 | case ELF::R_PPC64_ADDR14: { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 775 | assert(((Value + Addend) & 3) == 0); |
| 776 | // Preserve the AA/LK bits in the branch instruction |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 777 | uint8_t aalk = *(LocalAddress + 3); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 778 | writeInt16BE(LocalAddress + 2, (aalk & 3) | ((Value + Addend) & 0xfffc)); |
| 779 | } break; |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 780 | case ELF::R_PPC64_REL16_LO: { |
| 781 | uint64_t FinalAddress = (Section.LoadAddress + Offset); |
| 782 | uint64_t Delta = Value - FinalAddress + Addend; |
| 783 | writeInt16BE(LocalAddress, applyPPClo(Delta)); |
| 784 | } break; |
| 785 | case ELF::R_PPC64_REL16_HI: { |
| 786 | uint64_t FinalAddress = (Section.LoadAddress + Offset); |
| 787 | uint64_t Delta = Value - FinalAddress + Addend; |
| 788 | writeInt16BE(LocalAddress, applyPPChi(Delta)); |
| 789 | } break; |
| 790 | case ELF::R_PPC64_REL16_HA: { |
| 791 | uint64_t FinalAddress = (Section.LoadAddress + Offset); |
| 792 | uint64_t Delta = Value - FinalAddress + Addend; |
| 793 | writeInt16BE(LocalAddress, applyPPCha(Delta)); |
| 794 | } break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 795 | case ELF::R_PPC64_ADDR32: { |
Adhemerval Zanella | 9b0b781 | 2013-01-04 19:08:13 +0000 | [diff] [blame] | 796 | int32_t Result = static_cast<int32_t>(Value + Addend); |
| 797 | if (SignExtend32<32>(Result) != Result) |
Adhemerval Zanella | 1ae2248 | 2013-01-09 17:08:15 +0000 | [diff] [blame] | 798 | llvm_unreachable("Relocation R_PPC64_ADDR32 overflow"); |
Adhemerval Zanella | 9b0b781 | 2013-01-04 19:08:13 +0000 | [diff] [blame] | 799 | writeInt32BE(LocalAddress, Result); |
| 800 | } break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 801 | case ELF::R_PPC64_REL24: { |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 802 | uint64_t FinalAddress = (Section.LoadAddress + Offset); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 803 | int32_t delta = static_cast<int32_t>(Value - FinalAddress + Addend); |
| 804 | if (SignExtend32<24>(delta) != delta) |
| 805 | llvm_unreachable("Relocation R_PPC64_REL24 overflow"); |
| 806 | // Generates a 'bl <address>' instruction |
| 807 | writeInt32BE(LocalAddress, 0x48000001 | (delta & 0x03FFFFFC)); |
| 808 | } break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 809 | case ELF::R_PPC64_REL32: { |
Adhemerval Zanella | 1ae2248 | 2013-01-09 17:08:15 +0000 | [diff] [blame] | 810 | uint64_t FinalAddress = (Section.LoadAddress + Offset); |
| 811 | int32_t delta = static_cast<int32_t>(Value - FinalAddress + Addend); |
| 812 | if (SignExtend32<32>(delta) != delta) |
| 813 | llvm_unreachable("Relocation R_PPC64_REL32 overflow"); |
| 814 | writeInt32BE(LocalAddress, delta); |
| 815 | } break; |
Adhemerval Zanella | e8bd03d | 2013-05-06 17:21:23 +0000 | [diff] [blame] | 816 | case ELF::R_PPC64_REL64: { |
| 817 | uint64_t FinalAddress = (Section.LoadAddress + Offset); |
| 818 | uint64_t Delta = Value - FinalAddress + Addend; |
| 819 | writeInt64BE(LocalAddress, Delta); |
| 820 | } break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 821 | case ELF::R_PPC64_ADDR64: |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 822 | writeInt64BE(LocalAddress, Value + Addend); |
| 823 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 824 | case ELF::R_PPC64_TOC: |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 825 | writeInt64BE(LocalAddress, findPPC64TOC()); |
| 826 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 827 | case ELF::R_PPC64_TOC16: { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 828 | uint64_t TOCStart = findPPC64TOC(); |
| 829 | Value = applyPPClo((Value + Addend) - TOCStart); |
| 830 | writeInt16BE(LocalAddress, applyPPClo(Value)); |
| 831 | } break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 832 | case ELF::R_PPC64_TOC16_DS: { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 833 | uint64_t TOCStart = findPPC64TOC(); |
| 834 | Value = ((Value + Addend) - TOCStart); |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 835 | writeInt16BE(LocalAddress, applyPPClo(Value) & ~3); |
| 836 | } break; |
| 837 | case ELF::R_PPC64_TOC16_LO: { |
| 838 | uint64_t TOCStart = findPPC64TOC(); |
| 839 | Value = ((Value + Addend) - TOCStart); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 840 | writeInt16BE(LocalAddress, applyPPClo(Value)); |
| 841 | } break; |
Ulrich Weigand | dbc8e1a | 2014-06-20 17:51:47 +0000 | [diff] [blame^] | 842 | case ELF::R_PPC64_TOC16_LO_DS: { |
| 843 | uint64_t TOCStart = findPPC64TOC(); |
| 844 | Value = ((Value + Addend) - TOCStart); |
| 845 | writeInt16BE(LocalAddress, applyPPClo(Value) & ~3); |
| 846 | } break; |
| 847 | case ELF::R_PPC64_TOC16_HI: { |
| 848 | uint64_t TOCStart = findPPC64TOC(); |
| 849 | Value = ((Value + Addend) - TOCStart); |
| 850 | writeInt16BE(LocalAddress, applyPPChi(Value)); |
| 851 | } break; |
| 852 | case ELF::R_PPC64_TOC16_HA: { |
| 853 | uint64_t TOCStart = findPPC64TOC(); |
| 854 | Value = ((Value + Addend) - TOCStart); |
| 855 | writeInt16BE(LocalAddress, applyPPCha(Value)); |
| 856 | } break; |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | |
Richard Sandiford | ca04408 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 860 | void RuntimeDyldELF::resolveSystemZRelocation(const SectionEntry &Section, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 861 | uint64_t Offset, uint64_t Value, |
| 862 | uint32_t Type, int64_t Addend) { |
Richard Sandiford | ca04408 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 863 | uint8_t *LocalAddress = Section.Address + Offset; |
| 864 | switch (Type) { |
| 865 | default: |
| 866 | llvm_unreachable("Relocation type not implemented yet!"); |
| 867 | break; |
| 868 | case ELF::R_390_PC16DBL: |
| 869 | case ELF::R_390_PLT16DBL: { |
| 870 | int64_t Delta = (Value + Addend) - (Section.LoadAddress + Offset); |
| 871 | assert(int16_t(Delta / 2) * 2 == Delta && "R_390_PC16DBL overflow"); |
| 872 | writeInt16BE(LocalAddress, Delta / 2); |
| 873 | break; |
| 874 | } |
| 875 | case ELF::R_390_PC32DBL: |
| 876 | case ELF::R_390_PLT32DBL: { |
| 877 | int64_t Delta = (Value + Addend) - (Section.LoadAddress + Offset); |
| 878 | assert(int32_t(Delta / 2) * 2 == Delta && "R_390_PC32DBL overflow"); |
| 879 | writeInt32BE(LocalAddress, Delta / 2); |
| 880 | break; |
| 881 | } |
| 882 | case ELF::R_390_PC32: { |
| 883 | int64_t Delta = (Value + Addend) - (Section.LoadAddress + Offset); |
| 884 | assert(int32_t(Delta) == Delta && "R_390_PC32 overflow"); |
| 885 | writeInt32BE(LocalAddress, Delta); |
| 886 | break; |
| 887 | } |
| 888 | case ELF::R_390_64: |
| 889 | writeInt64BE(LocalAddress, Value + Addend); |
| 890 | break; |
| 891 | } |
| 892 | } |
| 893 | |
Andrew Kaylor | 5f3a998 | 2013-08-19 19:38:06 +0000 | [diff] [blame] | 894 | // The target location for the relocation is described by RE.SectionID and |
| 895 | // RE.Offset. RE.SectionID can be used to find the SectionEntry. Each |
| 896 | // SectionEntry has three members describing its location. |
| 897 | // SectionEntry::Address is the address at which the section has been loaded |
| 898 | // into memory in the current (host) process. SectionEntry::LoadAddress is the |
| 899 | // address that the section will have in the target process. |
| 900 | // SectionEntry::ObjAddress is the address of the bits for this section in the |
| 901 | // original emitted object image (also in the current address space). |
| 902 | // |
| 903 | // Relocations will be applied as if the section were loaded at |
| 904 | // SectionEntry::LoadAddress, but they will be applied at an address based |
| 905 | // on SectionEntry::Address. SectionEntry::ObjAddress will be used to refer to |
| 906 | // Target memory contents if they are required for value calculations. |
| 907 | // |
| 908 | // The Value parameter here is the load address of the symbol for the |
| 909 | // relocation to be applied. For relocations which refer to symbols in the |
| 910 | // current object Value will be the LoadAddress of the section in which |
| 911 | // the symbol resides (RE.Addend provides additional information about the |
| 912 | // symbol location). For external symbols, Value will be the address of the |
| 913 | // symbol in the target address space. |
Rafael Espindola | f1f1c62 | 2013-04-29 17:24:34 +0000 | [diff] [blame] | 914 | void RuntimeDyldELF::resolveRelocation(const RelocationEntry &RE, |
Andrew Kaylor | 5f3a998 | 2013-08-19 19:38:06 +0000 | [diff] [blame] | 915 | uint64_t Value) { |
Rafael Espindola | f1f1c62 | 2013-04-29 17:24:34 +0000 | [diff] [blame] | 916 | const SectionEntry &Section = Sections[RE.SectionID]; |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 917 | return resolveRelocation(Section, RE.Offset, Value, RE.RelType, RE.Addend, |
| 918 | RE.SymOffset); |
Rafael Espindola | f1f1c62 | 2013-04-29 17:24:34 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 921 | void RuntimeDyldELF::resolveRelocation(const SectionEntry &Section, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 922 | uint64_t Offset, uint64_t Value, |
| 923 | uint32_t Type, int64_t Addend, |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 924 | uint64_t SymOffset) { |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 925 | switch (Arch) { |
| 926 | case Triple::x86_64: |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 927 | resolveX86_64Relocation(Section, Offset, Value, Type, Addend, SymOffset); |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 928 | break; |
| 929 | case Triple::x86: |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 930 | resolveX86Relocation(Section, Offset, (uint32_t)(Value & 0xffffffffL), Type, |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 931 | (uint32_t)(Addend & 0xffffffffL)); |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 932 | break; |
Tim Northover | fa1b2f8 | 2013-05-04 20:13:59 +0000 | [diff] [blame] | 933 | case Triple::aarch64: |
Christian Pirker | 99974c7 | 2014-03-26 14:57:32 +0000 | [diff] [blame] | 934 | case Triple::aarch64_be: |
James Molloy | bd2ffa0 | 2014-04-30 10:15:41 +0000 | [diff] [blame] | 935 | case Triple::arm64: |
| 936 | case Triple::arm64_be: |
Tim Northover | fa1b2f8 | 2013-05-04 20:13:59 +0000 | [diff] [blame] | 937 | resolveAArch64Relocation(Section, Offset, Value, Type, Addend); |
| 938 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 939 | case Triple::arm: // Fall through. |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 940 | case Triple::armeb: |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 941 | case Triple::thumb: |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 942 | case Triple::thumbeb: |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 943 | resolveARMRelocation(Section, Offset, (uint32_t)(Value & 0xffffffffL), Type, |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 944 | (uint32_t)(Addend & 0xffffffffL)); |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 945 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 946 | case Triple::mips: // Fall through. |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 947 | case Triple::mipsel: |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 948 | resolveMIPSRelocation(Section, Offset, (uint32_t)(Value & 0xffffffffL), |
| 949 | Type, (uint32_t)(Addend & 0xffffffffL)); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 950 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 951 | case Triple::ppc64: // Fall through. |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame] | 952 | case Triple::ppc64le: |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 953 | resolvePPC64Relocation(Section, Offset, Value, Type, Addend); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 954 | break; |
Richard Sandiford | ca04408 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 955 | case Triple::systemz: |
| 956 | resolveSystemZRelocation(Section, Offset, Value, Type, Addend); |
| 957 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 958 | default: |
| 959 | llvm_unreachable("Unsupported CPU type!"); |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 963 | relocation_iterator RuntimeDyldELF::processRelocationRef( |
| 964 | unsigned SectionID, relocation_iterator RelI, ObjectImage &Obj, |
| 965 | ObjSectionToIDMap &ObjSectionToID, const SymbolTableMap &Symbols, |
| 966 | StubMap &Stubs) { |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 967 | uint64_t RelType; |
Juergen Ributzka | 046709f | 2014-03-21 07:26:41 +0000 | [diff] [blame] | 968 | Check(RelI->getType(RelType)); |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 969 | int64_t Addend; |
Juergen Ributzka | 046709f | 2014-03-21 07:26:41 +0000 | [diff] [blame] | 970 | Check(getELFRelocationAddend(*RelI, Addend)); |
| 971 | symbol_iterator Symbol = RelI->getSymbol(); |
Eli Bendersky | 667b879 | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 972 | |
| 973 | // Obtain the symbol name which is referenced in the relocation |
| 974 | StringRef TargetName; |
Rafael Espindola | 7595447 | 2013-06-05 02:55:01 +0000 | [diff] [blame] | 975 | if (Symbol != Obj.end_symbols()) |
| 976 | Symbol->getName(TargetName); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 977 | DEBUG(dbgs() << "\t\tRelType: " << RelType << " Addend: " << Addend |
| 978 | << " TargetName: " << TargetName << "\n"); |
Eli Bendersky | 667b879 | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 979 | RelocationValueRef Value; |
| 980 | // First search for the symbol in the local symbol table |
Rafael Espindola | 7595447 | 2013-06-05 02:55:01 +0000 | [diff] [blame] | 981 | SymbolTableMap::const_iterator lsi = Symbols.end(); |
| 982 | SymbolRef::Type SymType = SymbolRef::ST_Unknown; |
| 983 | if (Symbol != Obj.end_symbols()) { |
| 984 | lsi = Symbols.find(TargetName.data()); |
| 985 | Symbol->getType(SymType); |
| 986 | } |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 987 | if (lsi != Symbols.end()) { |
| 988 | Value.SectionID = lsi->second.first; |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 989 | Value.Offset = lsi->second.second; |
Ulrich Weigand | 78e9765 | 2013-04-05 13:29:04 +0000 | [diff] [blame] | 990 | Value.Addend = lsi->second.second + Addend; |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 991 | } else { |
Eli Bendersky | 667b879 | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 992 | // Search for the symbol in the global symbol table |
Rafael Espindola | 7595447 | 2013-06-05 02:55:01 +0000 | [diff] [blame] | 993 | SymbolTableMap::const_iterator gsi = GlobalSymbolTable.end(); |
| 994 | if (Symbol != Obj.end_symbols()) |
| 995 | gsi = GlobalSymbolTable.find(TargetName.data()); |
Eli Bendersky | fc07908 | 2012-05-01 06:58:59 +0000 | [diff] [blame] | 996 | if (gsi != GlobalSymbolTable.end()) { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 997 | Value.SectionID = gsi->second.first; |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 998 | Value.Offset = gsi->second.second; |
Ulrich Weigand | 78e9765 | 2013-04-05 13:29:04 +0000 | [diff] [blame] | 999 | Value.Addend = gsi->second.second + Addend; |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 1000 | } else { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 1001 | switch (SymType) { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1002 | case SymbolRef::ST_Debug: { |
| 1003 | // TODO: Now ELF SymbolRef::ST_Debug = STT_SECTION, it's not obviously |
| 1004 | // and can be changed by another developers. Maybe best way is add |
| 1005 | // a new symbol type ST_Section to SymbolRef and use it. |
| 1006 | section_iterator si(Obj.end_sections()); |
| 1007 | Symbol->getSection(si); |
| 1008 | if (si == Obj.end_sections()) |
| 1009 | llvm_unreachable("Symbol section not found, bad object file format!"); |
| 1010 | DEBUG(dbgs() << "\t\tThis is section symbol\n"); |
| 1011 | // Default to 'true' in case isText fails (though it never does). |
| 1012 | bool isCode = true; |
| 1013 | si->isText(isCode); |
| 1014 | Value.SectionID = findOrEmitSection(Obj, (*si), isCode, ObjSectionToID); |
| 1015 | Value.Addend = Addend; |
| 1016 | break; |
| 1017 | } |
| 1018 | case SymbolRef::ST_Data: |
| 1019 | case SymbolRef::ST_Unknown: { |
| 1020 | Value.SymbolName = TargetName.data(); |
| 1021 | Value.Addend = Addend; |
Richard Mitton | ad6d349 | 2013-08-16 18:54:26 +0000 | [diff] [blame] | 1022 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1023 | // Absolute relocations will have a zero symbol ID (STN_UNDEF), which |
| 1024 | // will manifest here as a NULL symbol name. |
| 1025 | // We can set this as a valid (but empty) symbol name, and rely |
| 1026 | // on addRelocationForSymbol to handle this. |
| 1027 | if (!Value.SymbolName) |
| 1028 | Value.SymbolName = ""; |
| 1029 | break; |
| 1030 | } |
| 1031 | default: |
| 1032 | llvm_unreachable("Unresolved symbol type!"); |
| 1033 | break; |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 1034 | } |
| 1035 | } |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 1036 | } |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1037 | uint64_t Offset; |
Juergen Ributzka | 046709f | 2014-03-21 07:26:41 +0000 | [diff] [blame] | 1038 | Check(RelI->getOffset(Offset)); |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1039 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1040 | DEBUG(dbgs() << "\t\tSectionID: " << SectionID << " Offset: " << Offset |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 1041 | << "\n"); |
James Molloy | bd2ffa0 | 2014-04-30 10:15:41 +0000 | [diff] [blame] | 1042 | if ((Arch == Triple::aarch64 || Arch == Triple::aarch64_be || |
| 1043 | Arch == Triple::arm64 || Arch == Triple::arm64_be) && |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1044 | (RelType == ELF::R_AARCH64_CALL26 || RelType == ELF::R_AARCH64_JUMP26)) { |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 1045 | // This is an AArch64 branch relocation, need to use a stub function. |
| 1046 | DEBUG(dbgs() << "\t\tThis is an AArch64 branch relocation."); |
| 1047 | SectionEntry &Section = Sections[SectionID]; |
| 1048 | |
| 1049 | // Look for an existing stub. |
| 1050 | StubMap::const_iterator i = Stubs.find(Value); |
| 1051 | if (i != Stubs.end()) { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1052 | resolveRelocation(Section, Offset, (uint64_t)Section.Address + i->second, |
| 1053 | RelType, 0); |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 1054 | DEBUG(dbgs() << " Stub function found\n"); |
| 1055 | } else { |
| 1056 | // Create a new stub function. |
| 1057 | DEBUG(dbgs() << " Create a new stub function\n"); |
| 1058 | Stubs[Value] = Section.StubOffset; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1059 | uint8_t *StubTargetAddr = |
| 1060 | createStubFunction(Section.Address + Section.StubOffset); |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 1061 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1062 | RelocationEntry REmovz_g3(SectionID, StubTargetAddr - Section.Address, |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 1063 | ELF::R_AARCH64_MOVW_UABS_G3, Value.Addend); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1064 | RelocationEntry REmovk_g2(SectionID, StubTargetAddr - Section.Address + 4, |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 1065 | ELF::R_AARCH64_MOVW_UABS_G2_NC, Value.Addend); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1066 | RelocationEntry REmovk_g1(SectionID, StubTargetAddr - Section.Address + 8, |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 1067 | ELF::R_AARCH64_MOVW_UABS_G1_NC, Value.Addend); |
| 1068 | RelocationEntry REmovk_g0(SectionID, |
| 1069 | StubTargetAddr - Section.Address + 12, |
| 1070 | ELF::R_AARCH64_MOVW_UABS_G0_NC, Value.Addend); |
| 1071 | |
| 1072 | if (Value.SymbolName) { |
| 1073 | addRelocationForSymbol(REmovz_g3, Value.SymbolName); |
| 1074 | addRelocationForSymbol(REmovk_g2, Value.SymbolName); |
| 1075 | addRelocationForSymbol(REmovk_g1, Value.SymbolName); |
| 1076 | addRelocationForSymbol(REmovk_g0, Value.SymbolName); |
| 1077 | } else { |
| 1078 | addRelocationForSection(REmovz_g3, Value.SectionID); |
| 1079 | addRelocationForSection(REmovk_g2, Value.SectionID); |
| 1080 | addRelocationForSection(REmovk_g1, Value.SectionID); |
| 1081 | addRelocationForSection(REmovk_g0, Value.SectionID); |
| 1082 | } |
| 1083 | resolveRelocation(Section, Offset, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1084 | (uint64_t)Section.Address + Section.StubOffset, RelType, |
| 1085 | 0); |
Tim Northover | 37cde97 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 1086 | Section.StubOffset += getMaxStubSize(); |
| 1087 | } |
| 1088 | } else if (Arch == Triple::arm && |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1089 | (RelType == ELF::R_ARM_PC24 || RelType == ELF::R_ARM_CALL || |
| 1090 | RelType == ELF::R_ARM_JUMP24)) { |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 1091 | // This is an ARM branch relocation, need to use a stub function. |
| 1092 | DEBUG(dbgs() << "\t\tThis is an ARM branch relocation."); |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1093 | SectionEntry &Section = Sections[SectionID]; |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 1094 | |
Eric Christopher | c33f622 | 2012-10-23 17:19:15 +0000 | [diff] [blame] | 1095 | // Look for an existing stub. |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 1096 | StubMap::const_iterator i = Stubs.find(Value); |
| 1097 | if (i != Stubs.end()) { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1098 | resolveRelocation(Section, Offset, (uint64_t)Section.Address + i->second, |
| 1099 | RelType, 0); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 1100 | DEBUG(dbgs() << " Stub function found\n"); |
| 1101 | } else { |
| 1102 | // Create a new stub function. |
| 1103 | DEBUG(dbgs() << " Create a new stub function\n"); |
| 1104 | Stubs[Value] = Section.StubOffset; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1105 | uint8_t *StubTargetAddr = |
| 1106 | createStubFunction(Section.Address + Section.StubOffset); |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1107 | RelocationEntry RE(SectionID, StubTargetAddr - Section.Address, |
Tim Northover | 3b684d8 | 2013-05-28 19:48:19 +0000 | [diff] [blame] | 1108 | ELF::R_ARM_PRIVATE_0, Value.Addend); |
Eli Bendersky | 667b879 | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 1109 | if (Value.SymbolName) |
| 1110 | addRelocationForSymbol(RE, Value.SymbolName); |
| 1111 | else |
| 1112 | addRelocationForSection(RE, Value.SectionID); |
| 1113 | |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1114 | resolveRelocation(Section, Offset, |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1115 | (uint64_t)Section.Address + Section.StubOffset, RelType, |
| 1116 | 0); |
Danil Malyshev | 70d22cc | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 1117 | Section.StubOffset += getMaxStubSize(); |
| 1118 | } |
Akira Hatanaka | a667aad | 2012-12-03 23:12:19 +0000 | [diff] [blame] | 1119 | } else if ((Arch == Triple::mipsel || Arch == Triple::mips) && |
| 1120 | RelType == ELF::R_MIPS_26) { |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 1121 | // This is an Mips branch relocation, need to use a stub function. |
| 1122 | DEBUG(dbgs() << "\t\tThis is a Mips branch relocation."); |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1123 | SectionEntry &Section = Sections[SectionID]; |
| 1124 | uint8_t *Target = Section.Address + Offset; |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 1125 | uint32_t *TargetAddress = (uint32_t *)Target; |
| 1126 | |
| 1127 | // Extract the addend from the instruction. |
| 1128 | uint32_t Addend = ((*TargetAddress) & 0x03ffffff) << 2; |
| 1129 | |
| 1130 | Value.Addend += Addend; |
| 1131 | |
| 1132 | // Look up for existing stub. |
| 1133 | StubMap::const_iterator i = Stubs.find(Value); |
| 1134 | if (i != Stubs.end()) { |
Petar Jovanovic | 45115f8 | 2013-11-19 21:56:00 +0000 | [diff] [blame] | 1135 | RelocationEntry RE(SectionID, Offset, RelType, i->second); |
| 1136 | addRelocationForSection(RE, SectionID); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 1137 | DEBUG(dbgs() << " Stub function found\n"); |
| 1138 | } else { |
| 1139 | // Create a new stub function. |
| 1140 | DEBUG(dbgs() << " Create a new stub function\n"); |
| 1141 | Stubs[Value] = Section.StubOffset; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1142 | uint8_t *StubTargetAddr = |
| 1143 | createStubFunction(Section.Address + Section.StubOffset); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 1144 | |
| 1145 | // Creating Hi and Lo relocations for the filled stub instructions. |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1146 | RelocationEntry REHi(SectionID, StubTargetAddr - Section.Address, |
Akira Hatanaka | 2e23624 | 2013-07-24 01:58:40 +0000 | [diff] [blame] | 1147 | ELF::R_MIPS_UNUSED1, Value.Addend); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1148 | RelocationEntry RELo(SectionID, StubTargetAddr - Section.Address + 4, |
Akira Hatanaka | 2e23624 | 2013-07-24 01:58:40 +0000 | [diff] [blame] | 1149 | ELF::R_MIPS_UNUSED2, Value.Addend); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 1150 | |
| 1151 | if (Value.SymbolName) { |
| 1152 | addRelocationForSymbol(REHi, Value.SymbolName); |
| 1153 | addRelocationForSymbol(RELo, Value.SymbolName); |
| 1154 | } else { |
| 1155 | addRelocationForSection(REHi, Value.SectionID); |
| 1156 | addRelocationForSection(RELo, Value.SectionID); |
| 1157 | } |
| 1158 | |
Petar Jovanovic | 45115f8 | 2013-11-19 21:56:00 +0000 | [diff] [blame] | 1159 | RelocationEntry RE(SectionID, Offset, RelType, Section.StubOffset); |
| 1160 | addRelocationForSection(RE, SectionID); |
Akira Hatanaka | 111174b | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 1161 | Section.StubOffset += getMaxStubSize(); |
| 1162 | } |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame] | 1163 | } else if (Arch == Triple::ppc64 || Arch == Triple::ppc64le) { |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1164 | if (RelType == ELF::R_PPC64_REL24) { |
| 1165 | // A PPC branch relocation will need a stub function if the target is |
| 1166 | // an external symbol (Symbol::ST_Unknown) or if the target address |
| 1167 | // is not within the signed 24-bits branch address. |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1168 | SectionEntry &Section = Sections[SectionID]; |
| 1169 | uint8_t *Target = Section.Address + Offset; |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1170 | bool RangeOverflow = false; |
| 1171 | if (SymType != SymbolRef::ST_Unknown) { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1172 | // A function call may points to the .opd entry, so the final symbol |
| 1173 | // value |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1174 | // in calculated based in the relocation values in .opd section. |
| 1175 | findOPDEntrySection(Obj, ObjSectionToID, Value); |
| 1176 | uint8_t *RelocTarget = Sections[Value.SectionID].Address + Value.Addend; |
| 1177 | int32_t delta = static_cast<int32_t>(Target - RelocTarget); |
| 1178 | // If it is within 24-bits branch range, just set the branch target |
| 1179 | if (SignExtend32<24>(delta) == delta) { |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1180 | RelocationEntry RE(SectionID, Offset, RelType, Value.Addend); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1181 | if (Value.SymbolName) |
| 1182 | addRelocationForSymbol(RE, Value.SymbolName); |
| 1183 | else |
| 1184 | addRelocationForSection(RE, Value.SectionID); |
| 1185 | } else { |
| 1186 | RangeOverflow = true; |
| 1187 | } |
| 1188 | } |
| 1189 | if (SymType == SymbolRef::ST_Unknown || RangeOverflow == true) { |
| 1190 | // It is an external symbol (SymbolRef::ST_Unknown) or within a range |
| 1191 | // larger than 24-bits. |
| 1192 | StubMap::const_iterator i = Stubs.find(Value); |
| 1193 | if (i != Stubs.end()) { |
| 1194 | // Symbol function stub already created, just relocate to it |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1195 | resolveRelocation(Section, Offset, |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 1196 | (uint64_t)Section.Address + i->second, RelType, 0); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1197 | DEBUG(dbgs() << " Stub function found\n"); |
| 1198 | } else { |
| 1199 | // Create a new stub function. |
| 1200 | DEBUG(dbgs() << " Create a new stub function\n"); |
| 1201 | Stubs[Value] = Section.StubOffset; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1202 | uint8_t *StubTargetAddr = |
| 1203 | createStubFunction(Section.Address + Section.StubOffset); |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1204 | RelocationEntry RE(SectionID, StubTargetAddr - Section.Address, |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1205 | ELF::R_PPC64_ADDR64, Value.Addend); |
| 1206 | |
| 1207 | // Generates the 64-bits address loads as exemplified in section |
| 1208 | // 4.5.1 in PPC64 ELF ABI. |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1209 | RelocationEntry REhst(SectionID, StubTargetAddr - Section.Address + 2, |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1210 | ELF::R_PPC64_ADDR16_HIGHEST, Value.Addend); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1211 | RelocationEntry REhr(SectionID, StubTargetAddr - Section.Address + 6, |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1212 | ELF::R_PPC64_ADDR16_HIGHER, Value.Addend); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1213 | RelocationEntry REh(SectionID, StubTargetAddr - Section.Address + 14, |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1214 | ELF::R_PPC64_ADDR16_HI, Value.Addend); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1215 | RelocationEntry REl(SectionID, StubTargetAddr - Section.Address + 18, |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1216 | ELF::R_PPC64_ADDR16_LO, Value.Addend); |
| 1217 | |
| 1218 | if (Value.SymbolName) { |
| 1219 | addRelocationForSymbol(REhst, Value.SymbolName); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1220 | addRelocationForSymbol(REhr, Value.SymbolName); |
| 1221 | addRelocationForSymbol(REh, Value.SymbolName); |
| 1222 | addRelocationForSymbol(REl, Value.SymbolName); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1223 | } else { |
| 1224 | addRelocationForSection(REhst, Value.SectionID); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1225 | addRelocationForSection(REhr, Value.SectionID); |
| 1226 | addRelocationForSection(REh, Value.SectionID); |
| 1227 | addRelocationForSection(REl, Value.SectionID); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1230 | resolveRelocation(Section, Offset, |
Andrew Kaylor | fb05a50 | 2012-11-02 19:45:23 +0000 | [diff] [blame] | 1231 | (uint64_t)Section.Address + Section.StubOffset, |
| 1232 | RelType, 0); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1233 | Section.StubOffset += getMaxStubSize(); |
| 1234 | } |
Ulrich Weigand | fa84ac9 | 2014-03-11 15:26:27 +0000 | [diff] [blame] | 1235 | if (SymType == SymbolRef::ST_Unknown) |
| 1236 | // Restore the TOC for external calls |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1237 | writeInt32BE(Target + 4, 0xE8410028); // ld r2,40(r1) |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1238 | } |
| 1239 | } else { |
Rafael Espindola | 4d4a48d | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 1240 | RelocationEntry RE(SectionID, Offset, RelType, Value.Addend); |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1241 | // Extra check to avoid relocation againt empty symbols (usually |
| 1242 | // the R_PPC64_TOC). |
Richard Mitton | ad6d349 | 2013-08-16 18:54:26 +0000 | [diff] [blame] | 1243 | if (SymType != SymbolRef::ST_Unknown && TargetName.empty()) |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1244 | Value.SymbolName = nullptr; |
Richard Mitton | ad6d349 | 2013-08-16 18:54:26 +0000 | [diff] [blame] | 1245 | |
| 1246 | if (Value.SymbolName) |
Adhemerval Zanella | 5fc11b3 | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 1247 | addRelocationForSymbol(RE, Value.SymbolName); |
| 1248 | else |
| 1249 | addRelocationForSection(RE, Value.SectionID); |
| 1250 | } |
Richard Sandiford | ca04408 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 1251 | } else if (Arch == Triple::systemz && |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1252 | (RelType == ELF::R_390_PLT32DBL || RelType == ELF::R_390_GOTENT)) { |
Richard Sandiford | ca04408 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 1253 | // Create function stubs for both PLT and GOT references, regardless of |
| 1254 | // whether the GOT reference is to data or code. The stub contains the |
| 1255 | // full address of the symbol, as needed by GOT references, and the |
| 1256 | // executable part only adds an overhead of 8 bytes. |
| 1257 | // |
| 1258 | // We could try to conserve space by allocating the code and data |
| 1259 | // parts of the stub separately. However, as things stand, we allocate |
| 1260 | // a stub for every relocation, so using a GOT in JIT code should be |
| 1261 | // no less space efficient than using an explicit constant pool. |
| 1262 | DEBUG(dbgs() << "\t\tThis is a SystemZ indirect relocation."); |
| 1263 | SectionEntry &Section = Sections[SectionID]; |
| 1264 | |
| 1265 | // Look for an existing stub. |
| 1266 | StubMap::const_iterator i = Stubs.find(Value); |
| 1267 | uintptr_t StubAddress; |
| 1268 | if (i != Stubs.end()) { |
| 1269 | StubAddress = uintptr_t(Section.Address) + i->second; |
| 1270 | DEBUG(dbgs() << " Stub function found\n"); |
| 1271 | } else { |
| 1272 | // Create a new stub function. |
| 1273 | DEBUG(dbgs() << " Create a new stub function\n"); |
| 1274 | |
| 1275 | uintptr_t BaseAddress = uintptr_t(Section.Address); |
| 1276 | uintptr_t StubAlignment = getStubAlignment(); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1277 | StubAddress = (BaseAddress + Section.StubOffset + StubAlignment - 1) & |
| 1278 | -StubAlignment; |
Richard Sandiford | ca04408 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 1279 | unsigned StubOffset = StubAddress - BaseAddress; |
| 1280 | |
| 1281 | Stubs[Value] = StubOffset; |
| 1282 | createStubFunction((uint8_t *)StubAddress); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1283 | RelocationEntry RE(SectionID, StubOffset + 8, ELF::R_390_64, |
| 1284 | Value.Addend - Addend); |
Richard Sandiford | ca04408 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 1285 | if (Value.SymbolName) |
| 1286 | addRelocationForSymbol(RE, Value.SymbolName); |
| 1287 | else |
| 1288 | addRelocationForSection(RE, Value.SectionID); |
| 1289 | Section.StubOffset = StubOffset + getMaxStubSize(); |
| 1290 | } |
| 1291 | |
| 1292 | if (RelType == ELF::R_390_GOTENT) |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1293 | resolveRelocation(Section, Offset, StubAddress + 8, ELF::R_390_PC32DBL, |
| 1294 | Addend); |
Richard Sandiford | ca04408 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 1295 | else |
| 1296 | resolveRelocation(Section, Offset, StubAddress, RelType, Addend); |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1297 | } else if (Arch == Triple::x86_64 && RelType == ELF::R_X86_64_PLT32) { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1298 | // The way the PLT relocations normally work is that the linker allocates |
| 1299 | // the |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1300 | // PLT and this relocation makes a PC-relative call into the PLT. The PLT |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1301 | // entry will then jump to an address provided by the GOT. On first call, |
| 1302 | // the |
| 1303 | // GOT address will point back into PLT code that resolves the symbol. After |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1304 | // the first call, the GOT entry points to the actual function. |
| 1305 | // |
| 1306 | // For local functions we're ignoring all of that here and just replacing |
| 1307 | // the PLT32 relocation type with PC32, which will translate the relocation |
| 1308 | // into a PC-relative call directly to the function. For external symbols we |
| 1309 | // can't be sure the function will be within 2^32 bytes of the call site, so |
| 1310 | // we need to create a stub, which calls into the GOT. This case is |
| 1311 | // equivalent to the usual PLT implementation except that we use the stub |
| 1312 | // mechanism in RuntimeDyld (which puts stubs at the end of the section) |
| 1313 | // rather than allocating a PLT section. |
| 1314 | if (Value.SymbolName) { |
| 1315 | // This is a call to an external function. |
| 1316 | // Look for an existing stub. |
| 1317 | SectionEntry &Section = Sections[SectionID]; |
| 1318 | StubMap::const_iterator i = Stubs.find(Value); |
| 1319 | uintptr_t StubAddress; |
| 1320 | if (i != Stubs.end()) { |
| 1321 | StubAddress = uintptr_t(Section.Address) + i->second; |
| 1322 | DEBUG(dbgs() << " Stub function found\n"); |
| 1323 | } else { |
| 1324 | // Create a new stub function (equivalent to a PLT entry). |
| 1325 | DEBUG(dbgs() << " Create a new stub function\n"); |
| 1326 | |
| 1327 | uintptr_t BaseAddress = uintptr_t(Section.Address); |
| 1328 | uintptr_t StubAlignment = getStubAlignment(); |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1329 | StubAddress = (BaseAddress + Section.StubOffset + StubAlignment - 1) & |
| 1330 | -StubAlignment; |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1331 | unsigned StubOffset = StubAddress - BaseAddress; |
| 1332 | Stubs[Value] = StubOffset; |
| 1333 | createStubFunction((uint8_t *)StubAddress); |
| 1334 | |
| 1335 | // Create a GOT entry for the external function. |
| 1336 | GOTEntries.push_back(Value); |
| 1337 | |
| 1338 | // Make our stub function a relative call to the GOT entry. |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1339 | RelocationEntry RE(SectionID, StubOffset + 2, ELF::R_X86_64_GOTPCREL, |
| 1340 | -4); |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1341 | addRelocationForSymbol(RE, Value.SymbolName); |
| 1342 | |
| 1343 | // Bump our stub offset counter |
| 1344 | Section.StubOffset = StubOffset + getMaxStubSize(); |
| 1345 | } |
| 1346 | |
| 1347 | // Make the target call a call into the stub table. |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1348 | resolveRelocation(Section, Offset, StubAddress, ELF::R_X86_64_PC32, |
| 1349 | Addend); |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1350 | } else { |
| 1351 | RelocationEntry RE(SectionID, Offset, ELF::R_X86_64_PC32, Value.Addend, |
| 1352 | Value.Offset); |
| 1353 | addRelocationForSection(RE, Value.SectionID); |
| 1354 | } |
Eli Bendersky | 667b879 | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 1355 | } else { |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1356 | if (Arch == Triple::x86_64 && RelType == ELF::R_X86_64_GOTPCREL) { |
| 1357 | GOTEntries.push_back(Value); |
| 1358 | } |
| 1359 | RelocationEntry RE(SectionID, Offset, RelType, Value.Addend, Value.Offset); |
Eli Bendersky | 667b879 | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 1360 | if (Value.SymbolName) |
| 1361 | addRelocationForSymbol(RE, Value.SymbolName); |
| 1362 | else |
| 1363 | addRelocationForSection(RE, Value.SectionID); |
| 1364 | } |
Juergen Ributzka | 046709f | 2014-03-21 07:26:41 +0000 | [diff] [blame] | 1365 | return ++RelI; |
Jim Grosbach | eff0a40 | 2012-01-16 22:26:39 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1368 | void RuntimeDyldELF::updateGOTEntries(StringRef Name, uint64_t Addr) { |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1369 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1370 | SmallVectorImpl<std::pair<SID, GOTRelocations>>::iterator it; |
| 1371 | SmallVectorImpl<std::pair<SID, GOTRelocations>>::iterator end = GOTs.end(); |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1372 | |
| 1373 | for (it = GOTs.begin(); it != end; ++it) { |
| 1374 | GOTRelocations &GOTEntries = it->second; |
| 1375 | for (int i = 0, e = GOTEntries.size(); i != e; ++i) { |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1376 | if (GOTEntries[i].SymbolName != nullptr && |
| 1377 | GOTEntries[i].SymbolName == Name) { |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1378 | GOTEntries[i].Offset = Addr; |
| 1379 | } |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | size_t RuntimeDyldELF::getGOTEntrySize() { |
| 1385 | // We don't use the GOT in all of these cases, but it's essentially free |
| 1386 | // to put them all here. |
| 1387 | size_t Result = 0; |
| 1388 | switch (Arch) { |
| 1389 | case Triple::x86_64: |
| 1390 | case Triple::aarch64: |
James Molloy | bd2ffa0 | 2014-04-30 10:15:41 +0000 | [diff] [blame] | 1391 | case Triple::aarch64_be: |
| 1392 | case Triple::arm64: |
| 1393 | case Triple::arm64_be: |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1394 | case Triple::ppc64: |
| 1395 | case Triple::ppc64le: |
| 1396 | case Triple::systemz: |
| 1397 | Result = sizeof(uint64_t); |
| 1398 | break; |
| 1399 | case Triple::x86: |
| 1400 | case Triple::arm: |
| 1401 | case Triple::thumb: |
| 1402 | case Triple::mips: |
| 1403 | case Triple::mipsel: |
| 1404 | Result = sizeof(uint32_t); |
| 1405 | break; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1406 | default: |
| 1407 | llvm_unreachable("Unsupported CPU type!"); |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1408 | } |
| 1409 | return Result; |
| 1410 | } |
| 1411 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1412 | uint64_t RuntimeDyldELF::findGOTEntry(uint64_t LoadAddress, uint64_t Offset) { |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1413 | |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1414 | const size_t GOTEntrySize = getGOTEntrySize(); |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1415 | |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1416 | SmallVectorImpl<std::pair<SID, GOTRelocations>>::const_iterator it; |
| 1417 | SmallVectorImpl<std::pair<SID, GOTRelocations>>::const_iterator end = |
| 1418 | GOTs.end(); |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1419 | |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1420 | int GOTIndex = -1; |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1421 | for (it = GOTs.begin(); it != end; ++it) { |
| 1422 | SID GOTSectionID = it->first; |
| 1423 | const GOTRelocations &GOTEntries = it->second; |
| 1424 | |
| 1425 | // Find the matching entry in our vector. |
| 1426 | uint64_t SymbolOffset = 0; |
| 1427 | for (int i = 0, e = GOTEntries.size(); i != e; ++i) { |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 1428 | if (!GOTEntries[i].SymbolName) { |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1429 | if (getSectionLoadAddress(GOTEntries[i].SectionID) == LoadAddress && |
| 1430 | GOTEntries[i].Offset == Offset) { |
| 1431 | GOTIndex = i; |
| 1432 | SymbolOffset = GOTEntries[i].Offset; |
| 1433 | break; |
| 1434 | } |
| 1435 | } else { |
| 1436 | // GOT entries for external symbols use the addend as the address when |
| 1437 | // the external symbol has been resolved. |
| 1438 | if (GOTEntries[i].Offset == LoadAddress) { |
| 1439 | GOTIndex = i; |
| 1440 | // Don't use the Addend here. The relocation handler will use it. |
| 1441 | break; |
| 1442 | } |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1443 | } |
| 1444 | } |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1445 | |
| 1446 | if (GOTIndex != -1) { |
| 1447 | if (GOTEntrySize == sizeof(uint64_t)) { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1448 | uint64_t *LocalGOTAddr = (uint64_t *)getSectionAddress(GOTSectionID); |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1449 | // Fill in this entry with the address of the symbol being referenced. |
| 1450 | LocalGOTAddr[GOTIndex] = LoadAddress + SymbolOffset; |
| 1451 | } else { |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1452 | uint32_t *LocalGOTAddr = (uint32_t *)getSectionAddress(GOTSectionID); |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1453 | // Fill in this entry with the address of the symbol being referenced. |
| 1454 | LocalGOTAddr[GOTIndex] = (uint32_t)(LoadAddress + SymbolOffset); |
| 1455 | } |
| 1456 | |
| 1457 | // Calculate the load address of this entry |
| 1458 | return getSectionLoadAddress(GOTSectionID) + (GOTIndex * GOTEntrySize); |
| 1459 | } |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1460 | } |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1461 | |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1462 | assert(GOTIndex != -1 && "Unable to find requested GOT entry."); |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1463 | return 0; |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
Lang Hames | 36072da | 2014-05-12 21:39:59 +0000 | [diff] [blame] | 1466 | void RuntimeDyldELF::finalizeLoad(ObjectImage &ObjImg, |
| 1467 | ObjSectionToIDMap &SectionMap) { |
Andrew Kaylor | 7bb1344 | 2013-10-11 21:25:48 +0000 | [diff] [blame] | 1468 | // If necessary, allocate the global offset table |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1469 | if (MemMgr) { |
| 1470 | // Allocate the GOT if necessary |
| 1471 | size_t numGOTEntries = GOTEntries.size(); |
| 1472 | if (numGOTEntries != 0) { |
| 1473 | // Allocate memory for the section |
| 1474 | unsigned SectionID = Sections.size(); |
| 1475 | size_t TotalSize = numGOTEntries * getGOTEntrySize(); |
| 1476 | uint8_t *Addr = MemMgr->allocateDataSection(TotalSize, getGOTEntrySize(), |
| 1477 | SectionID, ".got", false); |
| 1478 | if (!Addr) |
| 1479 | report_fatal_error("Unable to allocate memory for GOT!"); |
| 1480 | |
| 1481 | GOTs.push_back(std::make_pair(SectionID, GOTEntries)); |
| 1482 | Sections.push_back(SectionEntry(".got", Addr, TotalSize, 0)); |
| 1483 | // For now, initialize all GOT entries to zero. We'll fill them in as |
| 1484 | // needed when GOT-based relocations are applied. |
| 1485 | memset(Addr, 0, TotalSize); |
| 1486 | } |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1487 | } else { |
Andrew Kaylor | 480dcb3 | 2013-10-05 01:52:09 +0000 | [diff] [blame] | 1488 | report_fatal_error("Unable to allocate memory for GOT!"); |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1489 | } |
Andrew Kaylor | 7bb1344 | 2013-10-11 21:25:48 +0000 | [diff] [blame] | 1490 | |
| 1491 | // Look for and record the EH frame section. |
| 1492 | ObjSectionToIDMap::iterator i, e; |
| 1493 | for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) { |
| 1494 | const SectionRef &Section = i->first; |
| 1495 | StringRef Name; |
| 1496 | Section.getName(Name); |
| 1497 | if (Name == ".eh_frame") { |
| 1498 | UnregisteredEHFrameSections.push_back(i->second); |
| 1499 | break; |
| 1500 | } |
| 1501 | } |
Andrew Kaylor | 4612fed | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Andrew Kaylor | adc7056 | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 1504 | bool RuntimeDyldELF::isCompatibleFormat(const ObjectBuffer *Buffer) const { |
| 1505 | if (Buffer->getBufferSize() < strlen(ELF::ElfMagic)) |
| 1506 | return false; |
Juergen Ributzka | 7608dc0 | 2014-03-21 20:28:42 +0000 | [diff] [blame] | 1507 | return (memcmp(Buffer->getBufferStart(), ELF::ElfMagic, |
| 1508 | strlen(ELF::ElfMagic))) == 0; |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 1509 | } |
Lang Hames | 173c69f | 2014-01-08 04:09:09 +0000 | [diff] [blame] | 1510 | |
| 1511 | bool RuntimeDyldELF::isCompatibleFile(const object::ObjectFile *Obj) const { |
| 1512 | return Obj->isELF(); |
| 1513 | } |
| 1514 | |
Eli Bendersky | 4c64758 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 1515 | } // namespace llvm |