Skip to content

Make LD_PRELOAD and DYLD_INSERT_LIBRARIES work on macOS - #246

Open
struct wants to merge 1 commit into
masterfrom
preload_fixes_nov_2026
Open

struct wants to merge 1 commit into
masterfrom
preload_fixes_nov_2026

Conversation

@struct

@struct struct commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Fixes some longstanding issues with using IsoAlloc with LD_PRELOAD or DYLD_INTERPOSE / DYLD_INSERT_LIBRARIES

macOS: interpose malloc, free, calloc, realloc, reallocf, valloc, posix_memalign, aligned_alloc, malloc_size, malloc_good_size, the typed malloc entry points and the libc++ operator new and delete symbols through a __DATA,__interpose table, register an IsoAlloc malloc zone as the default zone, and forward pointers that belong to libSystem back to their zone instead of aborting or losing them.

Both: initialize every mutex and the one time state on the lazy init path (libSystem calls malloc before our constructor), add fork handlers that take every lock in prepare, keep big zones mapped at exit unless ISO_DTOR_CLEANUP, hook valloc and pvalloc, fix the nothrow new and delete signatures, guard the free paths against a NULL root, and never abort from the size lookup used by realloc on foreign pointers.

Tests: tests/preload with make preload_tests (alias make test_macos) runs six programs under the real preload mechanism of each OS, in CI for the macOS, clang and gcc jobs.

macOS: interpose malloc, free, calloc, realloc, reallocf, valloc,
posix_memalign, aligned_alloc, malloc_size, malloc_good_size, the
typed malloc entry points and the libc++ operator new and delete
symbols through a __DATA,__interpose table, register an IsoAlloc
malloc zone as the default zone, and forward pointers that belong
to libSystem back to their zone instead of aborting or losing them.

Both: initialize every mutex and the one time state on the lazy
init path (libSystem calls malloc before our constructor), add
fork handlers that take every lock in prepare, keep big zones
mapped at exit unless ISO_DTOR_CLEANUP, hook valloc and pvalloc,
fix the nothrow new and delete signatures, guard the free paths
against a NULL root, and never abort from the size lookup used
by realloc on foreign pointers.

Tests: tests/preload with make preload_tests (alias make test_macos)
runs six programs under the real preload mechanism of each OS, in
CI for the macOS, clang and gcc jobs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant