Skip to content

Commit a644f5f

Browse files
committed
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 cb36f8e 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
1 parent 7571e0f commit a644f5f

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

config/llvm.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# -----------------
55
#
66
# Look for the LLVM installation, check that it's new enough, set the
7-
# corresponding LLVM_{CFLAGS,CXXFLAGS,BINPATH} and LDFLAGS
7+
# corresponding LLVM_{CFLAGS,CXXFLAGS,BINPATH,LIBS}
88
# variables. Also verify that CLANG is available, to transform C
99
# into bitcode.
1010
#
@@ -55,7 +55,7 @@ AC_DEFUN([PGAC_LLVM_SUPPORT],
5555
5656
for pgac_option in `$LLVM_CONFIG --ldflags`; do
5757
case $pgac_option in
58-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
58+
-L*) LLVM_LIBS="$LLVM_LIBS $pgac_option";;
5959
esac
6060
done
6161

configure

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5213,7 +5213,7 @@ fi
52135213

52145214
for pgac_option in `$LLVM_CONFIG --ldflags`; do
52155215
case $pgac_option in
5216-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
5216+
-L*) LLVM_LIBS="$LLVM_LIBS $pgac_option";;
52175217
esac
52185218
done
52195219

@@ -9020,12 +9020,12 @@ fi
90209020
# Note the user could also set XML2_CFLAGS/XML2_LIBS directly
90219021
for pgac_option in $XML2_CFLAGS; do
90229022
case $pgac_option in
9023-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
9023+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
90249024
esac
90259025
done
90269026
for pgac_option in $XML2_LIBS; do
90279027
case $pgac_option in
9028-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
9028+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
90299029
esac
90309030
done
90319031
fi
@@ -9250,12 +9250,12 @@ fi
92509250
# note that -llz4 will be added by AC_CHECK_LIB below.
92519251
for pgac_option in $LZ4_CFLAGS; do
92529252
case $pgac_option in
9253-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
9253+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
92549254
esac
92559255
done
92569256
for pgac_option in $LZ4_LIBS; do
92579257
case $pgac_option in
9258-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
9258+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
92599259
esac
92609260
done
92619261
fi
@@ -9391,12 +9391,12 @@ fi
93919391
# note that -lzstd will be added by AC_CHECK_LIB below.
93929392
for pgac_option in $ZSTD_CFLAGS; do
93939393
case $pgac_option in
9394-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
9394+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
93959395
esac
93969396
done
93979397
for pgac_option in $ZSTD_LIBS; do
93989398
case $pgac_option in
9399-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
9399+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
94009400
esac
94019401
done
94029402
fi
@@ -16256,7 +16256,7 @@ fi
1625616256

1625716257
if test "$with_icu" = yes; then
1625816258
ac_save_CPPFLAGS=$CPPFLAGS
16259-
CPPFLAGS="$ICU_CFLAGS $CPPFLAGS"
16259+
CPPFLAGS="$CPPFLAGS $ICU_CFLAGS"
1626016260

1626116261
# Verify we have ICU's header files
1626216262
ac_fn_c_check_header_mongrel "$LINENO" "unicode/ucol.h" "ac_cv_header_unicode_ucol_h" "$ac_includes_default"
@@ -18693,7 +18693,7 @@ Use --without-tcl to disable building PL/Tcl." "$LINENO" 5
1869318693
fi
1869418694
# now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
1869518695
ac_save_CPPFLAGS=$CPPFLAGS
18696-
CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
18696+
CPPFLAGS="$CPPFLAGS $TCL_INCLUDE_SPEC"
1869718697
ac_fn_c_check_header_mongrel "$LINENO" "tcl.h" "ac_cv_header_tcl_h" "$ac_includes_default"
1869818698
if test "x$ac_cv_header_tcl_h" = xyes; then :
1869918699

@@ -18762,7 +18762,7 @@ fi
1876218762
# check for <Python.h>
1876318763
if test "$with_python" = yes; then
1876418764
ac_save_CPPFLAGS=$CPPFLAGS
18765-
CPPFLAGS="$python_includespec $CPPFLAGS"
18765+
CPPFLAGS="$CPPFLAGS $python_includespec"
1876618766
ac_fn_c_check_header_mongrel "$LINENO" "Python.h" "ac_cv_header_Python_h" "$ac_includes_default"
1876718767
if test "x$ac_cv_header_Python_h" = xyes; then :
1876818768

configure.ac

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,12 @@ if test "$with_libxml" = yes ; then
10441044
# Note the user could also set XML2_CFLAGS/XML2_LIBS directly
10451045
for pgac_option in $XML2_CFLAGS; do
10461046
case $pgac_option in
1047-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
1047+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
10481048
esac
10491049
done
10501050
for pgac_option in $XML2_LIBS; do
10511051
case $pgac_option in
1052-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
1052+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
10531053
esac
10541054
done
10551055
fi
@@ -1093,12 +1093,12 @@ if test "$with_lz4" = yes; then
10931093
# note that -llz4 will be added by AC_CHECK_LIB below.
10941094
for pgac_option in $LZ4_CFLAGS; do
10951095
case $pgac_option in
1096-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
1096+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
10971097
esac
10981098
done
10991099
for pgac_option in $LZ4_LIBS; do
11001100
case $pgac_option in
1101-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
1101+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
11021102
esac
11031103
done
11041104
fi
@@ -1118,12 +1118,12 @@ if test "$with_zstd" = yes; then
11181118
# note that -lzstd will be added by AC_CHECK_LIB below.
11191119
for pgac_option in $ZSTD_CFLAGS; do
11201120
case $pgac_option in
1121-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
1121+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
11221122
esac
11231123
done
11241124
for pgac_option in $ZSTD_LIBS; do
11251125
case $pgac_option in
1126-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
1126+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
11271127
esac
11281128
done
11291129
fi
@@ -1901,7 +1901,7 @@ fi
19011901

19021902
if test "$with_icu" = yes; then
19031903
ac_save_CPPFLAGS=$CPPFLAGS
1904-
CPPFLAGS="$ICU_CFLAGS $CPPFLAGS"
1904+
CPPFLAGS="$CPPFLAGS $ICU_CFLAGS"
19051905

19061906
# Verify we have ICU's header files
19071907
AC_CHECK_HEADER(unicode/ucol.h, [],
@@ -2331,7 +2331,7 @@ Use --without-tcl to disable building PL/Tcl.])
23312331
fi
23322332
# now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
23332333
ac_save_CPPFLAGS=$CPPFLAGS
2334-
CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
2334+
CPPFLAGS="$CPPFLAGS $TCL_INCLUDE_SPEC"
23352335
AC_CHECK_HEADER(tcl.h, [], [AC_MSG_ERROR([header file <tcl.h> is required for Tcl])])
23362336
CPPFLAGS=$ac_save_CPPFLAGS
23372337
fi
@@ -2368,7 +2368,7 @@ fi
23682368
# check for <Python.h>
23692369
if test "$with_python" = yes; then
23702370
ac_save_CPPFLAGS=$CPPFLAGS
2371-
CPPFLAGS="$python_includespec $CPPFLAGS"
2371+
CPPFLAGS="$CPPFLAGS $python_includespec"
23722372
AC_CHECK_HEADER(Python.h, [], [AC_MSG_ERROR([header file <Python.h> is required for Python])])
23732373
CPPFLAGS=$ac_save_CPPFLAGS
23742374
fi

src/Makefile.global.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ CPP = @CPP@
240240
CPPFLAGS = @CPPFLAGS@
241241
PG_SYSROOT = @PG_SYSROOT@
242242

243-
override CPPFLAGS := $(ICU_CFLAGS) $(CPPFLAGS)
243+
override CPPFLAGS += $(ICU_CFLAGS)
244244

245245
ifdef PGXS
246246
override CPPFLAGS := -I$(includedir_server) -I$(includedir_internal) $(CPPFLAGS)

src/backend/jit/llvm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ endif
3131
# All files in this directory use LLVM.
3232
CFLAGS += $(LLVM_CFLAGS)
3333
CXXFLAGS += $(LLVM_CXXFLAGS)
34-
override CPPFLAGS := $(LLVM_CPPFLAGS) $(CPPFLAGS)
34+
override CPPFLAGS += $(LLVM_CPPFLAGS)
3535
SHLIB_LINK += $(LLVM_LIBS)
3636

3737
# Because this module includes C++ files, we need to use a C++

src/bin/initdb/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include $(top_builddir)/src/Makefile.global
2020
# from libpq, else we have risks of version skew if we run with a libpq
2121
# shared library from a different PG version. Define
2222
# USE_PRIVATE_ENCODING_FUNCS to ensure that that happens.
23-
override CPPFLAGS := -DUSE_PRIVATE_ENCODING_FUNCS -I$(libpq_srcdir) -I$(top_srcdir)/src/timezone $(ICU_CFLAGS) $(CPPFLAGS)
23+
override CPPFLAGS := -DUSE_PRIVATE_ENCODING_FUNCS -I$(libpq_srcdir) -I$(top_srcdir)/src/timezone $(CPPFLAGS) $(ICU_CFLAGS)
2424

2525
# We need libpq only because fe_utils does.
2626
LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport) $(ICU_LIBS)

src/interfaces/libpq/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ NAME= pq
2222
SO_MAJOR_VERSION= 5
2323
SO_MINOR_VERSION= $(MAJORVERSION)
2424

25-
override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port
25+
override CPPFLAGS := -I$(srcdir) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port $(CPPFLAGS)
2626
ifneq ($(PORTNAME), win32)
2727
override CFLAGS += $(PTHREAD_CFLAGS)
2828
endif

src/pl/plpython/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ifeq ($(PORTNAME), win32)
1111
override python_libspec =
1212
endif
1313

14-
override CPPFLAGS := -I. -I$(srcdir) $(python_includespec) $(CPPFLAGS)
14+
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) $(python_includespec)
1515

1616
rpathdir = $(python_libdir)
1717

src/pl/tcl/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ top_builddir = ../../..
1111
include $(top_builddir)/src/Makefile.global
1212

1313

14-
override CPPFLAGS := -I. -I$(srcdir) $(TCL_INCLUDE_SPEC) $(CPPFLAGS)
14+
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) $(TCL_INCLUDE_SPEC)
1515

1616
# On Windows, we don't link directly with the Tcl library; see below
1717
ifneq ($(PORTNAME), win32)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy