mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
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
This commit is contained in:
@ -254,7 +254,7 @@ CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
PG_SYSROOT = @PG_SYSROOT@
|
||||
|
||||
override CPPFLAGS := $(ICU_CFLAGS) $(LIBNUMA_CFLAGS) $(LIBURING_CFLAGS) $(CPPFLAGS)
|
||||
override CPPFLAGS += $(ICU_CFLAGS) $(LIBNUMA_CFLAGS) $(LIBURING_CFLAGS)
|
||||
|
||||
ifdef PGXS
|
||||
override CPPFLAGS := -I$(includedir_server) -I$(includedir_internal) $(CPPFLAGS)
|
||||
|
@ -31,7 +31,7 @@ endif
|
||||
# All files in this directory use LLVM.
|
||||
CFLAGS += $(LLVM_CFLAGS)
|
||||
CXXFLAGS += $(LLVM_CXXFLAGS)
|
||||
override CPPFLAGS := $(LLVM_CPPFLAGS) $(CPPFLAGS)
|
||||
override CPPFLAGS += $(LLVM_CPPFLAGS)
|
||||
SHLIB_LINK += $(LLVM_LIBS)
|
||||
|
||||
# Because this module includes C++ files, we need to use a C++
|
||||
|
@ -20,7 +20,7 @@ include $(top_builddir)/src/Makefile.global
|
||||
# from libpq, else we have risks of version skew if we run with a libpq
|
||||
# shared library from a different PG version. Define
|
||||
# USE_PRIVATE_ENCODING_FUNCS to ensure that that happens.
|
||||
override CPPFLAGS := -DUSE_PRIVATE_ENCODING_FUNCS -I$(libpq_srcdir) -I$(top_srcdir)/src/timezone $(ICU_CFLAGS) $(CPPFLAGS)
|
||||
override CPPFLAGS := -DUSE_PRIVATE_ENCODING_FUNCS -I$(libpq_srcdir) -I$(top_srcdir)/src/timezone $(CPPFLAGS) $(ICU_CFLAGS)
|
||||
|
||||
# We need libpq only because fe_utils does.
|
||||
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport) $(ICU_LIBS)
|
||||
|
@ -163,7 +163,7 @@ libpgcommon_shlib.a: $(OBJS_SHLIB)
|
||||
# The JSON API normally exits on out-of-memory; disable that behavior for shared
|
||||
# library builds. This requires libpq's pqexpbuffer.h.
|
||||
jsonapi_shlib.o: override CPPFLAGS += -DJSONAPI_USE_PQEXPBUFFER
|
||||
jsonapi_shlib.o: override CPPFLAGS += -I$(libpq_srcdir)
|
||||
jsonapi_shlib.o: override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
|
||||
|
||||
# Because this uses its own compilation rule, it doesn't use the
|
||||
# dependency tracking logic from Makefile.global. To make sure that
|
||||
|
@ -24,7 +24,7 @@ NAME = pq-oauth-$(MAJORVERSION)
|
||||
override shlib := lib$(NAME)$(DLSUFFIX)
|
||||
override stlib := libpq-oauth.a
|
||||
|
||||
override CPPFLAGS := -I$(libpq_srcdir) -I$(top_builddir)/src/port $(LIBCURL_CPPFLAGS) $(CPPFLAGS)
|
||||
override CPPFLAGS := -I$(libpq_srcdir) -I$(top_builddir)/src/port $(CPPFLAGS) $(LIBCURL_CPPFLAGS)
|
||||
|
||||
OBJS = \
|
||||
$(WIN32RES)
|
||||
|
@ -24,7 +24,7 @@ NAME= pq
|
||||
SO_MAJOR_VERSION= 5
|
||||
SO_MINOR_VERSION= $(MAJORVERSION)
|
||||
|
||||
override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port
|
||||
override CPPFLAGS := -I$(srcdir) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port $(CPPFLAGS)
|
||||
ifneq ($(PORTNAME), win32)
|
||||
override CFLAGS += $(PTHREAD_CFLAGS)
|
||||
endif
|
||||
|
@ -11,7 +11,7 @@ ifeq ($(PORTNAME), win32)
|
||||
override python_libspec =
|
||||
endif
|
||||
|
||||
override CPPFLAGS := -I. -I$(srcdir) $(python_includespec) $(CPPFLAGS)
|
||||
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) $(python_includespec)
|
||||
|
||||
rpathdir = $(python_libdir)
|
||||
|
||||
|
@ -11,7 +11,7 @@ top_builddir = ../../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
|
||||
|
||||
override CPPFLAGS := -I. -I$(srcdir) $(TCL_INCLUDE_SPEC) $(CPPFLAGS)
|
||||
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) $(TCL_INCLUDE_SPEC)
|
||||
|
||||
# On Windows, we don't link directly with the Tcl library; see below
|
||||
ifneq ($(PORTNAME), win32)
|
||||
|
Reference in New Issue
Block a user