[Bug c/58092] New: BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 Bug ID: 58092 Summary: BEQ (Branch on equal) jumps to wrong address (executes conditional code!) Product: gcc Version: 4.6.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: zajec5 at gmail dot com Created attachment 30617 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30617&action=edit Minimal test case (ANSI C) In my code I'm using simple if (rev == 0x4) to make a conditional write. Unfortunately when using mipsel gcc with "-Os" the code from conditional part is *partially* executed even when "rev" doesn't equal 4. > mipsel-openwrt-linux-uclibc-gcc -v Reading specs from /home/zajec/openwrt/openwrt.git/staging_dir/toolchain-mipsel_gcc-4.6-linaro_uClibc-0.9.33.2/lib64/gcc/mipsel-openwrt-linux-uclibc/4.6.4/specs COLLECT_GCC=mipsel-openwrt-linux-uclibc-gcc COLLECT_LTO_WRAPPER=/home/zajec/openwrt/openwrt.git/staging_dir/toolchain-mipsel_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mipsel-openwrt-linux-uclibc/4.6.4/lto-wrapper Target: mipsel-openwrt-linux-uclibc Configured with: /home/zajec/openwrt/openwrt.git/build_dir/toolchain-mipsel_gcc-4.6-linaro_uClibc-0.9.33.2/gcc-linaro-4.6-2012.12/configure --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt/Linaro GCC 4.6-2012.12 r36315' --prefix=/home/zajec/openwrt/openwrt.git/staging_dir/toolchain-mipsel_gcc-4.6-linaro_uClibc-0.9.33.2 --build=x86_64-suse-linux --host=x86_64-suse-linux --target=mipsel-openwrt-linux-uclibc --with-gnu-ld --enable-target-optspace --disable-libgomp --disable-libmudflap --disable-multilib --disable-nls --with-host-libstdcxx=-lstdc++ --with-float=soft --with-gmp=/home/zajec/openwrt/openwrt.git/staging_dir/host --with-mpfr=/home/zajec/openwrt/openwrt.git/staging_dir/host --disable-decimal-float --with-mips-plt --with-mpc=/home/zajec/openwrt/openwrt.git/staging_dir/host --disable-libssp --disable-__cxa_atexit --with-headers=/home/zajec/openwrt/openwrt.git/staging_dir/toolchain-mipsel_gcc-4.6-linaro_uClibc-0.9.33.2/include --enable-languages=c,c++ --enable-shared --enable-threads --with-slibdir=/home/zajec/openwrt/openwrt.git/staging_dir/toolchain-mipsel_gcc-4.6-linaro_uClibc-0.9.33.2/lib --enable-lto --with-libelf=/home/zajec/openwrt/openwrt.git/staging_dir/host Thread model: posix gcc version 4.6.4 (OpenWrt/Linaro GCC 4.6-2012.12 r36315)
[Bug c/58092] BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 --- Comment #1 from Rafał Miłecki --- Created attachment 30618 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30618&action=edit Compiled version of test.c Command I use to compile test.c: mipsel-openwrt-linux-uclibc-gcc \ -I arch/mips/include \ -I arch/mips/include/generated \ -I arch/mips/include/asm/mach-bcm47xx \ -I arch/mips/include/asm/mach-generic \ -I include \ -include include/linux/kconfig.h \ -D__KERNEL__ -DMODULE \ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -Werror-implicit-function-declaration -Wno-format-security -Wframe-larger-than=1024 -Wno-unused-but-set-variable -Wdeclaration-after-statement -Wno-pointer-sign \ -fno-strict-aliasing -fno-common -fno-delete-null-pointer-checks -fno-caller-saves -fno-stack-protector -fno-pic -pipe -fomit-frame-pointer -femit-struct-debug-baseonly -fno-strict-overflow -fconserve-stack \ -mno-check-zero-division -mno-abicalls -mno-branch-likely -msoft-float -mno-long-calls -ffreestanding -mabi=32 -march=mips32 -Wa,-mips32 -Wa,--trap \ -D CC_HAVE_ASM_GOTO \ -Os \ -c -o test.o test.c
[Bug c/58092] BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 --- Comment #2 from Rafał Miłecki --- ### Decompiled object ### : 0: 24020002li v0,2 4: 24030004li v1,4 8: aca2sw v0,0(a1) c: 10830002beq a0,v1,18 10: 24020008li v0,8 14: 8ca20040lw v0,64(a1) 18: aca20040sw v0,64(a1) 1c: 03e8jr ra 20: nop ### Decompiled with my explanations ### 0: 24020002li v0,2 4: 24030004li v1,4 8: aca2sw v0,0(a1) v0 (0x2) is stored in a1 unconditionally - this is fine c: 10830002beq a0,v1,18 10: 24020008li v0,8 a0 (rev argument) is compared with v1 (0x4) - if equal CPU jumps to 0x18 14: 8ca20040lw v0,64(a1) the above line is executed to rev != 4 18: aca20040sw v0,64(a1) the above lins (store v0 in a1+64) is always executed! it should be executed for rev==4 only v0 is 0x8 by default, or some different value for rev != 4 1c: 03e8jr ra 20: nop
[Bug c/58092] BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 --- Comment #4 from Rafał Miłecki --- Created attachment 30619 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30619&action=edit test.i generated by adding -save-temps Hi Mikael! I added -save-temps at the end of my "mipsel-openwrt-linux-uclibc-gcc" call and got warning: mipsel-openwrt-linux-uclibc-gcc: warning: -pipe ignored because -save-temps specified and test.i of course. By looking at decompiled version of test.o it seems to still contain the bug, so ignored "-pipe" shouldn't hurt us. Hope this is what you expected!
[Bug target/58092] BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 --- Comment #6 from Rafał Miłecki --- OK, I've installed "cross-mips-linux-gcc" package from: http://download.opensuse.org/repositories/home:/duwe:/crosstools/openSUSE_12.2/ and it works. After compiling test.c with: > /opt/cross/bin/mips-linux-gcc -v Using built-in specs. COLLECT_GCC=/opt/cross/bin/mips-linux-gcc COLLECT_LTO_WRAPPER=/opt/cross/libexec/gcc/mips-linux/4.5.3/lto-wrapper Target: mips-linux Configured with: ../configure --prefix=/opt/cross --enable-bootstrap=no --build=x86_64-suse-linux --target=mips-linux --enable-languages=c,c++ --with-float=soft --disable-libmudflap --disable-multilib Thread model: posix gcc version 4.5.3 (GCC) I got a correct test.o. So this issue is specific to Linaro or OpenWrt.
[Bug target/58092] BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 --- Comment #7 from Rafał Miłecki --- I compiled two versions of gcc on my own: 1) gcc-4.6.4.tar.bz2 2) gcc-linaro-4.6-2012.12.tar.bz2 For both of them I've used binutils-2.22.tar.bz2 test.o compiled with gcc-4.6.4.tar.bz2 : 0: 24020002li v0,2 4: aca2sw v0,0(a1) 8: 24020004li v0,4 c: 14820002bne a0,v0,18 10: 24020008li v0,8 14: aca20040sw v0,64(a1) 18: 03e8jr ra 1c: nop test.o compiled with gcc-linaro-4.6-2012.12.tar.bz2 : 0: 24020002li v0,2 4: 24030004li v1,4 8: aca2sw v0,0(a1) c: 10830002beq a0,v1,18 10: 24020008li v0,8 14: 8ca20040lw v0,64(a1) 18: aca20040sw v0,64(a1) 1c: 03e8jr ra 20: nop So it seems to be Linaro fault. I'll report that problem to them.
[Bug target/58092] BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 --- Comment #8 from Rafał Miłecki --- I found link to bug repository on https://support.linaro.org/home and reported that issue to Linaro developers: https://bugs.launchpad.net/gcc-linaro/+bug/1209171 Hope they'll handle this.
[Bug target/58092] BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 Rafał Miłecki changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #9 from Rafał Miłecki --- Not our bug
[Bug target/58092] BEQ (Branch on equal) jumps to wrong address (executes conditional code!)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58092 Rafał Miłecki changed: What|Removed |Added Resolution|INVALID |FIXED --- Comment #10 from Rafał Miłecki --- Well... I spent more time testing that and it has appeared *to be* our bug. It was a bug in 4.6.3 that was fixed in 4.6.4. Linaro was simply based on 4.6.3 at some point.