diff options
author | Pirama Arumuga Nainar <pirama@google.com> | 2021-06-25 21:14:53 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-06-25 21:14:53 +0000 |
commit | f4b9f5a9ed1932f104274bcc6f7e8c48ac7faa78 (patch) | |
tree | e4e192a00cdd1a33815a765f6b212069222e9d84 | |
parent | c78b60c87d1ea93e9caf83a5821d8d678c13995c (diff) | |
parent | b98bc39d9f3d44fc2910c0bdd16ba1933cab282d (diff) | |
download | extras-f4b9f5a9ed1932f104274bcc6f7e8c48ac7faa78.tar.gz |
Merge "Mark constructor as static" into sc-dev am: b98bc39d9f
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/extras/+/15105506
Change-Id: I5b2ae5cecc6d2ae44b41f46bddda656dd31dd7e5
-rw-r--r-- | toolchain-extras/Android.bp | 3 | ||||
-rw-r--r-- | toolchain-extras/profile-clang-extras.cpp | 21 |
2 files changed, 7 insertions, 17 deletions
diff --git a/toolchain-extras/Android.bp b/toolchain-extras/Android.bp index 007817ec..220f3e34 100644 --- a/toolchain-extras/Android.bp +++ b/toolchain-extras/Android.bp @@ -129,11 +129,10 @@ cc_test { srcs: [ "profile-clang-extras-test.cpp", ], - static_libs: [ + whole_static_libs: [ "libprofile-clang-extras", ], ldflags: [ - "-uinit_profile_extras", "-Wl,--wrap,open", ], native_coverage: false, diff --git a/toolchain-extras/profile-clang-extras.cpp b/toolchain-extras/profile-clang-extras.cpp index 89c18b2a..bb713e18 100644 --- a/toolchain-extras/profile-clang-extras.cpp +++ b/toolchain-extras/profile-clang-extras.cpp @@ -36,24 +36,15 @@ static void llvm_signal_handler(__unused int signum) { } } -__attribute__((weak)) int init_profile_extras_once = 0; - // Initialize libprofile-extras: -// - Install a signal handler that triggers __llvm_profile_write_file on <COVERAGE_FLUSH_SIGNAL>. -// -// We want this initializer to run during load time. // -// Just marking init_profile_extras() with __attribute__((constructor)) isn't -// enough since the linker drops it from its output since no other symbol from -// this static library is referenced. +// - Install a signal handler that triggers __llvm_profile_write_file on +// <COVERAGE_FLUSH_SIGNAL>. // -// We force the linker to include init_profile_extras() by passing -// '-uinit_profile_extras' to the linker (in build/soong). -__attribute__((constructor)) int init_profile_extras(void) { - if (init_profile_extras_once) - return 0; - init_profile_extras_once = 1; - +// We want this initializer to run during load time. In addition to marking +// this function as a constructor, we link this library with `--whole-archive` +// to force this function to be included in the output. +static __attribute__((constructor)) int init_profile_extras(void) { if (chained_signal_handler != SIG_ERR) { return -1; } |