Bug 78531 - [7 Regression] bootstrap broken with _FORTIFY_SOURCE enabled
Summary: [7 Regression] bootstrap broken with _FORTIFY_SOURCE enabled
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: 7.0
Assignee: Eric Botcazou
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-25 17:28 UTC by Matthias Klose
Modified: 2016-11-27 20:25 UTC (History)
1 user (show)

See Also:
Host:
Target: *-linux-gnu
Build:
Known to work: 6.2.1
Known to fail: 7.0
Last reconfirmed: 2016-11-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2016-11-25 17:28:18 UTC
seen with trunk r242874 on all linux architectures, and this patch to enable the build with -D_FORTIFY_SOURCE=2. This works on the gcc-6-branch, system glibc is 2.24.

--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1176,6 +1176,10 @@ c_cpp_builtins (cpp_reader *pfile)
   builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
   builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
 
+  /* Fortify Source enabled by default for optimization levels > 0 */
+  if (optimize)
+    builtin_define_with_int_value ("_FORTIFY_SOURCE", 2);
+
   /* Misc.  */
   if (flag_gnu89_inline)
     cpp_define (pfile, "__GNUC_GNU_INLINE__");


/<<PKGBUILDDIR>>/build/./prev-gcc/xgcc -B/<<PKGBUILDDIR>>/build/./prev-gcc/ -B/usr/x86_64-linux-gnu/bin/ -B/usr/x86_64-linux-gnu/bin/ -B/usr/x86_64-linux-gnu/lib/ -isystem /usr/x86_64-linux-gnu/include -isystem /usr/x86_64-linux-gnu/sys-include -isystem /<<PKGBUILDDIR>>/build/sys-include    -c -g -O2 -fno-stack-protector  -gnatpg  -W -Wall -nostdinc -I- -I. -Iada/generated -Iada -I../../src/gcc/ada -I../../src/gcc/ada/gcc-interface ../../src/gcc/ada/a-charac.ads -o ada/a-charac.o
*** buffer overflow detected ***: /<<PKGBUILDDIR>>/build/./prev-gcc/gnat1 terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x790cb)[0x7f4945f4a0cb]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x54)[0x7f4945feb2c4]
/lib/x86_64-linux-gnu/libc.so.6(+0x118240)[0x7f4945fe9240]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1[0x6f73c6]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1(gigi+0xcc9)[0x705dc9]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1(back_end__call_back_end+0x1b0)[0x9e8d40]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1(_ada_gnat1drv+0x897)[0x9e9ba7]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1[0x6c866d]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1[0xd7920f]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1(_ZN6toplev4mainEiPPc+0x6ef)[0x6ac8bf]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1(main+0x27)[0x6aec37]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7f4945ef13f1]
/<<PKGBUILDDIR>>/build/./prev-gcc/gnat1(_start+0x2a)[0x6af02a]
======= Memory map: ========
00400000-01df1000 r-xp 00000000 fd:01 530541                             /<<PKGBUILDDIR>>/build/prev-gcc/gnat1
01ff0000-01ff9000 r--p 019f0000 fd:01 530541                             /<<PKGBUILDDIR>>/build/prev-gcc/gnat1
01ff9000-02007000 rw-p 019f9000 fd:01 530541                             /<<PKGBUILDDIR>>/build/prev-gcc/gnat1
02007000-0267f000 rw-p 00000000 00:00 0 
02b53000-02cc2000 rw-p 00000000 00:00 0                                  [heap]
7f4945933000-7f4945949000 r-xp 00000000 fd:01 529904                     /<<PKGBUILDDIR>>/build/prev-gcc/libgcc_s.so.1
7f4945949000-7f4945b48000 ---p 00016000 fd:01 529904                     /<<PKGBUILDDIR>>/build/prev-gcc/libgcc_s.so.1
7f4945b48000-7f4945b49000 r--p 00015000 fd:01 529904                     /<<PKGBUILDDIR>>/build/prev-gcc/libgcc_s.so.1
7f4945b49000-7f4945b4a000 rw-p 00016000 fd:01 529904                     /<<PKGBUILDDIR>>/build/prev-gcc/libgcc_s.so.1
7f4945b4a000-7f4945b63000 rw-p 00000000 00:00 0 
7f4945cd1000-7f4945ed1000 rw-p 00000000 00:00 0 
7f4945ed1000-7f494608e000 r-xp 00000000 fd:01 257285                     /lib/x86_64-linux-gnu/libc-2.24.so
7f494608e000-7f494628e000 ---p 001bd000 fd:01 257285                     /lib/x86_64-linux-gnu/libc-2.24.so
7f494628e000-7f4946292000 r--p 001bd000 fd:01 257285                     /lib/x86_64-linux-gnu/libc-2.24.so
7f4946292000-7f4946294000 rw-p 001c1000 fd:01 257285                     /lib/x86_64-linux-gnu/libc-2.24.so
7f4946294000-7f4946298000 rw-p 00000000 00:00 0 
7f4946298000-7f49463a0000 r-xp 00000000 fd:01 257184                     /lib/x86_64-linux-gnu/libm-2.24.so
7f49463a0000-7f494659f000 ---p 00108000 fd:01 257184                     /lib/x86_64-linux-gnu/libm-2.24.so
7f494659f000-7f49465a0000 r--p 00107000 fd:01 257184                     /lib/x86_64-linux-gnu/libm-2.24.so
7f49465a0000-7f49465a1000 rw-p 00108000 fd:01 257184                     /lib/x86_64-linux-gnu/libm-2.24.so
7f49465a1000-7f49465ba000 r-xp 00000000 fd:01 257301                     /lib/x86_64-linux-gnu/libz.so.1.2.8
7f49465ba000-7f49467b9000 ---p 00019000 fd:01 257301                     /lib/x86_64-linux-gnu/libz.so.1.2.8
7f49467b9000-7f49467ba000 r--p 00018000 fd:01 257301                     /lib/x86_64-linux-gnu/libz.so.1.2.8
7f49467ba000-7f49467bb000 rw-p 00019000 fd:01 257301                     /lib/x86_64-linux-gnu/libz.so.1.2.8
7f49467bb000-7f49467be000 r-xp 00000000 fd:01 257282                     /lib/x86_64-linux-gnu/libdl-2.24.so
7f49467be000-7f49469bd000 ---p 00003000 fd:01 257282                     /lib/x86_64-linux-gnu/libdl-2.24.so
7f49469bd000-7f49469be000 r--p 00002000 fd:01 257282                     /lib/x86_64-linux-gnu/libdl-2.24.so
7f49469be000-7f49469bf000 rw-p 00003000 fd:01 257282                     /lib/x86_64-linux-gnu/libdl-2.24.so
7f49469bf000-7f4946a3e000 r-xp 00000000 fd:01 266273                     /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.1
7f4946a3e000-7f4946c3d000 ---p 0007f000 fd:01 266273                     /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.1
7f4946c3d000-7f4946c3e000 r--p 0007e000 fd:01 266273                     /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.1
7f4946c3e000-7f4946c3f000 rw-p 0007f000 fd:01 266273                     /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.1
7f4946c3f000-7f4946ca2000 r-xp 00000000 fd:01 266354                     /usr/lib/x86_64-linux-gnu/libmpfr.so.4.1.5
7f4946ca2000-7f4946ea1000 ---p 00063000 fd:01 266354                     /usr/lib/x86_64-linux-gnu/libmpfr.so.4.1.5
7f4946ea1000-7f4946ea3000 r--p 00062000 fd:01 266354                     /usr/lib/x86_64-linux-gnu/libmpfr.so.4.1.5
7f4946ea3000-7f4946ea4000 rw-p 00064000 fd:01 266354                     /usr/lib/x86_64-linux-gnu/libmpfr.so.4.1.5
7f4946ea4000-7f4946ebb000 r-xp 00000000 fd:01 266369                     /usr/lib/x86_64-linux-gnu/libmpc.so.3.0.0
7f4946ebb000-7f49470ba000 ---p 00017000 fd:01 266369                     /usr/lib/x86_64-linux-gnu/libmpc.so.3.0.0
7f49470ba000-7f49470bb000 r--p 00016000 fd:01 266369                     /usr/lib/x86_64-linux-gnu/libmpc.so.3.0.0
7f49470bb000-7f49470bc000 rw-p 00017000 fd:01 266369                     /usr/lib/x86_64-linux-gnu/libmpc.so.3.0.0
7f49470bc000-7f494723f000 r-xp 00000000 fd:01 265189                     /usr/lib/x86_64-linux-gnu/libisl.so.15.2.1
7f494723f000-7f494743e000 ---p 00183000 fd:01 265189                     /usr/lib/x86_64-linux-gnu/libisl.so.15.2.1
7f494743e000-7f494743f000 r--p 00182000 fd:01 265189                     /usr/lib/x86_64-linux-gnu/libisl.so.15.2.1
7f494743f000-7f4947441000 rw-p 00183000 fd:01 265189                     /usr/lib/x86_64-linux-gnu/libisl.so.15.2.1
7f4947441000-7f4947466000 r-xp 00000000 fd:01 257196                     /lib/x86_64-linux-gnu/ld-2.24.so
7f49474ea000-7f494751f000 rw-p 00000000 00:00 0 
7f494754c000-7f4947550000 rw-p 00000000 00:00 0 
7f494757d000-7f4947581000 rw-p 00000000 00:00 0 
7f4947595000-7f494765b000 rw-p 00000000 00:00 0 
7f494765b000-7f4947665000 rw-p 00000000 00:00 0 
7f4947665000-7f4947666000 r--p 00024000 fd:01 257196                     /lib/x86_64-linux-gnu/ld-2.24.so
7f4947666000-7f4947667000 rw-p 00025000 fd:01 257196                     /lib/x86_64-linux-gnu/ld-2.24.so
7f4947667000-7f4947668000 rw-p 00000000 00:00 0 
7ffc8a440000-7ffc8a487000 rw-p 00000000 00:00 0                          [stack]
7ffc8a5a0000-7ffc8a5a2000 r--p 00000000 00:00 0                          [vvar]
7ffc8a5a2000-7ffc8a5a4000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
+===========================GNAT BUG DETECTED==============================+
| 7.0.0 20161124 (experimental) [trunk revision 242837] (x86_64-linux-gnu) |
| Program_Error unhandled signal                                           |
| Error detected at system.ads:178:5                                       |
| Please submit a bug report; see http://gcc.gnu.org/bugs.html.            |
| Use a subject line meaningful to you and us to track the bug.            |
| Include the entire contents of this bug box in the report.               |
| Include the exact command that you entered.                              |
| Also include sources listed below.                                       |
+==========================================================================+

Please include these source files with error report
Note that list may not be accurate in some cases,
so please double check that the problem can still
be reproduced with the set of files listed.
Consider also -gnatd.n switch (see debug.adb).

../../src/gcc/ada/system.ads
../../src/gcc/ada/a-charac.ads
../../src/gcc/ada/ada.ads

compilation abandoned
../../src/gcc/ada/gcc-interface/Make-lang.in:119: recipe for target 'ada/a-charac.o' failed
make[5]: *** [ada/a-charac.o] Error 1
Makefile:4655: recipe for target 'all-stage3-gcc' failed
make[4]: *** [all-stage3-gcc] Error 2
make[4]: Leaving directory '/<<PKGBUILDDIR>>/build'
Makefile:26581: recipe for target 'stage3-bubble' failed
make[3]: *** [stage3-bubble] Error 2
make[3]: Leaving directory '/<<PKGBUILDDIR>>/build'
Makefile:26644: recipe for target 'bootstrap' failed
make[2]: *** [bootstrap] Error 2
Comment 1 Eric Botcazou 2016-11-25 23:06:01 UTC
Valgrind doesn't complain though and it would help to have a proper backtrace.
Comment 2 Matthias Klose 2016-11-26 14:03:05 UTC
hmm, that doesn't look better:

Breakpoint 1, __GI___fortify_fail (msg=msg@entry=0x7ffff69f487d "buffer overflow detected")
    at fortify_fail.c:28
28      fortify_fail.c: No such file or directory.
(gdb) bt
#0  __GI___fortify_fail (msg=msg@entry=0x7ffff69f487d "buffer overflow detected") at fortify_fail.c:28
#1  0x00007ffff6980240 in __GI___chk_fail () at chk_fail.c:28
#2  0x00000000006f7716 in build_raise_check(int, exception_info_kind) ()
#3  0x0000000000706119 in gigi ()
#4  0x00000000009e8c90 in back_end.call_back_end ()
#5  0x00000000009e9af7 in gnat1drv ()
#6  0x00000000006c89ed in gnat_parse_file() ()
#7  0x0000000000d791cf in compile_file() ()
#8  0x00000000006acc7f in toplev::main(int, char**) ()
#9  0x00000000006aeff7 in main ()
Comment 3 Eric Botcazou 2016-11-26 17:00:43 UTC
> hmm, that doesn't look better:
> 
> Breakpoint 1, __GI___fortify_fail (msg=msg@entry=0x7ffff69f487d "buffer
> overflow detected")
>     at fortify_fail.c:28
> 28      fortify_fail.c: No such file or directory.
> (gdb) bt
> #0  __GI___fortify_fail (msg=msg@entry=0x7ffff69f487d "buffer overflow
> detected") at fortify_fail.c:28
> #1  0x00007ffff6980240 in __GI___chk_fail () at chk_fail.c:28
> #2  0x00000000006f7716 in build_raise_check(int, exception_info_kind) ()
> #3  0x0000000000706119 in gigi ()
> #4  0x00000000009e8c90 in back_end.call_back_end ()
> #5  0x00000000009e9af7 in gnat1drv ()
> #6  0x00000000006c89ed in gnat_parse_file() ()
> #7  0x0000000000d791cf in compile_file() ()
> #8  0x00000000006acc7f in toplev::main(int, char**) ()
> #9  0x00000000006aeff7 in main ()

A little better though, thanks.  I guess it's this declaration in namet.h:

/* The global name buffer. */
struct Bounded_String
{
  Nat Max_Length;
  Nat Length;
  char Chars[1];
  /* The 1 here is wrong, but it doesn't matter, because all the code either
     goes by Length, or NUL-terminates the string before processing it. */
};

I thought this was a well-known allocation idiom in C++ because you don't have flexible array members, do you?  That being said, I can put the real value.
Comment 4 Eric Botcazou 2016-11-26 17:03:50 UTC
I guess we want to do something, although there's nothing broken.
Comment 5 Eric Botcazou 2016-11-27 20:24:03 UTC
Author: ebotcazou
Date: Sun Nov 27 20:23:31 2016
New Revision: 242901

URL: https://gcc.gnu.org/viewcvs?rev=242901&root=gcc&view=rev
Log:
	PR ada/78531
	* namet.h (Max_Line_Length): Define.
	(struct Bounded_String): Declare Chars with exact size.
	(namet__get_decoded_name_string): Delete.
	(Get_Decoded_Name_String): Likewise.
	(casing__set_all_upper_case): Likewise.

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/namet.h
Comment 6 Eric Botcazou 2016-11-27 20:25:29 UTC
This should work again.