This is an archive of the discontinued LLVM Phabricator instance.

[scudo] [android] Use ELF TLS on Android API >= 30.
AbandonedPublic

Authored by hctim on Jan 5 2021, 11:21 AM.

Details

Summary

On Android 11 and newer, we use Scudo standalone as the platform
allocator inside of libc. This causes a problem, as the platform version
of scudo owns the sanitizer TLS slot. When we run compiler-rt-based
scudo tests on a newer device, these two version of Scudo fight over the
slot.

This used to not break things as the compiler-rt version would just
clobber the TLS slot, and the platform version was never invoked. After
https://android-review.googlesource.com/c/platform/bionic/+/1299034/
however, the platform version re-clobbers the TLS slot after it's been
initialised by the constructors for the compiler-rt version under test.

To work around this, on newer devices that support ELF TLS, we add ELF
TLS support to compiler-rt scudo. This requires targeting a higher API
level (at least 29). If the user is targeting a lower API level and is
running an Android 11-or-greater device, the tests will be automatically
disabled as there's no reasonable way to resolve the conflict.

Diff Detail

Event Timeline

hctim created this revision.Jan 5 2021, 11:21 AM
hctim requested review of this revision.Jan 5 2021, 11:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2021, 11:21 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
hctim added inline comments.Jan 5 2021, 11:22 AM
compiler-rt/CMakeLists.txt
280

FWIW - I'm fairly sure this was broken before (Android 10 was the first with ELF TLS at API level 29?), but it was just untested on the bots because they're currently running at API level 24.

cryptoad accepted this revision.Jan 5 2021, 11:37 AM

Thanks Mitch! Looks reasonable to me.

compiler-rt/lib/scudo/scudo_tsd_shared.cpp
53

nit: we will fall in this without the || condition?

compiler-rt/lib/scudo/scudo_tsd_shared.inc
29

nit: we will fall in this without the || condition?

This revision is now accepted and ready to land.Jan 5 2021, 11:37 AM
oontvoo added inline comments.Jan 5 2021, 11:38 AM
compiler-rt/lib/scudo/CMakeLists.txt
29

shouldn't this be inherited from SANITIZER_COMMON_CFLAGS?

oontvoo added inline comments.Jan 12 2021, 11:25 AM
compiler-rt/test/lit.common.cfg.py
370–376

nit: this whole block might be better in compiler-rt/test/scudo/lit.cfg.py because it's not used anywhere else outside of scudo

hctim abandoned this revision.Jan 12 2021, 12:30 PM

We're actually going to kill support for compiler-rt based scudo on Android, so this patch should become obsolete soon. Preferably, we'd like to delete the entire thing but it seems like it might be used for Windows builds experimentally...

Patches to port GWP-ASan tests to scudo-standalone should be coming soon.