Skip to content

Commit 2dad10f

Browse files
committed
Make another try at using -Wl,--as-needed to suppress linking of unnecessary
shared libraries. We've tried this before and had problems with libreadline not linking properly on some platforms, but that seems to be a libreadline bug that may have been fixed by now. In any case, it's early enough in the 8.4 devel cycle that we can afford to have some transient breakage while we work out any portability problems. On Darwin, we try -Wl,-dead_strip_dylibs, which seems to be the equivalent incantation there.
1 parent 07d08a8 commit 2dad10f

File tree

3 files changed

+138
-2
lines changed

3 files changed

+138
-2
lines changed

config/c-compiler.m4

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Macros to detect C compiler features
2-
# $PostgreSQL: pgsql/config/c-compiler.m4,v 1.16 2008/04/18 18:43:08 alvherre Exp $
2+
# $PostgreSQL: pgsql/config/c-compiler.m4,v 1.17 2008/05/18 20:13:12 tgl Exp $
33

44

55
# PGAC_C_SIGNED
@@ -110,3 +110,19 @@ _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
110110
[CFLAGS="$pgac_save_CFLAGS"
111111
AC_MSG_RESULT(no)])
112112
])# PGAC_PROG_CC_CFLAGS_OPT
113+
114+
115+
116+
# PGAC_PROG_CC_LDFLAGS_OPT
117+
# ------------------------
118+
# Given a string, check if the compiler supports the string as a
119+
# command-line option. If it does, add the string to LDFLAGS.
120+
AC_DEFUN([PGAC_PROG_CC_LDFLAGS_OPT],
121+
[AC_MSG_CHECKING([if $CC supports $1])
122+
pgac_save_LDFLAGS=$LDFLAGS
123+
LDFLAGS="$pgac_save_LDFLAGS $1"
124+
AC_LINK_IFELSE([AC_LANG_PROGRAM()],
125+
AC_MSG_RESULT(yes),
126+
[LDFLAGS="$pgac_save_LDFLAGS"
127+
AC_MSG_RESULT(no)])
128+
])# PGAC_PROG_CC_LDFLAGS_OPT

configure

+110
Original file line numberDiff line numberDiff line change
@@ -4318,6 +4318,116 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
43184318

43194319

43204320

4321+
# If compiler will take -Wl,--as-needed then add that to LDFLAGS.
4322+
# This is much easier than trying to filter LIBS to the minimum for each
4323+
# executable. (Note that shared libraries won't use this switch, though.)
4324+
# On Darwin it's spelled -Wl,-dead_strip_dylibs, but don't try that elsewhere
4325+
if test "$PORTNAME" != "darwin"; then
4326+
{ echo "$as_me:$LINENO: checking if $CC supports -Wl,--as-needed" >&5
4327+
echo $ECHO_N "checking if $CC supports -Wl,--as-needed... $ECHO_C" >&6; }
4328+
pgac_save_LDFLAGS=$LDFLAGS
4329+
LDFLAGS="$pgac_save_LDFLAGS -Wl,--as-needed"
4330+
cat >conftest.$ac_ext <<_ACEOF
4331+
/* confdefs.h. */
4332+
_ACEOF
4333+
cat confdefs.h >>conftest.$ac_ext
4334+
cat >>conftest.$ac_ext <<_ACEOF
4335+
/* end confdefs.h. */
4336+
4337+
int
4338+
main ()
4339+
{
4340+
4341+
;
4342+
return 0;
4343+
}
4344+
_ACEOF
4345+
rm -f conftest.$ac_objext conftest$ac_exeext
4346+
if { (ac_try="$ac_link"
4347+
case "(($ac_try" in
4348+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
4349+
*) ac_try_echo=$ac_try;;
4350+
esac
4351+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
4352+
(eval "$ac_link") 2>conftest.er1
4353+
ac_status=$?
4354+
grep -v '^ *+' conftest.er1 >conftest.err
4355+
rm -f conftest.er1
4356+
cat conftest.err >&5
4357+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
4358+
(exit $ac_status); } && {
4359+
test -z "$ac_c_werror_flag" ||
4360+
test ! -s conftest.err
4361+
} && test -s conftest$ac_exeext &&
4362+
$as_test_x conftest$ac_exeext; then
4363+
{ echo "$as_me:$LINENO: result: yes" >&5
4364+
echo "${ECHO_T}yes" >&6; }
4365+
else
4366+
echo "$as_me: failed program was:" >&5
4367+
sed 's/^/| /' conftest.$ac_ext >&5
4368+
4369+
LDFLAGS="$pgac_save_LDFLAGS"
4370+
{ echo "$as_me:$LINENO: result: no" >&5
4371+
echo "${ECHO_T}no" >&6; }
4372+
fi
4373+
4374+
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
4375+
conftest$ac_exeext conftest.$ac_ext
4376+
4377+
else
4378+
{ echo "$as_me:$LINENO: checking if $CC supports -Wl,-dead_strip_dylibs" >&5
4379+
echo $ECHO_N "checking if $CC supports -Wl,-dead_strip_dylibs... $ECHO_C" >&6; }
4380+
pgac_save_LDFLAGS=$LDFLAGS
4381+
LDFLAGS="$pgac_save_LDFLAGS -Wl,-dead_strip_dylibs"
4382+
cat >conftest.$ac_ext <<_ACEOF
4383+
/* confdefs.h. */
4384+
_ACEOF
4385+
cat confdefs.h >>conftest.$ac_ext
4386+
cat >>conftest.$ac_ext <<_ACEOF
4387+
/* end confdefs.h. */
4388+
4389+
int
4390+
main ()
4391+
{
4392+
4393+
;
4394+
return 0;
4395+
}
4396+
_ACEOF
4397+
rm -f conftest.$ac_objext conftest$ac_exeext
4398+
if { (ac_try="$ac_link"
4399+
case "(($ac_try" in
4400+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
4401+
*) ac_try_echo=$ac_try;;
4402+
esac
4403+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
4404+
(eval "$ac_link") 2>conftest.er1
4405+
ac_status=$?
4406+
grep -v '^ *+' conftest.er1 >conftest.err
4407+
rm -f conftest.er1
4408+
cat conftest.err >&5
4409+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
4410+
(exit $ac_status); } && {
4411+
test -z "$ac_c_werror_flag" ||
4412+
test ! -s conftest.err
4413+
} && test -s conftest$ac_exeext &&
4414+
$as_test_x conftest$ac_exeext; then
4415+
{ echo "$as_me:$LINENO: result: yes" >&5
4416+
echo "${ECHO_T}yes" >&6; }
4417+
else
4418+
echo "$as_me: failed program was:" >&5
4419+
sed 's/^/| /' conftest.$ac_ext >&5
4420+
4421+
LDFLAGS="$pgac_save_LDFLAGS"
4422+
{ echo "$as_me:$LINENO: result: no" >&5
4423+
echo "${ECHO_T}no" >&6; }
4424+
fi
4425+
4426+
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
4427+
conftest$ac_exeext conftest.$ac_ext
4428+
4429+
fi
4430+
43214431
# Create compiler version string
43224432
if test x"$GCC" = x"yes" ; then
43234433
cc_string="GCC `${CC} --version | sed q`"

configure.in

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.560 2008/05/03 00:24:05 adunstan Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.561 2008/05/18 20:13:12 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -450,6 +450,16 @@ fi
450450
AC_PROG_CPP
451451
AC_SUBST(GCC)
452452

453+
# If compiler will take -Wl,--as-needed then add that to LDFLAGS.
454+
# This is much easier than trying to filter LIBS to the minimum for each
455+
# executable. (Note that shared libraries won't use this switch, though.)
456+
# On Darwin it's spelled -Wl,-dead_strip_dylibs, but don't try that elsewhere
457+
if test "$PORTNAME" != "darwin"; then
458+
PGAC_PROG_CC_LDFLAGS_OPT([-Wl,--as-needed])
459+
else
460+
PGAC_PROG_CC_LDFLAGS_OPT([-Wl,-dead_strip_dylibs])
461+
fi
462+
453463
# Create compiler version string
454464
if test x"$GCC" = x"yes" ; then
455465
cc_string="GCC `${CC} --version | sed q`"

0 commit comments

Comments
 (0)