GCC-2.95 - bug in i386 pic code generation when using inline asm.
Leon Bottou
leonb@research.att.com
Fri Feb 18 10:45:00 GMT 2000
leonb@tamil% uname -a
Linux tamil 2.2.5 #5 SMP Fri Sep 24 10:49:52 EDT 1999 i686 unknown
leonb@tamil% gcc -v
Reading specs from
/home/opt/libc6/egcs-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)
leonb@tamil% cat > bug.c <<EOF
int x = 0;
int main() { asm("xor %%ebx,%%ebx" : : : "ebx"); return x; }
EOF
-- Note that ebx is clobbered and declared as such.
-- The asm statement should be a noop
leonb@tamil% gcc -fpic bug.c -o bug
leonb@tamil% bug
Segmentation fault (core dumped) // WOW - It works without -fpic
leonb@tamil% gcc -fpic -S bug.c
leonb@tamil% cat bug.s
......
main:
pushl %ebp
movl %esp,%ebp
pushl %ebx
call .LPR0
addl $_GLOBAL_OFFSET_TABLE_,%ebx
#APP
xor %ebx,%ebx // Ok
#NO_APP
movl x@GOT(%ebx),%eax // WOW: PIC uses EBX but forgot that I clobbered
it!
movl (%eax),%edx
movl %edx,%eax
jmp .L2
.p2align 4,,7
.L2:
movl -4(%ebp),%ebx
movl %ebp,%esp
popl %ebp
ret
.....
More information about the Gcc-bugs
mailing list