From c581d353f7749d23bf5e337ec57e4bc6c644803b Mon Sep 17 00:00:00 2001 From: wangmingrong1 Date: Thu, 14 Nov 2024 16:01:00 +0800 Subject: [PATCH] gcov: Correct existing gcov configuration --- arch/arm/src/cmake/armclang.cmake | 4 ++-- arch/arm/src/cmake/clang.cmake | 4 ++-- arch/arm/src/cmake/gcc.cmake | 2 +- arch/arm/src/cmake/ghs.cmake | 2 +- arch/arm/src/cmake/platform.cmake | 2 +- arch/arm/src/common/Toolchain.defs | 2 +- arch/arm64/src/Toolchain.defs | 2 +- arch/arm64/src/cmake/platform.cmake | 2 +- arch/risc-v/src/cmake/Toolchain.cmake | 2 +- arch/risc-v/src/cmake/platform.cmake | 2 +- arch/risc-v/src/common/Toolchain.defs | 2 +- arch/sim/src/cmake/Toolchain.cmake | 2 +- arch/sim/src/sim/CMakeLists.txt | 2 +- arch/sim/src/sim/posix/sim_hostmisc.c | 4 ++-- arch/tricore/src/cmake/ToolchainGnuc.cmake | 2 +- arch/tricore/src/cmake/platform.cmake | 2 +- arch/tricore/src/common/ToolchainGnuc.defs | 4 ++-- arch/x86_64/src/cmake/Toolchain.cmake | 2 +- arch/x86_64/src/cmake/platform.cmake | 2 +- arch/xtensa/src/cmake/platform.cmake | 2 +- arch/xtensa/src/lx6/Toolchain.defs | 2 +- arch/xtensa/src/lx7/Toolchain.defs | 2 +- boards/sim/sim/sim/scripts/Make.defs | 8 ++++++-- libs/libbuiltin/Makefile | 1 - libs/libbuiltin/compiler-rt/CMakeLists.txt | 7 +++++++ libs/libbuiltin/compiler-rt/Make.defs | 3 +++ sched/Kconfig | 20 -------------------- tools/Config.mk | 2 +- 28 files changed, 43 insertions(+), 50 deletions(-) diff --git a/arch/arm/src/cmake/armclang.cmake b/arch/arm/src/cmake/armclang.cmake index dc9762e39d0..0d023b114bc 100644 --- a/arch/arm/src/cmake/armclang.cmake +++ b/arch/arm/src/cmake/armclang.cmake @@ -116,8 +116,8 @@ if(CONFIG_STACK_USAGE_WARNING AND NOT "${CONFIG_STACK_USAGE_WARNING}" STREQUAL add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING}) endif() -if(CONFIG_SCHED_GCOV) - add_compile_options(-fprofile-generate -ftest-coverage) +if(CONFIG_COVERAGE_ALL) + add_compile_options(-fprofile-instr-generate -fcoverage-mapping) endif() if(CONFIG_PROFILE_ALL) diff --git a/arch/arm/src/cmake/clang.cmake b/arch/arm/src/cmake/clang.cmake index fe519d72624..de5bfacb83c 100644 --- a/arch/arm/src/cmake/clang.cmake +++ b/arch/arm/src/cmake/clang.cmake @@ -117,8 +117,8 @@ if(CONFIG_STACK_USAGE_WARNING AND NOT "${CONFIG_STACK_USAGE_WARNING}" STREQUAL add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING}) endif() -if(CONFIG_SCHED_GCOV_ALL) - add_compile_options(-fprofile-generate -ftest-coverage) +if(CONFIG_COVERAGE_ALL) + add_compile_options(-fprofile-instr-generate -fcoverage-mapping) endif() if(CONFIG_PROFILE_ALL) diff --git a/arch/arm/src/cmake/gcc.cmake b/arch/arm/src/cmake/gcc.cmake index d28c0eff737..12cf2cbd741 100644 --- a/arch/arm/src/cmake/gcc.cmake +++ b/arch/arm/src/cmake/gcc.cmake @@ -127,7 +127,7 @@ if(CONFIG_STACK_USAGE_WARNING AND NOT "${CONFIG_STACK_USAGE_WARNING}" STREQUAL add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING}) endif() -if(CONFIG_SCHED_GCOV_ALL) +if(CONFIG_COVERAGE_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() diff --git a/arch/arm/src/cmake/ghs.cmake b/arch/arm/src/cmake/ghs.cmake index 16068a27768..d45d521bbf1 100644 --- a/arch/arm/src/cmake/ghs.cmake +++ b/arch/arm/src/cmake/ghs.cmake @@ -88,7 +88,7 @@ if(CONFIG_STACK_USAGE_WARNING AND NOT "${CONFIG_STACK_USAGE_WARNING}" STREQUAL add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING}) endif() -if(CONFIG_SCHED_GCOV_ALL) +if(CONFIG_COVERAGE_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() diff --git a/arch/arm/src/cmake/platform.cmake b/arch/arm/src/cmake/platform.cmake index 26e9adaebd8..401eac466a1 100644 --- a/arch/arm/src/cmake/platform.cmake +++ b/arch/arm/src/cmake/platform.cmake @@ -83,6 +83,6 @@ if(CONFIG_LIBSUPCXX_TOOLCHAIN) nuttx_find_toolchain_lib(libsupc++.a) endif() -if(CONFIG_SCHED_GCOV) +if(CONFIG_COVERAGE_TOOLCHAIN) nuttx_find_toolchain_lib(libgcov.a) endif() diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs index 883ab9b35c0..b68f94dc0cf 100644 --- a/arch/arm/src/common/Toolchain.defs +++ b/arch/arm/src/common/Toolchain.defs @@ -502,7 +502,7 @@ ifeq ($(CONFIG_LIBSUPCXX_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a)) endif -ifeq ($(CONFIG_SCHED_GCOV),y) +ifeq ($(CONFIG_COVERAGE_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a)) endif diff --git a/arch/arm64/src/Toolchain.defs b/arch/arm64/src/Toolchain.defs index 9656b40785d..bafa0251f8c 100644 --- a/arch/arm64/src/Toolchain.defs +++ b/arch/arm64/src/Toolchain.defs @@ -223,7 +223,7 @@ ifeq ($(CONFIG_LIBSUPCXX_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a)) endif -ifeq ($(CONFIG_SCHED_GCOV),y) +ifeq ($(CONFIG_COVERAGE_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a)) endif diff --git a/arch/arm64/src/cmake/platform.cmake b/arch/arm64/src/cmake/platform.cmake index 130f620fa8b..6314978d4c2 100644 --- a/arch/arm64/src/cmake/platform.cmake +++ b/arch/arm64/src/cmake/platform.cmake @@ -56,7 +56,7 @@ if(CONFIG_LIBSUPCXX_TOOLCHAIN) OUTPUT_VARIABLE extra_library) list(APPEND EXTRA_LIB ${extra_library}) endif() -if(CONFIG_SCHED_GCOV) +if(CONFIG_COVERAGE_TOOLCHAIN) execute_process( COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS} --print-file-name=libgcov.a diff --git a/arch/risc-v/src/cmake/Toolchain.cmake b/arch/risc-v/src/cmake/Toolchain.cmake index d44d2845b96..75c5ad9cacb 100644 --- a/arch/risc-v/src/cmake/Toolchain.cmake +++ b/arch/risc-v/src/cmake/Toolchain.cmake @@ -159,7 +159,7 @@ if(${CONFIG_STACK_USAGE_WARNING}) endif() endif() -if(CONFIG_SCHED_GCOV_ALL) +if(CONFIG_COVERAGE_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() diff --git a/arch/risc-v/src/cmake/platform.cmake b/arch/risc-v/src/cmake/platform.cmake index 41996556265..fe582f713d8 100644 --- a/arch/risc-v/src/cmake/platform.cmake +++ b/arch/risc-v/src/cmake/platform.cmake @@ -61,7 +61,7 @@ if(CONFIG_LIBSUPCXX_TOOLCHAIN) list(APPEND EXTRA_LIB ${extra_library}) endif() -if(CONFIG_SCHED_GCOV) +if(CONFIG_COVERAGE_TOOLCHAIN) execute_process( COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS} --print-file-name=libgcov.a diff --git a/arch/risc-v/src/common/Toolchain.defs b/arch/risc-v/src/common/Toolchain.defs index 803a6278cc1..f0d6e02856d 100644 --- a/arch/risc-v/src/common/Toolchain.defs +++ b/arch/risc-v/src/common/Toolchain.defs @@ -417,7 +417,7 @@ ifeq ($(CONFIG_LIBSUPCXX_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a)) endif -ifeq ($(CONFIG_SCHED_GCOV),y) +ifeq ($(CONFIG_COVERAGE_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a)) endif diff --git a/arch/sim/src/cmake/Toolchain.cmake b/arch/sim/src/cmake/Toolchain.cmake index 8cb388b4fb9..9ce379bd48a 100644 --- a/arch/sim/src/cmake/Toolchain.cmake +++ b/arch/sim/src/cmake/Toolchain.cmake @@ -86,7 +86,7 @@ if(CONFIG_STACK_USAGE_WARNING) add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING}) endif() -if(CONFIG_SCHED_GCOV_ALL) +if(CONFIG_COVERAGE_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() diff --git a/arch/sim/src/sim/CMakeLists.txt b/arch/sim/src/sim/CMakeLists.txt index ce909412b7e..74651482323 100644 --- a/arch/sim/src/sim/CMakeLists.txt +++ b/arch/sim/src/sim/CMakeLists.txt @@ -27,7 +27,7 @@ set(HOSTSRCS) set(HOST_INCLUDE_DIRS) set(STDLIBS pthread) -if(CONFIG_SCHED_GCOV) +if(CONFIG_COVERAGE_TOOLCHAIN) list(APPEND STDLIBS gcov) endif() diff --git a/arch/sim/src/sim/posix/sim_hostmisc.c b/arch/sim/src/sim/posix/sim_hostmisc.c index 44f3f19c872..b7987057885 100644 --- a/arch/sim/src/sim/posix/sim_hostmisc.c +++ b/arch/sim/src/sim/posix/sim_hostmisc.c @@ -50,7 +50,7 @@ * Public Function Prototypes ****************************************************************************/ -#ifdef CONFIG_SCHED_GCOV +#ifndef CONFIG_COVERAGE_NONE void __gcov_dump(void); #endif @@ -72,7 +72,7 @@ extern int backtrace(void **array, int size); void host_abort(int status) { -#ifdef CONFIG_SCHED_GCOV +#ifndef CONFIG_COVERAGE_NONE /* Dump gcov data. */ host_uninterruptible_no_return(__gcov_dump); diff --git a/arch/tricore/src/cmake/ToolchainGnuc.cmake b/arch/tricore/src/cmake/ToolchainGnuc.cmake index 123ed995d37..59b665c0000 100644 --- a/arch/tricore/src/cmake/ToolchainGnuc.cmake +++ b/arch/tricore/src/cmake/ToolchainGnuc.cmake @@ -84,7 +84,7 @@ if(CONFIG_STACK_CANARIES) add_compile_options(-fstack-protector-all) endif() -if(CONFIG_SCHED_GCOV_ALL) +if(CONFIG_COVERAGE_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() diff --git a/arch/tricore/src/cmake/platform.cmake b/arch/tricore/src/cmake/platform.cmake index da0207fa616..a2e2cf8d4da 100644 --- a/arch/tricore/src/cmake/platform.cmake +++ b/arch/tricore/src/cmake/platform.cmake @@ -60,7 +60,7 @@ if(CONFIG_TRICORE_TOOLCHAIN_GNU) OUTPUT_VARIABLE extra_library) list(APPEND EXTRA_LIB ${extra_library}) endif() - if(CONFIG_SCHED_GCOV) + if(CONFIG_COVERAGE_TOOLCHAIN) execute_process( COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS} --print-file-name=libgcov.a diff --git a/arch/tricore/src/common/ToolchainGnuc.defs b/arch/tricore/src/common/ToolchainGnuc.defs index 0e1d164f10b..ed961a4a204 100644 --- a/arch/tricore/src/common/ToolchainGnuc.defs +++ b/arch/tricore/src/common/ToolchainGnuc.defs @@ -58,7 +58,7 @@ ifneq ($(CONFIG_STACK_USAGE_WARNING),0) ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING) endif -ifeq ($(CONFIG_SCHED_GCOV_ALL),y) +ifeq ($(CONFIG_COVERAGE_ALL),y) ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage endif @@ -183,7 +183,7 @@ ifeq ($(CONFIG_LIBSUPCXX),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a)) endif -ifeq ($(CONFIG_SCHED_GCOV),y) +ifeq ($(CONFIG_COVERAGE_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a)) endif diff --git a/arch/x86_64/src/cmake/Toolchain.cmake b/arch/x86_64/src/cmake/Toolchain.cmake index 162d818e11f..aa862a16d9e 100644 --- a/arch/x86_64/src/cmake/Toolchain.cmake +++ b/arch/x86_64/src/cmake/Toolchain.cmake @@ -75,7 +75,7 @@ if(${CONFIG_STACK_USAGE_WARNING}) endif() endif() -if(CONFIG_SCHED_GCOV_ALL) +if(CONFIG_COVERAGE_ALL) add_compile_options(-fprofile-generate -ftest-coverage) endif() diff --git a/arch/x86_64/src/cmake/platform.cmake b/arch/x86_64/src/cmake/platform.cmake index 414deb5c328..6e196376f8b 100644 --- a/arch/x86_64/src/cmake/platform.cmake +++ b/arch/x86_64/src/cmake/platform.cmake @@ -61,7 +61,7 @@ if(CONFIG_LIBSUPCXX_TOOLCHAIN) list(APPEND EXTRA_LIB ${extra_library}) endif() -if(CONFIG_SCHED_GCOV) +if(CONFIG_COVERAGE_TOOLCHAIN) execute_process( COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS} --print-file-name=libgcov.a diff --git a/arch/xtensa/src/cmake/platform.cmake b/arch/xtensa/src/cmake/platform.cmake index 3e3c1b6ea1c..bf6beee0d03 100644 --- a/arch/xtensa/src/cmake/platform.cmake +++ b/arch/xtensa/src/cmake/platform.cmake @@ -56,7 +56,7 @@ if(CONFIG_LIBSUPCXX_TOOLCHAIN) OUTPUT_VARIABLE extra_library) list(APPEND EXTRA_LIB ${extra_library}) endif() -if(CONFIG_SCHED_GCOV) +if(CONFIG_COVERAGE_TOOLCHAIN) execute_process( COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS} --print-file-name=libgcov.a diff --git a/arch/xtensa/src/lx6/Toolchain.defs b/arch/xtensa/src/lx6/Toolchain.defs index 6c3d51abbfb..78a5794c0b0 100644 --- a/arch/xtensa/src/lx6/Toolchain.defs +++ b/arch/xtensa/src/lx6/Toolchain.defs @@ -199,7 +199,7 @@ ifeq ($(CONFIG_LIBSUPCXX_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a)) endif -ifeq ($(CONFIG_SCHED_GCOV),y) +ifeq ($(CONFIG_COVERAGE_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a)) endif diff --git a/arch/xtensa/src/lx7/Toolchain.defs b/arch/xtensa/src/lx7/Toolchain.defs index d9da19b7054..a0aebcc8087 100644 --- a/arch/xtensa/src/lx7/Toolchain.defs +++ b/arch/xtensa/src/lx7/Toolchain.defs @@ -203,7 +203,7 @@ ifeq ($(CONFIG_LIBSUPCXX_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a)) endif -ifeq ($(CONFIG_SCHED_GCOV),y) +ifeq ($(CONFIG_COVERAGE_TOOLCHAIN),y) EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a)) endif diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index 70042b094cd..79466fe7b4c 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -72,8 +72,12 @@ ifneq ($(CONFIG_STACK_USAGE_WARNING),0) ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING) endif -ifeq ($(CONFIG_SCHED_GCOV_ALL),y) - ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage +ifeq ($(CONFIG_COVERAGE_ALL),y) + ifeq ($(CONFIG_ARCH_TOOLCHAIN_GCC),y) + ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage + else ifeq ($(CONFIG_ARCH_TOOLCHAIN_CLANG),y) + ARCHOPTIMIZATION += -fprofile-instr-generate -fcoverage-mapping + endif endif ifneq ($(CONFIG_PROFILE_ALL)$(CONFIG_SIM_PROFILE),) diff --git a/libs/libbuiltin/Makefile b/libs/libbuiltin/Makefile index 54350fbbcf7..2728539da4c 100644 --- a/libs/libbuiltin/Makefile +++ b/libs/libbuiltin/Makefile @@ -27,7 +27,6 @@ KBIN = libkbuiltin$(LIBEXT) KBINDIR = kbin include compiler-rt/Make.defs - include libgcc/Make.defs AOBJS = $(addprefix $(BINDIR)$(DELIM), $(ASRCS:.S=$(OBJEXT))) diff --git a/libs/libbuiltin/compiler-rt/CMakeLists.txt b/libs/libbuiltin/compiler-rt/CMakeLists.txt index c99368bd1b7..96731c6c82b 100644 --- a/libs/libbuiltin/compiler-rt/CMakeLists.txt +++ b/libs/libbuiltin/compiler-rt/CMakeLists.txt @@ -133,6 +133,9 @@ if(CONFIG_COVERAGE_COMPILER_RT) rt.profile PRIVATE ${INCDIR} ${CMAKE_CURRENT_LIST_DIR}/compiler-rt/lib/profile) + target_compile_options(rt.profile -fno-profile-instr-generate + -fno-coverage-mapping) + target_compile_options(rt.profile PRIVATE -DCOMPILER_RT_HAS_UNAME -Wno-undef -Wno-strict-prototypes -Wno-shadow) @@ -149,5 +152,9 @@ if(CONFIG_COVERAGE_COMPILER_RT) elseif(CONFIG_COVERAGE_MINI) nuttx_add_system_library(rt.miniprofile) + + target_compile_options(rt.miniprofile -fno-profile-instr-generate + -fno-coverage-mapping) + target_sources(rt.profile PRIVATE ${CMAKE_CURRENT_LIST_DIR}/coverage.c) endif() diff --git a/libs/libbuiltin/compiler-rt/Make.defs b/libs/libbuiltin/compiler-rt/Make.defs index 9dd4fd2c6ed..93faaf892b1 100644 --- a/libs/libbuiltin/compiler-rt/Make.defs +++ b/libs/libbuiltin/compiler-rt/Make.defs @@ -98,6 +98,7 @@ ifeq ($(CONFIG_COVERAGE_COMPILER_RT),y) FLAGS += ${INCDIR_PREFIX}$(CURDIR)/compiler-rt/compiler-rt/lib/profile +FLAGS += -fno-profile-instr-generate -fno-coverage-mapping FLAGS += -Wno-undef -Wno-strict-prototypes -Wno-shadow FLAGS += -DCOMPILER_RT_HAS_UNAME @@ -107,6 +108,8 @@ CSRCS += InstrProfilingPlatform.c else ifeq ($(CONFIG_COVERAGE_MINI),y) +FLAGS += -fno-profile-instr-generate -fno-coverage-mapping + CSRCS += coverage.c endif diff --git a/sched/Kconfig b/sched/Kconfig index a5613dac567..ac4f703ca68 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -1348,26 +1348,6 @@ config SCHED_STACK_RECORD to disable.Through instrumentation, record the backtrace at the deepest point in the stack. -config SCHED_GCOV - bool "Enable GCOV support" - select HAVE_CXXINITIALIZE - default n - ---help--- - Enable GCOV support for code coverage analysis. - After turning on this option, code coverage can be analyzed. - If this option is enabled, image size and performance will be - significantly reduced. Before use, you need to add the - "-fprofile-generate -ftest-coverage" compilation parameters - to the file to be analyzed. - -config SCHED_GCOV_ALL - bool "Enable gcov call graph for all modules" - depends on SCHED_GCOV - default n - ---help--- - Enable gcov profiling for all code, it will instrument - all code, which will cause a large performance penalty for the code. - endmenu menu "Files and I/O" diff --git a/tools/Config.mk b/tools/Config.mk index 97472ef9b83..6db3090317d 100644 --- a/tools/Config.mk +++ b/tools/Config.mk @@ -659,7 +659,7 @@ endef # CLEAN - Default clean target -ifeq ($(CONFIG_SCHED_GCOV),y) +ifeq ($(CONFIG_COVERAGE_NONE),) EXTRA = *.gcno *.gcda endif