This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug other/50916] New: -Os, -D_FORTIFY_SOURCE breaks strcpy & others if inlined
- From: "dezgeg at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 29 Oct 2011 23:33:32 +0000
- Subject: [Bug other/50916] New: -Os, -D_FORTIFY_SOURCE breaks strcpy & others if inlined
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50916
Bug #: 50916
Summary: -Os, -D_FORTIFY_SOURCE breaks strcpy & others if
inlined
Classification: Unclassified
Product: gcc
Version: 4.6.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: dezgeg@gmail.com
Created attachment 25665
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25665
The preprocessed source
Not totally sure if a glibc or gcc bug, but anyway: GCC 4.6.2 causes the
following code to get into an infinite loop in strcpy if compiled with
gcc -std=c99 -Os -D_FORTIFY_SOURCE=2
#include <argp.h>
#include <string.h>
int main (void) {
char buf[1024];
char* str = "hello";
strcpy (buf, str);
return 0;
}
It seems that something in the #includes is pulling in the following definition
for strcpy:
extern __inline char *
strcpy (char *__restrict __dest, const char *__restrict __src)
{
return __builtin___strcpy_chk (__dest, __src, __builtin_object_size (__dest,
2 > 1));
}
...and then the __builtin_strcpy_chk seems to turn back into strcpy (due to
-Os?):
00000035 <strcpy>:
35: 55 push %ebp
36: 89 e5 mov %esp,%ebp
38: 5d pop %ebp
39: e9 fc ff ff ff jmp 3a <strcpy+0x5>
3a: R_386_PC32 strcpy
...which then causes the infinite loop.
gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.6/lto-wrapper
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.2-2'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc
--enable-targets=all --with-arch-32=i586 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.6.2 (Debian 4.6.2-2)