update gcov info for newer versions of gcc
v2 cover update gcov info for newer versions of gcc
The gcov info changes with different versions of gcc. This patch series updates it so that we can capture coverage for xen built with newer compilers.
This doesn't solve all the problems with coverage as Xen still crashes when trying to reset/read coverage[0]. Still, it's a step forward.
[0] https://gitlab.com/xen-project/xen/-/issues/168
I have tested it with a workaround for the aforementioned bug (commenting out freeing of the init sections) and the following gcc versions:
- gcc 4.8.5
- gcc 4.9.4
- gcc 6.5.0
- gcc 7.5.0
- gcc 8.5.0
- gcc 9.5.0
- gcc 10.5.0
- gcc 11.4.0
- gcc 12.3.0
Javi Merino (2):
coverage: simplify the logic of choosing the number of gcov counters
depending on the gcc version
coverage: update gcov info for newer versions of gcc
xen/common/coverage/Makefile | 6 +----- xen/common/coverage/gcc_4_7.c | 39 ++++++++++++++++++++++++++--------- xen/common/coverage/gcc_4_9.c | 33 ----------------------------- xen/common/coverage/gcc_5.c | 33 ----------------------------- xen/common/coverage/gcc_7.c | 30 --------------------------- 5 files changed, 30 insertions(+), 111 deletions(-) delete mode 100644 xen/common/coverage/gcc_4_9.c delete mode 100644 xen/common/coverage/gcc_5.c delete mode 100644 xen/common/coverage/gcc_7.c
Signature · 1 line
2.41.0
PATCH v2 1/2 coverage: simplify the logic of choosing the number of gcov counters depending on the gcc version
The current structure of choosing the correct file based on the compiler version makes us make 33 line files just to define a constant. The changes after gcc 4.7 are minimal, just the number of counters.
Fold the changes in gcc_4_9.c, gcc_5.c and gcc_7.c into gcc_4_7.c to remove a lot of the boilerplate and keep the logic of choosing the GCOV_COUNTER in gcc_4_7.c.
--- xen/common/coverage/Makefile | 6 +----- xen/common/coverage/gcc_4_7.c | 17 +++++++++-------- xen/common/coverage/gcc_4_9.c | 33 --------------------------------- xen/common/coverage/gcc_5.c | 33 --------------------------------- xen/common/coverage/gcc_7.c | 30 ------------------------------ 5 files changed, 10 insertions(+), 109 deletions(-) delete mode 100644 xen/common/coverage/gcc_4_9.c delete mode 100644 xen/common/coverage/gcc_5.c delete mode 100644 xen/common/coverage/gcc_7.c
xen/common/coverage/Makefile +1 -5
@@ -1,11 +1,7 @@ obj-y += coverage.o ifneq ($(CONFIG_CC_IS_CLANG),y) obj-y += gcov_base.o gcov.o -obj-y += $(call cc-ifversion,-lt,0407, \ - gcc_3_4.o, $(call cc-ifversion,-lt,0409, \ - gcc_4_7.o, $(call cc-ifversion,-lt,0500, \ - gcc_4_9.o, $(call cc-ifversion,-lt,0700, \ - gcc_5.o, gcc_7.o)))) +obj-y += $(call cc-ifversion,-lt,0407, gcc_3_4.o, gcc_4_7.o) else obj-y += llvm.o endif
xen/common/coverage/gcc_4_7.c +9 -8
@@ -18,15 +18,16 @@#include "gcov.h" -/* -* GCOV_COUNTERS will be defined if this file is included by other -* source files. -*/ -#ifndef GCOV_COUNTERS -# if !(GCC_VERSION >=40700 &&GCC_VERSION <40900 ) -# error "Wrong version of GCC used to compile gcov" -# endif +#if (GCC_VERSION >=40700 &&GCC_VERSION <40900 )#define GCOV_COUNTERS 8 +#elif (GCC_VERSION >=40900 &&GCC_VERSION <50000 ) +#define GCOV_COUNTERS 9 +#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 +#define GCOV_COUNTERS 10 +#elif GCC_VERSION >=70000 +#define GCOV_COUNTERS 9 +#else +#error "Wrong version of GCC used to compile gcov"#endif #define GCOV_TAG_FUNCTION_LENGTH 3
xen/common/coverage/gcc_4_9.c deleted +0 -33
@@ -1,33 +0,0 @@ -/* -* This code provides functions to handle gcc's profiling data format -* introduced with gcc 4.7. -* -* For a better understanding, refer to gcc source: -* gcc/gcov-io.h -* libgcc/libgcov.c -* -* Uses gcc-internal data definitions. -* -* Imported from Linux and modified for Xen by -* Wei Liu <[email protected]> -*/ - -#include "gcov.h" - -#if !(GCC_VERSION >=40900 &&GCC_VERSION <50000 ) -#error "Wrong version of GCC used to compile gcov" -#endif - -#define GCOV_COUNTERS 9 - -#include "gcc_4_7.c" - -/* -* Local variables: -* mode: C -* c-file-style: "BSD" -* c-basic-offset: 4 -* tab-width: 4 -* indent-tabs-mode: nil -* End: -*/
xen/common/coverage/gcc_5.c deleted +0 -33
@@ -1,33 +0,0 @@ -/* -* This code provides functions to handle gcc's profiling data format -* introduced with gcc 5. -* -* For a better understanding, refer to gcc source: -* gcc/gcov-io.h -* libgcc/libgcov.c -* -* Uses gcc-internal data definitions. -* -* Imported from Linux and modified for Xen by -* Wei Liu <[email protected]> -*/ - -#include "gcov.h" - -#if GCC_VERSION <50000 ||GCC_VERSION >=70000 -#error "Wrong version of GCC used to compile gcov" -#endif - -#define GCOV_COUNTERS 10 - -#include "gcc_4_7.c" - -/* -* Local variables: -* mode: C -* c-file-style: "BSD" -* c-basic-offset: 4 -* tab-width: 4 -* indent-tabs-mode: nil -* End: -*/
xen/common/coverage/gcc_7.c deleted +0 -30
@@ -1,30 +0,0 @@ -/* -* This code provides functions to handle gcc's profiling data format -* introduced with gcc 7. -* -* For a better understanding, refer to gcc source: -* gcc/gcov-io.h -* libgcc/libgcov.c -* -* Uses gcc-internal data definitions. -*/ - -#include "gcov.h" - -#if GCC_VERSION <70000 -#error "Wrong version of GCC used to compile gcov" -#endif - -#define GCOV_COUNTERS 9 - -#include "gcc_4_7.c" - -/* -* Local variables: -* mode: C -* c-file-style: "BSD" -* c-basic-offset: 4 -* tab-width: 4 -* indent-tabs-mode: nil -* End: -*/
Signature · 1 line
2.41.0
PATCH v2 2/2 coverage: update gcov info for newer versions of gcc
In reply to Javi MerinoShamelessly copy changes to gcov_info structures from linux so that we can capture coverage for xen built with newer compilers.
--- xen/common/coverage/gcc_4_7.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
xen/common/coverage/gcc_4_7.c +21 -3
@@ -24,14 +24,23 @@#define GCOV_COUNTERS 9#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 #define GCOV_COUNTERS 10 -#elif GCC_VERSION >=70000 +#elif GCC_VERSION >=70000 &&GCC_VERSION <100000 #define GCOV_COUNTERS 9 +#elif GCC_VERSION >=100000 +#define GCOV_COUNTERS 8#else #error "Wrong version of GCC used to compile gcov"#endif #define GCOV_TAG_FUNCTION_LENGTH 3 +#if GCC_VERSION >=120000 +/* Since GCC 12.1, sizes are in BYTES and not in WORDS (4B). */ +#define GCOV_UNIT_SIZE 4 +#else +#define GCOV_UNIT_SIZE 1 +#endif +static struct gcov_info *gcov_info_head;/**
@@ -89,6 +98,10 @@ struct gcov_info {unsigned int version;struct gcov_info *next;unsigned int stamp; +#if (GCC_VERSION >=120000 ) +/* GCC 12.1 introduced a checksum field */ +unsigned int checksum; +#endif const char *filename;void (*merge[GCOV_COUNTERS ])(gcov_type *,unsigned int );unsigned int n_functions;
@@ -161,13 +174,18 @@ size_t gcov_info_to_gcda(char *buffer, const struct gcov_info *info) pos +=gcov_store_uint32 (buffer, pos, info->version); pos +=gcov_store_uint32 (buffer, pos, info->stamp); +#if (GCC_VERSION >=120000 ) +/* Use zero as checksum of the compilation unit. */ + pos +=gcov_store_uint32 (buffer, pos,0 ); +#endif +for ( fi_idx =0 ; fi_idx < info->n_functions; fi_idx++ ) { fi_ptr = info->functions[fi_idx];/* Function record. */ pos +=gcov_store_uint32 (buffer, pos,GCOV_TAG_FUNCTION ); - pos +=gcov_store_uint32 (buffer, pos,GCOV_TAG_FUNCTION_LENGTH ); + pos +=gcov_store_uint32 (buffer, pos,GCOV_TAG_FUNCTION_LENGTH *GCOV_UNIT_SIZE ); pos +=gcov_store_uint32 (buffer, pos, fi_ptr->ident); pos +=gcov_store_uint32 (buffer, pos, fi_ptr->lineno_checksum); pos +=gcov_store_uint32 (buffer, pos, fi_ptr->cfg_checksum);
@@ -182,7 +200,7 @@ size_t gcov_info_to_gcda(char *buffer, const struct gcov_info *info)/* Counter record. */ pos +=gcov_store_uint32 (buffer, pos,GCOV_TAG_FOR_COUNTER (ct_idx)); - pos +=gcov_store_uint32 (buffer, pos, ci_ptr->num *2 ); + pos +=gcov_store_uint32 (buffer, pos, ci_ptr->num *2 *GCOV_UNIT_SIZE );for ( cv_idx =0 ; cv_idx < ci_ptr->num; cv_idx++ ) pos +=gcov_store_uint64 (buffer, pos, ci_ptr->values[cv_idx]);
Signature · 1 line
2.41.0
Re: [XEN PATCH v2 1/2] coverage: simplify the logic of choosing the number of gcov counters depending on the gcc version
In reply to Javi MerinoQuoted 55 lines · Javi Merino
The current structure of choosing the correct file based on the compiler version makes us make 33 line files just to define a constant. The changes after gcc 4.7 are minimal, just the number of counters.
Fold the changes in
gcc_4_9.c,gcc_5.candgcc_7.cintogcc_4_7.cto remove a lot of the boilerplate and keep the logic of choosing theGCOV_COUNTERingcc_4_7.c.Signed-off-by Javi Merino <[email protected]>--- xen/common/coverage/Makefile | 6 +----- xen/common/coverage/gcc_4_7.c | 17 +++++++++-------- xen/common/coverage/gcc_4_9.c | 33 --------------------------------- xen/common/coverage/gcc_5.c | 33 --------------------------------- xen/common/coverage/gcc_7.c | 30 ------------------------------ 5 files changed, 10 insertions(+), 109 deletions(-) delete mode 100644 xen/common/coverage/gcc_4_9.c delete mode 100644 xen/common/coverage/gcc_5.c delete mode 100644 xen/common/coverage/gcc_7.cxen/common/coverage/Makefile +1
-5@@ -1,11 +1,7 @@ obj-y += coverage.o ifneq ($(CONFIG_CC_IS_CLANG),y) obj-y += gcov_base.o gcov.o -obj-y += $(call cc-ifversion,-lt,0407, \ - gcc_3_4.o, $(call cc-ifversion,-lt,0409, \ - gcc_4_7.o, $(call cc-ifversion,-lt,0500, \ - gcc_4_9.o, $(call cc-ifversion,-lt,0700, \ - gcc_5.o, gcc_7.o)))) +obj-y += $(call cc-ifversion,-lt,0407, gcc_3_4.o, gcc_4_7.o) else obj-y += llvm.o endifxen/common/coverage/gcc_4_7.c +1
-8@@ -18,15 +18,16 @@#include "gcov.h" -/* -* GCOV_COUNTERS will be defined if this file is included by other -* source files. -*/ -#ifndef GCOV_COUNTERS -# if !(GCC_VERSION >=40700 &&GCC_VERSION <40900 ) -# error "Wrong version of GCC used to compile gcov" -# endif +#if (GCC_VERSION >=40700 &&GCC_VERSION <40900 )
xen/common/coverage/gcc_4_7.c line 31
Quoted 10 lines
xen/common/coverage/gcc_4_7.c +8
-0#define GCOV_COUNTERS 8 +#elif (GCC_VERSION >=40900 &&GCC_VERSION <50000 ) +#define GCOV_COUNTERS 9 +#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 +#define GCOV_COUNTERS 10 +#elif GCC_VERSION >=70000 +#define GCOV_COUNTERS 9 +#else +#error "Wrong version of GCC used to compile gcov"#endif
How about inverse order:
#if GCC_VERSION >= 70000
#define GCOV_COUNTERS 9
#elif GCC_VERSION >= 50000
#define GCOV_COUNTERS 10
#elif GCC_VERSION >= 40900
#define GCOV_COUNTERS 9
#elif GCC_VERSION >= 40700
#define GCOV_COUNTERS 8
#else
#error "Wrong version of GCC used to compile gcov" #endif
Otherwise a nit and a question: Parentheses would want using consistently. And wouldn't it make sense to combine the two ranges resulting in 9 being chosen? (Imo in the alternative layout that's less desirable.)
Since the adjustment would be easy to make, I'd be fine doing so while committing, and then
As an unrelated remark: gcc_3_4.c is clearly outdated as well, simply by its name. Imo it would have wanted to be gcc_4_1.c the latest as of commit 03f22f0070f3 ("README: adjust gcc version requirement"), i.e. for over 10 years.
Jan
Re: [XEN PATCH v2 2/2] coverage: update gcov info for newer versions of gcc
In reply to Javi MerinoQuoted 14 lines · Javi Merino
Shamelessly copy changes to
gcov_infostructures from linux so that we can capture coverage for xen built with newer compilers.Signed-off-by Javi Merino <[email protected]>--- xen/common/coverage/gcc_4_7.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)xen/common/coverage/gcc_4_7.c +0
-0@@ -24,14 +24,23 @@#define GCOV_COUNTERS 9
xen/common/coverage/gcc_4_7.c line 33
Quoted 10 lines
xen/common/coverage/gcc_4_7.c +3
-1#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 #define GCOV_COUNTERS 10 -#elif GCC_VERSION >=70000 +#elif GCC_VERSION >=70000 &&GCC_VERSION <100000 #define GCOV_COUNTERS 9 +#elif GCC_VERSION >=100000 +#define GCOV_COUNTERS 8#else #error "Wrong version of GCC used to compile gcov"#endif
This would need adjustment if patch 1 is adjusted as suggested, then ...
xen/common/coverage/gcc_4_7.c line 42
Quoted 8 lines
xen/common/coverage/gcc_4_7.c +6
-0#define GCOV_TAG_FUNCTION_LENGTH 3 +#if GCC_VERSION >=120000 +/* Since GCC 12.1, sizes are in BYTES and not in WORDS (4B). */ +#define GCOV_UNIT_SIZE 4 +#else +#define GCOV_UNIT_SIZE 1 +#endif
... making the earlier group also match this one (which already works downwards in version number space).
As to the comments (here and below): Since the version check is for 12.0, may I suggest to simply say "gcc 12" everywhere?
xen/common/coverage/gcc_4_7.c struct gcov_info { · line 101
Quoted 5 lines
xen/common/coverage/gcc_4_7.c +1
-0@@ -89,6 +98,10 @@ struct gcov_info {unsigned int version;struct gcov_info *next;unsigned int stamp; +#if (GCC_VERSION >=120000 )
Nit: Here any below parentheses likely want omitting, to match there being none further up. Preferably with the adjustments (which again I'd be okay doing while committing, so long as you agree)
Jan
Re: [XEN PATCH v2 1/2] coverage: simplify the logic of choosing the number of gcov counters depending on the gcc version
In reply to Jan BeulichQuoted 81 lines · Jan Beulich
Quoted 55 lines · Javi Merino
The current structure of choosing the correct file based on the compiler version makes us make 33 line files just to define a constant. The changes after gcc 4.7 are minimal, just the number of counters.
Fold the changes in
gcc_4_9.c,gcc_5.candgcc_7.cintogcc_4_7.cto remove a lot of the boilerplate and keep the logic of choosing theGCOV_COUNTERingcc_4_7.c.Signed-off-by Javi Merino <[email protected]>--- xen/common/coverage/Makefile | 6 +----- xen/common/coverage/gcc_4_7.c | 17 +++++++++-------- xen/common/coverage/gcc_4_9.c | 33 --------------------------------- xen/common/coverage/gcc_5.c | 33 --------------------------------- xen/common/coverage/gcc_7.c | 30 ------------------------------ 5 files changed, 10 insertions(+), 109 deletions(-) delete mode 100644 xen/common/coverage/gcc_4_9.c delete mode 100644 xen/common/coverage/gcc_5.c delete mode 100644 xen/common/coverage/gcc_7.cxen/common/coverage/Makefile +1
-5@@ -1,11 +1,7 @@ obj-y += coverage.o ifneq ($(CONFIG_CC_IS_CLANG),y) obj-y += gcov_base.o gcov.o -obj-y += $(call cc-ifversion,-lt,0407, \ - gcc_3_4.o, $(call cc-ifversion,-lt,0409, \ - gcc_4_7.o, $(call cc-ifversion,-lt,0500, \ - gcc_4_9.o, $(call cc-ifversion,-lt,0700, \ - gcc_5.o, gcc_7.o)))) +obj-y += $(call cc-ifversion,-lt,0407, gcc_3_4.o, gcc_4_7.o) else obj-y += llvm.o endifxen/common/coverage/gcc_4_7.c +1
-8@@ -18,15 +18,16 @@#include "gcov.h" -/* -* GCOV_COUNTERS will be defined if this file is included by other -* source files. -*/ -#ifndef GCOV_COUNTERS -# if !(GCC_VERSION >=40700 &&GCC_VERSION <40900 ) -# error "Wrong version of GCC used to compile gcov" -# endif +#if (GCC_VERSION >=40700 &&GCC_VERSION <40900 )xen/common/coverage/gcc_4_7.c line 31
Quoted 10 lines
xen/common/coverage/gcc_4_7.c +8
-0#define GCOV_COUNTERS 8 +#elif (GCC_VERSION >=40900 &&GCC_VERSION <50000 ) +#define GCOV_COUNTERS 9 +#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 +#define GCOV_COUNTERS 10 +#elif GCC_VERSION >=70000 +#define GCOV_COUNTERS 9 +#else +#error "Wrong version of GCC used to compile gcov"#endif How about inverse order:
#if
GCC_VERSION>= 70000
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 50000
#defineGCOV_COUNTERS10
#elifGCC_VERSION>= 40900
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 40700
#defineGCOV_COUNTERS8
#else
#error "Wrong version of GCC used to compile gcov" #endif
Quoted 1 line
Otherwise a nit and a question: Parentheses would want using consistently.
True, the parenthesis are unnecessary and inconsistent in the patch.
Quoted 6 lines
And wouldn't it make sense to combine the two ranges resulting in 9 being chosen? (Imo in the alternative layout that's less desirable.)
Since the adjustment would be easy to make, I'd be fine doing so while committing, and then
Reviewed-by Jan Beulich <[email protected]>
Happy for you to do the changes. Or I can do it and fix the next patch as well.
Cheers,
Javi
Quoted 6 lines
As an unrelated remark:
gcc_3_4.cis clearly outdated as well, simply by its name. Imo it would have wanted to begcc_4_1.cthe latest as of commit03f22f0070f3("README: adjust gcc version requirement"), i.e. for over 10 years.Jan
Re: [XEN PATCH v2 2/2] coverage: update gcov info for newer versions of gcc
In reply to Jan BeulichQuoted 30 lines · Jan Beulich
Quoted 14 lines · Javi Merino
Shamelessly copy changes to
gcov_infostructures from linux so that we can capture coverage for xen built with newer compilers.Signed-off-by Javi Merino <[email protected]>--- xen/common/coverage/gcc_4_7.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)xen/common/coverage/gcc_4_7.c +0
-0@@ -24,14 +24,23 @@#define GCOV_COUNTERS 9xen/common/coverage/gcc_4_7.c line 33
Quoted 10 lines
xen/common/coverage/gcc_4_7.c +3
-1#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 #define GCOV_COUNTERS 10 -#elif GCC_VERSION >=70000 +#elif GCC_VERSION >=70000 &&GCC_VERSION <100000 #define GCOV_COUNTERS 9 +#elif GCC_VERSION >=100000 +#define GCOV_COUNTERS 8#else #error "Wrong version of GCC used to compile gcov"#endif This would need adjustment if patch 1 is adjusted as suggested, then ...
Quoted 2 lines
xen/common/coverage/gcc_4_7.c +0
-0#define GCOV_TAG_FUNCTION_LENGTH 3
Quoted 9 lines
xen/common/coverage/gcc_4_7.c line 42
Quoted 6 lines
xen/common/coverage/gcc_4_7.c +6
-0+#if GCC_VERSION >=120000 +/* Since GCC 12.1, sizes are in BYTES and not in WORDS (4B). */ +#define GCOV_UNIT_SIZE 4 +#else +#define GCOV_UNIT_SIZE 1 +#endif ... making the earlier group also match this one (which already works downwards in version number space).
True
Quoted 12 lines
As to the comments (here and below): Since the version check is for 12.0, may I suggest to simply say "gcc 12" everywhere?
xen/common/coverage/gcc_4_7.c struct gcov_info { · line 101
Quoted 5 lines
xen/common/coverage/gcc_4_7.c +1
-0@@ -89,6 +98,10 @@ struct gcov_info {unsigned int version;struct gcov_info *next;unsigned int stamp; +#if (GCC_VERSION >=120000 )Nit: Here any below parentheses likely want omitting, to match there being none further up. Preferably with the adjustments (which again I'd be okay doing while committing, so long as you agree)
Quoted 1 line
Acked-by Jan Beulich <[email protected]>
I'm ok with those changes and I'm fine with you doing them.
Cheers,
Javi
Re: [XEN PATCH v2 1/2] coverage: simplify the logic of choosing the number of gcov counters depending on the gcc version
In reply to Jan BeulichQuoted 68 lines · Jan Beulich
Quoted 55 lines · Javi Merino
The current structure of choosing the correct file based on the compiler version makes us make 33 line files just to define a constant. The changes after gcc 4.7 are minimal, just the number of counters.
Fold the changes in
gcc_4_9.c,gcc_5.candgcc_7.cintogcc_4_7.cto remove a lot of the boilerplate and keep the logic of choosing theGCOV_COUNTERingcc_4_7.c.Signed-off-by Javi Merino <[email protected]>--- xen/common/coverage/Makefile | 6 +----- xen/common/coverage/gcc_4_7.c | 17 +++++++++-------- xen/common/coverage/gcc_4_9.c | 33 --------------------------------- xen/common/coverage/gcc_5.c | 33 --------------------------------- xen/common/coverage/gcc_7.c | 30 ------------------------------ 5 files changed, 10 insertions(+), 109 deletions(-) delete mode 100644 xen/common/coverage/gcc_4_9.c delete mode 100644 xen/common/coverage/gcc_5.c delete mode 100644 xen/common/coverage/gcc_7.cxen/common/coverage/Makefile +1
-5@@ -1,11 +1,7 @@ obj-y += coverage.o ifneq ($(CONFIG_CC_IS_CLANG),y) obj-y += gcov_base.o gcov.o -obj-y += $(call cc-ifversion,-lt,0407, \ - gcc_3_4.o, $(call cc-ifversion,-lt,0409, \ - gcc_4_7.o, $(call cc-ifversion,-lt,0500, \ - gcc_4_9.o, $(call cc-ifversion,-lt,0700, \ - gcc_5.o, gcc_7.o)))) +obj-y += $(call cc-ifversion,-lt,0407, gcc_3_4.o, gcc_4_7.o) else obj-y += llvm.o endifxen/common/coverage/gcc_4_7.c +1
-8@@ -18,15 +18,16 @@#include "gcov.h" -/* -* GCOV_COUNTERS will be defined if this file is included by other -* source files. -*/ -#ifndef GCOV_COUNTERS -# if !(GCC_VERSION >=40700 &&GCC_VERSION <40900 ) -# error "Wrong version of GCC used to compile gcov" -# endif +#if (GCC_VERSION >=40700 &&GCC_VERSION <40900 )xen/common/coverage/gcc_4_7.c line 31
Quoted 10 lines
xen/common/coverage/gcc_4_7.c +8
-0#define GCOV_COUNTERS 8 +#elif (GCC_VERSION >=40900 &&GCC_VERSION <50000 ) +#define GCOV_COUNTERS 9 +#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 +#define GCOV_COUNTERS 10 +#elif GCC_VERSION >=70000 +#define GCOV_COUNTERS 9 +#else +#error "Wrong version of GCC used to compile gcov"#endif How about inverse order:
Quoted 11 lines
#if
GCC_VERSION>= 70000
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 50000
#defineGCOV_COUNTERS10
#elifGCC_VERSION>= 40900
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 40700
#defineGCOV_COUNTERS8
#else
#error "Wrong version of GCC used to compile gcov" #endif
Forward order is the one that results in a smaller diff when inserting new entries.
More importantly, it's the more natural way to structure such a list.
~Andrew
Re: [XEN PATCH v2 1/2] coverage: simplify the logic of choosing the number of gcov counters depending on the gcc version
Quoted 81 lines · Andrew Cooper
Quoted 68 lines · Jan Beulich
Quoted 55 lines · Javi Merino
The current structure of choosing the correct file based on the compiler version makes us make 33 line files just to define a constant. The changes after gcc 4.7 are minimal, just the number of counters.
Fold the changes in
gcc_4_9.c,gcc_5.candgcc_7.cintogcc_4_7.cto remove a lot of the boilerplate and keep the logic of choosing theGCOV_COUNTERingcc_4_7.c.Signed-off-by Javi Merino <[email protected]>--- xen/common/coverage/Makefile | 6 +----- xen/common/coverage/gcc_4_7.c | 17 +++++++++-------- xen/common/coverage/gcc_4_9.c | 33 --------------------------------- xen/common/coverage/gcc_5.c | 33 --------------------------------- xen/common/coverage/gcc_7.c | 30 ------------------------------ 5 files changed, 10 insertions(+), 109 deletions(-) delete mode 100644 xen/common/coverage/gcc_4_9.c delete mode 100644 xen/common/coverage/gcc_5.c delete mode 100644 xen/common/coverage/gcc_7.cxen/common/coverage/Makefile +1
-5@@ -1,11 +1,7 @@ obj-y += coverage.o ifneq ($(CONFIG_CC_IS_CLANG),y) obj-y += gcov_base.o gcov.o -obj-y += $(call cc-ifversion,-lt,0407, \ - gcc_3_4.o, $(call cc-ifversion,-lt,0409, \ - gcc_4_7.o, $(call cc-ifversion,-lt,0500, \ - gcc_4_9.o, $(call cc-ifversion,-lt,0700, \ - gcc_5.o, gcc_7.o)))) +obj-y += $(call cc-ifversion,-lt,0407, gcc_3_4.o, gcc_4_7.o) else obj-y += llvm.o endifxen/common/coverage/gcc_4_7.c +1
-8@@ -18,15 +18,16 @@#include "gcov.h" -/* -* GCOV_COUNTERS will be defined if this file is included by other -* source files. -*/ -#ifndef GCOV_COUNTERS -# if !(GCC_VERSION >=40700 &&GCC_VERSION <40900 ) -# error "Wrong version of GCC used to compile gcov" -# endif +#if (GCC_VERSION >=40700 &&GCC_VERSION <40900 )xen/common/coverage/gcc_4_7.c line 31
Quoted 10 lines
xen/common/coverage/gcc_4_7.c +8
-0#define GCOV_COUNTERS 8 +#elif (GCC_VERSION >=40900 &&GCC_VERSION <50000 ) +#define GCOV_COUNTERS 9 +#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 +#define GCOV_COUNTERS 10 +#elif GCC_VERSION >=70000 +#define GCOV_COUNTERS 9 +#else +#error "Wrong version of GCC used to compile gcov"#endif How about inverse order:
Quoted 11 lines
#if
GCC_VERSION>= 70000
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 50000
#defineGCOV_COUNTERS10
#elifGCC_VERSION>= 40900
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 40700
#defineGCOV_COUNTERS8
#else
#error "Wrong version of GCC used to compile gcov" #endif
Quoted 2 lines
Forward order is the one that results in a smaller diff when inserting new entries.
Hmm, even in forward order one prior #elif will need touching (to amend the version check), so I'm afraid I don't see such a diff being smaller (it's uniformly -1/+3 afaict).
Quoted 1 line
More importantly, it's the more natural way to structure such a list.
I would say multiple views are possible: Naming recent compiler versions first may also be viewed as beneficial. In the end what counts is how easy it is to follow the overall construct. And I'm pretty sure less complex expressions help there.
Jan
Re: [XEN PATCH v2 1/2] coverage: simplify the logic of choosing the number of gcov counters depending on the gcc version
Quoted 81 lines · Jan Beulich
Quoted 80 lines · Andrew Cooper
Quoted 79 lines · Jan Beulich
Quoted 55 lines · Javi Merino
The current structure of choosing the correct file based on the compiler version makes us make 33 line files just to define a constant. The changes after gcc 4.7 are minimal, just the number of counters.
Fold the changes in
gcc_4_9.c,gcc_5.candgcc_7.cintogcc_4_7.cto remove a lot of the boilerplate and keep the logic of choosing theGCOV_COUNTERingcc_4_7.c.Signed-off-by Javi Merino <[email protected]>--- xen/common/coverage/Makefile | 6 +----- xen/common/coverage/gcc_4_7.c | 17 +++++++++-------- xen/common/coverage/gcc_4_9.c | 33 --------------------------------- xen/common/coverage/gcc_5.c | 33 --------------------------------- xen/common/coverage/gcc_7.c | 30 ------------------------------ 5 files changed, 10 insertions(+), 109 deletions(-) delete mode 100644 xen/common/coverage/gcc_4_9.c delete mode 100644 xen/common/coverage/gcc_5.c delete mode 100644 xen/common/coverage/gcc_7.cxen/common/coverage/Makefile +1
-5@@ -1,11 +1,7 @@ obj-y += coverage.o ifneq ($(CONFIG_CC_IS_CLANG),y) obj-y += gcov_base.o gcov.o -obj-y += $(call cc-ifversion,-lt,0407, \ - gcc_3_4.o, $(call cc-ifversion,-lt,0409, \ - gcc_4_7.o, $(call cc-ifversion,-lt,0500, \ - gcc_4_9.o, $(call cc-ifversion,-lt,0700, \ - gcc_5.o, gcc_7.o)))) +obj-y += $(call cc-ifversion,-lt,0407, gcc_3_4.o, gcc_4_7.o) else obj-y += llvm.o endifxen/common/coverage/gcc_4_7.c +1
-8@@ -18,15 +18,16 @@#include "gcov.h" -/* -* GCOV_COUNTERS will be defined if this file is included by other -* source files. -*/ -#ifndef GCOV_COUNTERS -# if !(GCC_VERSION >=40700 &&GCC_VERSION <40900 ) -# error "Wrong version of GCC used to compile gcov" -# endif +#if (GCC_VERSION >=40700 &&GCC_VERSION <40900 )xen/common/coverage/gcc_4_7.c line 31
Quoted 10 lines
xen/common/coverage/gcc_4_7.c +8
-0#define GCOV_COUNTERS 8 +#elif (GCC_VERSION >=40900 &&GCC_VERSION <50000 ) +#define GCOV_COUNTERS 9 +#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 +#define GCOV_COUNTERS 10 +#elif GCC_VERSION >=70000 +#define GCOV_COUNTERS 9 +#else +#error "Wrong version of GCC used to compile gcov"#endif How about inverse order:
#if
GCC_VERSION>= 70000
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 50000
#defineGCOV_COUNTERS10
#elifGCC_VERSION>= 40900
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 40700
#defineGCOV_COUNTERS8
#else
#error "Wrong version of GCC used to compile gcov" #endif
Quoted 3 lines
Quoted 2 lines
Forward order is the one that results in a smaller diff when inserting new entries.
Hmm, even in forward order one prior #elif will need touching
#if GCC_VERSION < 40700
#define GCOV_COUNTERS 8
#elif GCC_VERSION < 40900
#define GCOV_COUNTERS 9
#elif GCC_VERSION < 50000
#define GCOV_COUNTERS 10
#elif GCC_VERSION < 70000
#define GCOV_COUNTERS 9
+#elif GCC_VERSION < FOO
+#define GCOV_COUNTERS BAR
#else
#error "Wrong version of GCC used to compile gcov" #endif
~Andrew
Re: [XEN PATCH v2 1/2] coverage: simplify the logic of choosing the number of gcov counters depending on the gcc version
Quoted 96 lines · Andrew Cooper
Quoted 81 lines · Jan Beulich
Quoted 80 lines · Andrew Cooper
Quoted 79 lines · Jan Beulich
Quoted 55 lines · Javi Merino
The current structure of choosing the correct file based on the compiler version makes us make 33 line files just to define a constant. The changes after gcc 4.7 are minimal, just the number of counters.
Fold the changes in
gcc_4_9.c,gcc_5.candgcc_7.cintogcc_4_7.cto remove a lot of the boilerplate and keep the logic of choosing theGCOV_COUNTERingcc_4_7.c.Signed-off-by Javi Merino <[email protected]>--- xen/common/coverage/Makefile | 6 +----- xen/common/coverage/gcc_4_7.c | 17 +++++++++-------- xen/common/coverage/gcc_4_9.c | 33 --------------------------------- xen/common/coverage/gcc_5.c | 33 --------------------------------- xen/common/coverage/gcc_7.c | 30 ------------------------------ 5 files changed, 10 insertions(+), 109 deletions(-) delete mode 100644 xen/common/coverage/gcc_4_9.c delete mode 100644 xen/common/coverage/gcc_5.c delete mode 100644 xen/common/coverage/gcc_7.cxen/common/coverage/Makefile +1
-5@@ -1,11 +1,7 @@ obj-y += coverage.o ifneq ($(CONFIG_CC_IS_CLANG),y) obj-y += gcov_base.o gcov.o -obj-y += $(call cc-ifversion,-lt,0407, \ - gcc_3_4.o, $(call cc-ifversion,-lt,0409, \ - gcc_4_7.o, $(call cc-ifversion,-lt,0500, \ - gcc_4_9.o, $(call cc-ifversion,-lt,0700, \ - gcc_5.o, gcc_7.o)))) +obj-y += $(call cc-ifversion,-lt,0407, gcc_3_4.o, gcc_4_7.o) else obj-y += llvm.o endifxen/common/coverage/gcc_4_7.c +1
-8@@ -18,15 +18,16 @@#include "gcov.h" -/* -* GCOV_COUNTERS will be defined if this file is included by other -* source files. -*/ -#ifndef GCOV_COUNTERS -# if !(GCC_VERSION >=40700 &&GCC_VERSION <40900 ) -# error "Wrong version of GCC used to compile gcov" -# endif +#if (GCC_VERSION >=40700 &&GCC_VERSION <40900 )xen/common/coverage/gcc_4_7.c line 31
Quoted 10 lines
xen/common/coverage/gcc_4_7.c +8
-0#define GCOV_COUNTERS 8 +#elif (GCC_VERSION >=40900 &&GCC_VERSION <50000 ) +#define GCOV_COUNTERS 9 +#elif GCC_VERSION >=50000 &&GCC_VERSION <70000 +#define GCOV_COUNTERS 10 +#elif GCC_VERSION >=70000 +#define GCOV_COUNTERS 9 +#else +#error "Wrong version of GCC used to compile gcov"#endif How about inverse order:
#if
GCC_VERSION>= 70000
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 50000
#defineGCOV_COUNTERS10
#elifGCC_VERSION>= 40900
#defineGCOV_COUNTERS9
#elifGCC_VERSION>= 40700
#defineGCOV_COUNTERS8
#else
#error "Wrong version of GCC used to compile gcov" #endifQuoted 3 lines
Quoted 2 lines
Forward order is the one that results in a smaller diff when inserting new entries.
Hmm, even in forward order one prior #elif will need touching
#if
GCC_VERSION< 40700
#defineGCOV_COUNTERS8
#elifGCC_VERSION< 40900
#defineGCOV_COUNTERS9
#elifGCC_VERSION< 50000
#defineGCOV_COUNTERS10
#elifGCC_VERSION< 70000
#defineGCOV_COUNTERS9(quoted diff) +2
-0+#elif GCC_VERSION < FOO +#define GCOV_COUNTERS BAR
Quoted 3 lines
#else
#error "Wrong version of GCC used to compile gcov" #endif
But that doesn't achieve the same as the other construct: No #error for gcc earlier than 4.7, and your (presumed; i.e. taking just patch context without the two added lines) construct would fail to build for gcc 7. We want an open upper bound but a determined lower one.
Jan