Do init_profile_extras constructor tasks only once

Bug: http://b/116873221

Currently, every coverage-enabled binary (the main executable or shared
library) in the process executes the init_profile_extras constructor
leading to redundant initialization.

Instead, add a weak global value that gets set once so following
constructors don't set a signal handler or create a pthread.  It's ok to
do this before the constructor succeeds because if pthread creation or
signal handler registration failed once, they are unlikely to succeed
the second time.

This is thread-safe since constructor initialization is single-threaded.
The one possibility for a race - the process doesn't have any
coverage-enabled library, and multiple threads dlopen() coverage-enabled
shared libraries - seems quite unlikely.

Test: Verify that only one extra thread is created for a daemon (adbd).
Change-Id: Ie969311c2ddac147497c870b5c365b4617b3c60a
1 file changed