Current implementation - syscall abstractions
I refactored my approach to test my malloc by just mocking syscalls under testing conditions to get rid of dynamic linking altogether.
This page ties together the investigation results and explains the design conclusions for the malloc project. This is a part of dynamic linking investigation series.
The core takeaway is simple but strict:
A process must use exactly one allocator implementation.
Everything else follows from this constraint.
Through return-address tracing, debugger inspection, and dynamic linking analysis, we established that:
malloc to a strong symbol defined in the executable.As a result:
Allowing multiple allocator implementations to coexist in a single process is undefined behavior.
Each allocator:
When two allocators operate on overlapping memory regions:
From a correctness standpoint, this situation cannot be reasoned about safely.
The allocator project deliberately targets the Linux / ELF behavior as the reference model because:
This makes Linux a natural baseline for allocator experimentation.
To achieve equivalent behavior on macOS, the project adopts explicit dyld interposition.
By injecting an interposing dylib:
This aligns macOS runtime behavior with the Linux model without relying on deprecated mechanisms such as flat namespaces.
This decision has direct consequences for tests:
The investigation tooling (callsite tracing, counters, containers) exists precisely to make these effects visible and controllable.
As a result of this analysis, the project enforces the following rules:
These constraints guide allocator design, testing strategy, and platform support decisions.
The differences between ELF and Mach-O are not merely academic — they directly affect allocator correctness.
By understanding and controlling dynamic linking behavior:
With these rules in place, the malloc project can reason about memory management in a principled, cross-platform way.
Finally the next page, Current Implementation & Syscall Abstraction, explains what decisions are made and is implemented for the test suite of the malloc project.