diff options
author | Denis Ovsienko <denis@ovsienko.info> | 2021-07-27 14:06:28 +0100 |
---|---|---|
committer | Denis Ovsienko <denis@ovsienko.info> | 2021-07-27 14:24:01 +0100 |
commit | c3c949e98e9d046a2017a122ba869c89329acdd1 (patch) | |
tree | 3952e31733037b8dcd26cb3eaba5cd0fbebd972c | |
parent | d3312a6438748730f40e4fd3cbd0dfc56ae16c54 (diff) | |
download | tcpdump-c3c949e98e9d046a2017a122ba869c89329acdd1.tar.gz |
Address some issues with XL C on Linux/POWER9.
XL C 16.1.1 Community Edition for Linux generated three warnings for
every file:
In file included from ./tcpdump.c:155:
./netdissect.h:254:8: warning: 1540-2990 The attribute
"__attribute__((format(printf, 2, 3)))" is not supported. The
attribute is ignored.
PRINTFLIKE_FUNCPTR(2, 3);
^
./netdissect.h:259:10: warning: 1540-2990 The attribute
" __attribute__((format(printf, 3, 4)))" is not supported.
The attribute is ignored.
PRINTFLIKE_FUNCPTR(3, 4);
^
./netdissect.h:263:9: warning: 1540-2990 The attribute
" __attribute__((format(printf, 2, 3)))" is not supported. The
attribute is ignored.
PRINTFLIKE_FUNCPTR(2, 3);
^
As it turns out, this is a bug in the compiler. In compiler-tests.h
update ND_IS_AT_LEAST_XL_C_VERSION() to tell newer XL C versions. In
funcattrs.h exempt XL C 16.1 from PRINTFLIKE_FUNCPTR().
In the course of preparing these changes notice that XL C uses the Clang
block in diag-control.h (XL C mimics both Clang and GCC to some extent),
although the behaviour is different between the two compilers. Add a new
block for XL C there.
In build_common.sh add more comments to explain XL C quirks and detect
XL C for Linux too so it receives the right CFLAGS. Update CHANGES to
mention this and earlier improvements.
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | build_common.sh | 13 | ||||
-rw-r--r-- | compiler-tests.h | 9 | ||||
-rw-r--r-- | diag-control.h | 20 | ||||
-rw-r--r-- | funcattrs.h | 6 |
5 files changed, 43 insertions, 6 deletions
@@ -24,6 +24,7 @@ Monthday, Month DD, YYYY by gharris and denis Handle some Autoconf/make errors better. Fix "make releasetar" on AIX and Solaris. Mend "make check" on Solaris 9 with Autoconf. + Address assorted compiler warnings. Wednesday, June 9, 2021 by gharris Summary for 4.99.1 tcpdump release diff --git a/build_common.sh b/build_common.sh index 794ec2c6..8ace59e4 100644 --- a/build_common.sh +++ b/build_common.sh @@ -74,9 +74,12 @@ print_cc_version() { "$CC" --version ;; xl*) - # XL C for AIX recognizes -qversion, prints to stdout and exits with 0, - # but on an unknown command-line flag displays its man page and waits. - "$CC" -qversion + # XL C 12.1 and 13.1 recognize "-qversion", print to stdout and exit + # with 0. XL C 12.1 on an unknown command-line flag displays its man + # page and waits. + # XL C 16.1 recognizes "-qversion" and "--version", prints to stdout + # and exits with 0. Community Edition also prints a banner to stderr. + "$CC" -qversion 2>/dev/null ;; sun*) # Sun compilers recognize -V, print to stderr and exit with an error. @@ -116,7 +119,7 @@ cc_id() { return fi - cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^IBM XL C.* for AIX, V\([0-9\.]*\).*$/xlc-\1/'` + cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^IBM XL C.*, V\([0-9\.]*\).*$/xlc-\1/'` if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then echo "$cc_id_guessed" return @@ -144,6 +147,8 @@ cc_werr_cflags() { echo '-Werror' ;; xlc-*) + # XL C 12.1 and 13.1 recognize "-qhalt=w". XL C 16.1 recognizes that + # and "-Werror". echo '-qhalt=w' ;; suncc-*) diff --git a/compiler-tests.h b/compiler-tests.h index 8b1a2331..d9cf81f0 100644 --- a/compiler-tests.h +++ b/compiler-tests.h @@ -133,12 +133,21 @@ * * The version number in __xlC__ has the major version in the * upper 8 bits and the minor version in the lower 8 bits. + * On AIX __xlC__ is always defined, __ibmxl__ becomes defined in XL C 16.1. + * On Linux since XL C 13.1.6 __xlC__ is not defined by default anymore, but + * __ibmxl__ is defined since at least XL C 13.1.1. */ #if ! defined(__xlC__) +#if ! defined(__ibmxl__) #define ND_IS_AT_LEAST_XL_C_VERSION(major,minor) 0 #else #define ND_IS_AT_LEAST_XL_C_VERSION(major, minor) \ + (__ibmxl_version__ > (major) || \ + (__ibmxl_version__ == (major) && __ibmxl_release__ >= (minor))) +#endif /* ! __ibmxl__ */ +#else /* ! __xlC__ */ +#define ND_IS_AT_LEAST_XL_C_VERSION(major, minor) \ (__xlC__ >= (((major) << 8) | (minor))) #endif diff --git a/diag-control.h b/diag-control.h index 8c9ca721..efebec45 100644 --- a/diag-control.h +++ b/diag-control.h @@ -48,10 +48,28 @@ #endif /* + * XL C 12.1 and 13.1 for AIX require no attention in this department. + * XL C 16.1 defines both __GNUC__ and __clang__, so has to be tested first. + */ +#if ND_IS_AT_LEAST_XL_C_VERSION(16,1) + /* + * See respective Clang note below. + */ + #define DIAG_OFF_ASSIGN_ENUM \ + DIAG_DO_PRAGMA(clang diagnostic push) \ + DIAG_DO_PRAGMA(clang diagnostic ignored "-Wassign-enum") + #define DIAG_ON_ASSIGN_ENUM \ + DIAG_DO_PRAGMA(clang diagnostic pop) + + #define DIAG_OFF_CAST_QUAL + #define DIAG_ON_CAST_QUAL + #define DIAG_OFF_DEPRECATION + #define DIAG_ON_DEPRECATION +/* * The current clang compilers also define __GNUC__ and __GNUC_MINOR__ * thus we need to test the clang case before the GCC one */ -#if ND_IS_AT_LEAST_CLANG_VERSION(2,8) +#elif ND_IS_AT_LEAST_CLANG_VERSION(2,8) /* * Clang complains if you OR together multiple enum values of a * given enum type and them pass it as an argument of that enum diff --git a/funcattrs.h b/funcattrs.h index f37e07e2..00efad73 100644 --- a/funcattrs.h +++ b/funcattrs.h @@ -124,8 +124,12 @@ /* * However, GCC didn't support that for function *pointers* until GCC * 4.1.0; see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3481. + * XL C 16.1 (and possibly some earlier versions, but not 12.1 or 13.1) has + * a similar bug, a bugfix for which should be available later: + * https://www.ibm.com/support/pages/apar/LI81402 */ - #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) < 401)) + #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) < 401)) || \ + (ND_IS_AT_LEAST_XL_C_VERSION(16,1) && !ND_IS_AT_LEAST_XL_C_VERSION(16,2)) #define PRINTFLIKE_FUNCPTR(x,y) #else #define PRINTFLIKE_FUNCPTR(x,y) __attribute__((__format__(__printf__,x,y))) |