We can't use initial-exec for the definition of __sancov_lowest_stack
because it gets linked into shared libraries such as the UBSan and
HWASan runtimes on Android. I think we can expect plain thread_local
to work unconditionally in sanitizer_common as several other sanitizers
are already using it, so drop the platform-dependent macro and just use
thread_local in the definition.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Any ideas why this was IE in the first place? Don't see any notes in the patch that added it (https://reviews.llvm.org/D37156)?
I guess Android was that main why we didn't use it before. Probably older API levels. Probably our buildbot is still on them. Wide use of thread_local may simplify sanitizers.
As I see thread_local is used in msan, which is not on Android, fuzzers, and asan fuchsia and netbsd.
However it's used in scudo, which is on Android
+Apple folks for any concerns.
Hi, thanks Vitaly!
AFAIR, thread_local (and TLS in general) require macOS 10.12 / iOS 10 / watchOS 3 or greater.
Therefore, can we hold off on this a bit?
@thetruestblue is looking into bumping the minimal sanitizer deployment targets for Apple platforms. Blue, when you do that, can you circle back here and apply this patch? This change is a good example for a sanity check: it doesn't work right now but should work afterwards.
__sancov_lowest_stack is only used by the sancov instrumentation pass when -fsanitize-coverage=stack-depth is passed, which is not the default. This option can't possibly work if SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE was defined to an empty string, because the instrumentation pass will unconditionally define the variable with TLS: https://github.com/llvm/llvm-project/blob/f67b481098cc30567d0f50a2b21f8f57b92052bd/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp#L489
So I think this is broken on the platforms where SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE is an empty string. That means we can wrap the definition of __sancov_lowest_stack in an #if !SANITIZER_APPLE and the code will work on Apple platforms as well as it did before (i.e. the runtime will build, but the compiler flag won't work). I'll update the patch to do that.