Skip to content

Commit 5f9021e

Browse files
committed
unix: disable reallocarray() in musl
musl 1.2.2 introduced reallocarray(), which appears to be used by at least OpenSSL. This poses problems for Linux distributions not running musl 1.2.2, such as Debian Bullseye (and earlier of course). Because we want our Python distributions to be relinkable on as many machines as possible, this commit removes reallocarray() from our musl build. This should hopefully enable Linux distros running an older musl to link our Python distributions. This is related to indygreg/PyOxidizer#392.
1 parent 354b21d commit 5f9021e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

cpython-unix/build-musl.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,44 @@ tar -xf musl-${MUSL_VERSION}.tar.gz
1414

1515
pushd musl-${MUSL_VERSION}
1616

17+
# Debian as of at least bullseye ships musl 1.2.1. musl 1.2.2
18+
# added reallocarray(), which gets used by at least OpenSSL.
19+
# Here, we disable this single function so as to not introduce
20+
# symbol dependencies on clients using an older musl version.
21+
patch -p1 <<EOF
22+
diff --git a/include/stdlib.h b/include/stdlib.h
23+
index b54a051f..194c2033 100644
24+
--- a/include/stdlib.h
25+
+++ b/include/stdlib.h
26+
@@ -145,7 +145,6 @@ int getloadavg(double *, int);
27+
int clearenv(void);
28+
#define WCOREDUMP(s) ((s) & 0x80)
29+
#define WIFCONTINUED(s) ((s) == 0xffff)
30+
-void *reallocarray (void *, size_t, size_t);
31+
#endif
32+
33+
#ifdef _GNU_SOURCE
34+
diff --git a/src/malloc/reallocarray.c b/src/malloc/reallocarray.c
35+
deleted file mode 100644
36+
index 4a6ebe46..00000000
37+
--- a/src/malloc/reallocarray.c
38+
+++ /dev/null
39+
@@ -1,13 +0,0 @@
40+
-#define _BSD_SOURCE
41+
-#include <errno.h>
42+
-#include <stdlib.h>
43+
-
44+
-void *reallocarray(void *ptr, size_t m, size_t n)
45+
-{
46+
- if (n && m > -1 / n) {
47+
- errno = ENOMEM;
48+
- return 0;
49+
- }
50+
-
51+
- return realloc(ptr, m * n);
52+
-}
53+
EOF
54+
1755
./configure \
1856
--prefix=/tools/host \
1957
--disable-shared

0 commit comments

Comments
 (0)