summarylogtreecommitdiffstats
path: root/gcc13-Wno-format-security.patch
blob: 371a469e43f974c2c5d7a2e53533ff23c6761883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
From 36216317682fab126def7625363b4a1013fae64f Mon Sep 17 00:00:00 2001
From: Joey Dumont <joey.dumont@gmail.com>
Date: Thu, 27 Apr 2023 06:58:53 -0400
Subject: [PATCH] Workaround for Werror=format-security errors in the libcpp
 and gcc components.

Both libcpp and the gcc subfolders have fail to compile when the Werror=format-security
flag is present. This patch attempts to to selectively disable this flag by adding
Wno-error=format-security in some build system variables.

In the gcc component, we simply augment the existing --disable-build-format-warnings
option to set -Wno-error=format-security. We also must add this flag to the strict_warn
set of CFLAGS, so that the gcc/c component can pick it up.

In the libcpp component, we add the --disable-build-format-warnings option
to the configure script, and give it the same options as gcc's option.
---
 gcc/configure       |  4 ++--
 gcc/configure.ac    |  4 ++--
 libcpp/configure    | 17 ++++++++++++++++-
 libcpp/configure.ac |  7 ++++++-
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index c7b26d192..ec112fd48 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -7089,7 +7089,7 @@ else
 fi
 
 if test $enable_build_format_warnings = no; then :
-  wf_opt=-Wno-format
+  wf_opt=-Wno-format -Wno-format-security
 else
   wf_opt=
 fi
@@ -7216,7 +7216,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
 strict_warn=
 save_CXXFLAGS="$CXXFLAGS"
-for real_option in -Wmissing-format-attribute -Wconditionally-supported -Woverloaded-virtual; do
+for real_option in -Wmissing-format-attribute -Wconditionally-supported -Woverloaded-virtual $wf_opt; do
   # Do the check with the no- prefix removed since gcc silently
   # accepts any -Wno-* option on purpose
   case $real_option in
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 09082e8cc..4c3e0463f 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -571,7 +571,7 @@ AC_ARG_ENABLE(build-format-warnings,
   AS_HELP_STRING([--disable-build-format-warnings],[don't use -Wformat while building GCC]),
   [],[enable_build_format_warnings=yes])
 AS_IF([test $enable_build_format_warnings = no],
-      [wf_opt=-Wno-format],[wf_opt=])
+      [wf_opt=-Wno-format -Wno-format-security],[wf_opt=])
 ACX_PROG_CXX_WARNING_OPTS(
 	m4_quote(m4_do([-W -Wall -Wno-narrowing -Wwrite-strings ],
 		       [-Wcast-qual $wf_opt])),
@@ -581,7 +581,7 @@ ACX_PROG_CC_WARNING_OPTS(
 		       [])), [c_loose_warn])
 ACX_PROG_CXX_WARNING_OPTS(
 	m4_quote(m4_do([-Wmissing-format-attribute ], [-Wconditionally-supported ],
-		       [-Woverloaded-virtual])), [strict_warn])
+		       [-Woverloaded-virtual $wf_opt])), [strict_warn])
 ACX_PROG_CC_WARNING_OPTS(
 	m4_quote(m4_do([-Wold-style-definition -Wc++-compat])), [c_strict_warn])
 ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC(
diff --git a/libcpp/configure b/libcpp/configure
index e9937cde3..8d8a721ad 100755
--- a/libcpp/configure
+++ b/libcpp/configure
@@ -729,6 +729,7 @@ ac_subst_files=''
 ac_user_opts='
 enable_option_checking
 enable_largefile
+enable_build_format_warnings
 enable_werror_always
 with_gnu_ld
 enable_rpath
@@ -1368,6 +1369,8 @@ Optional Features:
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --disable-largefile     omit support for large files
+  --disable-build-format-warnings
+                          don't use -Wformat while building GCC
   --enable-werror-always  enable -Werror despite compiler version
   --disable-rpath         do not hardcode runtime library paths
   --enable-maintainer-mode enable rules only needed by maintainers
@@ -4904,6 +4907,18 @@ fi
 
 # Figure out what compiler warnings we can enable.
 # See config/warnings.m4 for details.
+# Check whether --enable-build-format-warnings was given.
+if test "${enable_build_format_warnings+set}" = set; then :
+  enableval=$enable_build_format_warnings;
+else
+  enable_build_format_warnings=yes
+fi
+
+if test $enable_build_format_warnings = no; then :
+  wf_opt="-Wno-format -Wno-format-security"
+else
+  wf_opt=
+fi
 
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
@@ -4914,7 +4929,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 warn=
 save_CFLAGS="$CFLAGS"
 for real_option in -W -Wall -Wno-narrowing -Wwrite-strings \
-			  -Wmissing-format-attribute; do
+			  -Wmissing-format-attribute $wf_opt; do
   # Do the check with the no- prefix removed since gcc silently
   # accepts any -Wno-* option on purpose
   case $real_option in
diff --git a/libcpp/configure.ac b/libcpp/configure.ac
index 89ac99b04..1bb6f770c 100644
--- a/libcpp/configure.ac
+++ b/libcpp/configure.ac
@@ -29,9 +29,14 @@ AC_SUBST([ETAGS])
 
 # Figure out what compiler warnings we can enable.
 # See config/warnings.m4 for details.
+AC_ARG_ENABLE(build-format-warnings,
+  AS_HELP_STRING([--disable-build-format-warnings],[don't use -Wformat while building GCC]),
+  [],[enable_build_format_warnings=yes])
+AS_IF([test $enable_build_format_warnings = no],
+      [wf_opt="-Wno-format -Wno-format-security"],[wf_opt=])
 
 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
-			  -Wmissing-format-attribute], [warn])
+			  -Wmissing-format-attribute $wf_opt], [warn])
 ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
 			  -Wold-style-definition -Wc++-compat], [c_warn])
 ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
-- 
2.40.1