The Python test suite now pass on Alpine Linux (musl C library)

Hi,

After many changes over multiple months, the Python test suite now pass on Alpine Linux which uses the musl C library. For example, the AMD64 Alpine Linux buildbot workers pass on 3.14, 3.15 and main branches (Free Threading and regular builds).

platform.libc_ver() was modified to detect musl. The linked_to_musl() function was added to test.support to detect if Python is linked to musl library. It’s mostly used to skip tests which are known to fail on musl (locale, strptime(), math.fma(), mmap.set_name(), os.pathconf() and os.NODEV).

In Python internals, the main change was to increase the stack size from 128 kiB (default on musl) to 1 MiB, and update internals to take this size in account for runtime stack size checks.

If you had issues on Alpine Linux in the past, please test again the current main branch.

I’m not sure about adding x86_64-linux-musl to PEP 11 (Tier 3). So far, I tried to only provide best effort to fix issues specific to musl. At least, we do have a buildbot running on Alpine Linux (thanks Zachary Ware for that!).

For me, what helped the most was that I learnt how to run an Alpine Linux container on my local machine :slight_smile:

Victor

38 Likes

Hi Victor,

Thanks for your contribution! I also ran the Python test suite on Alpine and everything looks good. Cheers!

I also noticed that after updating musl to the latest version, one of the fma tests is now passing. I’ve opened a PR to enable this test—could you please help review it?

Thanks!

Lu

@vstinner Hello again!

I noticed that on Alpine, perf can’t collect Python function-level hotspot info. The reason is that the perf trampoline isn’t enabled.

The trampoline is a CPU-architecture-specific feature and has little to do with OS/libc, so I simply modified configure to reuse the same trampoline as glibc. It appears to work: function-level hotspots are now successfully collected, and several perf-related tests (test_perf_profiler, test_perfmaps, test_samply_profiler) are now PASS (they were previously SKIP).

What do you think about this? If OK, I’d be happy to open an issue. I’ve previously contributed to Eclipse Jifa (a perf tool for Java), so I have some background in profiling.

That said, I’ve only tested on the latest Alpine + musl, so it still needs to be verified on older versions as well. The aarch64 platform also needs to be tested separately (since trampoline is architecture-specific).

1 Like

Yes, it’s worth it to propose a pull request fixing perf trampolines on musl.

1 Like

Thanks for confirming! Then I’ll go ahead