mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.66k stars 1.64k forks source link

Inconsistent host_machine.cpu() for Debian ppc64el cross vs. native #13741

Open smcv opened 2 months ago

smcv commented 2 months ago

Describe the bug On Debian ppc64el (64-bit PowerPC little-endian), Meson detects the host_machine.cpu() to be ppc64le during native builds, but meson env2mfile says ppc64el instead.

Which of these should it ideally be?

  1. ppc64, matching the cpu_family() and disregarding the endianness;
  2. ppc64le, matching a typical Linux uname -m output on these machines;
  3. ppc64el, matching the Debian architecture name (probably not this one)

For completeness, GNU tools call this architecture powerpc64le-linux-gnu.

To Reproduce For a native build: https://buildd.debian.org/status/package.php?p=libglvnd is a convenient example of a package that logs the cpu() and cpu_family() during meson setup.

For a cross-build: source code inspection, or run the unit test that I'm going to propose as a PR, or install ppc64el cross-compilers and run meson env2mfile (a precise reproducer is left as an exercise to the reader).

Expected behavior If I do a native build and a cross-build, both with ppc64el as the host architecture, they should agree on the name of the CPU.

system parameters

smcv commented 2 months ago

For native builds and the build architecture, detect_cpu_family() has a special case that normalizes powerpc64* and ppc64* to ppc64, but detect_cpu() does not have a matching special case, resulting in this inconsistency.

For cross-builds, env2mfile seems to be trying to map powerpc64le to ppc64 in its lookup tables for both cpu_family() and cpu(), but this is ineffective, because the key that is used for the lookup for cpu() is a Debian architecture name (amd64, ppc64el) and not a GNU CPU name (x86_64, powerpc64le). For amd64, this is fixed by #13722, which has the side-effect of changing the cpu() for ppc64el to ppc64, matching the cpu_family().

The downstream debcrossgen tool written by @jpakkane is currently used in Debian for cross-compiling (with the goal of having meson env2mfile replace it), and it similarly appears to be trying to map powerpc64le to ppc64, but similarly this is ineffective because powerpc64le is not the key that is looked up.

I think this maybe means that ppc64 would be the correct answer?