Skip to content

Commit bc4735f

Browse files
authored
Merge pull request #239 from infosiftr/i386
Fix i386 musl builds (broken by Alpine 3.23)
2 parents 6b907b1 + 32603b7 commit bc4735f

20 files changed

+185
-16
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
name: Generate Jobs
3535
run: |
3636
strategy="$(GENERATE_STACKBREW_LIBRARY='.github/workflows/fake-gsl.sh' "$BASHBREW_SCRIPTS/github-actions/generate.sh")"
37+
strategy="$("$BASHBREW_SCRIPTS/github-actions/munge-i386.sh" -c <<<"$strategy")"
3738
strategy="$(.github/workflows/munge-build.sh -c <<<"$strategy")"
3839
3940
EOF="EOF-$RANDOM-$RANDOM-$RANDOM"
@@ -47,7 +48,7 @@ jobs:
4748
name: ${{ matrix.name }}
4849
runs-on: ${{ matrix.os }}
4950
env:
50-
BASHBREW_ARCH: amd64 # TODO consider using "$BASHBREW_SCRIPTS/bashbrew-host-arch.sh" ? (would make it harder to force i386 in our matrix too, so explicit is probably better)
51+
BASHBREW_ARCH: ${{ matrix.BASHBREW_ARCH }}
5152
steps:
5253
- uses: actions/checkout@v4
5354
- uses: docker-library/bashbrew@HEAD # build.sh needs bashbrew

.github/workflows/munge-build.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ set -Eeuo pipefail
33

44
jq '
55
.matrix.include |= map(
6-
.runs.build = (
6+
(.name | contains("i386")) as $i386
7+
| if $i386 and (.name | contains("uclibc")) then empty else . end # uclibc builds are heavy; do not test i386/uclibc on GHA
8+
| .BASHBREW_ARCH = (if $i386 then "i386" else "amd64" end)
9+
| .runs.build = (
710
[
811
"dir=" + (.meta.entries[].directory | @sh),
912
"rm -rf \"$dir/$BASHBREW_ARCH\"", # make sure our OCI directory is clean so we can "git diff --exit-code" later
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Description: fix "read-only segment has dynamic relocations" on musl + i386 (1.36-specific patch)
2+
Bug-Gentoo: https://bugs.gentoo.org/933771
3+
Origin: https://git.alpinelinux.org/aports/tree/main/busybox/0023-Hackfix-to-disable-HW-acceleration-for-MD5-SHA1-on-x.patch?id=bfc5ced82296a4bd72e9dde34449b066682bd353
4+
Origin-GitLab: https://gitlab.alpinelinux.org/alpine/aports/-/blob/bfc5ced82296a4bd72e9dde34449b066682bd353/main/busybox/0023-Hackfix-to-disable-HW-acceleration-for-MD5-SHA1-on-x.patch
5+
6+
From 11e8f6d75aa73cfab17345f42678d4df3c2a4053 Mon Sep 17 00:00:00 2001
7+
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
8+
Date: Thu, 5 Jan 2023 15:47:55 +0100
9+
Subject: [PATCH] Hackfix to disable HW acceleration for MD5/SHA1 on x86
10+
MIME-Version: 1.0
11+
Content-Type: text/plain; charset=UTF-8
12+
Content-Transfer-Encoding: 8bit
13+
14+
This causes a direct segfault with musl libc.
15+
16+
See: http://lists.busybox.net/pipermail/busybox/2023-January/090078.html
17+
---
18+
libbb/hash_md5_sha.c | 6 +++---
19+
1 file changed, 3 insertions(+), 3 deletions(-)
20+
21+
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
22+
index 57a801459..96e9731c4 100644
23+
--- a/libbb/hash_md5_sha.c
24+
+++ b/libbb/hash_md5_sha.c
25+
@@ -14,7 +14,7 @@
26+
#define NEED_SHA512 (ENABLE_SHA512SUM || ENABLE_USE_BB_CRYPT_SHA)
27+
28+
#if ENABLE_SHA1_HWACCEL || ENABLE_SHA256_HWACCEL
29+
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
30+
+# if defined(__GNUC__) && defined(__x86_64__)
31+
static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
32+
{
33+
asm ("cpuid"
34+
@@ -1191,7 +1191,7 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
35+
ctx->total64 = 0;
36+
ctx->process_block = sha1_process_block64;
37+
#if ENABLE_SHA1_HWACCEL
38+
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
39+
+# if defined(__GNUC__) && defined(__x86_64__)
40+
{
41+
int ni = shaNI;
42+
if (!ni)
43+
@@ -1243,7 +1243,7 @@ void FAST_FUNC sha256_begin(sha256_ctx_t *ctx)
44+
/*ctx->total64 = 0; - done by prepending two 32-bit zeros to init256 */
45+
ctx->process_block = sha256_process_block64;
46+
#if ENABLE_SHA256_HWACCEL
47+
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
48+
+# if defined(__GNUC__) && defined(__x86_64__)
49+
{
50+
int ni = shaNI;
51+
if (!ni)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Description: fix "read-only segment has dynamic relocations" on musl + i386
2+
Bug-Gentoo: https://bugs.gentoo.org/933771
3+
Origin: https://git.alpinelinux.org/aports/tree/main/busybox/0023-Hackfix-to-disable-HW-acceleration-for-MD5-SHA1-on-x.patch?id=bfc5ced82296a4bd72e9dde34449b066682bd353
4+
Origin-GitLab: https://gitlab.alpinelinux.org/alpine/aports/-/blob/bfc5ced82296a4bd72e9dde34449b066682bd353/main/busybox/0023-Hackfix-to-disable-HW-acceleration-for-MD5-SHA1-on-x.patch
5+
6+
From 11e8f6d75aa73cfab17345f42678d4df3c2a4053 Mon Sep 17 00:00:00 2001
7+
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
8+
Date: Thu, 5 Jan 2023 15:47:55 +0100
9+
Subject: [PATCH] Hackfix to disable HW acceleration for MD5/SHA1 on x86
10+
MIME-Version: 1.0
11+
Content-Type: text/plain; charset=UTF-8
12+
Content-Transfer-Encoding: 8bit
13+
14+
This causes a direct segfault with musl libc.
15+
16+
See: http://lists.busybox.net/pipermail/busybox/2023-January/090078.html
17+
---
18+
libbb/hash_md5_sha.c | 6 +++---
19+
1 file changed, 3 insertions(+), 3 deletions(-)
20+
21+
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
22+
index 57a801459..96e9731c4 100644
23+
--- a/libbb/hash_md5_sha.c
24+
+++ b/libbb/hash_md5_sha.c
25+
@@ -14,7 +14,7 @@
26+
#define NEED_SHA512 (ENABLE_SHA512SUM || ENABLE_USE_BB_CRYPT_SHA)
27+
28+
#if ENABLE_SHA1_HWACCEL || ENABLE_SHA256_HWACCEL
29+
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
30+
+# if defined(__GNUC__) && defined(__x86_64__)
31+
static void cpuid_eax_ebx_ecx(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
32+
{
33+
asm ("cpuid"
34+
@@ -1191,7 +1191,7 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
35+
ctx->total64 = 0;
36+
ctx->process_block = sha1_process_block64;
37+
#if ENABLE_SHA1_HWACCEL
38+
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
39+
+# if defined(__GNUC__) && defined(__x86_64__)
40+
{
41+
int ni = shaNI;
42+
if (!ni)
43+
@@ -1243,7 +1243,7 @@ void FAST_FUNC sha256_begin(sha256_ctx_t *ctx)
44+
/*ctx->total64 = 0; - done by prepending two 32-bit zeros to init256 */
45+
ctx->process_block = sha256_process_block64;
46+
#if ENABLE_SHA256_HWACCEL
47+
-# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
48+
+# if defined(__GNUC__) && defined(__x86_64__)
49+
{
50+
int ni = shaNI;
51+
if (!ni)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Description: libbb/sha: add missing sha-NI guard (musl version)
2+
Author: André Przywara <andre.przywara@arm.com>; Tianon Gravi <tianon@debian.org>
3+
Date: Tue, 10 Sep 2024 06:33:00 -0700; Fri, 05 Dec 2025 15:22:58 -0800
4+
Origin: http://lists.busybox.net/pipermail/busybox/2024-September/090899.html
5+
6+
See "hackfix-to-disable-HW-acceleration-for-MD5-SHA1-on-x86.patch" for the reason Tianon had to change this specifically for musl (x86/i386 exclusion).
7+
8+
The ENABLE_SHA1_HWACCEL Kconfig symbol is meant to be archicture
9+
agnostic, so can be enabled regardless of whether your build
10+
architecture provides hardware acceleration or not. At the moment only
11+
x86 implements this, so every piece of optimised code should be guarded
12+
by both ENABLE_SHA1_HWACCEL and (__x86_64__ || __i386__). This is missing
13+
at one place, so compiling for arm64 breaks when ENABLE_SHA1_HWACCEL is
14+
enabled:
15+
================================
16+
libbb/hash_md5_sha.c: In function ‘sha1_end’:
17+
libbb/hash_md5_sha.c:1316:28: error: ‘sha1_process_block64_shaNI’ undeclared (first use in this function); did you mean ‘sha1_process_block64’?
18+
1316 | || ctx->process_block == sha1_process_block64_shaNI
19+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
20+
| sha1_process_block64
21+
libbb/hash_md5_sha.c:1316:28: note: each undeclared identifier is reported only once for each function it appears in
22+
make[1]: *** [scripts/Makefile.build:197: libbb/hash_md5_sha.o] Error 1
23+
make: *** [Makefile:744: libbb] Error 2
24+
================================
25+
26+
Add the missing guards around the call to sha1_process_block64_shaNI to
27+
fix the build on other architectures with ENABLE_SHA1_HWACCEL enabled.
28+
29+
Change-Id: I40bba388422625f4230abf15a5de23e1fdc654fc
30+
Signed-off-by: André Przywara <andre.przywara@arm.com>
31+
---
32+
libbb/hash_md5_sha.c | 2 ++
33+
1 file changed, 2 insertions(+)
34+
35+
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
36+
index 57a801459..75a61c32c 100644
37+
--- a/libbb/hash_md5_sha.c
38+
+++ b/libbb/hash_md5_sha.c
39+
@@ -1313,7 +1313,9 @@ unsigned FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf)
40+
hash_size = 8;
41+
if (ctx->process_block == sha1_process_block64
42+
#if ENABLE_SHA1_HWACCEL
43+
+# if defined(__GNUC__) && defined(__x86_64__)
44+
|| ctx->process_block == sha1_process_block64_shaNI
45+
+# endif
46+
#endif
47+
) {
48+
hash_size = 5;
49+
--
50+
2.25.1

Dockerfile-builder.template

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,19 @@ WORKDIR /usr/src/busybox
265265
(
266266
[
267267
"no-cbq.patch",
268+
if env.variant == "musl" then
269+
if .version | startswith("1.36.") then
270+
"hackfix-to-disable-HW-acceleration-for-MD5-SHA1-on-x86-1.36.patch"
271+
else
272+
"hackfix-to-disable-HW-acceleration-for-MD5-SHA1-on-x86.patch"
273+
end
274+
else empty end,
268275
if .version | startswith("1.36.") then empty else
269-
"sha1_process_block64_shaNI.patch"
276+
if env.variant == "musl" then
277+
"sha1_process_block64_shaNI-musl.patch"
278+
else
279+
"sha1_process_block64_shaNI.patch"
280+
end
270281
end,
271282
empty # trailing comma
272283
]

latest-1/musl/Dockerfile.builder

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

latest-1/musl/i386/blobs/sha256/4610d1977fb623dd2d7e4e38e3be6a6bee6d620127efa5a8769a6ffe86c24a1a renamed to latest-1/musl/i386/blobs/sha256/50d90be1c956225a90830e293ec46091159f80070822f2c1cd88ecbcb0a07e2c

File renamed without changes.

latest-1/musl/i386/blobs/sha256/03f4959ecf03177e7ba16988af905ca243c73405d88ee20d61899fb4c344c139 renamed to latest-1/musl/i386/blobs/sha256/7b1b3b5b5a7b3e4413f4365182d8a5b6c84edb7e738201f0e4934a9deb72cb94

File renamed without changes.

latest-1/musl/i386/blobs/sha256/b162ea3532cb9897f657a76e3e6f98d81a90fd0cc5a17e90ff883683266963b7 renamed to latest-1/musl/i386/blobs/sha256/bbf830b8590e5198fb60300a924b646c4df4399b90408859d3e4bf5008eb48eb

File renamed without changes.

0 commit comments

Comments
 (0)