Skip to content

Commit 2711559

Browse files
committed
Merge bitcoin/bitcoin#22365: guix: Avoid relying on newer symbols by rebasing our cross toolchains on older glibcs
647f7e5 guix: Also sort SHA256SUMS.part (Carl Dong) dc4137a guix: Build depends/qt with our platform definition (Carl Dong) 16b0a93 guix: Rebase toolchain on glibc 2.24 (2.27 for riscv64) (Carl Dong) Pull request description: After this PR, we'll have the following: - riscv64 -> build with a toolchain targeting glibc 2.27 - everything else -> builds with a toolchain targeting glibc 2.24, but will not have symbols > 2.17 (checked by `symbol-check.py`) ACKs for top commit: achow101: reACK 647f7e5 hebasto: ACK 647f7e5 MarcoFalke: review ACK 647f7e5 fanquake: ACK 647f7e5 - documentation can be fixed shortly. Tree-SHA512: ddff57a5d7c053687b0a273720d4ad7d28c6fc8816226d4304869284d017af5e3630d4b57565d91e74f2e1b7583c9c83ee8b2e5e70e41d619ab618e602c97a94
2 parents c609e10 + 647f7e5 commit 2711559

8 files changed

+522
-2
lines changed

contrib/guix/libexec/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ make -C depends --jobs="$JOBS" HOST="$HOST" \
214214
x86_64_linux_NM=x86_64-linux-gnu-nm \
215215
x86_64_linux_STRIP=x86_64-linux-gnu-strip \
216216
qt_config_opts_i686_linux='-platform linux-g++ -xplatform bitcoin-linux-g++' \
217+
qt_config_opts_x86_64_linux='-platform linux-g++ -xplatform bitcoin-linux-g++' \
217218
FORCE_USE_SYSTEM_CLANG=1
218219

219220

@@ -445,5 +446,6 @@ mv --no-target-directory "$OUTDIR" "$ACTUAL_OUTDIR" \
445446
find "$ACTUAL_OUTDIR" -type f
446447
} | xargs realpath --relative-base="$PWD" \
447448
| xargs sha256sum \
449+
| sort -k2 \
448450
| sponge "$ACTUAL_OUTDIR"/SHA256SUMS.part
449451
)

contrib/guix/libexec/codesign.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@ mv --no-target-directory "$OUTDIR" "$ACTUAL_OUTDIR" \
108108
find "$ACTUAL_OUTDIR" -type f
109109
} | xargs realpath --relative-base="$PWD" \
110110
| xargs sha256sum \
111+
| sort -k2 \
111112
| sponge "$ACTUAL_OUTDIR"/SHA256SUMS.part
112113
)

contrib/guix/manifest.scm

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,25 @@ chain for " target " development."))
135135
(package-with-extra-patches gcc-8
136136
(search-our-patches "gcc-8-sort-libtool-find-output.patch")))
137137

138+
;; Building glibc with stack smashing protector first landed in glibc 2.25, use
139+
;; this function to disable for older glibcs
140+
;;
141+
;; From glibc 2.25 changelog:
142+
;;
143+
;; * Most of glibc can now be built with the stack smashing protector enabled.
144+
;; It is recommended to build glibc with --enable-stack-protector=strong.
145+
;; Implemented by Nick Alcock (Oracle).
146+
(define (make-glibc-without-ssp xglibc)
147+
(package-with-extra-configure-variable
148+
(package-with-extra-configure-variable
149+
xglibc "libc_cv_ssp" "no")
150+
"libc_cv_ssp_strong" "no"))
151+
138152
(define* (make-bitcoin-cross-toolchain target
139153
#:key
140154
(base-gcc-for-libc gcc-7)
141155
(base-kernel-headers linux-libre-headers-5.4)
142-
(base-libc glibc) ; glibc 2.31
156+
(base-libc (make-glibc-without-ssp glibc-2.24))
143157
(base-gcc (make-gcc-rpath-link base-gcc)))
144158
"Convenience wrapper around MAKE-CROSS-TOOLCHAIN with default values
145159
desirable for building Bitcoin Core release binaries."
@@ -557,6 +571,28 @@ and endian independent.")
557571
inspecting signatures in Mach-O binaries.")
558572
(license license:expat))))
559573

574+
(define-public glibc-2.24
575+
(package
576+
(inherit glibc)
577+
(version "2.24")
578+
(source (origin
579+
(method git-fetch)
580+
(uri (git-reference
581+
(url "https://sourceware.org/git/glibc.git")
582+
(commit "0d7f1ed30969886c8dde62fbf7d2c79967d4bace")))
583+
(file-name (git-file-name "glibc" "0d7f1ed30969886c8dde62fbf7d2c79967d4bace"))
584+
(sha256
585+
(base32
586+
"0g5hryia5v1k0qx97qffgwzrz4lr4jw3s5kj04yllhswsxyjbic3"))
587+
(patches (search-our-patches "glibc-ldd-x86_64.patch"
588+
"glibc-versioned-locpath.patch"
589+
"glibc-2.24-elfm-loadaddr-dynamic-rewrite.patch"
590+
"glibc-2.24-no-build-time-cxx-header-run.patch"))))))
591+
592+
(define glibc-2.27/bitcoin-patched
593+
(package-with-extra-patches glibc-2.27
594+
(search-our-patches "glibc-2.27-riscv64-Use-__has_include__-to-include-asm-syscalls.h.patch")))
595+
560596
(packages->manifest
561597
(append
562598
(list ;; The Basics
@@ -606,7 +642,10 @@ inspecting signatures in Mach-O binaries.")
606642
(make-nsis-with-sde-support nsis-x86_64)
607643
osslsigncode))
608644
((string-contains target "-linux-")
609-
(list (make-bitcoin-cross-toolchain target)))
645+
(list (cond ((string-contains target "riscv64-")
646+
(make-bitcoin-cross-toolchain target #:base-libc glibc-2.27/bitcoin-patched))
647+
(else
648+
(make-bitcoin-cross-toolchain target)))))
610649
((string-contains target "darwin")
611650
(list clang-toolchain-10 binutils imagemagick libtiff librsvg font-tuffy cmake xorriso python-signapple))
612651
(else '())))))
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
commit 6b02af31e9a721bb15a11380cd22d53b621711f8
2+
Author: Szabolcs Nagy <[email protected]>
3+
Date: Wed Oct 18 17:26:23 2017 +0100
4+
5+
[AARCH64] Rewrite elf_machine_load_address using _DYNAMIC symbol
6+
7+
This patch rewrites aarch64 elf_machine_load_address to use special _DYNAMIC
8+
symbol instead of _dl_start.
9+
10+
The static address of _DYNAMIC symbol is stored in the first GOT entry.
11+
Here is the change which makes this solution work (part of binutils 2.24):
12+
https://sourceware.org/ml/binutils/2013-06/msg00248.html
13+
14+
i386, x86_64 targets use the same method to do this as well.
15+
16+
The original implementation relies on a trick that R_AARCH64_ABS32 relocation
17+
being resolved at link time and the static address fits in the 32bits.
18+
However, in LP64, normally, the address is defined to be 64 bit.
19+
20+
Here is the C version one which should be portable in all cases.
21+
22+
* sysdeps/aarch64/dl-machine.h (elf_machine_load_address): Use
23+
_DYNAMIC symbol to calculate load address.
24+
25+
diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h
26+
index e86d8b5b63..5a5b8a5de5 100644
27+
--- a/sysdeps/aarch64/dl-machine.h
28+
+++ b/sysdeps/aarch64/dl-machine.h
29+
@@ -49,26 +49,11 @@ elf_machine_load_address (void)
30+
/* To figure out the load address we use the definition that for any symbol:
31+
dynamic_addr(symbol) = static_addr(symbol) + load_addr
32+
33+
- The choice of symbol is arbitrary. The static address we obtain
34+
- by constructing a non GOT reference to the symbol, the dynamic
35+
- address of the symbol we compute using adrp/add to compute the
36+
- symbol's address relative to the PC.
37+
- This depends on 32bit relocations being resolved at link time
38+
- and that the static address fits in the 32bits. */
39+
-
40+
- ElfW(Addr) static_addr;
41+
- ElfW(Addr) dynamic_addr;
42+
-
43+
- asm (" \n"
44+
-" adrp %1, _dl_start; \n"
45+
-" add %1, %1, #:lo12:_dl_start \n"
46+
-" ldr %w0, 1f \n"
47+
-" b 2f \n"
48+
-"1: \n"
49+
-" .word _dl_start \n"
50+
-"2: \n"
51+
- : "=r" (static_addr), "=r" (dynamic_addr));
52+
- return dynamic_addr - static_addr;
53+
+ _DYNAMIC sysmbol is used here as its link-time address stored in
54+
+ the special unrelocated first GOT entry. */
55+
+
56+
+ extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
57+
+ return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
58+
}
59+
60+
/* Set up the loaded object described by L so its unrelocated PLT
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
commit dc23a45db566095e83ff0b7a57afc87fb5ca89a1
2+
Author: Florian Weimer <[email protected]>
3+
Date: Wed Sep 21 10:45:32 2016 +0200
4+
5+
Avoid running $(CXX) during build to obtain header file paths
6+
7+
This reduces the build time somewhat and is particularly noticeable
8+
during rebuilds with few code changes.
9+
10+
diff --git a/Makerules b/Makerules
11+
index 7e4077ee50..c338850de5 100644
12+
--- a/Makerules
13+
+++ b/Makerules
14+
@@ -121,14 +121,10 @@ ifneq (,$(CXX))
15+
# will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
16+
before-compile := $(common-objpfx)cstdlib $(common-objpfx)cmath \
17+
$(before-compile)
18+
-cstdlib=$(shell echo "\#include <cstdlib>" | $(CXX) -M -MP -x c++ - \
19+
- | sed -n "/cstdlib:/{s/:$$//;p}")
20+
-$(common-objpfx)cstdlib: $(cstdlib)
21+
+$(common-objpfx)cstdlib: $(c++-cstdlib-header)
22+
$(INSTALL_DATA) $< $@T
23+
$(move-if-change) $@T $@
24+
-cmath=$(shell echo "\#include <cmath>" | $(CXX) -M -MP -x c++ - \
25+
- | sed -n "/cmath:/{s/:$$//;p}")
26+
-$(common-objpfx)cmath: $(cmath)
27+
+$(common-objpfx)cmath: $(c++-cmath-header)
28+
$(INSTALL_DATA) $< $@T
29+
$(move-if-change) $@T $@
30+
endif
31+
diff --git a/config.make.in b/config.make.in
32+
index 95c6f36876..04a8b3ed7f 100644
33+
--- a/config.make.in
34+
+++ b/config.make.in
35+
@@ -45,6 +45,8 @@ defines = @DEFINES@
36+
sysheaders = @sysheaders@
37+
sysincludes = @SYSINCLUDES@
38+
c++-sysincludes = @CXX_SYSINCLUDES@
39+
+c++-cstdlib-header = @CXX_CSTDLIB_HEADER@
40+
+c++-cmath-header = @CXX_CMATH_HEADER@
41+
all-warnings = @all_warnings@
42+
enable-werror = @enable_werror@
43+
44+
diff --git a/configure b/configure
45+
index 17625e1041..6ff252744b 100755
46+
--- a/configure
47+
+++ b/configure
48+
@@ -635,6 +635,8 @@ BISON
49+
INSTALL_INFO
50+
PERL
51+
BASH_SHELL
52+
+CXX_CMATH_HEADER
53+
+CXX_CSTDLIB_HEADER
54+
CXX_SYSINCLUDES
55+
SYSINCLUDES
56+
AUTOCONF
57+
@@ -5054,6 +5056,18 @@ fi
58+
59+
60+
61+
+# Obtain some C++ header file paths. This is used to make a local
62+
+# copy of those headers in Makerules.
63+
+if test -n "$CXX"; then
64+
+ find_cxx_header () {
65+
+ echo "#include <$1>" | $CXX -M -MP -x c++ - | sed -n "/$1:/{s/:\$//;p}"
66+
+ }
67+
+ CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
68+
+ CXX_CMATH_HEADER="$(find_cxx_header cmath)"
69+
+fi
70+
+
71+
+
72+
+
73+
# Test if LD_LIBRARY_PATH contains the notation for the current directory
74+
# since this would lead to problems installing/building glibc.
75+
# LD_LIBRARY_PATH contains the current directory if one of the following
76+
diff --git a/configure.ac b/configure.ac
77+
index 33bcd62180..9938ab0dc2 100644
78+
--- a/configure.ac
79+
+++ b/configure.ac
80+
@@ -1039,6 +1039,18 @@ fi
81+
AC_SUBST(SYSINCLUDES)
82+
AC_SUBST(CXX_SYSINCLUDES)
83+
84+
+# Obtain some C++ header file paths. This is used to make a local
85+
+# copy of those headers in Makerules.
86+
+if test -n "$CXX"; then
87+
+ find_cxx_header () {
88+
+ echo "#include <$1>" | $CXX -M -MP -x c++ - | sed -n "/$1:/{s/:\$//;p}"
89+
+ }
90+
+ CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
91+
+ CXX_CMATH_HEADER="$(find_cxx_header cmath)"
92+
+fi
93+
+AC_SUBST(CXX_CSTDLIB_HEADER)
94+
+AC_SUBST(CXX_CMATH_HEADER)
95+
+
96+
# Test if LD_LIBRARY_PATH contains the notation for the current directory
97+
# since this would lead to problems installing/building glibc.
98+
# LD_LIBRARY_PATH contains the current directory if one of the following
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From 562c52cc81a4e456a62e6455feb32732049e9070 Mon Sep 17 00:00:00 2001
2+
From: "H.J. Lu" <[email protected]>
3+
Date: Mon, 31 Dec 2018 09:26:42 -0800
4+
Subject: [PATCH] riscv: Use __has_include__ to include <asm/syscalls.h> [BZ
5+
#24022]
6+
7+
<asm/syscalls.h> has been removed by
8+
9+
commit 27f8899d6002e11a6e2d995e29b8deab5aa9cc25
10+
Author: David Abdurachmanov <[email protected]>
11+
Date: Thu Nov 8 20:02:39 2018 +0100
12+
13+
riscv: add asm/unistd.h UAPI header
14+
15+
Marcin Juszkiewicz reported issues while generating syscall table for riscv
16+
using 4.20-rc1. The patch refactors our unistd.h files to match some other
17+
architectures.
18+
19+
- Add asm/unistd.h UAPI header, which has __ARCH_WANT_NEW_STAT only for 64-bit
20+
- Remove asm/syscalls.h UAPI header and merge to asm/unistd.h
21+
- Adjust kernel asm/unistd.h
22+
23+
So now asm/unistd.h UAPI header should show all syscalls for riscv.
24+
25+
<asm/syscalls.h> may be restored by
26+
27+
Subject: [PATCH] riscv: restore asm/syscalls.h UAPI header
28+
Date: Tue, 11 Dec 2018 09:09:35 +0100
29+
30+
UAPI header asm/syscalls.h was merged into UAPI asm/unistd.h header,
31+
which did resolve issue with missing syscalls macros resulting in
32+
glibc (2.28) build failure. It also broke glibc in a different way:
33+
asm/syscalls.h is being used by glibc. I noticed this while doing
34+
Fedora 30/Rawhide mass rebuild.
35+
36+
The patch returns asm/syscalls.h header and incl. it into asm/unistd.h.
37+
I plan to send a patch to glibc to use asm/unistd.h instead of
38+
asm/syscalls.h
39+
40+
In the meantime, we use __has_include__, which was added to GCC 5, to
41+
check if <asm/syscalls.h> exists before including it. Tested with
42+
build-many-glibcs.py for riscv against kernel 4.19.12 and 4.20-rc7.
43+
44+
[BZ #24022]
45+
* sysdeps/unix/sysv/linux/riscv/flush-icache.c: Check if
46+
<asm/syscalls.h> exists with __has_include__ before including it.
47+
---
48+
sysdeps/unix/sysv/linux/riscv/flush-icache.c | 6 +++++-
49+
1 file changed, 5 insertions(+), 1 deletion(-)
50+
51+
diff --git a/sysdeps/unix/sysv/linux/riscv/flush-icache.c b/sysdeps/unix/sysv/linux/riscv/flush-icache.c
52+
index d612ef4c6c..0b2042620b 100644
53+
--- a/sysdeps/unix/sysv/linux/riscv/flush-icache.c
54+
+++ b/sysdeps/unix/sysv/linux/riscv/flush-icache.c
55+
@@ -21,7 +21,11 @@
56+
#include <stdlib.h>
57+
#include <atomic.h>
58+
#include <sys/cachectl.h>
59+
-#include <asm/syscalls.h>
60+
+#if __has_include__ (<asm/syscalls.h>)
61+
+# include <asm/syscalls.h>
62+
+#else
63+
+# include <asm/unistd.h>
64+
+#endif
65+
66+
typedef int (*func_type) (void *, void *, unsigned long int);
67+
68+
--
69+
2.31.1
70+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
By default, 'RTDLLIST' in 'ldd' refers to 'lib64/ld-linux-x86-64.so', whereas
2+
it's in 'lib/' for us. This patch fixes that.
3+
4+
--- glibc-2.17/sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed 2012-12-25 04:02:13.000000000 +0100
5+
+++ glibc-2.17/sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed 2013-09-15 23:08:03.000000000 +0200
6+
@@ -1,3 +1,3 @@
7+
/LD_TRACE_LOADED_OBJECTS=1/a\
8+
add_env="$add_env LD_LIBRARY_VERSION=\\$verify_out"
9+
-s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|x32\)\(/[^/]*\)\(-x86-64\|-x32\)\(\.so\.[0-9.]*\)[ ]*$_\1"\2\4\6 \264\4-x86-64\6 \2x32\4-x32\6"_
10+
+s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|x32\)\(/[^/]*\)\(-x86-64\|-x32\)\(\.so\.[0-9.]*\)[ ]*$_\1"\2\4\6 \2\4-x86-64\6 \2x32\4-x32\6"_

0 commit comments

Comments
 (0)