This CL drastically simplifies the way we're hooking the memory allocation routines in ASan on Mac by using dylib interposition to replace the main malloc_zone_* functions. This allows us to avoid replacing the default CFAllocator and drop the CF dependency at all.
Committing this patch as is will result in the static runtime being broken, so we probably need to work out the transition plan before switching to the dynamic runtime.
Details
- Reviewers
kcc
Diff Detail
Event Timeline
Cool. Do we have many clients on Mac that would have to hack their specific build systems for the dynamic runtime? I think that if installed Clang would be able to produce working binaries with "clang++ -fsanitize=address a.cc" the change is fine.
minor nits below.
asan_malloc_mac.cc | ||
---|---|---|
140 | Don't need else after return. | |
200 | Hm? So the code for free_common is just | |
343–344 | delete this whole block? |
This is getting rid of mach_override, right? Yay!!
I'd like some Apple folks to review this too, but as long as the tests pass I think
the review may happen post-commit.
asan_malloc_mac.cc | ||
---|---|---|
324 | note sure I understand this comment and the following line |
Addressed Phabricator comments by Kostya and Alexey and off-list comments by Anna Zaks and Dave Payne
Dummy implementations for malloc_make_purgeable and malloc_make_nonpurgeable (required by Chrome)
asan_intercepted_functions.h | ||
---|---|---|
232 | Hm, can you use uptr instead of size_t? | |
asan_malloc_mac.cc | ||
86 | Why do you need to allocate/free memory for zone name via ASan allocator (with fetching stack trace for malloc etc.) | |
104 | Remove this (or hide under verbosity?) | |
138 | Can memptr be zero? Or it's fine to segfault in this case? | |
194 | Why? (just curious) | |
lit_tests/heap-overflow.cc | ||
32–33 | _?wrap_malloc here and below? | |
tests/CMakeLists.txt | ||
84 | Will static runtime work at all after this change? If no, plan to remove rules for building it in /lib/asan/CMakeLists.txt |
More comments from Alexey
asan_intercepted_functions.h | ||
---|---|---|
232 | I think it's generally wrong to rewrite the function prototypes using our typenames. | |
asan_malloc_mac.cc | ||
86 | Good catch, thanks! Done. | |
104 | Done | |
138 | Added a check. | |
194 | We needed it because some allocations used to be intercepted incorrectly on Mac, and sometimes invalid free were reported because of the zone mismatch. In such cases we wanted to keep going. | |
lit_tests/heap-overflow.cc | ||
32–33 | Seems to work as is, but good idea anyway. | |
tests/CMakeLists.txt | ||
84 | It won't. There'll be a cleanup CL afterwards. |
asan_malloc_mac.cc | ||
---|---|---|
47 | Done. Although I'm a bit unsure about this since I'm not allocating asan_zone itself. | |
87 | It sure does. Something clicked in my head and made me apply the bug mitigation pattern used for strncpy :) | |
lit_tests/malloc_delete_mismatch.cc | ||
1 ↗ | (On Diff #736) | Yes. Let me upload another diff. |
Hm, can you use uptr instead of size_t?