]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: warnings: compile build tools with -Werror too
authorMike Frysinger <vapier@gentoo.org>
Wed, 30 Jun 2021 00:16:38 +0000 (20:16 -0400)
committerMike Frysinger <vapier@gentoo.org>
Tue, 9 Jan 2024 02:36:44 +0000 (21:36 -0500)
Add support for compiling build tools with various -Werror settings.
Since the tools don't compile cleanly with the same set of flags as
the rest of the sim code, we need to maintain & test a separate list.

Only bother when not cross-compiling so we don't have to test all the
flags against the build compiler.  This should be good enough for our
actual development flows.

sim/Makefile.am
sim/Makefile.in
sim/configure
sim/m4/sim_ac_option_warnings.m4

index 9183b349725e86a060a142ed8fba313e508bbeb5..a6e080eaafbd02e68a3eb41c1baf12b641fb07cb 100644 (file)
@@ -67,7 +67,7 @@ AM_CPPFLAGS_FOR_BUILD = \
        -I$(srcroot)/include \
        $(SIM_HW_CFLAGS) \
        $(SIM_INLINE)
-COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(AM_CPPFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD)
+COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(AM_CPPFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(BUILD_WERROR_CFLAGS) $(BUILD_WARN_CFLAGS)
 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@
 
 ## Deps to add to the install-data-local target.
index c96e8a9b2d240229899eed903255cb2275438b22..1e94771577d95a7e9b9473ed16272728ecdb23bc 100644 (file)
@@ -1608,6 +1608,8 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BUILD_WARN_CFLAGS = @BUILD_WARN_CFLAGS@
+BUILD_WERROR_CFLAGS = @BUILD_WERROR_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CC_FOR_BUILD = @CC_FOR_BUILD@
@@ -1901,7 +1903,7 @@ AM_CPPFLAGS = $(INCGNU) -I$(srcroot) -I$(srcroot)/include -I../bfd \
        -,_,$(@D)_$(@F))) -I$(srcdir)/common -DSIM_TOPDIR_BUILD
 AM_CPPFLAGS_FOR_BUILD = -I$(srcroot)/include $(SIM_HW_CFLAGS) \
        $(SIM_INLINE) -I$(srcdir)/common
-COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(AM_CPPFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD)
+COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(AM_CPPFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(BUILD_WERROR_CFLAGS) $(BUILD_WARN_CFLAGS)
 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@
 SIM_INSTALL_DATA_LOCAL_DEPS = 
 SIM_INSTALL_EXEC_LOCAL_DEPS = $(am__append_33)
index 88dc76f27c20699427926afcfe4a39e1eff0400d..e8d7be56b81763543bfd9398b2a966d34e2a3a80 100755 (executable)
@@ -991,6 +991,8 @@ PACKAGE_NAME
 PATH_SEPARATOR
 SHELL
 SIM_TOOLCHAIN_VARS
+BUILD_WERROR_CFLAGS
+BUILD_WARN_CFLAGS
 WERROR_CFLAGS
 WARN_CFLAGS'
 ac_subst_files=''
@@ -12683,7 +12685,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12686 "configure"
+#line 12688 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12789,7 +12791,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12792 "configure"
+#line 12794 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16179,6 +16181,12 @@ build_warnings="$build_warnings
 -Wstrict-prototypes
 -Wno-enum-conversion
 "
+build_build_warnings="
+-Wno-missing-braces
+-Wno-stringop-truncation
+-Wno-implicit-fallthrough
+-Wno-shadow=local
+"
 
 case "${host}" in
   *-*-mingw32*)
@@ -16228,9 +16236,12 @@ if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
 fi
 fi
 WARN_CFLAGS=""
+BUILD_WARN_CFLAGS=""
 if test "x${build_warnings}" != x -a "x$GCC" = xyes
 then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking compiler warning flags" >&5
+
+
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking compiler warning flags" >&5
 $as_echo_n "checking compiler warning flags... " >&6; }
     # Separate out the -Werror flag as some files just cannot be
     # compiled with it enabled.
@@ -16273,6 +16284,59 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${WARN_CFLAGS} ${WERROR_CFLAGS}" >&5
 $as_echo "${WARN_CFLAGS} ${WERROR_CFLAGS}" >&6; }
 
+
+        if test "x$cross_compiling" = "xno"; then :
+       SAVE_WARN_CFLAGS=$WARN_CFLAGS
+       build_warnings=$build_build_warnings
+           { $as_echo "$as_me:${as_lineno-$LINENO}: checking compiler warning flags" >&5
+$as_echo_n "checking compiler warning flags... " >&6; }
+    # Separate out the -Werror flag as some files just cannot be
+    # compiled with it enabled.
+    for w in ${build_warnings}; do
+       case $w in
+       -Werr*) WERROR_CFLAGS=-Werror ;;
+       *)       w="$w"
+  case $w in
+  -Wno-*)
+    wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
+  -Wformat-nonliteral)
+            w="-Wformat $w"
+    wtest="$w"
+    ;;
+  *)
+    wtest=$w ;;
+  esac
+
+    saved_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -Werror $wtest"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  WARN_CFLAGS="${WARN_CFLAGS} $w"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  CFLAGS="$saved_CFLAGS"
+ ;;
+       esac
+    done
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${WARN_CFLAGS} ${WERROR_CFLAGS}" >&5
+$as_echo "${WARN_CFLAGS} ${WERROR_CFLAGS}" >&6; }
+
+       BUILD_WARN_CFLAGS=$WARN_CFLAGS
+       WARN_CFLAGS=$SAVE_WARN_CFLAGS
+       BUILD_WERROR_CFLAGS=$WERROR_CFLAGS
+
+fi
+
           { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wno-shadow=local is supported" >&5
 $as_echo_n "checking whether -Wno-shadow=local is supported... " >&6; }
         w="-Wno-shadow=local"
index 7a28ca621a0b967c37f822a5142c4dd63004621a..3b00889dbb05a1fb0683f0e8f13c511325041c65 100644 (file)
@@ -76,6 +76,17 @@ dnl The cgen virtual insn logic involves enum conversions.
 dnl Disable until we can figure out how to make this work.
 -Wno-enum-conversion
 "
+build_build_warnings="
+dnl TODO Fix the sh/gencode.c which triggers a ton of these warnings.
+-Wno-missing-braces
+dnl TODO Figure out the igen code that triggers warnings w/FORTIFY_SOURCE.
+-Wno-stringop-truncation
+dnl Fixing this requires ATTRIBUTE_FALLTHROUGH support at build time, but we
+dnl don't have gnulib there (yet).
+-Wno-implicit-fallthrough
+dnl TODO Enable this after cleaning up code.
+-Wno-shadow=local
+"
 
 case "${host}" in
   *-*-mingw32*)
@@ -123,8 +134,10 @@ if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
   echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
 fi])dnl
 WARN_CFLAGS=""
+BUILD_WARN_CFLAGS=""
 if test "x${build_warnings}" != x -a "x$GCC" = xyes
 then
+AC_DEFUN([_SIM_TEST_ALL_WARNING_FLAGS], [dnl
     AC_MSG_CHECKING(compiler warning flags)
     # Separate out the -Werror flag as some files just cannot be
     # compiled with it enabled.
@@ -135,6 +148,20 @@ then
        esac
     done
     AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
+])
+
+    dnl Test the host flags.
+    _SIM_TEST_ALL_WARNING_FLAGS
+
+    dnl Test the build flags.
+    AS_IF([test "x$cross_compiling" = "xno"], [dnl
+       SAVE_WARN_CFLAGS=$WARN_CFLAGS
+       build_warnings=$build_build_warnings
+       _SIM_TEST_ALL_WARNING_FLAGS
+       BUILD_WARN_CFLAGS=$WARN_CFLAGS
+       WARN_CFLAGS=$SAVE_WARN_CFLAGS
+       BUILD_WERROR_CFLAGS=$WERROR_CFLAGS
+    ])
 
     dnl Test individual flags to export to dedicated variables.
     m4_map([_SIM_EXPORT_WARNING_FLAG], m4_split(m4_normalize([
@@ -183,3 +210,5 @@ AC_DEFUN([_SIM_EXPORT_WARNING_FLAG], [dnl
 ])
 AC_SUBST(WARN_CFLAGS)
 AC_SUBST(WERROR_CFLAGS)
+AC_SUBST(BUILD_WARN_CFLAGS)
+AC_SUBST(BUILD_WERROR_CFLAGS)