Skip to content

Commit 54b66a6

Browse files
committed
Merge #19522: build: fix building libconsensus with reduced exports for Darwin targets
de4238f build: consolidate reduced export checks (fanquake) 012bdec build: add building libconsensus to end-of-configure output (fanquake) 8f360e3 build: remove ax_gcc_func_attribute macro (fanquake) f054a08 build: remove AX_GCC_FUNC_ATTRIBUTE test for dllimport (fanquake) 7cd0a69 build: test for __declspec(dllexport) in configure (fanquake) 1624e17 build: remove duplicate visibility attribute detection (fanquake) Pull request description: Darwin targets do not have a `protected` visibility function attribute, see [LLVM explanation](https://github.com/llvm/llvm-project/blob/8e9a505139fbef7d2e6e9d0adfe1efc87326f9ef/clang/lib/Basic/Targets/OSTargets.h#L131). This means that the `AX_GCC_FUNC_ATTRIBUTE` check for `visibility` fails: ```bash configure:24513: checking for __attribute__((visibility)) configure:24537: g++ -std=c++11 -o conftest -g -O2 -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -Wl,-headerpad_max_install_names conftest.cpp >&5 conftest.cpp:35:56: warning: target does not support 'protected' visibility; using 'default' [-Wunsupported-visibility] int foo_pro( void ) __attribute__((visibility("protected"))); ^ 1 warning generated. configure:24537: $? = 0 configure:24550: result: no ``` This leads to `EXPORT_SYMBOL` being [defined to nothing](https://github.com/bitcoin/bitcoin/blob/f4de89edfa8be4501534fec0c662c650a4ce7ef2/src/script/bitcoinconsensus.h#L29), as `HAVE_FUNC_ATTRIBUTE_VISIBILITY` is not defined, and when building with reduced exports, you end up with a libbitcoinconsensus.dylib that doesn't export any `_bitcoinconsensus_*` symbols. ```bash ➜ git:(master) nm -C src/.libs/libbitcoinconsensus.dylib | rg _bitcoinconsensus_ ➜ git:(master) ``` We do have a [second check](https://github.com/bitcoin/bitcoin/blob/f4de89edfa8be4501534fec0c662c650a4ce7ef2/configure.ac#L882) for the `visibility` attribute, which works for Darwin as it's only testing for default visibility, however the result of this check isn't used at all. It was added in #4725, along with the `--enable-reduce-exports` option, however when libbitcoinconsensus was added in #5235, it used the results of the added `AX_GCC_FUNC_ATTRIBUTE` calls. This PR removes our usage of the AX_GCC_FUNC_ATTRIBUTE macro entirely, in favour of our own checks in configure. This meant adding a check for `dllexport`, which I've tested as working with both [GCC](https://gcc.gnu.org/onlinedocs/gcc/Microsoft-Windows-Function-Attributes.html) and [Clang](https://releases.llvm.org/10.0.0/tools/clang/docs/AttributeReference.html#dllexport) when building for Windows. I haven't added an equivalent check for `dllimport`, as we weren't actually using the result of that check, we're just testing that `MSC_VER` was defined before using. With these changes building a libbitcoinconsensus with reduced exports, when targeting Darwin, works as expected: ```bash ./autogen.sh ./configure --disable-tests --disable-bench --with-utils=no --with-daemon=no --with-gui=no --disable-wallet --with-libs=yes --enable-reduce-exports make -j8 ... nm -C src/.libs/libbitcoinconsensus.dylib | rg _bitcoinconsensus_ 000000000000a340 T _bitcoinconsensus_verify_script 00000000000097e0 T _bitcoinconsensus_verify_script_with_amount 000000000000a3c0 T _bitcoinconsensus_version ``` ```python >>> import ctypes >>> consensus = ctypes.CDLL("src/.libs/libbitcoinconsensus.dylib") >>> print(consensus.bitcoinconsensus_version()) 1 >>> exit() ``` TODO: Modify a CI job to compile with --enable-reduce-exports and check for symbols in shared lib? ACKs for top commit: laanwj: Code review ACK de4238f Tree-SHA512: d148f3c55d14dac6e9e5b718cc65bb557bcf6f663218d24bc9044b86281bd5dd3d931ebea79c336a58e8ed50d683218c0a9e75494f2267b91097665043e252ae
2 parents 8d82edd + de4238f commit 54b66a6

File tree

3 files changed

+26
-246
lines changed

3 files changed

+26
-246
lines changed

build-aux/m4/ax_gcc_func_attribute.m4

Lines changed: 0 additions & 223 deletions
This file was deleted.

configure.ac

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,6 @@ if test x$ac_cv_sys_large_files != x &&
813813
CPPFLAGS="$CPPFLAGS -D_LARGE_FILES=$ac_cv_sys_large_files"
814814
fi
815815

816-
AX_GCC_FUNC_ATTRIBUTE([visibility])
817-
AX_GCC_FUNC_ATTRIBUTE([dllexport])
818-
AX_GCC_FUNC_ATTRIBUTE([dllimport])
819-
820816
if test x$use_glibc_compat != xno; then
821817
AX_CHECK_LINK_FLAG([[-Wl,--wrap=__divmoddi4]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=__divmoddi4"])
822818
AX_CHECK_LINK_FLAG([[-Wl,--wrap=log2f]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=log2f"])
@@ -984,13 +980,13 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
984980
[ AC_MSG_RESULT(no)]
985981
)
986982

987-
AC_MSG_CHECKING([for visibility attribute])
988-
AC_LINK_IFELSE([AC_LANG_SOURCE([
989-
int foo_def( void ) __attribute__((visibility("default")));
983+
AC_MSG_CHECKING([for default visibility attribute])
984+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
985+
int foo(void) __attribute__((visibility("default")));
990986
int main(){}
991987
])],
992988
[
993-
AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE,1,[Define if the visibility attribute is supported.])
989+
AC_DEFINE(HAVE_DEFAULT_VISIBILITY_ATTRIBUTE,1,[Define if the visibility attribute is supported.])
994990
AC_MSG_RESULT(yes)
995991
],
996992
[
@@ -1001,6 +997,18 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([
1001997
]
1002998
)
1003999

1000+
AC_MSG_CHECKING([for dllexport attribute])
1001+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1002+
__declspec(dllexport) int foo(void);
1003+
int main(){}
1004+
])],
1005+
[
1006+
AC_DEFINE(HAVE_DLLEXPORT_ATTRIBUTE,1,[Define if the dllexport attribute is supported.])
1007+
AC_MSG_RESULT(yes)
1008+
],
1009+
[AC_MSG_RESULT(no)]
1010+
)
1011+
10041012
dnl thread_local is currently disabled when building with glibc back compat.
10051013
dnl Our minimum supported glibc is 2.17, however support for thread_local
10061014
dnl did not arrive in glibc until 2.18.
@@ -1183,12 +1191,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
11831191
[ AC_MSG_RESULT(no); HAVE_WEAK_GETAUXVAL=0 ]
11841192
)
11851193

1186-
dnl Check for reduced exports
1187-
if test x$use_reduce_exports = xyes; then
1188-
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"],
1189-
[AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])])
1190-
fi
1191-
11921194
AC_MSG_CHECKING([for std::system])
11931195
AC_LINK_IFELSE(
11941196
[ AC_LANG_PROGRAM(
@@ -1402,9 +1404,11 @@ BOOST_CPPFLAGS="-DBOOST_SP_USE_STD_ATOMIC -DBOOST_AC_USE_STD_ATOMIC $BOOST_CPPFL
14021404
BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_THREAD_LIB"
14031405
fi
14041406

1407+
dnl Check for reduced exports
14051408
if test x$use_reduce_exports = xyes; then
1406-
CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS"
1407-
AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"],, [[$LDFLAG_WERROR]])
1409+
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[CXXFLAGS="$CXXFLAGS -fvisibility=hidden"],
1410+
[AC_MSG_ERROR([Cannot set hidden symbol visibility. Use --disable-reduce-exports.])],[[$CXXFLAG_WERROR]])
1411+
AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]],[RELDFLAGS="-Wl,--exclude-libs,ALL"],,[[$LDFLAG_WERROR]])
14081412
fi
14091413

14101414
if test x$use_tests = xyes; then
@@ -1875,6 +1879,7 @@ echo
18751879
echo "Options used to compile and link:"
18761880
echo " boost process = $ax_cv_boost_process"
18771881
echo " multiprocess = $build_multiprocess"
1882+
echo " with libs = $build_bitcoin_libs"
18781883
echo " with wallet = $enable_wallet"
18791884
if test "x$enable_wallet" != "xno"; then
18801885
echo " with sqlite = $use_sqlite"

src/script/bitcoinconsensus.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
#if defined(BUILD_BITCOIN_INTERNAL) && defined(HAVE_CONFIG_H)
1212
#include <config/bitcoin-config.h>
1313
#if defined(_WIN32)
14-
#if defined(DLL_EXPORT)
15-
#if defined(HAVE_FUNC_ATTRIBUTE_DLLEXPORT)
16-
#define EXPORT_SYMBOL __declspec(dllexport)
17-
#else
18-
#define EXPORT_SYMBOL
19-
#endif
14+
#if defined(HAVE_DLLEXPORT_ATTRIBUTE)
15+
#define EXPORT_SYMBOL __declspec(dllexport)
16+
#else
17+
#define EXPORT_SYMBOL
2018
#endif
21-
#elif defined(HAVE_FUNC_ATTRIBUTE_VISIBILITY)
19+
#elif defined(HAVE_DEFAULT_VISIBILITY_ATTRIBUTE)
2220
#define EXPORT_SYMBOL __attribute__ ((visibility ("default")))
2321
#endif
2422
#elif defined(MSC_VER) && !defined(STATIC_LIBBITCOINCONSENSUS)

0 commit comments

Comments
 (0)