This is an archive of the discontinued LLVM Phabricator instance.

[lsan][darwin] Unmask camouflaged class_rw_t pointers
ClosedPublic

Authored by lgrey on Sep 1 2022, 10:21 AM.

Details

Summary

Detailed motivation here: https://docs.google.com/document/d/1xUNo5ovPKJMYxitiHUQVRxGI3iUmspI51Jm4w8puMwo

check-asan (with LSAN enabled) and check-lsan are currently broken on recent macOS versions, due to pervasive false positives. Whenever the Objective-C runtime realizes a class, it allocates data for it, then stores that data with flags in the low bits. This means LSAN can not recognize it as a pointer while scanning.

This change checks every potential pointer on Apple platforms, and if the high bit is set, attempts to extract a pointer by masking out the high bit and flags. This is ugly, but it's also the best approach I could think of (see doc above); very open to other suggestions.

Diff Detail

Event Timeline

lgrey created this revision.Sep 1 2022, 10:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2022, 10:21 AM
Herald added a subscriber: Enna1. · View Herald Transcript
lgrey requested review of this revision.Sep 1 2022, 10:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2022, 10:21 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
yln accepted this revision.Sep 1 2022, 12:25 PM

Thanks!

I've applied the patch and can confirm that this fixes the LSan-related test failures for check-asan on a recent version of macOS.

This revision is now accepted and ready to land.Sep 1 2022, 12:25 PM
This revision was automatically updated to reflect the committed changes.