fanquake
commented at 4:49 pm on July 8, 2022:
member
Use Guix to produce a -static-pie bitcoind using GCC 14.3.0 and glibc 2.42. Using glibc for static builds, would be less of a leap compared to switching to musl libc (POC in #23203).
Produce a static position independent executable on targets that support it.
A static position independent executable is similar to a static executable,
but can be loaded at any address without a dynamic linker.
0# file bitcoind1 ELF 64-bit LSB pie executable, x86-64, version 1(GNU/Linux), static-pie linked, for GNU/Linux 3.2.0, stripped
23# ldd bitcoind4 statically linked
x86_64-linux-gnu size comparison:
master (a7e80676104b5c90c5b5e3bfab815d55a9061052) bitcoind is 15.35 megabytes.
This PR (597b5296d3adc693001ce39626fe32b9545eb604) bitcoind is 17.45 megabytes.
fanquake added the label
Build system
on Jul 8, 2022
fanquake marked this as a draft
on Jul 8, 2022
DrahtBot
commented at 10:29 pm on July 8, 2022:
contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.
Conflicts
Reviewers, this pull request conflicts with the following ones:
#33764 (ci: Add Windows + UCRT jobs for cross-compiling and native testing by hebasto)
#32764 (guix: Build for macOS using Clang only by hebasto)
#32162 (depends: Switch from multilib to platform-specific toolchains by hebasto)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
fanquake force-pushed
on Jul 13, 2022
fanquake
commented at 5:46 pm on July 13, 2022:
member
Rebased, and made small changes to fixup the linter and improve the security/symbol checks.
theuni
commented at 9:00 pm on July 13, 2022:
member
This is amazing!
Using glibc for static builds, would be less of a leap compared to switching to musl libc (POC in #23203).
Hard agree. Static musl builds would be very cool but tricky to audit for parity and thus pretty unlikely to ever become official/supported imo. This is a MUCH more palatable change.
fanquake force-pushed
on Jul 14, 2022
fanquake
commented at 10:41 am on July 14, 2022:
member
Added an additional patch to disable building various features/libs in GCC that we don’t need. i.e libquadmath, libsanitizer, gcov, libada and native language support. This should speed up compiling GCC, and slightly reduces the size of the pthread patch. I’m not currently disabling these features via the available configure flags, because they get passed through to GMP, which cannot handle them.
I’ve also updated -flto usage to be -flto=auto, as that seems to now be the preferred invocation, and it mitigates GCC warning output. i.e:
0lto-wrapper: warning: using serial compilation of 84 LTRANS jobs
1lto-wrapper: note: see the '-flto' option documentation for more information
I’ve also split the ELF PIE check into it’s own func, so we can special-case x86_64, and re-added the list of allowed ELF libs, but special-cased x86_64 to only pass if the list is empty.
luke-jr
commented at 5:00 pm on July 16, 2022:
member
How does this handle resolvers? eg, static glibc 2.33 applications break on systems with glibc 2.34…
DrahtBot added the label
Needs rebase
on Jul 19, 2022
fanquake force-pushed
on Jul 19, 2022
DrahtBot removed the label
Needs rebase
on Jul 19, 2022
DrahtBot added the label
Needs rebase
on Jul 30, 2022
Frank-GER
commented at 4:47 pm on August 4, 2022:
none
Which OS did you build on?
On Ubuntu 20.04 after build:
file bitcoind
bitcoind: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, for GNU/Linux 3.2.0, stripped
Trying to run it, it crashes after seconds:
addcon thread start
Loading addresses from DNS seed dnsseed.emzy.de.
bitcoind: dl-call-libc-early-init.c:37: _dl_call_libc_early_init: Assertion `sym != NULL’ failed.
Aborted (core dumped)
Any ideas?
fanquake
commented at 8:05 am on August 5, 2022:
member
Which OS did you build on?
The base OS shouldn’t matter, because the build is performed with Guix. However I’ve been performing these builds on Ubuntu 22.04.
Any ideas?
How did you actually build bitcoind? Something like HOSTS="x86_64-linux-gnu" ./contrib/guix/guix-build?
fanquake force-pushed
on Aug 5, 2022
fanquake
commented at 8:39 am on August 5, 2022:
member
Rebased on master. Added a commit to use LIEF master, which reduces the number of changes in our scripts, as support for -static-pie ELF binaries has been added: https://github.com/lief-project/LIEF/issues/747. Will switch to a new release when one is available.
DrahtBot removed the label
Needs rebase
on Aug 5, 2022
Frank-GER
commented at 5:12 pm on August 5, 2022:
none
How did you actually build bitcoind? Something like HOSTS=“x86_64-linux-gnu” ./contrib/guix/guix-build?
I have just re-tested building the changes here (ef0edd55f3bc1e3f229134ec7ecac632de52eea7), and this produces a -static-pie binary as expected:
0guix-build-ef0edd55f3bc/distsrc-ef0edd55f3bc-x86_64-linux-gnu/src/bitcoind: ELF 64-bit LSB pie executable, x86-64, version 1(GNU/Linux), static-pie linked, for GNU/Linux 3.2.0, with debug_info, not stripped
It’s not clear to me that you are actually running a Guix build.
Frank-GER
commented at 6:22 pm on August 5, 2022:
none
the build I was testing:
~/bitcoin/guix-build-caa066465973/distsrc-caa066465973-x86_64-linux-gnu/src$ file bitcoind
bitcoind: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, for GNU/Linux 3.2.0, with debug_info, not stripped
just building again, fresh cloned with commit ef0edd5
export HOSTS=‘x86_64-linux-gnu’
./contrib/guix/guix-build
$ file guix-build-ef0edd55f3bc/distsrc-ef0edd55f3bc-x86_64-linux-gnu/src/bitcoind
guix-build-ef0edd55f3bc/distsrc-ef0edd55f3bc-x86_64-linux-gnu/src/bitcoind: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, for GNU/Linux 3.2.0, with debug_info, not stripped
build and run on Ubuntu 20.04
there is no other bitcoind on that OS
Frank-GER
commented at 2:27 pm on August 8, 2022:
none
building the same on Ubuntu 22.04:
file guix-build-ef0edd55f3bc/distsrc-ef0edd55f3bc-x86_64-linux-gnu/src/bitcoind
guix-build-ef0edd55f3bc/distsrc-ef0edd55f3bc-x86_64-linux-gnu/src/bitcoind: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), static-pie linked, for GNU/Linux 3.2.0, with debug_info, not stripped
Taking this bitcoind to Ubuntu 20 it shows:
file ./bitcoind
./bitcoind: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, for GNU/Linux 3.2.0, with debug_info, not stripped
and crashes with the above mentioned message:
bitcoind: dl-call-libc-early-init.c:37: _dl_call_libc_early_init: Assertion `sym != NULL’ failed.
Aborted (core dumped)
Checksums are the same for both builds (on Ubuntu 20 and 22)
Ubuntu 20 sees it as dynamic linked, Ubuntu 22 as static-pie linked.
On Ubuntu 20 it crashes, on Ubuntu 22 it works.
Same bitcoind on Debian 10:
file ./bitcoind
./bitcoind: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, for GNU/Linux 3.2.0, with debug_info, not stripped
ldd ./bitcoind
statically linked
Gets past that point where it crashes on Ubuntu 20 and starts syncing
fanquake force-pushed
on Aug 24, 2022
fanquake
commented at 3:34 pm on August 24, 2022:
member
Pushed a number of changes, and rebased on master.
Switched from glibc 2.35 to 2.36.
Added infra for aarch64 -static-pie builds.
More fine-grained / logical commits.
Updated to the latest version of LIEF (master).
fanquake force-pushed
on Sep 5, 2022
fanquake force-pushed
on Sep 7, 2022
DrahtBot added the label
Needs rebase
on Sep 13, 2022
fanquake force-pushed
on Sep 13, 2022
fanquake removed the label
Needs rebase
on Sep 13, 2022
fanquake force-pushed
on Jan 13, 2023
fanquake force-pushed
on Jan 25, 2023
DrahtBot added the label
Needs rebase
on Feb 17, 2023
fanquake force-pushed
on Feb 17, 2023
fanquake force-pushed
on Feb 17, 2023
fanquake
commented at 11:22 am on February 17, 2023:
member
DrahtBot removed the label
Needs rebase
on Feb 17, 2023
DrahtBot added the label
Needs rebase
on Mar 27, 2023
fanquake force-pushed
on Mar 27, 2023
DrahtBot removed the label
Needs rebase
on Mar 27, 2023
fanquake force-pushed
on May 22, 2023
DrahtBot added the label
CI failed
on May 30, 2023
DrahtBot removed the label
CI failed
on May 31, 2023
DrahtBot added the label
Needs rebase
on Jun 28, 2023
fanquake force-pushed
on Jun 30, 2023
DrahtBot removed the label
Needs rebase
on Jun 30, 2023
fanquake renamed this:
[POC] guix: produce a fully -static-pie x86_64 bitcoind using GCC and glibc
[POC] guix: produce a fully `-static-pie` bitcoind
on Jul 27, 2023
DrahtBot added the label
Needs rebase
on Aug 22, 2023
fanquake force-pushed
on Aug 23, 2023
DrahtBot removed the label
Needs rebase
on Aug 23, 2023
DrahtBot added the label
CI failed
on Aug 23, 2023
DrahtBot added the label
Needs rebase
on Aug 24, 2023
fanquake force-pushed
on Aug 24, 2023
DrahtBot removed the label
Needs rebase
on Aug 24, 2023
DrahtBot removed the label
CI failed
on Aug 24, 2023
fanquake force-pushed
on Aug 26, 2023
fanquake force-pushed
on Aug 27, 2023
fanquake force-pushed
on Sep 8, 2023
DrahtBot added the label
Needs rebase
on Nov 13, 2023
fanquake force-pushed
on Nov 13, 2023
DrahtBot removed the label
Needs rebase
on Nov 13, 2023
fanquake
commented at 3:37 pm on November 27, 2023:
member
DrahtBot added the label
Needs rebase
on Jan 16, 2024
fanquake force-pushed
on Jan 16, 2024
DrahtBot removed the label
Needs rebase
on Jan 16, 2024
DrahtBot removed the label
CI failed
on Jan 16, 2024
fanquake force-pushed
on Feb 16, 2024
DrahtBot added the label
CI failed
on Feb 28, 2024
DrahtBot removed the label
CI failed
on Mar 4, 2024
DrahtBot added the label
Needs rebase
on Mar 14, 2024
fanquake force-pushed
on Mar 15, 2024
fanquake
commented at 5:17 pm on March 15, 2024:
member
Rebased. Simplified somewhat. Switched to GCC 13.2.0 and glibc 2.39.
DrahtBot removed the label
Needs rebase
on Mar 15, 2024
DrahtBot added the label
Needs rebase
on Mar 26, 2024
fanquake force-pushed
on Mar 26, 2024
DrahtBot removed the label
Needs rebase
on Mar 26, 2024
fanquake force-pushed
on Apr 15, 2024
DrahtBot added the label
Needs rebase
on Apr 17, 2024
fanquake force-pushed
on May 2, 2024
DrahtBot removed the label
Needs rebase
on May 2, 2024
DrahtBot
commented at 5:22 am on May 2, 2024:
contributor
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.
Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
Leave a comment here, if you need help tracking down a confusing failure.
DrahtBot added the label
Needs rebase
on Jun 8, 2024
fanquake force-pushed
on Jul 1, 2024
fanquake force-pushed
on Jul 1, 2024
DrahtBot removed the label
Needs rebase
on Jul 1, 2024
DrahtBot removed the label
CI failed
on Jul 1, 2024
DrahtBot added the label
CI failed
on Jul 15, 2024
DrahtBot removed the label
CI failed
on Jul 20, 2024
fanquake force-pushed
on Jul 25, 2024
DrahtBot added the label
Needs rebase
on Aug 28, 2024
fanquake force-pushed
on Aug 28, 2024
DrahtBot removed the label
Needs rebase
on Aug 28, 2024
fanquake force-pushed
on Sep 19, 2024
DrahtBot added the label
Needs rebase
on Dec 20, 2024
fanquake force-pushed
on Jan 20, 2025
DrahtBot removed the label
Needs rebase
on Jan 20, 2025
fanquake force-pushed
on Feb 5, 2025
DrahtBot added the label
CI failed
on Feb 5, 2025
DrahtBot removed the label
CI failed
on Feb 5, 2025
fanquake force-pushed
on Feb 12, 2025
DrahtBot added the label
CI failed
on Feb 12, 2025
DrahtBot added the label
Needs rebase
on Feb 19, 2025
fanquake force-pushed
on Feb 19, 2025
DrahtBot removed the label
Needs rebase
on Feb 19, 2025
DrahtBot removed the label
CI failed
on Feb 19, 2025
fanquake force-pushed
on Feb 27, 2025
fanquake force-pushed
on Mar 12, 2025
fanquake force-pushed
on Mar 20, 2025
fanquake force-pushed
on Apr 11, 2025
DrahtBot added the label
Needs rebase
on May 12, 2025
fanquake force-pushed
on May 12, 2025
DrahtBot removed the label
Needs rebase
on May 12, 2025
fanquake force-pushed
on May 14, 2025
fanquake force-pushed
on May 14, 2025
DrahtBot added the label
Needs rebase
on May 27, 2025
fanquake force-pushed
on May 28, 2025
DrahtBot removed the label
Needs rebase
on May 28, 2025
DrahtBot added the label
Needs rebase
on Jun 11, 2025
fanquake force-pushed
on Jun 11, 2025
DrahtBot removed the label
Needs rebase
on Jun 11, 2025
achow101 requested review from theuni
on Oct 22, 2025
achow101 requested review from willcl-ark
on Oct 22, 2025
dergoegge
commented at 3:08 pm on October 22, 2025:
member
Concept ACK
achow101 requested review from m3dwards
on Oct 22, 2025
fanquake force-pushed
on Oct 28, 2025
fanquake force-pushed
on Oct 28, 2025
willcl-ark referenced this in commit
0074e4aa14
on Oct 28, 2025
willcl-ark referenced this in commit
3f8848d5d2
on Oct 28, 2025
willcl-ark referenced this in commit
1944d38c16
on Oct 29, 2025
willcl-ark referenced this in commit
11ca259f4d
on Oct 29, 2025
willcl-ark referenced this in commit
0430ebf3a8
on Oct 29, 2025
willcl-ark referenced this in commit
cbe8ae4b33
on Oct 29, 2025
willcl-ark referenced this in commit
1146ab21ac
on Oct 29, 2025
fanquake force-pushed
on Oct 29, 2025
fanquake force-pushed
on Oct 29, 2025
fanquake referenced this in commit
be853e9f7a
on Nov 3, 2025
fanquake referenced this in commit
9bcdd81636
on Nov 4, 2025
fanquake referenced this in commit
701fb7c8e2
on Nov 4, 2025
fanquake force-pushed
on Nov 4, 2025
fanquake referenced this in commit
5c41fa2918
on Nov 4, 2025
fanquake referenced this in commit
ffd7ca3c46
on Nov 5, 2025
fanquake referenced this in commit
8649f7dcf7
on Nov 5, 2025
fanquake force-pushed
on Nov 5, 2025
DrahtBot added the label
CI failed
on Nov 5, 2025
fanquake force-pushed
on Nov 5, 2025
DrahtBot removed the label
CI failed
on Nov 5, 2025
fanquake referenced this in commit
5b51244f21
on Nov 6, 2025
fanquake force-pushed
on Nov 6, 2025
fanquake renamed this:
[POC] guix: produce a fully `-static-pie` bitcoind
guix: produce a fully `-static-pie` bitcoind
on Nov 6, 2025
fanquake renamed this:
guix: produce a fully `-static-pie` bitcoind
guix: produce a `-static-pie` bitcoind
on Nov 6, 2025
fanquake referenced this in commit
a6417a24f6
on Nov 7, 2025
m3dwards
commented at 4:38 pm on November 7, 2025:
contributor
This is very cool.
Have I got the potential trade-offs correct here?
Positives:
More portable - especially running a modern binary on an older linux
Enable very small docker images
Downsides:
Static glibc can struggle with resolvers and locale (although I don’t think locale is an issue here) potentially undermining the portability benefit. I don’t know if --enable-static-nss solves this? But as referenced in this line it’s been broken for a long time.
Binary would be bigger
fanquake referenced this in commit
6efb234510
on Nov 10, 2025
fanquake referenced this in commit
ce204ecace
on Nov 10, 2025
fanquake referenced this in commit
746c540845
on Nov 11, 2025
fanquake referenced this in commit
4568773763
on Nov 11, 2025
fanquake force-pushed
on Nov 11, 2025
fanquake
commented at 12:20 pm on November 11, 2025:
member
Binary would be bigger
Yes ~2mb. I’ve added a comparison of bitcoind size for master vs this change, to the PR description.
fanquake referenced this in commit
0716bb53f0
on Nov 11, 2025
fanquake referenced this in commit
94b5b3816c
on Nov 11, 2025
fanquake referenced this in commit
86fffd9380
on Nov 12, 2025
fanquake referenced this in commit
2b6e451075
on Nov 12, 2025
fanquake force-pushed
on Nov 12, 2025
fanquake referenced this in commit
e40362b4ff
on Nov 13, 2025
fanquake referenced this in commit
81be7e5bef
on Nov 14, 2025
fanquake referenced this in commit
ce6769c0e3
on Nov 14, 2025
fanquake referenced this in commit
26c6dd1ca5
on Nov 14, 2025
fanquake force-pushed
on Nov 14, 2025
DrahtBot added the label
Needs rebase
on Nov 17, 2025
fanquake referenced this in commit
680f587b10
on Nov 17, 2025
fanquake force-pushed
on Nov 17, 2025
willcl-ark
commented at 12:35 pm on November 17, 2025:
member
What are the exact implications of this? I guix-built this branch and loaded it into a scratch docker container and the dns seeds were connected to and loaded fine. Is this coming from my host system perhaps, even inside a scratch container?
I also tested the binary on alpine and it appeared to “fallback” to using libnss without issue…
fanquake referenced this in commit
f21d5bd923
on Nov 17, 2025
DrahtBot removed the label
Needs rebase
on Nov 17, 2025
fanquake referenced this in commit
59304910cb
on Nov 17, 2025
willcl-ark
commented at 11:48 am on November 18, 2025:
member
What are the exact implications of this? I guix-built this branch and loaded it into a scratch docker container and the dns seeds were connected to and loaded fine. Is this coming from my host system perhaps, even inside a scratch container?
I also tested the binary on alpine and it appeared to “fallback” to using libnss without issue…
Some additional context. When run in an alpine container with strace I see:
0x86_64-linux-gnu/bitcoin-84d3c4d14e70/bin on pr-25573 [$] via ❄️ impure (nix-shell-env) took 11s
1❯ strace -f \
2 -e trace=open,openat,stat,statx,access,readlink \
3 ./bitcoind -datadir=/tmp/b1 -daemon=0 2>&1 | grep -i 'libnss' 4[pid 930543] openat(AT_FDCWD, "/nix/store/khwsqzc1s0b92y3l695g95f4773lb2h1-capnproto-1.2.0/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXEC)= -1 ENOENT (No such file or directory) 5[pid 930543] openat(AT_FDCWD, "/gnu/store/hhrsk659w4k3zs0bin6i4q1lnbr4zxx0-glibc-cross-x86_64-linux-gnu-2.42/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXECstrace: Process 930545 attached
6[pid 930543] openat(AT_FDCWD, "/nix/store/khwsqzc1s0b92y3l695g95f4773lb2h1-capnproto-1.2.0/lib/libnss_mdns4_minimal.so.2", O_RDONLY|O_CLOEXEC)= -1 ENOENT (No such file or directory) 7[pid 930543] openat(AT_FDCWD, "/gnu/store/hhrsk659w4k3zs0bin6i4q1lnbr4zxx0-glibc-cross-x86_64-linux-gnu-2.42/lib/libnss_mdns4_minimal.so.2", O_RDONLY|O_CLOEXEC)= -1 ENOENT (No such file or directory) 8[pid 930543] openat(AT_FDCWD, "/nix/store/khwsqzc1s0b92y3l695g95f4773lb2h1-capnproto-1.2.0/lib/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC)= -1 ENOENT (No such file or directory) 9[pid 930543] openat(AT_FDCWD, "/gnu/store/hhrsk659w4k3zs0bin6i4q1lnbr4zxx0-glibc-cross-x86_64-linux-gnu-2.42/lib/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC)= -1 ENOENT (No such file or directory)10^C⏎
Both succeed in retrieving DNS seed addresses.
willcl-ark
commented at 2:48 pm on November 18, 2025:
member
Ah OK I think I might understand better now. Both systems I tested on include files and dns backends as part of nsswitch.conf (line starting with hosts: ):
0# alpine Container 1 2x86_64-linux-gnu/bitcoin-84d3c4d14e70/bin on pr-25573 [$] via ❄️ impure (nix-shell-env) 3❯ cat /etc/nsswitch.conf
4passwd: files systemd
5group: files [success=merge] systemd
6shadow: files systemd
7sudoers: files
8 9hosts: mymachines mdns4_minimal [NOTFOUND=return] files myhostname dns mdns4
10networks: files
1112ethers: files
13services: files
14protocols: files
15rpc: files
1617# NixOS host1819x86_64-linux-gnu/bitcoin-84d3c4d14e70/bin on pr-25573 [$] via ❄️ impure (nix-shell-env)20❯ docker run --rm -it --entrypoint=sh alpine -lc 'cat /etc/nsswitch.conf'21# musl itself does not support NSS, however some third-party DNS22# implementations use the nsswitch.conf file to determine what23# policy to follow.24# Editing this file is not recommended.25hosts: files dns
…and these backends are actually baked into a static glibc, which allows it to succeed in lookups.
The (failed) dlopen calls on my Nix host are because my system nsswitch.conf includes extra backends which we try to open the lib for, but fail.
So it seems to be that --enable-static-nss must be for “statically linking extra lookup backends in” in addition to the baked in defaults.
If my understanding here is correct, then it seems totally fine to proceed without static nss enabled (while it is broken), as it doesn’t break our basic DNS lookup functionality at all, and at worst results in some failing dlopen trys.
fanquake referenced this in commit
5b4c9a1b3b
on Nov 19, 2025
fanquake referenced this in commit
9351c2be9b
on Nov 20, 2025
fanquake referenced this in commit
61a8f3840a
on Nov 20, 2025
fanquake referenced this in commit
23c1c4636d
on Nov 25, 2025
fanquake referenced this in commit
c767125efa
on Nov 25, 2025
fanquake referenced this in commit
19cb502045
on Nov 25, 2025
fanquake referenced this in commit
0ee5642048
on Nov 25, 2025
-static-pie
Produce a static position independent executable on targets that support it.
A static position independent executable is similar to a static executable,
but can be loaded at any address without a dynamic linker.
See https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2025-11-27 00:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me