Bug 21096 - gcc7 warnings
Summary: gcc7 warnings
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-31 17:50 UTC by dilyan.palauzov@aegee.org
Modified: 2017-02-03 09:06 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch (1.37 KB, patch)
2017-02-01 10:26 UTC, Nick Clifton
Details | Diff
Proposed patch (1.65 KB, patch)
2017-02-02 10:59 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description dilyan.palauzov@aegee.org 2017-01-31 17:50:36 UTC
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
Comment 1 Nick Clifton 2017-02-01 10:26:27 UTC
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
Comment 2 Alan Modra 2017-02-01 12:06:55 UTC
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?
Comment 3 Nick Clifton 2017-02-01 12:33:02 UTC
(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.
Comment 4 dilyan.palauzov@aegee.org 2017-02-01 19:39:07 UTC
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.
Comment 5 Nick Clifton 2017-02-02 10:59:53 UTC
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
Comment 6 dilyan.palauzov@aegee.org 2017-02-02 19:29:35 UTC
The second patch eliminates all warnings.
Comment 7 Sourceware Commits 2017-02-03 09:05:55 UTC
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.
Comment 8 Nick Clifton 2017-02-03 09:06:23 UTC
Patch applied.