This is an archive of the discontinued LLVM Phabricator instance.

Support building tsan on android.
Needs ReviewPublic

Authored by yabinc on Nov 19 2015, 9:26 PM.

Details

Summary

This is needed to build executables linked with tsan static libraries
on Android.

Diff Detail

Event Timeline

yabinc updated this revision to Diff 40739.Nov 19 2015, 9:26 PM
yabinc retitled this revision from to Support building tsan on android..
yabinc updated this object.
danalbert added a subscriber: llvm-commits.

I assume we're going to actually want to go the other direction on this and build a shared library for Android's TSAN (see eugenis' comment on https://android-review.googlesource.com/#/c/120507/1/core/config_sanitizers.mk@68)

danalbert edited subscribers, added: cfe-commits; removed: llvm-commits.Nov 19 2015, 9:36 PM
eugenis edited edge metadata.Nov 20 2015, 11:18 AM

I assume we're going to actually want to go the other direction on this and build a shared library for Android's TSAN (see eugenis' comment on https://android-review.googlesource.com/#/c/120507/1/core/config_sanitizers.mk@68)

Yes, we should use shared runtime library on Android.
See AsanSharedRuntime in SanitizerArgs.h, we need something similar for TSan.

kcc edited edge metadata.Nov 20 2015, 11:22 AM

performance is a very strong reason to have tsan linked statically.
every memory access in the app is instrumented with a function call,
if we make this call go through PLT we'll get significant drop in performance.

This is not a blocker, but I want to explicitly mention it.

dvyukov edited edge metadata.Nov 20 2015, 11:25 AM

Yes, we should use shared runtime library on Android.

Note that tsan is different from all of asan/msan/ubsan in that it does zillions of calls into runtime, so the indirection will have non-zero runtime cost.
Is it possible to statically link it into something that has the bulk of verified code?

I vaguely recall that android runtime loader had some symbol lookup differencies with glibc and that prevented interceptors (when statically linked into the main executable) from working. Maybe it is not the case now.

I vaguely recall that android runtime loader had some symbol lookup differencies with glibc and that prevented interceptors (when statically linked into the main executable) from working. Maybe it is not the case now.

This is no longer the case... There should be no difference in symbol lookup order between glibc and android linker. If you find any - please let me know. :)

The only difference is that main executable group is not RTLD_GLOBAL in android (it is RTLD_GLOBAL in glibc) - so the symbols of DT_NEEDED libraries are not visible by default; the way to enforce this for you library on android is to use -z global ld option

OK, it sounds like static runtime would work fine.
We would still need a way to switch to the shared runtime for the apps (the workflow when we LD_PRELOAD the runtime into the Zygote to run instrumented apps on a non-instrumented device). Something like -shared-libasan flag but for TSan. Does not have to be done now.

LGTM