Skip to content

Commit 2dee95b

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 cdcdabc commit 2dee95b

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,7 +5158,7 @@ fi
51585158

51595159
for pgac_option in `$LLVM_CONFIG --ldflags`; do
51605160
case $pgac_option in
5161-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
5161+
-L*) LLVM_LIBS="$LLVM_LIBS $pgac_option";;
51625162
esac
51635163
done
51645164

@@ -9191,12 +9191,12 @@ fi
91919191
# Note the user could also set XML2_CFLAGS/XML2_LIBS directly
91929192
for pgac_option in $XML2_CFLAGS; do
91939193
case $pgac_option in
9194-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
9194+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
91959195
esac
91969196
done
91979197
for pgac_option in $XML2_LIBS; do
91989198
case $pgac_option in
9199-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
9199+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
92009200
esac
92019201
done
92029202
fi
@@ -9421,12 +9421,12 @@ fi
94219421
# note that -llz4 will be added by AC_CHECK_LIB below.
94229422
for pgac_option in $LZ4_CFLAGS; do
94239423
case $pgac_option in
9424-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
9424+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
94259425
esac
94269426
done
94279427
for pgac_option in $LZ4_LIBS; do
94289428
case $pgac_option in
9429-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
9429+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
94309430
esac
94319431
done
94329432
fi
@@ -17349,7 +17349,7 @@ _ACEOF
1734917349

1735017350
if test "$with_icu" = yes; then
1735117351
ac_save_CPPFLAGS=$CPPFLAGS
17352-
CPPFLAGS="$ICU_CFLAGS $CPPFLAGS"
17352+
CPPFLAGS="$CPPFLAGS $ICU_CFLAGS"
1735317353

1735417354
# Verify we have ICU's header files
1735517355
ac_fn_c_check_header_mongrel "$LINENO" "unicode/ucol.h" "ac_cv_header_unicode_ucol_h" "$ac_includes_default"
@@ -19553,7 +19553,7 @@ Use --without-tcl to disable building PL/Tcl." "$LINENO" 5
1955319553
fi
1955419554
# now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
1955519555
ac_save_CPPFLAGS=$CPPFLAGS
19556-
CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
19556+
CPPFLAGS="$CPPFLAGS $TCL_INCLUDE_SPEC"
1955719557
ac_fn_c_check_header_mongrel "$LINENO" "tcl.h" "ac_cv_header_tcl_h" "$ac_includes_default"
1955819558
if test "x$ac_cv_header_tcl_h" = xyes; then :
1955919559

@@ -19622,7 +19622,7 @@ fi
1962219622
# check for <Python.h>
1962319623
if test "$with_python" = yes; then
1962419624
ac_save_CPPFLAGS=$CPPFLAGS
19625-
CPPFLAGS="$python_includespec $CPPFLAGS"
19625+
CPPFLAGS="$CPPFLAGS $python_includespec"
1962619626
ac_fn_c_check_header_mongrel "$LINENO" "Python.h" "ac_cv_header_Python_h" "$ac_includes_default"
1962719627
if test "x$ac_cv_header_Python_h" = xyes; then :
1962819628

configure.ac

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,12 +1039,12 @@ if test "$with_libxml" = yes ; then
10391039
# Note the user could also set XML2_CFLAGS/XML2_LIBS directly
10401040
for pgac_option in $XML2_CFLAGS; do
10411041
case $pgac_option in
1042-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
1042+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
10431043
esac
10441044
done
10451045
for pgac_option in $XML2_LIBS; do
10461046
case $pgac_option in
1047-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
1047+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
10481048
esac
10491049
done
10501050
fi
@@ -1088,12 +1088,12 @@ if test "$with_lz4" = yes; then
10881088
# note that -llz4 will be added by AC_CHECK_LIB below.
10891089
for pgac_option in $LZ4_CFLAGS; do
10901090
case $pgac_option in
1091-
-I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";;
1091+
-I*|-D*) INCLUDES="$INCLUDES $pgac_option";;
10921092
esac
10931093
done
10941094
for pgac_option in $LZ4_LIBS; do
10951095
case $pgac_option in
1096-
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
1096+
-L*) LIBDIRS="$LIBDIRS $pgac_option";;
10971097
esac
10981098
done
10991099
fi
@@ -2016,7 +2016,7 @@ AC_CHECK_DECLS([strtoll, strtoull])
20162016

20172017
if test "$with_icu" = yes; then
20182018
ac_save_CPPFLAGS=$CPPFLAGS
2019-
CPPFLAGS="$ICU_CFLAGS $CPPFLAGS"
2019+
CPPFLAGS="$CPPFLAGS $ICU_CFLAGS"
20202020

20212021
# Verify we have ICU's header files
20222022
AC_CHECK_HEADER(unicode/ucol.h, [],
@@ -2360,7 +2360,7 @@ Use --without-tcl to disable building PL/Tcl.])
23602360
fi
23612361
# now that we have TCL_INCLUDE_SPEC, we can check for <tcl.h>
23622362
ac_save_CPPFLAGS=$CPPFLAGS
2363-
CPPFLAGS="$TCL_INCLUDE_SPEC $CPPFLAGS"
2363+
CPPFLAGS="$CPPFLAGS $TCL_INCLUDE_SPEC"
23642364
AC_CHECK_HEADER(tcl.h, [], [AC_MSG_ERROR([header file <tcl.h> is required for Tcl])])
23652365
CPPFLAGS=$ac_save_CPPFLAGS
23662366
fi
@@ -2397,7 +2397,7 @@ fi
23972397
# check for <Python.h>
23982398
if test "$with_python" = yes; then
23992399
ac_save_CPPFLAGS=$CPPFLAGS
2400-
CPPFLAGS="$python_includespec $CPPFLAGS"
2400+
CPPFLAGS="$CPPFLAGS $python_includespec"
24012401
AC_CHECK_HEADER(Python.h, [], [AC_MSG_ERROR([header file <Python.h> is required for Python])])
24022402
CPPFLAGS=$ac_save_CPPFLAGS
24032403
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
@@ -21,7 +21,7 @@ NAME= pq
2121
SO_MAJOR_VERSION= 5
2222
SO_MINOR_VERSION= $(MAJORVERSION)
2323

24-
override CPPFLAGS := -DFRONTEND -DUNSAFE_STAT_OK -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port
24+
override CPPFLAGS := -DFRONTEND -DUNSAFE_STAT_OK -I$(srcdir) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port $(CPPFLAGS)
2525
ifneq ($(PORTNAME), win32)
2626
override CFLAGS += $(PTHREAD_CFLAGS)
2727
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