On Linux readelf fails to build with a "-Werror=format-truncation=" error, since "-Werror" is added to the build flags.
all ===> readelf
cc -O2 -Wno-error -I. -I/home/djcj/Downloads/elftoolchain-code/readelf -I/home/djcj/Downloads/elftoolchain-code/readelf/../common -I/home/djcj/Downloads/elftoolchain-code/readelf/../libdwarf -I/home/djcj/Downloads/elftoolchain-code/readelf/../libelf -I/home/djcj/Downloads/elftoolchain-code/readelf/../libelftc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-uninitialized -Wreturn-type -Wcast-qual -Wpointer-arith -Wwrite-strings -Wswitch -Wshadow -Werror -c readelf.c
readelf.c: In function ‘get_regoff_str’:
readelf.c:6071:43: error: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size 16 [-Werror=format-truncation=]
6071 | snprintf(rs, sizeof(rs), "%s%+jd", dwarf_regname(re, reg),
| ^~
readelf.c:6071:42: note: using the range [-9223372036854775808, 9223372036854775807] for directive argument
6071 | snprintf(rs, sizeof(rs), "%s%+jd", dwarf_regname(re, reg),
| ^~~~~~~~
In file included from /usr/include/stdio.h:894,
from readelf.c:42:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 3 and 52 bytes into a destination of size 16
71 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
*** Error code 1
Stop.****
Changing the buffer size in the function get_regoff_str from 16 to 64 did it for me.
OS: Ubuntu 22.04
Compiler: GCC 11.4.0
Thanks for the bug report.
The Elftoolchain tree doesn't build out of the box on Ubuntu 22.04 and gcc 11 (
/usr/share/mk/bsd.lib.mk
from thebmake
package seems to need a patch).That said, [r4020] should hopefully fix this particular issue.
Related
Commit: [r4020]