Skip to content

Commit 4d10fda

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 f9cbff4 commit 4d10fda

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Makefile.global.in

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,19 @@ endif
574574
libpq = -L$(libpq_builddir) -lpq
575575

576576
# This macro is for use by client executables (not libraries) that use libpq.
577-
# We force clients to pull symbols from the non-shared libraries libpgport
577+
# We want clients to pull symbols from the non-shared libraries libpgport
578578
# and libpgcommon rather than pulling some libpgport symbols from libpq just
579579
# because libpq uses those functions too. This makes applications less
580580
# dependent on changes in libpq's usage of pgport. To do this we link to
581581
# pgport before libpq. This does cause duplicate -lpgport's to appear
582-
# on client link lines.
583-
ifdef PGXS
582+
# on client link lines, since that also appears in $(LIBS). On platforms
583+
# where we have symbol export control for libpq, the whole exercise is
584+
# unnecessary because libpq won't expose any of these symbols. Currently,
585+
# only macOS warns about duplicate library references, so we only suppress
586+
# the duplicates on macOS.
587+
ifeq ($(PORTNAME),darwin)
588+
libpq_pgport = $(libpq)
589+
else ifdef PGXS
584590
libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq)
585591
else
586592
libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)

0 commit comments

Comments
 (0)