In Android, further initialization is always necessary whether preinit_array can be used.
LazyInitialize is needed regardless of .preinit_array support on platforms where runtime is loaded as dynamic library, e.g. Android.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This presumably disables DT_PREINIT_ARRAY on Android, but bionic supports DT_PREINIT_ARRAY.
What does this fix?
BIonic supports it, but the sanitizer cannot use it for Android because sanitizers are shared libraries on Android, and preinit array only works for excutables.
Worth a comment IMO.
I think this is a fix for LazyInitialize in the tsan_rtl.h - the logic there assumes that when preinit_array is always used whenever it can be used, and no further initialization is necessary. This assumption does not hold under -shared-libsan. IMO this should be fixed in LazyInitialize, not here.
compiler-rt/lib/tsan/rtl/tsan_rtl.h | ||
---|---|---|
682 | should we instead define SANITIZER_CAN_USE_PREINIT_ARRAY=0 for ANDROID ? |
compiler-rt/lib/tsan/rtl/tsan_rtl.h | ||
---|---|---|
682 | Yes, it was my suggestion to add this only for Android to avoid the branch, even if it's marked UNLIKELY... (Partly because we don't have access to the to measure the actual impact). Fine to remove the #if if @vitalybuka and @eugenis recommend it. |
compiler-rt/lib/tsan/rtl/tsan_rtl.h | ||
---|---|---|
682 | Yes, performance impact should be small. |
compiler-rt/lib/tsan/rtl/tsan_rtl.h | ||
---|---|---|
682 | ohhh before the change, if SANITIZER_CAN_USE_PREINIT_ARRAY if (UNLIKELY(!is_initialized)) will be skipped so we remove the #if |
compiler-rt/lib/tsan/rtl/tsan_rtl.h | ||
---|---|---|
682 | Oh, sorry, I mis-read the question. |
@dvyukov yes, I restore the ifder for other platforms and is_initialized check is a must for Android.
should we instead define SANITIZER_CAN_USE_PREINIT_ARRAY=0 for ANDROID ?