Fix linking of OpenLDAP libraries

Started by Albe Laurenzover 19 years ago28 messages
#1Albe Laurenz
all@adv.magwien.gv.at
1 attachment(s)

I have realized that my modifications in configure.in and
src/interfaces/libpq/Makefile to link libpq against
OpenLDAP are buggy.

Here is a proposed patch to fix it.

I write this to pgsql-hackers too because I want to share
the difficulty I'm facing - maybe somebody has a better
idea.

To handle thread safety, OpenLDAP comes with a second
library libldap_r. The thread safe API is identical to
the normal API, the difference is that you must link
against libldap_r instead of libldap to get thead safety.

These are my problems:
- While libpq should be thread safe when ./configured with
--enable_thread_safety, the backend should be linked
against the normal libldap.
- At least on RedHat Linux, you need to link against the
pthread library too if you want to link against libldap_r,
because the latter has unresolved dependencies.

My solution:
- If thread safety is not desired, I link against libldap.
No problem.
- If thread safety is desired, I first try to link against
libldap_r without the thread libraries, and only if that
fails add the thread libraries to LIBS.
- I tweak src/backend/Makefile so that it strips libldap_r
and the thread libs from LIBS and replace it with
libldap if necessary.

That means that if --enable_thread_safety and --with-ldap
is both specified, all executables except 'postgres' will
be linked against libldap_r (and the thread libs, if
necessary).

I tested my patch on RedHat Enterprise Linux 3 and AIX 5.3.

The behaviour for Windows (use the native WLDAP32.DLL)
is unchanged.

Yours,
Laurenz Albe

Attachments:

ldaplink.patchapplication/octet-stream; name=ldaplink.patchDownload
diff -c -r pgsql.orig/configure.in pgsql/configure.in
*** pgsql.orig/configure.in	2006-08-21 10:41:01.000000000 +0200
--- pgsql/configure.in	2006-08-21 11:27:51.000000000 +0200
***************
*** 709,722 ****
  fi
  
  
- if test "$with_ldap" = yes ; then
-   if test "$PORTNAME" != "win32"; then
-      AC_CHECK_LIB(ldap,    ldap_bind, [], [AC_MSG_ERROR([library 'ldap' is required for LDAP])])
-   else
-      AC_CHECK_LIB(wldap32, ldap_bind, [], [AC_MSG_ERROR([library 'wldap32' is required for LDAP])])
-   fi
- fi
- 
  ##
  ## Header files
  ##
--- 709,714 ----
***************
*** 1109,1122 ****
  PGAC_FUNC_GETPWUID_R_5ARG
  PGAC_FUNC_STRERROR_R_INT
  
- # this will link libpq against libldap_r
- if test "$with_ldap" = yes ; then
-   if test "$PORTNAME" != "win32"; then
-     AC_CHECK_LIB(ldap_r,    ldap_simple_bind, [], [AC_MSG_ERROR([library 'ldap_r' is required for LDAP])])
-     PTHREAD_LIBS="$PTHREAD_LIBS -lldap_r"
-   fi
- fi
- 
  CFLAGS="$_CFLAGS"
  LIBS="$_LIBS"
  
--- 1101,1106 ----
***************
*** 1130,1135 ****
--- 1114,1137 ----
  AC_SUBST(PTHREAD_LIBS)
  
  
+ # We can test for libldap_r only after we know PTHREAD_LIBS
+ if test "$with_ldap" = yes ; then
+   if test "$PORTNAME" != "win32"; then
+     if test "$enable_thread_safety" = yes; then
+       # try without PTHREAD_LIBS first, different function to avoid cache
+       AC_CHECK_LIB(ldap_r, ldap_bind, [], [
+         AC_CHECK_LIB(ldap_r, ldap_simple_bind,
+           [LIBS="-lldap_r $PTHREAD_LIBS $LIBS"; HAVE_LIBLDAP_R=1],
+           [AC_MSG_ERROR([library 'ldap_r' is required for LDAP])], [$PTHREAD_LIBS])
+       ])
+     else
+       AC_CHECK_LIB(ldap,   ldap_bind, [], [AC_MSG_ERROR([library 'ldap' is required for LDAP])])
+     fi
+   else
+     AC_CHECK_LIB(wldap32,  ldap_bind, [], [AC_MSG_ERROR([library 'wldap32' is required for LDAP])])
+   fi
+ fi
+ 
  # This test makes sure that run tests work at all.  Sometimes a shared
  # library is found by the linker, but the runtime linker can't find it.
  # This check should come after all modifications of compiler or linker
diff -c -r pgsql.orig/src/backend/Makefile pgsql/src/backend/Makefile
*** pgsql.orig/src/backend/Makefile	2006-08-21 10:41:04.000000000 +0200
--- pgsql/src/backend/Makefile	2006-08-21 11:02:36.000000000 +0200
***************
*** 28,35 ****
  # We put libpgport into OBJS, so remove it from LIBS
  LIBS := $(filter-out -lpgport, $(LIBS))
  
  # The backend doesn't need everything that's in LIBS, however
! LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
  
  ##########################################################################
  
--- 28,40 ----
  # We put libpgport into OBJS, so remove it from LIBS
  LIBS := $(filter-out -lpgport, $(LIBS))
  
+ # If libldap_r is in LIBS, use libldap instead for the backend
+ ifeq ($(filter -lldap_r, $(LIBS)),-lldap_r)
+ LIBS += -lldap
+ endif
+ 
  # The backend doesn't need everything that's in LIBS, however
! LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses -lldap_r $(PTHREAD_LIBS), $(LIBS))
  
  ##########################################################################
  
diff -c -r pgsql.orig/src/interfaces/libpq/Makefile pgsql/src/interfaces/libpq/Makefile
*** pgsql.orig/src/interfaces/libpq/Makefile	2006-08-21 10:41:10.000000000 +0200
--- pgsql/src/interfaces/libpq/Makefile	2006-08-21 11:35:38.000000000 +0200
***************
*** 57,68 ****
  # shared library link.  (The order in which you list them here doesn't
  # matter.)
  ifneq ($(PORTNAME), win32)
! SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl, $(LIBS)) $(PTHREAD_LIBS)
  else
! SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl $(PTHREAD_LIBS), $(LIBS))
  endif
  ifeq ($(PORTNAME), win32)
! SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32 -lwldap32, $(LIBS))
  endif
  
  
--- 57,68 ----
  # shared library link.  (The order in which you list them here doesn't
  # matter.)
  ifneq ($(PORTNAME), win32)
! SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl -lldap -lldap_r, $(LIBS)) $(PTHREAD_LIBS)
  else
! SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl -lwldap32 $(PTHREAD_LIBS), $(LIBS))
  endif
  ifeq ($(PORTNAME), win32)
! SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
  endif
  
  
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albe Laurenz (#1)
Re: [HACKERS] Fix linking of OpenLDAP libraries

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

# The backend doesn't need everything that's in LIBS, however
! LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses -lldap_r $(PTHREAD_LIBS), $(LIBS))

This seems pretty risky. What if PTHREAD_LIBS contains -L switches?
They'd get removed even if needed for other libraries.

It would probably be safer not to put LDAP into LIBS at all, but invent
two new macros for configure to set, say LDAP_LIBS and LDAP_LIBS_R,
and add these to the link lines in the backend and libpq respectively.

regards, tom lane

#3Albe Laurenz
all@adv.magwien.gv.at
In reply to: Tom Lane (#2)
Re: [HACKERS] Fix linking of OpenLDAP libraries

Tom Lane wrote on September 04, 2006:

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

# The backend doesn't need everything that's in LIBS, however
! LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses

-lcurses -lldap_r $(PTHREAD_LIBS), $(LIBS))

This seems pretty risky. What if PTHREAD_LIBS contains -L switches?
They'd get removed even if needed for other libraries.

It would probably be safer not to put LDAP into LIBS at all, but

invent

two new macros for configure to set, say LDAP_LIBS and LDAP_LIBS_R,
and add these to the link lines in the backend and libpq respectively.

That seems like a good idea.
I'll try to work it out and resubmit the fix.

Yours,
Laurenz Albe

#4Albe Laurenz
all@adv.magwien.gv.at
In reply to: Albe Laurenz (#3)
1 attachment(s)
Re: [HACKERS] Fix linking of OpenLDAP libraries

Tom Lane wrote:

I have realized that my modifications in configure.in and
src/interfaces/libpq/Makefile to link libpq against
OpenLDAP are buggy.

Here is a proposed patch to fix it.

[...]

# The backend doesn't need everything that's in LIBS, however
! LIBS := $(filter-out -lz -lreadline -ledit -ltermcap
-lncurses -lcurses -lldap_r $(PTHREAD_LIBS), $(LIBS))

This seems pretty risky. What if PTHREAD_LIBS contains -L switches?
They'd get removed even if needed for other libraries.

It would probably be safer not to put LDAP into LIBS at all,
but invent two new macros for configure to set, say LDAP_LIBS
and LDAP_LIBS_R, and add these to the link lines in the backend
and libpq respectively.

Here is a new patch that replaces the previous one; it adds two
macros LDAP_LIBS_FE and LDAP_LIBS_BE for frontend and backend,
respectively.

I did not only add them to the Makefile for interfaces/libpq,
but also everywhere something is linked against libpq in case
somebody links static.
I don't know if that's necessary, or if static builds are
supported - if not, the changes to those Makefiles should
perhaps not be applied.

Tested on Linux, AIX and Windows.

Yours,
Laurenz Albe

Attachments:

ldaplink2.patchapplication/octet-stream; name=ldaplink2.patchDownload
diff -r -c pgsql.orig/configure.in pgsql/configure.in
*** pgsql.orig/configure.in	2006-09-05 15:53:13.000000000 +0200
--- pgsql/configure.in	2006-09-05 16:18:56.000000000 +0200
***************
*** 709,722 ****
  fi
  
  
- if test "$with_ldap" = yes ; then
-   if test "$PORTNAME" != "win32"; then
-      AC_CHECK_LIB(ldap,    ldap_bind, [], [AC_MSG_ERROR([library 'ldap' is required for LDAP])])
-   else
-      AC_CHECK_LIB(wldap32, ldap_bind, [], [AC_MSG_ERROR([library 'wldap32' is required for LDAP])])
-   fi
- fi
- 
  ##
  ## Header files
  ##
--- 709,714 ----
***************
*** 1109,1122 ****
  PGAC_FUNC_GETPWUID_R_5ARG
  PGAC_FUNC_STRERROR_R_INT
  
- # this will link libpq against libldap_r
- if test "$with_ldap" = yes ; then
-   if test "$PORTNAME" != "win32"; then
-     AC_CHECK_LIB(ldap_r,    ldap_simple_bind, [], [AC_MSG_ERROR([library 'ldap_r' is required for LDAP])])
-     PTHREAD_LIBS="$PTHREAD_LIBS -lldap_r"
-   fi
- fi
- 
  CFLAGS="$_CFLAGS"
  LIBS="$_LIBS"
  
--- 1101,1106 ----
***************
*** 1130,1135 ****
--- 1114,1147 ----
  AC_SUBST(PTHREAD_LIBS)
  
  
+ # We can test for libldap_r only after we know PTHREAD_LIBS
+ if test "$with_ldap" = yes ; then
+   _LIBS="$LIBS"
+   if test "$PORTNAME" != "win32"; then
+     AC_CHECK_LIB(ldap, ldap_bind, [], [AC_MSG_ERROR([library 'ldap' is required for LDAP])])
+     LDAP_LIBS_BE="-lldap"
+     if test "$enable_thread_safety" = yes; then
+       # try without PTHREAD_LIBS first, different function to avoid cache
+       AC_CHECK_LIB(ldap_r, ldap_bind, [], [
+         AC_CHECK_LIB(ldap_r, ldap_simple_bind,
+           [LIBS="-lldap_r $PTHREAD_LIBS $LIBS"; HAVE_LIBLDAP_R=1],
+           [AC_MSG_ERROR([library 'ldap_r' is required for LDAP])], [$PTHREAD_LIBS])
+       ])
+       LDAP_LIBS_FE="-lldap_r"
+     else
+       LDAP_LIBS_FE="-lldap"
+     fi
+   else
+     AC_CHECK_LIB(wldap32,  ldap_bind, [], [AC_MSG_ERROR([library 'wldap32' is required for LDAP])])
+     LDAP_LIBS_FE="-lwldap32"
+     LDAP_LIBS_BE="-lwldap32"
+   fi
+   LIBS="$_LIBS"
+ fi
+ AC_SUBST(LDAP_LIBS_FE)
+ AC_SUBST(LDAP_LIBS_BE)
+ 
+ 
  # This test makes sure that run tests work at all.  Sometimes a shared
  # library is found by the linker, but the runtime linker can't find it.
  # This check should come after all modifications of compiler or linker
diff -r -c pgsql.orig/src/backend/Makefile pgsql/src/backend/Makefile
*** pgsql.orig/src/backend/Makefile	2006-09-05 15:53:16.000000000 +0200
--- pgsql/src/backend/Makefile	2006-09-05 16:20:16.000000000 +0200
***************
*** 26,32 ****
  OBJS = $(SUBSYSOBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
  
  # We put libpgport into OBJS, so remove it from LIBS
! LIBS := $(filter-out -lpgport, $(LIBS))
  
  # The backend doesn't need everything that's in LIBS, however
  LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
--- 26,32 ----
  OBJS = $(SUBSYSOBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
  
  # We put libpgport into OBJS, so remove it from LIBS
! LIBS := $(filter-out -lpgport, $(LIBS) $(LDAP_LIBS_BE))
  
  # The backend doesn't need everything that's in LIBS, however
  LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
diff -r -c pgsql.orig/src/bin/pg_ctl/Makefile pgsql/src/bin/pg_ctl/Makefile
*** pgsql.orig/src/bin/pg_ctl/Makefile	2006-09-05 15:53:19.000000000 +0200
--- pgsql/src/bin/pg_ctl/Makefile	2006-09-07 16:39:50.000000000 +0200
***************
*** 21,27 ****
  all: submake-libpq submake-libpgport pg_ctl
  
  pg_ctl: $(OBJS) $(libpq_builddir)/libpq.a
! 	$(CC) $(CFLAGS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
  
  install: all installdirs
  	$(INSTALL_PROGRAM) pg_ctl$(X) '$(DESTDIR)$(bindir)/pg_ctl$(X)'
--- 21,27 ----
  all: submake-libpq submake-libpgport pg_ctl
  
  pg_ctl: $(OBJS) $(libpq_builddir)/libpq.a
! 	$(CC) $(CFLAGS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) $(LDAP_LIBS_FE) -o $@$(X)
  
  install: all installdirs
  	$(INSTALL_PROGRAM) pg_ctl$(X) '$(DESTDIR)$(bindir)/pg_ctl$(X)'
diff -r -c pgsql.orig/src/bin/pg_dump/Makefile pgsql/src/bin/pg_dump/Makefile
*** pgsql.orig/src/bin/pg_dump/Makefile	2006-09-05 15:53:19.000000000 +0200
--- pgsql/src/bin/pg_dump/Makefile	2006-09-07 16:29:43.000000000 +0200
***************
*** 15,20 ****
--- 15,21 ----
  include $(top_builddir)/src/Makefile.global
  
  override CPPFLAGS := -DFRONTEND -I$(libpq_srcdir) $(CPPFLAGS)
+ LIBS += $(LDAP_LIBS_FE)
  
  OBJS=	pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
  	pg_backup_files.o pg_backup_null.o pg_backup_tar.o \
diff -r -c pgsql.orig/src/bin/psql/Makefile pgsql/src/bin/psql/Makefile
*** pgsql.orig/src/bin/psql/Makefile	2006-09-05 15:53:19.000000000 +0200
--- pgsql/src/bin/psql/Makefile	2006-09-07 16:32:27.000000000 +0200
***************
*** 31,37 ****
  all: submake-libpq submake-libpgport submake-backend psql
  
  psql: $(OBJS) $(libpq_builddir)/libpq.a
! 	$(CC) $(CFLAGS) $(OBJS) $(EXTRA_OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
  
  help.o: $(srcdir)/sql_help.h
  
--- 31,37 ----
  all: submake-libpq submake-libpgport submake-backend psql
  
  psql: $(OBJS) $(libpq_builddir)/libpq.a
! 	$(CC) $(CFLAGS) $(OBJS) $(EXTRA_OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) $(LDAP_LIBS_FE) -o $@$(X)
  
  help.o: $(srcdir)/sql_help.h
  
diff -r -c pgsql.orig/src/bin/scripts/Makefile pgsql/src/bin/scripts/Makefile
*** pgsql.orig/src/bin/scripts/Makefile	2006-09-05 15:53:19.000000000 +0200
--- pgsql/src/bin/scripts/Makefile	2006-09-07 16:33:44.000000000 +0200
***************
*** 21,27 ****
  all: submake-libpq submake-backend $(PROGRAMS)
  
  %: %.o $(WIN32RES)
! 	$(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
  
  createdb: createdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o
  createlang: createlang.o common.o print.o mbprint.o
--- 21,27 ----
  all: submake-libpq submake-backend $(PROGRAMS)
  
  %: %.o $(WIN32RES)
! 	$(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LIBS) $(LDAP_LIBS_FE) -o $@$(X)
  
  createdb: createdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o
  createlang: createlang.o common.o print.o mbprint.o
diff -r -c pgsql.orig/src/interfaces/ecpg/compatlib/Makefile pgsql/src/interfaces/ecpg/compatlib/Makefile
*** pgsql.orig/src/interfaces/ecpg/compatlib/Makefile	2006-09-05 15:53:20.000000000 +0200
--- pgsql/src/interfaces/ecpg/compatlib/Makefile	2006-09-06 11:28:17.000000000 +0200
***************
*** 22,28 ****
  override CFLAGS += $(PTHREAD_CFLAGS)
  SHLIB_LINK = -L../ecpglib -lecpg -L../pgtypeslib -lpgtypes $(libpq) \
  	$(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt -lm, $(LIBS)) \
! 	$(PTHREAD_LIBS)
  
  OBJS= informix.o
  
--- 22,28 ----
  override CFLAGS += $(PTHREAD_CFLAGS)
  SHLIB_LINK = -L../ecpglib -lecpg -L../pgtypeslib -lpgtypes $(libpq) \
  	$(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt -lm, $(LIBS)) \
! 	$(LDAP_LIBS_FE) $(PTHREAD_LIBS)
  
  OBJS= informix.o
  
diff -r -c pgsql.orig/src/interfaces/ecpg/ecpglib/Makefile pgsql/src/interfaces/ecpg/ecpglib/Makefile
*** pgsql.orig/src/interfaces/ecpg/ecpglib/Makefile	2006-09-05 15:53:20.000000000 +0200
--- pgsql/src/interfaces/ecpg/ecpglib/Makefile	2006-09-06 11:27:16.000000000 +0200
***************
*** 35,41 ****
  endif
  
  SHLIB_LINK = -L../pgtypeslib -lpgtypes $(libpq) \
! 	$(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt -lm, $(LIBS)) $(PTHREAD_LIBS)
  
  ifeq ($(PORTNAME), win32)
  # Link to shfolder.dll instead of shell32.dll
--- 35,41 ----
  endif
  
  SHLIB_LINK = -L../pgtypeslib -lpgtypes $(libpq) \
! 	$(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt -lm, $(LIBS)) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)
  
  ifeq ($(PORTNAME), win32)
  # Link to shfolder.dll instead of shell32.dll
diff -r -c pgsql.orig/src/interfaces/ecpg/test/Makefile.regress pgsql/src/interfaces/ecpg/test/Makefile.regress
*** pgsql.orig/src/interfaces/ecpg/test/Makefile.regress	2006-09-05 15:53:21.000000000 +0200
--- pgsql/src/interfaces/ecpg/test/Makefile.regress	2006-09-07 16:23:31.000000000 +0200
***************
*** 3,9 ****
  override CFLAGS += $(PTHREAD_CFLAGS) 
  
  override LDFLAGS := -L../../ecpglib -L../../pgtypeslib -L../../../libpq $(LDFLAGS)
! override LIBS := -lpgtypes -lecpg -lpq $(LIBS) $(PTHREAD_LIBS)
  
  ECPG = ../../preproc/ecpg -I$(srcdir)/../../include
  
--- 3,9 ----
  override CFLAGS += $(PTHREAD_CFLAGS) 
  
  override LDFLAGS := -L../../ecpglib -L../../pgtypeslib -L../../../libpq $(LDFLAGS)
! override LIBS := -lpgtypes -lecpg -lpq $(LIBS) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)
  
  ECPG = ../../preproc/ecpg -I$(srcdir)/../../include
  
diff -r -c pgsql.orig/src/interfaces/libpq/Makefile pgsql/src/interfaces/libpq/Makefile
*** pgsql.orig/src/interfaces/libpq/Makefile	2006-09-05 15:53:21.000000000 +0200
--- pgsql/src/interfaces/libpq/Makefile	2006-09-05 16:16:32.000000000 +0200
***************
*** 57,68 ****
  # shared library link.  (The order in which you list them here doesn't
  # matter.)
  ifneq ($(PORTNAME), win32)
! SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl, $(LIBS)) $(PTHREAD_LIBS)
  else
! SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl $(PTHREAD_LIBS), $(LIBS))
  endif
  ifeq ($(PORTNAME), win32)
! SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32 -lwldap32, $(LIBS))
  endif
  
  
--- 57,68 ----
  # shared library link.  (The order in which you list them here doesn't
  # matter.)
  ifneq ($(PORTNAME), win32)
! SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl -lldap -lldap_r, $(LIBS) $(LDAP_LIBS_FE)) $(PTHREAD_LIBS)
  else
! SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl -lwldap32 $(PTHREAD_LIBS), $(LIBS) $(LDAP_LIBS_FE))
  endif
  ifeq ($(PORTNAME), win32)
! SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
  endif
  
  
diff -r -c pgsql.orig/src/Makefile.global.in pgsql/src/Makefile.global.in
*** pgsql.orig/src/Makefile.global.in	2006-09-05 15:53:21.000000000 +0200
--- pgsql/src/Makefile.global.in	2006-09-05 16:17:27.000000000 +0200
***************
*** 219,224 ****
--- 219,226 ----
  # Linking
  
  LIBS = @LIBS@
+ LDAP_LIBS_FE = @LDAP_LIBS_FE@
+ LDAP_LIBS_BE = @LDAP_LIBS_BE@
  LD = @LD@
  with_gnu_ld = @with_gnu_ld@
  ld_R_works = @ld_R_works@
#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albe Laurenz (#4)
Re: [HACKERS] Fix linking of OpenLDAP libraries

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

I did not only add them to the Makefile for interfaces/libpq,
but also everywhere something is linked against libpq in case
somebody links static.

I intensely dislike that part of the patch, but will work on applying
the rest.

If we do need to start mentioning all of libpq's dependencies everywhere
it's linked, I think it's time for a generic solution to that, instead
of hacking each such place over again every time a new dependency pops up.
But at the moment I'm unconvinced that we need to do it.

regards, tom lane

#6Martijn van Oosterhout
kleptog@svana.org
In reply to: Tom Lane (#5)
Re: [HACKERS] Fix linking of OpenLDAP libraries

On Fri, Sep 08, 2006 at 03:20:00PM -0400, Tom Lane wrote:

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

I did not only add them to the Makefile for interfaces/libpq,
but also everywhere something is linked against libpq in case
somebody links static.

If we do need to start mentioning all of libpq's dependencies everywhere
it's linked, I think it's time for a generic solution to that, instead
of hacking each such place over again every time a new dependency pops up.

The business of having to include every single dependancy when linking
static is quite irritating. It has almost reached the point where
people are just giving up static linking because it's too much of a
pain.

However, if we do want to support it, the way you do it is by extending
pg_config to do something like:

pg_config --dynamic-lick => returns -lpq
pg_config --static-link => returns -lpq <plus other libs>

That way only people who actually want static linking need be bothered.

Have a ncie day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

From each according to his ability. To each according to his ability to litigate.

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albe Laurenz (#4)
Re: [HACKERS] Fix linking of OpenLDAP libraries

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

Here is a new patch that replaces the previous one; it adds two
macros LDAP_LIBS_FE and LDAP_LIBS_BE for frontend and backend,
respectively.

I did not only add them to the Makefile for interfaces/libpq,
but also everywhere something is linked against libpq in case
somebody links static.

Applied, but without that last part. It builds OK for me on Darwin,
which is moderately picky about that sort of thing, but someone should
try AIX.

regards, tom lane

#8Christopher Browne
cbbrowne@acm.org
In reply to: Albe Laurenz (#4)
Re: [HACKERS] Fix linking of OpenLDAP libraries

tgl@sss.pgh.pa.us (Tom Lane) wrote:

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

Here is a new patch that replaces the previous one; it adds two
macros LDAP_LIBS_FE and LDAP_LIBS_BE for frontend and backend,
respectively.

I did not only add them to the Makefile for interfaces/libpq,
but also everywhere something is linked against libpq in case
somebody links static.

Applied, but without that last part. It builds OK for me on Darwin,
which is moderately picky about that sort of thing, but someone should
try AIX.

I'd like to, but that has to take second place to Slony-I activity
next week; I'll see about putting that on my ToDo list. (After SSL,
readline...)
--
output = ("cbbrowne" "@" "gmail.com")
http://linuxdatabases.info/info/emacs.html
Send messages calling for fonts not available to the recipient(s).
This can (in the case of Zmail) totally disable the user's machine and
mail system for up to a whole day in some circumstances.
-- from the Symbolics Guidelines for Sending Mail

#9Albe Laurenz
all@adv.magwien.gv.at
In reply to: Christopher Browne (#8)
Re: [HACKERS] Fix linking of OpenLDAP libraries

Here is a new patch that replaces the previous one; it adds two
macros LDAP_LIBS_FE and LDAP_LIBS_BE for frontend and backend,
respectively.

I did not only add them to the Makefile for interfaces/libpq,
but also everywhere something is linked against libpq in case
somebody links static.

Applied, but without that last part. It builds OK for me on Darwin,
which is moderately picky about that sort of thing, but someone should
try AIX.

I'll do that today.

Laurenz Albe

#10Albe Laurenz
all@adv.magwien.gv.at
In reply to: Albe Laurenz (#9)
Re: [HACKERS] Fix linking of OpenLDAP libraries

Tom Lane wrote:

Here is a new patch that replaces the previous one; it adds two
macros LDAP_LIBS_FE and LDAP_LIBS_BE for frontend and backend,
respectively.

I did not only add them to the Makefile for interfaces/libpq,
but also everywhere something is linked against libpq in case
somebody links static.

Applied, but without that last part. It builds OK for me on Darwin,
which is moderately picky about that sort of thing, but someone should
try AIX.

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.

Should -lldap or -lldap_r be added to pg_config --libs?
If yes, which of them?

Yours,
Laurenz Albe

#11Martijn van Oosterhout
kleptog@svana.org
In reply to: Albe Laurenz (#10)
Re: [HACKERS] Fix linking of OpenLDAP libraries

On Mon, Sep 11, 2006 at 12:13:29PM +0200, Albe Laurenz wrote:

Applied, but without that last part. It builds OK for me on Darwin,
which is moderately picky about that sort of thing, but someone should
try AIX.

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.

Should -lldap or -lldap_r be added to pg_config --libs?
If yes, which of them?

Static links are going to require it on every platform, not just AIX.
The question do we want to ask is how easy do we want to make static
linking, because the same treatment will have to apply to -lssl,
-lcrypto, -lkrb5, -lk5crypto and quite possibly others. Do we really
want to go there?

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

From each according to his ability. To each according to his ability to litigate.

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albe Laurenz (#10)
Re: [HACKERS] Fix linking of OpenLDAP libraries

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

Tom Lane wrote:

Applied, but without that last part. It builds OK for me on Darwin,
which is moderately picky about that sort of thing, but someone should
try AIX.

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.

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.

regards, tom lane

#13Tom Lane
tgl@sss.pgh.pa.us
In reply to: Martijn van Oosterhout (#11)
Re: [HACKERS] Fix linking of OpenLDAP libraries

Martijn van Oosterhout <kleptog@svana.org> writes:

Static links are going to require it on every platform, not just AIX.
The question do we want to ask is how easy do we want to make static
linking, because the same treatment will have to apply to -lssl,
-lcrypto, -lkrb5, -lk5crypto and quite possibly others. Do we really
want to go there?

Well, we already have a solution for static linking within the PG build
environment, the question is do we wish to export it. Given the lack of
complaints to date, I think not. Do we really want to encourage anyone
to statically link libraries that don't belong to their project? It's
not only the build-time dependency hell, it's the difficulty of
installing library updates. There's a reason why dynamic link is the
default on all modern platforms.

regards, tom lane

#14Albe Laurenz
all@adv.magwien.gv.at
In reply to: Tom Lane (#13)
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) only a 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.so unless 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

#15Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albe Laurenz (#14)
Re: [PATCHES] Fix linking of OpenLDAP libraries

"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

#16Kevin Brown
kevin@sysexperts.com
In reply to: Tom Lane (#15)
Re: [PATCHES] Fix linking of OpenLDAP libraries

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

#17Albe Laurenz
all@adv.magwien.gv.at
In reply to: Kevin Brown (#16)
Re: [PATCHES] Fix linking of OpenLDAP libraries

Kevin Brown wrote:

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.

That is not entirely true.
The difference between a static and a shared library on AIX
is that the *.o files in a dynamic library are dynamic objects,
produced by the linker (what is called *.so in Linux), and the
*.o files in a static library are the output of the compiler
(what is called *.o in Linux).

What IS true is that you can do a static build against a dynamic
library. Against a static library you can only do static builds.

Yours,
Laurenz Albe

#18Albe Laurenz
all@adv.magwien.gv.at
In reply to: Albe Laurenz (#17)
1 attachment(s)
Re: [PATCHES] Fix linking of OpenLDAP libraries

Tom Lane wrote:

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.

The natural way in AIX would be:
- Create libpq.so
- Create libpq.a by 'rm -f libpq.a; ar -rc libpq.a libpq.so'
- Install only libpq.a

For a static build on AIX, you have to specify all the libraries and
give the linker -bstatic and -bI:/lib/syscalls.exp

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

I have done that (see the attached patch) and it works fine.
I don't have the native AIX C compiler, so I could only test
it with gcc.

I have taken the liberty to modify the static link line
in Makefile.global.in to contain the LDAP libraries, I hope
that's appropriate.

Yours,
Laurenz Albe

Attachments:

aix.link.patchapplication/octet-stream; name=aix.link.patchDownload
diff -c -r pgsql.orig/src/Makefile.global.in pgsql/src/Makefile.global.in
*** pgsql.orig/src/Makefile.global.in	2006-09-11 10:22:38.000000000 +0200
--- pgsql/src/Makefile.global.in	2006-09-12 14:02:55.000000000 +0200
***************
*** 343,355 ****
  # If doing static linking, shared library dependency info isn't available,
  # so add in the libraries that libpq depends on.
  ifeq ($(enable_shared), no)
! libpq += $(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt, $(LIBS)) $(PTHREAD_LIBS)
! else
! # On AIX even shared libraries do not remember their required libs,
! # so again add in what libpq depends on.
! ifeq ($(PORTNAME), aix)
! libpq += $(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt, $(LIBS)) $(PTHREAD_LIBS)
! endif
  endif
  
  # This macro is for use by client executables (not libraries) that use libpq.
--- 343,349 ----
  # If doing static linking, shared library dependency info isn't available,
  # so add in the libraries that libpq depends on.
  ifeq ($(enable_shared), no)
! libpq += $(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt -lldap -lldap_r, $(LIBS) $(LDAP_LIBS_FE)) $(PTHREAD_LIBS)
  endif
  
  # This macro is for use by client executables (not libraries) that use libpq.
diff -c -r pgsql.orig/src/template/aix pgsql/src/template/aix
*** pgsql.orig/src/template/aix	2006-09-11 10:22:38.000000000 +0200
--- pgsql/src/template/aix	2006-09-12 14:04:16.000000000 +0200
***************
*** 7,12 ****
--- 7,15 ----
        CFLAGS="-O2 -qmaxmem=16384 -qsrcmsg -qlonglong"
        ;;
    esac
+   LDFLAGS="$LDFLAGS -brtl"
+ else
+   LDFLAGS="$LDFLAGS -Wl,-brtl"
  fi
  
  # Native memset() is faster, tested on:
#19Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albe Laurenz (#18)
AIX shared libraries (was Re: [PATCHES] Fix linking of OpenLDAP libraries)

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

Tom Lane wrote:

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.

The natural way in AIX would be:
- Create libpq.so
- Create libpq.a by 'rm -f libpq.a; ar -rc libpq.a libpq.so'
- Install only libpq.a

Hm. This seems possible with some moderate hacking on Makefile.shlib
(certainly it'd be no more invasive than the existing Windows-specific
platform variants). However, looking at what's already in
Makefile.shlib for AIX makes me doubt the above claim a bit, because
AFAICS libpq.so is produced from libpq.a on that platform. Is it
possible that the rules have changed across AIX versions, and that the
code in there now is needful for older versions?

Another issue with installing only .a is that there's no provision
for versioning in .a library names ... what happens to someone who
needs two generations of libpq on his machine?

regards, tom lane

#20Albe Laurenz
all@adv.magwien.gv.at
In reply to: Tom Lane (#19)
Re: AIX shared libraries (was Re: [PATCHES] Fix linking of OpenLDAP libraries)

Tom Lane wrote:

The natural way in AIX would be:
- Create libpq.so
- Create libpq.a by 'rm -f libpq.a; ar -rc libpq.a libpq.so'
- Install only libpq.a

Hm. This seems possible with some moderate hacking on Makefile.shlib
(certainly it'd be no more invasive than the existing Windows-specific
platform variants). However, looking at what's already in
Makefile.shlib for AIX makes me doubt the above claim a bit, because
AFAICS libpq.so is produced from libpq.a on that platform. Is it
possible that the rules have changed across AIX versions, and that the
code in there now is needful for older versions?

I don't think that this behaviour has changed. I remember it from
AIX 4.3.2.

Of course libpq.so is created from (the static) libpq.a.
But once you have the dynamic library, you can link statically
against it.

Another issue with installing only .a is that there's no provision
for versioning in .a library names ... what happens to someone who
needs two generations of libpq on his machine?

Use different directories and set LIBPATH?
I don't know if there is a canonical way to do that. I'll investigate.

Yours,
Laurenz Albe

#21Rocco Altier
RoccoA@Routescape.com
In reply to: Albe Laurenz (#20)
Re: AIX shared libraries (was Re: [PATCHES] Fix linking of OpenLDAP libraries)

Tom Lane wrote:

Is it
possible that the rules have changed across AIX versions,
and that the code in there now is needful for older versions?

I don't think that this behaviour has changed. I remember it from
AIX 4.3.2.

AIX 4.3 is the first version to support the -brtl. The current code is
in place to mimic the behaviour of dlopen, etc, on the older platforms.

I think we are at a point that we can stop maintaining AIX older than
4.3 if we want.

-rocco

#22Rocco Altier
RoccoA@Routescape.com
In reply to: Albe Laurenz (#18)
Re: [PATCHES] Fix linking of OpenLDAP libraries

The patch did not work for me :-(

My buildfarm members failed in local testing to execute the
install-check, because initdb failed to find libpq.so.

Make check did succeed, so I think there is a possibility of getting it
working, but it won't be as simple as adding -brtl to the template.

I was also getting duplicate symbols in the link, that I wasn't before
either.

I don't have time right now to work through all the issues, but wanted
to give feedback that the patch isn't quite this simple.

Thanks,
-rocco

Show quoted text

-----Original Message-----
From: pgsql-hackers-owner@postgresql.org
[mailto:pgsql-hackers-owner@postgresql.org] On Behalf Of Albe Laurenz
Sent: Tuesday, September 12, 2006 9:01 AM
To: Tom Lane *EXTERN*
Cc: pgsql-hackers@postgresql.org
Subject: Re: [PATCHES] [HACKERS] Fix linking of OpenLDAP libraries

Tom Lane wrote:

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.

The natural way in AIX would be:
- Create libpq.so
- Create libpq.a by 'rm -f libpq.a; ar -rc libpq.a libpq.so'
- Install only libpq.a

For a static build on AIX, you have to specify all the libraries and
give the linker -bstatic and -bI:/lib/syscalls.exp

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

I have done that (see the attached patch) and it works fine.
I don't have the native AIX C compiler, so I could only test
it with gcc.

I have taken the liberty to modify the static link line
in Makefile.global.in to contain the LDAP libraries, I hope
that's appropriate.

Yours,
Laurenz Albe

#23Chris Browne
cbbrowne@acm.org
In reply to: Rocco Altier (#21)
Re: AIX shared libraries

RoccoA@Routescape.com ("Rocco Altier") writes:

Tom Lane wrote:

Is it
possible that the rules have changed across AIX versions,
and that the code in there now is needful for older versions?

I don't think that this behaviour has changed. I remember it from
AIX 4.3.2.

AIX 4.3 is the first version to support the -brtl. The current code is
in place to mimic the behaviour of dlopen, etc, on the older platforms.

I think we are at a point that we can stop maintaining AIX older than
4.3 if we want.

Version 5.1 is no longer being maintained by IBM; we were some
displeased when we heard when support offerings were expiring :-(.
Fortunately, we already had plans in place for a migration to 5.3.

I have to agree that even 4.3 is "really rather old" now.

Looking at IBM's "support lifecycle" list...
<http://www-306.ibm.com/software/info/supportlifecycle/list/a.html&gt;

AIX version Available Support Withdrawn
-----------------------------------------------------------------
5.1 May 2001 April 2006
5.2 Oct 2002 Sept 2008
5.3 Aug 2004 unannounced, presumably late 2010...

I'd guess that 4.3 fell out of support in late 2004.
--
let name="cbbrowne" and tld="linuxdatabases.info" in String.concat "@" [name;tld];;
http://linuxfinances.info/info/
"Of course 5 years from now that will be different, but 5 years from
now everyone will be running free GNU on their 200 MIPS, 64M
SPARCstation-5." -- Andrew Tanenbaum, 1992.

#24Albe Laurenz
all@adv.magwien.gv.at
In reply to: Chris Browne (#23)
Re: AIX shared libraries

Tom Lane wrote:

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.

Hm. This seems possible with some moderate hacking on Makefile.shlib
(certainly it'd be no more invasive than the existing Windows-specific
platform variants). [...]

Another issue with installing only .a is that there's no provision
for versioning in .a library names ... what happens to someone who
needs two generations of libpq on his machine?

Ok, I have spent some time researching and thinking, and I
have three proposals how to deal with linking on AIX.

1) Leave everything as it is and add the LDAP libraries to the
AIX hack in Makefile.shlib.
Pros:
- Little work.
Cons:
- PostgreSQL will continue to be statically linked on AIX (unless
somebody feeds configure the right LDFLAGS).

2) Remove the AIX hack from Makefile.shlib, add -brtl and
-blibpath:"$(rpathdir)":*-L directories in LDPATH*:/usr/lib:/lib
(this sets the AIX equivalent for RPATH) to LDFLAGS for AIX.
Pros:
- Dynamic linking on AIX.
- The organization of the libraries (libpq.a static,
libpq.so dynamic) is similar to other operating systems.
Cons:
- The library organization is counter-intuitive to AIX people,
and most people will inadvertedly link statically when linking
against libpq.
- According to Rocco Altier it will not work on historic
versions of AIX (no -brtl flag).

3) Major hacking in Makefile.shlib to achieve the following:
- libXX.so.n is built from libXX.a in the traditional way.
Then libXX.a is deleted, and recreated as archive
containing libXX.so.n.
- Linking takes place withOUT -brtl, but with -blibpath:...
as in 2).
- When the shared libs are installed, I see two options:
a) copy (and overwrite) libXX.a to libdir, do not
install libXX.so.n
b) Look for existing libXX.a in libdir, extract all
libXX.so.k from it, mark them LOADONLY with
'strip -e libXX.so.k', create a new libXX.a with
these objects and the new libXX.so.n

Pros:
- Dynamic linking on AIX.
- AIX-conforming organization of libraries.
- In the case of 3)b), multiple versions of the library
can be retained in the same archive. Linking is only
possible with the latest versions, but old programs
continue to work.
- 3)a) will probably work on older versions of AIX
(I hope there's a -blibpath flag).
Cons:
- Much work, particularly with 3)b).
- Library organization on AIX will be different from other
platforms.
- 3)b) will probably not work on old versions of AIX
(I read a posting that makes me believe that 'strip -e'
was not around before 4.3.3.

I am willing to implement whatever solution we decide upon.
I personally would prefer 3)a), but am happy with anything
except 1).

Yours,
Laurenz Albe

I personally would prefer 3)a)

#25Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albe Laurenz (#24)
Re: AIX shared libraries

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

I personally would prefer 3)a)

3) Major hacking in Makefile.shlib to achieve the following:
- libXX.so.n is built from libXX.a in the traditional way.
Then libXX.a is deleted, and recreated as archive
containing libXX.so.n.
- Linking takes place withOUT -brtl, but with -blibpath:...
as in 2).
- When the shared libs are installed, I see two options:
a) copy (and overwrite) libXX.a to libdir, do not
install libXX.so.n

Hm. The objection I see to this is that it will not support concurrent
installation of multiple libpq versions. What about

4) Build and install only libXX.so.n, don't install libXX.a at all

5) As 4), plus actively remove any libXX.a seen in the install directory

regards, tom lane

#26Albe Laurenz
all@adv.magwien.gv.at
In reply to: Tom Lane (#25)
Re: AIX shared libraries

Tom Lane wrote:

3) Major hacking in Makefile.shlib to achieve the following:
- libXX.so.n is built from libXX.a in the traditional way.
Then libXX.a is deleted, and recreated as archive
containing libXX.so.n.
- Linking takes place withOUT -brtl, but with -blibpath:...
as in 2).
- When the shared libs are installed, I see two options:
a) copy (and overwrite) libXX.a to libdir, do not
install libXX.so.n

Hm. The objection I see to this is that it will not support
concurrent installation of multiple libpq versions. What about

4) Build and install only libXX.so.n, don't install libXX.a at all

Won't work - the linker looks for libXX.so and won't find
libXX.so.n. If you create a symbolic link
libXX.so --> libXX.so.n, you can link, but the executable will
depend on libXX.so and not on libXX.so.n.

Moreover, you cannot link statically any more because in a
static link only libXX.a files will be searched...

5) As 4), plus actively remove any libXX.a seen in the
install directory

Same problem.

Yours,
Laurenz Albe

#27Tom Lane
tgl@sss.pgh.pa.us
In reply to: Albe Laurenz (#26)
Re: AIX shared libraries

"Albe Laurenz" <all@adv.magwien.gv.at> writes:

Tom Lane wrote:

Hm. The objection I see to this is that it will not support
concurrent installation of multiple libpq versions. What about

4) Build and install only libXX.so.n, don't install libXX.a at all

Won't work - the linker looks for libXX.so and won't find
libXX.so.n. If you create a symbolic link
libXX.so --> libXX.so.n, you can link, but the executable will
depend on libXX.so and not on libXX.so.n.

Ugh. So given that linker behavior, it's basically impossible to
support multiple libpq versions in the same directory anyway on AIX.

I concur with your 3a) then. Do you have time to do that now?

regards, tom lane

#28Albe Laurenz
all@adv.magwien.gv.at
In reply to: Tom Lane (#27)
Re: AIX shared libraries

Tom Lane wrote:

Ugh. So given that linker behavior, it's basically impossible to
support multiple libpq versions in the same directory anyway on AIX.

It is possible, if you have both versions of the shared object in
the same library. Essentially what I proposed for 3b).
It is the way IBM does it with their system libraries.

I set up a sample with libpq version 4 and version 5 in libpq.a:

$ dump -ov /postgres/8.2/lib/libpq.a
/postgres/8.2/lib/libpq.a[libpq.so.4]:
***Object Module Header***
[...]
Flags=( EXEC DYNLOAD SHROBJ LOADONLY DEP_SYSTEM )
[...]
/postgres/8.2/lib/libpq.a[libpq.so.5]:
***Object Module Header***
[...]
Flags=( EXEC DYNLOAD SHROBJ DEP_SYSTEM )
[...]

The linker will only link against the shared object that does
not have the LOADONLY flag set, but stuff linked against
libpq.a(libpq.so.4) will continue to work.

I concur with your 3a) then. Do you have time to do that now?

I'll start right away.

Yours,
Laurenz Albe