My program c.c is extremely simple
#include <stdio.h>
int main()
{
int ret = 0;
return ret;
}
When I compile it using "clang -fsanitize=address c.c " and run a.out the following message is displayed, however, the program runs successfully
a.out(40820,0x106ffe600) malloc: nano zone abandoned due to inability to preallocate reserved vm space.
The code is compiled using (Xcode 13) Apple clang version 13.0.0 (clang-1300.0.29.3) Target: x86_64-apple-darwin21.1.0 Thread model: posix
OS is macOS Monterey (12.0.1)
Any insights to understand this better will be helpful
Try:
MallocNanoZone=0 ./a.out
NOTE: My explanation may be a bit inaccurate because I only just studied it to answer the question: I just briefly read the libmalloc code to try and follow what's going on, here is what I think is happening:
The nano_malloc routine in libmalloc tries to pre-allocate the pre-calculated sized memory for pre-calculated memory addresses. Because you are injecting address sanitizer hooks into the binary (-fsanitize=address) the addresses are not usable to calculate the exact size for preallocation in your a.out ... Which in turns means that the pre-determination of how much space is needed at which bands in the virtual memory is weirded out.
So you can simply disable it by turning off the preband allocation ... set the environment variable MallocNanoZone=0 and off you go.