Summary: gcc 4.0 produces corrupted shared library if it is statically linked
with libstdc++ and etc. stuff


>g++ -v

Using built-in specs.
Target: sparc-sun-solaris2.9
Configured with: ../gcc-4.0.0/configure
--prefix=/home2/anton/opt/gcc-4.0.0-noshared --with-gnu-ld
--with-ld=/home2/anton/opt/bin/ld --with-gnu-as
--with-as=/home2/anton/opt/bin/as --disable-libgcj --enable-languages=c,c++
--disable-shared
Thread model: posix
gcc version 4.0.0

>uname -a

SunOS solaris 5.9 Generic_117171-07 sun4u sparc SUNW,Sun-Blade-100

Source code of shared library:

=== q.cpp start ===

#include <stdio.h>

extern "C" {
  void foo() {
    printf("sizeof(void*)=%d\n", sizeof(void*));
  }
}

=== q.cpp end ===

>g++ -m64 -fPIC q.cpp -shared -o libq.so
>file libq.so
libq.so:        ELF 64-bit MSB dynamic lib SPARCV9 Version 1, dynamically
linked, not stripped
>ldd -Ur libq.so
        libm.so.1 =>     /usr/lib/64/libm.so.1
        libc.so.1 =>     /usr/lib/64/libc.so.1
        libdl.so.1 =>    /usr/lib/64/libdl.so.1
        /usr/platform/SUNW,Sun-Blade-100/lib/sparcv9/libc_psr.so.1

   unreferenced object=/usr/lib/64/libm.so.1; unused dependency of ./libq.so
   unused object=/usr/lib/64/libm.so.1; member of cyclic group [1]

Everything seems to be OK.

But when we load .so with the following simple program test.cpp, it prints error
message:

=== test.cpp start ===
#include <dlfcn.h>      /* defines dlopen(), etc.       */
#include <stdlib.h>
#include <stdio.h>

int main() {

  void* lib_handle = dlopen("/home2/anton/projects/frekenbok/libq.so", 
RTLD_LAZY);
  if (!lib_handle) {
      fprintf(stderr, "Error during dlopen(): %s\n", dlerror());
      exit(1);
  }

}
=== test.cpp end ===

>g++ -m64 test.cpp
>./a.out
Error during dlopen(): ld.so.1: a.out: fatal: relocation error: R_SPARC_WDISP30:
file /home2/anton/projects/frekenbok/libq.so: symbol strcpy: value 0x6053f9f7
does not fit


There is no problem if gcc is configured with shared enabled (i.e. without
"--disable-shared" flag), and .so is dynamically linked with libstdc++.so etc.
As well everything is fine in 32 bit mode (-m32), even statically linked.

So the problem appears _only_ in 64 bit mode and _only_ when resulting shared
library is statically linked.

-- 
           Summary: gcc 4.0 fails to statically link on Solaris SPARC 64 bit
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: info at yourkit dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21277

Reply via email to