From f9509192512a4c4b9e3915a096333d4b6b297956 Mon Sep 17 00:00:00 2001 From: Cosima Neidahl Date: Wed, 23 Jul 2025 22:42:13 +0200 Subject: [PATCH] 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. --- meson.build | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index dfcc963227..bb1fa37f4b 100644 --- a/meson.build +++ b/meson.build @@ -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'],