------- Comment #2 from hjl dot tools at gmail dot com 2009-05-06 14:51 -------
(In reply to comment #1)
> I've just confirmed the bug on i686-pc-solaris2.10. It doesn't occur on
> i686-pc-solaris2.11, though, so this is indeed a Sun ld bug.
>
> I've got a few questions to resolve, though:
>
> * Why does generating code for i686 instead of i386 change gcc's assembler
> output
> so significantly?
>
The difference is in how to get PC for -fPIC:
bash-3.2$ cat p.c
void
foo ()
{
bar ();
}
bash-3.2$ gcc -m32 -fPIC p.c -S -O3 -mtune=i386
bash-3.2$ cat p.s
.file "p.c"
.text
.p2align 2,,3
.globl foo
.type foo, @function
foo:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $4, %esp
call .L3
.L3:
popl %ebx
addl $_GLOBAL_OFFSET_TABLE_+[.-.L3], %ebx
call b...@plt
popl %eax
popl %ebx
leave
ret
.size foo, .-foo
.ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
.section .note.GNU-stack,"",@progbits
bash-3.2$ gcc -m32 -fPIC p.c -S -O3 -mtune=i686
bash-3.2$ cat p.s
.file "p.c"
.text
.p2align 4,,15
.globl foo
.type foo, @function
foo:
pushl %ebp
movl %esp, %ebp
pushl %ebx
call __i686.get_pc_thunk.bx
addl $_GLOBAL_OFFSET_TABLE_, %ebx
subl $4, %esp
call b...@plt
addl $4, %esp
popl %ebx
popl %ebp
ret
.size foo, .-foo
.ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
.section
.text.__i686.get_pc_thunk.bx,"axG",@progbits,__i686.get_pc_thunk.bx,comdat
.globl __i686.get_pc_thunk.bx
.hidden __i686.get_pc_thunk.bx
.type __i686.get_pc_thunk.bx, @function
__i686.get_pc_thunk.bx:
movl (%esp), %ebx
ret
.section .note.GNU-stack,"",@progbits
bash-3.2$
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40027