Skip to content
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

use shared libraries #4679

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

Conversation

milahu
Copy link

@milahu milahu commented Jul 15, 2024

i want to link nano-node against shared libraries, to speed up the build process

so effectively, i have reverted #4030 (and some other commits)

this PR should not be merged in its current form
because most package managers dont allow pinning dependencies like nix or guix

ideally, there should be a build option like USE_SHARED_LIBS
and the CMakeLists.txt should have separate branches for static or shared build

Error: logging should be initialized before creating a logger

fixed: runtime error: Error: logging should be initialized before creating a logger

the build is passing, but now i get this error on runtime... ideas?

$ /nix/store/4cw51sk7va4mx1nnbcfh61vba8i5jyvv-nano-node-26.1/bin/nano_wallet
Assertion (global_initialized) failed
nano::logger::logger(std::string)
/build/source/nano/lib/logging.cpp:220
Error: logging should be initialized before creating a logger

 0# 0x0000000000A11F07 in /nix/store/4cw51sk7va4mx1nnbcfh61vba8i5jyvv-nano-node-26.1/bin/nano_wallet
 1# 0x0000000000A09DD8 in /nix/store/4cw51sk7va4mx1nnbcfh61vba8i5jyvv-nano-node-26.1/bin/nano_wallet
 2# 0x00000000009ABAB2 in /nix/store/4cw51sk7va4mx1nnbcfh61vba8i5jyvv-nano-node-26.1/bin/nano_wallet
 3# 0x000000000050CAAF in /nix/store/4cw51sk7va4mx1nnbcfh61vba8i5jyvv-nano-node-26.1/bin/nano_wallet
 4# __libc_start_main in /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6
 5# 0x000000000052F915 in /nix/store/4cw51sk7va4mx1nnbcfh61vba8i5jyvv-nano-node-26.1/bin/nano_wallet

Aborted (core dumped)

it works as expected with the nano-node with gitmodules build
(nixpkgs has only nano-wallet but not the full nano-node, dont ask me why)

nix-shell -p nano-wallet
nano_wallet

my build script is nano-node.nix

you will need nix to run that build script

git clone --depth=1 https://github.com/milahu/nur-packages
cd nur-packages
nix-build . -A nano-node
./result/bin/nano_wallet

it seems like nano::logger::initialize is not called

nano::logger was added in #4375 by @pwojcikdev

nano/lib/logging.cpp
void nano::logger::initialize (nano::log_config fallback, std::optional<std::filesystem::path> data_path, std::vector<std::string> const & config_overrides)
{
        // Only load log config from file if data_path is available (i.e. not running in cli mode)
        nano::log_config config = data_path ? nano::load_log_config (fallback, *data_path, config_overrides) : fallback;
        initialize_common (config, data_path);
        global_initialized = true;
}

so nano::logger::logger fails

nano::logger::logger (std::string identifier) :
  identifier{ std::move (identifier) }
{
  release_assert (global_initialized, "logging should be initialized before creating a logger");
}

but nano::logger::initialize should be called from nano/nano_wallet/entry.cpp

int main (int argc, char * const * argv)
{
  nano::set_umask (); // Make sure the process umask is set before any files are created
  nano::initialize_file_descriptor_limit ();
  nano::logger::initialize (nano::log_config::cli_default ());
backtrace
(gdb) bt
#0  0x00007ffff56e3efc in __pthread_kill_implementation () from /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6
#1  0x00007ffff5693e86 in raise () from /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6
#2  0x00007ffff567c935 in abort () from /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6
#3  0x00000000007a0769 in assert_internal (check_expr=check_expr@entry=0x8e5144 "global_initialized", 
    func=func@entry=0x903fb8 "nano::logger::logger(std::string)", file=file@entry=0x903f90 "/build/source/nano/lib/logging.cpp", line=line@entry=220, 
    is_release_assert=is_release_assert@entry=true, error_msg="logging should be initialized before creating a logger")
    at /build/source/nano/lib/utility.cpp:168
#4  0x0000000000770a3f in nano::logger::logger (this=this@entry=0xb14860 <(anonymous namespace)::logger>, identifier="")
    at /build/source/nano/lib/logging.cpp:220
#5  0x0000000000499450 in __static_initialization_and_destruction_0 () at /build/source/nano/nano_wallet/entry.cpp:28
#6  0x00000000004996d1 in _GLOBAL__sub_I_entry.cpp(void) () at /build/source/nano/nano_wallet/entry.cpp:342
#7  0x00007ffff567e23e in __libc_start_main_impl () from /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6
#8  0x0000000000498c35 in _start ()

so nano::logger::logger is called by

#5 0x0000000000499450 in __static_initialization_and_destruction_0 () at /build/source/nano/nano_wallet/entry.cpp:28

nano/nano_wallet/entry.cpp

namespace
{
nano::logger logger{ "wallet_daemon" };

im surprised that this works in the original version (does it?)

ldd
$ ldd result/bin/.nano_wallet-wrapped
        linux-vdso.so.1 (0x00007ffccd8e9000)
        libcryptopp.so.8 => /nix/store/l9x8a6mbsija15dfclyy5mh5p4ayygcc-crypto++-8.9.0/lib/libcryptopp.so.8 (0x00007f39fec9d000)
        libargon2.so.1 => /nix/store/mqkwyf0j5mb7f68qdw964xx6828k6dd2-libargon2-20190702/lib/libargon2.so.1 (0x00007f39fec93000)
        liblmdb.so => /nix/store/jghdj60m9gkysiar29afz8shp1y78n19-lmdb-0.9.32/lib/liblmdb.so (0x00007f39fec7c000)
        libboost_filesystem.so.1.81.0 => /nix/store/r3j1ry1w4l7psklv1xxgxpg7hlsic0ir-boost-1.81.0/lib/libboost_filesystem.so.1.81.0 (0x00007f39fec54000)
        libboost_thread.so.1.81.0 => /nix/store/r3j1ry1w4l7psklv1xxgxpg7hlsic0ir-boost-1.81.0/lib/libboost_thread.so.1.81.0 (0x00007f39fec37000)
        libboost_chrono.so.1.81.0 => /nix/store/r3j1ry1w4l7psklv1xxgxpg7hlsic0ir-boost-1.81.0/lib/libboost_chrono.so.1.81.0 (0x00007f39fec2d000)
        libboost_atomic.so.1.81.0 => /nix/store/r3j1ry1w4l7psklv1xxgxpg7hlsic0ir-boost-1.81.0/lib/libboost_atomic.so.1.81.0 (0x00007f39fec23000)
        librocksdb.so.9 => /nix/store/6fgsvpkrda4i3g5b0cz8i36mgh61nq42-rocksdb-9.1.1/lib/librocksdb.so.9 (0x00007f39fdfda000)
        libboost_program_options.so.1.81.0 => /nix/store/r3j1ry1w4l7psklv1xxgxpg7hlsic0ir-boost-1.81.0/lib/libboost_program_options.so.1.81.0 (0x00007f39fdf6c000)
        libdl.so.2 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libdl.so.2 (0x00007f39fdf67000)
        libspdlog.so.1.13 => /nix/store/3ri8agivq4209yqpcnd0vk4yiycjai1q-spdlog-1.13.0/lib/libspdlog.so.1.13 (0x00007f39fdef2000)
        libfmt.so.10 => /nix/store/fl6ayalxs1vg121p30l8nxx1dmhs49fj-fmt-10.2.1/lib/libfmt.so.10 (0x00007f39fdecd000)
        libboost_iostreams.so.1.81.0 => /nix/store/r3j1ry1w4l7psklv1xxgxpg7hlsic0ir-boost-1.81.0/lib/libboost_iostreams.so.1.81.0 (0x00007f39fdeb4000)
        libboost_regex.so.1.81.0 => /nix/store/r3j1ry1w4l7psklv1xxgxpg7hlsic0ir-boost-1.81.0/lib/libboost_regex.so.1.81.0 (0x00007f39fde61000)
        libboost_system.so.1.81.0 => /nix/store/r3j1ry1w4l7psklv1xxgxpg7hlsic0ir-boost-1.81.0/lib/libboost_system.so.1.81.0 (0x00007f39fde5c000)
        libminiupnpc.so.17 => /nix/store/isa8z597dw3rg5ig6c91ry2qha3wdqsm-miniupnpc-2.2.6/lib/libminiupnpc.so.17 (0x00007f39fde4b000)
        libQt5Widgets.so.5 => /nix/store/jiszkap5g68fiin4lg911r55970p59jb-qtbase-5.15.12/lib/libQt5Widgets.so.5 (0x00007f39fd794000)
        libQt5Gui.so.5 => /nix/store/jiszkap5g68fiin4lg911r55970p59jb-qtbase-5.15.12/lib/libQt5Gui.so.5 (0x00007f39fd115000)
        libQt5Core.so.5 => /nix/store/jiszkap5g68fiin4lg911r55970p59jb-qtbase-5.15.12/lib/libQt5Core.so.5 (0x00007f39fcb4e000)
        libm.so.6 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libm.so.6 (0x00007f39fca6b000)
        libc.so.6 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6 (0x00007f39fc87e000)
        /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/ld-linux-x86-64.so.2 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib64/ld-linux-x86-64.so.2 (0x00007f39ff1ec000)
        libstdc++.so.6 => /nix/store/p3ffjixpnfgkqh20nsrc13vrj3yfi0nj-gcc-13.2.0-lib/lib/libstdc++.so.6 (0x00007f39fc61c000)
        libgcc_s.so.1 => /nix/store/p3ffjixpnfgkqh20nsrc13vrj3yfi0nj-gcc-13.2.0-lib/lib/libgcc_s.so.1 (0x00007f39fc5f7000)
        libpthread.so.0 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libpthread.so.0 (0x00007f39fc5f0000)
        librt.so.1 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/librt.so.1 (0x00007f39fc5eb000)
        libsnappy.so.1 => /nix/store/9m1y0bvyr6dlab6373jh7y8hmd6r0ia3-snappy-1.2.0/lib/libsnappy.so.1 (0x00007f39fc5dc000)
        libz.so.1 => /nix/store/nw1bnjadmzk9hnd4nbvxmqlh074vr16j-zlib-1.3.1/lib/libz.so.1 (0x00007f39fc5bc000)
        libbz2.so.1 => /nix/store/q4k8gmw2gpncglwdvz9fmqqwnynsb143-bzip2-1.0.8/lib/libbz2.so.1 (0x00007f39fc5a9000)
        liblz4.so.1 => /nix/store/w7ir04z15bxny7w5kzbyvwd7bi3kfi08-lz4-1.9.4/lib/liblz4.so.1 (0x00007f39fc570000)
        libzstd.so.1 => /nix/store/7mnvfrpsbivkxyfbmqczdq5pbb1n59j1-zstd-1.5.6/lib/libzstd.so.1 (0x00007f39fc49e000)
        liblzma.so.5 => /nix/store/n87dnp3cw99gssql0xk9yycrhrg50gir-xz-5.4.6/lib/liblzma.so.5 (0x00007f39fc46d000)
        libicudata.so.73 => /nix/store/hxfhcs6sdqang5qgzrjhhhq6qwdd7vql-icu4c-73.2/lib/libicudata.so.73 (0x00007f39fa5df000)
        libicui18n.so.73 => /nix/store/hxfhcs6sdqang5qgzrjhhhq6qwdd7vql-icu4c-73.2/lib/libicui18n.so.73 (0x00007f39fa28f000)
        libicuuc.so.73 => /nix/store/hxfhcs6sdqang5qgzrjhhhq6qwdd7vql-icu4c-73.2/lib/libicuuc.so.73 (0x00007f39fa083000)
        libGL.so.1 => /nix/store/s2w3qaw28ch6z0ymahkbhv66fbwz8hbb-libGL-1.7.0/lib/libGL.so.1 (0x00007f39f9ff3000)
        libpng16.so.16 => /nix/store/31l4c9kwx37gy2cr1xiswbbp4azsyp1n-libpng-apng-1.6.43/lib/libpng16.so.16 (0x00007f39f9fba000)
        libharfbuzz.so.0 => /nix/store/3058213v7kg1r0c7hrz4qyda2impjv5a-harfbuzz-8.4.0/lib/libharfbuzz.so.0 (0x00007f39f9e89000)
        libpcre2-16.so.0 => /nix/store/sik7a8dic5lxhm4cp9npibk97x9jcxwf-pcre2-10.43/lib/libpcre2-16.so.0 (0x00007f39f9df6000)
        libgthread-2.0.so.0 => /nix/store/bcms6vbac6jyffwyj8y630brpy1il4ks-glib-2.80.0/lib/libgthread-2.0.so.0 (0x00007f39f9def000)
        libglib-2.0.so.0 => /nix/store/bcms6vbac6jyffwyj8y630brpy1il4ks-glib-2.80.0/lib/libglib-2.0.so.0 (0x00007f39f9ca4000)
        libGLX.so.0 => /nix/store/wr5abp6s0z61mp1wwyjxhwcrs6sx3jwq-libglvnd-1.7.0/lib/libGLX.so.0 (0x00007f39f9c70000)
        libX11.so.6 => /nix/store/h0aal69rli3p604dmijx7mps1diwx4f3-libX11-1.8.9/lib/libX11.so.6 (0x00007f39f9b2b000)
        libXext.so.6 => /nix/store/pdikq8hwkj15d1jvlv48p98xn0xnn4dx-libXext-1.3.6/lib/libXext.so.6 (0x00007f39f9b14000)
        libGLdispatch.so.0 => /nix/store/wr5abp6s0z61mp1wwyjxhwcrs6sx3jwq-libglvnd-1.7.0/lib/libGLdispatch.so.0 (0x00007f39f9a5b000)
        libfreetype.so.6 => /nix/store/8ilnvaa1d66z1qn866phpdx5jpam0lm7-freetype-2.13.2/lib/libfreetype.so.6 (0x00007f39f998d000)
        libgraphite2.so.3 => /nix/store/ff6vzhlbnydw8n9kh7bsfwh01pi2i3qc-graphite2-1.3.14/lib/libgraphite2.so.3 (0x00007f39f9964000)
        libpcre2-8.so.0 => /nix/store/sik7a8dic5lxhm4cp9npibk97x9jcxwf-pcre2-10.43/lib/libpcre2-8.so.0 (0x00007f39f98c2000)
        libxcb.so.1 => /nix/store/cvbf30dc4mamggijbxwlwxaxd7q4wch1-libxcb-1.17.0/lib/libxcb.so.1 (0x00007f39f9897000)
        libbrotlidec.so.1 => /nix/store/qa2j4ql5vb7n1zyi8ai5acivsjkg0l8m-brotli-1.1.0-lib/lib/libbrotlidec.so.1 (0x00007f39f9889000)
        libXau.so.6 => /nix/store/mhs3ys5lbahsvrai5y0fv49q2xp4pc31-libXau-1.0.11/lib/libXau.so.6 (0x00007f39f9884000)
        libXdmcp.so.6 => /nix/store/6gg4xf3abpmdpkhpqkqwx2hdvs7fmgwc-libXdmcp-1.1.5/lib/libXdmcp.so.6 (0x00007f39f987a000)
        libbrotlicommon.so.1 => /nix/store/qa2j4ql5vb7n1zyi8ai5acivsjkg0l8m-brotli-1.1.0-lib/lib/libbrotlicommon.so.1 (0x00007f39f9857000)

backport to V26.0

i tried to backport this patch to V26.0 as a workaround for #4680 (comment)
but this fails to build with dynamic boost libraries

undefined reference to `boost::log::v2_mt_posix::sinks::text_file_backend::~text_file_backend()'

see also #269

boost::log was removed in #4030 = V26.1
and without boost::log the build just works with dynamic boost libraries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant