Thread: Re: [PATCHES] Fix linking of OpenLDAP libraries
Tom Lane wrote: >> It builds fine on AIX 5.3 as long as you tell it to link with >> libpq.so. Static builds against libpq.a will fail. > > Hm. We have been assuming that AIX's problem is that dynamic libraries > don't remember their dependencies properly, but maybe the real issue is > that it prefers static over dynamic libraries? If so, what we ought to > be doing is adding the prefer-dynamic-libraries switch to the default > LDFLAGS on that platform. AIX shared libraries know their dependencies well, and you don't have to specify them again when linking against the library. Let me expand a little on some of the peculiarities of shared libraries on AIX: - A normal AIX shared library is called libXX.a It is an 'ar' archive that contains the shared object(s). - In static linking mode, the shared object will be included in the executable. In dynamic linking mode (the default) onlya reference to the shared object is included. - AIX can also link against shared objects called libXX.so (like other UNIXen). - When it resolves a -lXX flag, the linker searches the -L list for libXX.a and libXX.so. It prefers libXX.a over libXX.sounless invoked with the flag -brtl. So the linker does not prefer static over dynamic libraries, it just perfers libXX.a over libXX.so. In our case, we have libpq.a and libpq.so in the same directory, so unless you link with -brtl you will get a static link (because libpq.a is a static library). To illustrate, let me include the output of 'ldd psql' for a dynamically linked PostgreSQL: 8.2/bin/psql needs: /postgres/8.2/lib/libpq.so /usr/lib/libpthread.a(shr_xpg5_64.o) /usr/lib/libc.a(shr_64.o) /usr/local/lib/libldap_r.a(libldap_r-2.3.so.0) /unix /usr/lib/libcrypt.a(shr_64.o) /usr/lib/libs.a(shr_64.o) See http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/c om.ibm.aix.cmds/doc/aixcmds3/ld.htm Should -brtl be added to src/template/aix? >> Should -lldap or -lldap_r be added to pg_config --libs? > > You have a mistaken idea of the purpose of pg_config --libs. > It exists to record what LIBS was at build time, not more, > not less. It is certainly not intended as a guide to how > to link libpq. *nods* Thanks for the clarification. Yours, Laurenz Albe
"Albe Laurenz" <all@adv.magwien.gv.at> writes: > Let me expand a little on some of the peculiarities of > shared libraries on AIX: > - A normal AIX shared library is called libXX.a > It is an 'ar' archive that contains the shared object(s). Ah, so the problem really boils down to funny naming conventions. If they use ".a" for both shared and static libraries, how does anyone tell the difference? > So the linker does not prefer static over dynamic libraries, > it just perfers libXX.a over libXX.so. > In our case, we have libpq.a and libpq.so in the same directory, > so unless you link with -brtl you will get a static link > (because libpq.a is a static library). I wonder whether we ought to suppress building (or at least installing) our .a libraries at all on AIX. Adding -btrl to LDFLAGS would help within the context of our own build, but external clients that link to libpq without saying that are going to get undesirable results. I think there's a reasonable argument that by installing a .a file that isn't a shared library, we are violating the platform's conventions. > Should -brtl be added to src/template/aix? Sounds that way, but that'll only help for psql and other stuff built within our build. Could you try this against CVS tip: * add -brtl to LDFLAGS in the template * Remove the AIX-specific hack on $(libpq) at lines 349-354 of src/Makefile.global.in * see if it configures and builds regards, tom lane
Tom Lane wrote: > "Albe Laurenz" <all@adv.magwien.gv.at> writes: > > Let me expand a little on some of the peculiarities of > > shared libraries on AIX: > > > - A normal AIX shared library is called libXX.a > > It is an 'ar' archive that contains the shared object(s). > > Ah, so the problem really boils down to funny naming conventions. > If they use ".a" for both shared and static libraries, how does anyone > tell the difference? It sounds to me like there is no difference. Notice how his example ldd output shows dependencies on specific .o entries within the various .a files that reside on the system, rather than on the .a files as a whole. If those entries had been statically linked then they wouldn't have shown up in the ldd output at all. So the difference is no longer between static libraries and shared libraries -- they're now just libraries. The only difference is how you link to them. What IBM has done here is very sensible, and is really what the other Unixes should have done from the beginning: a library is just a library, and what differs is how it's used. -- Kevin Brown kevin@sysexperts.com