From b8f898ef88ab34f3a5914cd3806155c8692ff7db Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Tue, 2 Jul 2019 23:49:19 -0700 Subject: [PATCH] Add libprofile-extras to all link steps when NATIVE_COVERAGE is enabled. libprofile-extras has a wrapper to getenv() that appends the effective userid (euid) of the current process to GCOV_PREFIX. This avoids conflicts and permissions issues when multiple processes try to create/access the same directories and files under /data/misc/trace. This library needs to be added and the -Wl,--wrap,getenv flag needs to be passed to all link steps. Since Android.mk does not propagate flags and libraries across dependencies, this change just adds the library and flag to all non-static-library Android.mk modules. As a consequence, *ALL* binaries created via Android.mk will have the signal handler and property watcher thread in libprofile-extras but they are no-ops in non-coverage-enabled binaries. The dependency is added early enough in core/binary.mk so that the LOCAL_SOONG_LINK_TYPE resolutions occur correctly. Test: Verify that coverage files are written to /data/misc/trace//proc/... instead of /data/misc/trace/proc/... Change-Id: I4d5f849c15e9a278253f2148185ddf3ab2878e2f --- core/binary.mk | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/binary.mk b/core/binary.mk index f63e4cdee9..e76942c73f 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -267,6 +267,20 @@ ifneq ($(LOCAL_SDK_VERSION),) endif endif +ifeq ($(NATIVE_COVERAGE),true) + ifndef LOCAL_IS_HOST_MODULE + my_ldflags += -Wl,--wrap,getenv + + ifneq ($(LOCAL_MODULE_CLASS),STATIC_LIBRARIES) + ifeq ($(LOCAL_SDK_VERSION),) + my_whole_static_libraries += libprofile-extras + else + my_whole_static_libraries += libprofile-extras_ndk + endif + endif + endif +endif + ifneq ($(LOCAL_USE_VNDK),) # Required VNDK version for vendor modules is BOARD_VNDK_VERSION. my_vndk_version := $(BOARD_VNDK_VERSION)