Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manylinux_2_34 x86-64 builds produce binaries that are not compatible with all x86-64 CPUs #1725

Open
alex opened this issue Dec 12, 2024 · 5 comments

Comments

@alex
Copy link
Member

alex commented Dec 12, 2024

manylinux_2_34 is built on AlmaLinux 9. Alma Linux is built for the x86-64-v2 sub-architecture, which assumes that a particular set of x86-64 CPU extensions. (See https://developers.redhat.com/blog/2021/01/05/building-red-hat-enterprise-linux-9-for-the-x86-64-v2-microarchitecture-level#recommendations_for_rhel_9)

As a result, wheels built in manylinux_2_34 by the system compiler will use these CPU extensions, making the wheels not compatible with all x86-64 CPUs, which of course results will result in SIGILL at runtime.

Because wheel tags have no awareness of x86-64-v2, this effectively makes binaries built with manylinux_2_34 unusable.

See pyca/cryptography#12069 for an example of the impact of this.

@njsmith
Copy link
Member

njsmith commented Dec 12, 2024

The immediate fix here is almost certainly to force the manylinux compilers to default to -march=x86-64 somehow, given that the current -march=x86-64-v2 default is, empirically, breaking stuff.

Longer term maybe there's a way for installers to be cleverer or something but that's probably beyond the scope of an issue here.

@alex
Copy link
Member Author

alex commented Dec 12, 2024

Yeah, I think there's a question about how force the system compile to have an -march=....

In terms of installer cleverness, I think that'd require a PEP to standardize a wheel tag for this?

@eli-schwartz
Copy link

https://git.almalinux.org/rpms/gcc/src/commit/33c7fdbe5394937f20abfaf7a6709864c0fab3d6/gcc.spec#L1163-L1172

It is... fascinating... that they are deploying the compiler with a default -march=... value rather than building all packages for RHEL / Alma using CFLAGS=".... -march=x86-64-v2". This is a pretty bad footgun for building statically linked / libc.so-only code on RHEL in order to deploy standalone binaries on other platforms.

Overriding CFLAGS to include -march=x86-64 should work at least, but only if users don't override CFLAGS, or stick to passing CFLAGS via CFLAGS="$CFLAGS -more-cflags-here". The most robust option will be if manylinux installs a custom gcc / g++ wrapper script:

#!/bin/sh

exec /path/to/real/gcc -march=x86-64 "$@"

@mayeut mayeut pinned this issue Dec 14, 2024
@mayeut
Copy link
Member

mayeut commented Dec 14, 2024

In terms of installer cleverness, I think that'd require a PEP to standardize a wheel tag for this?

We'd need a PEP to support this properly.
The best that can be done here is what has been suggested by @eli-schwartz: wrap all gcc binaries. This won't solve the issue if someone wants to graft binaries that were installed with dnf install ... but at least, building from sources should be fixed.
It seems usage of x86-64-v2 could be detected at ELF level (at least in some cases) and that should probably go in auditwheel (likely default to failure with a way to override).

@mayeut
Copy link
Member

mayeut commented Dec 21, 2024

The compilers calls shall all be wrapped now.
Next item on my list will be auditwheel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants