/
ImageLoaderMachOCompressed.cpp
2155 lines (1969 loc) · 89.9 KB
/
ImageLoaderMachOCompressed.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
*
* Copyright (c) 2008 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#if __arm__ || __arm64__
#include <System/sys/mman.h>
#else
#include <sys/mman.h>
#endif
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <mach/mach.h>
#include <mach/thread_status.h>
#include <mach-o/loader.h>
#include <mach-o/dyld_images.h>
#include "dyld2.h"
#include "ImageLoaderMachOCompressed.h"
#include "Closure.h"
#include "Array.h"
#ifndef BIND_SUBOPCODE_THREADED_SET_JOP
#define BIND_SUBOPCODE_THREADED_SET_JOP 0x0F
#endif
// relocation_info.r_length field has value 3 for 64-bit executables and value 2 for 32-bit executables
#if __LP64__
#define RELOC_SIZE 3
#define LC_SEGMENT_COMMAND LC_SEGMENT_64
#define LC_ROUTINES_COMMAND LC_ROUTINES_64
struct macho_segment_command : public segment_command_64 {};
struct macho_section : public section_64 {};
struct macho_routines_command : public routines_command_64 {};
#else
#define RELOC_SIZE 2
#define LC_SEGMENT_COMMAND LC_SEGMENT
#define LC_ROUTINES_COMMAND LC_ROUTINES
struct macho_segment_command : public segment_command {};
struct macho_section : public section {};
struct macho_routines_command : public routines_command {};
#endif
// create image for main executable
ImageLoaderMachOCompressed* ImageLoaderMachOCompressed::instantiateMainExecutable(const macho_header* mh, uintptr_t slide, const char* path,
unsigned int segCount, unsigned int libCount, const LinkContext& context)
{
ImageLoaderMachOCompressed* image = ImageLoaderMachOCompressed::instantiateStart(mh, path, segCount, libCount);
// set slide for PIE programs
image->setSlide(slide);
// for PIE record end of program, to know where to start loading dylibs
if ( slide != 0 )
fgNextPIEDylibAddress = (uintptr_t)image->getEnd();
image->disableCoverageCheck();
image->instantiateFinish(context);
image->setMapped(context);
if ( context.verboseMapping ) {
dyld::log("dyld: Main executable mapped %s\n", path);
for(unsigned int i=0, e=image->segmentCount(); i < e; ++i) {
const char* name = image->segName(i);
if ( (strcmp(name, "__PAGEZERO") == 0) || (strcmp(name, "__UNIXSTACK") == 0) )
dyld::log("%18s at 0x%08lX->0x%08lX\n", name, image->segPreferredLoadAddress(i), image->segPreferredLoadAddress(i)+image->segSize(i));
else
dyld::log("%18s at 0x%08lX->0x%08lX\n", name, image->segActualLoadAddress(i), image->segActualEndAddress(i));
}
}
return image;
}
// create image by mapping in a mach-o file
ImageLoaderMachOCompressed* ImageLoaderMachOCompressed::instantiateFromFile(const char* path, int fd, const uint8_t* fileData, size_t lenFileData,
uint64_t offsetInFat, uint64_t lenInFat, const struct stat& info,
unsigned int segCount, unsigned int libCount,
const struct linkedit_data_command* codeSigCmd,
const struct encryption_info_command* encryptCmd,
const LinkContext& context)
{
ImageLoaderMachOCompressed* image = ImageLoaderMachOCompressed::instantiateStart((macho_header*)fileData, path, segCount, libCount);
try {
// record info about file
image->setFileInfo(info.st_dev, info.st_ino, info.st_mtime);
// if this image is code signed, let kernel validate signature before mapping any pages from image
image->loadCodeSignature(codeSigCmd, fd, offsetInFat, context);
// Validate that first data we read with pread actually matches with code signature
image->validateFirstPages(codeSigCmd, fd, fileData, lenFileData, offsetInFat, context);
// mmap segments
image->mapSegments(fd, offsetInFat, lenInFat, info.st_size, context);
// if framework is FairPlay encrypted, register with kernel
image->registerEncryption(encryptCmd, context);
// probe to see if code signed correctly
image->crashIfInvalidCodeSignature();
// finish construction
image->instantiateFinish(context);
// if path happens to be same as in LC_DYLIB_ID load command use that, otherwise malloc a copy of the path
const char* installName = image->getInstallPath();
if ( (installName != NULL) && (strcmp(installName, path) == 0) && (path[0] == '/') )
image->setPathUnowned(installName);
#if TARGET_OS_OSX
// <rdar://problem/6563887> app crashes when libSystem cannot be found
else if ( (installName != NULL) && (strcmp(path, "/usr/lib/libgcc_s.1.dylib") == 0) && (strcmp(installName, "/usr/lib/libSystem.B.dylib") == 0) )
image->setPathUnowned("/usr/lib/libSystem.B.dylib");
#endif
else if ( (path[0] != '/') || (strstr(path, "../") != NULL) ) {
// rdar://problem/10733082 Fix up @rpath based paths during introspection
// rdar://problem/5135363 turn relative paths into absolute paths so gdb, Symbolication can later find them
char realPath[MAXPATHLEN];
if ( fcntl(fd, F_GETPATH, realPath) == 0 )
image->setPaths(path, realPath);
else
image->setPath(path);
}
else {
// <rdar://problem/46682306> always try to realpath dylibs since they may have been dlopen()ed using a symlink path
if ( installName != NULL ) {
char realPath[MAXPATHLEN];
if ( (fcntl(fd, F_GETPATH, realPath) == 0) && (strcmp(path, realPath) != 0) )
image->setPaths(path, realPath);
else
image->setPath(path);
}
else {
image->setPath(path);
}
}
// make sure path is stable before recording in dyld_all_image_infos
image->setMapped(context);
}
catch (...) {
// ImageLoader::setMapped() can throw an exception to block loading of image
// <rdar://problem/6169686> Leaked fSegmentsArray and image segments during failed dlopen_preflight
delete image;
throw;
}
return image;
}
// create image by using cached mach-o file
ImageLoaderMachOCompressed* ImageLoaderMachOCompressed::instantiateFromCache(const macho_header* mh, const char* path, long slide,
const struct stat& info, unsigned int segCount,
unsigned int libCount, const LinkContext& context)
{
ImageLoaderMachOCompressed* image = ImageLoaderMachOCompressed::instantiateStart(mh, path, segCount, libCount);
try {
// record info about file
image->setFileInfo(info.st_dev, info.st_ino, info.st_mtime);
// remember this is from shared cache and cannot be unloaded
image->fInSharedCache = true;
image->setNeverUnload();
image->setSlide(slide);
image->disableCoverageCheck();
// segments already mapped in cache
if ( context.verboseMapping ) {
dyld::log("dyld: Using shared cached for %s\n", path);
for(unsigned int i=0; i < image->fSegmentsCount; ++i) {
dyld::log("%18s at 0x%08lX->0x%08lX\n", image->segName(i), image->segActualLoadAddress(i), image->segActualEndAddress(i));
}
}
image->instantiateFinish(context);
#if TARGET_OS_SIMULATOR
char realPath[MAXPATHLEN] = { 0 };
if ( dyld::gLinkContext.rootPaths == NULL )
throw "root path is not set";
strlcpy(realPath, dyld::gLinkContext.rootPaths[0], MAXPATHLEN);
strlcat(realPath, path, MAXPATHLEN);
image->setPaths(path, realPath);
#endif
image->setMapped(context);
}
catch (...) {
// ImageLoader::setMapped() can throw an exception to block loading of image
// <rdar://problem/6169686> Leaked fSegmentsArray and image segments during failed dlopen_preflight
delete image;
throw;
}
return image;
}
// create image by copying an in-memory mach-o file
ImageLoaderMachOCompressed* ImageLoaderMachOCompressed::instantiateFromMemory(const char* moduleName, const macho_header* mh, uint64_t len,
unsigned int segCount, unsigned int libCount, const LinkContext& context)
{
ImageLoaderMachOCompressed* image = ImageLoaderMachOCompressed::instantiateStart(mh, moduleName, segCount, libCount);
try {
// map segments
if ( mh->filetype == MH_EXECUTE )
throw "can't load another MH_EXECUTE";
// vmcopy segments
image->mapSegments((const void*)mh, len, context);
// for compatibility, never unload dylibs loaded from memory
image->setNeverUnload();
image->disableCoverageCheck();
// bundle loads need path copied
if ( moduleName != NULL )
image->setPath(moduleName);
image->instantiateFinish(context);
image->setMapped(context);
}
catch (...) {
// ImageLoader::setMapped() can throw an exception to block loading of image
// <rdar://problem/6169686> Leaked fSegmentsArray and image segments during failed dlopen_preflight
delete image;
throw;
}
return image;
}
ImageLoaderMachOCompressed::ImageLoaderMachOCompressed(const macho_header* mh, const char* path, unsigned int segCount,
uint32_t segOffsets[], unsigned int libCount)
: ImageLoaderMachO(mh, path, segCount, segOffsets, libCount), fDyldInfo(NULL), fChainedFixups(NULL), fExportsTrie(NULL)
{
}
ImageLoaderMachOCompressed::~ImageLoaderMachOCompressed()
{
// don't do clean up in ~ImageLoaderMachO() because virtual call to segmentCommandOffsets() won't work
destroy();
}
// construct ImageLoaderMachOCompressed using "placement new" with SegmentMachO objects array at end
ImageLoaderMachOCompressed* ImageLoaderMachOCompressed::instantiateStart(const macho_header* mh, const char* path,
unsigned int segCount, unsigned int libCount)
{
size_t size = sizeof(ImageLoaderMachOCompressed) + segCount * sizeof(uint32_t) + libCount * sizeof(ImageLoader*);
ImageLoaderMachOCompressed* allocatedSpace = static_cast<ImageLoaderMachOCompressed*>(malloc(size));
if ( allocatedSpace == NULL )
throw "malloc failed";
uint32_t* segOffsets = ((uint32_t*)(((uint8_t*)allocatedSpace) + sizeof(ImageLoaderMachOCompressed)));
bzero(&segOffsets[segCount], libCount*sizeof(void*)); // zero out lib array
return new (allocatedSpace) ImageLoaderMachOCompressed(mh, path, segCount, segOffsets, libCount);
}
// common code to finish initializing object
void ImageLoaderMachOCompressed::instantiateFinish(const LinkContext& context)
{
// now that segments are mapped in, get real fMachOData, fLinkEditBase, and fSlide
this->parseLoadCmds(context);
}
uint32_t* ImageLoaderMachOCompressed::segmentCommandOffsets() const
{
return ((uint32_t*)(((uint8_t*)this) + sizeof(ImageLoaderMachOCompressed)));
}
ImageLoader* ImageLoaderMachOCompressed::libImage(unsigned int libIndex) const
{
const uintptr_t* images = ((uintptr_t*)(((uint8_t*)this) + sizeof(ImageLoaderMachOCompressed) + fSegmentsCount*sizeof(uint32_t)));
// mask off low bits
return (ImageLoader*)(images[libIndex] & (-4));
}
bool ImageLoaderMachOCompressed::libReExported(unsigned int libIndex) const
{
const uintptr_t* images = ((uintptr_t*)(((uint8_t*)this) + sizeof(ImageLoaderMachOCompressed) + fSegmentsCount*sizeof(uint32_t)));
// re-export flag is low bit
return ((images[libIndex] & 1) != 0);
}
bool ImageLoaderMachOCompressed::libIsUpward(unsigned int libIndex) const
{
const uintptr_t* images = ((uintptr_t*)(((uint8_t*)this) + sizeof(ImageLoaderMachOCompressed) + fSegmentsCount*sizeof(uint32_t)));
// upward flag is second bit
return ((images[libIndex] & 2) != 0);
}
void ImageLoaderMachOCompressed::setLibImage(unsigned int libIndex, ImageLoader* image, bool reExported, bool upward)
{
uintptr_t* images = ((uintptr_t*)(((uint8_t*)this) + sizeof(ImageLoaderMachOCompressed) + fSegmentsCount*sizeof(uint32_t)));
uintptr_t value = (uintptr_t)image;
if ( reExported )
value |= 1;
if ( upward )
value |= 2;
images[libIndex] = value;
}
void ImageLoaderMachOCompressed::rebaseAt(const LinkContext& context, uintptr_t addr, uintptr_t slide, uint8_t type)
{
if ( context.verboseRebase ) {
dyld::log("dyld: rebase: %s:*0x%08lX += 0x%08lX\n", this->getShortName(), (uintptr_t)addr, slide);
}
//dyld::log("0x%08lX type=%d\n", addr, type);
uintptr_t* locationToFix = (uintptr_t*)addr;
switch (type) {
case REBASE_TYPE_POINTER:
*locationToFix += slide;
break;
case REBASE_TYPE_TEXT_ABSOLUTE32:
*locationToFix += slide;
break;
default:
dyld::throwf("bad rebase type %d", type);
}
}
void ImageLoaderMachOCompressed::throwBadRebaseAddress(uintptr_t address, uintptr_t segmentEndAddress, int segmentIndex,
const uint8_t* startOpcodes, const uint8_t* endOpcodes, const uint8_t* pos)
{
dyld::throwf("malformed rebase opcodes (%ld/%ld): address 0x%08lX is outside of segment %s (0x%08lX -> 0x%08lX)",
(intptr_t)(pos-startOpcodes), (intptr_t)(endOpcodes-startOpcodes), address, segName(segmentIndex),
segActualLoadAddress(segmentIndex), segmentEndAddress);
}
void ImageLoaderMachOCompressed::rebase(const LinkContext& context, uintptr_t slide)
{
// binary uses chained fixups where are applied during binding
if ( fDyldInfo == NULL )
return;
CRSetCrashLogMessage2(this->getPath());
const uint8_t* const start = fLinkEditBase + fDyldInfo->rebase_off;
const uint8_t* const end = &start[fDyldInfo->rebase_size];
const uint8_t* p = start;
if ( start == end )
return;
uint32_t ignore;
bool bindingBecauseOfRoot = this->overridesCachedDylib(ignore);
vmAccountingSetSuspended(context, bindingBecauseOfRoot);
try {
uint8_t type = 0;
int segmentIndex = 0;
uintptr_t address = segActualLoadAddress(0);
uintptr_t segmentStartAddress = segActualLoadAddress(0);
uintptr_t segmentEndAddress = segActualEndAddress(0);
uintptr_t count;
uintptr_t skip;
bool done = false;
while ( !done && (p < end) ) {
uint8_t immediate = *p & REBASE_IMMEDIATE_MASK;
uint8_t opcode = *p & REBASE_OPCODE_MASK;
++p;
switch (opcode) {
case REBASE_OPCODE_DONE:
done = true;
break;
case REBASE_OPCODE_SET_TYPE_IMM:
type = immediate;
break;
case REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
segmentIndex = immediate;
if ( segmentIndex >= fSegmentsCount )
dyld::throwf("REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment %d which is too large (0..%d)",
segmentIndex, fSegmentsCount-1);
#if TEXT_RELOC_SUPPORT
if ( !segWriteable(segmentIndex) && !segHasRebaseFixUps(segmentIndex) && !segHasBindFixUps(segmentIndex) )
#else
if ( !segWriteable(segmentIndex) )
#endif
dyld::throwf("REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment %d which is not a writable segment (%s)",
segmentIndex, segName(segmentIndex));
segmentStartAddress = segActualLoadAddress(segmentIndex);
segmentEndAddress = segActualEndAddress(segmentIndex);
address = segmentStartAddress + read_uleb128(p, end);
break;
case REBASE_OPCODE_ADD_ADDR_ULEB:
address += read_uleb128(p, end);
break;
case REBASE_OPCODE_ADD_ADDR_IMM_SCALED:
address += immediate*sizeof(uintptr_t);
break;
case REBASE_OPCODE_DO_REBASE_IMM_TIMES:
for (int i=0; i < immediate; ++i) {
if ( (address < segmentStartAddress) || (address >= segmentEndAddress) )
throwBadRebaseAddress(address, segmentEndAddress, segmentIndex, start, end, p);
rebaseAt(context, address, slide, type);
address += sizeof(uintptr_t);
}
fgTotalRebaseFixups += immediate;
break;
case REBASE_OPCODE_DO_REBASE_ULEB_TIMES:
count = read_uleb128(p, end);
for (uint32_t i=0; i < count; ++i) {
if ( (address < segmentStartAddress) || (address >= segmentEndAddress) )
throwBadRebaseAddress(address, segmentEndAddress, segmentIndex, start, end, p);
rebaseAt(context, address, slide, type);
address += sizeof(uintptr_t);
}
fgTotalRebaseFixups += count;
break;
case REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB:
if ( (address < segmentStartAddress) || (address >= segmentEndAddress) )
throwBadRebaseAddress(address, segmentEndAddress, segmentIndex, start, end, p);
rebaseAt(context, address, slide, type);
address += read_uleb128(p, end) + sizeof(uintptr_t);
++fgTotalRebaseFixups;
break;
case REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB:
count = read_uleb128(p, end);
skip = read_uleb128(p, end);
for (uint32_t i=0; i < count; ++i) {
if ( (address < segmentStartAddress) || (address >= segmentEndAddress) )
throwBadRebaseAddress(address, segmentEndAddress, segmentIndex, start, end, p);
rebaseAt(context, address, slide, type);
address += skip + sizeof(uintptr_t);
}
fgTotalRebaseFixups += count;
break;
default:
dyld::throwf("bad rebase opcode %d", *(p-1));
}
}
}
catch (const char* msg) {
const char* newMsg = dyld::mkstringf("%s in %s", msg, this->getPath());
free((void*)msg);
throw newMsg;
}
CRSetCrashLogMessage2(NULL);
}
const ImageLoader::Symbol* ImageLoaderMachOCompressed::findShallowExportedSymbol(const char* symbol, const ImageLoader** foundIn) const
{
//dyld::log("Compressed::findExportedSymbol(%s) in %s\n", symbol, this->getShortName());
uint32_t trieFileOffset = fDyldInfo ? fDyldInfo->export_off : fExportsTrie->dataoff;
uint32_t trieFileSize = fDyldInfo ? fDyldInfo->export_size : fExportsTrie->datasize;
if ( trieFileSize == 0 )
return NULL;
#if LOG_BINDINGS
dyld::logBindings("%s: %s\n", this->getShortName(), symbol);
#endif
++ImageLoaderMachO::fgSymbolTrieSearchs;
const uint8_t* start = &fLinkEditBase[trieFileOffset];
const uint8_t* end = &start[trieFileSize];
const uint8_t* foundNodeStart = this->trieWalk(start, end, symbol);
if ( foundNodeStart != NULL ) {
const uint8_t* p = foundNodeStart;
const uintptr_t flags = read_uleb128(p, end);
// found match, return pointer to terminal part of node
if ( flags & EXPORT_SYMBOL_FLAGS_REEXPORT ) {
// re-export from another dylib, lookup there
const uintptr_t ordinal = read_uleb128(p, end);
const char* importedName = (char*)p;
if ( importedName[0] == '\0' )
importedName = symbol;
if ( (ordinal > 0) && (ordinal <= libraryCount()) ) {
const ImageLoader* reexportedFrom = libImage((unsigned int)ordinal-1);
// Missing weak-dylib
if ( reexportedFrom == NULL )
return NULL;
//dyld::log("Compressed::findExportedSymbol(), %s -> %s/%s\n", symbol, reexportedFrom->getShortName(), importedName);
const char* reExportLibPath = libPath((unsigned int)ordinal-1);
return reexportedFrom->findExportedSymbol(importedName, true, reExportLibPath, foundIn);
}
else {
//dyld::throwf("bad mach-o binary, library ordinal (%u) invalid (max %u) for re-exported symbol %s in %s",
// ordinal, libraryCount(), symbol, this->getPath());
}
}
else {
//dyld::log("findExportedSymbol(%s) in %s found match, returning %p\n", symbol, this->getShortName(), p);
if ( foundIn != NULL )
*foundIn = (ImageLoader*)this;
// return pointer to terminal part of node
return (Symbol*)foundNodeStart;
}
}
return NULL;
}
bool ImageLoaderMachOCompressed::containsSymbol(const void* addr) const
{
uint32_t trieFileOffset = fDyldInfo ? fDyldInfo->export_off : fExportsTrie->dataoff;
uint32_t trieFileSize = fDyldInfo ? fDyldInfo->export_size : fExportsTrie->datasize;
const uint8_t* start = &fLinkEditBase[trieFileOffset];
const uint8_t* end = &start[trieFileSize];
return ( (start <= addr) && (addr < end) );
}
uintptr_t ImageLoaderMachOCompressed::exportedSymbolAddress(const LinkContext& context, const Symbol* symbol, const ImageLoader* requestor, bool runResolver) const
{
uint32_t trieFileOffset = fDyldInfo ? fDyldInfo->export_off : fExportsTrie->dataoff;
uint32_t trieFileSize = fDyldInfo ? fDyldInfo->export_size : fExportsTrie->datasize;
const uint8_t* exportNode = (uint8_t*)symbol;
const uint8_t* exportTrieStart = fLinkEditBase + trieFileOffset;
const uint8_t* exportTrieEnd = exportTrieStart + trieFileSize;
if ( (exportNode < exportTrieStart) || (exportNode > exportTrieEnd) )
throw "symbol is not in trie";
//dyld::log("exportedSymbolAddress(): node=%p, nodeOffset=0x%04X in %s\n", symbol, (int)((uint8_t*)symbol - exportTrieStart), this->getShortName());
uintptr_t flags = read_uleb128(exportNode, exportTrieEnd);
switch ( flags & EXPORT_SYMBOL_FLAGS_KIND_MASK ) {
case EXPORT_SYMBOL_FLAGS_KIND_REGULAR:
if ( runResolver && (flags & EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) ) {
// this node has a stub and resolver, run the resolver to get target address
uintptr_t stub = read_uleb128(exportNode, exportTrieEnd) + (uintptr_t)fMachOData; // skip over stub
// <rdar://problem/10657737> interposing dylibs have the stub address as their replacee
uintptr_t interposedStub = interposedAddress(context, stub, requestor);
if ( interposedStub != stub )
return interposedStub;
// stub was not interposed, so run resolver
typedef uintptr_t (*ResolverProc)(void);
ResolverProc resolver = (ResolverProc)(read_uleb128(exportNode, exportTrieEnd) + (uintptr_t)fMachOData);
#if __has_feature(ptrauth_calls)
resolver = (ResolverProc)__builtin_ptrauth_sign_unauthenticated(resolver, ptrauth_key_asia, 0);
#endif
uintptr_t result = (*resolver)();
if ( context.verboseBind )
dyld::log("dyld: resolver at %p returned 0x%08lX\n", resolver, result);
#if __has_feature(ptrauth_calls)
result = (uintptr_t)__builtin_ptrauth_strip((void*)result, ptrauth_key_asia);
#endif
return result;
}
return read_uleb128(exportNode, exportTrieEnd) + (uintptr_t)fMachOData;
case EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL:
if ( flags & EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER )
dyld::throwf("unsupported exported symbol kind. flags=%lu at node=%p", flags, symbol);
return read_uleb128(exportNode, exportTrieEnd) + (uintptr_t)fMachOData;
case EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE:
if ( flags & EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER )
dyld::throwf("unsupported exported symbol kind. flags=%lu at node=%p", flags, symbol);
return read_uleb128(exportNode, exportTrieEnd);
default:
dyld::throwf("unsupported exported symbol kind. flags=%lu at node=%p", flags, symbol);
}
}
bool ImageLoaderMachOCompressed::exportedSymbolIsWeakDefintion(const Symbol* symbol) const
{
uint32_t trieFileOffset = fDyldInfo ? fDyldInfo->export_off : fExportsTrie->dataoff;
uint32_t trieFileSize = fDyldInfo ? fDyldInfo->export_size : fExportsTrie->datasize;
const uint8_t* exportNode = (uint8_t*)symbol;
const uint8_t* exportTrieStart = fLinkEditBase + trieFileOffset;
const uint8_t* exportTrieEnd = exportTrieStart + trieFileSize;
if ( (exportNode < exportTrieStart) || (exportNode > exportTrieEnd) )
throw "symbol is not in trie";
uintptr_t flags = read_uleb128(exportNode, exportTrieEnd);
return ( flags & EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION );
}
const char* ImageLoaderMachOCompressed::exportedSymbolName(const Symbol* symbol) const
{
throw "NSNameOfSymbol() not supported with compressed LINKEDIT";
}
unsigned int ImageLoaderMachOCompressed::exportedSymbolCount() const
{
throw "NSSymbolDefinitionCountInObjectFileImage() not supported with compressed LINKEDIT";
}
const ImageLoader::Symbol* ImageLoaderMachOCompressed::exportedSymbolIndexed(unsigned int index) const
{
throw "NSSymbolDefinitionNameInObjectFileImage() not supported with compressed LINKEDIT";
}
unsigned int ImageLoaderMachOCompressed::importedSymbolCount() const
{
throw "NSSymbolReferenceCountInObjectFileImage() not supported with compressed LINKEDIT";
}
const ImageLoader::Symbol* ImageLoaderMachOCompressed::importedSymbolIndexed(unsigned int index) const
{
throw "NSSymbolReferenceCountInObjectFileImage() not supported with compressed LINKEDIT";
}
const char* ImageLoaderMachOCompressed::importedSymbolName(const Symbol* symbol) const
{
throw "NSSymbolReferenceNameInObjectFileImage() not supported with compressed LINKEDIT";
}
uintptr_t ImageLoaderMachOCompressed::resolveFlat(const LinkContext& context, const char* symbolName, bool weak_import,
bool runResolver, const ImageLoader** foundIn)
{
const Symbol* sym;
if ( context.flatExportFinder(symbolName, &sym, foundIn) ) {
if ( *foundIn != this )
context.addDynamicReference(this, const_cast<ImageLoader*>(*foundIn));
return (*foundIn)->getExportedSymbolAddress(sym, context, this, runResolver);
}
// if a bundle is loaded privately the above will not find its exports
if ( this->isBundle() && this->hasHiddenExports() ) {
// look in self for needed symbol
sym = this->findShallowExportedSymbol(symbolName, foundIn);
if ( sym != NULL )
return (*foundIn)->getExportedSymbolAddress(sym, context, this, runResolver);
}
if ( weak_import ) {
// definition can't be found anywhere, ok because it is weak, just return 0
return 0;
}
throwSymbolNotFound(context, symbolName, this->getPath(), "", "flat namespace");
}
static void patchCacheUsesOf(const ImageLoader::LinkContext& context, const dyld3::closure::Image* overriddenImage,
uint32_t cacheOffsetOfImpl, const char* symbolName, uintptr_t newImpl,
DyldSharedCache::DataConstLazyScopedWriter& patcher)
{
patcher.makeWriteable();
uintptr_t cacheStart = (uintptr_t)context.dyldCache;
uint32_t imageIndex = overriddenImage->imageNum() - (uint32_t)context.dyldCache->cachedDylibsImageArray()->startImageNum();
context.dyldCache->forEachPatchableUseOfExport(imageIndex, cacheOffsetOfImpl, ^(dyld_cache_patchable_location patchLocation) {
uintptr_t* loc = (uintptr_t*)(cacheStart+patchLocation.cacheOffset);
#if __has_feature(ptrauth_calls)
if ( patchLocation.authenticated ) {
dyld3::MachOLoaded::ChainedFixupPointerOnDisk fixupInfo;
fixupInfo.arm64e.authRebase.auth = true;
fixupInfo.arm64e.authRebase.addrDiv = patchLocation.usesAddressDiversity;
fixupInfo.arm64e.authRebase.diversity = patchLocation.discriminator;
fixupInfo.arm64e.authRebase.key = patchLocation.key;
uintptr_t newValue = fixupInfo.arm64e.signPointer(loc, newImpl + DyldSharedCache::getAddend(patchLocation));
if ( *loc != newValue ) {
*loc = newValue;
if ( context.verboseBind )
dyld::log("dyld: cache fixup: *%p = %p (JOP: diversity 0x%04X, addr-div=%d, key=%s) to %s\n",
loc, (void*)newValue, patchLocation.discriminator, patchLocation.usesAddressDiversity, DyldSharedCache::keyName(patchLocation), symbolName);
}
return;
}
#endif
uintptr_t newValue = newImpl + (uintptr_t)DyldSharedCache::getAddend(patchLocation);
if ( *loc != newValue ) {
*loc = newValue;
if ( context.verboseBind )
dyld::log("dyld: cache fixup: *%p = %p to %s\n", loc, (void*)newValue, symbolName);
}
});
}
uintptr_t ImageLoaderMachOCompressed::resolveWeak(const LinkContext& context, const char* symbolName, bool weak_import,
bool runResolver, const ImageLoader** foundIn,
DyldSharedCache::DataConstLazyScopedWriter& patcher)
{
const Symbol* sym;
CoalesceNotifier notifier = nullptr;
__block uintptr_t foundOutsideCache = 0;
__block const char* foundOutsideCachePath = nullptr;
__block uintptr_t lastFoundInCache = 0;
if ( this->usesChainedFixups() ) {
notifier = ^(const Symbol* implSym, const ImageLoader* implIn, const mach_header* implMh) {
// This block is only called in dyld2 mode when a non-cached image is search for which weak-def implementation to use
// As a side effect of that search we notice any implementations outside and inside the cache,
// and use that to trigger patching the cache to use the implementation outside the cache.
uintptr_t implAddr = implIn->getExportedSymbolAddress(implSym, context, nullptr, false, symbolName);
if ( ((dyld3::MachOLoaded*)implMh)->inDyldCache() ) {
if ( foundOutsideCache != 0 ) {
// have an implementation in cache and and earlier one not in the cache, patch cache to use earlier one
lastFoundInCache = implAddr;
uint32_t imageIndex;
if ( context.dyldCache->findMachHeaderImageIndex(implMh, imageIndex) ) {
const dyld3::closure::Image* overriddenImage = context.dyldCache->cachedDylibsImageArray()->imageForNum(imageIndex+1);
uint32_t cacheOffsetOfImpl = (uint32_t)((uintptr_t)implAddr - (uintptr_t)context.dyldCache);
if ( context.verboseWeakBind )
dyld::log("dyld: weak bind, patching dyld cache uses of %s to use 0x%lX in %s\n", symbolName, foundOutsideCache, foundOutsideCachePath);
patchCacheUsesOf(context, overriddenImage, cacheOffsetOfImpl, symbolName, foundOutsideCache, patcher);
}
}
}
else {
// record first non-cache implementation
if ( foundOutsideCache == 0 ) {
foundOutsideCache = implAddr;
foundOutsideCachePath = implIn->getPath();
}
}
};
}
if ( context.coalescedExportFinder(symbolName, &sym, foundIn, notifier) ) {
if ( *foundIn != this )
context.addDynamicReference(this, const_cast<ImageLoader*>(*foundIn));
return (*foundIn)->getExportedSymbolAddress(sym, context, this, runResolver);
}
// if a bundle is loaded privately the above will not find its exports
if ( this->isBundle() && this->hasHiddenExports() ) {
// look in self for needed symbol
sym = this->findShallowExportedSymbol(symbolName, foundIn);
if ( sym != NULL )
return (*foundIn)->getExportedSymbolAddress(sym, context, this, runResolver);
}
if ( weak_import ) {
// definition can't be found anywhere, ok because it is weak, just return 0
return 0;
}
throwSymbolNotFound(context, symbolName, this->getPath(), "", "weak");
}
uintptr_t ImageLoaderMachOCompressed::resolveTwolevel(const LinkContext& context, const char* symbolName, const ImageLoader* definedInImage,
const ImageLoader* requestorImage, unsigned requestorOrdinalOfDef, bool weak_import, bool runResolver,
const ImageLoader** foundIn)
{
// two level lookup
uintptr_t address;
if ( definedInImage->findExportedSymbolAddress(context, symbolName, requestorImage, requestorOrdinalOfDef, runResolver, foundIn, &address) )
return address;
if ( weak_import ) {
// definition can't be found anywhere, ok because it is weak, just return 0
return 0;
}
// nowhere to be found, check if maybe this image is too new for this OS
char versMismatch[256];
versMismatch[0] = '\0';
uint32_t imageMinOS = this->minOSVersion();
// dyld is always built for the current OS, so we can get the current OS version
// from the load command in dyld itself.
extern const mach_header __dso_handle;
uint32_t dyldMinOS = ImageLoaderMachO::minOSVersion(&__dso_handle);
if ( imageMinOS > dyldMinOS ) {
#if TARGET_OS_OSX
const char* msg = dyld::mkstringf(" (which was built for Mac OS X %d.%d)", imageMinOS >> 16, (imageMinOS >> 8) & 0xFF);
#else
const char* msg = dyld::mkstringf(" (which was built for iOS %d.%d)", imageMinOS >> 16, (imageMinOS >> 8) & 0xFF);
#endif
strcpy(versMismatch, msg);
::free((void*)msg);
}
throwSymbolNotFound(context, symbolName, this->getPath(), versMismatch, definedInImage->getPath());
}
uintptr_t ImageLoaderMachOCompressed::resolve(const LinkContext& context, const char* symbolName,
uint8_t symboFlags, long libraryOrdinal, const ImageLoader** targetImage,
DyldSharedCache::DataConstLazyScopedWriter& patcher,
LastLookup* last, bool runResolver)
{
*targetImage = NULL;
// only clients that benefit from caching last lookup pass in a LastLookup struct
if ( last != NULL ) {
if ( (last->ordinal == libraryOrdinal)
&& (last->flags == symboFlags)
&& (last->name == symbolName) ) {
*targetImage = last->foundIn;
return last->result;
}
}
bool weak_import = (symboFlags & BIND_SYMBOL_FLAGS_WEAK_IMPORT);
uintptr_t symbolAddress;
if ( context.bindFlat || (libraryOrdinal == BIND_SPECIAL_DYLIB_FLAT_LOOKUP) ) {
symbolAddress = this->resolveFlat(context, symbolName, weak_import, runResolver, targetImage);
}
else if ( libraryOrdinal == BIND_SPECIAL_DYLIB_WEAK_LOOKUP ) {
symbolAddress = this->resolveWeak(context, symbolName, weak_import, runResolver, targetImage, patcher);
}
else {
if ( libraryOrdinal == BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE ) {
*targetImage = context.mainExecutable;
}
else if ( libraryOrdinal == BIND_SPECIAL_DYLIB_SELF ) {
*targetImage = this;
}
else if ( libraryOrdinal <= 0 ) {
dyld::throwf("bad mach-o binary, unknown special library ordinal (%ld) too big for symbol %s in %s",
libraryOrdinal, symbolName, this->getPath());
}
else if ( (unsigned)libraryOrdinal <= libraryCount() ) {
*targetImage = libImage((unsigned int)libraryOrdinal-1);
}
else {
dyld::throwf("bad mach-o binary, library ordinal (%ld) too big (max %u) for symbol %s in %s",
libraryOrdinal, libraryCount(), symbolName, this->getPath());
}
if ( *targetImage == NULL ) {
if ( weak_import ) {
// if target library not loaded and reference is weak or library is weak return 0
symbolAddress = 0;
}
else {
// Try get the path from the load commands
if ( const char* depPath = libPath((unsigned int)libraryOrdinal-1) ) {
dyld::throwf("can't resolve symbol %s in %s because dependent dylib %s could not be loaded",
symbolName, this->getPath(), depPath);
} else {
dyld::throwf("can't resolve symbol %s in %s because dependent dylib #%ld could not be loaded",
symbolName, this->getPath(), libraryOrdinal);
}
}
}
else {
symbolAddress = resolveTwolevel(context, symbolName, *targetImage, this, (unsigned)libraryOrdinal, weak_import, runResolver, targetImage);
}
}
// save off lookup results if client wants
if ( last != NULL ) {
last->ordinal = libraryOrdinal;
last->flags = symboFlags;
last->name = symbolName;
last->foundIn = *targetImage;
last->result = symbolAddress;
}
return symbolAddress;
}
uintptr_t ImageLoaderMachOCompressed::bindAt(const LinkContext& context, ImageLoaderMachOCompressed* image,
uintptr_t addr, uint8_t type, const char* symbolName,
uint8_t symbolFlags, intptr_t addend, long libraryOrdinal,
ExtraBindData *extraBindData,
const char* msg, DyldSharedCache::DataConstLazyScopedWriter& patcher,
LastLookup* last, bool runResolver)
{
const ImageLoader* targetImage;
uintptr_t symbolAddress;
// resolve symbol
if (type == BIND_TYPE_THREADED_REBASE) {
symbolAddress = 0;
targetImage = nullptr;
} else
symbolAddress = image->resolve(context, symbolName, symbolFlags, libraryOrdinal, &targetImage, patcher, last, runResolver);
// do actual update
return image->bindLocation(context, image->imageBaseAddress(), addr, symbolAddress, type, symbolName, addend, image->getPath(), targetImage ? targetImage->getPath() : NULL, msg, extraBindData, image->fSlide);
}
void ImageLoaderMachOCompressed::throwBadBindingAddress(uintptr_t address, uintptr_t segmentEndAddress, int segmentIndex,
const uint8_t* startOpcodes, const uint8_t* endOpcodes, const uint8_t* pos)
{
dyld::throwf("malformed binding opcodes (%ld/%ld): address 0x%08lX is outside segment %s (0x%08lX -> 0x%08lX)",
(intptr_t)(pos-startOpcodes), (intptr_t)(endOpcodes-startOpcodes), address, segName(segmentIndex),
segActualLoadAddress(segmentIndex), segmentEndAddress);
}
void ImageLoaderMachOCompressed::doBind(const LinkContext& context, bool forceLazysBound, const ImageLoader* reExportParent)
{
CRSetCrashLogMessage2(this->getPath());
// if prebound and loaded at prebound address, and all libraries are same as when this was prebound, then no need to bind
// note: flat-namespace binaries need to have imports rebound (even if correctly prebound)
if ( this->usablePrebinding(context) ) {
// don't need to bind
// except weak which may now be inline with the regular binds
if ( this->participatesInCoalescing() && (fDyldInfo != nullptr) ) {
// run through all binding opcodes
DyldSharedCache::DataConstLazyScopedWriter patcher(context.dyldCache, mach_task_self(), context.verboseMapping ? &dyld::log : nullptr);
auto* patcherPtr = &patcher;
eachBind(context, ^(const LinkContext& ctx, ImageLoaderMachOCompressed* image,
uintptr_t addr, uint8_t type, const char* symbolName,
uint8_t symbolFlags, intptr_t addend, long libraryOrdinal,
ExtraBindData *extraBindData,
const char* msg, LastLookup* last, bool runResolver) {
if ( libraryOrdinal != BIND_SPECIAL_DYLIB_WEAK_LOOKUP )
return (uintptr_t)0;
return ImageLoaderMachOCompressed::bindAt(ctx, image, addr, type, symbolName, symbolFlags,
addend, libraryOrdinal, extraBindData,
msg, *patcherPtr, last, runResolver);
});
}
}
else {
uint64_t t0 = mach_absolute_time();
uint32_t ignore;
bool bindingBecauseOfRoot = ( this->overridesCachedDylib(ignore) || this->inSharedCache() );
vmAccountingSetSuspended(context, bindingBecauseOfRoot);
if ( fChainedFixups != NULL ) {
DyldSharedCache::DataConstLazyScopedWriter patcher(context.dyldCache, mach_task_self(), context.verboseMapping ? &dyld::log : nullptr);
const dyld_chained_fixups_header* fixupsHeader = (dyld_chained_fixups_header*)(fLinkEditBase + fChainedFixups->dataoff);
doApplyFixups(context, fixupsHeader, patcher);
}
else if ( fDyldInfo != nullptr ) {
#if TEXT_RELOC_SUPPORT
// if there are __TEXT fixups, temporarily make __TEXT writable
if ( fTextSegmentBinds )
this->makeTextSegmentWritable(context, true);
#endif
// make the cache writable for this block
DyldSharedCache::DataConstLazyScopedWriter patcher(context.dyldCache, mach_task_self(), context.verboseMapping ? &dyld::log : nullptr);
auto* patcherPtr = &patcher;
if ( this->inSharedCache() )
patcher.makeWriteable();
// run through all binding opcodes
eachBind(context, ^(const LinkContext& ctx, ImageLoaderMachOCompressed* image,
uintptr_t addr, uint8_t type, const char* symbolName,
uint8_t symbolFlags, intptr_t addend, long libraryOrdinal,
ExtraBindData *extraBindData,
const char* msg, LastLookup* last, bool runResolver) {
return ImageLoaderMachOCompressed::bindAt(ctx, image, addr, type, symbolName, symbolFlags,
addend, libraryOrdinal, extraBindData,
msg, *patcherPtr, last, runResolver);
});
#if TEXT_RELOC_SUPPORT
// if there were __TEXT fixups, restore write protection
if ( fTextSegmentBinds )
this->makeTextSegmentWritable(context, false);
#endif
// if this image is in the shared cache, but depends on something no longer in the shared cache,
// there is no way to reset the lazy pointers, so force bind them now
if ( forceLazysBound || fInSharedCache )
this->doBindJustLazies(context, patcher);
// this image is in cache, but something below it is not. If
// this image has lazy pointer to a resolver function, then
// the stub may have been altered to point to a shared lazy pointer.
if ( fInSharedCache )
this->updateOptimizedLazyPointers(context);
}
uint64_t t1 = mach_absolute_time();
ImageLoader::fgTotalRebindCacheTime += (t1-t0);
}
// See if this dylib overrides something in the dyld cache
uint32_t dyldCacheOverrideImageNum;
if ( context.dyldCache && context.dyldCache->header.builtFromChainedFixups && overridesCachedDylib(dyldCacheOverrideImageNum) ) {
// make the cache writable for this block
DyldSharedCache::DataConstLazyScopedWriter patcher(context.dyldCache, mach_task_self(), context.verboseMapping ? &dyld::log : nullptr);
auto* patcherPtr = &patcher;
// need to patch all other places in cache that point to the overridden dylib, to point to this dylib instead
const dyld3::closure::Image* overriddenImage = context.dyldCache->cachedDylibsImageArray()->imageForNum(dyldCacheOverrideImageNum);
uint32_t imageIndex = dyldCacheOverrideImageNum - (uint32_t)context.dyldCache->cachedDylibsImageArray()->startImageNum();
//dyld::log("doBind() found override of %s\n", this->getPath());
context.dyldCache->forEachPatchableExport(imageIndex, ^(uint32_t cacheOffsetOfImpl, const char* exportName) {
uintptr_t newImpl = 0;
const ImageLoader* foundIn = nullptr;
if ( this->findExportedSymbolAddress(context, exportName, NULL, 0, false, &foundIn, &newImpl) ) {
//dyld::log(" patchCacheUsesOf(%s) found in %s\n", exportName, foundIn->getPath());
patchCacheUsesOf(context, overriddenImage, cacheOffsetOfImpl, exportName, newImpl, *patcherPtr);
}
else {
// <rdar://problem/59196856> allow patched impls to move between re-export sibling dylibs
if ( reExportParent != nullptr ) {
reExportParent->forEachReExportDependent(^(const ImageLoader* reExportedDep, bool& stop) {
uintptr_t siblingImpl = 0;
const ImageLoader* foundInSibling = nullptr;
if ( reExportedDep->findExportedSymbolAddress(context, exportName, NULL, 0, false, &foundInSibling, &siblingImpl) ) {