summaryrefslogtreecommitdiff
path: root/scripts/Makefile.gcov
blob: 16c5b876440c24c11e4d0deb154193da36ce434e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# SPDX-License-Identifier: GPL-2.0-only
CFLAGS_GCOV	:= -fprofile-arcs -ftest-coverage
ifdef CONFIG_CC_IS_GCC
CFLAGS_GCOV	+= -fno-tree-loop-im
# Use atomic counter updates to avoid concurrent-access crashes in GCOV.
# Only enable if -fprofile-update=prefer-atomic does not introduce new
# undefined symbols (e.g. libatomic calls that the kernel cannot link).
CFLAGS_GCOV	+= $(call try-run,\
	echo 'long long x; void f(void){x++;}' | \
	$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w $(CFLAGS_GCOV) \
	-x c - -c -o "$$TMP.base" && \
	echo 'long long x; void f(void){x++;}' | \
	$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w $(CFLAGS_GCOV) \
	-fprofile-update=prefer-atomic \
	-x c - -c -o "$$TMP" && \
	$(NM) "$$TMP.base" | grep ' U ' > "$$TMP.ubase" || true ; \
	$(NM) "$$TMP" | grep ' U ' > "$$TMP.utest" || true ; \
	cmp -s "$$TMP.ubase" "$$TMP.utest",\
	-fprofile-update=prefer-atomic)
endif
export CFLAGS_GCOV