Skip to content

Commit d36c9a8

Browse files
miss-islingtoncdce8pAA-Turner
authored
[3.14] gh-90548: Fix musl version detection with --strip-all (GH-137864) (#138348)
Co-authored-by: Marc Mueller <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent 096fa04 commit d36c9a8

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Lib/platform.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
194194
| (GLIBC_([0-9.]+))
195195
| (libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)
196196
| (musl-([0-9.]+))
197+
| (libc.musl(?:-\w+)?.so(?:\.(\d[0-9.]*))?)
197198
""",
198199
re.ASCII | re.VERBOSE)
199200

@@ -219,9 +220,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
219220
continue
220221
if not m:
221222
break
222-
libcinit, glibc, glibcversion, so, threads, soversion, musl, muslversion = [
223-
s.decode('latin1') if s is not None else s
224-
for s in m.groups()]
223+
decoded_groups = [s.decode('latin1') if s is not None else s
224+
for s in m.groups()]
225+
(libcinit, glibc, glibcversion, so, threads, soversion,
226+
musl, muslversion, musl_so, musl_sover) = decoded_groups
225227
if libcinit and not lib:
226228
lib = 'libc'
227229
elif glibc:
@@ -241,6 +243,10 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
241243
lib = 'musl'
242244
if not ver or V(muslversion) > V(ver):
243245
ver = muslversion
246+
elif musl_so:
247+
lib = 'musl'
248+
if musl_sover and (not ver or V(musl_sover) > V(ver)):
249+
ver = musl_sover
244250
pos = m.end()
245251
return lib, version if ver is None else ver
246252

Lib/test/test_platform.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ def test_libc_ver(self):
558558
# musl uses semver, but we accept some variations anyway:
559559
(b'/aports/main/musl/src/musl-12.5', ('musl', '12.5')),
560560
(b'/aports/main/musl/src/musl-1.2.5.7', ('musl', '1.2.5.7')),
561+
(b'libc.musl.so.1', ('musl', '1')),
562+
(b'libc.musl-x86_64.so.1.2.5', ('musl', '1.2.5')),
561563
(b'', ('', '')),
562564
):
563565
with open(filename, 'wb') as fp:
@@ -576,6 +578,10 @@ def test_libc_ver(self):
576578
(b'GLIBC_1.23.4\0GLIBC_1.9\0GLIBC_1.21\0', ('glibc', '1.23.4')),
577579
(b'libc.so.2.4\0libc.so.9\0libc.so.23.1\0', ('libc', '23.1')),
578580
(b'musl-1.4.1\0musl-2.1.1\0musl-2.0.1\0', ('musl', '2.1.1')),
581+
(
582+
b'libc.musl-x86_64.so.1.4.1\0libc.musl-x86_64.so.2.1.1\0libc.musl-x86_64.so.2.0.1',
583+
('musl', '2.1.1'),
584+
),
579585
(b'no match here, so defaults are used', ('test', '100.1.0')),
580586
):
581587
with open(filename, 'wb') as f:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``musl`` detection for :func:`platform.libc_ver` on Alpine Linux if
2+
compiled with --strip-all.

0 commit comments

Comments
 (0)