meson: Detect ELF ABI version for bpf build on ppc64 (#38307)

On 64-bit POWER, there are multiple versions of the ELF ABI in use.

- little-endian powerpc64 is ELFv2
- big-endian powerpc64 is
  - ELFv2 when using musl
  - either ELFv1 or ELFv2 when using glibc

Previously, the BPF build was hard-coding `-D_CALL_ELF=2`, which is
ELFv2. This makes the build fail on ELFv1, similarly to the original
issue that necessitated the addition of this flag on powerpc64le.

To fix this:

1. Use ELFv1 as the default (when `_CALL_ELF` is not defined, this is
the assumption that should be made about the ABI version).
2. Check if the C compiler has `_CALL_ELF` defined, and if it does,
override the default with that.
That's technically not the *correct* compiler in this situation, but I'm
unsure how to get a compiler object for the BPF one from Meson to do the
`*_define('_CALL_ELF')` checks with, and they *should* both be targeting
the same ABI version anyway.
3. Add the ABI version to the `_CALL_ELF` definition for the BPF
compiler flags.

This makes a BPF-enabled build succeed on powerpc64 w/ ELFv1 glibc.
This commit is contained in:
Cosima Neidahl
2025-07-23 22:42:13 +02:00
committed by GitHub
parent 349d1240a0
commit f950919251

View File

@@ -1734,9 +1734,21 @@ if conf.get('BPF_FRAMEWORK') == 1
#
# C.f. https://mesonbuild.com/Reference-tables.html#cpu-families
# and src/basic/missing_syscall_def.h.
# Start with older ABI. When define is missing, we're likely targeting that.
ppc64_elf_version = '1'
if host_machine.cpu_family() == 'ppc64'
# cc doesn't have to be bpf_compiler, but they should be targeting the same ABI
call_elf_value = cc.get_define('_CALL_ELF')
if call_elf_value != ''
ppc64_elf_version = call_elf_value
endif
endif
cpu_arch_defines = {
'ppc' : ['-D__powerpc__', '-D__TARGET_ARCH_powerpc'],
'ppc64' : ['-D__powerpc64__', '-D__TARGET_ARCH_powerpc', '-D_CALL_ELF=2'],
'ppc64' : ['-D__powerpc64__', '-D__TARGET_ARCH_powerpc', '-D_CALL_ELF=' + ppc64_elf_version],
'riscv32' : ['-D__riscv', '-D__riscv_xlen=32', '-D__TARGET_ARCH_riscv'],
'riscv64' : ['-D__riscv', '-D__riscv_xlen=64', '-D__TARGET_ARCH_riscv'],
'x86' : ['-D__i386__', '-D__TARGET_ARCH_x86'],