@@ -90,6 +90,12 @@ AC_ARG_ENABLE([hardening],
9090 [ use_hardening=$enableval] ,
9191 [ use_hardening=yes] )
9292
93+ AC_ARG_ENABLE ( [ reduce-exports] ,
94+ [ AS_HELP_STRING ( [ --enable-reduce-exports] ,
95+ [ attempt to reduce exported symbols in the resulting executables (default is yes)] ) ] ,
96+ [ use_reduce_exports=$enableval] ,
97+ [ use_reduce_exports=auto] )
98+
9399AC_ARG_ENABLE ( [ ccache] ,
94100 [ AS_HELP_STRING ( [ --enable-ccache] ,
95101 [ use ccache for building (default is yes if ccache is found)] ) ] ,
@@ -396,6 +402,36 @@ AC_TRY_COMPILE([#include <sys/socket.h>],
396402
397403AC_SEARCH_LIBS ( [ clock_gettime] ,[ rt] )
398404
405+ AC_MSG_CHECKING ( [ for visibility attribute] )
406+ AC_LINK_IFELSE ( [ AC_LANG_SOURCE ( [
407+ int foo_def( void ) __attribute__((visibility("default")));
408+ int main(){}
409+ ] ) ] ,
410+ [
411+ AC_DEFINE ( HAVE_VISIBILITY_ATTRIBUTE ,1 ,[ Define if the visibility attribute is supported.] )
412+ AC_MSG_RESULT ( yes )
413+ ] ,
414+ [
415+ AC_MSG_RESULT ( no )
416+ if test x$use_reduce_exports = xyes; then
417+ AC_MSG_ERROR ( [ Cannot find a working visibility attribute. Use --disable-reduced-exports.] )
418+ fi
419+ AC_MSG_WARN ( [ Cannot find a working visibility attribute. Disabling reduced exports.] )
420+ use_reduce_exports=no
421+ ]
422+ )
423+
424+ if test x$use_reduce_exports != xno; then
425+ AX_CHECK_COMPILE_FLAG ( [ -fvisibility=hidden] ,[ RE_CXXFLAGS="-fvisibility=hidden"] ,
426+ [
427+ if test x$use_reduce_exports = xyes; then
428+ AC_MSG_ERROR ( [ Cannot set default symbol visibility. Use --disable-reduced-exports.] )
429+ fi
430+ AC_MSG_WARN ( [ Cannot set default symbol visibility. Disabling reduced exports.] )
431+ use_reduce_exports=no
432+ ] )
433+ fi
434+
399435LEVELDB_CPPFLAGS=
400436LIBLEVELDB=
401437LIBMEMENV=
@@ -426,6 +462,40 @@ AX_BOOST_PROGRAM_OPTIONS
426462AX_BOOST_THREAD
427463AX_BOOST_CHRONO
428464
465+
466+ if test x$use_reduce_exports != xno; then
467+ AC_MSG_CHECKING ( [ for working boost reduced exports] )
468+ TEMP_CPPFLAGS="$CPPFLAGS"
469+ CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS"
470+ AC_PREPROC_IFELSE ( [ AC_LANG_PROGRAM ( [ [
471+ @%:@ include <boost/version.hpp>
472+ ] ] , [ [
473+ #if BOOST_VERSION >= 104900
474+ // Everything is okay
475+ #else
476+ # error Boost version is too old
477+ #endif
478+ ] ] ) ] ,[
479+ AC_MSG_RESULT ( yes )
480+ ] ,[ :
481+ if test x$use_reduce_exports = xauto; then
482+ use_reduce_exports=no
483+ else
484+ if test x$use_reduce_exports = xyes; then
485+ AC_MSG_ERROR ( [ boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduced-exports.] )
486+ fi
487+ fi
488+ AC_MSG_RESULT ( no )
489+ AC_MSG_WARN ( [ boost versions < 1.49 are known to have symbol visibility issues. Disabling reduced exports.] )
490+ ] )
491+ CPPFLAGS="$TEMP_CPPFLAGS"
492+ fi
493+
494+ if test x$use_reduce_exports != xno; then
495+ CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS"
496+ AX_CHECK_LINK_FLAG ( [ [ -Wl,--exclude-libs,ALL] ] , [ RELDFLAGS="-Wl,--exclude-libs,ALL"] )
497+ fi
498+
429499if test x$use_tests = xyes; then
430500
431501 if test x$HEXDUMP = x; then
@@ -672,6 +742,13 @@ else
672742 AC_MSG_RESULT ( [ no] )
673743fi
674744
745+ AC_MSG_CHECKING ( [ whether to reduce exports] )
746+ if test x$use_reduce_exports != xno; then
747+ AC_MSG_RESULT ( [ yes] )
748+ else
749+ AC_MSG_RESULT ( [ no] )
750+ fi
751+
675752if test x$build_bitcoin_utils$build_bitcoind$bitcoin_enable_qt$use_tests = xnononono; then
676753 AC_MSG_ERROR ( [ No targets! Please specify at least one of: --with-utils --with-daemon --with-gui or --enable-tests] )
677754fi
@@ -704,6 +781,7 @@ AC_SUBST(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE)
704781AC_SUBST ( COPYRIGHT_YEAR , _COPYRIGHT_YEAR )
705782
706783
784+ AC_SUBST ( RELDFLAGS )
707785AC_SUBST ( LIBTOOL_LDFLAGS )
708786AC_SUBST ( USE_UPNP )
709787AC_SUBST ( USE_QRCODE )
0 commit comments