Skip to content

Commit 43f6b62

Browse files
committed
fix(amd64): properly load libsystem_* in macOS 11+
1 parent 62e0942 commit 43f6b62

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

coregrind/m_mach/dyld_cache.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static int try_to_init(void) {
149149
dyld_cache.header = (const dyld_cache_header *) cache_address;
150150
const dyld_cache_mapping_info* mappings = (const dyld_cache_mapping_info*)(calculate_relative(dyld_cache.header, dyld_cache.header->mappingOffset));
151151
dyld_cache.slide = cache_address - mappings[0].address;
152+
VG_(debugLog)(2, "dyld_cache", "dyld cache slide: %#lx\n", dyld_cache.slide);
152153

153154
if (!try_to_init_header(cache_address)) {
154155
return 0;
@@ -208,23 +209,22 @@ Addr VG_(dyld_cache_get_slide)(void) {
208209
return dyld_cache.slide;
209210
}
210211

211-
void VG_(dyld_cache_init)(void) {
212+
void VG_(dyld_cache_init)(Bool is_dynamic) {
212213
if (!try_to_init()) {
213214
VG_(dmsg)(
214215
"WARNING: could not read from dyld shared cache (DSC)\n"
215216
"Some reports (especially memory leaks) might be missing or incorrect (false-positives)\n"
216217
);
217218
return;
218219
}
219-
#if defined(VGP_arm64_darwin)
220-
// We currently detect if dyld is loading/using a library by checking if stat64 fails.
221-
// However, dyld doesn't seem to call stat64 for all of them anymore.
222-
// Because dynamic binaries on arm64 are mandatory, they will necessarily include those,
223-
// so we request them to be loaded right away to ensure we have their symbols.
224-
VG_(dyld_cache_load_library)("/usr/lib/system/libsystem_kernel.dylib");
225-
VG_(dyld_cache_load_library)("/usr/lib/system/libsystem_pthread.dylib");
226-
VG_(dyld_cache_load_library)("/usr/lib/system/libsystem_platform.dylib");
227-
#endif
220+
if (is_dynamic) {
221+
// We currently detect if dyld is loading/using a library by checking if stat64 fails.
222+
// However, dyld doesn't seem to call stat64 for all of them anymore.
223+
// All arm64 binaries are executables but some x86 ones might not be so let's avoid them just to be safe.
224+
VG_(dyld_cache_load_library)("/usr/lib/system/libsystem_kernel.dylib");
225+
VG_(dyld_cache_load_library)("/usr/lib/system/libsystem_pthread.dylib");
226+
VG_(dyld_cache_load_library)("/usr/lib/system/libsystem_platform.dylib");
227+
}
228228
}
229229

230230
int VG_(dyld_cache_might_be_in)(const HChar* path) {

coregrind/m_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
19761976
// p: none
19771977
//--------------------------------------------------------------
19781978
# if defined(VGO_darwin) && DARWIN_VERS >= DARWIN_11_00
1979-
VG_(dyld_cache_init)();
1979+
VG_(dyld_cache_init)(the_iicii.dynamic);
19801980
# endif
19811981

19821982
//--------------------------------------------------------------

coregrind/pub_core_mach.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ extern void VG_(mach_record_system_memory)(void);
7272
#if DARWIN_VERS >= DARWIN_11_00
7373
// Dyld shared cache (DSC) parsing, which is required as system libraries are not provided on disk
7474
// starting with macOS 11.0 (Big Sur)
75-
extern void VG_(dyld_cache_init)(void);
75+
extern void VG_(dyld_cache_init)(Bool is_dynamic);
7676
extern int VG_(dyld_cache_might_be_in)(const HChar*);
7777
extern int VG_(dyld_cache_load_library)(const HChar*);
7878
extern Addr VG_(dyld_cache_get_slide)(void);

0 commit comments

Comments
 (0)