Discussion:
ldd on AIX 5.2 not listing zlib library on built-in path
(too old to reply)
Renate Bahnemann
2003-10-24 11:45:11 UTC
Permalink
Hi

I would like to understand the results that I'm geting from ldd on AIX
5.2.

Also, I don't quite understand how AIX shared libraries are shipper.
It seems as though the shared object is held inside an archive (.a)
file.

I am trying to rebuild and ship a 3rd party library (zlib) that is
already installed in /usr/lib. There it is found as /usr/lib/libz.a

I've rebuilt zlib it in another directory from its .configure script.
My build environment contains the following:

export PATH=/bin:/usr/bin:/usr/sbin
export LDSHARED="cc -G"
export CC=xlc_r

./configure --prefix=targetdir --shared

This produces:
libz.so@ -> libz.so.1.1.4
libz.so.1@ -> libz.so.1.1.4
libz.so.1.1.4

(It was only when I added the LDSHARED setting that I managed to get a
shared lib. Before, I always built a static library.)

When I do 'dump -H myapp' I see that the path to zlib is showing my
directory.

However when I do
ldd myapp
I get:
...
/usr/lib/zlib.a(shr.o)
...

I've tried setting LIBPATH to point to my homegrown library first. But
it didn't help.

I was wondering whether the reason is that the one library is inside a
.a file whereas in the other one it is the shared object itself. And
that AIX prefers the .a format?

Any AIX guru's out there who wouldn't mind explaining this to me?

The reason why I am trying to do this is that I am building something
for 4 different UNIX platforms and am trying to be consistent across
all (AIX, Solaris, HPUX and Linux).

BTW ldd behaves strangely on our system. One has to be logged in as
root to run it.

Thanks
Renate
Ulrich--nO--(dot)-sPAM--Link
2003-10-24 15:37:10 UTC
Permalink
Post by Renate Bahnemann
I would like to understand the results that I'm geting from ldd on AIX
5.2.
Also, I don't quite understand how AIX shared libraries are shipper.
It seems as though the shared object is held inside an archive (.a)
file.
The AIX linker has some mighty features not present on other major
unices. A few weeks ago a url to a PDF was in this newsgroup.
I know all the answers are in this document, but I cannot say I
understood most of it. Heavy stuff.
Gary Hook is one of the authors.
There should be a styleguide for consistant use for system libs.
Post by Renate Bahnemann
I am trying to rebuild and ship a 3rd party library (zlib) that is
already installed in /usr/lib. There it is found as /usr/lib/libz.a
On AIX 5.1 /usr/lib/libz.a is a link to /opt/freeware/lib/libz.a

dump -Ht /opt/freeware/lib/libz.a shows that the archive libz.a contains
one member with the name "libz.so.1"
Post by Renate Bahnemann
I've rebuilt zlib it in another directory from its .configure script.
export PATH=/bin:/usr/bin:/usr/sbin
export LDSHARED="cc -G"
export CC=xlc_r
./configure --prefix=targetdir --shared
libz.so.1.1.4
(It was only when I added the LDSHARED setting that I managed to get a
shared lib. Before, I always built a static library.)
When I do 'dump -H myapp' I see that the path to zlib is showing my
directory.
AFAIK dump shows what the linker ld has written to disk at linktime, ldd
shows what was resolved at loadtime.
Post by Renate Bahnemann
However when I do
ldd myapp
...
/usr/lib/zlib.a(shr.o)
...
I've tried setting LIBPATH to point to my homegrown library first. But
it didn't help.
On AIX all objects are position independend. You don't need a compiler
flag like "-KPIC" or "-fpic".
I resolved the problem by relinking all objects from the static libz.a
to a new shared lib libz.a (On AIX 4.3.3).
If you build your zlib that way, a "/usr/lib/zlib.a (shr.o)" can be
resolved.

Managed to link the apps on AIX 5.1 against the system /usr/lib/libz.a
by simply copying the headers "zlib.h" and "zconf.h" into /usr/inlcude
before configuring a source package.
Works with openssl and openssh, but the resulting /usr/local/bin/ssh is
not interchangeable between 4.3.3 and 5.1 because the different layout
of the libz.a.
Post by Renate Bahnemann
I was wondering whether the reason is that the one library is inside a
.a file whereas in the other one it is the shared object itself. And
that AIX prefers the .a format?
AFAIK *.a is searched before *.so.
For including *.so into the library search path of an app, you need
to give a "-brtl" to xlc.
dump -Ht <filename of linker output> you can look at the library search
dirs compiled into the app. Further dirs can be given by environment
variables.
Post by Renate Bahnemann
Any AIX guru's out there who wouldn't mind explaining this to me?
The reason why I am trying to do this is that I am building something
for 4 different UNIX platforms and am trying to be consistent across
all (AIX, Solaris, HPUX and Linux).
Me too.
And consistent accross different releases of these O/S.

---
Uli
Paul Pluzhnikov
2003-10-24 16:05:00 UTC
Permalink
Post by Renate Bahnemann
Also, I don't quite understand how AIX shared libraries are shipper.
It seems as though the shared object is held inside an archive (.a)
file.
Yes, that's how AIX shared libraries have been built and shipped
for ages. The linker didn't used to support .so filenames at all.
Post by Renate Bahnemann
When I do 'dump -H myapp' I see that the path to zlib is showing my
directory.
How did you build "myapp", and what is the "dump -H" output?
Post by Renate Bahnemann
I've tried setting LIBPATH to point to my homegrown library first. But
it didn't help.
I am guessing your app depends on libz.a(shr.o). If so, it will
never look for libz.so, until you rebuild it.
Post by Renate Bahnemann
Any AIX guru's out there who wouldn't mind explaining this to me?
Read all about AIX dynamic linking here:

http://www.ibm.com/servers/esdd/pdfs/aix_ll.pdf

Cheers,
--
In order to understand recursion you must first understand recursion.
Renate Bahnemann
2003-10-28 19:09:05 UTC
Permalink
Uli & Paul

Thankyou very much for your help.

(I'm only getting back to this now because I was side tracked onto
something completely different and only got back to this problem
today.)

Adding the -brtl option for the linker seems to have solved my
problem.
Post by Paul Pluzhnikov
http://www.ibm.com/servers/esdd/pdfs/aix_ll.pdf
Thanks! very helpful document that I have bookmarked.
Post by Paul Pluzhnikov
How did you build "myapp", and what is the "dump -H" output?
I need to confess that the application that I am building is curl
(freeware) and its library libcurl. Again using the configure script
that is provided by the authors. I will eventually link libcurl into
our own application, but just wanted to get curl itself built
successfully.

The settings and command that gave me the desired results are:-

export ZLIBHOME=<homegrown-zlib-root-directory>
export SSLHOME=<homegrown-ssl-root-directory>
export CC=xlc_r
export CPPFLAGS=-I${ZLIBHOME}/include
export LDFLAGS="-brtl -L${ZLIBHOME}/lib -L{SSLHOME}/lib"
./configure --prefix=${DESTINATION} \
--with-ssl=${SSLHOME} \
--with-zlib=${ZLIBHOME} \
--enable-shared \
--disable-gopher \
--disable-ldap \
--disable-telnet
make
make install

I've got an empty LIBPATH and curl appears to find its shared
libraries OK.

"dump -H curl" gives the following output (hope this is readable):

<<< snip >>>
curl:

***Loader Section***
Loader Header Information
VERSION# #SYMtableENT #RELOCent LENidSTR
0x00000001 0x00000052 0x00000110 0x0000015e

#IMPfilID OFFidSTR LENstrTBL OFFstrTBL
0x00000009 0x00001490 0x0000024a 0x000015ee


***Import File Strings***
INDEX PATH BASE MEMBER
0 /export/src/cc/cc_Tools/aix-5.2-powerpc/curl-7.10.7/lib:/export/src/cc/cc_Tools/aix-5.2-powerpc/zlib-1.1.4/lib:/export/src/cc/cc_Tools/aix-5.2-powerpc/openssl-0.9.7b/lib:/usr/lpp/xlopt:/usr/lib/threads:/usr/lib:/lib
1 libcurl.so
2 libssl.so
3 libcrypto.so
4 libz.so
5 libpthreads.a shr_comm.o
6 libpthreads.a shr_xpg5.o
7 libc.a shr.o
8 librtl.a shr.o
<<< snip >>>

Results from "ldd curl" are:-

<<< snip >>>
curl needs:
/export/src/cc/cc_Tools/aix-5.2-powerpc/curl-7.10.7/lib/libcurl.so
/export/src/cc/cc_Tools/aix-5.2-powerpc/openssl-0.9.7b/lib/libssl.so
/export/src/cc/cc_Tools/aix-5.2-powerpc/openssl-0.9.7b/lib/libcrypto.so
/export/src/cc/cc_Tools/aix-5.2-powerpc/zlib-1.1.4/lib/libz.so
/usr/lib/libpthreads.a(shr_comm.o)
/usr/lib/libpthreads.a(shr_xpg5.o)
/usr/lib/threads/libc.a(shr.o)
/usr/lib/librtl.a(shr.o)
/unix
/usr/lib/libcrypt.a(shr.o)
<<< snip >>>
Post by Paul Pluzhnikov
The AIX linker has some mighty features not present on other major
unices. A few weeks ago a url to a PDF was in this newsgroup.
I know all the answers are in this document, but I cannot say I
understood most of it. Heavy stuff.
Neither did I. But it is a very handy document to have.
Post by Paul Pluzhnikov
There should be a styleguide for consistant use for system libs.
Post by Renate Bahnemann
I am trying to rebuild and ship a 3rd party library (zlib) that is
already installed in /usr/lib. There it is found as /usr/lib/libz.a
On AIX 5.1 /usr/lib/libz.a is a link to /opt/freeware/lib/libz.a
On our AIX 5.2 machine it is similarly a link to
/usr/opt/freeware/lib/libz.a
My goal was to *not* use it but to ship my own copy instead within our
own installation. We always set LIBPATH via a wrapper script to point
to our own library directory.
Post by Paul Pluzhnikov
AFAIK dump shows what the linker ld has written to disk at linktime, ldd
shows what was resolved at loadtime.
OK. That makes sense.
Post by Paul Pluzhnikov
On AIX all objects are position independend. You don't need a compiler
flag like "-KPIC" or "-fpic".
Thanks. That is usefull to know.
Post by Paul Pluzhnikov
I resolved the problem by relinking all objects from the static libz.a
to a new shared lib libz.a (On AIX 4.3.3).
If you build your zlib that way, a "/usr/lib/zlib.a (shr.o)" can be
resolved.
I somehow got a shared .so file built for libz. Again their configure
script did it for me.
Post by Paul Pluzhnikov
AFAIK *.a is searched before *.so.
That is what can be reversed by the -brtl flag, not so?
In the PDF document it says on p. 17 "...when -brtl is specified and
-bdynamic is in effect, the -l flag will search for files ending in
.so as well as in .a, though .so is given precedence over .a"
Post by Paul Pluzhnikov
For including *.so into the library search path of an app, you need
to give a "-brtl" to xlc.
Thanks! This piece of info provided the breakthrough for me.

Once again thankyou for your help.

Regards
Renate

Loading...