Page MenuHomePhabricator

[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

Unit TestsFailed

TimeTest
60 msx64 windows > Clang.CoverageMapping::branch-constfolded.cpp
Script: -- : 'RUN: at line 3'; c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w16c2-1\llvm-project\premerge-checks\build\lib\clang\12.0.0\include -nostdsysteminc -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name branch-constfolded.cpp C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\CoverageMapping\branch-constfolded.cpp | c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\CoverageMapping\branch-constfolded.cpp
60 msx64 windows > Clang.CoverageMapping::branch-macros.cpp
Script: -- : 'RUN: at line 4'; c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w16c2-1\llvm-project\premerge-checks\build\lib\clang\12.0.0\include -nostdsysteminc -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name branch-macros.cpp C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\CoverageMapping\branch-macros.cpp | c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\CoverageMapping\branch-macros.cpp
50 msx64 windows > Clang.CoverageMapping::branch-mincounters.cpp
Script: -- : 'RUN: at line 4'; c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w16c2-1\llvm-project\premerge-checks\build\lib\clang\12.0.0\include -nostdsysteminc -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name branch-logical-mixed.cpp C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\CoverageMapping\branch-mincounters.cpp | c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\CoverageMapping\branch-mincounters.cpp
60 msx64 windows > Clang.CoverageMapping::branch-templates.cpp
Script: -- : 'RUN: at line 4'; c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w16c2-1\llvm-project\premerge-checks\build\lib\clang\12.0.0\include -nostdsysteminc -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name branch-templates.cpp C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\CoverageMapping\branch-templates.cpp | c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\CoverageMapping\branch-templates.cpp
60 msx64 windows > Clang.Profile::branch-logical-mixed.cpp
Script: -- : 'RUN: at line 4'; c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w16c2-1\llvm-project\premerge-checks\build\lib\clang\12.0.0\include -nostdsysteminc -main-file-name branch-logical-mixed.cpp C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\Profile\branch-logical-mixed.cpp -o - -emit-llvm -fprofile-instrument=clang | c:\ws\w16c2-1\llvm-project\premerge-checks\build\bin\filecheck.exe -allow-deprecated-dag-overlap C:\ws\w16c2-1\llvm-project\premerge-checks\clang\test\Profile\branch-logical-mixed.cpp
View Full Test Results (6 Failed)

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.