Skip to contentSkip to conversation

Branch condition problems

Qemu-devel Blue Swirl 2 participants 2 messages Mar 22, 2007

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

Hi,

I can't reproduce the problem with attached test program. Also the generated ops look just fine:

IN:

0x00010074:  sethi  %hi(0x20000), %g3
0x00010078:  or  %g3, 0xa0, %g3 ! 0x200a0
0x0001007c:  mov  -1, %g1
0x00010080:  mov  -1, %g2
0x00010084:  tst  %g0
0x00010088:  bne  0x10094
0x0001008c:  std  %g1, [ %g3 ]

OP:
0x0000: movl_T0_im 0x20000
0x0001: movl_g3_T0
0x0002: movl_T0_g3
0x0003: movl_T1_sim 0xa0
0x0004: or_T1_T0
0x0005: movl_g3_T0
0x0006: movl_T1_sim 0xffffffff 0x0007: movl_g1_T1
0x0008: movl_T1_sim 0xffffffff 0x0009: movl_g2_T1
0x000a: movl_T0_im 0x0
0x000b: movl_T1_im 0x0
0x000c: or_T1_T0
0x000d: logic_T0_cc
Set T2:
0x000e: eval_bne
First part of std:
0x000f: movl_T0_g3
0x0010: movl_T1_g1
flush_T2 here:
0x0011: jz_T2_label 0x0
0x0012: movl_npc_im 0x10094
0x0013: jmp_label 0x1
0x0014: movl_npc_im 0x10090
Now reuse T2, rest of std:
0x0015: movl_T2_g2
0x0016: std_raw
0x0017: next_insn
0x0018: movl_T0_0
0x0019: exit_tb
0x001a: end

--------------
IN:
Branch not taken (OK)

0x00010090:  nop
0x00010094:  mov  1, %g1        ! 0x1
0x00010098:  ta  0x10

OP:
0x0000: movl_T1_sim 0x1
0x0001: movl_g1_T1
0x0002: movl_T0_im 0x0
0x0003: movl_T1_sim 0x10
0x0004: add_T1_T0
0x0005: jmp_im 0x10098
0x0006: movl_npc_im 0x1009c
0x0007: trap_T0
0x0008: next_insn
0x0009: movl_T0_0
0x000a: exit_tb
0x000b: end

Can you describe how to reproduce the bug?

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

#1 lore raw
Quoted 5 lines · Blue Swirl

Hi,

I can't reproduce the problem with attached test program. Also the generated ops look just fine:

[snip]

Quoted 3 lines

Can you describe how to reproduce the bug?

Well I also have difficulties to reproduce it with a simple program. I have detected it while trying to build binutils on a Debian unstable distribution running in QEMU.

The problem occurs when running the configure script of libiberty as a normal user using fakeroot, using bash as /bin/sh. The last character of some of the $LINENO variables is wrongly computed. It is computed using the modulo function from gcc (moddi3) called from fmtumax() called from itos(). In some very rare conditions (I don't know all of them) a branch is falsely taken which result in a wrong sign. When added to 0x30, it results in a wrong character. Some of them like ) or ( are triggering an error message. I have been able to track the bug up to the branch instruction followed by a std instruction by directly editing the assembly code of bash to cancel some tests.

Note that you need to use fakeroot to see the problem, and also that using gdb workaround the bug. Rebuilding bash with -O0 or -O1 workarounds the problem. Using -g helps to get the function names along with the assembly code when using objdump

To reproduce it, the best way is to use a Debian unstable distribution running in QEMU, at run (I can provide an image if you need one):

apt-get install binutils
cd binutils-2.17-3/libiberty
fakeroot ./configure

You will see that some tests fail with a strange error message from bash. This error is fixed by the patch I posted or by the one you posted.

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net