This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


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

PIC bug: libgcj is broken with current cvs gcc


Java "Hello world" segfaults on a shared libgcj built with the current
gcc:

Program received signal SIGSEGV, Segmentation fault.
0x0 in ?? ()
(gdb) bt
#0  0x0 in ?? ()
#1  0x4023712c in _Jv_RegisterClass (klass=0x804cb20)
    at ../../../libjava/java/lang/natClassLoader.cc:456
#2  0x804b8d3 in global constructors keyed to Hello.Hello () at
Hello.java:6
#3  0x804b935 in __do_global_ctors_aux ()
#4  0x8048f2a in _init ()
#5  0x4041430c in __libc_start_main (main=0x804b8e0 <main>, argc=1,
    ubp_av=0xbffffa34, init=0x8048f00 <_init>, fini=0x804b94c <_fini>,
    rtld_fini=0x4000de14 <_dl_fini>, stack_end=0xbffffa2c)
    at ../sysdeps/generic/libc-start.c:104

The crash occurs when the first class that is not in libgcj.so tries to
register. Building with "gcj -static" works fine, so it looks like the
PIC bug reported by HJ Lu is to blame:

http://gcc.gnu.org/ml/gcc-bugs/2000-09/msg00030.html

The solution is to reverse the following patch:

http://gcc.gnu.org/ml/gcc-patches/2000-08/msg01201.html

gdb shows that the code generated for _Jv_RegisterClass is quite
different with this patch reverted:

(current cvs output, broken:)

Dump of assembler code for function _Jv_RegisterClass:
0x40237110 <_Jv_RegisterClass>: push   %ebp
0x40237111 <_Jv_RegisterClass+1>:       mov    %esp,%ebp
0x40237113 <_Jv_RegisterClass+3>:       sub    $0x14,%esp
0x40237116 <_Jv_RegisterClass+6>:       mov    0x8(%ebp),%eax
0x40237119 <_Jv_RegisterClass+9>:       movl   $0x0,0xfffffffc(%ebp)
0x40237120 <_Jv_RegisterClass+16>:      mov    %eax,0xfffffff8(%ebp)
0x40237123 <_Jv_RegisterClass+19>:      lea    0xfffffff8(%ebp),%eax
0x40237126 <_Jv_RegisterClass+22>:      push   %eax
0x40237127 <_Jv_RegisterClass+23>:      call   0x4013680c <_init+32272>
0x4023712c <_Jv_RegisterClass+28>:      add    $0x10,%esp
0x4023712f <_Jv_RegisterClass+31>:      mov    %ebp,%esp
0x40237131 <_Jv_RegisterClass+33>:      pop    %ebp
0x40237132 <_Jv_RegisterClass+34>:      ret
End of assembler dump.

(with patch reverted, working:)

Dump of assembler code for function _Jv_RegisterClass:
0x4023cdc0 <_Jv_RegisterClass>: push   %ebp
0x4023cdc1 <_Jv_RegisterClass+1>:       mov    %esp,%ebp
0x4023cdc3 <_Jv_RegisterClass+3>:       push   %ebx
0x4023cdc4 <_Jv_RegisterClass+4>:       sub    $0x20,%esp
0x4023cdc7 <_Jv_RegisterClass+7>:
    call   0x4023c510
<_GLOBAL_.I.forName__Q34java4lang5ClassPQ34java4lang6String+32>
0x4023cdcc <_Jv_RegisterClass+12>:      add    $0x148f54,%ebx
0x4023cdd2 <_Jv_RegisterClass+18>:      mov    0x8(%ebp),%eax
0x4023cdd5 <_Jv_RegisterClass+21>:      movl   $0x0,0xfffffff4(%ebp)
0x4023cddc <_Jv_RegisterClass+28>:      mov    %eax,0xfffffff0(%ebp)
0x4023cddf <_Jv_RegisterClass+31>:      lea    0xfffffff0(%ebp),%eax
0x4023cde2 <_Jv_RegisterClass+34>:      push   %eax
0x4023cde3 <_Jv_RegisterClass+35>:      call   0x4013680c <_init+32272>
0x4023cde8 <_Jv_RegisterClass+40>:      mov    0xfffffffc(%ebp),%ebx
0x4023cdeb <_Jv_RegisterClass+43>:      add    $0x10,%esp
0x4023cdee <_Jv_RegisterClass+46>:      mov    %ebp,%esp
0x4023cdf0 <_Jv_RegisterClass+48>:      pop    %ebp
0x4023cdf1 <_Jv_RegisterClass+49>:      ret
End of assembler dump.

regards

  [ bryce ]



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