Tuesday, 19 June 2007

gnu compiler has things inside it

Coming to you from the land of gmake, ggrep, gegrep, gsed, gpwd, gcd, gcat, gdf, guname, ... gar, gld, gobjdump, (watch out gprof is often solaris gprof (in /usr/ccs/bin) ggprof is gnu gprof) ...  :)   i.e. solaris.

Watch out on solaris what linker is being used. And also watch out gcc libs may have internal library paths which can affect linking.

1. linker
 
gcc may be configured (at gcc compile time) to use gnu binutils or to use solaris linker/assembler. I would guess that the binutils might be more of a challenge to get working on solaris? Many (all?) sunfreeware packages of gcc use solaris linker/assembler. One difference noted is that solaris linker passes over libs just once by default. So library order is important and duplicates may have to be used (or else put "-Wl,-z,rescan" in LDFLAGS to pass to linker).  Another difference is different flags used to add to rpath at link time (-rpath for gnu ld, -R for solaris ld).

2. rpath in 64bit libs

/usr/sfw/lib contains 32bit libs, /usr/sfw/lib/64 contains 64bit libs.

But often the 64bit libgcc_s.so or 64bit libstdc++.so contain /usr/sfw/lib (32bit) in rpath.

This must be overridden using rpath in your own 64bit binary or using LD_LIBRARY_PATH in environment.


machine 1 (solaris 10, sparc):

gcc 4.1.1 configured with gnu binutils and gcc 3.4.3 from sunfreeware configured with solaris linker/assembler

$ /opt/GCC-SunOS-10-4.1.1/bin/g++ -print-prog-name=ld
/opt/GCC-SunOS-10-4.1.1/bin/ld

$ /usr/sfw/bin/g++ -print-prog-name=ld
/usr/ccs/bin/ld

$ /usr/sbin/pkgchk -l -p /usr/sfw/bin/g++
        SUNWgcc       


machine 2 (solaris 10, amd/x86):

both gcc 4.1.1 and gcc 3.4.3 from sunfreeware configured with solaris linker/assembler
$ /usr/sfw/bin/g++ -print-prog-name=ld
/usr/ccs/bin/ld

$ /opt/GCC-SunOS-10-4.1.1/bin/g++ -print-prog-name=ld
/usr/ccs/bin/ld

$ /usr/sbin/pkgchk -l -p /usr/sfw/bin/g++
        SUNWgcc


wacky:  64bit gcc libraries often have bad rpath in them  (see this 32bit lib rpath in the 64bit lib)
The runtime dynamic linker is happy to go with 32bit libs but of course it then has a problem loading them.
Interesting to note that the ld or gcc found in path affects the ldd -s output.

$ ldd -s /usr/sfw/lib/64/libstdc++.so

   find object=libm.so.2; required by /usr/sfw/lib/64/libstdc++.so
    search path=/usr/sfw/lib  (RPATH from file /usr/sfw/lib/64/libstdc++.so)
    trying path=/usr/sfw/lib/libm.so.2
    search path=/lib/64:/usr/lib/64:/opt/GCC-SunOS-10-4.1.1/lib/sparcv9  (configuration default - /var/ld/64/ld.config)
    trying path=/lib/64/libm.so.2
        libm.so.2 =>     /lib/64/libm.so.2

   find object=libgcc_s.so.1; required by /usr/sfw/lib/64/libstdc++.so
    search path=/usr/sfw/lib  (RPATH from file /usr/sfw/lib/64/libstdc++.so)
    trying path=/usr/sfw/lib/libgcc_s.so.1
    search path=/lib/64:/usr/lib/64:/opt/GCC-SunOS-10-4.1.1/lib/sparcv9  (configuration default - /var/ld/64/ld.config)
    trying path=/lib/64/libgcc_s.so.1
    trying path=/usr/lib/64/libgcc_s.so.1
    trying path=/opt/GCC-SunOS-10-4.1.1/lib/sparcv9/libgcc_s.so.1
        libgcc_s.so.1 =>         /opt/GCC-SunOS-10-4.1.1/lib/sparcv9/libgcc_s.so.1

   find object=libc.so.1; required by /usr/sfw/lib/64/libstdc++.so
    search path=/usr/sfw/lib  (RPATH from file /usr/sfw/lib/64/libstdc++.so)
    trying path=/usr/sfw/lib/libc.so.1
    search path=/lib/64:/usr/lib/64:/opt/GCC-SunOS-10-4.1.1/lib/sparcv9  (configuration default - /var/ld/64/ld.config)
    trying path=/lib/64/libc.so.1
        libc.so.1 =>     /lib/64/libc.so.1

   find object=libc.so.1; required by /lib/64/libm.so.2
    search path=/lib/64:/usr/lib/64:/opt/GCC-SunOS-10-4.1.1/lib/sparcv9  (configuration default - /var/ld/64/ld.config)
    trying path=/lib/64/libc.so.1

   find object=libc.so.1; required by /opt/GCC-SunOS-10-4.1.1/lib/sparcv9/libgcc_s.so.1
    search path=/lib/64:/usr/lib/64:/opt/GCC-SunOS-10-4.1.1/lib/sparcv9  (configuration default - /var/ld/64/ld.config)
    trying path=/lib/64/libc.so.1

   object=/lib/64/libc.so.1; filter for /usr/lib/sparcv9/ld.so.1

   object=/lib/64/libc.so.1; filter for libm.so.2

   find object=libm.so.2; required by /lib/64/libc.so.1
    search path=/lib/64:/usr/lib/64:/opt/GCC-SunOS-10-4.1.1/lib/sparcv9  (configuration default - /var/ld/64/ld.config)
    trying path=/lib/64/libm.so.2

   object=/lib/64/libc.so.1; filter for /platform/$PLATFORM/lib/sparcv9/libc_psr.so.1

   find object=/platform/SUNW,Sun-Fire-T200/lib/sparcv9/libc_psr.so.1; required by /lib/64/libc.so.1
        /platform/SUNW,Sun-Fire-T200/lib/sparcv9/libc_psr.so.1

No comments: