Jim Grosbach | e0934be | 2012-01-16 23:50:58 +0000 | [diff] [blame] | 1 | //===-- RuntimeDyld.cpp - Run-time dynamic linker for MC-JIT ----*- C++ -*-===// |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +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 the MC-JIT runtime dynamic linker. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Jim Grosbach | 8b54dca | 2011-03-23 19:52:00 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "dyld" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ExecutionEngine/RuntimeDyld.h" |
Andrew Kaylor | 3f23cef | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 16 | #include "ObjectImageCommon.h" |
Eli Bendersky | 76463fd | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 17 | #include "RuntimeDyldELF.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "RuntimeDyldImpl.h" |
Eli Bendersky | 76463fd | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 19 | #include "RuntimeDyldMachO.h" |
Rafael Espindola | 3ecfcc2 | 2013-06-11 18:01:14 +0000 | [diff] [blame] | 20 | #include "llvm/Support/FileSystem.h" |
Tim Northover | f00677d | 2012-10-29 10:47:04 +0000 | [diff] [blame] | 21 | #include "llvm/Support/MathExtras.h" |
Rafael Espindola | 7486d92 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 22 | #include "llvm/Object/ELF.h" |
Eli Bendersky | 76463fd | 2012-01-22 07:05:02 +0000 | [diff] [blame] | 23 | |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | using namespace llvm::object; |
| 26 | |
Chandler Carruth | 53c5e7b | 2011-04-05 23:54:31 +0000 | [diff] [blame] | 27 | // Empty out-of-line virtual destructor as the key function. |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 28 | RuntimeDyldImpl::~RuntimeDyldImpl() {} |
Chandler Carruth | 53c5e7b | 2011-04-05 23:54:31 +0000 | [diff] [blame] | 29 | |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +0000 | [diff] [blame] | 30 | namespace llvm { |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +0000 | [diff] [blame] | 31 | |
Rafael Espindola | a2e40fb | 2013-05-05 20:43:10 +0000 | [diff] [blame] | 32 | StringRef RuntimeDyldImpl::getEHFrameSection() { |
| 33 | return StringRef(); |
| 34 | } |
| 35 | |
Jim Grosbach | f8c1c84 | 2011-04-12 21:20:41 +0000 | [diff] [blame] | 36 | // Resolve the relocations for all symbols we currently know about. |
| 37 | void RuntimeDyldImpl::resolveRelocations() { |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 38 | // First, resolve relocations associated with external symbols. |
Eli Bendersky | 37bc5a2 | 2012-04-30 12:15:58 +0000 | [diff] [blame] | 39 | resolveExternalSymbols(); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 40 | |
Jim Grosbach | 61425c0 | 2012-01-16 22:26:39 +0000 | [diff] [blame] | 41 | // Just iterate over the sections we have and resolve all the relocations |
| 42 | // in them. Gross overkill, but it gets the job done. |
| 43 | for (int i = 0, e = Sections.size(); i != e; ++i) { |
Andrew Kaylor | 32bd10b | 2013-08-19 19:38:06 +0000 | [diff] [blame] | 44 | // The Section here (Sections[i]) refers to the section in which the |
| 45 | // symbol for the relocation is located. The SectionID in the relocation |
| 46 | // entry provides the section to which the relocation will be applied. |
Andrew Kaylor | 2898988 | 2012-11-05 20:57:16 +0000 | [diff] [blame] | 47 | uint64_t Addr = Sections[i].LoadAddress; |
| 48 | DEBUG(dbgs() << "Resolving relocations Section #" << i |
| 49 | << "\t" << format("%p", (uint8_t *)Addr) |
| 50 | << "\n"); |
| 51 | resolveRelocationList(Relocations[i], Addr); |
Andrew Kaylor | 8e9ec01 | 2013-10-01 01:47:35 +0000 | [diff] [blame^] | 52 | Relocations.erase(i); |
Jim Grosbach | 61425c0 | 2012-01-16 22:26:39 +0000 | [diff] [blame] | 53 | } |
Jim Grosbach | f8c1c84 | 2011-04-12 21:20:41 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Jim Grosbach | e940c1b | 2012-09-13 21:50:06 +0000 | [diff] [blame] | 56 | void RuntimeDyldImpl::mapSectionAddress(const void *LocalAddress, |
Jim Grosbach | 020f4e8 | 2012-01-16 23:50:55 +0000 | [diff] [blame] | 57 | uint64_t TargetAddress) { |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 58 | for (unsigned i = 0, e = Sections.size(); i != e; ++i) { |
| 59 | if (Sections[i].Address == LocalAddress) { |
| 60 | reassignSectionAddress(i, TargetAddress); |
| 61 | return; |
| 62 | } |
| 63 | } |
| 64 | llvm_unreachable("Attempting to remap address of unknown section!"); |
Jim Grosbach | 020f4e8 | 2012-01-16 23:50:55 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Eli Bendersky | 5fe0198 | 2012-04-29 12:40:47 +0000 | [diff] [blame] | 67 | // Subclasses can implement this method to create specialized image instances. |
Sylvestre Ledru | c8e41c5 | 2012-07-23 08:51:15 +0000 | [diff] [blame] | 68 | // The caller owns the pointer that is returned. |
Andrew Kaylor | 3f23cef | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 69 | ObjectImage *RuntimeDyldImpl::createObjectImage(ObjectBuffer *InputBuffer) { |
| 70 | return new ObjectImageCommon(InputBuffer); |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Andrew Kaylor | 3f23cef | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 73 | ObjectImage *RuntimeDyldImpl::loadObject(ObjectBuffer *InputBuffer) { |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 74 | OwningPtr<ObjectImage> obj(createObjectImage(InputBuffer)); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 75 | if (!obj) |
| 76 | report_fatal_error("Unable to create object image from memory buffer!"); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 77 | |
| 78 | Arch = (Triple::ArchType)obj->getArch(); |
| 79 | |
Eli Bendersky | d98c9e9 | 2012-05-01 06:58:59 +0000 | [diff] [blame] | 80 | // Symbols found in this object |
| 81 | StringMap<SymbolLoc> LocalSymbols; |
| 82 | // Used sections from the object file |
| 83 | ObjSectionToIDMap LocalSections; |
| 84 | |
Tim Northover | f00677d | 2012-10-29 10:47:04 +0000 | [diff] [blame] | 85 | // Common symbols requiring allocation, with their sizes and alignments |
Eli Bendersky | d98c9e9 | 2012-05-01 06:58:59 +0000 | [diff] [blame] | 86 | CommonSymbolMap CommonSymbols; |
Tim Northover | f00677d | 2012-10-29 10:47:04 +0000 | [diff] [blame] | 87 | // Maximum required total memory to allocate all common symbols |
Eli Bendersky | d98c9e9 | 2012-05-01 06:58:59 +0000 | [diff] [blame] | 88 | uint64_t CommonSize = 0; |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 89 | |
| 90 | error_code err; |
| 91 | // Parse symbols |
| 92 | DEBUG(dbgs() << "Parse symbols:\n"); |
| 93 | for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols(); |
| 94 | i != e; i.increment(err)) { |
| 95 | Check(err); |
| 96 | object::SymbolRef::Type SymType; |
| 97 | StringRef Name; |
| 98 | Check(i->getType(SymType)); |
| 99 | Check(i->getName(Name)); |
| 100 | |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 101 | uint32_t flags; |
| 102 | Check(i->getFlags(flags)); |
| 103 | |
| 104 | bool isCommon = flags & SymbolRef::SF_Common; |
| 105 | if (isCommon) { |
| 106 | // Add the common symbols to a list. We'll allocate them all below. |
Rafael Espindola | 59a0e79 | 2013-04-29 22:24:22 +0000 | [diff] [blame] | 107 | uint32_t Align; |
| 108 | Check(i->getAlignment(Align)); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 109 | uint64_t Size = 0; |
| 110 | Check(i->getSize(Size)); |
Tim Northover | f00677d | 2012-10-29 10:47:04 +0000 | [diff] [blame] | 111 | CommonSize += Size + Align; |
| 112 | CommonSymbols[*i] = CommonSymbolInfo(Size, Align); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 113 | } else { |
| 114 | if (SymType == object::SymbolRef::ST_Function || |
Akira Hatanaka | b889e0c | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 115 | SymType == object::SymbolRef::ST_Data || |
| 116 | SymType == object::SymbolRef::ST_Unknown) { |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 117 | uint64_t FileOffset; |
Eli Bendersky | 5fe0198 | 2012-04-29 12:40:47 +0000 | [diff] [blame] | 118 | StringRef SectionData; |
Tim Northover | 7882213 | 2012-12-17 17:59:35 +0000 | [diff] [blame] | 119 | bool IsCode; |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 120 | section_iterator si = obj->end_sections(); |
| 121 | Check(i->getFileOffset(FileOffset)); |
| 122 | Check(i->getSection(si)); |
| 123 | if (si == obj->end_sections()) continue; |
Eli Bendersky | 5fe0198 | 2012-04-29 12:40:47 +0000 | [diff] [blame] | 124 | Check(si->getContents(SectionData)); |
Tim Northover | 7882213 | 2012-12-17 17:59:35 +0000 | [diff] [blame] | 125 | Check(si->isText(IsCode)); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 126 | const uint8_t* SymPtr = (const uint8_t*)InputBuffer->getBufferStart() + |
| 127 | (uintptr_t)FileOffset; |
Eli Bendersky | 5fe0198 | 2012-04-29 12:40:47 +0000 | [diff] [blame] | 128 | uintptr_t SectOffset = (uintptr_t)(SymPtr - |
| 129 | (const uint8_t*)SectionData.begin()); |
Tim Northover | 7882213 | 2012-12-17 17:59:35 +0000 | [diff] [blame] | 130 | unsigned SectionID = findOrEmitSection(*obj, *si, IsCode, LocalSections); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 131 | LocalSymbols[Name.data()] = SymbolLoc(SectionID, SectOffset); |
| 132 | DEBUG(dbgs() << "\tFileOffset: " << format("%p", (uintptr_t)FileOffset) |
| 133 | << " flags: " << flags |
| 134 | << " SID: " << SectionID |
| 135 | << " Offset: " << format("%p", SectOffset)); |
Amara Emerson | 098d6d5 | 2012-11-16 11:11:59 +0000 | [diff] [blame] | 136 | GlobalSymbolTable[Name] = SymbolLoc(SectionID, SectOffset); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 137 | } |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 138 | } |
| 139 | DEBUG(dbgs() << "\tType: " << SymType << " Name: " << Name << "\n"); |
| 140 | } |
| 141 | |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 142 | // Allocate common symbols |
| 143 | if (CommonSize != 0) |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 144 | emitCommonSymbols(*obj, CommonSymbols, CommonSize, LocalSymbols); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 145 | |
Eli Bendersky | 5fe0198 | 2012-04-29 12:40:47 +0000 | [diff] [blame] | 146 | // Parse and process relocations |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 147 | DEBUG(dbgs() << "Parse relocations:\n"); |
| 148 | for (section_iterator si = obj->begin_sections(), |
| 149 | se = obj->end_sections(); si != se; si.increment(err)) { |
| 150 | Check(err); |
| 151 | bool isFirstRelocation = true; |
| 152 | unsigned SectionID = 0; |
| 153 | StubMap Stubs; |
Rafael Espindola | 7486d92 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 154 | section_iterator RelocatedSection = si->getRelocatedSection(); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 155 | |
| 156 | for (relocation_iterator i = si->begin_relocations(), |
| 157 | e = si->end_relocations(); i != e; i.increment(err)) { |
| 158 | Check(err); |
| 159 | |
Eli Bendersky | 5fe0198 | 2012-04-29 12:40:47 +0000 | [diff] [blame] | 160 | // If it's the first relocation in this section, find its SectionID |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 161 | if (isFirstRelocation) { |
Rafael Espindola | 7486d92 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 162 | SectionID = |
| 163 | findOrEmitSection(*obj, *RelocatedSection, true, LocalSections); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 164 | DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n"); |
| 165 | isFirstRelocation = false; |
| 166 | } |
| 167 | |
Rafael Espindola | ca0e736 | 2013-04-29 19:03:21 +0000 | [diff] [blame] | 168 | processRelocationRef(SectionID, *i, *obj, LocalSections, LocalSymbols, |
Rafael Espindola | efa91f6 | 2013-04-29 14:44:23 +0000 | [diff] [blame] | 169 | Stubs); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 172 | |
Andrew Kaylor | ff9fa05 | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 173 | // Give the subclasses a chance to tie-up any loose ends. |
| 174 | finalizeLoad(); |
| 175 | |
Andrew Kaylor | 3f23cef | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 176 | return obj.take(); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 179 | void RuntimeDyldImpl::emitCommonSymbols(ObjectImage &Obj, |
| 180 | const CommonSymbolMap &CommonSymbols, |
| 181 | uint64_t TotalSize, |
| 182 | SymbolTableMap &SymbolTable) { |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 183 | // Allocate memory for the section |
| 184 | unsigned SectionID = Sections.size(); |
| 185 | uint8_t *Addr = MemMgr->allocateDataSection(TotalSize, sizeof(void*), |
Andrew Kaylor | 53608a3 | 2012-11-15 23:50:01 +0000 | [diff] [blame] | 186 | SectionID, false); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 187 | if (!Addr) |
| 188 | report_fatal_error("Unable to allocate memory for common symbols!"); |
| 189 | uint64_t Offset = 0; |
Rafael Espindola | a2e40fb | 2013-05-05 20:43:10 +0000 | [diff] [blame] | 190 | Sections.push_back(SectionEntry(StringRef(), Addr, TotalSize, 0)); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 191 | memset(Addr, 0, TotalSize); |
| 192 | |
| 193 | DEBUG(dbgs() << "emitCommonSection SectionID: " << SectionID |
| 194 | << " new addr: " << format("%p", Addr) |
| 195 | << " DataSize: " << TotalSize |
| 196 | << "\n"); |
| 197 | |
| 198 | // Assign the address of each symbol |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 199 | for (CommonSymbolMap::const_iterator it = CommonSymbols.begin(), |
| 200 | itEnd = CommonSymbols.end(); it != itEnd; it++) { |
Tim Northover | f00677d | 2012-10-29 10:47:04 +0000 | [diff] [blame] | 201 | uint64_t Size = it->second.first; |
| 202 | uint64_t Align = it->second.second; |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 203 | StringRef Name; |
| 204 | it->first.getName(Name); |
Tim Northover | f00677d | 2012-10-29 10:47:04 +0000 | [diff] [blame] | 205 | if (Align) { |
| 206 | // This symbol has an alignment requirement. |
| 207 | uint64_t AlignOffset = OffsetToAlignment((uint64_t)Addr, Align); |
| 208 | Addr += AlignOffset; |
| 209 | Offset += AlignOffset; |
| 210 | DEBUG(dbgs() << "Allocating common symbol " << Name << " address " << |
Andrew Kaylor | 5fc8c7c | 2012-11-01 19:49:21 +0000 | [diff] [blame] | 211 | format("%p\n", Addr)); |
Tim Northover | f00677d | 2012-10-29 10:47:04 +0000 | [diff] [blame] | 212 | } |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 213 | Obj.updateSymbolAddress(it->first, (uint64_t)Addr); |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 214 | SymbolTable[Name.data()] = SymbolLoc(SectionID, Offset); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 215 | Offset += Size; |
| 216 | Addr += Size; |
| 217 | } |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 220 | unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj, |
| 221 | const SectionRef &Section, |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 222 | bool IsCode) { |
| 223 | |
| 224 | unsigned StubBufSize = 0, |
| 225 | StubSize = getMaxStubSize(); |
| 226 | error_code err; |
Rafael Espindola | 7486d92 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 227 | const ObjectFile *ObjFile = Obj.getObjectFile(); |
| 228 | // FIXME: this is an inefficient way to handle this. We should computed the |
| 229 | // necessary section allocation size in loadObject by walking all the sections |
| 230 | // once. |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 231 | if (StubSize > 0) { |
Rafael Espindola | 7486d92 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 232 | for (section_iterator SI = ObjFile->begin_sections(), |
| 233 | SE = ObjFile->end_sections(); |
| 234 | SI != SE; SI.increment(err), Check(err)) { |
| 235 | section_iterator RelSecI = SI->getRelocatedSection(); |
| 236 | if (!(RelSecI == Section)) |
| 237 | continue; |
| 238 | |
| 239 | for (relocation_iterator I = SI->begin_relocations(), |
| 240 | E = SI->end_relocations(); I != E; I.increment(err), Check(err)) { |
| 241 | StubBufSize += StubSize; |
| 242 | } |
| 243 | } |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 244 | } |
Rafael Espindola | 7486d92 | 2013-05-30 03:05:14 +0000 | [diff] [blame] | 245 | |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 246 | StringRef data; |
| 247 | uint64_t Alignment64; |
| 248 | Check(Section.getContents(data)); |
| 249 | Check(Section.getAlignment(Alignment64)); |
| 250 | |
| 251 | unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL; |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 252 | bool IsRequired; |
| 253 | bool IsVirtual; |
| 254 | bool IsZeroInit; |
Andrew Kaylor | 53608a3 | 2012-11-15 23:50:01 +0000 | [diff] [blame] | 255 | bool IsReadOnly; |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 256 | uint64_t DataSize; |
Adhemerval Zanella | 6e8946c | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 257 | StringRef Name; |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 258 | Check(Section.isRequiredForExecution(IsRequired)); |
| 259 | Check(Section.isVirtual(IsVirtual)); |
| 260 | Check(Section.isZeroInit(IsZeroInit)); |
Andrew Kaylor | 53608a3 | 2012-11-15 23:50:01 +0000 | [diff] [blame] | 261 | Check(Section.isReadOnlyData(IsReadOnly)); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 262 | Check(Section.getSize(DataSize)); |
Adhemerval Zanella | 6e8946c | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 263 | Check(Section.getName(Name)); |
Richard Sandiford | 6fc2ad6 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 264 | if (StubSize > 0) { |
| 265 | unsigned StubAlignment = getStubAlignment(); |
| 266 | unsigned EndAlignment = (DataSize | Alignment) & -(DataSize | Alignment); |
| 267 | if (StubAlignment > EndAlignment) |
| 268 | StubBufSize += StubAlignment - EndAlignment; |
| 269 | } |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 270 | |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 271 | unsigned Allocate; |
| 272 | unsigned SectionID = Sections.size(); |
| 273 | uint8_t *Addr; |
| 274 | const char *pData = 0; |
| 275 | |
| 276 | // Some sections, such as debug info, don't need to be loaded for execution. |
| 277 | // Leave those where they are. |
| 278 | if (IsRequired) { |
| 279 | Allocate = DataSize + StubBufSize; |
| 280 | Addr = IsCode |
| 281 | ? MemMgr->allocateCodeSection(Allocate, Alignment, SectionID) |
Andrew Kaylor | 53608a3 | 2012-11-15 23:50:01 +0000 | [diff] [blame] | 282 | : MemMgr->allocateDataSection(Allocate, Alignment, SectionID, IsReadOnly); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 283 | if (!Addr) |
| 284 | report_fatal_error("Unable to allocate section memory!"); |
| 285 | |
| 286 | // Virtual sections have no data in the object image, so leave pData = 0 |
| 287 | if (!IsVirtual) |
| 288 | pData = data.data(); |
| 289 | |
| 290 | // Zero-initialize or copy the data from the image |
| 291 | if (IsZeroInit || IsVirtual) |
| 292 | memset(Addr, 0, DataSize); |
| 293 | else |
| 294 | memcpy(Addr, pData, DataSize); |
| 295 | |
| 296 | DEBUG(dbgs() << "emitSection SectionID: " << SectionID |
Adhemerval Zanella | 6e8946c | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 297 | << " Name: " << Name |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 298 | << " obj addr: " << format("%p", pData) |
| 299 | << " new addr: " << format("%p", Addr) |
| 300 | << " DataSize: " << DataSize |
| 301 | << " StubBufSize: " << StubBufSize |
| 302 | << " Allocate: " << Allocate |
| 303 | << "\n"); |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 304 | Obj.updateSectionAddress(Section, (uint64_t)Addr); |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 305 | } |
| 306 | else { |
| 307 | // Even if we didn't load the section, we need to record an entry for it |
Eli Bendersky | 5fe0198 | 2012-04-29 12:40:47 +0000 | [diff] [blame] | 308 | // to handle later processing (and by 'handle' I mean don't do anything |
| 309 | // with these sections). |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 310 | Allocate = 0; |
| 311 | Addr = 0; |
| 312 | DEBUG(dbgs() << "emitSection SectionID: " << SectionID |
Adhemerval Zanella | 6e8946c | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 313 | << " Name: " << Name |
Preston Gurd | c68dda8 | 2012-04-12 20:13:57 +0000 | [diff] [blame] | 314 | << " obj addr: " << format("%p", data.data()) |
| 315 | << " new addr: 0" |
| 316 | << " DataSize: " << DataSize |
| 317 | << " StubBufSize: " << StubBufSize |
| 318 | << " Allocate: " << Allocate |
| 319 | << "\n"); |
| 320 | } |
| 321 | |
Rafael Espindola | a2e40fb | 2013-05-05 20:43:10 +0000 | [diff] [blame] | 322 | Sections.push_back(SectionEntry(Name, Addr, DataSize, (uintptr_t)pData)); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 323 | return SectionID; |
| 324 | } |
| 325 | |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 326 | unsigned RuntimeDyldImpl::findOrEmitSection(ObjectImage &Obj, |
| 327 | const SectionRef &Section, |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 328 | bool IsCode, |
| 329 | ObjSectionToIDMap &LocalSections) { |
| 330 | |
| 331 | unsigned SectionID = 0; |
| 332 | ObjSectionToIDMap::iterator i = LocalSections.find(Section); |
| 333 | if (i != LocalSections.end()) |
| 334 | SectionID = i->second; |
| 335 | else { |
Preston Gurd | 689ff9c | 2012-04-16 22:12:58 +0000 | [diff] [blame] | 336 | SectionID = emitSection(Obj, Section, IsCode); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 337 | LocalSections[Section] = SectionID; |
| 338 | } |
| 339 | return SectionID; |
| 340 | } |
| 341 | |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 342 | void RuntimeDyldImpl::addRelocationForSection(const RelocationEntry &RE, |
| 343 | unsigned SectionID) { |
| 344 | Relocations[SectionID].push_back(RE); |
| 345 | } |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 346 | |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 347 | void RuntimeDyldImpl::addRelocationForSymbol(const RelocationEntry &RE, |
| 348 | StringRef SymbolName) { |
| 349 | // Relocation by symbol. If the symbol is found in the global symbol table, |
| 350 | // create an appropriate section relocation. Otherwise, add it to |
| 351 | // ExternalSymbolRelocations. |
| 352 | SymbolTableMap::const_iterator Loc = |
| 353 | GlobalSymbolTable.find(SymbolName); |
| 354 | if (Loc == GlobalSymbolTable.end()) { |
| 355 | ExternalSymbolRelocations[SymbolName].push_back(RE); |
Eli Bendersky | 37bc5a2 | 2012-04-30 12:15:58 +0000 | [diff] [blame] | 356 | } else { |
Eli Bendersky | c201e6e | 2012-05-01 10:41:12 +0000 | [diff] [blame] | 357 | // Copy the RE since we want to modify its addend. |
| 358 | RelocationEntry RECopy = RE; |
| 359 | RECopy.Addend += Loc->second.second; |
| 360 | Relocations[Loc->second.first].push_back(RECopy); |
Eli Bendersky | 37bc5a2 | 2012-04-30 12:15:58 +0000 | [diff] [blame] | 361 | } |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | uint8_t *RuntimeDyldImpl::createStubFunction(uint8_t *Addr) { |
Tim Northover | 4a9b6b7 | 2013-05-04 20:14:09 +0000 | [diff] [blame] | 365 | if (Arch == Triple::aarch64) { |
| 366 | // This stub has to be able to access the full address space, |
| 367 | // since symbol lookup won't necessarily find a handy, in-range, |
| 368 | // PLT stub for functions which could be anywhere. |
| 369 | uint32_t *StubAddr = (uint32_t*)Addr; |
| 370 | |
| 371 | // Stub can use ip0 (== x16) to calculate address |
| 372 | *StubAddr = 0xd2e00010; // movz ip0, #:abs_g3:<addr> |
| 373 | StubAddr++; |
| 374 | *StubAddr = 0xf2c00010; // movk ip0, #:abs_g2_nc:<addr> |
| 375 | StubAddr++; |
| 376 | *StubAddr = 0xf2a00010; // movk ip0, #:abs_g1_nc:<addr> |
| 377 | StubAddr++; |
| 378 | *StubAddr = 0xf2800010; // movk ip0, #:abs_g0_nc:<addr> |
| 379 | StubAddr++; |
| 380 | *StubAddr = 0xd61f0200; // br ip0 |
| 381 | |
| 382 | return Addr; |
| 383 | } else if (Arch == Triple::arm) { |
Akira Hatanaka | b889e0c | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 384 | // TODO: There is only ARM far stub now. We should add the Thumb stub, |
| 385 | // and stubs for branches Thumb - ARM and ARM - Thumb. |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 386 | uint32_t *StubAddr = (uint32_t*)Addr; |
| 387 | *StubAddr = 0xe51ff004; // ldr pc,<label> |
| 388 | return (uint8_t*)++StubAddr; |
NAKAMURA Takumi | 4af1ca5 | 2012-12-04 00:08:14 +0000 | [diff] [blame] | 389 | } else if (Arch == Triple::mipsel || Arch == Triple::mips) { |
Akira Hatanaka | b889e0c | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 390 | uint32_t *StubAddr = (uint32_t*)Addr; |
| 391 | // 0: 3c190000 lui t9,%hi(addr). |
| 392 | // 4: 27390000 addiu t9,t9,%lo(addr). |
| 393 | // 8: 03200008 jr t9. |
| 394 | // c: 00000000 nop. |
| 395 | const unsigned LuiT9Instr = 0x3c190000, AdduiT9Instr = 0x27390000; |
| 396 | const unsigned JrT9Instr = 0x03200008, NopInstr = 0x0; |
| 397 | |
| 398 | *StubAddr = LuiT9Instr; |
| 399 | StubAddr++; |
| 400 | *StubAddr = AdduiT9Instr; |
| 401 | StubAddr++; |
| 402 | *StubAddr = JrT9Instr; |
| 403 | StubAddr++; |
| 404 | *StubAddr = NopInstr; |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 405 | return Addr; |
Bill Schmidt | f38cc38 | 2013-07-26 01:35:43 +0000 | [diff] [blame] | 406 | } else if (Arch == Triple::ppc64 || Arch == Triple::ppc64le) { |
Adhemerval Zanella | 6e8946c | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 407 | // PowerPC64 stub: the address points to a function descriptor |
| 408 | // instead of the function itself. Load the function address |
| 409 | // on r11 and sets it to control register. Also loads the function |
| 410 | // TOC in r2 and environment pointer to r11. |
| 411 | writeInt32BE(Addr, 0x3D800000); // lis r12, highest(addr) |
| 412 | writeInt32BE(Addr+4, 0x618C0000); // ori r12, higher(addr) |
| 413 | writeInt32BE(Addr+8, 0x798C07C6); // sldi r12, r12, 32 |
| 414 | writeInt32BE(Addr+12, 0x658C0000); // oris r12, r12, h(addr) |
| 415 | writeInt32BE(Addr+16, 0x618C0000); // ori r12, r12, l(addr) |
| 416 | writeInt32BE(Addr+20, 0xF8410028); // std r2, 40(r1) |
| 417 | writeInt32BE(Addr+24, 0xE96C0000); // ld r11, 0(r12) |
| 418 | writeInt32BE(Addr+28, 0xE84C0008); // ld r2, 0(r12) |
| 419 | writeInt32BE(Addr+32, 0x7D6903A6); // mtctr r11 |
| 420 | writeInt32BE(Addr+36, 0xE96C0010); // ld r11, 16(r2) |
| 421 | writeInt32BE(Addr+40, 0x4E800420); // bctr |
Andrew Kaylor | 5fc8c7c | 2012-11-01 19:49:21 +0000 | [diff] [blame] | 422 | |
Adhemerval Zanella | 6e8946c | 2012-10-25 13:13:48 +0000 | [diff] [blame] | 423 | return Addr; |
Richard Sandiford | 6fc2ad6 | 2013-05-03 14:15:35 +0000 | [diff] [blame] | 424 | } else if (Arch == Triple::systemz) { |
| 425 | writeInt16BE(Addr, 0xC418); // lgrl %r1,.+8 |
| 426 | writeInt16BE(Addr+2, 0x0000); |
| 427 | writeInt16BE(Addr+4, 0x0004); |
| 428 | writeInt16BE(Addr+6, 0x07F1); // brc 15,%r1 |
| 429 | // 8-byte address stored at Addr + 8 |
| 430 | return Addr; |
Andrew Kaylor | ff9fa05 | 2013-08-19 23:27:43 +0000 | [diff] [blame] | 431 | } else if (Arch == Triple::x86_64) { |
| 432 | *Addr = 0xFF; // jmp |
| 433 | *(Addr+1) = 0x25; // rip |
| 434 | // 32-bit PC-relative address of the GOT entry will be stored at Addr+2 |
Akira Hatanaka | b889e0c | 2012-08-17 21:28:04 +0000 | [diff] [blame] | 435 | } |
| 436 | return Addr; |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | // Assign an address to a symbol name and resolve all the relocations |
| 440 | // associated with it. |
| 441 | void RuntimeDyldImpl::reassignSectionAddress(unsigned SectionID, |
| 442 | uint64_t Addr) { |
| 443 | // The address to use for relocation resolution is not |
| 444 | // the address of the local section buffer. We must be doing |
Andrew Kaylor | 2898988 | 2012-11-05 20:57:16 +0000 | [diff] [blame] | 445 | // a remote execution environment of some sort. Relocations can't |
| 446 | // be applied until all the sections have been moved. The client must |
| 447 | // trigger this with a call to MCJIT::finalize() or |
| 448 | // RuntimeDyld::resolveRelocations(). |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 449 | // |
| 450 | // Addr is a uint64_t because we can't assume the pointer width |
| 451 | // of the target is the same as that of the host. Just use a generic |
| 452 | // "big enough" type. |
| 453 | Sections[SectionID].LoadAddress = Addr; |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 456 | void RuntimeDyldImpl::resolveRelocationList(const RelocationList &Relocs, |
| 457 | uint64_t Value) { |
| 458 | for (unsigned i = 0, e = Relocs.size(); i != e; ++i) { |
Rafael Espindola | 87b5017 | 2013-04-29 17:24:34 +0000 | [diff] [blame] | 459 | const RelocationEntry &RE = Relocs[i]; |
| 460 | // Ignore relocations for sections that were not loaded |
| 461 | if (Sections[RE.SectionID].Address == 0) |
| 462 | continue; |
| 463 | resolveRelocation(RE, Value); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
Eli Bendersky | 37bc5a2 | 2012-04-30 12:15:58 +0000 | [diff] [blame] | 467 | void RuntimeDyldImpl::resolveExternalSymbols() { |
Andrew Kaylor | 8e9ec01 | 2013-10-01 01:47:35 +0000 | [diff] [blame^] | 468 | while(!ExternalSymbolRelocations.empty()) { |
| 469 | StringMap<RelocationList>::iterator i = ExternalSymbolRelocations.begin(); |
| 470 | |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 471 | StringRef Name = i->first(); |
| 472 | RelocationList &Relocs = i->second; |
Andrew Kaylor | 8e9ec01 | 2013-10-01 01:47:35 +0000 | [diff] [blame^] | 473 | if (Name.size() == 0) { |
| 474 | // This is an absolute symbol, use an address of zero. |
| 475 | DEBUG(dbgs() << "Resolving absolute relocations." << "\n"); |
| 476 | resolveRelocationList(Relocs, 0); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 477 | } else { |
Andrew Kaylor | 8e9ec01 | 2013-10-01 01:47:35 +0000 | [diff] [blame^] | 478 | uint64_t Addr = 0; |
| 479 | SymbolTableMap::const_iterator Loc = GlobalSymbolTable.find(Name); |
| 480 | if (Loc == GlobalSymbolTable.end()) { |
| 481 | // This is an external symbol, try to get its address from |
| 482 | // MemoryManager. |
| 483 | Addr = MemMgr->getSymbolAddress(Name.data()); |
| 484 | } else { |
| 485 | // We found the symbol in our global table. It was probably in a |
| 486 | // Module that we loaded previously. |
| 487 | SymbolLoc SymLoc = GlobalSymbolTable.lookup(Name); |
| 488 | Addr = getSectionLoadAddress(SymLoc.first) + SymLoc.second; |
| 489 | } |
| 490 | |
| 491 | // FIXME: Implement error handling that doesn't kill the host program! |
| 492 | if (!Addr) |
| 493 | report_fatal_error("Program used external function '" + Name + |
| 494 | "' which could not be resolved!"); |
| 495 | |
| 496 | updateGOTEntries(Name, Addr); |
| 497 | DEBUG(dbgs() << "Resolving relocations Name: " << Name |
| 498 | << "\t" << format("0x%lx", Addr) |
| 499 | << "\n"); |
| 500 | resolveRelocationList(Relocs, Addr); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 501 | } |
Andrew Kaylor | 8e9ec01 | 2013-10-01 01:47:35 +0000 | [diff] [blame^] | 502 | |
| 503 | ExternalSymbolRelocations.erase(i->first()); |
Danil Malyshev | 0e4fa5f | 2012-03-30 16:45:19 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
| 507 | |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +0000 | [diff] [blame] | 508 | //===----------------------------------------------------------------------===// |
| 509 | // RuntimeDyld class implementation |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 510 | RuntimeDyld::RuntimeDyld(RTDyldMemoryManager *mm) { |
Andrew Kaylor | 53608a3 | 2012-11-15 23:50:01 +0000 | [diff] [blame] | 511 | // FIXME: There's a potential issue lurking here if a single instance of |
| 512 | // RuntimeDyld is used to load multiple objects. The current implementation |
| 513 | // associates a single memory manager with a RuntimeDyld instance. Even |
| 514 | // though the public class spawns a new 'impl' instance for each load, |
| 515 | // they share a single memory manager. This can become a problem when page |
| 516 | // permissions are applied. |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 517 | Dyld = 0; |
| 518 | MM = mm; |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | RuntimeDyld::~RuntimeDyld() { |
| 522 | delete Dyld; |
| 523 | } |
| 524 | |
Andrew Kaylor | 3f23cef | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 525 | ObjectImage *RuntimeDyld::loadObject(ObjectBuffer *InputBuffer) { |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 526 | if (!Dyld) { |
Rafael Espindola | 3ecfcc2 | 2013-06-11 18:01:14 +0000 | [diff] [blame] | 527 | sys::fs::file_magic Type = |
| 528 | sys::fs::identify_magic(InputBuffer->getBuffer()); |
| 529 | switch (Type) { |
| 530 | case sys::fs::file_magic::elf_relocatable: |
| 531 | case sys::fs::file_magic::elf_executable: |
| 532 | case sys::fs::file_magic::elf_shared_object: |
| 533 | case sys::fs::file_magic::elf_core: |
| 534 | Dyld = new RuntimeDyldELF(MM); |
| 535 | break; |
| 536 | case sys::fs::file_magic::macho_object: |
| 537 | case sys::fs::file_magic::macho_executable: |
| 538 | case sys::fs::file_magic::macho_fixed_virtual_memory_shared_lib: |
| 539 | case sys::fs::file_magic::macho_core: |
| 540 | case sys::fs::file_magic::macho_preload_executable: |
| 541 | case sys::fs::file_magic::macho_dynamically_linked_shared_lib: |
| 542 | case sys::fs::file_magic::macho_dynamic_linker: |
| 543 | case sys::fs::file_magic::macho_bundle: |
| 544 | case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub: |
| 545 | case sys::fs::file_magic::macho_dsym_companion: |
| 546 | Dyld = new RuntimeDyldMachO(MM); |
| 547 | break; |
| 548 | case sys::fs::file_magic::unknown: |
| 549 | case sys::fs::file_magic::bitcode: |
| 550 | case sys::fs::file_magic::archive: |
| 551 | case sys::fs::file_magic::coff_object: |
| 552 | case sys::fs::file_magic::pecoff_executable: |
Alexey Samsonov | 9c22f87 | 2013-06-18 15:03:28 +0000 | [diff] [blame] | 553 | case sys::fs::file_magic::macho_universal_binary: |
Rafael Espindola | 3ecfcc2 | 2013-06-11 18:01:14 +0000 | [diff] [blame] | 554 | report_fatal_error("Incompatible object format!"); |
Eli Bendersky | a66a185 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 555 | } |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 556 | } else { |
Eli Bendersky | a66a185 | 2012-01-16 08:56:09 +0000 | [diff] [blame] | 557 | if (!Dyld->isCompatibleFormat(InputBuffer)) |
Danil Malyshev | cf852dc | 2011-07-13 07:57:58 +0000 | [diff] [blame] | 558 | report_fatal_error("Incompatible object format!"); |
| 559 | } |
| 560 | |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +0000 | [diff] [blame] | 561 | return Dyld->loadObject(InputBuffer); |
| 562 | } |
| 563 | |
Jim Grosbach | b027105 | 2011-04-08 17:31:24 +0000 | [diff] [blame] | 564 | void *RuntimeDyld::getSymbolAddress(StringRef Name) { |
Andrew Kaylor | 8e9ec01 | 2013-10-01 01:47:35 +0000 | [diff] [blame^] | 565 | if (!Dyld) |
| 566 | return NULL; |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +0000 | [diff] [blame] | 567 | return Dyld->getSymbolAddress(Name); |
| 568 | } |
| 569 | |
Jim Grosbach | 35ed842 | 2012-09-05 16:50:40 +0000 | [diff] [blame] | 570 | uint64_t RuntimeDyld::getSymbolLoadAddress(StringRef Name) { |
Andrew Kaylor | 8e9ec01 | 2013-10-01 01:47:35 +0000 | [diff] [blame^] | 571 | if (!Dyld) |
| 572 | return 0; |
Jim Grosbach | 35ed842 | 2012-09-05 16:50:40 +0000 | [diff] [blame] | 573 | return Dyld->getSymbolLoadAddress(Name); |
| 574 | } |
| 575 | |
Jim Grosbach | f8c1c84 | 2011-04-12 21:20:41 +0000 | [diff] [blame] | 576 | void RuntimeDyld::resolveRelocations() { |
| 577 | Dyld->resolveRelocations(); |
| 578 | } |
| 579 | |
Jim Grosbach | 61425c0 | 2012-01-16 22:26:39 +0000 | [diff] [blame] | 580 | void RuntimeDyld::reassignSectionAddress(unsigned SectionID, |
| 581 | uint64_t Addr) { |
| 582 | Dyld->reassignSectionAddress(SectionID, Addr); |
Jim Grosbach | f8c1c84 | 2011-04-12 21:20:41 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Jim Grosbach | e940c1b | 2012-09-13 21:50:06 +0000 | [diff] [blame] | 585 | void RuntimeDyld::mapSectionAddress(const void *LocalAddress, |
Jim Grosbach | 020f4e8 | 2012-01-16 23:50:55 +0000 | [diff] [blame] | 586 | uint64_t TargetAddress) { |
| 587 | Dyld->mapSectionAddress(LocalAddress, TargetAddress); |
| 588 | } |
| 589 | |
Jim Grosbach | 91dde15 | 2011-03-22 18:22:27 +0000 | [diff] [blame] | 590 | StringRef RuntimeDyld::getErrorString() { |
Jim Grosbach | b3eecaf | 2011-03-22 18:19:42 +0000 | [diff] [blame] | 591 | return Dyld->getErrorString(); |
| 592 | } |
| 593 | |
Rafael Espindola | a2e40fb | 2013-05-05 20:43:10 +0000 | [diff] [blame] | 594 | StringRef RuntimeDyld::getEHFrameSection() { |
| 595 | return Dyld->getEHFrameSection(); |
| 596 | } |
| 597 | |
Jim Grosbach | 6e56331 | 2011-03-21 22:15:52 +0000 | [diff] [blame] | 598 | } // end namespace llvm |