This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Use malloc zone interceptors on OS X
ClosedPublic

Authored by kubamracek on Nov 4 2015, 4:46 AM.

Details

Summary

In ASan, we have a custom OS X malloc zone and a few malloc-related interceptors implemented in asan_malloc_mac.cc. Since intercepting just malloc/realloc/free is not enough for OS X (we will miss some allocations), we need to implement the malloc zone for TSan as well.

This patch moves the malloc zone implementation into sanitizer_malloc_mac.inc and factors out the ASan-specific details, which remain in asan_malloc_mac.cc. After that, TSan can reuse that in tsan_malloc_mac.cc. All of this is done via macros (COMMON_MALLOC_*), mostly because of the stack trace handling in interceptors (and the interceptors themselves need to be in a .inc file).

There are a few pieces missing in the TSan's use of the malloc zone (e.g. COMMON_MALLOC_FILL_STATS is empty), but they're not really required and I'd like to first get to a point where we can actually *run* TSan without crashing during startup (before we implement non-essential features).

(This is part of an effort to port TSan to OS X, and it's one the very first steps. Don't expect TSan on OS X to actually work or pass tests at this point.)

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 39189.Nov 4 2015, 4:46 AM
kubamracek retitled this revision from to [tsan] Use malloc zone interceptors on OS X.
kubamracek updated this object.
kubamracek added reviewers: dvyukov, samsonov, glider, kcc.
dvyukov accepted this revision.Nov 4 2015, 6:02 AM
dvyukov edited edge metadata.

LGTM

This revision is now accepted and ready to land.Nov 4 2015, 6:02 AM

I'm going to split this into two patches. The first one is refactoring only (NFC), which just landed in r252052. I'll watch the bots, and if nothing breaks, I'll commit the rest soon.

Second part (TSan malloc zone) landed in r252155.

kubamracek closed this revision.Nov 5 2015, 5:48 AM