Strange PIC code on ia32 since Aug. 29.
Horst von Brand
vonbrand@sleipnir.valparaiso.cl
Sun Sep 3 17:27:00 GMT 2000
"H . J . Lu" <hjl@valinux.com> said:
[...]
> 2. Use gcc 2.95.2, egcs 1.1.2 or gcc 2.7.2.3.
>
> Study psABI says about PIC and what the previous gcc generates. I am
> enlosing the correct asm output here. gcc shouldn't output some random
> asm code and call it PIC. Did you see the difference?
>
>
> H.J.
> ----
> .file "p.c"
> .version "01.01"
> gcc2_compiled.:
> .text
> .align 4
> .globl foo
> .type foo,@function
> foo:
> pushl %ebp
> movl %esp, %ebp
> pushl %ebx
> pushl %eax
> call .L3
> .L3:
> popl %ebx
> addl $_GLOBAL_OFFSET_TABLE_+[.-.L3], %ebx
> call bar@PLT
> movl -4(%ebp), %ebx
> leave
> ret
> .Lfe1:
> .size foo,.Lfe1-foo
> .ident "GCC: (GNU) 2.96 20000731 (experimental)"
AFAIU, @PLT doesn't use %ebx, so the original code you cited is right, gcc
optimized out the setting of %ebx (perhaps not 100% according to the specs,
but correct). OTOH, for:
int x;
foo ()
{
bar (x);
}
I get (P3):
.file "tst.c"
.version "01.01"
gcc2_compiled.:
.text
.align 16
.LPR0:
movl (%esp), %ebx
ret
.globl foo
.type foo,@function
foo:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $16, %esp
call .LPR0
addl $_GLOBAL_OFFSET_TABLE_, %ebx
movl x@GOT(%ebx), %eax
movl (%eax), %eax
pushl %eax
call bar@PLT
movl -4(%ebp), %ebx
movl %ebp, %esp
popl %ebp
ret
.Lfe1:
.size foo,.Lfe1-foo
.comm x,4,4
.ident "GCC: (GNU) 2.96 20000901 (experimental)"
More information about the Gcc-bugs
mailing list