diff options
| author | Mark Wielaard <[email protected]> | 2014-01-23 00:56:41 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2014-01-30 10:17:15 +0100 |
| commit | f48eb6b15fee66e54b488d71738979fc608f25ee (patch) | |
| tree | 22be2f2780909d8d61df125b29de5f3f60e52e97 | |
| parent | 13968d9aa9990d53999b14494ed55c2d68d4ead5 (diff) | |
Use -Wformat=2 by default for all files.
This just makes sure that all format strings are given as literals to
printf like functions so the compiler can see and check them. Remove
all no_Wformat, add -Wformat=2 unconditionally to AM_CFLAGS.
Signed-off-by: Mark Wielaard <[email protected]>
| -rw-r--r-- | backends/ChangeLog | 10 | ||||
| -rw-r--r-- | backends/Makefile.am | 3 | ||||
| -rw-r--r-- | backends/aarch64_regs.c | 30 | ||||
| -rw-r--r-- | config/ChangeLog | 4 | ||||
| -rw-r--r-- | config/eu.am | 5 | ||||
| -rw-r--r-- | src/ChangeLog | 18 | ||||
| -rw-r--r-- | src/Makefile.am | 6 | ||||
| -rw-r--r-- | src/nm.c | 93 | ||||
| -rw-r--r-- | src/size.c | 30 | ||||
| -rw-r--r-- | src/strings.c | 33 | ||||
| -rw-r--r-- | tests/ChangeLog | 4 | ||||
| -rw-r--r-- | tests/Makefile.am | 1 |
12 files changed, 145 insertions, 92 deletions
diff --git a/backends/ChangeLog b/backends/ChangeLog index a742eb25..0df68195 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,13 @@ +2014-01-22 Mark Wielaard <[email protected]> + + * Makefile.am (aarch64_regs_no_Wformat): Removed. + * aarch64_regs.c (regtype): Add bool nr argument. snprintf arg + when nr is true. + (regtyper): New function. + (regtypen): Likewise. + (aarch64_register_info): Call either regtyper or regtypen not + regtype directly. + 2014-01-14 Mark Wielaard <[email protected]> * aarch64_symbol.c (aarch64_check_special_symbol): Check shdr is diff --git a/backends/Makefile.am b/backends/Makefile.am index b8bea36b..90e93a88 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to create Makefile.in ## -## Copyright (C) 2000-2010, 2013 Red Hat, Inc. +## Copyright (C) 2000-2010, 2013, 2014 Red Hat, Inc. ## Copyright (C) 2012 Tilera Corporation ## This file is part of elfutils. ## @@ -86,7 +86,6 @@ aarch64_SRCS = aarch64_init.c aarch64_regs.c aarch64_symbol.c \ aarch64_corenote.c aarch64_retval.c aarch64_cfi.c libebl_aarch64_pic_a_SOURCES = $(aarch64_SRCS) am_libebl_aarch64_pic_a_OBJECTS = $(aarch64_SRCS:.c=.os) -aarch64_regs_no_Wformat = yes sparc_SRCS = sparc_init.c sparc_symbol.c sparc_regs.c sparc_retval.c \ sparc_corenote.c sparc64_corenote.c sparc_auxv.c diff --git a/backends/aarch64_regs.c b/backends/aarch64_regs.c index aec201f3..bd10c464 100644 --- a/backends/aarch64_regs.c +++ b/backends/aarch64_regs.c @@ -1,5 +1,5 @@ /* Register names and numbers for AArch64 DWARF. - Copyright (C) 2013 Red Hat, Inc. + Copyright (C) 2013, 2014 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -47,32 +47,48 @@ aarch64_register_info (Ebl *ebl __attribute__ ((unused)), return 128; ssize_t - regtype (const char *setname, int type, const char *fmt, int arg) + regtype (const char *setname, int type, const char *rname, bool nr, int arg) { *setnamep = setname; *typep = type; - int s = snprintf (name, namelen, fmt, arg); + int s; + if (nr) + s = snprintf (name, namelen, "%s%d", rname, arg); + else + s = snprintf (name, namelen, "%s", rname); if (s < 0 || (unsigned) s >= namelen) return -1; return s + 1; } + ssize_t + regtyper (const char *setname, int type, const char *rname) + { + return regtype (setname, type, rname, false, 0); + } + + ssize_t + regtypen (const char *setname, int type, const char *rname, int arg) + { + return regtype (setname, type, rname, true, arg); + } + *prefix = ""; *bits = 64; switch (regno) { case 0 ... 30: - return regtype ("integer", DW_ATE_signed, "x%d", regno); + return regtypen ("integer", DW_ATE_signed, "x", regno); case 31: - return regtype ("integer", DW_ATE_address, "sp", 0); + return regtyper ("integer", DW_ATE_address, "sp"); case 32: return 0; case 33: - return regtype ("integer", DW_ATE_address, "elr", 0); + return regtyper ("integer", DW_ATE_address, "elr"); case 34 ... 63: return 0; @@ -84,7 +100,7 @@ aarch64_register_info (Ebl *ebl __attribute__ ((unused)), integers. 128-bit quad-word is the only singular value that covers the whole register, so mark the register thus. */ *bits = 128; - return regtype ("FP/SIMD", DW_ATE_unsigned, "v%d", regno - 64); + return regtypen ("FP/SIMD", DW_ATE_unsigned, "v", regno - 64); case 96 ... 127: return 0; diff --git a/config/ChangeLog b/config/ChangeLog index 53fddec6..0fca489a 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,7 @@ +2014-01-22 Mark Wielaard <[email protected]> + + * eu.am (AM_CFLAGS): Unconditionally add -Wformat=2. + 2014-01-03 Mark Wielaard <[email protected]> * elfutils.spec.in: Update for 0.158. diff --git a/config/eu.am b/config/eu.am index 38718c7f..d2b4e795 100644 --- a/config/eu.am +++ b/config/eu.am @@ -1,6 +1,6 @@ ## Common automake fragments for elfutils subdirectory makefiles. ## -## Copyright (C) 2010 Red Hat, Inc. +## Copyright (C) 2010, 2014 Red Hat, Inc. ## ## This file is part of elfutils. ## @@ -31,10 +31,9 @@ DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"${localedir}"' AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_srcdir)/lib -I.. -AM_CFLAGS = -std=gnu99 -Wall -Wshadow \ +AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \ $(if $($(*F)_no_Werror),,-Werror) \ $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \ - $(if $($(*F)_no_Wformat),-Wno-format,-Wformat=2) \ $($(*F)_CFLAGS) if MUDFLAP diff --git a/src/ChangeLog b/src/ChangeLog index 26a607d8..134ad905 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,21 @@ +2014-01-22 Mark Wielaard <[email protected]> + + * Makefile.am (nm_no_Wformat): Removed. + (size_no_Wformat): Likewise. + (strings_no_Wformat): Likewise. + (addr2line_no_Wformat): Likewise. + * size.c (show_sysv): Use fmtstr directly as literal in printf. + (show_sysv_one_line): Likewise. + * strings.c (locfmt): Removed. + (radix): New static enum. + (parse_opt): Set radix, not locfmt. + (process_chunk_mb): Use fmtstr directly as literal in printf based + on radix. + (process_chunk): Likewise. + * nm.c (show_symbols_sysv): Use fmtstr directly as literal in printf. + (show_symbols_bsd): Likewise. + (show_symbols_posix): Likewise. + 2014-01-21 Mark Wielaard <[email protected]> * stack.c (show_inlines): New static boolean. diff --git a/src/Makefile.am b/src/Makefile.am index 9a78348f..e3711608 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to create Makefile.in ## -## Copyright (C) 1996-2013 Red Hat, Inc. +## Copyright (C) 1996-2014 Red Hat, Inc. ## This file is part of elfutils. ## ## This file is free software; you can redistribute it and/or modify @@ -88,10 +88,6 @@ if DEMANGLE demanglelib = -lstdc++ endif -nm_no_Wformat = yes -size_no_Wformat = yes -strings_no_Wformat = yes -addr2line_no_Wformat = yes # XXX While the file is not finished, don't warn about this ldgeneric_no_Wunused = yes @@ -1,5 +1,5 @@ /* Print symbol information from ELF file in human-readable form. - Copyright (C) 2000-2008, 2009, 2011, 2012 Red Hat, Inc. + Copyright (C) 2000-2008, 2009, 2011, 2012, 2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper <[email protected]>, 2000. @@ -794,15 +794,6 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char *fullname, /* TRANS: the "sysv|" parts makes the string unique. */ longest_where, sgettext ("sysv|Line")); - /* Which format string to use (different radix for numbers). */ - const char *number_fmtstr; - if (radix == radix_hex) - number_fmtstr = "%0*" PRIx64; - else if (radix == radix_decimal) - number_fmtstr = "%0*" PRId64; - else - number_fmtstr = "%0*" PRIo64; - #ifdef USE_DEMANGLE size_t demangle_buffer_len = 0; char *demangle_buffer = NULL; @@ -850,9 +841,15 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char *fullname, addressbuf[0] = sizebuf[0] = '\0'; else { - snprintf (addressbuf, sizeof (addressbuf), number_fmtstr, + snprintf (addressbuf, sizeof (addressbuf), + (radix == radix_hex ? "%0*" PRIx64 + : (radix == radix_decimal ? "%0*" PRId64 + : "%0*" PRIo64)), digits, syms[cnt].sym.st_value); - snprintf (sizebuf, sizeof (sizebuf), number_fmtstr, + snprintf (sizebuf, sizeof (sizebuf), + (radix == radix_hex ? "%0*" PRIx64 + : (radix == radix_decimal ? "%0*" PRId64 + : "%0*" PRIo64)), digits, syms[cnt].sym.st_size); } @@ -929,19 +926,6 @@ show_symbols_bsd (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx, if (prefix != NULL && ! print_file_name) printf ("\n%s:\n", fname); - static const char *const fmtstrs[] = - { - [radix_hex] = "%6$s%2$0*1$" PRIx64 "%8$s %7$s%3$c%4$s %5$s", - [radix_decimal] = "%6$s%*" PRId64 "%8$s %7$s%3$c%4$s %5$s", - [radix_octal] = "%6$s%2$0*1$" PRIo64 "%8$s %7$s%3$c%4$s %5$s" - }; - static const char *const sfmtstrs[] = - { - [radix_hex] = "%6$s%2$0*1$" PRIx64 "%8$s %10$0*9$" PRIx64 " %7$s%3$c%4$s %5$s", - [radix_decimal] = "%6$s%2$*1$" PRId64 "%8$s %10$*9$" PRId64 " %7$s%3$c%4$s %5$s", - [radix_octal] = "%6$s%2$0*1$" PRIo64 "%8$s %10$0*9$" PRIo64 " %7$s%3$c%4$s %5$s" - }; - #ifdef USE_DEMANGLE size_t demangle_buffer_len = 0; char *demangle_buffer = NULL; @@ -1016,16 +1000,41 @@ show_symbols_bsd (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx, else color = color_symbol; } - - printf (print_size && syms[cnt].sym.st_size != 0 - ? sfmtstrs[radix] : fmtstrs[radix], - digits, syms[cnt].sym.st_value, - class_type_char (elf, ehdr, &syms[cnt].sym), marker, - symstr, - color_mode ? color_address : "", - color, - color_mode ? color_off : "", - digits, (uint64_t) syms[cnt].sym.st_size); + if (print_size && syms[cnt].sym.st_size != 0) + { +#define HEXFMT "%6$s%2$0*1$" PRIx64 "%8$s %10$0*9$" PRIx64 " %7$s%3$c%4$s %5$s" +#define DECFMT "%6$s%2$*1$" PRId64 "%8$s %10$*9$" PRId64 " %7$s%3$c%4$s %5$s" +#define OCTFMT "%6$s%2$0*1$" PRIo64 "%8$s %10$0*9$" PRIo64 " %7$s%3$c%4$s %5$s" + printf ((radix == radix_hex ? HEXFMT + : (radix == radix_decimal ? DECFMT : OCTFMT)), + digits, syms[cnt].sym.st_value, + class_type_char (elf, ehdr, &syms[cnt].sym), marker, + symstr, + color_mode ? color_address : "", + color, + color_mode ? color_off : "", + digits, (uint64_t) syms[cnt].sym.st_size); +#undef HEXFMT +#undef DECFMT +#undef OCTFMT + } + else + { +#define HEXFMT "%6$s%2$0*1$" PRIx64 "%8$s %7$s%3$c%4$s %5$s" +#define DECFMT "%6$s%2$*1$" PRId64 "%8$s %7$s%3$c%4$s %5$s" +#define OCTFMT "%6$s%2$0*1$" PRIo64 "%8$s %7$s%3$c%4$s %5$s" + printf ((radix == radix_hex ? HEXFMT + : (radix == radix_decimal ? DECFMT : OCTFMT)), + digits, syms[cnt].sym.st_value, + class_type_char (elf, ehdr, &syms[cnt].sym), marker, + symstr, + color_mode ? color_address : "", + color, + color_mode ? color_off : ""); +#undef HEXFMT +#undef DECFMT +#undef OCTFMT + } } if (color_mode) @@ -1047,14 +1056,6 @@ show_symbols_posix (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx, if (prefix != NULL && ! print_file_name) printf ("%s:\n", fullname); - const char *fmtstr; - if (radix == radix_hex) - fmtstr = "%s %c%s %0*" PRIx64 " %0*" PRIx64 "\n"; - else if (radix == radix_decimal) - fmtstr = "%s %c%s %*" PRId64 " %*" PRId64 "\n"; - else - fmtstr = "%s %c%s %0*" PRIo64 " %0*" PRIo64 "\n"; - int digits = length_map[gelf_getclass (elf) - 1][radix]; #ifdef USE_DEMANGLE @@ -1096,7 +1097,11 @@ show_symbols_posix (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx, putchar_unlocked (' '); } - printf (fmtstr, + printf ((radix == radix_hex + ? "%s %c%s %0*" PRIx64 " %0*" PRIx64 "\n" + : (radix == radix_decimal + ? "%s %c%s %*" PRId64 " %*" PRId64 "\n" + : "%s %c%s %0*" PRIo64 " %0*" PRIo64 "\n")), symstr, class_type_char (elf, ehdr, &syms[cnt].sym), mark_special @@ -1,5 +1,5 @@ /* Print size information from ELF file. - Copyright (C) 2000-2007,2009,2012 Red Hat, Inc. + Copyright (C) 2000-2007,2009,2012,2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper <[email protected]>, 2000. @@ -441,14 +441,6 @@ show_sysv (Elf *elf, const char *prefix, const char *fname, digits - 2, sgettext ("sysv|size"), digits, sgettext ("sysv|addr")); - const char *fmtstr; - if (radix == radix_hex) - fmtstr = "%-*s %*" PRIx64 " %*" PRIx64 "\n"; - else if (radix == radix_decimal) - fmtstr = "%-*s %*" PRId64 " %*" PRId64 "\n"; - else - fmtstr = "%-*s %*" PRIo64 " %*" PRIo64 "\n"; - /* Iterate over all sections. */ GElf_Off total = 0; while ((scn = elf_nextscn (elf, scn)) != NULL) @@ -459,7 +451,11 @@ show_sysv (Elf *elf, const char *prefix, const char *fname, /* Ignore all sections which are not used at runtime. */ if ((shdr->sh_flags & SHF_ALLOC) != 0) { - printf (fmtstr, + printf ((radix == radix_hex + ? "%-*s %*" PRIx64 " %*" PRIx64 "\n" + : (radix == radix_decimal + ? "%-*s %*" PRId64 " %*" PRId64 "\n" + : "%-*s %*" PRIo64 " %*" PRIo64 "\n")), maxlen, elf_strptr (elf, shstrndx, shdr->sh_name), digits - 2, shdr->sh_size, digits, shdr->sh_addr); @@ -490,14 +486,6 @@ show_sysv_one_line (Elf *elf) error (EXIT_FAILURE, 0, gettext ("cannot get section header string table index")); - const char *fmtstr; - if (radix == radix_hex) - fmtstr = "%" PRIx64 "(%s)"; - else if (radix == radix_decimal) - fmtstr = "%" PRId64 "(%s)"; - else - fmtstr = "%" PRIo64 "(%s)"; - /* Iterate over all sections. */ GElf_Off total = 0; bool first = true; @@ -515,8 +503,10 @@ show_sysv_one_line (Elf *elf) fputs_unlocked (" + ", stdout); first = false; - printf (fmtstr, shdr->sh_size, - elf_strptr (elf, shstrndx, shdr->sh_name)); + printf ((radix == radix_hex ? "%" PRIx64 "(%s)" + : (radix == radix_decimal ? "%" PRId64 "(%s)" + : "%" PRIo64 "(%s)")), + shdr->sh_size, elf_strptr (elf, shstrndx, shdr->sh_name)); total += shdr->sh_size; } diff --git a/src/strings.c b/src/strings.c index 084eb999..37210a74 100644 --- a/src/strings.c +++ b/src/strings.c @@ -1,5 +1,5 @@ /* Print the strings of printable characters in files. - Copyright (C) 2005-2010, 2012 Red Hat, Inc. + Copyright (C) 2005-2010, 2012, 2014 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper <[email protected]>, 2005. @@ -116,8 +116,15 @@ static bool char_7bit; /* True if file names should be printed before strings. */ static bool print_file_name; -/* Location print format string. */ -static const char *locfmt; +/* Radix for printed numbers. */ +static enum +{ + radix_none = 0, + radix_decimal, + radix_hex, + radix_octal +} radix = radix_none; + /* Page size in use. */ static size_t ps; @@ -279,16 +286,16 @@ parse_opt (int key, char *arg, switch (arg[0]) { case 'd': - locfmt = "%7" PRId64 " "; + radix = radix_decimal; break; case 'o': octfmt: - locfmt = "%7" PRIo64 " "; + radix = radix_octal; break; case 'x': - locfmt = "%7" PRIx64 " "; + radix = radix_hex; break; default: @@ -355,8 +362,11 @@ process_chunk_mb (const char *fname, const unsigned char *buf, off64_t to, fputs_unlocked (": ", stdout); } - if (unlikely (locfmt != NULL)) - printf (locfmt, (int64_t) to - len - (buf - start)); + if (unlikely (radix != radix_none)) + printf ((radix == radix_octal ? "%7" PRIo64 " " + : (radix == radix_decimal ? "%7" PRId64 " " + : "%7" PRIx64 " ")), + (int64_t) to - len - (buf - start)); if (unlikely (*unprinted != NULL)) { @@ -420,8 +430,11 @@ process_chunk (const char *fname, const unsigned char *buf, off64_t to, fputs_unlocked (": ", stdout); } - if (likely (locfmt != NULL)) - printf (locfmt, (int64_t) to - len - (buf - start)); + if (likely (radix != radix_none)) + printf ((radix == radix_octal ? "%7" PRIo64 " " + : (radix == radix_decimal ? "%7" PRId64 " " + : "%7" PRIx64 " ")), + (int64_t) to - len - (buf - start)); if (unlikely (*unprinted != NULL)) { diff --git a/tests/ChangeLog b/tests/ChangeLog index aa468c44..cbf26725 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2014-01-22 Mark Wielaard <[email protected]> + + * Makefile.am (line2addr_no_Wformat): Removed. + 2014-01-21 Mark Wielaard <[email protected]> * Makefile.am (TESTS): Add run-stack-i-test.sh. diff --git a/tests/Makefile.am b/tests/Makefile.am index aa13cfa3..c75e7969 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -355,7 +355,6 @@ get_lines_LDADD = $(libdw) $(libelf) $(libmudflap) get_files_LDADD = $(libdw) $(libelf) $(libmudflap) get_aranges_LDADD = $(libdw) $(libelf) $(libmudflap) allfcts_LDADD = $(libdw) $(libelf) $(libmudflap) -line2addr_no_Wformat = yes line2addr_LDADD = $(libdw) $(libmudflap) addrscopes_LDADD = $(libdw) $(libmudflap) funcscopes_LDADD = $(libdw) $(libmudflap) |
