Skip to content

Commit d38f6a4

Browse files
authored
Merge pull request #39 from pythonspeed/36-aligned-alloc-sometimes-missing
Don't load aligned_alloc on macOS
2 parents 4ea08f5 + 0b09da0 commit d38f6a4

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

.changelog/36.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug that prevented Fil from running on macOS Mojave and older.

filprofiler/_filpreload.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,16 @@ static void __attribute__((constructor)) constructor() {
113113
fprintf(stderr, "Couldn't load munmap(): %s\n", dlerror());
114114
exit(1);
115115
}
116+
117+
// Older macOS don't have aligned_alloc... but therefore presumably also won't
118+
// call it.
119+
#ifndef __APPLE__
116120
underlying_real_aligned_alloc = dlsym(RTLD_NEXT, "aligned_alloc");
117121
if (!underlying_real_aligned_alloc) {
118122
fprintf(stderr, "Couldn't load aligned_alloc(): %s\n", dlerror());
119123
exit(1);
120124
}
125+
#endif
121126

122127
initialized = 1;
123128
unsetenv("LD_PRELOAD");
@@ -355,7 +360,11 @@ SYMBOL_PREFIX(aligned_alloc)(size_t alignment, size_t size) {
355360
#endif
356361
}
357362

363+
#ifdef __APPLE__
364+
void *result = aligned_alloc(alignment, size);
365+
#else
358366
void *result = underlying_real_aligned_alloc(alignment, size);
367+
#endif
359368

360369
// For now we only track anonymous mmap()s:
361370
if (!am_i_reentrant()) {

0 commit comments

Comments
 (0)