Skip to content

Commit 1985743

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 0928e18 commit 1985743

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
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
@@ -5173,7 +5173,7 @@ fi
51735173

51745174
for pgac_option in `$LLVM_CONFIG --ldflags`; do
51755175
case $pgac_option in
5176-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
5176+
-L*) LLVM_LIBS="$LLVM_LIBS $pgac_option";;
51775177
esac
51785178
done
51795179

@@ -9218,12 +9218,12 @@ fi
92189218
# Note the user could also set XML2_CFLAGS/XML2_LIBS directly
92199219
for pgac_option in $XML2_CFLAGS; do
92209220
case $pgac_option in
9221-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
9221+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
92229222
esac
92239223
done
92249224
for pgac_option in $XML2_LIBS; do
92259225
case $pgac_option in
9226-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
9226+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
92279227
esac
92289228
done
92299229
fi
@@ -9448,12 +9448,12 @@ fi
94489448
# note that -llz4 will be added by AC_CHECK_LIB below.
94499449
for pgac_option in $LZ4_CFLAGS; do
94509450
case $pgac_option in
9451-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
9451+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
94529452
esac
94539453
done
94549454
for pgac_option in $LZ4_LIBS; do
94559455
case $pgac_option in
9456-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
9456+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
94579457
esac
94589458
done
94599459
fi
@@ -9589,12 +9589,12 @@ fi
95899589
# note that -lzstd will be added by AC_CHECK_LIB below.
95909590
for pgac_option in $ZSTD_CFLAGS; do
95919591
case $pgac_option in
9592-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
9592+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
95939593
esac
95949594
done
95959595
for pgac_option in $ZSTD_LIBS; do
95969596
case $pgac_option in
9597-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
9597+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
95989598
esac
95999599
done
96009600
fi
@@ -17654,7 +17654,7 @@ _ACEOF
1765417654

1765517655
if test "$with_icu" = yes; then
1765617656
ac_save_CPPFLAGS=$CPPFLAGS
17657-
CPPFLAGS="$ICU_CFLAGS $CPPFLAGS"
17657+
CPPFLAGS="$CPPFLAGS $ICU_CFLAGS"
1765817658

1765917659
# Verify we have ICU's header files
1766017660
ac_fn_c_check_header_mongrel "$LINENO" "unicode/ucol.h" "ac_cv_header_unicode_ucol_h" "$ac_includes_default"
@@ -19807,7 +19807,7 @@ Use --without-tcl to disable building PL/Tcl." "$LINENO" 5
1980719807
fi
1980819808
# now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
1980919809
ac_save_CPPFLAGS=$CPPFLAGS
19810-
CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
19810+
CPPFLAGS="$CPPFLAGS $TCL_INCLUDE_SPEC"
1981119811
ac_fn_c_check_header_mongrel "$LINENO" "tcl.h" "ac_cv_header_tcl_h" "$ac_includes_default"
1981219812
if test "x$ac_cv_header_tcl_h" = xyes; then :
1981319813

@@ -19876,7 +19876,7 @@ fi
1987619876
# check for <Python.h>
1987719877
if test "$with_python" = yes; then
1987819878
ac_save_CPPFLAGS=$CPPFLAGS
19879-
CPPFLAGS="$python_includespec $CPPFLAGS"
19879+
CPPFLAGS="$CPPFLAGS $python_includespec"
1988019880
ac_fn_c_check_header_mongrel "$LINENO" "Python.h" "ac_cv_header_Python_h" "$ac_includes_default"
1988119881
if test "x$ac_cv_header_Python_h" = xyes; then :
1988219882

configure.ac

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,12 +1052,12 @@ if test "$with_libxml" = yes ; then
10521052
# Note the user could also set XML2_CFLAGS/XML2_LIBS directly
10531053
for pgac_option in $XML2_CFLAGS; do
10541054
case $pgac_option in
1055-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
1055+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
10561056
esac
10571057
done
10581058
for pgac_option in $XML2_LIBS; do
10591059
case $pgac_option in
1060-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
1060+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
10611061
esac
10621062
done
10631063
fi
@@ -1101,12 +1101,12 @@ if test "$with_lz4" = yes; then
11011101
# note that -llz4 will be added by AC_CHECK_LIB below.
11021102
for pgac_option in $LZ4_CFLAGS; do
11031103
case $pgac_option in
1104-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
1104+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
11051105
esac
11061106
done
11071107
for pgac_option in $LZ4_LIBS; do
11081108
case $pgac_option in
1109-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
1109+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
11101110
esac
11111111
done
11121112
fi
@@ -1126,12 +1126,12 @@ if test "$with_zstd" = yes; then
11261126
# note that -lzstd will be added by AC_CHECK_LIB below.
11271127
for pgac_option in $ZSTD_CFLAGS; do
11281128
case $pgac_option in
1129-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
1129+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
11301130
esac
11311131
done
11321132
for pgac_option in $ZSTD_LIBS; do
11331133
case $pgac_option in
1134-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
1134+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
11351135
esac
11361136
done
11371137
fi
@@ -2089,7 +2089,7 @@ AC_CHECK_DECLS([strtoll, strtoull])
20892089

20902090
if test "$with_icu" = yes; then
20912091
ac_save_CPPFLAGS=$CPPFLAGS
2092-
CPPFLAGS="$ICU_CFLAGS $CPPFLAGS"
2092+
CPPFLAGS="$CPPFLAGS $ICU_CFLAGS"
20932093

20942094
# Verify we have ICU's header files
20952095
AC_CHECK_HEADER(unicode/ucol.h, [],
@@ -2439,7 +2439,7 @@ Use --without-tcl to disable building PL/Tcl.])
24392439
fi
24402440
# now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
24412441
ac_save_CPPFLAGS=$CPPFLAGS
2442-
CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
2442+
CPPFLAGS="$CPPFLAGS $TCL_INCLUDE_SPEC"
24432443
AC_CHECK_HEADER(tcl.h, [], [AC_MSG_ERROR([header file <tcl.h> is required for Tcl])])
24442444
CPPFLAGS=$ac_save_CPPFLAGS
24452445
fi
@@ -2476,7 +2476,7 @@ fi
24762476
# check for <Python.h>
24772477
if test "$with_python" = yes; then
24782478
ac_save_CPPFLAGS=$CPPFLAGS
2479-
CPPFLAGS="$python_includespec $CPPFLAGS"
2479+
CPPFLAGS="$CPPFLAGS $python_includespec"
24802480
AC_CHECK_HEADER(Python.h, [], [AC_MSG_ERROR([header file <Python.h> is required for Python])])
24812481
CPPFLAGS=$ac_save_CPPFLAGS
24822482
fi

src/Makefile.global.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ CPP = @CPP@
242242
CPPFLAGS = @CPPFLAGS@
243243
PG_SYSROOT = @PG_SYSROOT@
244244

245-
override CPPFLAGS := $(ICU_CFLAGS) $(CPPFLAGS)
245+
override CPPFLAGS += $(ICU_CFLAGS)
246246

247247
ifdef PGXS
248248
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/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 := -DFRONTEND -DUNSAFE_STAT_OK -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port
25+
override CPPFLAGS := -DFRONTEND -DUNSAFE_STAT_OK -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