Skip to content

Commit 6bf7d89

Browse files
author
florian
committed
Add -Wformat -Wformat-security to the list of compile flags.
This was not as straight forward as expected. Specifically, adding the new flag to CFLAGS in configure.ac did not work and was causing compiler warnings. For instance, compiling memcheck/tests/execve2.c will generate a -Wnonnull warning even though the testcase is explicitly compiled with -Wno-nonnull. The reason is that (a) -Wformat is implied by -Wnonnull and (b) the list of compiler flags gets assembled in the wrong order. The culprit appears to be that we modify CFLAGS in configure.ac and that really is not the right place. Conceptually, configure should determine tool-chain capabilities and not assemble compiler flags. That should be done in Makefiles. This patch entangles all this. So, whatever was added to CFLAGS in configure.ac has now been moved to Makefile.all.am and Makefile.tool-tests.am. Those are: -Wno-long-long -Wwrite-strings -Wcast-qual -fno-stack-protector Note, that this change allows us to simplify Makefile.tool-tests.am which in the past was disabling some of those flags (e.g. by adding -Wno-cast-qual again). In case of the clang compiler, extra command line options are needed. I've moved those into a separate 'if COMPILER_IS_CLANG' section and not merge them into baseline flags. Related to BZ 334727. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14798 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent d2f4f03 commit 6bf7d89

File tree

4 files changed

+51
-45
lines changed

4 files changed

+51
-45
lines changed

Makefile.all.am

+11-1
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,20 @@ AM_CFLAGS_BASE = \
105105
-Wpointer-arith \
106106
-Wstrict-prototypes \
107107
-Wmissing-declarations \
108-
@FLAG_W_NO_TAUTOLOGICAL_COMPARE@ \
108+
-Wno-long-long \
109+
@FLAG_W_CAST_QUAL@ \
110+
@FLAG_W_WRITE_STRINGS@ \
111+
@FLAG_W_FORMAT@ \
112+
@FLAG_W_FORMAT_SECURITY@ \
113+
@FLAG_FNO_STACK_PROTECTOR@ \
109114
-fno-strict-aliasing \
110115
-fno-builtin
111116

117+
if COMPILER_IS_CLANG
118+
AM_CFLAGS_BASE += -Wno-cast-align -Wno-self-assign \
119+
-Wno-tautological-compare
120+
endif
121+
112122
# These flags are used for building the preload shared objects (PSOs).
113123
# The aim is to give reasonable performance but also to have good
114124
# stack traces, since users often see stack traces extending

Makefile.tool-tests.am

+12-14
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ endif
1818

1919
# Nb: Tools need to augment these flags with an arch-selection option, such
2020
# as $(AM_FLAG_M3264_PRI).
21-
AM_CFLAGS = -Winline -Wall -Wshadow -g
22-
AM_CXXFLAGS = -Winline -Wall -Wshadow -g
21+
AM_CFLAGS = -Winline -Wall -Wshadow -Wno-long-long -g \
22+
@FLAG_FNO_STACK_PROTECTOR@
23+
AM_CXXFLAGS = -Winline -Wall -Wshadow -Wno-long-long -g \
24+
@FLAG_FNO_STACK_PROTECTOR@
2325
# Include AM_CPPFLAGS in AM_CCASFLAGS to allow for older versions of
2426
# automake; see comments in Makefile.all.am for more detail.
2527
AM_CCASFLAGS = $(AM_CPPFLAGS)
@@ -28,21 +30,17 @@ if VGCONF_OS_IS_DARWIN
2830
noinst_DSYMS = $(check_PROGRAMS)
2931
endif
3032

31-
if HAS_WRITE_STRINGS_WARNING
32-
CFLAGS += -Wno-write-strings
33-
endif
34-
3533
if COMPILER_IS_CLANG
36-
CFLAGS += -Wno-format-extra-args # perf/tinycc.c
37-
CFLAGS += -Wno-literal-range # none/tests/amd64/fxtract.c
38-
CFLAGS += -Wno-string-plus-int # drd/tests/annotate_ignore_rw.c
39-
CXXFLAGS += -Wno-unused-private-field # drd/tests/tsan_unittest.cpp
34+
AM_CFLAGS += -Wno-format-extra-args # perf/tinycc.c
35+
AM_CFLAGS += -Wno-literal-range # none/tests/amd64/fxtract.c
36+
AM_CFLAGS += -Wno-tautological-constant-out-of-range-compare # ...../aes.c
37+
AM_CFLAGS += -Wno-self-assign # memcheck/tests/unit_libcbase.c
38+
AM_CFLAGS += -Wno-string-plus-int # drd/tests/annotate_ignore_rw.c
39+
AM_CFLAGS += -Wno-uninitialized # clang 3.4.2 and earlier
40+
AM_CFLAGS += -Wno-unused-value # clang 3.0.0
41+
AM_CXXFLAGS += -Wno-unused-private-field # drd/tests/tsan_unittest.cpp
4042
endif
4143

42-
# Compile testcases without -Wcast-qual
43-
CFLAGS += -Wno-cast-qual
44-
CXXFLAGS += -Wno-cast-qual
45-
4644
check-local: build-noinst_DSYMS
4745

4846
clean-local: clean-noinst_DSYMS

configure.ac

+25-27
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ AM_INIT_AUTOMAKE([foreign subdir-objects])
1515

1616
AM_MAINTAINER_MODE
1717

18+
#----------------------------------------------------------------------------
19+
# Do NOT modify these flags here. Except in feature tests in which case
20+
# the original values must be properly restored.
21+
#----------------------------------------------------------------------------
22+
CFLAGS="$CFLAGS"
23+
CXXFLAGS="$CXXFLAGS"
24+
1825
#----------------------------------------------------------------------------
1926
# Checks for various programs.
2027
#----------------------------------------------------------------------------
21-
CFLAGS="-Wno-long-long $CFLAGS"
22-
CXXFLAGS="-Wno-long-long $CXXFLAGS"
2328

2429
AC_PROG_LN_S
2530
AC_PROG_CC
@@ -145,11 +150,6 @@ fi
145150
AM_CONDITIONAL(COMPILER_IS_CLANG, test $is_clang = clang -o $is_clang = applellvm)
146151
AM_CONDITIONAL(COMPILER_IS_ICC, test $is_clang = icc)
147152

148-
if test $is_clang = clang -o $is_clang = applellvm ; then
149-
CFLAGS="$CFLAGS -Wno-tautological-compare -Wno-cast-align -Wno-self-assign"
150-
CXXFLAGS="$CXXFLAGS -Wno-tautological-compare -Wno-cast-align -Wno-self-assign"
151-
fi
152-
153153
# Note: m4 arguments are quoted with [ and ] so square brackets in shell
154154
# statements have to be quoted.
155155
case "${is_clang}-${gcc_version}" in
@@ -1686,11 +1686,6 @@ AC_DEFUN([AC_GCC_WARNING_COND],[
16861686
])
16871687

16881688
AC_GCC_WARNING_COND([pointer-sign], [HAS_POINTER_SIGN_WARNING])
1689-
AC_GCC_WARNING_COND([write-strings], [HAS_WRITE_STRINGS_WARNING])
1690-
if test $has_warning_flag = yes; then
1691-
CFLAGS="$CFLAGS -Wwrite-strings"
1692-
CXXFLAGS="$CXXFLAGS -Wwrite-strings"
1693-
fi
16941689

16951690
# Convenience function to check whether GCC supports a particular
16961691
# warning option. Similar to AC_GCC_WARNING_COND, but does a
@@ -1712,14 +1707,31 @@ AC_DEFUN([AC_GCC_WARNING_SUBST_NO],[
17121707
CFLAGS=$safe_CFLAGS
17131708
])
17141709

1710+
# Convenience function. Like AC_GCC_WARNING_SUBST_NO, except it substitutes
1711+
# -W$1 (instead of -Wno-$1).
1712+
AC_DEFUN([AC_GCC_WARNING_SUBST],[
1713+
AC_MSG_CHECKING([if gcc accepts -W$1])
1714+
safe_CFLAGS=$CFLAGS
1715+
CFLAGS="-W$1"
1716+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
1717+
AC_SUBST([$2], [-W$1])
1718+
AC_MSG_RESULT([yes])], [
1719+
AC_SUBST([$2], [])
1720+
AC_MSG_RESULT([no])])
1721+
CFLAGS=$safe_CFLAGS
1722+
])
1723+
17151724
AC_GCC_WARNING_SUBST_NO([empty-body], [FLAG_W_NO_EMPTY_BODY])
17161725
AC_GCC_WARNING_SUBST_NO([format-zero-length], [FLAG_W_NO_FORMAT_ZERO_LENGTH])
1717-
AC_GCC_WARNING_SUBST_NO([tautological-compare], [FLAG_W_NO_TAUTOLOGICAL_COMPARE])
17181726
AC_GCC_WARNING_SUBST_NO([nonnull], [FLAG_W_NO_NONNULL])
17191727
AC_GCC_WARNING_SUBST_NO([overflow], [FLAG_W_NO_OVERFLOW])
17201728
AC_GCC_WARNING_SUBST_NO([uninitialized], [FLAG_W_NO_UNINITIALIZED])
17211729
AC_GCC_WARNING_SUBST_NO([unused-function], [FLAG_W_NO_UNUSED_FUNCTION])
17221730
AC_GCC_WARNING_SUBST_NO([static-local-in-inline], [FLAG_W_NO_STATIC_LOCAL_IN_INLINE])
1731+
AC_GCC_WARNING_SUBST([write-strings], [FLAG_W_WRITE_STRINGS])
1732+
AC_GCC_WARNING_SUBST([format], [FLAG_W_FORMAT])
1733+
AC_GCC_WARNING_SUBST([format-security], [FLAG_W_FORMAT_SECURITY])
1734+
AC_GCC_WARNING_SUBST([cast-qual], [FLAG_W_CAST_QUAL])
17231735

17241736

17251737
# does this compiler support -Wextra or the older -W ?
@@ -1748,14 +1760,6 @@ AC_MSG_RESULT([-Wextra])
17481760
])
17491761
CFLAGS=$safe_CFLAGS
17501762

1751-
# does this compiler support -Wcast-qual ?
1752-
AC_GCC_WARNING_COND([cast-qual], [HAS_CAST_QUAL_WARNING])
1753-
if test $has_warning_flag = yes; then
1754-
CFLAGS="$CFLAGS -Wcast-qual"
1755-
CXXFLAGS="$CXXFLAGS -Wcast-qual"
1756-
fi
1757-
1758-
17591763
# does this compiler support -fno-stack-protector ?
17601764
AC_MSG_CHECKING([if gcc accepts -fno-stack-protector])
17611765

@@ -1777,12 +1781,6 @@ CFLAGS=$safe_CFLAGS
17771781

17781782
AC_SUBST(FLAG_FNO_STACK_PROTECTOR)
17791783

1780-
if test x$no_stack_protector = xyes; then
1781-
CFLAGS="$CFLAGS -fno-stack-protector"
1782-
CXXFLAGS="$CXXFLAGS -fno-stack-protector"
1783-
fi
1784-
1785-
17861784
# does this compiler support --param inline-unit-growth=... ?
17871785

17881786
AC_MSG_CHECKING([if gcc accepts --param inline-unit-growth])

memcheck/tests/vbit-test/Makefile.am

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ SOURCES = \
3333
valgrind.c
3434

3535
vbit_test_SOURCES = $(SOURCES)
36-
vbit_test_CPPFLAGS = $(AM_CPPFLAGS) \
36+
vbit_test_CPPFLAGS = $(AM_CPPFLAGS_PRI) \
3737
-I$(top_srcdir)/include \
3838
-I$(top_srcdir)/memcheck \
3939
-I$(top_srcdir)/VEX/pub
40-
vbit_test_CFLAGS = $(AM_CFLAGS) -std=c99
40+
vbit_test_CFLAGS = $(AM_CFLAGS_PRI) -std=c99
4141
vbit_test_DEPENDENCIES =
4242
vbit_test_LDADD =
43-
vbit_test_LDFLAGS =
43+
vbit_test_LDFLAGS = $(AM_CFLAGS_PRI) -std=c99
4444
vbit_test_LINK = $(LINK)
4545
$(LINK) $(vbit_test_CFLAGS) $(vbit_test_LDFLAGS)

0 commit comments

Comments
 (0)