This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

-fPIC bug


unless I'm on crack, this looks like a bug where
the compiler allows a register to be clobbered without
doing anything about it.

% cat foo.c
int foo(){
    asm("mov $0,%%ebx":::"%ebx");
    return 0;
}
% cat bar.c
extern int foo();
int main(){
    foo();
    return 0;
}
% gcc -shared -fPIC -o foo.so foo.c
% gcc bar.c ./foo.so
% ldd a.out
        ./foo.so => ./foo.so (0x40015000)
        libc.so.6 => /lib/libc.so.6 (0x4001c000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
% ./a.out
Segmentation fault (core dumped)
% objdump foo.so
...
00000770 <foo>:
 770:   55                      push   %ebp
 771:   89 e5                   mov    %esp,%ebp
 773:   bb 00 00 00 00          mov    $0x0,%ebx
 778:   31 c0                   xor    %eax,%eax
 77a:   eb 04                   jmp    780 <foo+0x10>
 77c:   8d 74 26 00             lea    0x0(%esi,1),%esi
 780:   c9                      leave  
 781:   c3                      ret    
...

note that the %ebx reg is clobbered, thus producing the
segfault when it is used for shared lib stuff later in the
program.  If you compile it without -fPIC and only -shared,
it saves the %ebx reg before entering the inline assembly (as
it should).  Is the -fPIC not to be used on this platform?
I ask because I was compiling using libtool, and it uses -fPIC.
Thoughts?

stats:
Linux alfonse 2.2.14 #3 Wed May 17 16:33:44 PDT 2000 i686 unknown
egcs-2.91.66

-dave klint

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]