https://bugs.gentoo.org/983993
https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/262 (2nd commit isn't relevant to the last tag)

From 8b14dd531fd990d548aea64ca4da8c270a9e36f5 Mon Sep 17 00:00:00 2001
From: Kastel <daminovruzal7@gmail.com>
Date: Sun, 15 Nov 2026 10:15:34 +0300
Subject: [PATCH 1/2] meson: raise BPF memcpy inline limit for LLVM 23

LLVM 23 stops inlining BPF memory intrinsics above 192 stores and
emits a libcall instead. A BPF object has no libc, so the build fails
in bpftool gen object:

  libbpf: failed to find BTF info for global/extern symbol 'memcpy'

Twenty-three of 95 objects in the full tree hit this. The largest copy
is 482 bytes (Surface Dial).

Pass -mllvm -bpf-max-stores-per-memfunc=1024 when clang accepts it.
The option is hidden, so it is feature-tested at configure time and
older clang is unaffected. The limit counts stores, which is roughly
bytes at alignment 1. 512 would cover the current tree; 1024 leaves
room for larger descriptors. It only raises the threshold.

The option also applies to memset, memmove and memcmp. A survey of the
final BPF IR with testing, stable and userhacks enabled shows 124 memcpy
calls at alignment 1 or 2; 27 exceed 192 stores and the largest is 482
bytes. There are no memset or memcmp intrinsics and no alignment > 8
copies. The final tree has no memmove; the only one in the series is
the DecoSE copy fixed in the next commit.

__builtin_memcpy_inline() would avoid the flag, but it is not
available in GCC 16.2.1. The GCC BPF path is unchanged and was not
tested.

Link: https://github.com/llvm/llvm-project/commit/891b8f6fa8e796464b34fa9460933fccf69f3cc3
Link: https://github.com/llvm/llvm-project/commit/dfe8b229d3ec40e49250cc587009d5752b58b087
Signed-off-by: Kastel <daminovruzal7@gmail.com>
---
 src/bpf/meson.build | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/bpf/meson.build b/src/bpf/meson.build
index 6b292b4..a510602 100644
--- a/src/bpf/meson.build
+++ b/src/bpf/meson.build
@@ -48,6 +48,23 @@ bpf_clang_flags = [
         '-Wno-microsoft-anon-tag',
 ]
 
+# LLVM 23 leaves large memory intrinsics as libcalls; a BPF object has no
+# libc. Raise the inline limit if this clang supports the hidden option.
+if bpf_compiler == 'clang'
+        bpf_max_stores = '-bpf-max-stores-per-memfunc=1024'
+        have_bpf_max_stores = run_command(
+                clang,
+                '-target', 'bpf',
+                '-mllvm', bpf_max_stores,
+                '-c', '-x', 'c', '/dev/null',
+                '-o', '/dev/null',
+                check : false,
+        ).returncode() == 0
+        if have_bpf_max_stores
+                bpf_clang_flags += ['-mllvm', bpf_max_stores]
+        endif
+endif
+
 bpf_gcc_flags = [
         '-std=gnu11',
         '-fno-stack-protector',
-- 
GitLab
