Bug 79033 - asan.c not compiling with make BOOT_CFLAGS='-O0' (or '-O1')
Summary: asan.c not compiling with make BOOT_CFLAGS='-O0' (or '-O1')
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Martin Sebor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-09 18:12 UTC by lkrupp
Modified: 2017-01-09 20:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-01-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lkrupp 2017-01-09 18:12:35 UTC
When building with:

make BOOT_CFLAGS='-O0' (or '-O1')

This command:

/home/louis/gcc_obj/./prev-gcc/xg++ -B/home/louis/gcc_obj/./prev-gcc/ -B/home/louis/gcc_inst/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -B/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs  -I/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu  -I/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/include  -I/home/louis/gcc_trunk/libstdc++-v3/libsupc++ -L/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -fno-PIE -c   -O1 -gtoggle -DIN_GCC     -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -fno-common  -DHAVE_CONFIG_H -I. -I. -I../../gcc_trunk/gcc -I../../gcc_trunk/gcc/. -I../../gcc_trunk/gcc/../include -I../../gcc_trunk/gcc/../libcpp/include  -I../../gcc_trunk/gcc/../libdecnumber -I../../gcc_trunk/gcc/../libdecnumber/bid -I../libdecnumber -I../../gcc_trunk/gcc/../libbacktrace   -o asan.o -MT asan.o -MMD -MP -MF ./.deps/asan.TPo ../../gcc_trunk/gcc/asan.c

gets this error:

../../gcc_trunk/gcc/asan.c:1065:1: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 10 [-Werror=format-truncation=]
 asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb,
 ^~~~~~~~~~~~~~~~~~~~~~~~~~
../../gcc_trunk/gcc/asan.c:1065:1: note: using the range [1, -2147483648] for directive argument
../../gcc_trunk/gcc/asan.c:1163:26: note: format output between 22 and 32 bytes into a destination of size 30
   use_after_return_class);

The problem is with this code:

1071   char buf[30];
...
1080   int use_after_return_class = -1;
...
1162       snprintf (buf, sizeof buf, "__asan_stack_malloc_%d",
1163                 use_after_return_class);

If use_after_return_class is in fact a negative 10-digit number, buf would overflow. With -O2, the compiler presumably knows more about the value of use_after_return_class, and asan.c compiles without errors.

Changing buf to an array of length 31 makes the error go away, but I believe the length should be 32 to leave room for the terminating null byte.
Comment 1 Martin Sebor 2017-01-09 18:52:12 UTC
Confirmed.  The warning is the result of splitting -Wformat-truncation out of the -Wformat-length warning in r244210.  Based on the note ("format output between 22 and 32 bytes") 32 sounds like the right size.  Let me do a build with BOOT_CFLAGS='-O0' to see if there are  any other problems and fix them all.
Comment 2 Martin Sebor 2017-01-09 20:09:21 UTC
Author: msebor
Date: Mon Jan  9 20:08:49 2017
New Revision: 244237

URL: https://gcc.gnu.org/viewcvs?rev=244237&root=gcc&view=rev
Log:
PR bootstrap/79033 - asan.c not compiling with make BOOT_CFLAGS=-O0

gcc/ChangeLog:
	* asan.c (asan_emit_stack_protection): Increase local buffer size
	to avoid snprintf truncation warning.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/asan.c
Comment 3 Martin Sebor 2017-01-09 20:12:52 UTC
Trivial fix committed in r244237.