Skip to content

compile error #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ThomasWaldmann opened this issue Mar 11, 2018 · 6 comments
Open

compile error #7

ThomasWaldmann opened this issue Mar 11, 2018 · 6 comments

Comments

@ThomasWaldmann
Copy link

/bin/bash ./libtool --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -I./../include  -DHAVE_x86_64_elf64_vec -DHAVE_i386_elf32_vec -DHAVE_iamcu_elf32_vec -DHAVE_x86_64_elf32_vec -DHAVE_i386_aout_linux_vec -DHAVE_i386_pei_vec -DHAVE_x86_64_pei_vec -DHAVE_l1om_elf64_vec -DHAVE_k1om_elf64_vec -DHAVE_elf64_le_vec -DHAVE_elf64_be_vec -DHAVE_elf32_le_vec -DHAVE_elf32_be_vec -DHAVE_plugin_vec  -DBINDIR='"/usr/local/bin"'  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -Werror -I./../zlib -g -O2 -MT pei-i386.lo -MD -MP -MF .deps/pei-i386.Tpo -c -o pei-i386.lo pei-i386.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -I. -I./../include -DHAVE_x86_64_elf64_vec -DHAVE_i386_elf32_vec -DHAVE_iamcu_elf32_vec -DHAVE_x86_64_elf32_vec -DHAVE_i386_aout_linux_vec -DHAVE_i386_pei_vec -DHAVE_x86_64_pei_vec -DHAVE_l1om_elf64_vec -DHAVE_k1om_elf64_vec -DHAVE_elf64_le_vec -DHAVE_elf64_be_vec -DHAVE_elf32_le_vec -DHAVE_elf32_be_vec -DHAVE_plugin_vec -DBINDIR=\"/usr/local/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -Werror -I./../zlib -g -O2 -MT pei-i386.lo -MD -MP -MF .deps/pei-i386.Tpo -c pei-i386.c -o pei-i386.o

In file included from coff-i386.c:614:0,
                 from pei-i386.c:45:
coffcode.h: In function ‘coff_write_object_contents’:
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);
                                              ^~~
coffcode.h:3775:44: note: directive argument in the range [4, 18446744073709551614]
        snprintf (s_name_buf, SCNNMLEN + 1, "/%lu", (unsigned long) string_size);
                                            ^~~~~~
In file included from /usr/include/stdio.h:862:0,
                 from sysdep.h:37,
                 from pei-i386.c:21:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 3 and 22 bytes into a destination of size 9
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
@ThomasWaldmann
Copy link
Author

OS: Ubuntu Linux 18.04 amd64 (pre-release)

I tried current master and d2ae637 commit (the one you used for the offered binaries), the error happens for both.

Any ideas?

@igrr
Copy link
Member

igrr commented Mar 14, 2018

@ThomasWaldmann What arguments are you passing to ./configure?

@ThomasWaldmann
Copy link
Author

None. Should I?

@fivdi
Copy link

fivdi commented Mar 18, 2018

Which version of gcc is being used for compiling? Probably gcc7, is this correct? If so, the compiler is generating the warning because string_size is being cast to an unsigned long which is potentially a 20 digit number (for example, 18446744073709551614) but s_name_buf is a 9 char buffer so gcc thinks the buffer might not be big enough.

Here's the line of code that generates the warning:

	snprintf (s_name_buf, SCNNMLEN + 1, "/%lu", (unsigned long) string_size);

s_name_buf is defined like this in this repository:

	char s_name_buf[SCNNMLEN + 1];

SCNNMLEN is defined like this:

#define SCNNMLEN (8)

As can be seen here, a more up-to-date version of binutils has a fix for the issue:

               /* The s_name field is defined to be NUL-padded but need not be
                  NUL-terminated.  We use a temporary buffer so that we can still
                  sprintf all eight chars without splatting a terminating NUL
                  over the first byte of the following member (s_paddr).  */
               /* PR 21096: The +20 is to stop a bogus warning from gcc7 about
                  a possible buffer overflow.  */
               char s_name_buf[SCNNMLEN + 1 + 20];

@ThomasWaldmann I'd suggest passing the parameters shown here to ./configure unless you have a reason to do otherwise.

@ThomasWaldmann
Copy link
Author

gcc version 7.3.0 (Ubuntu 7.3.0-11ubuntu1)

@Lapshin
Copy link

Lapshin commented Jun 13, 2024

Closing as outdated.

The project is moved to https://github.com/espressif/binutils-gdb repo (branch name pattern esp32ulp-elf-*). Create issue in the new project if found something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants