Skip to content

Commit 75c5626

Browse files
committed
Suppress macOS warnings about duplicate libraries in link commands.
As of Xcode 15 (macOS Sonoma), the linker complains about duplicate references to the same library. We see warnings about libpgport and libpgcommon being duplicated in many client executables. This is a consequence of the hack introduced in commit 6b7ef07 to list libpgport before libpq while not removing it from $(LIBS). (Commit 8396447 later applied the same rule to libpgcommon.) The concern in 6b7ef07 was to ensure that the client executable wouldn't unintentionally depend on pgport functions from libpq. That concern is obsolete on any platform for which we can do symbol export control, because if we can then the pgport functions in libpq won't be exposed anyway. Hence, we can fix this problem by just removing libpgport and libpgcommon from $(libpq_pgport), and letting clients depend on the occurrences in $(LIBS). In the back branches, do that only on macOS (which we know has symbol export control). In HEAD, let's be more aggressive and remove the extra libraries everywhere. The only still-supported platforms that lack export control are MinGW/Cygwin, and it doesn't seem worth sweating over ABI stability details for those (or if somebody does care, it'd probably be possible to perform symbol export control for those too). As well as being simpler, this might give some microscopic improvement in build time. The meson build system is not changed here, as it doesn't have this particular disease, though it does have some related issues that we'll fix separately. Discussion: https://postgr.es/m/467042.1695766998@sss.pgh.pa.us
1 parent 19bc6fd commit 75c5626

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/Makefile.global.in

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,19 +586,32 @@ endif
586586
libpq = -L$(libpq_builddir) -lpq
587587

588588
# libpq_pgport is for use by client executables (not libraries) that use libpq.
589-
# We force clients to pull symbols from the non-shared libraries libpgport
589+
# We want clients to pull symbols from the non-shared libraries libpgport
590590
# and libpgcommon rather than pulling some libpgport symbols from libpq just
591591
# because libpq uses those functions too. This makes applications less
592-
# dependent on changes in libpq's usage of pgport (on platforms where we
593-
# don't have symbol export control for libpq). To do this we link to
592+
# dependent on changes in libpq's usage of pgport. To do this we link to
594593
# pgport before libpq. This does cause duplicate -lpgport's to appear
595-
# on client link lines, since that also appears in $(LIBS).
594+
# on client link lines, since that also appears in $(LIBS). On platforms
595+
# where we have symbol export control for libpq, the whole exercise is
596+
# unnecessary because libpq won't expose any of these symbols. Currently,
597+
# only macOS warns about duplicate library references, so we only suppress
598+
# the duplicates on macOS.
599+
ifeq ($(PORTNAME),darwin)
600+
libpq_pgport = $(libpq)
601+
else ifdef PGXS
602+
libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq)
603+
else
604+
libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)
605+
endif
606+
596607
# libpq_pgport_shlib is the same idea, but for use in client shared libraries.
608+
# We need those clients to use the shlib variants. (Ideally, users of this
609+
# macro would strip libpgport and libpgcommon from $(LIBS), but no harm is
610+
# done if they don't, since they will have satisfied all their references
611+
# from these libraries.)
597612
ifdef PGXS
598-
libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq)
599613
libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
600614
else
601-
libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)
602615
libpq_pgport_shlib = -L$(top_builddir)/src/common -lpgcommon_shlib -L$(top_builddir)/src/port -lpgport_shlib $(libpq)
603616
endif
604617

0 commit comments

Comments
 (0)