Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: reverse-hash on August 09, 2024, 10:37:33 PM



Title: When compiling bitcoind the binary doubles in size between 26.2 and 27.0
Post by: reverse-hash on August 09, 2024, 10:37:33 PM
Hello, people,

I am asking for your help in case any of you could give me some suggestions. I have my own node working with docker and I try to keep the daemon as light as possible.

The compilation process is exactly the same for both versions, I just change the bitcoin repository version tag.

Do you know what could be the reason? You can find a link to the complete dockerfile at the end of the post.

Thanks a lot

Code:
  make HOST=$(gcc -dumpmachine) NO_QT=1 NO_ZMQ=1 NO_WALLET=1 NO_BDB=1 NO_SQLITE=1 \
  && ./autogen.sh \
  && ./configure \
    --prefix=$PWD/depends/$(gcc -dumpmachine) LDFLAGS="-static-libstdc++" \
    --disable-bench \
    --disable-cli \
    --disable-debug \
    --disable-man \
    --disable-tests \
    --disable-upnp \
    --disable-wallet \
    --disable-zmq \
    --with-qrencode=no \
    --enable-fuzz-binary=no \
    --enable-strip \
    --without-gui \
    --without-bdb \
    --with-sqlite=no \   
  && make \

Code:
REPOSITORY       TAG           IMAGE ID       CREATED         SIZE
bitcoind         27.1          7a14ec692f8c   2 days ago      149MB
bitcoind         26.2          6fc0c7867196   4 days ago      80.1MB


https://raw.githubusercontent.com/reverse-hash/bitcoin-full-node-with-docker/main/bitcoind/Dockerfile (https://raw.githubusercontent.com/reverse-hash/bitcoin-full-node-with-docker/main/bitcoind/Dockerfile)


Title: Re: When compiling bitcoind the binary doubles in size between 26.2 and 27.0
Post by: reverse-hash on August 14, 2024, 11:16:06 PM
I found the solution. I share it just in case it can be useful for someone.

In the LDFLAGS , just add the option "-s" or "--strip-all". Example: LDFLAGS="-static-libstdc++ -s"

According to GNU linker (ld) documentation:

Code:
-s
--strip-all
    Omit all symbol information from the output file.

In summary, symbol information is essential during development and debugging, but for a final product, especially if we're looking to optimize size, it can be removed without affecting the functionality of the executable.


Title: Re: When compiling bitcoind the binary doubles in size between 26.2 and 27.0
Post by: NotATether on August 15, 2024, 08:42:03 AM
In summary, symbol information is essential during development and debugging, but for a final product, especially if we're looking to optimize size, it can be removed without affecting the functionality of the executable.

That makes sense, since the symbols are the only way I can think of that make a binary with otherwise a few changes grow really large in size.

Is it possible that the build steps are running with the -g flag somewhere inside the configure script or the automake file? Because Bitcoin Core3 is not supposed to be including debug info by default.


Title: Re: When compiling bitcoind the binary doubles in size between 26.2 and 27.0
Post by: reverse-hash on August 16, 2024, 06:48:39 PM
In summary, symbol information is essential during development and debugging, but for a final product, especially if we're looking to optimize size, it can be removed without affecting the functionality of the executable.

That makes sense, since the symbols are the only way I can think of that make a binary with otherwise a few changes grow really large in size.

Is it possible that the build steps are running with the -g flag somewhere inside the configure script or the automake file? Because Bitcoin Core3 is not supposed to be including debug info by default.

Thank you. After reviewing again the documentation I found the key:

Code:
Alternatively, or in addition, debugging information can be skipped for compilation. The default compile flags are -g -O2, and can be changed with: ./configure CXXFLAGS="-g0"
Doc: https://github.com/bitcoin/bitcoin/blob/43740f4971f45cd5499470b6a085b3ecd8b96d28/doc/build-unix.md

Not sure why, but -g is there by default :/.


Title: Re: When compiling bitcoind the binary doubles in size between 26.2 and 27.0
Post by: achow101 on August 17, 2024, 04:46:45 PM
--disable-debug is slightly misleading. It doesn't disable the inclusion of the debug symbols; rather it disables optimizations that make debugging very difficult.

Unless you override CFLAGS and/or CXXFLAGS, the debug symbols will always be included. For releases, we run strip on the result to produce a release binary with no debug symbols, and a separate file containing the debug symbols.

This is all likely to change very soon anyways as we switch to using cmake.


Title: Re: When compiling bitcoind the binary doubles in size between 26.2 and 27.0
Post by: reverse-hash on August 25, 2024, 04:13:54 PM
--disable-debug is slightly misleading. It doesn't disable the inclusion of the debug symbols; rather it disables optimizations that make debugging very difficult.

Unless you override CFLAGS and/or CXXFLAGS, the debug symbols will always be included. For releases, we run strip on the result to produce a release binary with no debug symbols, and a separate file containing the debug symbols.

This is all likely to change very soon anyways as we switch to using cmake.

Thanks a lot achow101. All clear now.