From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9411 invoked by alias); 3 Jul 2011 10:53:23 -0000 Received: (qmail 9398 invoked by uid 22791); 3 Jul 2011 10:53:21 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ,TW_CX,TW_DC,TW_EQ,TW_GX 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; Sun, 03 Jul 2011 10:53:05 +0000 From: "sedat.dilek at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/49618] New: When building uClibc with GCC 4.6.1 old_atexit is miscompiled X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sedat.dilek 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" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Date: Sun, 03 Jul 2011 10:53:00 -0000 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-07/txt/msg00128.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D49618 Summary: When building uClibc with GCC 4.6.1 old_atexit is miscompiled Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: sedat.dilek@gmail.com Created attachment 24661 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=3D24661 Preprocessed file "old_atexit.i" Hi, this issue kept me UP for several weeks. It first occured when generating a mipsel target-toolchain based on gcc-4.6.0 with uClibc-0.9.32 for a router project called freetz. Finally, I could track the problem with the assistan= ce from Edwin T=C3=B6r=C3=B6k. A big thank you, Edwin. ### Problem description: When building uClibc with GCC 4.6.1 old_atexit is miscompiled, which causes this testprogram to crash when calling old_atexit: #include void foo() {} int main() { return atexit(foo);} This is a regression from GCC 4.5.3 which compiled old_atexit() fine. Attached is the preprocessed file old_atexit.i. Commandline to create old_atexit.os: mipsel-linux-uclibc-gcc -S old_atexit.i -o old_atexit.os -funsigned-char -fno-builtin -fno-asm -msoft-float -std=3Dgnu99 -march=3D4kc -mtune=3D4kc -= mabi=3D32 -fno-stack-protector -Os -funit-at-a-time -fmerge-all-constants -fstrict-aliasing -fno-tree-loop-optimize -fno-tree-dominator-opts -fno-strength-reduce -mno-split-addresses -fPIC As seen below with GCC 4.6.1 &__dso_handle is assumed to be non-NULL and the branch (beqz) eliminated, but it is in fact NULL at runtime which causes the crash. With GCC 4.5.3 there is a beqz that tests for &__dso_handle =3D=3D NULL: 000537d0 : 537d0: 3c1c0003 lui gp,0x3 537d4: 279c8d10 addiu gp,gp,-29424 537d8: 0399e021 addu gp,gp,t9 537dc: 8f828a2c lw v0,-30164(gp) 537e0: 8f9989ac lw t9,-30292(gp) 537e4: 8c460000 lw a2,0(v0) ^^^^^^^^^^ SIGSEGV here, with a NULL dereference 537e8: 00002821 move a1,zero 537ec: 03200008 jr t9 537f0: 0002300a movz a2,zero,v0 old_atexit.os with GCC 4.6.1: .file 1 "old_atexit.c" .section .mdebug.abi32 .previous .gnu_attribute 4, 3 .abicalls .text .align 2 .globl old_atexit .set nomips16 .ent old_atexit .type old_atexit, @function old_atexit: .frame $sp,0,$31 # vars=3D 0, regs=3D 0/0, args=3D 0,= gp=3D 0 .mask 0x00000000,0 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro lw $2,%got(__dso_handle)($28) lw $25,%call16(__cxa_atexit)($28) lw $6,0($2) move $5,$0 .reloc 1f,R_MIPS_JALR,__cxa_atexit 1: jr $25 movz $6,$0,$2 .set macro .set reorder .end old_atexit .size old_atexit, .-old_atexit .weak atexit atexit =3D old_atexit .weak __dso_handle .ident "GCC: (GNU) 4.6.1" old_atexit.os with GCC 4.5.3: .file 1 "old_atexit.c" .section .mdebug.abi32 .previous .gnu_attribute 4, 3 .abicalls .text .align 2 .globl old_atexit .set nomips16 .ent old_atexit .type old_atexit, @function old_atexit: .frame $sp,0,$31 # vars=3D 0, regs=3D 0/0, args=3D 0,= gp=3D 0 .mask 0x00000000,0 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro lw $2,%got(__dso_handle)($28) beq $2,$0,$L2 move $6,$0 lw $6,0($2) $L2: lw $25,%call16(__cxa_atexit)($28) .reloc 1f,R_MIPS_JALR,__cxa_atexit 1: jr $25 move $5,$0 .set macro .set reorder .end old_atexit .size old_atexit, .-old_atexit .weak atexit atexit =3D old_atexit .weak __dso_handle .ident "GCC: (GNU) 4.5.3" ### GCC versions (with gcc -v output) for target and host: $ /mnt/sdb3/freetz/freetz-trunk_gcc-4.6.1/toolchain/build/mipsel_gcc-4.6.1_uC= libc-0.9.32/mipsel-linux-uclibc/bin/mipsel-linux-uclibc-gcc -v Using built-in specs. COLLECT_GCC=3D/mnt/sdb3/freetz/freetz-trunk_gcc-4.6.1/toolchain/build/mipse= l_gcc-4.6.1_uClibc-0.9.32/mipsel-linux-uclibc/bin/mipsel-linux-uclibc-gcc COLLECT_LTO_WRAPPER=3D/mnt/sdb3/freetz/freetz-trunk_gcc-4.6.1/toolchain/bui= ld/mipsel_gcc-4.6.1_uClibc-0.9.32/mipsel-linux-uclibc/bin/../libexec/gcc/mi= psel-linux-uclibc/4.6.1/lto-wrapper Target: mipsel-linux-uclibc Configured with: /mnt/sdb3/freetz/freetz-trunk/source/toolchain-mipsel_gcc-4.6.1_uClibc-0.9.= 32/gcc-4.6.1/configure --prefix=3D/mnt/sdb3/freetz/freetz-trunk/toolchain/build/mipsel_gcc-4.6.1_u= Clibc-0.9.32/mipsel-linux-uclibc --with-sysroot=3D/mnt/sdb3/freetz/freetz-trunk/toolchain/build/mipsel_gcc-4= .6.1_uClibc-0.9.32/mipsel-linux-uclibc/usr/ --build=3Di386-pc-linux-gnu --host=3Di386-pc-linux-gnu --target=3Dmipsel-li= nux-uclibc --enable-languages=3Dc,c++ --enable-shared --enable-threads --with-gmp=3D/mnt/sdb3/freetz/freetz-trunk/tools/build --with-mpfr=3D/mnt/sdb3/freetz/freetz-trunk/tools/build --with-mpc=3D/mnt/sdb3/freetz/freetz-trunk/tools/build --with-gnu-ld --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --disable-multilib --disable-tls --disable-fixed-point --with-float=3Dsoft --enable-cxx-flags=3D-msoft-float --disable-libssp --with-march=3D4kc --dis= able-nls --with-mips-plt --disable-decimal-float Thread model: posix gcc version 4.6.1 (GCC) $ /mnt/sdb3/freetz/freetz-trunk_gcc-4.5.3/toolchain/build/mipsel_gcc-4.5.3_uC= libc-0.9.32/mipsel-linux-uclibc/bin/mipsel-linux-uclibc-gcc -v Using built-in specs. COLLECT_GCC=3D/mnt/sdb3/freetz/freetz-trunk_gcc-4.5.3/toolchain/build/mipse= l_gcc-4.5.3_uClibc-0.9.32/mipsel-linux-uclibc/bin/mipsel-linux-uclibc-gcc COLLECT_LTO_WRAPPER=3D/mnt/sdb3/freetz/freetz-trunk_gcc-4.5.3/toolchain/bui= ld/mipsel_gcc-4.5.3_uClibc-0.9.32/mipsel-linux-uclibc/bin/../libexec/gcc/mi= psel-linux-uclibc/4.5.3/lto-wrapper Target: mipsel-linux-uclibc Configured with: /mnt/sdb3/freetz/freetz-trunk/source/toolchain-mipsel_gcc-4.5.3_uClibc-0.9.= 32/gcc-4.5.3/configure --prefix=3D/mnt/sdb3/freetz/freetz-trunk/toolchain/build/mipsel_gcc-4.5.3_u= Clibc-0.9.32/mipsel-linux-uclibc --with-sysroot=3D/mnt/sdb3/freetz/freetz-trunk/toolchain/build/mipsel_gcc-4= .5.3_uClibc-0.9.32/mipsel-linux-uclibc/usr/ --build=3Di386-pc-linux-gnu --host=3Di386-pc-linux-gnu --target=3Dmipsel-li= nux-uclibc --enable-languages=3Dc,c++ --enable-shared --enable-threads --with-gmp=3D/mnt/sdb3/freetz/freetz-trunk/tools/build --with-mpfr=3D/mnt/sdb3/freetz/freetz-trunk/tools/build --with-mpc=3D/mnt/sdb3/freetz/freetz-trunk/tools/build --with-gnu-ld --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --disable-multilib --disable-tls --disable-fixed-point --with-float=3Dsoft --enable-cxx-flags=3D-msoft-float --disable-libssp --with-march=3D4kc --dis= able-nls --with-mips-plt --disable-decimal-float Thread model: posix gcc version 4.5.3 (GCC) $ gcc -v Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/lto-= wrapper Target: i486-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Debian 4.6.1-1' --with-bugurl=3Dfile:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=3Dc,c++,fortran,objc,obj-c++,go --prefix=3D/usr --program-suffix=3D-4.6 --enable-shared --enable-multiarch --with-multiarch-defaults=3Di386-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=3D/usr/lib/i386-linux-gnu --without-included-gettext --enable-threads=3Dposix --with-gxx-include-dir=3D/usr/include/c++/4.6 --libdir=3D/usr/lib/i386-linu= x-gnu --enable-nls --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-libstdcxx-time=3Dyes --enable-plugin --enable-objc-gc --enable-targets=3Dall --with-arch-32=3Di586 --with-tune=3Dgeneric --enable-checking=3Drelease --build=3Di486-linux-gnu --host=3Di486-linux-gnu --target=3Di486-linux-gnu Thread model: posix gcc version 4.6.1 (Debian 4.6.1-1) ### Target is a Speedport W701V router: # uname -a Linux fritz.fonwlan.box 2.6.13.1-ohio #1 Thu Jun 30 17:59:33 CEST 2011 mips GNU/Linux # cat /proc/version=20 Linux version 2.6.13.1-ohio () (gcc version 3.4.6) #1 Thu Jun 30 17:59:33 C= EST 2011 ### Host is a Debian/sid i386 system: $ uname -a Linux seduxbox 2.6.39-2-686-pae #1 SMP Wed Jun 8 11:33:14 UTC 2011 i686 GNU/Linux $ cat /proc/version=20 Linux version 2.6.39-2-686-pae (Debian 2.6.39-2) (ben@decadent.org.uk) (gcc version 4.4.6 (Debian 4.4.6-3) ) #1 SMP Wed Jun 8 11:33:14 UTC 2011 Hope this helps to kill that BUG. Kind Regards, - Sedat -