On 19.01.17 00:33, Jeff Law wrote:
On 01/18/2017 11:43 AM, Andreas Tobler wrote:
Hi all,
I have the following issue here on aarch64-*-freebsd:
(sorry if the format is hardly readable)
......
/export/devel/net/src/gcc/head/gcc/gcc/config/aarch64/aarch64.c: In
function 'void aarch64_elf_asm_destructor(rtx, int)':
/export/devel/net/src/gcc/head/gcc/gcc/config/aarch64/aarch64.c:5760:1:
error: %.5u' directive output may be truncated writing between 5 and 10
bytes into a region of size 6 [-Werror=format-truncation=]
aarch64_elf_asm_destructor (rtx symbol, int priority)
^~~~~~~~~~~~~~~~~~~~~~~~~~
/export/devel/net/src/gcc/head/gcc/gcc/config/aarch64/aarch64.c:5760:1:
note: using the range [1, 4294967295] for directive argument
/export/devel/net/src/gcc/head/gcc/gcc/config/aarch64/aarch64.c:5768:65:
note: format output between 18 and 23 bytes into a destination of size 18
snprintf (buf, sizeof (buf), ".fini_array.%.5u", priority);
^
.......
This is the code snippet, it does not only occur in aarch64, but also at
least in pa and avr.
----
static void
aarch64_elf_asm_destructor (rtx symbol, unsigned short priority)
{
if (priority == DEFAULT_INIT_PRIORITY)
default_dtor_section_asm_out_destructor (symbol, priority);
else
{
section *s;
char buf[18];
snprintf (buf, sizeof (buf), ".fini_array.%.5u", priority);
s = get_section (buf, SECTION_WRITE, NULL);
switch_to_section (s);
assemble_align (POINTER_SIZE);
assemble_aligned_integer (POINTER_BYTES, symbol);
}
}
----
I have now four options to solve this, (a fifth one would be to remove
format-truncation from -Wall/Wextra?)
1.) increase buf to 23
2.) use %.5hu in snprintf
3.) cast priority in snprintf to (unsigned int)
4.) make priority unsigned short.
Solution 1, 2 and 3 work, but with pros and cons.
#3 likely won't work with with lower optimization levels since it
depends on VRP to narrow the object's range.
I'd approve #2 or #1 without hesitation.
Ok.
I did a mistake while describing the situation. The function has this
parameter:
aarch64_elf_asm_destructor (rtx symbol, int priority)
I copied the already modified piece of code....
So the cast in #3 would be (unsigned short) iso (unsigned int).
If no other opinions come up I'll go with #2.
Thanks.
Andreas