From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10012 invoked by alias); 20 Sep 2011 05:20:38 -0000 Received: (qmail 10000 invoked by uid 22791); 20 Sep 2011 05:20:36 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CP X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Sep 2011 05:20:22 +0000 From: "hjl.tools at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/50460] New: [4.7 Regression] __builtin___strcpy_chk/__builtin_object_size don't work Date: Tue, 20 Sep 2011 08:16:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hjl.tools at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg01366.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50460 Bug #: 50460 Summary: [4.7 Regression] __builtin___strcpy_chk/__builtin_object_size don't work Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned@gcc.gnu.org ReportedBy: hjl.tools@gmail.com On Linux/x86, revision 178028 gave [hjl@gnu-34 gcc]$ cat ~/tmp/foo.c const char *str1 = "JIHGFEDCBA"; extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__artificial__)) char * __attribute__ ((__nothrow__)) strcpy (char *__restrict __dest, __const char *__restrict __src) { return __builtin___strcpy_chk (__dest, __src, __builtin_object_size (__dest, 2 > 1)); } int main () { struct A { char buf1[9]; char buf2[1]; } a; strcpy (a.buf1 + (0 + 4), str1 + 5); return 0; } [hjl@gnu-34 gcc]$ ./xgcc -B./ -O2 ~/tmp/foo.c [hjl@gnu-34 gcc]$ ./a.out [hjl@gnu-34 gcc]$ instead of [hjl@gnu-34 gcc]$ ./a.out *** buffer overflow detected ***: ./a.out terminated ======= Backtrace: ========= /lib64/libc.so.6(__fortify_fail+0x37)[0x3e56103ca7] /lib64/libc.so.6[0x3e56101c20] ./a.out[0x40041e] /lib64/libc.so.6(__libc_start_main+0xed)[0x3e560215bd] ./a.out[0x400451] ======= Memory map: ======== 00400000-00401000 r-xp 00000000 08:11 52433950 /export/gnu/import/svn/gcc-test-ia32corei7/bld/gcc/a.out 00600000-00601000 rw-p 00000000 08:11 52433950 /export/gnu/import/svn/gcc-test-ia32corei7/bld/gcc/a.out 00a33000-00a54000 rw-p 00000000 00:00 0 [heap] 3e55c00000-3e55c22000 r-xp 00000000 08:06 392457 /lib64/ld-2.14.90.so 3e55e21000-3e55e22000 r--p 00021000 08:06 392457 /lib64/ld-2.14.90.so 3e55e22000-3e55e23000 rw-p 00022000 08:06 392457 /lib64/ld-2.14.90.so 3e55e23000-3e55e24000 rw-p 00000000 00:00 0 3e56000000-3e561a6000 r-xp 00000000 08:06 392458 /lib64/libc-2.14.90.so 3e561a6000-3e563a5000 ---p 001a6000 08:06 392458 /lib64/libc-2.14.90.so 3e563a5000-3e563a9000 r--p 001a5000 08:06 392458 /lib64/libc-2.14.90.so 3e563a9000-3e563aa000 rw-p 001a9000 08:06 392458 /lib64/libc-2.14.90.so 3e563aa000-3e563b0000 rw-p 00000000 00:00 0 3e57800000-3e57815000 r-xp 00000000 08:06 392602 /lib64/libgcc_s-4.6.0-20110603.so.1 3e57815000-3e57a14000 ---p 00015000 08:06 392602 /lib64/libgcc_s-4.6.0-20110603.so.1 3e57a14000-3e57a15000 rw-p 00014000 08:06 392602 /lib64/libgcc_s-4.6.0-20110603.so.1 7fb292f73000-7fb292f76000 rw-p 00000000 00:00 0 7fb292f93000-7fb292f95000 rw-p 00000000 00:00 0 7fff0d60a000-7fff0d62b000 rw-p 00000000 00:00 0 [stack] 7fff0d68a000-7fff0d68b000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] Aborted (core dumped) [hjl@gnu-34 gcc]$ Revision 177983 is OK.