Skip to contentSkip to conversation

configure: Add compiler option -Wmissing-format-attribute

PATCH In review Stefan Weil 2 participants 4 messages Nov 15, 2010 – Nov 21, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: Add compiler option -Wmissing-format-attribute

With the previous patches, hopefully all functions with printf like arguments use gcc's format checking.

This was tested with default build configuration on linux and windows hosts (including some cross compilations), so chances are good that there remain few (if any) functions without format checking.

---
 HACKING   |    3 ---
 configure |    1 +
 2 files changed, 1 insertions(+), 3 deletions(-)
HACKING +0 -3
index 6ba9d7e..3af53fd 100644
@@ -120,6 +120,3 @@ gcc's printf attribute directive in the prototype.
 This makes it so gcc's -Wformat and -Wformat-security options can do
 their jobs and cross-check format strings with the number and types
 of arguments.
-
-Currently many functions in QEMU are not following this rule but
-patches to add the attribute would be very much appreciated.
configure +1 -0
index 7025d2b..d4c983a 100755
@@ -140,6 +140,7 @@ windres="${cross_prefix}${windres}"
 QEMU_CFLAGS="-fno-strict-aliasing $QEMU_CFLAGS"
 CFLAGS="-g $CFLAGS"
 QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
+QEMU_CFLAGS="-Wmissing-format-attribute $QEMU_CFLAGS"
 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
 QEMU_CFLAGS="-D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
Signature · 1 line
1.7.2.3
#1 lore raw

Am 15.11.2010 21:22, schrieb Stefan Weil:

Quoted 11 lines

With the previous patches, hopefully all functions with printf like arguments use gcc's format checking.

This was tested with default build configuration on linux and windows hosts (including some cross compilations), so chances are good that there remain few (if any) functions without format checking.

---

[snip]

Hi,

to make testing and committing of this and the previous patches easier, I have now set up a git repository which contains all of them (more at the bottom of this mail).

I'd appreciate if someone could test compilation especially with these environment (which I could not test):

* BSD / Darwin host
* Special configure options

This was my configuration (+ cross compilations for windows / mips / powerpc):

$ ./configure --enable-debug-tcg --trace-backend=simple --audio-drv-list="oss,alsa,sdl,esd,pa" --enable-attr
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
config directory  /usr/local/etc
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /home/stefan/src/qemu
C compiler        gcc
Host C compiler   gcc
CFLAGS            -O2 -g
QEMU_CFLAGS       -Werror -m64 -I. -I$(SRC_PATH) -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wmissing-format-attribute -Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing  -fstack-protector-all -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits
LDFLAGS           -Wl,--warn-common -m64 -g
make              make
install           install
host CPU          x86_64
host big endian   no
target list       i386-softmmu x86_64-softmmu arm-softmmu cris-softmmu m68k-softmmu microblaze-softmmu mips-softmmu mipsel-softmmu mips64-softmmu mips64el-softmmu ppc-softmmu ppcemb-softmmu ppc64-softmmu sh4-softmmu sh4eb-softmmu sparc-softmmu sparc64-softmmu i386-linux-user x86_64-linux-user alpha-linux-user arm-linux-user armeb-linux-user cris-linux-user m68k-linux-user microblaze-linux-user mips-linux-user mipsel-linux-user ppc-linux-user ppc64-linux-user ppc64abi32-linux-user sh4-linux-user sh4eb-linux-user sparc-linux-user sparc64-linux-user sparc32plus-linux-user
tcg debug enabled yes
Mon debug enabled no
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
-Werror enabled   yes
SDL support       yes
curses support    yes
curl support      yes
check support     no
mingw32 support   no
Audio drivers     oss alsa sdl esd pa
Extra audio cards ac97 es1370 sb16 hda
Block whitelist
Mixer emulation   no
VNC TLS support   no
VNC SASL support  no
VNC JPEG support  yes
VNC PNG support   yes
VNC thread        no
xen support       no
brlapi support    no
bluez  support    no
Documentation     yes
NPTL support      yes
GUEST_BASE        yes
PIE user targets  no
vde support       yes
IO thread         no
Linux AIO support yes
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
fdt support       no
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
uuid support      yes
vhost-net support no
Trace backend     simple
Trace output file trace-<pid>
spice support     no

Regards,
Stefan

The following changes since commit cf2c1839a955482f2e208d7400594bf076c222f2:

add copyright to spiceaudio (2010-11-11 17:59:25 +0300)

are available in the git repository at:
git://git.weilnetz.de/git/qemu for-blueswirl

Stefan Weil (7):
*-dis: Replace fprintf_ftype by fprintf_function (format checking)
target-sparc: Use fprintf_function (format checking)
trace: Use fprintf_function (format checking)
audio: Use GCC_FMT_ATTR (format checking)
darwin-user: Use GCC_FMT_ATTR (format checking)
slirp: Remove unused code for bad sprintf
configure: Add compiler option -Wmissing-format-attribute

 HACKING                |    3 ---
 alpha-dis.c            |    3 +++
 arm-dis.c              |   14 +++++++-------
 audio/audio_pt_int.c   |    3 ++-
 configure              |    1 +
 darwin-user/machload.c |    2 +-
 darwin-user/qemu.h     |    2 +-
 dis-asm.h              |   10 ++--------
 m68k-dis.c             |    2 +-
 microblaze-dis.c       |    2 +-
 mips-dis.c             |    2 --
 sh4-dis.c              |   16 +++++-----------
 simpletrace.h          |    6 +++---
 slirp/misc.c           |   42 ------------------------------------------
 slirp/slirp.h          |   14 --------------
 slirp/slirp_config.h   |    6 ------
 target-sparc/cpu.h     |    4 ++--
 17 files changed, 29 insertions(+), 103 deletions(-)
#2 lore raw
In reply to Stefan Weil
Quoted 11 lines · Stefan Weil

With the previous patches, hopefully all functions with printf like arguments use gcc's format checking.

This was tested with default build configuration on linux and windows hosts (including some cross compilations), so chances are good that there remain few (if any) functions without format checking.

This breaks the build for me. disas.c doesn't build.

Regards,

Anthony Liguori

Quoted 29 lines
---
  HACKING   |    3 ---
  configure |    1 +
  2 files changed, 1 insertions(+), 3 deletions(-)
HACKING +0 -3
index 6ba9d7e..3af53fd 100644
@@ -120,6 +120,3 @@ gcc's printf attribute directive in the prototype.
  This makes it so gcc's -Wformat and -Wformat-security options can do
  their jobs and cross-check format strings with the number and types
  of arguments.
-
-Currently many functions in QEMU are not following this rule but
-patches to add the attribute would be very much appreciated.
configure +1 -0
index 7025d2b..d4c983a 100755
@@ -140,6 +140,7 @@ windres="${cross_prefix}${windres}"
  QEMU_CFLAGS="-fno-strict-aliasing $QEMU_CFLAGS"
  CFLAGS="-g $CFLAGS"
  QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
+QEMU_CFLAGS="-Wmissing-format-attribute $QEMU_CFLAGS"
  QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
  QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
  QEMU_CFLAGS="-D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
#3 lore raw

Am 21.11.2010 15:51, schrieb Anthony Liguori:

Quoted 9 lines · Stefan Weil
Quoted 8 lines

With the previous patches, hopefully all functions with printf like arguments use gcc's format checking.

This was tested with default build configuration on linux and windows hosts (including some cross compilations), so chances are good that there remain few (if any) functions without format checking.

Quoted 8 lines
Quoted 2 lines

This breaks the build for me. disas.c doesn't build.

Regards,

Anthony Liguori

Did you apply the "previous patches"? You can pull them here:

git://git.weilnetz.de/git/qemu for-blueswirl

If you did apply them: could you please tell me your build environment and add the build error messages?

Thanks,

Stefan Weil