From 1d5f0a88e0dac70cf6f99ccee2fac8eb33c1a7cf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Jan 2025 16:01:56 +0100 Subject: fundamental: unify gcc warning pragmas at one place This also drops HAVE_WSTRINGOP_TRUNCATION as the corresponding option was introduced in GCC 8, and our baseline is GCC 8.4. --- meson.build | 3 --- src/basic/macro.h | 9 --------- src/fundamental/macro-fundamental.h | 8 ++++++++ src/resolve/resolved-dns-dnssec.c | 15 ++++++--------- src/shared/ethtool-util.c | 8 +++----- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/meson.build b/meson.build index 5c364e1379..f9f400a7d6 100644 --- a/meson.build +++ b/meson.build @@ -538,14 +538,11 @@ endif cpp = ' '.join(cc.cmd_array() + get_option('c_args')) + ' -E' -has_wstringop_truncation = cc.has_argument('-Wstringop-truncation') - ##################################################################### # compilation result tests conf.set('_GNU_SOURCE', 1) conf.set('__SANE_USERSPACE_TYPES__', true) -conf.set10('HAVE_WSTRINGOP_TRUNCATION', has_wstringop_truncation) conf.set('SIZEOF_DEV_T', cc.sizeof('dev_t', prefix : '#include ')) conf.set('SIZEOF_INO_T', cc.sizeof('ino_t', prefix : '#include ')) diff --git a/src/basic/macro.h b/src/basic/macro.h index 68eb7bbd0e..026ec13637 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -30,15 +30,6 @@ #define _function_no_sanitize_float_cast_overflow_ #endif -#if HAVE_WSTRINGOP_TRUNCATION -# define DISABLE_WARNING_STRINGOP_TRUNCATION \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"") -#else -# define DISABLE_WARNING_STRINGOP_TRUNCATION \ - _Pragma("GCC diagnostic push") -#endif - /* test harness */ #define EXIT_TEST_SKIP 77 diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 709657dd28..6122a0a92b 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -48,6 +48,14 @@ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Waddress\"") +#define DISABLE_WARNING_STRINGOP_TRUNCATION \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"") + +#define DISABLE_WARNING_ZERO_LENGTH_BOUNDS \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wzero-length-bounds\"") + #define REENABLE_WARNING \ _Pragma("GCC diagnostic pop") diff --git a/src/resolve/resolved-dns-dnssec.c b/src/resolve/resolved-dns-dnssec.c index 09cc2cb731..aff185a2dd 100644 --- a/src/resolve/resolved-dns-dnssec.c +++ b/src/resolve/resolved-dns-dnssec.c @@ -15,11 +15,10 @@ #include "string-table.h" #if PREFER_OPENSSL && OPENSSL_VERSION_MAJOR >= 3 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +DISABLE_WARNING_DEPRECATED_DECLARATIONS; DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(RSA*, RSA_free, NULL); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(EC_KEY*, EC_KEY_free, NULL); -# pragma GCC diagnostic pop +REENABLE_WARNING; #endif #define VERIFY_RRS_MAX 256 @@ -101,8 +100,7 @@ static int dnssec_rsa_verify_raw( int r; #if PREFER_OPENSSL -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" + DISABLE_WARNING_DEPRECATED_DECLARATIONS; _cleanup_(RSA_freep) RSA *rpubkey = NULL; _cleanup_(EVP_PKEY_freep) EVP_PKEY *epubkey = NULL; _cleanup_(EVP_PKEY_CTX_freep) EVP_PKEY_CTX *ctx = NULL; @@ -153,7 +151,7 @@ static int dnssec_rsa_verify_raw( return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Signature verification failed: 0x%lx", ERR_get_error()); -# pragma GCC diagnostic pop + REENABLE_WARNING; #else gcry_sexp_t public_key_sexp = NULL, data_sexp = NULL, signature_sexp = NULL; gcry_mpi_t n = NULL, e = NULL, s = NULL; @@ -303,8 +301,7 @@ static int dnssec_ecdsa_verify_raw( int k; #if PREFER_OPENSSL -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" + DISABLE_WARNING_DEPRECATED_DECLARATIONS; _cleanup_(EC_GROUP_freep) EC_GROUP *ec_group = NULL; _cleanup_(EC_POINT_freep) EC_POINT *p = NULL; _cleanup_(EC_KEY_freep) EC_KEY *eckey = NULL; @@ -365,7 +362,7 @@ static int dnssec_ecdsa_verify_raw( return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Signature verification failed: 0x%lx", ERR_get_error()); -# pragma GCC diagnostic pop + REENABLE_WARNING; #else gcry_sexp_t public_key_sexp = NULL, data_sexp = NULL, signature_sexp = NULL; gcry_mpi_t q = NULL, r = NULL, s = NULL; diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index 51c75780cd..aeed917a6a 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -11,6 +11,7 @@ #include "extract-word.h" #include "fd-util.h" #include "log.h" +#include "macro-fundamental.h" #include "memory-util.h" #include "socket-util.h" #include "string-table.h" @@ -452,12 +453,9 @@ static int get_stringset(int ethtool_fd, const char *ifname, enum ethtool_string if (buffer.info.sset_mask == 0) return -EOPNOTSUPP; -#pragma GCC diagnostic push -#if HAVE_ZERO_LENGTH_BOUNDS -# pragma GCC diagnostic ignored "-Wzero-length-bounds" -#endif + DISABLE_WARNING_ZERO_LENGTH_BOUNDS; len = buffer.info.data[0]; -#pragma GCC diagnostic pop + REENABLE_WARNING; if (len == 0) return -EOPNOTSUPP; -- cgit v1.2.3 From 83a3018e20d7e637e662fb98e05b41162aef54ac Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Jan 2025 13:46:18 +0100 Subject: nss-systemd: work around -Werror=zero-as-null-pointer-constant issue with PTHREAD_MUTEX_INITIALIZER This fixes builds on Fedora: ../src/nss-systemd/nss-systemd.c:105:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] 105 | .mutex = PTHREAD_MUTEX_INITIALIZER, | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/nss-systemd/nss-systemd.c:105:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] ../src/nss-systemd/nss-systemd.c:109:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] 109 | .mutex = PTHREAD_MUTEX_INITIALIZER, | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/nss-systemd/nss-systemd.c:109:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] ../src/nss-systemd/nss-systemd.c:113:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] 113 | .mutex = PTHREAD_MUTEX_INITIALIZER, | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/nss-systemd/nss-systemd.c:113:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] ../src/nss-systemd/nss-systemd.c:117:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] 117 | .mutex = PTHREAD_MUTEX_INITIALIZER, | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/nss-systemd/nss-systemd.c:117:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] cc1: all warnings being treated as errors --- src/fundamental/macro-fundamental.h | 4 ++++ src/nss-systemd/nss-systemd.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 6122a0a92b..7bee2915e1 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -56,6 +56,10 @@ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wzero-length-bounds\"") +#define DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"") + #define REENABLE_WARNING \ _Pragma("GCC diagnostic pop") diff --git a/src/nss-systemd/nss-systemd.c b/src/nss-systemd/nss-systemd.c index d686d920fc..683352fab9 100644 --- a/src/nss-systemd/nss-systemd.c +++ b/src/nss-systemd/nss-systemd.c @@ -101,6 +101,9 @@ typedef struct GetentData { bool by_membership; } GetentData; +/* On current glibc PTHREAD_MUTEX_INITIALIZER is defined in a way incompatible with + * -Wzero-as-null-pointer-constant, work around this for now. */ +DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT; static GetentData getpwent_data = { .mutex = PTHREAD_MUTEX_INITIALIZER, }; @@ -116,6 +119,7 @@ static GetentData getspent_data = { static GetentData getsgent_data = { .mutex = PTHREAD_MUTEX_INITIALIZER, }; +REENABLE_WARNING; static void setup_logging_once(void) { static pthread_once_t once = PTHREAD_ONCE_INIT; -- cgit v1.2.3 From 9c881fa867f184e80293ee86974f2c0c0b5fb7a3 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 17 Jan 2025 04:27:36 +0900 Subject: fundamental-macro: conditionalize several gcc warning pragmas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the following error: In file included from ../src/basic/macro.h:13, from ../src/basic/env-util.h:9, from ../src/nss-systemd/nss-systemd.c:7: ../src/fundamental/macro-fundamental.h:61:9: error: option ‘-Wzero-as-null-pointer-constant’ is valid for C++/ObjC++ but not for C [-Werror=pragmas] 61 | _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"") | ^~~~~~~ ../src/nss-systemd/nss-systemd.c:106:1: note: in expansion of macro ‘DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT’ 106 | DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors --- meson.build | 11 ++++++++--- src/boot/meson.build | 6 ++++++ src/fundamental/macro-fundamental.h | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index f9f400a7d6..48ba967d0e 100644 --- a/meson.build +++ b/meson.build @@ -516,9 +516,6 @@ add_project_link_arguments( userspace_c_args += cc.get_supported_arguments(possible_cc_flags) userspace_c_ld_args += cc.get_supported_link_arguments(possible_link_flags) -have = cc.has_argument('-Wzero-length-bounds') -conf.set10('HAVE_ZERO_LENGTH_BOUNDS', have) - if cc.compiles(''' #include #include @@ -538,6 +535,14 @@ endif cpp = ' '.join(cc.cmd_array() + get_option('c_args')) + ' -E' +# new in GCC 10 +have = cc.has_argument('-Wzero-length-bounds') +conf.set10('HAVE_WARNING_ZERO_LENGTH_BOUNDS', have) + +# new in GCC 15 +have = cc.has_argument('-Wzero-as-null-pointer-constant') +conf.set10('HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT', have) + ##################################################################### # compilation result tests diff --git a/src/boot/meson.build b/src/boot/meson.build index cc5102c551..f726996233 100644 --- a/src/boot/meson.build +++ b/src/boot/meson.build @@ -74,6 +74,12 @@ if conf.get('ENABLE_BOOTLOADER') != 1 endif efi_conf = configuration_data() + +# import several configs from userspace +foreach name : ['HAVE_WARNING_ZERO_LENGTH_BOUNDS', 'HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT'] + efi_conf.set10(name, conf.get(name) == 1) +endforeach + efi_conf.set10('ENABLE_TPM', get_option('tpm')) foreach ctype : ['color-normal', 'color-entry', 'color-highlight', 'color-edit'] diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 7bee2915e1..5eb31cd742 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -52,13 +52,23 @@ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"") -#define DISABLE_WARNING_ZERO_LENGTH_BOUNDS \ +#if HAVE_WARNING_ZERO_LENGTH_BOUNDS +# define DISABLE_WARNING_ZERO_LENGTH_BOUNDS \ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wzero-length-bounds\"") +#else +# define DISABLE_WARNING_ZERO_LENGTH_BOUNDS \ + _Pragma("GCC diagnostic push") +#endif -#define DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT \ +#if HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT +# define DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT \ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"") +#else +# define DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT \ + _Pragma("GCC diagnostic push") +#endif #define REENABLE_WARNING \ _Pragma("GCC diagnostic pop") -- cgit v1.2.3