-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CPython: WiP patches needed for cross compilation
- Loading branch information
Showing
3 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
https://bugs.python.org/issue21622 | ||
|
||
Based on the patch from Alpine Linux | ||
https://git.alpinelinux.org/aports/tree/main/python2/musl-find_library.patch | ||
|
||
--- a/Lib/ctypes/util.py | ||
+++ b/Lib/ctypes/util.py | ||
@@ -92,6 +92,8 @@ elif sys.platform.startswith("aix"): | ||
elif os.name == "posix": | ||
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump | ||
import re, tempfile | ||
+ from glob import glob | ||
+ musl_ldso = glob('/lib/ld-musl-*.so.1') | ||
|
||
def _is_elf(filename): | ||
"Return True if the given file is an ELF file" | ||
@@ -265,6 +267,57 @@ elif os.name == "posix": | ||
def find_library(name, is64 = False): | ||
return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name)) | ||
|
||
+ elif musl_ldso and os.path.isfile(musl_ldso[0]): | ||
+ | ||
+ def _is_elf(filepath): | ||
+ try: | ||
+ with open(filepath, 'rb') as fh: | ||
+ return fh.read(4) == b'\x7fELF' | ||
+ except: | ||
+ return False | ||
+ | ||
+ def find_library(name): | ||
+ # absolute name? | ||
+ if os.path.isabs(name): | ||
+ if _is_elf(name): | ||
+ return name | ||
+ else: | ||
+ return None | ||
+ | ||
+ # special case for unified standard libs | ||
+ stdlibs = ['libcrypt.so', 'libdl.so', 'libm.so', 'libpthread.so', 'libresolv.so', 'librt.so', 'libutil.so', 'libxnet.so'] | ||
+ if name in stdlibs: | ||
+ name = 'libc.so' | ||
+ elif ('lib' + name + '.so') in stdlibs: | ||
+ name = 'c' | ||
+ | ||
+ paths = [] | ||
+ # read path list from /etc/ld-musl-$(ARCH).path | ||
+ path_list = musl_ldso[0].replace('/lib/', '/etc/').replace('.so.1', '.path') | ||
+ try: | ||
+ with open(path_list, 'r') as fh: | ||
+ paths = [path for line in fh for path in line.rstrip('\n').split(':') if path] | ||
+ except: | ||
+ paths = [] | ||
+ # default path list if /etc/ld-musl-$(ARCH).path is empty or does not exist | ||
+ if not paths: | ||
+ paths = ['/lib', '/usr/local/lib', '/usr/lib'] | ||
+ | ||
+ # prepend paths from LD_LIBRARY_PATH | ||
+ if 'LD_LIBRARY_PATH' in os.environ: | ||
+ paths = os.environ['LD_LIBRARY_PATH'].split(':') + paths | ||
+ | ||
+ for d in paths: | ||
+ f = os.path.join(d, name) | ||
+ if _is_elf(f): | ||
+ return os.path.basename(f) | ||
+ | ||
+ prefix = os.path.join(d, 'lib'+name) | ||
+ for suffix in ['.so', '.so.*']: | ||
+ for f in glob('{0}{1}'.format(prefix, suffix)): | ||
+ if _is_elf(f): | ||
+ return os.path.basename(f) | ||
+ | ||
else: | ||
|
||
def _findSoname_ldconfig(name): |
75 changes: 75 additions & 0 deletions
75
patches/python-3.9.2/030-bpo-43112-detect-musl-as-a-separate-SOABI-GH-24502.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
From 3f79de7b8411c76a1fcd1ca850ea62500be7a881 Mon Sep 17 00:00:00 2001 | ||
From: Natanael Copa <ncopa@alpinelinux.org> | ||
Date: Sat, 29 Jan 2022 00:02:54 +0100 | ||
Subject: [PATCH 1/2] bpo-43112: detect musl as a separate SOABI (GH-24502) | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
musl libc and gnu libc are not ABI compatible so we need set different | ||
SOABI for musl and not simply assume that all linux is linux-gnu. | ||
|
||
Replace linux-gnu with the detected os for the build from config.guess | ||
for linux-musl*. | ||
|
||
(cherry picked from commit 1f036ede59e2c4befc07714cf76603c591d5c972) | ||
Signed-off-by: Šimon Bořek <simon.borek@nic.cz> | ||
--- | ||
Lib/test/test_sysconfig.py | 8 ++++---- | ||
.../next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst | 1 + | ||
configure | 5 +++++ | ||
configure.ac | 5 +++++ | ||
4 files changed, 15 insertions(+), 4 deletions(-) | ||
create mode 100644 Misc/NEWS.d/next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst | ||
|
||
--- a/Lib/test/test_sysconfig.py | ||
+++ b/Lib/test/test_sysconfig.py | ||
@@ -425,11 +425,11 @@ class TestSysConfig(unittest.TestCase): | ||
self.assertTrue('linux' in suffix, suffix) | ||
if re.match('(i[3-6]86|x86_64)$', machine): | ||
if ctypes.sizeof(ctypes.c_char_p()) == 4: | ||
- self.assertTrue(suffix.endswith('i386-linux-gnu.so') or | ||
- suffix.endswith('x86_64-linux-gnux32.so'), | ||
- suffix) | ||
+ expected_suffixes = 'i386-linux-gnu.so', 'x86_64-linux-gnux32.so', 'i386-linux-musl.so' | ||
else: # 8 byte pointer size | ||
- self.assertTrue(suffix.endswith('x86_64-linux-gnu.so'), suffix) | ||
+ expected_suffixes = 'x86_64-linux-gnu.so', 'x86_64-linux-musl.so' | ||
+ self.assertTrue(suffix.endswith(expected_suffixes), | ||
+ f'unexpected suffix {suffix!r}') | ||
|
||
@unittest.skipUnless(sys.platform == 'darwin', 'OS X-specific test') | ||
def test_osx_ext_suffix(self): | ||
--- /dev/null | ||
+++ b/Misc/NEWS.d/next/Build/2021-02-10-17-54-04.bpo-43112.H5Lat6.rst | ||
@@ -0,0 +1 @@ | ||
+Detect musl libc as a separate SOABI (tagged as ``linux-musl``). | ||
\ No newline at end of file | ||
--- a/configure | ||
+++ b/configure | ||
@@ -5376,6 +5376,11 @@ EOF | ||
|
||
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then | ||
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '` | ||
+ case "$build_os" in | ||
+ linux-musl*) | ||
+ PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'` | ||
+ ;; | ||
+ esac | ||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PLATFORM_TRIPLET" >&5 | ||
$as_echo "$PLATFORM_TRIPLET" >&6; } | ||
else | ||
--- a/configure.ac | ||
+++ b/configure.ac | ||
@@ -866,6 +866,11 @@ EOF | ||
|
||
if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then | ||
PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '` | ||
+ case "$build_os" in | ||
+ linux-musl*) | ||
+ PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'` | ||
+ ;; | ||
+ esac | ||
AC_MSG_RESULT([$PLATFORM_TRIPLET]) | ||
else | ||
AC_MSG_RESULT([none]) |