[issue43112] SOABI on Linux does not distinguish between GNU libc and musl libc
Natanael Copa
report at bugs.python.org
Wed Feb 3 04:26:13 EST 2021
New submission from Natanael Copa <ncopa at alpinelinux.org>:
The SOABI does not make any difference between GNU libc and musl libc.
Using official docker images:
# debian build with GNU libc
$ docker run --rm python:slim python -c 'import sysconfig;print(sysconfig.get_config_var("SOABI"))'
cpython-39-x86_64-linux-gnu
# alpine build with musl libc
$ docker run --rm python:alpine python -c 'import sysconfig;print(sysconfig.get_config_var("SOABI"))'
cpython-39-x86_64-linux-gnu
Both ends with `-gnu`, while it would be expected that with musl it would end with `-musl`
This affects the extension suffix:
$ docker run --rm python:slim python-config --extension-suffix
.cpython-39-x86_64-linux-gnu.so
$ docker run --rm python:alpine python-config --extension-suffix
.cpython-39-x86_64-linux-gnu.so
Which again affects the pre-compiled binary wheels, and binary modules built with musl libc gets mixed up with the GNU libc modules due to the -gnu.so suffix.
The source of the problem is that the `configure.ac` file assumes that all defined(__linux__) is -gnu when detecting the PLATFORM_TRIPLET.
```
...
#if defined(__ANDROID__)
# Android is not a multiarch system.
#elif defined(__linux__)
# if defined(__x86_64__) && defined(__LP64__)
x86_64-linux-gnu
# elif defined(__x86_64__) && defined(__ILP32__)
x86_64-linux-gnux32
# elif defined(__i386__)
...
```
So when building python with musl libc the PLATFORM_TRIPLET always sets `*-linux-gnu`.
output from configure run on musl system:
```
...
checking for a sed that does not truncate output... /bin/sed
checking for --with-cxx-main=<compiler>... no
checking for the platform triplet based on compiler characteristics... x86_64-linux-gnu
...
```
A first step in fixing this would be to make sure that we only set -gnu when __GLIBC__ is defined:
```diff
diff --git a/configure.ac b/configure.ac
index 1f5a008388..1b4690c90f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -726,7 +726,7 @@ cat >> conftest.c <<EOF
#undef unix
#if defined(__ANDROID__)
# Android is not a multiarch system.
-#elif defined(__linux__)
+#elif defined(__linux__) && defined (__GLIBC__)
# if defined(__x86_64__) && defined(__LP64__)
x86_64-linux-gnu
```
But that would make build with musl fail with "unknown platform triplet".
Not sure what the proper fix would be, but one way to extract the suffix from `$CPP -dumpmachine`
----------
components: Interpreter Core
messages: 386183
nosy: ncopa
priority: normal
severity: normal
status: open
title: SOABI on Linux does not distinguish between GNU libc and musl libc
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43112>
_______________________________________
More information about the Python-bugs-list
mailing list