unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Carl Dong <contact@carldong.me>
Cc: "help-guix@gnu.org" <help-guix@gnu.org>
Subject: Re: Bootstrappable bitcoin release builds with Guix
Date: Wed, 17 Apr 2019 22:58:36 +0200	[thread overview]
Message-ID: <874l6w8i2r.fsf@gnu.org> (raw)
In-Reply-To: <XPyvidOFdcS4et-G9uyZ-WL0YP8kVW-aHd--4HmMTy-Z4pMw3qFJAf6sbqWtj4zijE-mgSxCLUkLnWyjwTYG0BSakHTCMk3Lqswd06vh7TM=@carldong.me> (Carl Dong's message of "Tue, 09 Apr 2019 15:03:38 +0000")

Hi Carl,

Carl Dong <contact@carldong.me> skribis:

> I've been on a quest to use Guix for Bitcoin Core's reproducible builds as I
> believe that Guix's focus on bootstrappability, and Guile's simplicity and
> flexibility are very desirable qualities in building an auditable, secure, and
> reliable build process. My pull request (very short thanks to Guix's
> infrastructure) can be found here:
> https://github.com/bitcoin/bitcoin/pull/15277/files

I’m late to the party, but this is awesome!  The goals you’re pursuing
are in line with those we’re after in Guix, Reproducible Builds, and
Bootstrappable, so it’s great to see that Guix can help others here.

> I've submitted patches for the Guix bitcoin-core package to make it
> reproducible, which seems to work fine. However, for easier acceptance into the
> bitcoin core process, I need to produce tarballs like the ones we have on our
> servers today: https://bitcoincore.org/bin/bitcoin-core-0.17.1/
>
> For some context, we have a "mini-guix" of sorts seen in our "depends tree"
> here: https://github.com/bitcoin/bitcoin/tree/master/depends. This builds all
> the dependencies for bitcoin just the way we want them, in preparation for
> getting linked into bitcoin itself.
>
> My current approach for the build process is to produce a Guix container in
> which I execute a build of our "depends tree" followed by a build of bitcoin
> itself. See the Guix manifest and scripts here:
> https://github.com/bitcoin/bitcoin/pull/15277/files

OK.  You could store the output of ‘guix describe -f channels’ in
addition to the manifest, and then do ‘guix pull -C’ of this file.  That
way, you’d be pinning a specific package set.

> However, there were three hiccups that I had to hack my way around:
>
> 1. libstdc++ would not link statically even with "-static-libstdc++". The hack
>    was to remove the .la file under $LIBRARY_PATH.

Weird.  Could you send a small test case for this to bug-guix@gnu.org?

> 2. Upon inspection of the binaries produced at the end of this process, they all
>    had rpaths. The hack was to use patchelf --remove-rpath on them.

Yes, ‘ld-wrapper’ and our ‘gcc’ packages add those on purpose; they’re
required for dynamically-linked binaries.  But you’re producing
statically-linked executables in the end, right?

> 3. Upon inspection of the binaries produced at the end of this process, their
>    interpreters all had a `/gnu/store/blahblah-glibc-2.28' prefix. The hack was
>    to use patchelf --set-interpreter on them.

To use /lib/ld-linux-x86-64.so.2 instead?

You can do that, but there’s a risk: this is assuming that the loader
and libc on the user’s machine are compatible with those you built
against.

> My questions are:
>
> 1. Is there a way to avoid the hacks that I listed above? I understand that it
>    might mean writing custom gcc packages and I'm 100% okay with that.
>
> 2. Is there an easier way of achieving the same thing?

I think the difficulty here lies in producing non-self-contained binary
tarballs, paradoxically.  :-)

By that I mean that the tarball at
<https://bitcoincore.org/bin/bitcoin-core-0.17.1/bitcoin-0.17.1-x86_64-linux-gnu.tar.gz>
makes assumptions on the user’s machine:

--8<---------------cut here---------------start------------->8---
$ file /tmp/bitcoin-0.17.1/bin/bitcoin-cli 
/tmp/bitcoin-0.17.1/bin/bitcoin-cli: ELF 64-bit LSB pie executable x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=aced8cd0e28adb7a9e0c15f2e794aae7150d348e, stripped
$ objdump -x /tmp/bitcoin-0.17.1/bin/bitcoin-cli |grep NEED
  NEEDED               librt.so.1
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libpthread.so.0
  NEEDED               libc.so.6
  NEEDED               ld-linux-x86-64.so.2
  VERNEED              0x0000000000002850
  VERNEEDNUM           0x0000000000000006
--8<---------------cut here---------------end--------------->8---

The binary assumes that /lib64/ld-linux-x86-64.so.2 exists, that
libgcc_s.so & co. will be found in the “standard locations”, etc.  These
assumptions do not hold on a standalone Guix system or on NixOS or
Gobolinux.  They are probably reasonable for FHS distros, though.

Can you achieve this by simply taking the ouptut of “guix build
bitcoin-core-alt” (where ‘bitcoin-core-alt’ is a variant that statically
links against libstdc++ etc.), patching the ELF interpreter, and then
copying it in a tarball?

You’d also get cross-compilation by adding ‘--target’.

Thanks,
Ludo’.

  reply	other threads:[~2019-04-17 20:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 15:03 Bootstrappable bitcoin release builds with Guix Carl Dong
2019-04-17 20:58 ` Ludovic Courtès [this message]
2019-04-23 20:56   ` Carl Dong
2019-05-03  9:31     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874l6w8i2r.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=contact@carldong.me \
    --cc=help-guix@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).