-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmake: Build libbitcoinconsensus
library
#41
Conversation
Examples of usage:
|
Nice. Couple of things that bugged me (not related to this patchset, I think) when doing a quick test:
|
What are your system, compiler etc?
Could you try the Ninja generator by adding UPD. I think that following the target dependency graph is an inherent behaviour. |
6cb330c
to
05b9bb4
Compare
Debian, gcc 13.2. Reproducer for me is:
That sucks :( The util/cli/wallet/tx tools seem to be build in parallel, at least. Did confirm that ninja didn't make much difference. |
CMakeLists.txt
Outdated
@@ -255,6 +256,11 @@ if(HARDENING) | |||
try_append_cxx_flags("-fcf-protection=full" TARGET hardening) | |||
|
|||
if(MINGW) | |||
add_library(link_ssp INTERFACE) | |||
target_link_libraries(link_ssp INTERFACE | |||
$<$<BOOL:${BUILD_SHARED_LIBS}>:ssp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on why this is needed (if it still is: bitcoin#28461). I'm suprised this is being added at this point, rather than in the hardening PR, where we actually started using ssp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only DLL failed to build without linking to libssp
when hardening, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested. Did it? If it doesn't fail on master with the changes in bitcoin#28461, it'd also be good to know why it fails here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd also be good to know why it fails here.
Indeed. FWIW, I have objdump
outputs as follow:
objdump -x src/.libs/libbitcoinconsensus-0.dll | grep -e "DLL Name:"
DLL Name: ADVAPI32.dll
DLL Name: KERNEL32.dll
DLL Name: msvcrt.dll
- this branch:
$ objdump -x build/src/script/libbitcoinconsensus.dll | grep -e "DLL Name:"
DLL Name: ADVAPI32.dll
DLL Name: KERNEL32.dll
DLL Name: msvcrt.dll
There are no traces of libssp
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect lssp to be needed everywhere other than bleeding-edge build environments. Is it possible that bitcoind.exe
without lssp links but fails to run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect lssp to be needed everywhere...
FWIW, it was introduced with the commit message:
mingw needs libssp for hardening with dlls
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested. Did it? If it doesn't fail on master with the changes in bitcoin#28461, it'd also be good to know why it fails here.
Resolved in the recent push.
src/script/CMakeLists.txt
Outdated
|
||
function(make_bitcoinconsensus_dll_available target) | ||
if(WIN32 AND BUILD_SHARED_LIBS) | ||
# The DLL must reside either in the same folder where the executable is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DLL must reside either in the same folder where the executable is
or somewhere in PATH. Using the former option.
Why? Is this some CMake behaviour? Would be good to be more clear in this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a Windows-specific behavior:
... the Windows operating system searches for ... DLL in the following locations in this order:
The application folder
The current folder
The Windows system folder
The Windows folder
@@ -320,6 +330,15 @@ message(" bitcoin-cli ......................... ${BUILD_CLI}") | |||
message(" bitcoin-tx .......................... ${BUILD_TX}") | |||
message(" bitcoin-util ........................ ${BUILD_UTIL}") | |||
message(" bitcoin-wallet ...................... ${BUILD_WALLET_TOOL}") | |||
message("Libraries:") | |||
if(BUILD_SHARED_LIBS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be collapsed down to just:
if(BUILD_SHARED_LIBS)
message(" library type ........................ Shared")
else()
message(" library type ........................ Static")
endif()
Then there's no need for an intermediate variable, and "cleaning up" afterwards? We know there's only two types of libs we are building.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implies that when BUILD_SHARED_LIBS=1
then no static libraries will be built. Is this the case? And no plan to build both in the future? I think it is normal to provide both static and shared libraries, for example:
/usr/local/lib/libx264.a
/usr/local/lib/libx264.so
/usr/local/lib/libx264.so.164
...
/usr/local/lib/libidn.a
/usr/local/lib/libidn.so
/usr/local/lib/libidn.so.12
/usr/local/lib/libidn.so.12.6.3
...
/usr/local/lib/libssh2.a
/usr/local/lib/libssh2.so
/usr/local/lib/libssh2.so.1
/usr/local/lib/libssh2.so.1.0.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And no plan to build both in the future?
Correct. No plans to build a shared lib and a static lib simultaneously, in a single run. Please see the related discussions:
- cmake: Add hardening, reduce exports, werror and install #32 (comment)
- Build: allow static or shared but not both bitcoin-core/secp256k1#1230
Also, you might want to look at bitcoin#28779.
Clearing the CMake cache, i.e., |
861e828
to
6a6a818
Compare
Clearing the entire build directory is what I did originally; clearing CMakeCache.txt loses my config settings so doesn't seem much better than clearing the build dir, but does also seem to fix it. |
You might want to use |
6e20a0f
to
d86340b
Compare
6a6a818
to
eaf2ffa
Compare
Rebased. |
eaf2ffa
to
8521a38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8521a38 LGTM
diff autotools vs cmake compile bitcoinconsensus
--- /tmp/autotools_compile 2023-11-03 09:40:47.597074000 +0100
+++ /tmp/cmake_compile 2023-11-03 10:57:39.073098000 +0100
@@ -1,52 +1,25 @@
--c consensus/merkle.cpp
+-c /path_to_source/bitcoin/bitcoin/src/consensus/merkle.cpp
-DABORT_ON_FAILED_ASSUME
--DBUILD_BITCOIN_INTERNAL # Missing in cmake on the command line but is in BUILD/build.ninja
-DDEBUG
-DDEBUG_LOCKCONTENTION
-DDEBUG_LOCKORDER
--DHAVE_BUILD_INFO
-DHAVE_CONFIG_H
--DPIC # Why missing in cmake?
--DPROVIDE_FUZZ_MAIN_FUNCTION
-DRPC_DOC_CHECK
-fcf-protection=full
-fPIC
-fstack-clash-protection
-fstack-protector-all
-ftrapv
-g3
--I.
--I../src/config
--I./obj
--I./secp256k1/include
--I/usr/local/include
+-I/path_to_source/bitcoin/bitcoin/src
+-I/path_to_source/bitcoin/bitcoin/src/secp256k1/include
+-I/path_to_build/src
-MD
--MF consensus/.deps/libbitcoinconsensus_la-merkle.Tpo
--MP
--MT consensus/libbitcoinconsensus_la-merkle.lo
--o consensus/libbitcoinconsensus_la-merkle.o
+-MF src/CMakeFiles/bitcoin_consensus.dir/consensus/merkle.cpp.o.d
+-MT src/CMakeFiles/bitcoin_consensus.dir/consensus/merkle.cpp.o
+-o src/CMakeFiles/bitcoin_consensus.dir/consensus/merkle.cpp.o
-O0
-std=c++17
--Wall
--Wconditional-uninitialized
--Wdate-time
--Wdocumentation
-Werror
--Wextra
--Wformat
--Wformat-security
--Wgnu
--Wimplicit-fallthrough
--Wloop-analysis
--Wno-self-assign
--Wno-thread-safety-reference-return
--Wno-unused-parameter
--Woverloaded-virtual
--Wredundant-decls
--Wshadow-field
-Wstack-protector
--Wsuggest-override
--Wthread-safety
--Wunreachable-code-loop-increment
--Wunused-member-function
--Wvla
diff autotools vs cmake link bitcoinconsensus
--- /tmp/autotools_link 2023-11-03 09:43:06.238869000 +0100
+++ /tmp/cmake_link 2023-11-03 09:58:17.605383000 +0100
@@ -1,57 +1,40 @@
--DPIC
-fPIC
--fstack-protector-all # Hmm?
+-ftrapv # Why this difference?
-g3
--L/usr/lib
--L/usr/local/lib
--L/usr/local/llvm-devel/lib/clang/18/lib/x86_64-portbld-freebsd14.0
--lc
--lc++
--lgcc
--lgcc
--lgcc_s
--lgcc_s
--lm
--nostdlib
--o .libs/libbitcoinconsensus.so.0.0.0
+-o src/script/libbitcoinconsensus.so.0.0.0
-O0
-shared
--std=c++17
--Wl,-soname -Wl,libbitcoinconsensus.so.0
--Wl,-z -Wl,now
--Wl,-z -Wl,relro
--Wl,-z -Wl,separate-code
+-Wl,-soname,libbitcoinconsensus.so.0
+-Wl,-z,now
+-Wl,-z,relro
+-Wl,-z,separate-code
-/usr/lib/crtbeginS.o
-/usr/lib/crtendS.o
-/usr/lib/crti.o
-/usr/lib/crtn.o
-.libs/libbitcoinconsensus_la-arith_uint256.o
+src/CMakeFiles/bitcoin_consensus.dir/arith_uint256.cpp.o
-.libs/libbitcoinconsensus_la-hash.o
+src/CMakeFiles/bitcoin_consensus.dir/hash.cpp.o
-.libs/libbitcoinconsensus_la-pubkey.o
+src/CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.o
-.libs/libbitcoinconsensus_la-uint256.o
+src/CMakeFiles/bitcoin_consensus.dir/uint256.cpp.o
-consensus/.libs/libbitcoinconsensus_la-merkle.o
+src/CMakeFiles/bitcoin_consensus.dir/consensus/merkle.cpp.o
-consensus/.libs/libbitcoinconsensus_la-tx_check.o
+src/CMakeFiles/bitcoin_consensus.dir/consensus/tx_check.cpp.o
-crypto/.libs/libbitcoinconsensus_la-aes.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/aes.cpp.o
-crypto/.libs/libbitcoinconsensus_la-chacha20.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/chacha20.cpp.o
-crypto/.libs/libbitcoinconsensus_la-chacha20poly1305.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/chacha20poly1305.cpp.o
-crypto/.libs/libbitcoinconsensus_la-hkdf_sha256_32.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/hkdf_sha256_32.cpp.o
-crypto/.libs/libbitcoinconsensus_la-hmac_sha256.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/hmac_sha256.cpp.o
-crypto/.libs/libbitcoinconsensus_la-hmac_sha512.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/hmac_sha512.cpp.o
-crypto/.libs/libbitcoinconsensus_la-muhash.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/muhash.cpp.o
-crypto/.libs/libbitcoinconsensus_la-poly1305.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/poly1305.cpp.o
-crypto/.libs/libbitcoinconsensus_la-ripemd160.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/ripemd160.cpp.o
-crypto/.libs/libbitcoinconsensus_la-sha1.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/sha1.cpp.o
-crypto/.libs/libbitcoinconsensus_la-sha256_sse4.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/sha256_sse4.cpp.o
-crypto/.libs/libbitcoinconsensus_la-sha256.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/sha256.cpp.o
-crypto/.libs/libbitcoinconsensus_la-sha3.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/sha3.cpp.o
-crypto/.libs/libbitcoinconsensus_la-sha512.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/sha512.cpp.o
-crypto/.libs/libbitcoinconsensus_la-siphash.o
+src/crypto/CMakeFiles/bitcoin_crypto_base.dir/siphash.cpp.o
-primitives/.libs/libbitcoinconsensus_la-block.o
+src/CMakeFiles/bitcoin_consensus.dir/primitives/block.cpp.o
-primitives/.libs/libbitcoinconsensus_la-transaction.o
+src/CMakeFiles/bitcoin_consensus.dir/primitives/transaction.cpp.o
-script/.libs/libbitcoinconsensus_la-bitcoinconsensus.o
+src/script/CMakeFiles/bitcoinconsensus.dir/bitcoinconsensus.cpp.o
-script/.libs/libbitcoinconsensus_la-interpreter.o
+src/CMakeFiles/bitcoin_consensus.dir/script/interpreter.cpp.o
-script/.libs/libbitcoinconsensus_la-script_error.o
+src/CMakeFiles/bitcoin_consensus.dir/script/script_error.cpp.o
-script/.libs/libbitcoinconsensus_la-script.o
+src/CMakeFiles/bitcoin_consensus.dir/script/script.cpp.o
-secp256k1/.libs/libsecp256k1.a
+libsecp256k1.a
-support/.libs/libbitcoinconsensus_la-cleanse.o
+src/script/CMakeFiles/bitcoinconsensus.dir/__/support/cleanse.cpp.o
-util/.libs/libbitcoinconsensus_la-strencodings.o
+src/CMakeFiles/bitcoin_consensus.dir/util/strencodings.cpp.o
On install: autotools installs both static and shared libbitcoinconsensus whereas cmake just one, depending on BUILD_SHARED_LIBS
(IMO that's ok given bitcoin#28779). The installed lib/pkgconfig/libbitcoinconsensus.pc
is identical between autotools and cmake.
Thank you for your valuable feedback. The way how this branch handles the |
Why? I noticed that when I added this (forgot to which source code file, edit: now I see it was #ifdef BUILD_BITCOIN_INTERNAL
#error 123
#else
#error 456
#endif it failed with "456"... |
@theuni, @fanquake, @TheCharlatan Fellow Libtool connoisseurs, In the master branch, I've got:
When linking
I can see |
I believe this is the list: https://git.savannah.gnu.org/cgit/libtool.git/tree/build-aux/ltmain.in#n5392 I'm not 100% sure it's what make it through to the linker, it may just be the list that libtool intercepts and does something with. But yes, that looks like it's been quietly swallowing up a list of arbitrary flags for years :( Edit: For the most part I think this actually ends up being the correct thing to do though, as the linker doesn't need most of those flags. |
8521a38
to
6ce3e63
Compare
Fixed. |
dd0ef98
to
3106952
Compare
I've addressed the previous comments and fixed other bugs that I found during extensive testing in different build scenarios. |
Yea, please lets not try and prematurely optimize anything here, for uses cases or users that may not even exist. Otherwise we'll end up with a stack of build complexity / options that we don't need, and just have to carry around forever. |
This doesn't really seem like a good tradeoff, or requirement to introduce.
Doesn't this just break as soon as the binaries are moved? |
Disregard this, either I misremembered how this worked in master or it's changed since. Either way, the above doesn't make much sense. I'm looking at master now and taking another stab at understanding where the problem is :) |
I've been playing around with this. Here is an attempt which adds a new binary with everything built-in: theuni@2831f77 It solves all of our problems, but it's getting a bit messy. It'd be hard to justify a I can't say I love it, but it works afaics. Thoughts? |
I have the same concerns.
It depends. The answer is "no, it doesn't break" if the user moves/installs the library to a well-known / standard location, or moves the |
How about this: theuni@f30fb14 ? Linking against an actual shared lib here as we do currently doesn't do us any good because we're not testing anything about the dyloader/dlopener, and we're not testing in C. How about we just add the file that's missing? It seems overly simple, but it works and removes the paths issue altogether. And as a benefit it means that we can remove the ifdefs in the test and just let them always run. |
Did this last week in the current build system here: TheCharlatan@34d9412 . I think if that consensus file is baked in, there is little point in keeping the |
Heh, the variable now means the exact opposite of its name. Concept ACK. Mind PRing that upstream for discussion, and we can bikeshed the names there? |
I'll be happy to join the discussion in that PR. Just curious about the current Autotools-based build system behaviour when it's configured with |
I'd like to clarify for myself and posterity our vision of the way how the user of the Bitcoin Core release package can run tests that are specific to the provided shared libraries, i.e.,
Please let me know if you think that these questions should be cross-posted to the main repo and discussed there. |
Does it mean that |
This library has existed for nearly 10 years with very little known uptake or impact. It has become a maintenance burden. In several cases it dictates our code/library structure (for example necessatating LIBBITCOIN_CRYPTO_BASE), as well as build-system procedures (building multiple copies of object files especially for the lib). Several discussions have arisen wrt migrating it to CMake and it has become difficult to justify adding more complexity for a library that is virtually unused anyway. See for example the discussions: hebasto#41 bitcoin#29123 Instead, we (fanquake, hebasto, TheCharlatan, and I) propose simply not migrating it to CMake and letting it end with v26. Any remaining use-cases could be handled in the future by libbitcoinkernel.
This library has existed for nearly 10 years with very little known uptake or impact. It has become a maintenance burden. In several cases it dictates our code/library structure (for example necessitating LIBBITCOIN_CRYPTO_BASE), as well as build-system procedures (building multiple copies of object files especially for the lib). Several discussions have arisen wrt migrating it to CMake and it has become difficult to justify adding more complexity for a library that is virtually unused anyway. See for example the discussions: hebasto#41 bitcoin#29123 Instead, we (fanquake, hebasto, TheCharlatan, and I) propose simply not migrating it to CMake and letting it end with v26. Any remaining use-cases could be handled in the future by libbitcoinkernel.
This library has existed for nearly 10 years with very little known uptake or impact. It has become a maintenance burden. In several cases it dictates our code/library structure (for example necessitating LIBBITCOIN_CRYPTO_BASE), as well as build-system procedures (building multiple copies of object files especially for the lib). Several discussions have arisen wrt migrating it to CMake and it has become difficult to justify adding more complexity for a library that is virtually unused anyway. See for example the discussions: hebasto#41 bitcoin#29123 Instead, we (fanquake, hebasto, TheCharlatan, and I) propose simply not migrating it to CMake and letting it end with v27. Any remaining use-cases could be handled in the future by libbitcoinkernel.
Marking this PR as a draft in the light of the bitcoin#29189. |
67ceebb
to
203a3ab
Compare
9b9f562 cmake: Add fuzzing options (Hennadii Stepanov) ea7861e cmake: Add `SANITIZERS` option (Hennadii Stepanov) Pull request description: New CMake variables that affect the build system configuration: - `SANITIZERS` - `BUILD_FUZZ_BINARY` - `FUZZ` In the light of bitcoin#29189, this PR is no longer based on #41. However, the `test/fuzz/script_bitcoin_consensus.cpp` might be easily added anytime. For OSS-Fuzz integration, please refer to hebasto/oss-fuzz#1. ACKs for top commit: theuni: Lightly tested ACK 9b9f562. Tree-SHA512: f762d1218f2f8bfe26bdd43f431cb37a26093a6899db7120b50df3083f81d6ad6aa867937e69930faff6ab4519532cfaca48aaf97831d4c2593b93423cb6d41a
ff2f574
to
dacc6f7
Compare
This library has existed for nearly 10 years with very little known uptake or impact. It has become a maintenance burden. In several cases it dictates our code/library structure (for example necessitating LIBBITCOIN_CRYPTO_BASE), as well as build-system procedures (building multiple copies of object files especially for the lib). Several discussions have arisen wrt migrating it to CMake and it has become difficult to justify adding more complexity for a library that is virtually unused anyway. See for example the discussions: hebasto#41 bitcoin#29123 Instead, we (fanquake, hebasto, TheCharlatan, and I) propose simply not migrating it to CMake and letting it end with v27. Any remaining use-cases could be handled in the future by libbitcoinkernel.
This library has existed for nearly 10 years with very little known uptake or impact. It has become a maintenance burden. In several cases it dictates our code/library structure (for example necessitating LIBBITCOIN_CRYPTO_BASE), as well as build-system procedures (building multiple copies of object files especially for the lib). Several discussions have arisen wrt migrating it to CMake and it has become difficult to justify adding more complexity for a library that is virtually unused anyway. See for example the discussions: hebasto#41 bitcoin#29123 Instead, we (fanquake, hebasto, TheCharlatan, and I) propose simply not migrating it to CMake and letting it end with v27. Any remaining use-cases could be handled in the future by libbitcoinkernel.
25dc87e libconsensus: deprecate (Cory Fields) Pull request description: This library has existed for nearly 10 years with very little known uptake or impact. It has become a maintenance burden. In several cases it dictates our code/library structure (for example necessitating LIBBITCOIN_CRYPTO_BASE), as well as build-system procedures (building multiple copies of object files especially for the lib). Several discussions have arisen wrt migrating it to CMake and it has become difficult to justify adding more complexity for a library that is virtually unused anyway. See for example the discussions: hebasto#41 #29123 And here: #29180 Where it is pointed out that the libbitcoinconsensus functions are slower than those the internal bitcoind equivalents due to the missing sha2 implementations. Instead, we (fanquake, hebasto, TheCharlatan, and I) propose simply not migrating it to CMake and letting it end with v27. Any remaining use-cases could be handled in the future by libbitcoinkernel. If there are any users currently using libbitcoinconsensus, please chime in with your use-case! Edit: Corrected final release to be v27. ACKs for top commit: TheCharlatan: ACK 25dc87e fanquake: ACK 25dc87e - this library has very little, if any impactful real world usage. It has been entirely broken (on various platforms) for long periods of its existence, where nobody even noticed. Pruning this out to save porting, and starting anew with the kernel, is the sane thing to do. Tree-SHA512: baff2b3c4f76f520c96021035f751fdcb51bedf00e767660249e92a7bc7c5c176786bcf2c4cfe2d2351c200f932b39eb886bcfb22fbec824a41617590d6a1638
This library has existed for nearly 10 years with very little known uptake or impact. It has become a maintenance burden. In several cases it dictates our code/library structure (for example necessitating LIBBITCOIN_CRYPTO_BASE), as well as build-system procedures (building multiple copies of object files especially for the lib). Several discussions have arisen wrt migrating it to CMake and it has become difficult to justify adding more complexity for a library that is virtually unused anyway. See for example the discussions: hebasto/bitcoin#41 bitcoin/bitcoin#29123 Instead, we (fanquake, hebasto, TheCharlatan, and I) propose simply not migrating it to CMake and letting it end with v27. Any remaining use-cases could be handled in the future by libbitcoinkernel.
New CMake variables that affect the build system configuration:
BUILD_BITCOINCONSENSUS_LIB
(Bitcoin Core specific)BUILD_SHARED_LIBS
(see CMake docs)This PR uses the same approach as the secp256k1 repo does, which differs from the current one in the master branch.
Also see: