Skip to content

Commit 4e582f0

Browse files
autobakteriepali
authored andcommitted
python3: backport and fix target musl libc detection
Patch 030: Backported from Python main branch[^1] for Python to distinguish between glibc and musl libc SOABI. Patch 131: Changes PLATFORM_TRIPLET -gnu/-musl suffix detection (performed by the backported patch) to be based on the target OS instead of the building OS. See included patches for more detailed descriptions. Specifically this fixes cross-compilation for mpc8548 CPUs with SPE instructions[^2] enabled. [^1]: merged to python:main as python/cpython#24502 'bpo-43112: detect musl as a separate SOABI' [^2]: https://www.nxp.com/docs/en/reference-manual/SPEPEM.pdf Co-authored-by: Pali Rohár <[email protected]> Signed-off-by: Šimon Bořek <[email protected]>
1 parent 45bedba commit 4e582f0

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
From 3f79de7b8411c76a1fcd1ca850ea62500be7a881 Mon Sep 17 00:00:00 2001
2+
From: Natanael Copa <[email protected]>
3+
Date: Sat, 29 Jan 2022 00:02:54 +0100
4+
Subject: [PATCH 1/2] bpo-43112: detect musl as a separate SOABI (GH-24502)
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
9+
musl libc and gnu libc are not ABI compatible so we need set different
10+
SOABI for musl and not simply assume that all linux is linux-gnu.
11+
12+
Replace linux-gnu with the detected os for the build from config.guess
13+
for linux-musl*.
14+
15+
(cherry picked from commit 1f036ede59e2c4befc07714cf76603c591d5c972)
16+
Signed-off-by: Šimon Bořek <[email protected]>
17+
---
18+
Lib/test/test_sysconfig.py | 8 ++++----
19+
.../next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst | 1 +
20+
configure | 5 +++++
21+
configure.ac | 5 +++++
22+
4 files changed, 15 insertions(+), 4 deletions(-)
23+
create mode 100644 Misc/NEWS.d/next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst
24+
25+
--- a/Lib/test/test_sysconfig.py
26+
+++ b/Lib/test/test_sysconfig.py
27+
@@ -425,11 +425,11 @@ class TestSysConfig(unittest.TestCase):
28+
self.assertTrue('linux' in suffix, suffix)
29+
if re.match('(i[3-6]86|x86_64)$', machine):
30+
if ctypes.sizeof(ctypes.c_char_p()) == 4:
31+
- self.assertTrue(suffix.endswith('i386-linux-gnu.so') or
32+
- suffix.endswith('x86_64-linux-gnux32.so'),
33+
- suffix)
34+
+ expected_suffixes = 'i386-linux-gnu.so', 'x86_64-linux-gnux32.so', 'i386-linux-musl.so'
35+
else: # 8 byte pointer size
36+
- self.assertTrue(suffix.endswith('x86_64-linux-gnu.so'), suffix)
37+
+ expected_suffixes = 'x86_64-linux-gnu.so', 'x86_64-linux-musl.so'
38+
+ self.assertTrue(suffix.endswith(expected_suffixes),
39+
+ f'unexpected suffix {suffix!r}')
40+
41+
@unittest.skipUnless(sys.platform == 'darwin', 'OS X-specific test')
42+
def test_osx_ext_suffix(self):
43+
--- /dev/null
44+
+++ b/Misc/NEWS.d/next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst
45+
@@ -0,0 +1 @@
46+
+Detect musl libc as a separate SOABI (tagged as ``linux-musl``).
47+
\ No newline at end of file
48+
--- a/configure
49+
+++ b/configure
50+
@@ -5376,6 +5376,11 @@ EOF
51+
52+
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
53+
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
54+
+ case "$build_os" in
55+
+ linux-musl*)
56+
+ PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
57+
+ ;;
58+
+ esac
59+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PLATFORM_TRIPLET" >&5
60+
$as_echo "$PLATFORM_TRIPLET" >&6; }
61+
else
62+
--- a/configure.ac
63+
+++ b/configure.ac
64+
@@ -866,6 +866,11 @@ EOF
65+
66+
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
67+
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
68+
+ case "$build_os" in
69+
+ linux-musl*)
70+
+ PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
71+
+ ;;
72+
+ esac
73+
AC_MSG_RESULT([$PLATFORM_TRIPLET])
74+
else
75+
AC_MSG_RESULT([none])
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 15d512cc35106392ed7583d0e000d9a1b865f1e1 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?=C5=A0imon=20Bo=C5=99ek?= <[email protected]>
3+
Date: Mon, 27 Jun 2022 13:53:37 +0200
4+
Subject: [PATCH 2/2] configure.ac: switch PLATFORM_TRIPLET suffix to '-musl'
5+
based on `host_os` instead of `build_os`
6+
7+
As `build_os` and `host_os` are results of autoconf's `AC_CANONICAL_BUILD`
8+
and `AC_CANONICAL_HOST` macros[^1], the former refers to the system running the build
9+
and the latter to the system that will run the compiled program.
10+
11+
`PLATFORM_TRIPLET` should refer to the target platform when cross-compiling.
12+
Its libc related part should be therefore derived from the target platform as well
13+
- which is currently not the case - `PLATFORM_TRIPLET` '-gnu' suffix is/isn't switched to '-musl'
14+
based on `build-os` rather than `host-os` which leads to error message[^2]
15+
and build failure when compiling Python on glibc system for musl target.
16+
17+
[^1]: https://www.gnu.org/software/autoconf/manual/autoconf-2.68/html_node/Canonicalizing.html ,
18+
https://www.gnu.org/software/autoconf/manual/autoconf-2.68/html_node/Specifying-Target-Triplets.html
19+
[^2]: "internal configure error for the platform triplet, please file a bug report"
20+
21+
Co-authored-by: Pali Rohár <[email protected]>
22+
Signed-off-by: Šimon Bořek <[email protected]>
23+
---
24+
configure | 2 +-
25+
configure.ac | 2 +-
26+
2 files changed, 2 insertions(+), 2 deletions(-)
27+
28+
--- a/configure
29+
+++ b/configure
30+
@@ -5376,7 +5376,7 @@ EOF
31+
32+
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
33+
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
34+
- case "$build_os" in
35+
+ case "$host_os" in
36+
linux-musl*)
37+
PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
38+
;;
39+
--- a/configure.ac
40+
+++ b/configure.ac
41+
@@ -866,7 +866,7 @@ EOF
42+
43+
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
44+
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
45+
- case "$build_os" in
46+
+ case "$host_os" in
47+
linux-musl*)
48+
PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
49+
;;

0 commit comments

Comments
 (0)