this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix relocation trouble, this for instance gets Apple's SplitViews example app running

+47 -7
+9 -6
src/dyld/MachOLoader.cpp
··· 299 299 } 300 300 } 301 301 302 - void MachOLoader::doRelocations(const std::vector<MachO::Relocation*>& rels, intptr base, intptr slide) 302 + void MachOLoader::doRelocations(const std::vector<MachO::Relocation*>& rels, intptr segmentBase, intptr slide) 303 303 { 304 - TRACE2(base, slide); 304 + TRACE2(segmentBase, slide); 305 305 m_lastResolvedSymbol.clear(); 306 306 m_lastResolvedAddress = 0; 307 307 308 308 #ifdef __i386__ 309 - base = 0; // TODO: WTF? But this helps. 309 + segmentBase = 0; // TODO: WTF? But this helps. 310 310 #endif 311 311 312 312 for (const MachO::Relocation* rel : rels) 313 313 { 314 - uintptr_t* ptr = (uintptr_t*) (uintptr_t(rel->addr) + base + slide); 314 + uintptr_t* ptr = (uintptr_t*) (uintptr_t(rel->addr) + segmentBase + slide); 315 315 uintptr_t symbol; 316 316 uintptr_t value = *ptr; 317 317 ··· 597 597 void MachOLoader::load(const MachO& mach, std::string sourcePath, Exports* exports, bool bindLater, bool bindLazy) 598 598 { 599 599 intptr slide = 0; 600 - intptr base = 0; 600 + intptr base = 0, segmentBase; 601 601 const FileMap::ImageMap* img; 602 602 size_t origRpathCount; 603 603 ··· 625 625 626 626 if (!bindLater) 627 627 doBind(mach.binds(), slide, !bindLazy); 628 - doRelocations(mach.relocations(), base, slide); 628 + 629 + segmentBase = mach.relocation_base(); 630 + 631 + doRelocations(mach.relocations(), segmentBase, slide); 629 632 doMProtect(); // decrease the segment protection value 630 633 631 634 if (!bindLater)
+1 -1
src/dyld/MachOLoader.h
··· 67 67 void* doBind(const std::vector<MachO::Bind*>& binds, intptr slide, bool resolveLazy = false); 68 68 69 69 // Binds external relocations 70 - void doRelocations(const std::vector<MachO::Relocation*>& rels, intptr base, intptr slide); 70 + void doRelocations(const std::vector<MachO::Relocation*>& rels, intptr segmentBase, intptr slide); 71 71 72 72 // Calls mprotect() to switch segment protections to the "initial" value. 73 73 // We initially set the maximum value.
+34
src/libmach-o/MachO.cpp
··· 79 79 } 80 80 return is_macho; 81 81 } 82 + 83 + uint64_t MachO::relocation_base() const 84 + { 85 + uint64_t addr; 86 + if (is64()) 87 + { 88 + for (segment_command_64* seg : m_segments64) 89 + { 90 + if (seg->initprot & VM_PROT_WRITE) 91 + { 92 + addr = seg->vmaddr; 93 + break; 94 + } 95 + } 96 + } 97 + else 98 + { 99 + if (m_header.flags & MH_SPLIT_SEGS) 100 + { 101 + for (segment_command* seg : m_segments) 102 + { 103 + if (seg->initprot & VM_PROT_WRITE) 104 + { 105 + addr = uint64_t(seg->vmaddr) & 0xffffffff; 106 + break; 107 + } 108 + } 109 + } 110 + else 111 + addr = uint64_t(m_segments[0]->vmaddr) & 0xffffffff; 112 + } 113 + return addr; 114 + } 115 +
+3
src/libmach-o/MachO.h
··· 131 131 const std::vector<TLVSection>& tlv_sections() const { return m_tlv_sections; } 132 132 133 133 uint64_t dyld_data() const { return m_dyld_data; } 134 + 135 + __attribute__ ((visibility ("default"))) 136 + uint64_t relocation_base() const; 134 137 135 138 bool is64() const { return m_is64; } 136 139