Skip to content

Commit 4975ae1

Browse files
committed
build: add option for reducing exports
Enabled automatically if boost >= 1.49. See: https://svn.boost.org/trac/boost/ticket/2309 Also, check for a default visibility attribute, so that we can mark future api functions correctly.
1 parent 984ff68 commit 4975ae1

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

configure.ac

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
9399
AC_ARG_ENABLE([ccache],
94100
[AS_HELP_STRING([--enable-ccache],
95101
[use ccache for building (default is yes if ccache is found)])],
@@ -396,6 +402,40 @@ AC_TRY_COMPILE([#include <sys/socket.h>],
396402

397403
AC_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+
if test x$use_reduce_exports != xno; then
434+
AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"])
435+
CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS"
436+
fi
437+
fi
438+
399439
LEVELDB_CPPFLAGS=
400440
LIBLEVELDB=
401441
LIBMEMENV=
@@ -420,6 +460,35 @@ fi
420460

421461
dnl Check for boost libs
422462
AX_BOOST_BASE
463+
464+
if test x$use_reduce_exports != xno; then
465+
AC_MSG_CHECKING([for working boost reduced exports])
466+
TEMP_CPPFLAGS="$CPPFLAGS"
467+
CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS"
468+
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
469+
@%:@include <boost/version.hpp>
470+
]], [[
471+
#if BOOST_VERSION >= 104900
472+
// Everything is okay
473+
#else
474+
# error Boost version is too old
475+
#endif
476+
]])],[
477+
AC_MSG_RESULT(yes)
478+
],[:
479+
if test x$use_reduce_exports = xauto; then
480+
use_reduce_exports=no
481+
else
482+
if test x$use_reduce_exports = xyes; then
483+
AC_MSG_ERROR([boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduced-exports.])
484+
fi
485+
fi
486+
AC_MSG_RESULT(no)
487+
AC_MSG_WARN([boost versions < 1.49 are known to have symbol visibility issues. Disabling reduced exports.])
488+
])
489+
CPPFLAGS="$TEMP_CPPFLAGS"
490+
fi
491+
423492
AX_BOOST_SYSTEM
424493
AX_BOOST_FILESYSTEM
425494
AX_BOOST_PROGRAM_OPTIONS
@@ -672,6 +741,13 @@ else
672741
AC_MSG_RESULT([no])
673742
fi
674743

744+
AC_MSG_CHECKING([whether to reduce exports])
745+
if test x$use_reduce_exports != xno; then
746+
AC_MSG_RESULT([yes])
747+
else
748+
AC_MSG_RESULT([no])
749+
fi
750+
675751
if test "x$use_tests$build_bitcoind$use_qt" = "xnonono"; then
676752
AC_MSG_ERROR([No targets! Please specify at least one of: --enable-cli --enable-daemon --enable-gui or --enable-tests])
677753
fi
@@ -704,6 +780,7 @@ AC_SUBST(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE)
704780
AC_SUBST(COPYRIGHT_YEAR, _COPYRIGHT_YEAR)
705781

706782

783+
AC_SUBST(RELDFLAGS)
707784
AC_SUBST(LIBTOOL_LDFLAGS)
708785
AC_SUBST(USE_UPNP)
709786
AC_SUBST(USE_QRCODE)

src/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ endif
262262

263263
bitcoind_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS)
264264
bitcoind_CPPFLAGS = $(BITCOIN_INCLUDES)
265+
bitcoind_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS)
265266

266267
# bitcoin-cli binary #
267268
bitcoin_cli_LDADD = \
@@ -299,10 +300,12 @@ endif
299300
bitcoin_tx_SOURCES = bitcoin-tx.cpp
300301
bitcoin_tx_CPPFLAGS = $(BITCOIN_INCLUDES)
301302
#
303+
bitcoin_tx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS)
302304

303305
if TARGET_WINDOWS
304306
bitcoin_cli_SOURCES += bitcoin-cli-res.rc
305307
endif
308+
bitcoin_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS)
306309

307310
CLEANFILES = leveldb/libleveldb.a leveldb/libmemenv.a *.gcda *.gcno
308311

src/Makefile.qt.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL)
362362
if USE_LIBSECP256K1
363363
qt_bitcoin_qt_LDADD += secp256k1/libsecp256k1.la
364364
endif
365-
qt_bitcoin_qt_LDFLAGS = $(AM_LDFLAGS) $(QT_LDFLAGS)
365+
qt_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS)
366366

367367
#locale/foo.ts -> locale/foo.qm
368368
QT_QM=$(QT_TS:.ts=.qm)

src/Makefile.qttest.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBIT
3636
if USE_LIBSECP256K1
3737
qt_test_test_bitcoin_qt_LDADD += secp256k1/libsecp256k1.la
3838
endif
39-
qt_test_test_bitcoin_qt_LDFLAGS = $(AM_LDFLAGS) $(QT_LDFLAGS)
39+
qt_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS)
4040

4141
CLEAN_BITCOIN_QT_TEST = $(TEST_QT_MOC_CPP) qt/test/*.gcda qt/test/*.gcno
4242

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ if USE_LIBSECP256K1
7575
endif
7676

7777
test_test_bitcoin_LDADD += $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS)
78+
test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS)
7879

7980
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
8081

0 commit comments

Comments
 (0)