postgresql/src/interfaces/libpq
Tom Lane a644f5fc66 Don't put library-supplied -L/-I switches before user-supplied ones.
For many optional libraries, we extract the -L and -l switches needed
to link the library from a helper program such as llvm-config.  In
some cases we put the resulting -L switches into LDFLAGS ahead of
-L switches specified via --with-libraries.  That risks breaking
the user's intention for --with-libraries.

It's not such a problem if the library's -L switch points to a
directory containing only that library, but on some platforms a
library helper may "helpfully" offer a switch such as -L/usr/lib
that points to a directory holding all standard libraries.  If the
user specified --with-libraries in hopes of overriding the standard
build of some library, the -L/usr/lib switch prevents that from
happening since it will come before the user-specified directory.

To fix, avoid inserting these switches directly into LDFLAGS during
configure, instead adding them to LIBDIRS or SHLIB_LINK.  They will
still eventually get added to LDFLAGS, but only after the switches
coming from --with-libraries.

The same problem exists for -I switches: those coming from
--with-includes should appear before any coming from helper programs
such as llvm-config.  We have not heard field complaints about this
case, but it seems certain that a user attempting to override a
standard library could have issues.

The changes for this go well beyond configure itself, however,
because many Makefiles have occasion to manipulate CPPFLAGS to
insert locally-desirable -I switches, and some of them got it wrong.
The correct ordering is any -I switches pointing at within-the-
source-tree-or-build-tree directories, then those from the tree-wide
CPPFLAGS, then those from helper programs.  There were several places
that risked pulling in a system-supplied copy of libpq headers, for
example, instead of the in-tree files.  (Commit cb36f8ec2 fixed one
instance of that a few months ago, but this exercise found more.)

The Meson build scripts may or may not have any comparable problems,
but I'll leave it to someone else to investigate that.

Reported-by: Charles Samborski <demurgos@demurgos.net>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/70f2155f-27ca-4534-b33d-7750e20633d7@demurgos.net
Backpatch-through: 13
2025-07-29 15:17:41 -04:00
..
po Translation updates 2025-05-05 12:14:36 +02:00
t Remove option to fall back from direct to postgres SSL negotiation 2024-05-16 17:17:37 +03:00
test meson: Add missing dependencies for libpq tests 2025-02-04 17:56:20 -05:00
.gitignore Run tap tests in src/interfaces/libpq. 2022-02-26 16:51:47 -08:00
exports.txt Improve the granularity of PQsocketPoll's timeout parameter. 2024-06-13 15:14:32 -04:00
fe-auth-sasl.h Refactor SASL exchange to return tri-state status 2024-03-21 14:45:46 +01:00
fe-auth-scram.c Refactor SASL exchange to return tri-state status 2024-03-21 14:45:46 +01:00
fe-auth.c Use PqMsg_* macros in fe-auth.c. 2024-06-26 11:25:38 -05:00
fe-auth.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe-cancel.c Correctly copy the target host identification in PQcancelCreate. 2025-07-02 15:47:59 -04:00
fe-connect.c Fix PQport to never return NULL unless the connection is NULL. 2025-07-17 12:46:58 -04:00
fe-exec.c With GB18030, prevent SIGSEGV from reading past end of allocation. 2025-05-05 04:52:07 -07:00
fe-gssapi-common.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe-gssapi-common.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe-lobj.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe-misc.c Don't reduce output request size on non-Unix-socket connections. 2025-06-10 18:39:34 -04:00
fe-print.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe-protocol3.c Support retrieval of results in chunks with libpq. 2024-04-06 20:45:11 -04:00
fe-secure-common.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe-secure-common.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe-secure-gssapi.c Don't reduce output request size on non-Unix-socket connections. 2025-06-10 18:39:34 -04:00
fe-secure-openssl.c libpq: Use strerror_r instead of strerror 2024-07-28 10:19:57 +02:00
fe-secure.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe-trace.c Rename libpq trace internal functions 2024-05-02 16:11:26 +02:00
legacy-pqsignal.c Avoid symbol collisions between pqsignal.c and legacy-pqsignal.c. 2025-01-14 18:50:24 -05:00
libpq-events.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
libpq-events.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
libpq-fe.h Provide feature-test macros for libpq features added in v17. 2024-08-23 10:12:56 -04:00
libpq-int.h Fix PQport to never return NULL unless the connection is NULL. 2025-07-17 12:46:58 -04:00
Makefile Don't put library-supplied -L/-I switches before user-supplied ones. 2025-07-29 15:17:41 -04:00
meson.build meson: Add missing dependencies for libpq tests 2025-02-04 17:56:20 -05:00
nls.mk Add missing source file to libpq/nls.mk 2024-04-17 09:11:02 +02:00
pg_service.conf.sample Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
pqexpbuffer.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
pqexpbuffer.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pthread-win32.c Clean up Windows-specific mutex code in libpq and ecpglib. 2024-02-09 11:11:39 -05:00
README Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
win32.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
win32.h Recognize network-failure errnos as indicating hard connection loss. 2020-10-10 13:28:12 -04:00

src/interfaces/libpq/README

This directory contains the C version of Libpq, the POSTGRES frontend library.