As a recent bug pointed out, you really only want to link libraries you
actually need because the others could export functions that you don't
want and interfere. Rather than relying a GCC only feature, this takes
the good old fashioned approach: filtering out the libraries you don't

Attached is a patch which applies this filtering to the backend and has
the same results as linking with --as-needed. I basically took the
filter list of libpq and altered it as follows:

libs removed: -lnsl -lresolv
libs added: -ldl -lm

Incidently, the libs removed don't appear to be needed by anything in
any file in the source, so I wonder if they're even required.

This probably needs a bit of testing on a few different architechtures
to make sure it works. I also only apply it to the non-windows, non-aix
case since the building requirements there are different enough that
someone with such a platforn should do it.

Have a nice day,
Martijn van Oosterhout   <>
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Index: src/backend/Makefile
RCS file: /projects/cvsroot/pgsql/src/backend/Makefile,v
retrieving revision 1.110
diff -u -r1.110 Makefile
--- src/backend/Makefile        27 Oct 2005 20:45:29 -0000      1.110
+++ src/backend/Makefile        27 Nov 2005 19:40:09 -0000
@@ -40,8 +40,11 @@
 ifneq ($(PORTNAME), win32)
 ifneq ($(PORTNAME), aix)
+# Filter out libraries we don't need
+BACKEND_LIBS=$(filter -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl 
-lsocket -lintl -lcrypt -ldl -lm, $(LIBS))
 postgres: $(OBJS)
-       $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@
+       $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(BACKEND_LIBS) -o $@

Attachment: pgpTPfERIO7kC.pgp
Description: PGP signature

Reply via email to