Enable clang coverage
This is to align with build/soong to support clang coverage.
- support env CLANG_COVERAGE and CLANG_COVERAGE_CONTINUOUS_MODE.
- support kill -37 signal to dump coverage.
- support build clang coverage together with hwasan.
Bug: 309894892
Change-Id: I14f75d7fdfdf872d2db3bbceb2c10d6572bcfebf
diff --git a/core/binary.mk b/core/binary.mk
index 7998a5a..d872b66 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -145,15 +145,21 @@
ifneq (,$(strip $(foreach dir,$(NATIVE_COVERAGE_PATHS),$(filter $(dir)%,$(LOCAL_PATH)))))
ifeq (,$(strip $(foreach dir,$(NATIVE_COVERAGE_EXCLUDE_PATHS),$(filter $(dir)%,$(LOCAL_PATH)))))
my_native_coverage := true
+ my_clang_coverage := true
else
my_native_coverage := false
+ my_clang_coverage := false
endif
else
my_native_coverage := false
+ my_clang_coverage := false
endif
ifneq ($(NATIVE_COVERAGE),true)
my_native_coverage := false
endif
+ifneq ($(CLANG_COVERAGE),true)
+ my_clang_coverage := false
+endif
# Exclude directories from checking allowed manual binder interface lists.
# TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
@@ -270,6 +276,7 @@
ifneq ($(my_ndk_api),current)
ifeq ($(call math_lt, $(my_ndk_api),23),true)
my_native_coverage := false
+ my_clang_coverage := false
endif
endif
endif
@@ -295,6 +302,36 @@
endif
endif
+ifeq ($(CLANG_COVERAGE),true)
+ ifndef LOCAL_IS_HOST_MODULE
+ my_ldflags += $(CLANG_COVERAGE_HOST_LDFLAGS)
+ ifneq ($(LOCAL_MODULE_CLASS),STATIC_LIBRARIES)
+ my_whole_static_libraries += libclang_rt.profile
+ ifeq ($(LOCAL_SDK_VERSION),)
+ my_whole_static_libraries += libprofile-clang-extras
+ else
+ my_whole_static_libraries += libprofile-clang-extras_ndk
+ endif
+ endif
+ endif
+ ifeq ($(my_clang_coverage),true)
+ my_profile_instr_generate := $(CLANG_COVERAGE_INSTR_PROFILE)
+ ifeq ($(CLANG_COVERAGE_CONTINUOUS_MODE),true)
+ my_cflags += $(CLANG_COVERAGE_CONTINUOUS_FLAGS)
+ my_ldflags += $(CLANG_COVERAGE_CONTINUOUS_FLAGS)
+ endif
+
+ my_profile_instr_generate += $(CLANG_COVERAGE_CONFIG_COMMFLAGS)
+ my_cflags += $(CLANG_COVERAGE_INSTR_PROFILE) $(CLANG_COVERAGE_CONFIG_CFLAGS) $(CLANG_COVERAGE_CONFIG_COMMFLAGS)
+ my_ldflags += $(CLANG_COVERAGE_CONFIG_COMMFLAGS)
+
+ ifneq ($(filter hwaddress,$(my_sanitize)),)
+ my_cflags += $(CLANG_COVERAGE_HWASAN_FLAGS)
+ my_ldflags += $(CLANG_COVERAGE_HWASAN_FLAGS)
+ endif
+ endif
+endif
+
ifneq ($(LOCAL_USE_VNDK),)
my_cflags += -D__ANDROID_VNDK__
ifneq ($(LOCAL_USE_VNDK_VENDOR),)