From aabbd0e8dee50956c905a40005bbb3d04d5614ac Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 Aug 2020 13:57:38 +0200 Subject: [PATCH] build: disable "-Wstringop-overflow" warning with LTO enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No amount of _Pragma was able to disable this warning. In function ‘strncpy’, inlined from ‘_nm_strndup_a_step’ at ./shared/nm-glib-aux/nm-macros-internal.h:1367:3, inlined from ‘nms_keyfile_nmmeta_check_filename’ at src/settings/plugins/keyfile/nms-keyfile-utils.c:61:0: /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^ src/settings/plugins/keyfile/nms-keyfile-utils.c: In function ‘nms_keyfile_nmmeta_check_filename’: src/settings/plugins/keyfile/nms-keyfile-utils.c:44: note: length computed here 44 | len = strlen (filename); | lto1: all warnings being treated as errors Oddly enough, gcc is still emitting the warning even with "-Wno-stringop-overflow", but at least it doesn't break the build. (cherry picked from commit 407a1f1e986c21f811d41c107bde4666f15f76f7) --- m4/compiler_options.m4 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/m4/compiler_options.m4 b/m4/compiler_options.m4 index 9adc1f14c3..d390a90cf0 100644 --- a/m4/compiler_options.m4 +++ b/m4/compiler_options.m4 @@ -60,11 +60,20 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then CFLAGS_MORE_WARNINGS="-Wall" + if test "x$enable_lto" = xyes; then + dnl With LTO and optimizations enabled, gcc 10.2.1-1.fc32 is really + dnl adamant to warn about correct uses of strncpy. Disable that warning. + _CFLAGS_MORE_WARNINGS_DISABLE_LTO="-Wno-stringop-overflow" + else + _CFLAGS_MORE_WARNINGS_DISABLE_LTO= + fi + if test "x$set_more_warnings" = xerror; then CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS -Werror" fi for option in \ + $_CFLAGS_MORE_WARNINGS_DISABLE_LTO \ -Wextra \ -Wdeclaration-after-statement \ -Wfloat-equal \