Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48e14d3

Browse files
committed
Use --as-needed when linking libpython3.so. Closes #11347.
Patch by Arfrever Frehtes Taifersar Arahesis.
1 parent 19f7ca2 commit 48e14d3

4 files changed

Lines changed: 94 additions & 48 deletions

File tree

Makefile.pre.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ PY_CFLAGS= $(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)
7676
# environment variables
7777
PY_CPPFLAGS= -I. -IInclude -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)
7878
PY_LDFLAGS= $(CONFIGURE_LDFLAGS) $(LDFLAGS)
79+
NO_AS_NEEDED= @NO_AS_NEEDED@
7980
LDLAST= @LDLAST@
8081
SGI_ABI= @SGI_ABI@
8182
CCSHARED= @CCSHARED@
@@ -459,7 +460,7 @@ libpython$(LDVERSION).so: $(LIBRARY_OBJS)
459460
fi
460461

461462
libpython3.so: libpython$(LDVERSION).so
462-
$(BLDSHARED) -o $@ -Wl,-hl$@ $^
463+
$(BLDSHARED) $(NO_AS_NEEDED) -o $@ -Wl,-h$@ $^
463464

464465
libpython$(LDVERSION).dylib: $(LIBRARY_OBJS)
465466
$(CC) -dynamiclib -Wl,-single_module $(PY_LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(LDVERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ Library
313313
Build
314314
-----
315315

316+
- Issue #11347: Use --as-needed when linking libpython3.so.
317+
316318
- Issue #11411: Fix 'make DESTDIR=' with a relative destination.
317319

318320
- Issue #11268: Prevent Mac OS X Installer failure if Documentation

configure

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ BUILDEXEEXT
668668
EGREP
669669
GREP
670670
CPP
671+
NO_AS_NEEDED
671672
MAINCC
672673
CXX
673674
OBJEXT
@@ -1572,6 +1573,52 @@ fi
15721573
15731574
} # ac_fn_c_try_compile
15741575
1576+
# ac_fn_c_try_link LINENO
1577+
# -----------------------
1578+
# Try to link conftest.$ac_ext, and return whether this succeeded.
1579+
ac_fn_c_try_link ()
1580+
{
1581+
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
1582+
rm -f conftest.$ac_objext conftest$ac_exeext
1583+
if { { ac_try="$ac_link"
1584+
case "(($ac_try" in
1585+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
1586+
*) ac_try_echo=$ac_try;;
1587+
esac
1588+
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
1589+
$as_echo "$ac_try_echo"; } >&5
1590+
(eval "$ac_link") 2>conftest.err
1591+
ac_status=$?
1592+
if test -s conftest.err; then
1593+
grep -v '^ *+' conftest.err >conftest.er1
1594+
cat conftest.er1 >&5
1595+
mv -f conftest.er1 conftest.err
1596+
fi
1597+
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
1598+
test $ac_status = 0; } && {
1599+
test -z "$ac_c_werror_flag" ||
1600+
test ! -s conftest.err
1601+
} && test -s conftest$ac_exeext && {
1602+
test "$cross_compiling" = yes ||
1603+
$as_test_x conftest$ac_exeext
1604+
}; then :
1605+
ac_retval=0
1606+
else
1607+
$as_echo "$as_me: failed program was:" >&5
1608+
sed 's/^/| /' conftest.$ac_ext >&5
1609+
1610+
ac_retval=1
1611+
fi
1612+
# Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
1613+
# created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
1614+
# interfere with the next link command; also delete a directory that is
1615+
# left behind by Apple's compiler. We do this before executing the actions.
1616+
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
1617+
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
1618+
as_fn_set_status $ac_retval
1619+
1620+
} # ac_fn_c_try_link
1621+
15751622
# ac_fn_c_try_cpp LINENO
15761623
# ----------------------
15771624
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
@@ -1773,52 +1820,6 @@ $as_echo "$ac_res" >&6; }
17731820

17741821
} # ac_fn_c_check_header_compile
17751822

1776-
# ac_fn_c_try_link LINENO
1777-
# -----------------------
1778-
# Try to link conftest.$ac_ext, and return whether this succeeded.
1779-
ac_fn_c_try_link ()
1780-
{
1781-
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
1782-
rm -f conftest.$ac_objext conftest$ac_exeext
1783-
if { { ac_try="$ac_link"
1784-
case "(($ac_try" in
1785-
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
1786-
*) ac_try_echo=$ac_try;;
1787-
esac
1788-
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
1789-
$as_echo "$ac_try_echo"; } >&5
1790-
(eval "$ac_link") 2>conftest.err
1791-
ac_status=$?
1792-
if test -s conftest.err; then
1793-
grep -v '^ *+' conftest.err >conftest.er1
1794-
cat conftest.er1 >&5
1795-
mv -f conftest.er1 conftest.err
1796-
fi
1797-
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
1798-
test $ac_status = 0; } && {
1799-
test -z "$ac_c_werror_flag" ||
1800-
test ! -s conftest.err
1801-
} && test -s conftest$ac_exeext && {
1802-
test "$cross_compiling" = yes ||
1803-
$as_test_x conftest$ac_exeext
1804-
}; then :
1805-
ac_retval=0
1806-
else
1807-
$as_echo "$as_me: failed program was:" >&5
1808-
sed 's/^/| /' conftest.$ac_ext >&5
1809-
1810-
ac_retval=1
1811-
fi
1812-
# Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
1813-
# created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
1814-
# interfere with the next link command; also delete a directory that is
1815-
# left behind by Apple's compiler. We do this before executing the actions.
1816-
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
1817-
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
1818-
as_fn_set_status $ac_retval
1819-
1820-
} # ac_fn_c_try_link
1821-
18221823
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
18231824
# -------------------------------------------
18241825
# Tests whether TYPE exists after having included INCLUDES, setting cache
@@ -4168,8 +4169,38 @@ $as_echo "$as_me: WARNING:
41684169
fi
41694170

41704171

4171-
# checks for UNIX variants that set C preprocessor variables
4172+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -Wl,--no-as-needed" >&5
4173+
$as_echo_n "checking for -Wl,--no-as-needed... " >&6; }
4174+
save_LDFLAGS="$LDFLAGS"
4175+
LDFLAGS="$LDFLAGS -Wl,--no-as-needed"
41724176

4177+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4178+
/* end confdefs.h. */
4179+
4180+
int
4181+
main ()
4182+
{
4183+
4184+
;
4185+
return 0;
4186+
}
4187+
_ACEOF
4188+
if ac_fn_c_try_link "$LINENO"; then :
4189+
NO_AS_NEEDED="-Wl,--no-as-needed"
4190+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
4191+
$as_echo "yes" >&6; }
4192+
else
4193+
NO_AS_NEEDED=""
4194+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
4195+
$as_echo "no" >&6; }
4196+
fi
4197+
rm -f core conftest.err conftest.$ac_objext \
4198+
conftest$ac_exeext conftest.$ac_ext
4199+
LDFLAGS="$save_LDFLAGS"
4200+
4201+
4202+
4203+
# checks for UNIX variants that set C preprocessor variables
41734204
ac_ext=c
41744205
ac_cpp='$CPP $CPPFLAGS'
41754206
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'

configure.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,18 @@ then
525525
fi
526526

527527

528+
AC_MSG_CHECKING([for -Wl,--no-as-needed])
529+
save_LDFLAGS="$LDFLAGS"
530+
LDFLAGS="$LDFLAGS -Wl,--no-as-needed"
531+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
532+
[NO_AS_NEEDED="-Wl,--no-as-needed"
533+
AC_MSG_RESULT([yes])],
534+
[NO_AS_NEEDED=""
535+
AC_MSG_RESULT([no])])
536+
LDFLAGS="$save_LDFLAGS"
537+
AC_SUBST(NO_AS_NEEDED)
538+
539+
528540
# checks for UNIX variants that set C preprocessor variables
529541
AC_USE_SYSTEM_EXTENSIONS
530542

0 commit comments

Comments
 (0)