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

aix: CC='gcc -maix64' results in"ERROR: Can not run test applications in this cross environment." #10872

Open
anarazel opened this issue Sep 29, 2022 · 0 comments

Comments

@anarazel
Copy link
Contributor

Hi,

The typical way to target 64 bits on AIX is to set CC to something like gcc -maix64. However that causes anything trying to run binaries to fail with "ERROR: Can not run test applications in this cross environment.".

Repro:

project('repro', 'c')

cc = meson.get_compiler('c')
cc.sizeof('void *')
rm -rf build/ && CC='gcc -maix64' m setup build
The Meson build system
Version: 0.63.99
Source dir: /home/andres/repro
Build dir: /home/andres/repro/build
Build type: native build
Project name: repro
Project version: undefined
C compiler for the host machine: gcc -maix64 (gcc 7.2.0 "gcc (GCC) 7.2.0")
C linker for the host machine: gcc -maix64 ld.aix 7.2.4
Host machine cpu family: ppc64
Host machine cpu: powerpc

meson.build:5:3: ERROR: Can not run test applications in this cross environment.

This can be worked around, by specifying -maix64 via CFLAGS:

The Meson build system
Version: 0.63.99
Source dir: /home/andres/repro
Build dir: /home/andres/repro/build
Build type: native build
Project name: repro
Project version: undefined
C compiler for the host machine: gcc (gcc 7.2.0 "gcc (GCC) 7.2.0")
C linker for the host machine: gcc ld.aix 7.2.4
Host machine cpu family: ppc
Host machine cpu: powerpc
Checking for size of "void *" : 8
Build targets in project: 0

Note the difference in "Host machine cpu family". With the CFLAGS approach it is wrong, which avoids the error above, but obviously isn't good either.

The cause of the failure is that machine_info_can_run() determines the native cpu family without the compiler:

"""Whether we can run binaries for this machine on the current machine.
Can almost always run 32-bit binaries on 64-bit natively if the host
and build systems are the same. We don't pass any compilers to
detect_cpu_family() here because we always want to know the OS
architecture, not what the compiler environment tells us.
"""
if machine_info.system != detect_system():
return False
true_build_cpu_family = detect_cpu_family({})

which in turn prevents meson from detecting ppc64:
elif trial == 'ppc':
# AIX always returns powerpc, check here for 64-bit
if any_compiler_has_define(compilers, '__64BIT__'):
trial = 'ppc64'

ISTM that detect_cpu_family() needs to correctly determine the CPU independent of the compiler. Unfortunately python does not natively provide a way for that. The documented way to get the effective bitness of the hardware is getconf HARDWARE_BITMODE.

Note that the cpu is wrong in both cases, but that's an issue for another day.

I can open a PR to call getconf HARDWARE_BITMODE. But it seems that the result should be cached somewhere - but I am not sure where?

Regards,

Andres

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

1 participant