When I compile bingutils-gdb with gcc7 I get the following warnings: In file included from /git/binutils-gdb/bfd/coff-i386.c:614:0, from /git/binutils-gdb/bfd/pei-i386.c:45: /git/binutils-gdb/bfd/coffcode.h: In function ‘coff_write_object_contents’: /git/binutils-gdb/bfd/coffcode.h:3775:46: error: ‘%lu’ directive output may be truncated writing between 1 and 20 bytes into a region of size 8 [-Werror=format-truncation=] snprintf (s_name_buf, SCNNMLEN + 1, "/%lu", (unsigned long) string_size); ^~~ /git/binutils-gdb/bfd/coffcode.h:3775:44: note: directive argument in the range [4, 18446744073709551614] snprintf (s_name_buf, SCNNMLEN + 1, "/%lu", (unsigned long) string_size); ^~~~~~ /git/binutils-gdb/bfd/coffcode.h:3775:8: note: format output between 3 and 22 bytes into a destination of size 9 snprintf (s_name_buf, SCNNMLEN + 1, "/%lu", (unsigned long) string_size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[2]: *** [Makefile:1688: pei-i386.lo] Error 1 /git/binutils-gdb/bfd/elf32-nds32.c: In function ‘nds32_elf_pick_relax’: /git/binutils-gdb/bfd/elf32-nds32.c:14976:27: error: ‘%08lx’ directive output may be truncated writing between 8 and 16 bytes into a region of size 9 [-Werror=format-truncation=] snprintf (code, 9, "%08lx", insn); ^~~~~ /git/binutils-gdb/bfd/elf32-nds32.c:14976:26: note: using the range [1, 18446744073709551615] for directive argument snprintf (code, 9, "%08lx", insn); ^~~~~~~ /git/binutils-gdb/bfd/elf32-nds32.c:14976:7: note: format output between 9 and 17 bytes into a destination of size 9 snprintf (code, 9, "%08lx", insn); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[2]: *** [Makefile:1688: elf32-nds32.lo] Error 1 /git/binutils-gdb/opcodes/aarch64-opc.c: In function ‘print_register_offset_address’: /git/binutils-gdb/opcodes/aarch64-opc.c:2967:29: error: ‘%li’ directive output may be truncated writing between 1 and 20 bytes into a region of size 12 [-Werror=format-truncation=] snprintf (tb, sizeof (tb), ", %s #%" PRIi64, shift_name, ^~~~~~~~~ /git/binutils-gdb/opcodes/aarch64-opc.c:2967:36: note: format string is defined here snprintf (tb, sizeof (tb), ", %s #%" PRIi64, shift_name, /git/binutils-gdb/opcodes/aarch64-opc.c:2967:29: note: using the range [1, -9223372036854775808] for directive argument snprintf (tb, sizeof (tb), ", %s #%" PRIi64, shift_name, ^~~~~~~~~ /git/binutils-gdb/opcodes/aarch64-opc.c:2967:2: note: format output between 6 and 25 bytes into a destination of size 16 snprintf (tb, sizeof (tb), ", %s #%" PRIi64, shift_name, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ opnd->shifter.amount); ~~~~~~~~~~~~~~~~~~~~~ /git/binutils-gdb/opcodes/aarch64-opc.c: In function ‘print_register_list’: /git/binutils-gdb/opcodes/aarch64-opc.c:2868:22: error: ‘%li’ directive output may be truncated writing between 1 and 20 bytes into a region of size 7 [-Werror=format-truncation=] snprintf (tb, 8, "[%" PRIi64 "]", opnd->reglist.index); ^~~~ /git/binutils-gdb/opcodes/aarch64-opc.c:2868:24: note: format string is defined here snprintf (tb, 8, "[%" PRIi64 "]", opnd->reglist.index); /git/binutils-gdb/opcodes/aarch64-opc.c:2868:22: note: using the range [1, -9223372036854775808] for directive argument snprintf (tb, 8, "[%" PRIi64 "]", opnd->reglist.index); ^~~~ /git/binutils-gdb/opcodes/aarch64-opc.c:2868:5: note: format output between 4 and 23 bytes into a destination of size 8 snprintf (tb, 8, "[%" PRIi64 "]", opnd->reglist.index); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[2]: *** [Makefile:1003: aarch64-opc.lo] Error 1 make[1]: *** [Makefile:1046: all-recursive] Error 1 make: *** [Makefile:693: all] Error 2
Created attachment 9787 [details] Proposed patch Hi Dilyan, Please could you try out this patch and let me know if it works. Thanks. Cheers Nick
Wouldn't it be better to remove this warning from Werror until and unless gcc can be fixed to not give so many false positives?
(In reply to Alan Modra from comment #2) > Wouldn't it be better to remove this warning from Werror until and unless > gcc can be fixed to not give so many false positives? Overall I think that the warning is useful, and it will certainly help prevent future bugs of this type. The fixes I have proposed are quite simple, and there are only four places where the binutils appear to be affected, so the price seems quite small to me.
It works, but there is one more warning: make[4]: Entering directory '/home/d/binutils/opcodes' /bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I/git/binutils-gdb/opcodes -I. -I/git/binutils-gdb/opcodes -I../bfd -I/git/binutils-gdb/opcodes/../include -I/git/binutils-gdb/opcodes/../bfd -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -Werror -g -O2 -MT tic6x-dis.lo -MD -MP -MF .deps/tic6x-dis.Tpo -c -o tic6x-dis.lo /git/binutils-gdb/opcodes/tic6x-dis.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/git/binutils-gdb/opcodes -I. -I/git/binutils-gdb/opcodes -I../bfd -I/git/binutils-gdb/opcodes/../include -I/git/binutils-gdb/opcodes/../bfd -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -Werror -g -O2 -MT tic6x-dis.lo -MD -MP -MF .deps/tic6x-dis.Tpo -c /git/binutils-gdb/opcodes/tic6x-dis.c -o tic6x-dis.o /git/binutils-gdb/opcodes/tic6x-dis.c: In function ‘print_insn_tic6x’: /git/binutils-gdb/opcodes/tic6x-dis.c:706:32: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=] snprintf (func_unit_buf, 7, " .%c%u%s%s", func_unit_char, ^~~~~~~~~~~~ /git/binutils-gdb/opcodes/tic6x-dis.c:706:4: note: ‘snprintf’ output between 5 and 8 bytes into a destination of size 7 snprintf (func_unit_buf, 7, " .%c%u%s%s", func_unit_char, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ func_unit_side, (func_unit_cross ? "X" : ""), data_str); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[4]: *** [Makefile:1003: tic6x-dis.lo] Error 1 make[4]: Target 'all-am' not remade because of errors.
Created attachment 9791 [details] Proposed patch Hi Dilyan, OK, please try this updated patch and let me know if it gets them all. Cheers Nick
The second patch eliminates all warnings.
The master branch has been updated by Nick Clifton <nickc@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1b7e3d2fb7036ce6f9d74e32dc052518f5cd45b6 commit 1b7e3d2fb7036ce6f9d74e32dc052518f5cd45b6 Author: Nick Clifton <nickc@redhat.com> Date: Fri Feb 3 09:04:21 2017 +0000 Fix compile time warning messages when compiling binutils with gcc 7.0.1. PR 21096 bfd * coffcode.h (coff_write_object_contents): Enlarge size of s_name_buf in order to avoid compile time warning about possible integer truncation. * elf32-nds32.c (nds32_elf_ex9_import_table): Mask off lower 32-bits of insn value before printing into buffer. opcodes * aarch64-opc.c (print_register_list): Ensure that the register list index will fir into the tb buffer. (print_register_offset_address): Likewise. * tic6x-dis.c (print_insn_tic6x): Increase size of func_unit_buf.
Patch applied.