]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: Detect ELF ABI version for bpf build on ppc64 (#38307)
authorCosima Neidahl <opna2608@protonmail.com>
Wed, 23 Jul 2025 20:42:13 +0000 (22:42 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 4 Aug 2025 14:49:46 +0000 (15:49 +0100)
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.

(cherry picked from commit f9509192512a4c4b9e3915a096333d4b6b297956)

meson.build

index b11fed9efa99e8fc7dca6db657aa11c9c2d78fe1..5d33a3025f1c7d1b6f4feb4e0479d0be4cc34adf 100644 (file)
@@ -1814,9 +1814,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'],