This is an archive of the discontinued LLVM Phabricator instance.

Port MemorySanitizer.cpp (compiler transform) to Android
Needs ReviewPublic

Authored by thurston on Jul 19 2016, 4:20 PM.

Details

Reviewers
eugenis
Summary

Change the LLVM instrumentation pass to match the corresponding changes (D23369) to external/compiler-rt/lib/msan i.e., accesses the MsanTLSSlot using either TLS_SLOT_TSAN (on Android) or original __thread variables (on non-Android).

Diff Detail

Event Timeline

thurston updated this revision to Diff 64598.Jul 19 2016, 4:20 PM
thurston retitled this revision from to Port msan to Android (continued).
thurston updated this object.
thurston added a reviewer: eugenis.
thurston added a project: Restricted Project.
thurston updated this revision to Diff 64609.Jul 19 2016, 4:42 PM

#define SANITIZER_ANDROID is just a serving suggestion

thurston updated this revision to Diff 64618.Jul 19 2016, 5:26 PM

Reuploaded with context

thurston updated this revision to Diff 67586.Aug 10 2016, 1:28 PM
thurston retitled this revision from Port msan to Android (continued) to Port MemorySanitizer.cpp (compiler transform) to Android.
thurston updated this object.

This emits the TLS access code inline:

  • using Intrinsic::thread_pointer and TLS_SLOT_TSAN if on Android
  • using the regular GlobalVariable::InitialExecTLSModel if on non-Android

to match the changes in D23369.

i.e., compared to the previous diff, this avoids the function calls in the generated code, and the copious #if SANITIZER_ANDROID throughout this source file.

eugenis added inline comments.Aug 10 2016, 2:22 PM
Transforms/Instrumentation/MemorySanitizer.cpp
498 ↗(On Diff #67586)

This would emit a call to llvm.thread.pointer for each TLS access. Please check that they are optimized out and the final assembly does not do the extra loads of TLS_SLOT_TSAN - and if it does, change the IR to call thread.pointer only once per function.

505 ↗(On Diff #67586)

As per the comment in the compiler-rt review, we need to keep the old TLS variables on non-Android.

510 ↗(On Diff #67586)

These should be named constants.

thurston updated this revision to Diff 67649.Aug 10 2016, 8:49 PM
thurston updated this object.

Matches the changes in D23369, to use TLS_SLOT_TSAN only on Android (use the original variables on non-Android platforms).
Also adds named constants offsetof__msan_param_tls etc.

Now the bad news: it does actually TLS_SLOT_TSAN many times within a function. I've done some refactoring to cache the value, but it's broken.