XEN: enable MC/DC coverage for Clang
PATCH 1/1 XEN: enable MC/DC coverage for Clang
Clang >= 18 supports Modified Condition/Decision Coverage (MC/DC). This patch enables the detection and usage of this feature when compiling Xen with Clang.
- Update detection logic to check for '-fcoverage-mcdc' when using Clang.
- Update llvm.c to handle the profile format changes (bitmap section) required for MC/DC.
- Guard -Wno-error=coverage-too-many-conditions with CONFIG_CC_IS_GCC to avoid passing a GCC-only warning option to Clang
--- xen/Kconfig | 2 +- xen/Rules.mk | 1 + xen/arch/x86/Makefile | 4 +++- xen/common/coverage/llvm.c | 24 +++++++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-)
xen/Kconfig +1 -1
@@ -53,7 +53,7 @@ config CC_HAS_ASM_GOTO_OUTPUT # Compiler supports -fcondition-coverage aka MC/DC config CC_HAS_MCDC - def_bool $(cc-option,-fcondition-coverage) + def_bool $(cc-option,-fcondition-coverage) || $(cc-option,-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc) # Set code alignment. #
xen/Rules.mk +1 -0
@@ -136,6 +136,7 @@ non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y)) ifeq ($(CONFIG_CC_IS_CLANG),y) cov-cflags-$(CONFIG_COVERAGE) := -fprofile-instr-generate -fcoverage-mapping + cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcoverage-mcdc else cov-cflags-$(CONFIG_COVERAGE) := -fprofile-arcs -ftest-coverage cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcondition-coverage
xen/arch/x86/Makefile +3 -1
@@ -99,7 +99,9 @@ ifneq ($(CONFIG_HVM),y) $(obj)/x86_emulate.o: CFLAGS-y += -Wno-unused-label endif ifeq ($(CONFIG_CONDITION_COVERAGE),y) -$(obj)/x86_emulate.o: CFLAGS-y += -Wno-error=coverage-too-many-conditions + ifeq ($(CONFIG_CC_IS_GCC),y) + $(obj)/x86_emulate.o: CFLAGS-y += -Wno-error=coverage-too-many-conditions + endif endif efi-y := $(shell if [ ! -r $(objtree)/include/xen/compile.h -o \
xen/common/coverage/llvm.c +23 -1
@@ -120,6 +120,10 @@ extern const char __start___llvm_prf_names[];extern const char __stop___llvm_prf_names[];extern uint64_t __start___llvm_prf_cnts[];extern uint64_t __stop___llvm_prf_cnts[]; +#ifdef CONFIG_CONDITION_COVERAGE +extern const char __start___llvm_prf_bits[]; +extern const char __stop___llvm_prf_bits[]; +#endif #define START_DATA ((const void *)__start___llvm_prf_data)#define END_DATA ((const void *)__stop___llvm_prf_data)
@@ -127,16 +131,25 @@ extern uint64_t __stop___llvm_prf_cnts[];#define END_NAMES ((const void *)__stop___llvm_prf_names)#define START_COUNTERS ((void *)__start___llvm_prf_cnts)#define END_COUNTERS ((void *)__stop___llvm_prf_cnts) +#define START_BITMAP ((void *)__start___llvm_prf_bits) +#define END_BITMAP ((void *)__stop___llvm_prf_bits) static void cf_check reset_counters(void) {memset (START_COUNTERS ,0 ,END_COUNTERS -START_COUNTERS ); +#ifdef CONFIG_CONDITION_COVERAGE +memset (START_BITMAP ,0 ,END_BITMAP -START_BITMAP ); +#endif } static uint32_t cf_check get_size(void) { -return ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA + +uint32_t size =ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA +END_COUNTERS -START_COUNTERS +END_NAMES -START_NAMES ,8 ); +#ifdef CONFIG_CONDITION_COVERAGE + size +=ROUNDUP (END_BITMAP -START_BITMAP ,8 ); +#endif +return size; } static int cf_check dump(
@@ -147,11 +160,17 @@ static int cf_check dump( .version = LLVM_PROFILE_VERSION, .num_data = DIV_ROUND_UP(END_DATA - START_DATA, sizeof(struct llvm_profile_data)), .num_counters = DIV_ROUND_UP(END_COUNTERS - START_COUNTERS, sizeof(uint64_t)), +#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 + .num_bitmap_bytes = END_BITMAP - START_BITMAP, +#endif .names_size = END_NAMES - START_NAMES, #if LLVM_PROFILE_VERSION >= 8 .counters_delta = START_COUNTERS - START_DATA, #else .counters_delta = (uintptr_t)START_COUNTERS, +#endif +#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 + .bitmap_delta = START_BITMAP - START_DATA, #endif .names_delta = (uintptr_t)START_NAMES, .value_kind_last = LLVM_PROFILE_NUM_KINDS - 1,
@@ -168,6 +187,9 @@ static int cf_check dump(APPEND_TO_BUFFER (&header,sizeof (header));APPEND_TO_BUFFER (START_DATA ,END_DATA -START_DATA );APPEND_TO_BUFFER (START_COUNTERS ,END_COUNTERS -START_COUNTERS ); +#if defined(CONFIG_CONDITION_COVERAGE ) +APPEND_TO_BUFFER (START_BITMAP ,END_BITMAP -START_BITMAP ); +#endif APPEND_TO_BUFFER (START_NAMES ,END_NAMES -START_NAMES );#undef APPEND_TO_BUFFER
Signature · 1 line
2.49.0
Quoted 5 lines · Saman Dehghan
Clang >= 18 supports Modified Condition/Decision Coverage (MC/DC). This patch enables the detection and usage of this feature when compiling Xen with Clang.
- Update detection logic to check for '-fcoverage-mcdc' when using Clang.
You check for ...
Quoted 18 lines
- Update
llvm.cto handle the profile format changes (bitmap section) required for MC/DC.
- Guard -Wno-error=coverage-too-many-conditions withCONFIG_CC_IS_GCCto avoid passing a GCC-only warning option to ClangSigned-off-by Saman Dehghan <[email protected]>--- xen/Kconfig | 2 +- xen/Rules.mk | 1 + xen/arch/x86/Makefile | 4 +++- xen/common/coverage/llvm.c | 24 +++++++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-)xen/Kconfig +0
-0
xen/Kconfig config CC_HAS_ASM_GOTO_OUTPUT · line 56
Quoted 5 lines
xen/Kconfig +1
-1@@ -53,7 +53,7 @@ config CC_HAS_ASM_GOTO_OUTPUT # Compiler supports -fcondition-coverage aka MC/DC config CC_HAS_MCDC - def_bool $(cc-option,-fcondition-coverage) + def_bool $(cc-option,-fcondition-coverage) || $(cc-option,-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc)
... more than that one option here. Presumably because the option alone wouldn't be liked by the compiler? (May want mentioning in that part of the description.)
xen/arch/x86/Makefile ifneq ($(CONFIG_HVM),y) · line 105
Quoted 11 lines
xen/arch/x86/Makefile +3
-1@@ -99,7 +99,9 @@ ifneq ($(CONFIG_HVM),y) $(obj)/x86_emulate.o: CFLAGS-y += -Wno-unused-label endif ifeq ($(CONFIG_CONDITION_COVERAGE),y) -$(obj)/x86_emulate.o: CFLAGS-y += -Wno-error=coverage-too-many-conditions + ifeq ($(CONFIG_CC_IS_GCC),y) + $(obj)/x86_emulate.o: CFLAGS-y += -Wno-error=coverage-too-many-conditions + endif endif
Please can the two conditionals be combined, like I think we do elsewhere:
ifeq ($(CONFIG_CONDITION_COVERAGE)$(CONFIG_CC_IS_GCC),yy)
or
ifeq ($(CONFIG_CONDITION_COVERAGE)_$(CONFIG_CC_IS_GCC),y_y)
?
Jan
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Saman Dehghan
Clang >= 18 supports Modified Condition/Decision Coverage (MC/DC). This patch enables the detection and usage of this feature when compiling Xen with Clang.
- Update detection logic to check for '-fcoverage-mcdc' when using
Clang.
Quoted 22 lines
You check for ...
Quoted 19 lines
- Update
llvm.cto handle the profile format changes (bitmap section) required for MC/DC.
- Guard -Wno-error=coverage-too-many-conditions withCONFIG_CC_IS_GCCto avoid passing a GCC-only warning option to ClangSigned-off-by Saman Dehghan <[email protected]>--- xen/Kconfig | 2 +- xen/Rules.mk | 1 + xen/arch/x86/Makefile | 4 +++- xen/common/coverage/llvm.c | 24 +++++++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-)xen/Kconfig +0
-0@@ -53,7 +53,7 @@ config CC_HAS_ASM_GOTO_OUTPUT
Quoted 4 lines
xen/Kconfig config CC_HAS_ASM_GOTO_OUTPUT
Quoted 4 lines
xen/Kconfig +1
-1# Compiler supports -fcondition-coverage aka MC/DC config CC_HAS_MCDC - def_bool $(cc-option,-fcondition-coverage) + def_bool $(cc-option,-fcondition-coverage) ||
$(cc-option,-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc)
Quoted 3 lines
... more than that one option here. Presumably because the option alone wouldn't be liked by the compiler? (May want mentioning in that part of
the
Quoted 2 lines
description.)
Yes, That is because '-fcoverage-mcdc' only allowed with '-fcoverage-mapping' and '-fcoverage-mapping' only allowed with '-fprofile-instr-generate'.
I will add this to the description.
Thanks.
Quoted 7 lines
xen/arch/x86/Makefile ifneq ($(CONFIG_HVM),y) · line 102
Quoted 7 lines
xen/arch/x86/Makefile +0
-1@@ -99,7 +99,9 @@ ifneq ($(CONFIG_HVM),y) $(obj)/x86_emulate.o: CFLAGS-y += -Wno-unused-label endif ifeq ($(CONFIG_CONDITION_COVERAGE),y) -$(obj)/x86_emulate.o: CFLAGS-y +=
-Wno-error=coverage-too-many-conditions
Quoted 2 lines
xen/arch/x86/Makefile ifneq ($(CONFIG_HVM),y) · line 103
Quoted 2 lines
xen/arch/x86/Makefile +2
-0+ ifeq ($(CONFIG_CC_IS_GCC),y) + $(obj)/x86_emulate.o: CFLAGS-y +=
-Wno-error=coverage-too-many-conditions
Quoted 5 lines
xen/arch/x86/Makefile ifneq ($(CONFIG_HVM),y) · line 105
Quoted 2 lines
xen/arch/x86/Makefile +1
-0+ endif endifPlease can the two conditionals be combined, like I think we do elsewhere:
Quoted 7 lines
ifeq ($(CONFIG_CONDITION_COVERAGE)$(CONFIG_CC_IS_GCC),yy)
or
ifeq ($(CONFIG_CONDITION_COVERAGE)_$(CONFIG_CC_IS_GCC),y_y)
?
I initially kept the nesting because I found several similar cases in the code base that weren’t merged , so I assumed it was intentional.
No problem at all, I will combine them.
Thanks.
Quoted 2 lines
Jan
PATCH v2 1/1 XEN: enable MC/DC coverage for Clang
In reply to Saman DehghanClang >= 18 supports Modified Condition/Decision Coverage (MC/DC). This patch enables the detection and usage of this feature when compiling Xen with Clang.
- Update detection logic in Kconfig to check for the required set of Clang flags for MC/DC:
'-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc'. This bundle is necessary because '-fcoverage-mcdc' requires '-fcoverage-mapping', which in turn requires '-fprofile-instr-generate'.
- Update llvm.c to handle the profile format changes (bitmap section) required for MC/DC.
- Guard -Wno-error=coverage-too-many-conditions with CONFIG_CC_IS_GCC to avoid passing a GCC-only warning option to Clang
--- xen/Kconfig | 2 +- xen/Rules.mk | 1 + xen/arch/x86/Makefile | 2 +- xen/common/coverage/llvm.c | 24 +++++++++++++++++++++++- 4 files changed, 26 insertions(+), 3 deletions(-)
xen/Kconfig +1 -1
@@ -53,7 +53,7 @@ config CC_HAS_ASM_GOTO_OUTPUT # Compiler supports -fcondition-coverage aka MC/DC config CC_HAS_MCDC - def_bool $(cc-option,-fcondition-coverage) + def_bool $(cc-option,-fcondition-coverage) || $(cc-option,-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc) # Set code alignment. #
xen/Rules.mk +1 -0
@@ -136,6 +136,7 @@ non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y)) ifeq ($(CONFIG_CC_IS_CLANG),y) cov-cflags-$(CONFIG_COVERAGE) := -fprofile-instr-generate -fcoverage-mapping + cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcoverage-mcdc else cov-cflags-$(CONFIG_COVERAGE) := -fprofile-arcs -ftest-coverage cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcondition-coverage
xen/arch/x86/Makefile +1 -1
@@ -98,7 +98,7 @@ $(obj)/usercopy.o: CFLAGS-y += -iquote . ifneq ($(CONFIG_HVM),y) $(obj)/x86_emulate.o: CFLAGS-y += -Wno-unused-label endif -ifeq ($(CONFIG_CONDITION_COVERAGE),y) +ifeq ($(CONFIG_CONDITION_COVERAGE)$(CONFIG_CC_IS_GCC),yy) $(obj)/x86_emulate.o: CFLAGS-y += -Wno-error=coverage-too-many-conditions endif
xen/common/coverage/llvm.c +23 -1
@@ -120,6 +120,10 @@ extern const char __start___llvm_prf_names[];extern const char __stop___llvm_prf_names[];extern uint64_t __start___llvm_prf_cnts[];extern uint64_t __stop___llvm_prf_cnts[]; +#ifdef CONFIG_CONDITION_COVERAGE +extern const char __start___llvm_prf_bits[]; +extern const char __stop___llvm_prf_bits[]; +#endif #define START_DATA ((const void *)__start___llvm_prf_data)#define END_DATA ((const void *)__stop___llvm_prf_data)
@@ -127,16 +131,25 @@ extern uint64_t __stop___llvm_prf_cnts[];#define END_NAMES ((const void *)__stop___llvm_prf_names)#define START_COUNTERS ((void *)__start___llvm_prf_cnts)#define END_COUNTERS ((void *)__stop___llvm_prf_cnts) +#define START_BITMAP ((void *)__start___llvm_prf_bits) +#define END_BITMAP ((void *)__stop___llvm_prf_bits) static void cf_check reset_counters(void) {memset (START_COUNTERS ,0 ,END_COUNTERS -START_COUNTERS ); +#ifdef CONFIG_CONDITION_COVERAGE +memset (START_BITMAP ,0 ,END_BITMAP -START_BITMAP ); +#endif } static uint32_t cf_check get_size(void) { -return ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA + +uint32_t size =ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA +END_COUNTERS -START_COUNTERS +END_NAMES -START_NAMES ,8 ); +#ifdef CONFIG_CONDITION_COVERAGE + size +=ROUNDUP (END_BITMAP -START_BITMAP ,8 ); +#endif +return size; } static int cf_check dump(
@@ -147,11 +160,17 @@ static int cf_check dump( .version = LLVM_PROFILE_VERSION, .num_data = DIV_ROUND_UP(END_DATA - START_DATA, sizeof(struct llvm_profile_data)), .num_counters = DIV_ROUND_UP(END_COUNTERS - START_COUNTERS, sizeof(uint64_t)), +#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 + .num_bitmap_bytes = END_BITMAP - START_BITMAP, +#endif .names_size = END_NAMES - START_NAMES, #if LLVM_PROFILE_VERSION >= 8 .counters_delta = START_COUNTERS - START_DATA, #else .counters_delta = (uintptr_t)START_COUNTERS, +#endif +#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 + .bitmap_delta = START_BITMAP - START_DATA, #endif .names_delta = (uintptr_t)START_NAMES, .value_kind_last = LLVM_PROFILE_NUM_KINDS - 1,
@@ -168,6 +187,9 @@ static int cf_check dump(APPEND_TO_BUFFER (&header,sizeof (header));APPEND_TO_BUFFER (START_DATA ,END_DATA -START_DATA );APPEND_TO_BUFFER (START_COUNTERS ,END_COUNTERS -START_COUNTERS ); +#if defined(CONFIG_CONDITION_COVERAGE ) +APPEND_TO_BUFFER (START_BITMAP ,END_BITMAP -START_BITMAP ); +#endif APPEND_TO_BUFFER (START_NAMES ,END_NAMES -START_NAMES );#undef APPEND_TO_BUFFER
Signature · 1 line
2.49.0
Quoted 14 lines · Saman Dehghan
Clang >= 18 supports Modified Condition/Decision Coverage (MC/DC). This patch enables the detection and usage of this feature when compiling Xen with Clang.
- Update detection logic in
Kconfigto check for the required set of Clang flags for MC/DC:
'-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc'. This bundle is necessary because '-fcoverage-mcdc' requires '-fcoverage-mapping', which in turn requires '-fprofile-instr-generate'.
- Updatellvm.cto handle the profile format changes (bitmap section) required for MC/DC.
- Guard -Wno-error=coverage-too-many-conditions withCONFIG_CC_IS_GCCto avoid passing a GCC-only warning option to Clang
Quoted 1 line
Signed-off-by Saman Dehghan <[email protected]>
ideally with ...
xen/Rules.mk non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y)) · line 139
Quoted 7 lines
xen/Rules.mk +1
-0@@ -136,6 +136,7 @@ non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y)) ifeq ($(CONFIG_CC_IS_CLANG),y) cov-cflags-$(CONFIG_COVERAGE) := -fprofile-instr-generate -fcoverage-mapping + cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcoverage-mcdc
... the excess (double) blank here dropped (can likely be done while committing, if no other need for a v3 arises).
Jan
PATCH v3 1/1 XEN: enable MC/DC coverage for Clang
In reply to Saman DehghanClang >= 18 supports Modified Condition/Decision Coverage (MC/DC). This patch enables the detection and usage of this feature when compiling Xen with Clang.
- Update detection logic in Kconfig to check for the required set of Clang flags for MC/DC:
'-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc'. This bundle is necessary because '-fcoverage-mcdc' requires '-fcoverage-mapping', which in turn requires '-fprofile-instr-generate'.
- Update llvm.c to handle the profile format changes (bitmap section) required for MC/DC.
- Guard -Wno-error=coverage-too-many-conditions with CONFIG_CC_IS_GCC to avoid passing a GCC-only warning option to Clang
--- xen/Kconfig | 9 +++++++-- xen/Rules.mk | 1 + xen/arch/x86/Makefile | 2 +- xen/common/coverage/llvm.c | 18 +++++++++++++++++- 4 files changed, 26 insertions(+), 4 deletions(-)
xen/Kconfig +7 -2
@@ -51,9 +51,14 @@ config CC_HAS_ASM_GOTO_OUTPUT depends on !GCC_ASM_GOTO_OUTPUT_BROKEN depends on $(success,echo 'int foo(int x) { asm goto ("": "=r"(x) ::: bar); return x; bar: return 0; }' | $(CC) -x c - -c -o /dev/null) -# Compiler supports -fcondition-coverage aka MC/DC +# Compiler supports Modified Condition/Decision Coverage (MC/DC). +# MC/DC is a rigorous code coverage metric that requires every condition +# within a decision (boolean expression) to be shown to independently +# influence the decision's final outcome. +# +# Minimum toolchain baseline: GCC >= 14, or Clang >= 18. config CC_HAS_MCDC - def_bool $(cc-option,-fcondition-coverage) + def_bool $(cc-option,-fcondition-coverage) || $(cc-option,-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc) # Set code alignment. #
xen/Rules.mk +1 -0
@@ -136,6 +136,7 @@ non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y)) ifeq ($(CONFIG_CC_IS_CLANG),y) cov-cflags-$(CONFIG_COVERAGE) := -fprofile-instr-generate -fcoverage-mapping + cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcoverage-mcdc else cov-cflags-$(CONFIG_COVERAGE) := -fprofile-arcs -ftest-coverage cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcondition-coverage
xen/arch/x86/Makefile +1 -1
@@ -98,7 +98,7 @@ $(obj)/usercopy.o: CFLAGS-y += -iquote . ifneq ($(CONFIG_HVM),y) $(obj)/x86_emulate.o: CFLAGS-y += -Wno-unused-label endif -ifeq ($(CONFIG_CONDITION_COVERAGE),y) +ifeq ($(CONFIG_CONDITION_COVERAGE)$(CONFIG_CC_IS_GCC),yy) $(obj)/x86_emulate.o: CFLAGS-y += -Wno-error=coverage-too-many-conditions endif
xen/common/coverage/llvm.c +17 -1
@@ -120,6 +120,8 @@ extern const char __start___llvm_prf_names[];extern const char __stop___llvm_prf_names[];extern uint64_t __start___llvm_prf_cnts[];extern uint64_t __stop___llvm_prf_cnts[]; +extern const char __start___llvm_prf_bits[]; +extern const char __stop___llvm_prf_bits[];#define START_DATA ((const void *)__start___llvm_prf_data)#define END_DATA ((const void *)__stop___llvm_prf_data)
@@ -127,16 +129,23 @@ extern uint64_t __stop___llvm_prf_cnts[];#define END_NAMES ((const void *)__stop___llvm_prf_names)#define START_COUNTERS ((void *)__start___llvm_prf_cnts)#define END_COUNTERS ((void *)__stop___llvm_prf_cnts) +#define START_BITMAP ((void *)__start___llvm_prf_bits) +#define END_BITMAP ((void *)__stop___llvm_prf_bits) static void cf_check reset_counters(void) {memset (START_COUNTERS ,0 ,END_COUNTERS -START_COUNTERS ); +if (IS_ENABLED (CONFIG_CONDITION_COVERAGE ) ) +memset (START_BITMAP ,0 ,END_BITMAP -START_BITMAP ); } static uint32_t cf_check get_size(void) { -return ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA + +uint32_t size =ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA +END_COUNTERS -START_COUNTERS +END_NAMES -START_NAMES ,8 ); +if (IS_ENABLED (CONFIG_CONDITION_COVERAGE ) ) + size +=ROUNDUP (END_BITMAP -START_BITMAP ,8 ); +return size; } static int cf_check dump(
@@ -155,6 +164,10 @@ static int cf_check dump(#endif .names_delta = (uintptr_t)START_NAMES, .value_kind_last = LLVM_PROFILE_NUM_KINDS - 1, +#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 + .num_bitmap_bytes = END_BITMAP - START_BITMAP, + .bitmap_delta = START_BITMAP - START_DATA, +#endif };unsigned int off =0 ;
@@ -168,6 +181,9 @@ static int cf_check dump(APPEND_TO_BUFFER (&header,sizeof (header));APPEND_TO_BUFFER (START_DATA ,END_DATA -START_DATA );APPEND_TO_BUFFER (START_COUNTERS ,END_COUNTERS -START_COUNTERS ); +#if defined(CONFIG_CONDITION_COVERAGE ) +APPEND_TO_BUFFER (START_BITMAP ,END_BITMAP -START_BITMAP ); +#endif APPEND_TO_BUFFER (START_NAMES ,END_NAMES -START_NAMES );#undef APPEND_TO_BUFFER
Signature · 1 line
2.49.0
xen/Kconfig config CC_HAS_ASM_GOTO_OUTPUT · line 54
Quoted 10 lines · Saman Dehghan
xen/Kconfig +1
-1@@ -51,9 +51,14 @@ config CC_HAS_ASM_GOTO_OUTPUT depends on !GCC_ASM_GOTO_OUTPUT_BROKEN depends on $(success,echo 'int foo(int x) { asm goto ("": "=r"(x) ::: bar); return x; bar: return 0; }' | $(CC) -x c - -c -o /dev/null) -# Compiler supports -fcondition-coverage aka MC/DC +# Compiler supports Modified Condition/Decision Coverage (MC/DC).
Ah sorry, I only meant for this line. Enough for someone to usefully google.
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
I can trim this down on commit if you're happy.
~Andrew
Quoted 12 lines
xen/Kconfig +6
-1+# MC/DC is a rigorous code coverage metric that requires every condition +# within a decision (boolean expression) to be shown to independently +# influence the decision's final outcome. +# +# Minimum toolchain baseline: GCC >= 14, or Clang >= 18. config CC_HAS_MCDC - def_bool $(cc-option,-fcondition-coverage) + def_bool $(cc-option,-fcondition-coverage) || $(cc-option,-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc) # Set code alignment. #
Quoted 16 lines · Andrew Cooper
xen/Kconfig config CC_HAS_ASM_GOTO_OUTPUT · line 54
Quoted 10 lines · Saman Dehghan
xen/Kconfig +1
-1@@ -51,9 +51,14 @@ config CC_HAS_ASM_GOTO_OUTPUT depends on !GCC_ASM_GOTO_OUTPUT_BROKEN depends on $(success,echo 'int foo(int x) { asm goto ("": "=r"(x) ::: bar); return x; bar: return 0; }' | $(CC) -x c - -c -o /dev/null) -# Compiler supports -fcondition-coverage aka MC/DC +# Compiler supports Modified Condition/Decision Coverage (MC/DC).Ah sorry, I only meant for this line. Enough for someone to usefully google.
Quoted 5 lines
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
I can trim this down on commit if you're happy.
~Andrew
I’m happy with it, thanks a lot Andrew for suggesting to trim that line.
~Saman
Quoted 13 lines
Quoted 13 lines
xen/Kconfig +6
-1+# MC/DC is a rigorous code coverage metric that requires every condition +# within a decision (boolean expression) to be shown to independently +# influence the decision's final outcome. +# +# Minimum toolchain baseline: GCC >= 14, or Clang >= 18. config CC_HAS_MCDC - def_bool $(cc-option,-fcondition-coverage) + def_bool $(cc-option,-fcondition-coverage) || $(cc-option,-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc) # Set code alignment. #
PATCH 1/1 xen: add paddings after bitmap section in LLVM coverage profile
In reply to Saman DehghanThe layout of LLVM coverage profile is like
header
data section
(padding #1)
counter section
(padding #2)
bitmap section
(padding #3)
name section
(padding #4)
Padding areas #1 and #2 are always zeroed on 64-bit platforms, but that is not the case for padding area #3 and #4. See LLVM docs [1] and compiler-rt's own version of "get_size()" [2].
The implementation in 08c787f "xen: Enable MC/DC coverage for Clang" partly considers padding #4 in get_size() but not in dump(). It worked because in the header .padding_bytes_after_bitmap_bytes is also initialized to zero so a reader may still know how to parse the profile. But we should probably not base ourselves on such assumption. Instead let's be as close as possible to hosted environment generated profiles, i.e. those generated by compiler-rt.
In this patch, get_size() implementation is mathematically the same but changed to reflect the layout somewhat better. For dump(), padding #4 is added both in the header and in the payload.
[1] https://llvm.org/docs/InstrProfileFormat.html
[2] https://github.com/llvm/llvm-project/blob/llvmorg-20.1.8/compiler-rt/lib/profile/InstrProfilingBuffer.c#L223
---
As an aside, an alternative way that has better long-term maintainability would be [3]. I ran it with Xen and could unofficially confirm it works, modulo implementation nitty-gritties.
[3] https://github.com/llvm/llvm-project/pull/167998
--- xen/common/coverage/llvm.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
xen/common/coverage/llvm.c +7 -5
@@ -141,11 +141,11 @@ static void cf_check reset_counters(void) static uint32_t cf_check get_size(void) { -uint32_t size =ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA + -END_COUNTERS -START_COUNTERS +END_NAMES -START_NAMES ,8 ); -if (IS_ENABLED (CONFIG_CONDITION_COVERAGE ) ) - size +=ROUNDUP (END_BITMAP -START_BITMAP ,8 ); -return size; +return sizeof (struct llvm_profile_header ) + +END_DATA -START_DATA + +END_COUNTERS -START_COUNTERS + +ROUNDUP (END_BITMAP -START_BITMAP ,8 ) + +ROUNDUP (END_NAMES -START_NAMES ,8 ); } static int cf_check dump(
@@ -167,6 +167,7 @@ static int cf_check dump(#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 .num_bitmap_bytes = END_BITMAP - START_BITMAP, .bitmap_delta = START_BITMAP - START_DATA, + .padding_bytes_after_bitmap_bytes = (-(END_BITMAP - START_BITMAP)) & 7,#endif };unsigned int off =0 ;
@@ -183,6 +184,7 @@ static int cf_check dump(APPEND_TO_BUFFER (START_COUNTERS ,END_COUNTERS -START_COUNTERS );#if defined(CONFIG_CONDITION_COVERAGE )APPEND_TO_BUFFER (START_BITMAP ,END_BITMAP -START_BITMAP ); + off += header.padding_bytes_after_bitmap_bytes;#endif APPEND_TO_BUFFER (START_NAMES ,END_NAMES -START_NAMES );#undef APPEND_TO_BUFFER
Signature · 1 line
2.34.1
Ping: [XEN PATCH] xen: add paddings after bitmap section in LLVM coverage profile
Thanks,
Wentao
Quoted 83 lines · Wentao Zhang
The layout of LLVM coverage profile is like
header
data section
(padding #1)
counter section
(padding #2)
bitmap section
(padding #3)
name section
(padding #4)Padding areas #1 and #2 are always zeroed on 64-bit platforms, but that is not the case for padding area #3 and #4. See LLVM docs [1] and compiler-rt's own version of "
get_size()" [2].The implementation in 08c787f "xen: Enable MC/DC coverage for Clang" partly considers padding #4 in
get_size()but not indump(). It worked because in the header .padding_bytes_after_bitmap_bytes is also initialized to zero so a reader may still know how to parse the profile. But we should probably not base ourselves on such assumption. Instead let's be as close as possible to hosted environment generated profiles, i.e. those generated by compiler-rt.In this patch,
get_size()implementation is mathematically the same but changed to reflect the layout somewhat better. Fordump(), padding #4 is added both in the header and in the payload.[1] https://llvm.org/docs/InstrProfileFormat.html
[2] https://github.com/llvm/llvm-project/blob/llvmorg-20.1.8/compiler-rt/lib/profile/InstrProfilingBuffer.c#L223Signed-off-by Wentao Zhang <[email protected]>---
As an aside, an alternative way that has better long-term maintainability would be [3]. I ran it with Xen and could unofficially confirm it works, modulo implementation nitty-gritties.
[3] https://github.com/llvm/llvm-project/pull/167998
--- xen/common/coverage/llvm.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)xen/common/coverage/llvm.c +7
-5@@ -141,11 +141,11 @@ static void cf_check reset_counters(void) static uint32_t cf_check get_size(void) { -uint32_t size =ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA + -END_COUNTERS -START_COUNTERS +END_NAMES -START_NAMES ,8 ); -if (IS_ENABLED (CONFIG_CONDITION_COVERAGE ) ) - size +=ROUNDUP (END_BITMAP -START_BITMAP ,8 ); -return size; +return sizeof (struct llvm_profile_header ) + +END_DATA -START_DATA + +END_COUNTERS -START_COUNTERS + +ROUNDUP (END_BITMAP -START_BITMAP ,8 ) + +ROUNDUP (END_NAMES -START_NAMES ,8 ); } static int cf_check dump(@@ -167,6 +167,7 @@ static int cf_check dump(#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 .num_bitmap_bytes = END_BITMAP - START_BITMAP, .bitmap_delta = START_BITMAP - START_DATA, + .padding_bytes_after_bitmap_bytes = (-(END_BITMAP - START_BITMAP)) & 7,#endif };unsigned int off =0 ;@@ -183,6 +184,7 @@ static int cf_check dump(APPEND_TO_BUFFER (START_COUNTERS ,END_COUNTERS -START_COUNTERS );#if defined(CONFIG_CONDITION_COVERAGE )APPEND_TO_BUFFER (START_BITMAP ,END_BITMAP -START_BITMAP ); + off += header.padding_bytes_after_bitmap_bytes;#endif APPEND_TO_BUFFER (START_NAMES ,END_NAMES -START_NAMES );#undef APPEND_TO_BUFFERSignature · 1 line
2.34.1
Re: [XEN PATCH] xen: add paddings after bitmap section in LLVM coverage profile
In reply to Wentao ZhangSince you ping-ed the patch, I'll give some comments, albeit I wouldn't feel qualified to eventually ack the change.
Quoted 12 lines · Wentao Zhang
The layout of LLVM coverage profile is like
header
data section
(padding #1)
counter section
(padding #2)
bitmap section
(padding #3)
name section
(padding #4)
Quoted 1 line
Padding areas #1 and #2 are always zeroed on 64-bit platforms,
How does zeroing (or not) matter when size is what is of interest?
Quoted 12 lines
but that
is not the case for padding area #3 and #4. See LLVM docs [1] and compiler-rt's own version of "get_size()" [2].The implementation in 08c787f "xen: Enable MC/DC coverage for Clang" partly considers padding #4 in
get_size()but not indump(). It worked because in the header .padding_bytes_after_bitmap_bytes is also initialized to zero so a reader may still know how to parse the profile. But we should probably not base ourselves on such assumption. Instead let's be as close as possible to hosted environment generated profiles, i.e. those generated by compiler-rt.
Quoted 3 lines
In this patch,
get_size()implementation is mathematically the same but changed to reflect the layout somewhat better. Fordump(), padding #4 is added both in the header and in the payload.
#4 is after the name section as per the description at the top, yet code you add in dump() is to set / use the .padding_bytes_after_bitmap_bytes field. That's #3 as per above, though.
Quoted 7 lines
xen/common/coverage/llvm.c +0
-1@@ -141,11 +141,11 @@ static void cf_check reset_counters(void) static uint32_t cf_check get_size(void) { - uint32_t size = ROUNDUP(sizeof(struct llvm_profile_header) + END_DATA - START_DATA +
xen/common/coverage/llvm.c static void cf_check reset_counters(void) · line 149
Quoted 10 lines
xen/common/coverage/llvm.c +5
-4- END_COUNTERS - START_COUNTERS + END_NAMES - START_NAMES, 8); -if (IS_ENABLED (CONFIG_CONDITION_COVERAGE ) ) - size +=ROUNDUP (END_BITMAP -START_BITMAP ,8 ); -return size; +return sizeof (struct llvm_profile_header ) + +END_DATA -START_DATA + +END_COUNTERS -START_COUNTERS + +ROUNDUP (END_BITMAP -START_BITMAP ,8 ) + +ROUNDUP (END_NAMES -START_NAMES ,8 ); }
Where are these 8-s and ...
xen/common/coverage/llvm.c static int cf_check dump( · line 170
Quoted 5 lines
xen/common/coverage/llvm.c +1
-0@@ -167,6 +167,7 @@ static int cf_check dump(#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 .num_bitmap_bytes = END_BITMAP - START_BITMAP, .bitmap_delta = START_BITMAP - START_DATA, + .padding_bytes_after_bitmap_bytes = (-(END_BITMAP - START_BITMAP)) & 7,
... this 7 coming from? All I can find in your [1] reference is "Sections might be padded to meet specific alignment requirements. For simplicity, header fields and data sections solely for padding purposes are omitted in the data layout graph above and the rest of this document." No other hit when searching for "pad" or "align" in that doc.
Unrelated to your change but relevant for understanding: I also can't seem to be able to figure out where the various __{start,stop}___llvm_prf_*[] symbols are coming from. It doesn't look to be our linker script: The LLVM_COV_{RW,RO}_DATA macros both don't define any symbols. If they did, I would have asked whether the alignment needs couldn't be accounted for there.
Jan
Quoted 23 lines · Saman Dehghan
Clang >= 18 supports Modified Condition/Decision Coverage (MC/DC). This patch enables the detection and usage of this feature when compiling Xen with Clang.
- Update detection logic to check for '-fcoverage-mcdc' when using Clang.
- Updatellvm.cto handle the profile format changes (bitmap section) required for MC/DC.
- Guard -Wno-error=coverage-too-many-conditions withCONFIG_CC_IS_GCCto avoid passing a GCC-only warning option to ClangSigned-off-by Saman Dehghan <[email protected]>--- xen/Kconfig | 2 +- xen/Rules.mk | 1 + xen/arch/x86/Makefile | 4 +++- xen/common/coverage/llvm.c | 24 +++++++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-)xen/Kconfig +0
-0
xen/Kconfig config CC_HAS_ASM_GOTO_OUTPUT · line 54
Quoted 2 lines
xen/Kconfig +0
-0@@ -53,7 +53,7 @@ config CC_HAS_ASM_GOTO_OUTPUT # Compiler supports -fcondition-coverage aka MC/DC
While you're improving these comments, please drop -fcondition-coverage (as it's no longer accurate), and expand MC/DC for the benefit of people who don't know what it is.
xen/Kconfig config CC_HAS_ASM_GOTO_OUTPUT · line 55
Quoted 1 line
xen/Kconfig +0
-0config CC_HAS_MCDC
Also, # GCC >= 14, or Clang >= 18
It's important for toolchain versions to be given in comments, so we can figure out what to clean up when upgrading the toolchain baselines.
xen/common/coverage/llvm.c extern const char __start___llvm_prf_names[]; · line 126
Quoted 12 lines
xen/common/coverage/llvm.c +4
-0@@ -120,6 +120,10 @@ extern const char __start___llvm_prf_names[];extern const char __stop___llvm_prf_names[];extern uint64_t __start___llvm_prf_cnts[];extern uint64_t __stop___llvm_prf_cnts[]; +#ifdef CONFIG_CONDITION_COVERAGE +extern const char __start___llvm_prf_bits[]; +extern const char __stop___llvm_prf_bits[]; +#endif
No need for these to be #ifdef'd. In turn, it lets you do ...
Quoted 6 lines
xen/common/coverage/llvm.c +0
-0#define START_DATA ((const void *)__start___llvm_prf_data)#define END_DATA ((const void *)__stop___llvm_prf_data)@@ -127,16 +131,25 @@ extern uint64_t __stop___llvm_prf_cnts[];#define END_NAMES ((const void *)__stop___llvm_prf_names)#define START_COUNTERS ((void *)__start___llvm_prf_cnts)
xen/common/coverage/llvm.c extern uint64_t __stop___llvm_prf_cnts[]; · line 142
Quoted 10 lines
xen/common/coverage/llvm.c +5
-0#define END_COUNTERS ((void *)__stop___llvm_prf_cnts) +#define START_BITMAP ((void *)__start___llvm_prf_bits) +#define END_BITMAP ((void *)__stop___llvm_prf_bits) static void cf_check reset_counters(void) {memset (START_COUNTERS ,0 ,END_COUNTERS -START_COUNTERS ); +#ifdef CONFIG_CONDITION_COVERAGE +memset (START_BITMAP ,0 ,END_BITMAP -START_BITMAP ); +#endif
... this:
if ( IS_ENABLED(CONFIG_CONDITION_COVERAGE) ) memset(START_BITMAP, 0, END_BITMAP - START_BITMAP);
xen/common/coverage/llvm.c extern uint64_t __stop___llvm_prf_cnts[]; · line 151
Quoted 10 lines
xen/common/coverage/llvm.c +4
-1} static uint32_t cf_check get_size(void) { -return ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA + +uint32_t size =ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA +END_COUNTERS -START_COUNTERS +END_NAMES -START_NAMES ,8 ); +#ifdef CONFIG_CONDITION_COVERAGE + size +=ROUNDUP (END_BITMAP -START_BITMAP ,8 ); +#endif
and similar here.
Quoted 12 lines
xen/common/coverage/llvm.c +4
-0+return size; } static int cf_check dump(@@ -147,11 +160,17 @@ static int cf_check dump( .version = LLVM_PROFILE_VERSION, .num_data = DIV_ROUND_UP(END_DATA - START_DATA, sizeof(struct llvm_profile_data)), .num_counters = DIV_ROUND_UP(END_COUNTERS - START_COUNTERS, sizeof(uint64_t)), +#if defined(CONFIG_CONDITION_COVERAGE) && LLVM_PROFILE_VERSION >= 9 + .num_bitmap_bytes = END_BITMAP - START_BITMAP, +#endif .names_size = END_NAMES - START_NAMES,
xen/common/coverage/llvm.c static int cf_check dump( · line 176
Quoted 10 lines
xen/common/coverage/llvm.c +3
-0#if LLVM_PROFILE_VERSION >=8 .counters_delta = START_COUNTERS - START_DATA, #else .counters_delta = (uintptr_t)START_COUNTERS, +#endif +#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 + .bitmap_delta = START_BITMAP - START_DATA, #endif .names_delta = (uintptr_t)START_NAMES, .value_kind_last = LLVM_PROFILE_NUM_KINDS - 1,
With structure initialisation, you do not need to have the fields in declaration order. Therefore, you want to do something like this:
.value_kind_last = LLVM_PROFILE_NUM_KINDS - 1, +#if defined(CONFIG_CONDITION_COVERAGE) && LLVM_PROFILE_VERSION >= 9 + .num_bitmap_bytes = END_BITMAP - START_BITMAP,
+ .bitmap_delta = START_BITMAP - START_DATA, +#endif
};
to keep the ifdefary more simple.
~Andrew
Quoted 73 lines · Andrew Cooper
Quoted 23 lines · Saman Dehghan
Clang >= 18 supports Modified Condition/Decision Coverage (MC/DC). This patch enables the detection and usage of this feature when compiling Xen with Clang.
- Update detection logic to check for '-fcoverage-mcdc' when using Clang.
- Updatellvm.cto handle the profile format changes (bitmap section) required for MC/DC.
- Guard -Wno-error=coverage-too-many-conditions withCONFIG_CC_IS_GCCto avoid passing a GCC-only warning option to ClangSigned-off-by Saman Dehghan <[email protected]>--- xen/Kconfig | 2 +- xen/Rules.mk | 1 + xen/arch/x86/Makefile | 4 +++- xen/common/coverage/llvm.c | 24 +++++++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-)xen/Kconfig +0
-0xen/Kconfig config CC_HAS_ASM_GOTO_OUTPUT · line 54
Quoted 2 lines
xen/Kconfig +0
-0@@ -53,7 +53,7 @@ config CC_HAS_ASM_GOTO_OUTPUT # Compiler supports -fcondition-coverage aka MC/DCWhile you're improving these comments, please drop -fcondition-coverage (as it's no longer accurate), and expand MC/DC for the benefit of people who don't know what it is.
xen/Kconfig config CC_HAS_ASM_GOTO_OUTPUT · line 55
Quoted 1 line
xen/Kconfig +0
-0config CC_HAS_MCDCAlso, # GCC >= 14, or Clang >= 18
It's important for toolchain versions to be given in comments, so we can figure out what to clean up when upgrading the toolchain baselines.
xen/common/coverage/llvm.c extern const char __start___llvm_prf_names[]; · line 126
Quoted 12 lines
xen/common/coverage/llvm.c +4
-0@@ -120,6 +120,10 @@ extern const char __start___llvm_prf_names[];extern const char __stop___llvm_prf_names[];extern uint64_t __start___llvm_prf_cnts[];extern uint64_t __stop___llvm_prf_cnts[]; +#ifdef CONFIG_CONDITION_COVERAGE +extern const char __start___llvm_prf_bits[]; +extern const char __stop___llvm_prf_bits[]; +#endif No need for these to be #ifdef'd. In turn, it lets you do ...
Quoted 6 lines
xen/common/coverage/llvm.c +0
-0#define START_DATA ((const void *)__start___llvm_prf_data)#define END_DATA ((const void *)__stop___llvm_prf_data)@@ -127,16 +131,25 @@ extern uint64_t __stop___llvm_prf_cnts[];#define END_NAMES ((const void *)__stop___llvm_prf_names)#define START_COUNTERS ((void *)__start___llvm_prf_cnts)xen/common/coverage/llvm.c extern uint64_t __stop___llvm_prf_cnts[]; · line 142
Quoted 10 lines
xen/common/coverage/llvm.c +5
-0#define END_COUNTERS ((void *)__stop___llvm_prf_cnts) +#define START_BITMAP ((void *)__start___llvm_prf_bits) +#define END_BITMAP ((void *)__stop___llvm_prf_bits) static void cf_check reset_counters(void) {memset (START_COUNTERS ,0 ,END_COUNTERS -START_COUNTERS ); +#ifdef CONFIG_CONDITION_COVERAGE +memset (START_BITMAP ,0 ,END_BITMAP -START_BITMAP ); +#endif ... this:
Quoted 4 lines
if (
IS_ENABLED(CONFIG_CONDITION_COVERAGE))
memset(START_BITMAP, 0, END_BITMAP - START_BITMAP);Quoted 1 line
xen/common/coverage/llvm.c +0
-0}
Thanks Andrew.
IS_ENABLED(CONFIG_CONDITION_COVERAGE) is not the same as #ifdef CONFIG_CONDITION_COVERAGE.
When the option is completely undefined, IS_ENABLED() returns 1 (enabled). So even with no CONFIG_CONDITION_COVERAGE defined, the code takes the "enabled" path, which is not what we want here.
Quoted 49 lines
xen/common/coverage/llvm.c extern uint64_t __stop___llvm_prf_cnts[]; · line 151
Quoted 9 lines
xen/common/coverage/llvm.c +4
-1static uint32_t cf_check get_size(void) { -return ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA + +uint32_t size =ROUNDUP (sizeof (struct llvm_profile_header ) +END_DATA -START_DATA +END_COUNTERS -START_COUNTERS +END_NAMES -START_NAMES ,8 ); +#ifdef CONFIG_CONDITION_COVERAGE + size +=ROUNDUP (END_BITMAP -START_BITMAP ,8 ); +#endif and similar here.
Quoted 12 lines
xen/common/coverage/llvm.c +4
-0+return size; } static int cf_check dump(@@ -147,11 +160,17 @@ static int cf_check dump( .version = LLVM_PROFILE_VERSION, .num_data = DIV_ROUND_UP(END_DATA - START_DATA, sizeof(struct llvm_profile_data)), .num_counters = DIV_ROUND_UP(END_COUNTERS - START_COUNTERS, sizeof(uint64_t)), +#if defined(CONFIG_CONDITION_COVERAGE) && LLVM_PROFILE_VERSION >= 9 + .num_bitmap_bytes = END_BITMAP - START_BITMAP, +#endif .names_size = END_NAMES - START_NAMES,xen/common/coverage/llvm.c static int cf_check dump( · line 176
Quoted 10 lines
xen/common/coverage/llvm.c +3
-0#if LLVM_PROFILE_VERSION >=8 .counters_delta = START_COUNTERS - START_DATA, #else .counters_delta = (uintptr_t)START_COUNTERS, +#endif +#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 + .bitmap_delta = START_BITMAP - START_DATA, #endif .names_delta = (uintptr_t)START_NAMES, .value_kind_last = LLVM_PROFILE_NUM_KINDS - 1,With structure initialisation, you do not need to have the fields in declaration order. Therefore, you want to do something like this:
.value_kind_last =
LLVM_PROFILE_NUM_KINDS- 1,xen/common/coverage/llvm.c +4
-0+#if defined(CONFIG_CONDITION_COVERAGE ) &&LLVM_PROFILE_VERSION >=9 + .num_bitmap_bytes = END_BITMAP - START_BITMAP, + .bitmap_delta = START_BITMAP - START_DATA, +#endif };to keep the ifdefary more simple.
~Andrew
Quoted 20 lines · Saman Dehghan
Quoted 19 lines · Andrew Cooper
xen/common/coverage/llvm.c extern uint64_t __stop___llvm_prf_cnts[]; · line 142
Quoted 13 lines · Saman Dehghan
xen/common/coverage/llvm.c +5
-0@@ -127,16 +131,25 @@ extern uint64_t __stop___llvm_prf_cnts[];#define END_NAMES ((const void *)__stop___llvm_prf_names)#define START_COUNTERS ((void *)__start___llvm_prf_cnts)#define END_COUNTERS ((void *)__stop___llvm_prf_cnts) +#define START_BITMAP ((void *)__start___llvm_prf_bits) +#define END_BITMAP ((void *)__stop___llvm_prf_bits) static void cf_check reset_counters(void) {memset (START_COUNTERS ,0 ,END_COUNTERS -START_COUNTERS ); +#ifdef CONFIG_CONDITION_COVERAGE +memset (START_BITMAP ,0 ,END_BITMAP -START_BITMAP ); +#endif ... this:
if (
IS_ENABLED(CONFIG_CONDITION_COVERAGE))
memset(START_BITMAP, 0, END_BITMAP - START_BITMAP);
Quoted 8 lines
Quoted 1 line
Review extern uint64_t __stop___llvm_prf_cnts[]; · line 143
Quoted 1 line
(quoted diff) +0
-0}Thanks Andrew.
IS_ENABLED(CONFIG_CONDITION_COVERAGE)is not the same as #ifdefCONFIG_CONDITION_COVERAGE.
When the option is completely undefined,IS_ENABLED()returns 1 (enabled). So even with noCONFIG_CONDITION_COVERAGEdefined, the code takes the "enabled" path, which is not what we want here.
What makes you think this? (No - that's not how IS_ENABLED() works.)
IS_ENABLED() exists for the purpose given here, to turn preprocessor conditionals into something visible to the compiler. Notably it allows for syntax checking even in the disabled code, which is why it's preferred wherever possible.
~Andrew
Quoted 21 lines · Saman Dehghan
Quoted 20 lines · Andrew Cooper
xen/common/coverage/llvm.c extern uint64_t __stop___llvm_prf_cnts[]; · line 142
Quoted 13 lines · Saman Dehghan
xen/common/coverage/llvm.c +5
-0@@ -127,16 +131,25 @@ extern uint64_t __stop___llvm_prf_cnts[];#define END_NAMES ((const void *)__stop___llvm_prf_names)#define START_COUNTERS ((void *)__start___llvm_prf_cnts)#define END_COUNTERS ((void *)__stop___llvm_prf_cnts) +#define START_BITMAP ((void *)__start___llvm_prf_bits) +#define END_BITMAP ((void *)__stop___llvm_prf_bits) static void cf_check reset_counters(void) {memset (START_COUNTERS ,0 ,END_COUNTERS -START_COUNTERS ); +#ifdef CONFIG_CONDITION_COVERAGE +memset (START_BITMAP ,0 ,END_BITMAP -START_BITMAP ); +#endif ... this:
if (
IS_ENABLED(CONFIG_CONDITION_COVERAGE))
memset(START_BITMAP, 0, END_BITMAP - START_BITMAP);
Quoted 7 lines
Quoted 1 line
Review extern uint64_t __stop___llvm_prf_cnts[]; · line 143
Quoted 1 line
(quoted diff) +0
-0}Thanks Andrew.
IS_ENABLED(CONFIG_CONDITION_COVERAGE)is not the same as #ifdefCONFIG_CONDITION_COVERAGE.
When the option is completely undefined,IS_ENABLED()returns 1 (enabled).
See our many other uses of IS_ENABLED(). If what you say was true, we'd have breakage for every one of those uses.
Jan
Quoted 3 lines · Jan Beulich
Quoted 1 line · Saman Dehghan
On Mon, Nov 24, 2025 at 5:15 AM Andrew Cooper <[email protected]>
Quoted 20 lines · wrote:
Quoted 20 lines
Quoted 20 lines · Saman Dehghan
xen/common/coverage/llvm.c extern uint64_t __stop___llvm_prf_cnts[]; · line 142
Quoted 13 lines
xen/common/coverage/llvm.c +5
-0@@ -127,16 +131,25 @@ extern uint64_t __stop___llvm_prf_cnts[];#define END_NAMES ((const void *)__stop___llvm_prf_names)#define START_COUNTERS ((void *)__start___llvm_prf_cnts)#define END_COUNTERS ((void *)__stop___llvm_prf_cnts) +#define START_BITMAP ((void *)__start___llvm_prf_bits) +#define END_BITMAP ((void *)__stop___llvm_prf_bits) static void cf_check reset_counters(void) {memset (START_COUNTERS ,0 ,END_COUNTERS -START_COUNTERS ); +#ifdef CONFIG_CONDITION_COVERAGE +memset (START_BITMAP ,0 ,END_BITMAP -START_BITMAP ); +#endif ... this:
if (
IS_ENABLED(CONFIG_CONDITION_COVERAGE))
memset(START_BITMAP, 0, END_BITMAP - START_BITMAP);
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Review extern uint64_t __stop___llvm_prf_cnts[]; · line 143
Quoted 1 line
(quoted diff) +0
-0}Thanks Andrew.
IS_ENABLED(CONFIG_CONDITION_COVERAGE)is not the same as #ifdefCONFIG_CONDITION_COVERAGE.
When the option is completely undefined,IS_ENABLED()returns 1
(enabled).
Quoted 2 lines
See our many other uses of
IS_ENABLED(). If what you say was true, we'd
have
Quoted 2 lines
breakage for every one of those uses.
Sorry, my bad. It works.
Quoted 1 line
Jan