* [PATCH] meson: Allow BPF code to be built with GCC
@ 2025-08-03 8:17 James Le Cuirot
2025-08-04 9:13 ` Sean Young
2025-08-10 14:20 ` [PATCH v2] " James Le Cuirot
0 siblings, 2 replies; 13+ messages in thread
From: James Le Cuirot @ 2025-08-03 8:17 UTC (permalink / raw)
To: linux-media; +Cc: Sam James, James Le Cuirot
GCC can also target BPF, but it does not understand the "-target bpf"
arguments passed to Clang.
Detect it as either bpf-gcc, bpf-none-gcc, or bpf-unknown-none-gcc, the
same as systemd does.
Determine the include paths with the compiler used by the rest of the
build rather than Clang, which might not be installed or might not give
the right answer, especially when cross-compiling.
Check whether Clang actually supports the BPF target so that
auto-detection doesn't cause the build to fail when it doesn't.
Disclaimer: I haven't actually tested the result of the GCC build.
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
---
meson.build | 23 ++++++++++++++++++-
.../keytable/bpf_protocols/cc_sys_includes.sh | 10 ++++++++
.../bpf_protocols/clang_sys_includes.sh | 9 --------
utils/keytable/bpf_protocols/meson.build | 12 +++++-----
utils/keytable/meson.build | 2 +-
5 files changed, 39 insertions(+), 17 deletions(-)
create mode 100755 utils/keytable/bpf_protocols/cc_sys_includes.sh
delete mode 100755 utils/keytable/bpf_protocols/clang_sys_includes.sh
diff --git a/meson.build b/meson.build
index 88781e59..0aff6970 100644
--- a/meson.build
+++ b/meson.build
@@ -83,11 +83,32 @@ endif
v4l2_utils_incdir = include_directories(v4l2_utils_incdir_arr)
prog_bash = find_program('bash')
-prog_clang = find_program('clang', required : get_option('bpf'))
prog_doxygen = find_program('doxygen', required : get_option('doxygen-doc'))
prog_grep = find_program('grep')
prog_perl = find_program('perl')
+if get_option('bpf').allowed()
+ bpf_args = []
+ prog_bpf = find_program('bpf-gcc',
+ 'bpf-none-gcc',
+ 'bpf-unknown-none-gcc',
+ required : false)
+
+ if not prog_bpf.found()
+ prog_bpf = find_program('clang', required : get_option('bpf'))
+ if prog_bpf.found()
+ target_bpf = run_command(prog_bpf, '-target', 'bpf', '--print-supported-cpus', check : get_option('bpf').enabled())
+ if target_bpf.returncode() == 0
+ bpf_args += ['-target', 'bpf']
+ else
+ prog_bpf = disabler()
+ endif
+ endif
+ endif
+else
+ prog_bpf = disabler()
+endif
+
dep_alsa = dependency('alsa', required : false)
if dep_alsa.found()
conf.set('HAVE_ALSA', 1)
diff --git a/utils/keytable/bpf_protocols/cc_sys_includes.sh b/utils/keytable/bpf_protocols/cc_sys_includes.sh
new file mode 100755
index 00000000..0a8fa277
--- /dev/null
+++ b/utils/keytable/bpf_protocols/cc_sys_includes.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Get C compiler's default includes on this system, as the BPF toolchain
+# generally doesn't see the Linux headers. This fixes "missing" files on some
+# architectures/distros, such as asm/byteorder.h, asm/socket.h, asm/sockios.h,
+# sys/cdefs.h etc.
+#
+# Use '-idirafter': Don't interfere with include mechanics except where the
+# build would have failed anyways.
+"$@" -v -E - </dev/null 2>&1 \
+ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
diff --git a/utils/keytable/bpf_protocols/clang_sys_includes.sh b/utils/keytable/bpf_protocols/clang_sys_includes.sh
deleted file mode 100755
index 9dc4af12..00000000
--- a/utils/keytable/bpf_protocols/clang_sys_includes.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-# Get Clang's default includes on this system, as opposed to those seen by
-# '-target bpf'. This fixes "missing" files on some architectures/distros,
-# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
-#
-# Use '-idirafter': Don't interfere with include mechanics except where the
-# build would have failed anyways.
-$CLANG -v -E - </dev/null 2>&1 \
- | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
diff --git a/utils/keytable/bpf_protocols/meson.build b/utils/keytable/bpf_protocols/meson.build
index 1e4f0064..dbb926c4 100644
--- a/utils/keytable/bpf_protocols/meson.build
+++ b/utils/keytable/bpf_protocols/meson.build
@@ -10,9 +10,9 @@ bpf_protocols_files = [
'xbox-dvd',
]
-clang_sys_includes = run_command('clang_sys_includes.sh',
- check : true,
- env : ['CLANG=' + prog_clang.full_path()])
+bpf_args += run_command('cc_sys_includes.sh',
+ cc.cmd_array(),
+ check : true).stdout().split()
foreach file : bpf_protocols_files
output = file + '.o'
@@ -21,9 +21,9 @@ foreach file : bpf_protocols_files
output : output,
input : input,
command : [
- prog_clang,
- clang_sys_includes.stdout().split(),
- '-D__linux__', '-fno-stack-protector', '-target', 'bpf',
+ prog_bpf,
+ bpf_args,
+ '-D__linux__', '-fno-stack-protector',
'-O2', '-c', '@INPUT@', '-o', '@OUTPUT@',
],
install : true,
diff --git a/utils/keytable/meson.build b/utils/keytable/meson.build
index e214e0b5..56e61a79 100644
--- a/utils/keytable/meson.build
+++ b/utils/keytable/meson.build
@@ -22,7 +22,7 @@ ir_keytable_c_args = [
'-DIR_KEYTABLE_USER_DIR="@0@"'.format(ir_keytable_user_dir),
]
-ir_bpf_enabled = prog_clang.found() and dep_libbpf.found() and dep_libelf.found()
+ir_bpf_enabled = prog_bpf.found() and dep_libbpf.found() and dep_libelf.found()
if ir_bpf_enabled
ir_keytable_sources += files(
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-03 8:17 [PATCH] meson: Allow BPF code to be built with GCC James Le Cuirot
@ 2025-08-04 9:13 ` Sean Young
2025-08-04 20:22 ` Sam James
2025-08-05 11:32 ` Sean Young
2025-08-10 14:20 ` [PATCH v2] " James Le Cuirot
1 sibling, 2 replies; 13+ messages in thread
From: Sean Young @ 2025-08-04 9:13 UTC (permalink / raw)
To: James Le Cuirot; +Cc: linux-media, Sam James
On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
> GCC can also target BPF, but it does not understand the "-target bpf"
> arguments passed to Clang.
>
> Detect it as either bpf-gcc, bpf-none-gcc, or bpf-unknown-none-gcc, the
> same as systemd does.
Thank you for the patch, I had not looked into this yet.
> Determine the include paths with the compiler used by the rest of the
> build rather than Clang, which might not be installed or might not give
> the right answer, especially when cross-compiling.
Fair enough.
> Check whether Clang actually supports the BPF target so that
> auto-detection doesn't cause the build to fail when it doesn't.
clang has supported BPF for a really long time. We've never bothered to
test whether clang supports BPF before and I've never seen this be a
problem; why introduce this test?
> Disclaimer: I haven't actually tested the result of the GCC build.
Let me test this.
I do wonder why you default to bpf-gcc rather than clang. Any particular
reason?
Thanks,
Sean
>
> Signed-off-by: James Le Cuirot <chewi@gentoo.org>
> ---
> meson.build | 23 ++++++++++++++++++-
> .../keytable/bpf_protocols/cc_sys_includes.sh | 10 ++++++++
> .../bpf_protocols/clang_sys_includes.sh | 9 --------
> utils/keytable/bpf_protocols/meson.build | 12 +++++-----
> utils/keytable/meson.build | 2 +-
> 5 files changed, 39 insertions(+), 17 deletions(-)
> create mode 100755 utils/keytable/bpf_protocols/cc_sys_includes.sh
> delete mode 100755 utils/keytable/bpf_protocols/clang_sys_includes.sh
>
> diff --git a/meson.build b/meson.build
> index 88781e59..0aff6970 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -83,11 +83,32 @@ endif
> v4l2_utils_incdir = include_directories(v4l2_utils_incdir_arr)
>
> prog_bash = find_program('bash')
> -prog_clang = find_program('clang', required : get_option('bpf'))
> prog_doxygen = find_program('doxygen', required : get_option('doxygen-doc'))
> prog_grep = find_program('grep')
> prog_perl = find_program('perl')
>
> +if get_option('bpf').allowed()
> + bpf_args = []
> + prog_bpf = find_program('bpf-gcc',
> + 'bpf-none-gcc',
> + 'bpf-unknown-none-gcc',
> + required : false)
> +
> + if not prog_bpf.found()
> + prog_bpf = find_program('clang', required : get_option('bpf'))
> + if prog_bpf.found()
> + target_bpf = run_command(prog_bpf, '-target', 'bpf', '--print-supported-cpus', check : get_option('bpf').enabled())
> + if target_bpf.returncode() == 0
> + bpf_args += ['-target', 'bpf']
> + else
> + prog_bpf = disabler()
> + endif
> + endif
> + endif
> +else
> + prog_bpf = disabler()
> +endif
> +
> dep_alsa = dependency('alsa', required : false)
> if dep_alsa.found()
> conf.set('HAVE_ALSA', 1)
> diff --git a/utils/keytable/bpf_protocols/cc_sys_includes.sh b/utils/keytable/bpf_protocols/cc_sys_includes.sh
> new file mode 100755
> index 00000000..0a8fa277
> --- /dev/null
> +++ b/utils/keytable/bpf_protocols/cc_sys_includes.sh
> @@ -0,0 +1,10 @@
> +#!/bin/sh
> +# Get C compiler's default includes on this system, as the BPF toolchain
> +# generally doesn't see the Linux headers. This fixes "missing" files on some
> +# architectures/distros, such as asm/byteorder.h, asm/socket.h, asm/sockios.h,
> +# sys/cdefs.h etc.
> +#
> +# Use '-idirafter': Don't interfere with include mechanics except where the
> +# build would have failed anyways.
> +"$@" -v -E - </dev/null 2>&1 \
> + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
> diff --git a/utils/keytable/bpf_protocols/clang_sys_includes.sh b/utils/keytable/bpf_protocols/clang_sys_includes.sh
> deleted file mode 100755
> index 9dc4af12..00000000
> --- a/utils/keytable/bpf_protocols/clang_sys_includes.sh
> +++ /dev/null
> @@ -1,9 +0,0 @@
> -#!/bin/sh
> -# Get Clang's default includes on this system, as opposed to those seen by
> -# '-target bpf'. This fixes "missing" files on some architectures/distros,
> -# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
> -#
> -# Use '-idirafter': Don't interfere with include mechanics except where the
> -# build would have failed anyways.
> -$CLANG -v -E - </dev/null 2>&1 \
> - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
> diff --git a/utils/keytable/bpf_protocols/meson.build b/utils/keytable/bpf_protocols/meson.build
> index 1e4f0064..dbb926c4 100644
> --- a/utils/keytable/bpf_protocols/meson.build
> +++ b/utils/keytable/bpf_protocols/meson.build
> @@ -10,9 +10,9 @@ bpf_protocols_files = [
> 'xbox-dvd',
> ]
>
> -clang_sys_includes = run_command('clang_sys_includes.sh',
> - check : true,
> - env : ['CLANG=' + prog_clang.full_path()])
> +bpf_args += run_command('cc_sys_includes.sh',
> + cc.cmd_array(),
> + check : true).stdout().split()
>
> foreach file : bpf_protocols_files
> output = file + '.o'
> @@ -21,9 +21,9 @@ foreach file : bpf_protocols_files
> output : output,
> input : input,
> command : [
> - prog_clang,
> - clang_sys_includes.stdout().split(),
> - '-D__linux__', '-fno-stack-protector', '-target', 'bpf',
> + prog_bpf,
> + bpf_args,
> + '-D__linux__', '-fno-stack-protector',
> '-O2', '-c', '@INPUT@', '-o', '@OUTPUT@',
> ],
> install : true,
> diff --git a/utils/keytable/meson.build b/utils/keytable/meson.build
> index e214e0b5..56e61a79 100644
> --- a/utils/keytable/meson.build
> +++ b/utils/keytable/meson.build
> @@ -22,7 +22,7 @@ ir_keytable_c_args = [
> '-DIR_KEYTABLE_USER_DIR="@0@"'.format(ir_keytable_user_dir),
> ]
>
> -ir_bpf_enabled = prog_clang.found() and dep_libbpf.found() and dep_libelf.found()
> +ir_bpf_enabled = prog_bpf.found() and dep_libbpf.found() and dep_libelf.found()
>
> if ir_bpf_enabled
> ir_keytable_sources += files(
> --
> 2.50.1
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-04 9:13 ` Sean Young
@ 2025-08-04 20:22 ` Sam James
2025-08-04 20:34 ` James Le Cuirot
2025-08-05 11:32 ` Sean Young
1 sibling, 1 reply; 13+ messages in thread
From: Sam James @ 2025-08-04 20:22 UTC (permalink / raw)
To: Sean Young; +Cc: James Le Cuirot, linux-media
Sean Young <sean@mess.org> writes:
> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
>> GCC can also target BPF, but it does not understand the "-target bpf"
>> arguments passed to Clang.
>>
>> Detect it as either bpf-gcc, bpf-none-gcc, or bpf-unknown-none-gcc, the
>> same as systemd does.
>
> Thank you for the patch, I had not looked into this yet.
>
>> Determine the include paths with the compiler used by the rest of the
>> build rather than Clang, which might not be installed or might not give
>> the right answer, especially when cross-compiling.
>
> Fair enough.
>
>> Check whether Clang actually supports the BPF target so that
>> auto-detection doesn't cause the build to fail when it doesn't.
>
> clang has supported BPF for a really long time. We've never bothered to
> test whether clang supports BPF before and I've never seen this be a
> problem; why introduce this test?
Clang takes a long time to build and you don't actually have to enable
all targets.
>
>> Disclaimer: I haven't actually tested the result of the GCC build.
>
> Let me test this.
>
> I do wonder why you default to bpf-gcc rather than clang. Any particular
> reason?
Clang *tends* to have BPF as a target (just not always), so having the
less common option > the more common one means the less common one can
be used.
i.e. if Clang was first, even if you have a cross BPF toolchain w/ GCC,
you probably can't then use the GCC path. But maybe it should be an
option instead.
>
> Thanks,
>
> Sean
>
>>
>> Signed-off-by: James Le Cuirot <chewi@gentoo.org>
>> ---
>> meson.build | 23 ++++++++++++++++++-
>> .../keytable/bpf_protocols/cc_sys_includes.sh | 10 ++++++++
>> .../bpf_protocols/clang_sys_includes.sh | 9 --------
>> utils/keytable/bpf_protocols/meson.build | 12 +++++-----
>> utils/keytable/meson.build | 2 +-
>> 5 files changed, 39 insertions(+), 17 deletions(-)
>> create mode 100755 utils/keytable/bpf_protocols/cc_sys_includes.sh
>> delete mode 100755 utils/keytable/bpf_protocols/clang_sys_includes.sh
>>
>> diff --git a/meson.build b/meson.build
>> index 88781e59..0aff6970 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -83,11 +83,32 @@ endif
>> v4l2_utils_incdir = include_directories(v4l2_utils_incdir_arr)
>>
>> prog_bash = find_program('bash')
>> -prog_clang = find_program('clang', required : get_option('bpf'))
>> prog_doxygen = find_program('doxygen', required : get_option('doxygen-doc'))
>> prog_grep = find_program('grep')
>> prog_perl = find_program('perl')
>>
>> +if get_option('bpf').allowed()
>> + bpf_args = []
>> + prog_bpf = find_program('bpf-gcc',
>> + 'bpf-none-gcc',
>> + 'bpf-unknown-none-gcc',
>> + required : false)
>> +
>> + if not prog_bpf.found()
>> + prog_bpf = find_program('clang', required : get_option('bpf'))
>> + if prog_bpf.found()
>> + target_bpf = run_command(prog_bpf, '-target', 'bpf', '--print-supported-cpus', check : get_option('bpf').enabled())
>> + if target_bpf.returncode() == 0
>> + bpf_args += ['-target', 'bpf']
>> + else
>> + prog_bpf = disabler()
>> + endif
>> + endif
>> + endif
>> +else
>> + prog_bpf = disabler()
>> +endif
>> +
>> dep_alsa = dependency('alsa', required : false)
>> if dep_alsa.found()
>> conf.set('HAVE_ALSA', 1)
>> diff --git a/utils/keytable/bpf_protocols/cc_sys_includes.sh b/utils/keytable/bpf_protocols/cc_sys_includes.sh
>> new file mode 100755
>> index 00000000..0a8fa277
>> --- /dev/null
>> +++ b/utils/keytable/bpf_protocols/cc_sys_includes.sh
>> @@ -0,0 +1,10 @@
>> +#!/bin/sh
>> +# Get C compiler's default includes on this system, as the BPF toolchain
>> +# generally doesn't see the Linux headers. This fixes "missing" files on some
>> +# architectures/distros, such as asm/byteorder.h, asm/socket.h, asm/sockios.h,
>> +# sys/cdefs.h etc.
>> +#
>> +# Use '-idirafter': Don't interfere with include mechanics except where the
>> +# build would have failed anyways.
>> +"$@" -v -E - </dev/null 2>&1 \
>> + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
>> diff --git a/utils/keytable/bpf_protocols/clang_sys_includes.sh b/utils/keytable/bpf_protocols/clang_sys_includes.sh
>> deleted file mode 100755
>> index 9dc4af12..00000000
>> --- a/utils/keytable/bpf_protocols/clang_sys_includes.sh
>> +++ /dev/null
>> @@ -1,9 +0,0 @@
>> -#!/bin/sh
>> -# Get Clang's default includes on this system, as opposed to those seen by
>> -# '-target bpf'. This fixes "missing" files on some architectures/distros,
>> -# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
>> -#
>> -# Use '-idirafter': Don't interfere with include mechanics except where the
>> -# build would have failed anyways.
>> -$CLANG -v -E - </dev/null 2>&1 \
>> - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
>> diff --git a/utils/keytable/bpf_protocols/meson.build b/utils/keytable/bpf_protocols/meson.build
>> index 1e4f0064..dbb926c4 100644
>> --- a/utils/keytable/bpf_protocols/meson.build
>> +++ b/utils/keytable/bpf_protocols/meson.build
>> @@ -10,9 +10,9 @@ bpf_protocols_files = [
>> 'xbox-dvd',
>> ]
>>
>> -clang_sys_includes = run_command('clang_sys_includes.sh',
>> - check : true,
>> - env : ['CLANG=' + prog_clang.full_path()])
>> +bpf_args += run_command('cc_sys_includes.sh',
>> + cc.cmd_array(),
>> + check : true).stdout().split()
>>
>> foreach file : bpf_protocols_files
>> output = file + '.o'
>> @@ -21,9 +21,9 @@ foreach file : bpf_protocols_files
>> output : output,
>> input : input,
>> command : [
>> - prog_clang,
>> - clang_sys_includes.stdout().split(),
>> - '-D__linux__', '-fno-stack-protector', '-target', 'bpf',
>> + prog_bpf,
>> + bpf_args,
>> + '-D__linux__', '-fno-stack-protector',
>> '-O2', '-c', '@INPUT@', '-o', '@OUTPUT@',
>> ],
>> install : true,
>> diff --git a/utils/keytable/meson.build b/utils/keytable/meson.build
>> index e214e0b5..56e61a79 100644
>> --- a/utils/keytable/meson.build
>> +++ b/utils/keytable/meson.build
>> @@ -22,7 +22,7 @@ ir_keytable_c_args = [
>> '-DIR_KEYTABLE_USER_DIR="@0@"'.format(ir_keytable_user_dir),
>> ]
>>
>> -ir_bpf_enabled = prog_clang.found() and dep_libbpf.found() and dep_libelf.found()
>> +ir_bpf_enabled = prog_bpf.found() and dep_libbpf.found() and dep_libelf.found()
>>
>> if ir_bpf_enabled
>> ir_keytable_sources += files(
>> --
>> 2.50.1
>>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-04 20:22 ` Sam James
@ 2025-08-04 20:34 ` James Le Cuirot
0 siblings, 0 replies; 13+ messages in thread
From: James Le Cuirot @ 2025-08-04 20:34 UTC (permalink / raw)
To: Sam James, Sean Young; +Cc: linux-media
[-- Attachment #1: Type: text/plain, Size: 8377 bytes --]
On Mon, 2025-08-04 at 21:22 +0100, Sam James wrote:
> Sean Young <sean@mess.org> writes:
>
> > On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
> > > GCC can also target BPF, but it does not understand the "-target bpf"
> > > arguments passed to Clang.
> > >
> > > Detect it as either bpf-gcc, bpf-none-gcc, or bpf-unknown-none-gcc, the
> > > same as systemd does.
> >
> > Thank you for the patch, I had not looked into this yet.
> >
> > > Determine the include paths with the compiler used by the rest of the
> > > build rather than Clang, which might not be installed or might not give
> > > the right answer, especially when cross-compiling.
> >
> > Fair enough.
> >
> > > Check whether Clang actually supports the BPF target so that
> > > auto-detection doesn't cause the build to fail when it doesn't.
> >
> > clang has supported BPF for a really long time. We've never bothered to
> > test whether clang supports BPF before and I've never seen this be a
> > problem; why introduce this test?
>
> Clang takes a long time to build and you don't actually have to enable
> all targets.
To expand on that, I have personally built Clang without BPF in the past.
systemd does this check, albeit with a more helpful error message. I can add
one if you like. But most of all, you don't want a situation where the build
might fail even if the user didn't explicitly ask for BPF support.
> > > Disclaimer: I haven't actually tested the result of the GCC build.
> >
> > Let me test this.
> >
> > I do wonder why you default to bpf-gcc rather than clang. Any particular
> > reason?
>
> Clang *tends* to have BPF as a target (just not always), so having the
> less common option > the more common one means the less common one can
> be used.
>
> i.e. if Clang was first, even if you have a cross BPF toolchain w/ GCC,
> you probably can't then use the GCC path. But maybe it should be an
> option instead.
There wasn't any particularly strong reason. I figured if you have bpf-gcc,
then that should definitely work, whereas Clang might not. Gentoo favours
bpf-gcc because it has wider platform support and is quicker to build. Chances
are that the rest of the build is being done with GCC. systemd allows you to
choose, but I didn't see the need. I imagine either works equally well.
> > Thanks,
> >
> > Sean
> >
> > >
> > > Signed-off-by: James Le Cuirot <chewi@gentoo.org>
> > > ---
> > > meson.build | 23 ++++++++++++++++++-
> > > .../keytable/bpf_protocols/cc_sys_includes.sh | 10 ++++++++
> > > .../bpf_protocols/clang_sys_includes.sh | 9 --------
> > > utils/keytable/bpf_protocols/meson.build | 12 +++++-----
> > > utils/keytable/meson.build | 2 +-
> > > 5 files changed, 39 insertions(+), 17 deletions(-)
> > > create mode 100755 utils/keytable/bpf_protocols/cc_sys_includes.sh
> > > delete mode 100755 utils/keytable/bpf_protocols/clang_sys_includes.sh
> > >
> > > diff --git a/meson.build b/meson.build
> > > index 88781e59..0aff6970 100644
> > > --- a/meson.build
> > > +++ b/meson.build
> > > @@ -83,11 +83,32 @@ endif
> > > v4l2_utils_incdir = include_directories(v4l2_utils_incdir_arr)
> > >
> > > prog_bash = find_program('bash')
> > > -prog_clang = find_program('clang', required : get_option('bpf'))
> > > prog_doxygen = find_program('doxygen', required : get_option('doxygen-doc'))
> > > prog_grep = find_program('grep')
> > > prog_perl = find_program('perl')
> > >
> > > +if get_option('bpf').allowed()
> > > + bpf_args = []
> > > + prog_bpf = find_program('bpf-gcc',
> > > + 'bpf-none-gcc',
> > > + 'bpf-unknown-none-gcc',
> > > + required : false)
> > > +
> > > + if not prog_bpf.found()
> > > + prog_bpf = find_program('clang', required : get_option('bpf'))
> > > + if prog_bpf.found()
> > > + target_bpf = run_command(prog_bpf, '-target', 'bpf', '--print-supported-cpus', check : get_option('bpf').enabled())
> > > + if target_bpf.returncode() == 0
> > > + bpf_args += ['-target', 'bpf']
> > > + else
> > > + prog_bpf = disabler()
> > > + endif
> > > + endif
> > > + endif
> > > +else
> > > + prog_bpf = disabler()
> > > +endif
> > > +
> > > dep_alsa = dependency('alsa', required : false)
> > > if dep_alsa.found()
> > > conf.set('HAVE_ALSA', 1)
> > > diff --git a/utils/keytable/bpf_protocols/cc_sys_includes.sh b/utils/keytable/bpf_protocols/cc_sys_includes.sh
> > > new file mode 100755
> > > index 00000000..0a8fa277
> > > --- /dev/null
> > > +++ b/utils/keytable/bpf_protocols/cc_sys_includes.sh
> > > @@ -0,0 +1,10 @@
> > > +#!/bin/sh
> > > +# Get C compiler's default includes on this system, as the BPF toolchain
> > > +# generally doesn't see the Linux headers. This fixes "missing" files on some
> > > +# architectures/distros, such as asm/byteorder.h, asm/socket.h, asm/sockios.h,
> > > +# sys/cdefs.h etc.
> > > +#
> > > +# Use '-idirafter': Don't interfere with include mechanics except where the
> > > +# build would have failed anyways.
> > > +"$@" -v -E - </dev/null 2>&1 \
> > > + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
> > > diff --git a/utils/keytable/bpf_protocols/clang_sys_includes.sh b/utils/keytable/bpf_protocols/clang_sys_includes.sh
> > > deleted file mode 100755
> > > index 9dc4af12..00000000
> > > --- a/utils/keytable/bpf_protocols/clang_sys_includes.sh
> > > +++ /dev/null
> > > @@ -1,9 +0,0 @@
> > > -#!/bin/sh
> > > -# Get Clang's default includes on this system, as opposed to those seen by
> > > -# '-target bpf'. This fixes "missing" files on some architectures/distros,
> > > -# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
> > > -#
> > > -# Use '-idirafter': Don't interfere with include mechanics except where the
> > > -# build would have failed anyways.
> > > -$CLANG -v -E - </dev/null 2>&1 \
> > > - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
> > > diff --git a/utils/keytable/bpf_protocols/meson.build b/utils/keytable/bpf_protocols/meson.build
> > > index 1e4f0064..dbb926c4 100644
> > > --- a/utils/keytable/bpf_protocols/meson.build
> > > +++ b/utils/keytable/bpf_protocols/meson.build
> > > @@ -10,9 +10,9 @@ bpf_protocols_files = [
> > > 'xbox-dvd',
> > > ]
> > >
> > > -clang_sys_includes = run_command('clang_sys_includes.sh',
> > > - check : true,
> > > - env : ['CLANG=' + prog_clang.full_path()])
> > > +bpf_args += run_command('cc_sys_includes.sh',
> > > + cc.cmd_array(),
> > > + check : true).stdout().split()
> > >
> > > foreach file : bpf_protocols_files
> > > output = file + '.o'
> > > @@ -21,9 +21,9 @@ foreach file : bpf_protocols_files
> > > output : output,
> > > input : input,
> > > command : [
> > > - prog_clang,
> > > - clang_sys_includes.stdout().split(),
> > > - '-D__linux__', '-fno-stack-protector', '-target', 'bpf',
> > > + prog_bpf,
> > > + bpf_args,
> > > + '-D__linux__', '-fno-stack-protector',
> > > '-O2', '-c', '@INPUT@', '-o', '@OUTPUT@',
> > > ],
> > > install : true,
> > > diff --git a/utils/keytable/meson.build b/utils/keytable/meson.build
> > > index e214e0b5..56e61a79 100644
> > > --- a/utils/keytable/meson.build
> > > +++ b/utils/keytable/meson.build
> > > @@ -22,7 +22,7 @@ ir_keytable_c_args = [
> > > '-DIR_KEYTABLE_USER_DIR="@0@"'.format(ir_keytable_user_dir),
> > > ]
> > >
> > > -ir_bpf_enabled = prog_clang.found() and dep_libbpf.found() and dep_libelf.found()
> > > +ir_bpf_enabled = prog_bpf.found() and dep_libbpf.found() and dep_libelf.found()
> > >
> > > if ir_bpf_enabled
> > > ir_keytable_sources += files(
> > > --
> > > 2.50.1
> > >
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 858 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-04 9:13 ` Sean Young
2025-08-04 20:22 ` Sam James
@ 2025-08-05 11:32 ` Sean Young
2025-08-05 15:03 ` Sam James
1 sibling, 1 reply; 13+ messages in thread
From: Sean Young @ 2025-08-05 11:32 UTC (permalink / raw)
To: James Le Cuirot; +Cc: linux-media, Sam James
On Mon, Aug 04, 2025 at 10:13:18AM +0100, Sean Young wrote:
> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
> > Disclaimer: I haven't actually tested the result of the GCC build.
>
> Let me test this.
It doesn't work:
# ir-keytable -p ./imon_rsc.o
Protocols changed to
symbol has unknown section 6
bpf_load_program() err=Permission denied
0: R1=ctx() R10=fp0
0: (bf) r6 = r1 ; R1=ctx() R6_w=ctx()
1: (62) *(u32 *)(r10 -4) = 0 ; R10=fp0 fp-8=0000????
2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
3: (18) r1 = 0xffff89ed1318f800 ; R1_w=map_ptr(ks=4,vs=16)
5: (07) r2 += -4 ; R2_w=fp-4
6: (85) call bpf_map_lookup_elem#1 ; R0_w=map_value(ks=4,vs=16)
7: (bf) r4 = r0 ; R0_w=map_value(ks=4,vs=16) R4_w=map_value(ks=4,vs=16)
8: (15) if r0 == 0x0 goto pc+7 ; R0_w=map_value(ks=4,vs=16)
9: (61) r0 = *(u32 *)(r6 +0) ; R0_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R6_w=ctx()
10: (bf) r1 = r0 ; R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R1_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
11: (bf) r2 = r0 ; R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R2_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
12: (54) w1 &= -16777216 ; R1_w=scalar(smin=0,smax=umax=umax32=0xff000000,smax32=0x7f000000,var_off=(0x0; 0xff000000))
13: (54) w2 &= -33554432 ; R2=scalar(smin=0,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
14: (16) if w2 == 0x0 goto pc+3 ; R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
15: (16) if w1 == 0x3000000 goto pc+31 47: R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R1=0x3000000 R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000)) R4=map_value(ks=4,vs=16) R6=ctx() R10=fp0 fp-8=0000????
47: (61) r5 = *(u32 *)(r4 +8) ; R4=map_value(ks=4,vs=16) R5_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
48: (16) if w5 == 0x1 goto pc+7 56: R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R1=0x3000000 R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000)) R4=map_value(ks=4,vs=16) R5_w=1 R6=ctx() R10=fp0 fp-8=0000????
56: (57) r0 &= 16777215 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
57: (b6) if w0 <= 0x960 goto pc+22 ; R0_w=scalar(smin=umin=smin32=umin32=2401,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
58: (61) r1 = *(u32 *)(r4 +12) ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R4=map_value(ks=4,vs=16)
59: (04) w1 += -4 ; R1=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
60: (26) if w1 > 0x1 goto pc-11 ; R1=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1))
61: (79) r3 = *(u64 *)(r4 +0) ; R3_w=scalar() R4=map_value(ks=4,vs=16)
62: (57) r3 &= 15 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=15,var_off=(0x0; 0xf))
63: (07) r3 += -1 ; R3_w=scalar(smin=smin32=-1,smax=smax32=14)
64: (25) if r3 > 0xe goto pc+46 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=14,var_off=(0x0; 0xf))
65: (67) r3 <<= 2 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
66: (18) r2 = 0x3c ; R2_w=60
68: (18) r9 = 0x0 ; R9_w=0
70: (0f) r2 += r3 ; R2_w=scalar(smin=umin=smin32=umin32=60,smax=umax=smax32=umax32=116,var_off=(0x0; 0x7c)) R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
71: (0f) r9 += r3 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c)) R9_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
72: (81) r2 = *(s32 *)(r2 +0)
R2 invalid mem access 'scalar'
processed 40 insns (limit 1000000) max_states_per_insn 0 total_states 3 peak_states 3 mark_read 1
Needs some analysis but I don't think your patch is ready for merging.
Thanks,
Sean
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-05 11:32 ` Sean Young
@ 2025-08-05 15:03 ` Sam James
2025-08-05 22:32 ` Sam James
0 siblings, 1 reply; 13+ messages in thread
From: Sam James @ 2025-08-05 15:03 UTC (permalink / raw)
To: Sean Young; +Cc: James Le Cuirot, linux-media
Sean Young <sean@mess.org> writes:
> On Mon, Aug 04, 2025 at 10:13:18AM +0100, Sean Young wrote:
>> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
>> > Disclaimer: I haven't actually tested the result of the GCC build.
>>
>> Let me test this.
>
> It doesn't work:
>
> # ir-keytable -p ./imon_rsc.o
> Protocols changed to
> symbol has unknown section 6
> bpf_load_program() err=Permission denied
> 0: R1=ctx() R10=fp0
> 0: (bf) r6 = r1 ; R1=ctx() R6_w=ctx()
> 1: (62) *(u32 *)(r10 -4) = 0 ; R10=fp0 fp-8=0000????
> 2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
> 3: (18) r1 = 0xffff89ed1318f800 ; R1_w=map_ptr(ks=4,vs=16)
> 5: (07) r2 += -4 ; R2_w=fp-4
> 6: (85) call bpf_map_lookup_elem#1 ; R0_w=map_value(ks=4,vs=16)
> 7: (bf) r4 = r0 ; R0_w=map_value(ks=4,vs=16) R4_w=map_value(ks=4,vs=16)
> 8: (15) if r0 == 0x0 goto pc+7 ; R0_w=map_value(ks=4,vs=16)
> 9: (61) r0 = *(u32 *)(r6 +0) ; R0_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R6_w=ctx()
> 10: (bf) r1 = r0 ; R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R1_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> 11: (bf) r2 = r0 ; R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R2_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> 12: (54) w1 &= -16777216 ; R1_w=scalar(smin=0,smax=umax=umax32=0xff000000,smax32=0x7f000000,var_off=(0x0; 0xff000000))
> 13: (54) w2 &= -33554432 ; R2=scalar(smin=0,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
> 14: (16) if w2 == 0x0 goto pc+3 ; R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
> 15: (16) if w1 == 0x3000000 goto pc+31 47:
> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> R1=0x3000000
> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
> 0xfe000000)) R4=map_value(ks=4,vs=16) R6=ctx() R10=fp0 fp-8=0000????
> 47: (61) r5 = *(u32 *)(r4 +8) ; R4=map_value(ks=4,vs=16) R5_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> 48: (16) if w5 == 0x1 goto pc+7 56:
> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> R1=0x3000000
> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
> 0xfe000000)) R4=map_value(ks=4,vs=16) R5_w=1 R6=ctx() R10=fp0
> fp-8=0000????
> 56: (57) r0 &= 16777215 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
> 57: (b6) if w0 <= 0x960 goto pc+22 ; R0_w=scalar(smin=umin=smin32=umin32=2401,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
> 58: (61) r1 = *(u32 *)(r4 +12) ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R4=map_value(ks=4,vs=16)
> 59: (04) w1 += -4 ; R1=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> 60: (26) if w1 > 0x1 goto pc-11 ; R1=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1))
> 61: (79) r3 = *(u64 *)(r4 +0) ; R3_w=scalar() R4=map_value(ks=4,vs=16)
> 62: (57) r3 &= 15 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=15,var_off=(0x0; 0xf))
> 63: (07) r3 += -1 ; R3_w=scalar(smin=smin32=-1,smax=smax32=14)
> 64: (25) if r3 > 0xe goto pc+46 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=14,var_off=(0x0; 0xf))
> 65: (67) r3 <<= 2 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
> 66: (18) r2 = 0x3c ; R2_w=60
> 68: (18) r9 = 0x0 ; R9_w=0
> 70: (0f) r2 += r3 ;
> R2_w=scalar(smin=umin=smin32=umin32=60,smax=umax=smax32=umax32=116,var_off=(0x0;
> 0x7c))
> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
> 0x3c))
> 71: (0f) r9 += r3 ;
> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
> 0x3c))
> R9_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
> 0x3c))
> 72: (81) r2 = *(s32 *)(r2 +0)
> R2 invalid mem access 'scalar'
> processed 40 insns (limit 1000000) max_states_per_insn 0 total_states 3 peak_states 3 mark_read 1
I'll have a look. Thanks.
>
> Needs some analysis but I don't think your patch is ready for merging.
>
> Thanks,
> Sean
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-05 15:03 ` Sam James
@ 2025-08-05 22:32 ` Sam James
2025-08-06 20:53 ` Sean Young
0 siblings, 1 reply; 13+ messages in thread
From: Sam James @ 2025-08-05 22:32 UTC (permalink / raw)
To: Sean Young; +Cc: James Le Cuirot, linux-media
Sam James <sam@gentoo.org> writes:
> Sean Young <sean@mess.org> writes:
>
>> On Mon, Aug 04, 2025 at 10:13:18AM +0100, Sean Young wrote:
>>> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
>>> > Disclaimer: I haven't actually tested the result of the GCC build.
>>>
>>> Let me test this.
>>
>> It doesn't work:
>>
>> # ir-keytable -p ./imon_rsc.o
>> Protocols changed to
>> symbol has unknown section 6
>> bpf_load_program() err=Permission denied
>> 0: R1=ctx() R10=fp0
>> 0: (bf) r6 = r1 ; R1=ctx() R6_w=ctx()
>> 1: (62) *(u32 *)(r10 -4) = 0 ; R10=fp0 fp-8=0000????
>> 2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
>> 3: (18) r1 = 0xffff89ed1318f800 ; R1_w=map_ptr(ks=4,vs=16)
>> 5: (07) r2 += -4 ; R2_w=fp-4
>> 6: (85) call bpf_map_lookup_elem#1 ; R0_w=map_value(ks=4,vs=16)
>> 7: (bf) r4 = r0 ; R0_w=map_value(ks=4,vs=16) R4_w=map_value(ks=4,vs=16)
>> 8: (15) if r0 == 0x0 goto pc+7 ; R0_w=map_value(ks=4,vs=16)
>> 9: (61) r0 = *(u32 *)(r6 +0) ; R0_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R6_w=ctx()
>> 10: (bf) r1 = r0 ; R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R1_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> 11: (bf) r2 = r0 ; R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R2_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> 12: (54) w1 &= -16777216 ; R1_w=scalar(smin=0,smax=umax=umax32=0xff000000,smax32=0x7f000000,var_off=(0x0; 0xff000000))
>> 13: (54) w2 &= -33554432 ; R2=scalar(smin=0,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
>> 14: (16) if w2 == 0x0 goto pc+3 ; R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
>> 15: (16) if w1 == 0x3000000 goto pc+31 47:
>> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> R1=0x3000000
>> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
>> 0xfe000000)) R4=map_value(ks=4,vs=16) R6=ctx() R10=fp0 fp-8=0000????
>> 47: (61) r5 = *(u32 *)(r4 +8) ; R4=map_value(ks=4,vs=16) R5_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> 48: (16) if w5 == 0x1 goto pc+7 56:
>> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> R1=0x3000000
>> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
>> 0xfe000000)) R4=map_value(ks=4,vs=16) R5_w=1 R6=ctx() R10=fp0
>> fp-8=0000????
>> 56: (57) r0 &= 16777215 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
>> 57: (b6) if w0 <= 0x960 goto pc+22 ; R0_w=scalar(smin=umin=smin32=umin32=2401,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
>> 58: (61) r1 = *(u32 *)(r4 +12) ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R4=map_value(ks=4,vs=16)
>> 59: (04) w1 += -4 ; R1=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> 60: (26) if w1 > 0x1 goto pc-11 ; R1=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1))
>> 61: (79) r3 = *(u64 *)(r4 +0) ; R3_w=scalar() R4=map_value(ks=4,vs=16)
>> 62: (57) r3 &= 15 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=15,var_off=(0x0; 0xf))
>> 63: (07) r3 += -1 ; R3_w=scalar(smin=smin32=-1,smax=smax32=14)
>> 64: (25) if r3 > 0xe goto pc+46 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=14,var_off=(0x0; 0xf))
>> 65: (67) r3 <<= 2 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
>> 66: (18) r2 = 0x3c ; R2_w=60
>> 68: (18) r9 = 0x0 ; R9_w=0
>> 70: (0f) r2 += r3 ;
>> R2_w=scalar(smin=umin=smin32=umin32=60,smax=umax=smax32=umax32=116,var_off=(0x0;
>> 0x7c))
>> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> 0x3c))
>> 71: (0f) r9 += r3 ;
>> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> 0x3c))
>> R9_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> 0x3c))
>> 72: (81) r2 = *(s32 *)(r2 +0)
>> R2 invalid mem access 'scalar'
>> processed 40 insns (limit 1000000) max_states_per_insn 0 total_states 3 peak_states 3 mark_read 1
>
> I'll have a look. Thanks.
OK, I can't reproduce it yet because I don't have the hardware (using
loopback doesn't seem to be sufficient, even with Clang).
Could you get the full bpf-* gcc invocation with `ninja --verbose`, and
then append -save-temps to it, and attach the .i it makes?
>
>>
>> Needs some analysis but I don't think your patch is ready for merging.
>>
>> Thanks,
>> Sean
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-05 22:32 ` Sam James
@ 2025-08-06 20:53 ` Sean Young
2025-08-06 21:09 ` Sam James
0 siblings, 1 reply; 13+ messages in thread
From: Sean Young @ 2025-08-06 20:53 UTC (permalink / raw)
To: Sam James; +Cc: James Le Cuirot, linux-media
On Tue, Aug 05, 2025 at 11:32:54PM +0100, Sam James wrote:
> Sam James <sam@gentoo.org> writes:
>
> > Sean Young <sean@mess.org> writes:
> >
> >> On Mon, Aug 04, 2025 at 10:13:18AM +0100, Sean Young wrote:
> >>> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
> >>> > Disclaimer: I haven't actually tested the result of the GCC build.
> >>>
> >>> Let me test this.
> >>
> >> It doesn't work:
> >>
> >> # ir-keytable -p ./imon_rsc.o
> >> Protocols changed to
> >> symbol has unknown section 6
> >> bpf_load_program() err=Permission denied
> >> 0: R1=ctx() R10=fp0
> >> 0: (bf) r6 = r1 ; R1=ctx() R6_w=ctx()
> >> 1: (62) *(u32 *)(r10 -4) = 0 ; R10=fp0 fp-8=0000????
> >> 2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
> >> 3: (18) r1 = 0xffff89ed1318f800 ; R1_w=map_ptr(ks=4,vs=16)
> >> 5: (07) r2 += -4 ; R2_w=fp-4
> >> 6: (85) call bpf_map_lookup_elem#1 ; R0_w=map_value(ks=4,vs=16)
> >> 7: (bf) r4 = r0 ; R0_w=map_value(ks=4,vs=16) R4_w=map_value(ks=4,vs=16)
> >> 8: (15) if r0 == 0x0 goto pc+7 ; R0_w=map_value(ks=4,vs=16)
> >> 9: (61) r0 = *(u32 *)(r6 +0) ; R0_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R6_w=ctx()
> >> 10: (bf) r1 = r0 ; R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R1_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> >> 11: (bf) r2 = r0 ; R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R2_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> >> 12: (54) w1 &= -16777216 ; R1_w=scalar(smin=0,smax=umax=umax32=0xff000000,smax32=0x7f000000,var_off=(0x0; 0xff000000))
> >> 13: (54) w2 &= -33554432 ; R2=scalar(smin=0,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
> >> 14: (16) if w2 == 0x0 goto pc+3 ; R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
> >> 15: (16) if w1 == 0x3000000 goto pc+31 47:
> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> >> R1=0x3000000
> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R6=ctx() R10=fp0 fp-8=0000????
> >> 47: (61) r5 = *(u32 *)(r4 +8) ; R4=map_value(ks=4,vs=16) R5_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> >> 48: (16) if w5 == 0x1 goto pc+7 56:
> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> >> R1=0x3000000
> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R5_w=1 R6=ctx() R10=fp0
> >> fp-8=0000????
> >> 56: (57) r0 &= 16777215 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
> >> 57: (b6) if w0 <= 0x960 goto pc+22 ; R0_w=scalar(smin=umin=smin32=umin32=2401,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
> >> 58: (61) r1 = *(u32 *)(r4 +12) ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R4=map_value(ks=4,vs=16)
> >> 59: (04) w1 += -4 ; R1=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
> >> 60: (26) if w1 > 0x1 goto pc-11 ; R1=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1))
> >> 61: (79) r3 = *(u64 *)(r4 +0) ; R3_w=scalar() R4=map_value(ks=4,vs=16)
> >> 62: (57) r3 &= 15 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=15,var_off=(0x0; 0xf))
> >> 63: (07) r3 += -1 ; R3_w=scalar(smin=smin32=-1,smax=smax32=14)
> >> 64: (25) if r3 > 0xe goto pc+46 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=14,var_off=(0x0; 0xf))
> >> 65: (67) r3 <<= 2 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
> >> 66: (18) r2 = 0x3c ; R2_w=60
> >> 68: (18) r9 = 0x0 ; R9_w=0
> >> 70: (0f) r2 += r3 ;
> >> R2_w=scalar(smin=umin=smin32=umin32=60,smax=umax=smax32=umax32=116,var_off=(0x0;
> >> 0x7c))
> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
> >> 0x3c))
> >> 71: (0f) r9 += r3 ;
> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
> >> 0x3c))
> >> R9_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
> >> 0x3c))
> >> 72: (81) r2 = *(s32 *)(r2 +0)
> >> R2 invalid mem access 'scalar'
> >> processed 40 insns (limit 1000000) max_states_per_insn 0 total_states 3 peak_states 3 mark_read 1
> >
> > I'll have a look. Thanks.
>
> OK, I can't reproduce it yet because I don't have the hardware (using
> loopback doesn't seem to be sufficient, even with Clang).
>
> Could you get the full bpf-* gcc invocation with `ninja --verbose`, and
> then append -save-temps to it, and attach the .i it makes?
Works fine with rc-loopback.
The problem is that gcc compiles this down to a lookup table which is then
stored in the .rodata section.
https://git.linuxtv.org/v4l-utils.git/tree/utils/keytable/bpf_protocols/imon_rsc.c#n97
Then ir-keytable fails to load and relocate the rodata section. Note the
error:
symbol has unknown section 6
section 6 is the rodata section.
ir-keytable simply has no handling for .rodata right now. I am not sure how
bpf handles .rodata (if at all), needs more investigation.
Sean
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-06 20:53 ` Sean Young
@ 2025-08-06 21:09 ` Sam James
2025-08-08 1:19 ` Sam James
0 siblings, 1 reply; 13+ messages in thread
From: Sam James @ 2025-08-06 21:09 UTC (permalink / raw)
To: Sean Young; +Cc: James Le Cuirot, linux-media
Sean Young <sean@mess.org> writes:
> On Tue, Aug 05, 2025 at 11:32:54PM +0100, Sam James wrote:
>> Sam James <sam@gentoo.org> writes:
>>
>> > Sean Young <sean@mess.org> writes:
>> >
>> >> On Mon, Aug 04, 2025 at 10:13:18AM +0100, Sean Young wrote:
>> >>> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
>> >>> > Disclaimer: I haven't actually tested the result of the GCC build.
>> >>>
>> >>> Let me test this.
>> >>
>> >> It doesn't work:
>> >>
>> >> # ir-keytable -p ./imon_rsc.o
>> >> Protocols changed to
>> >> symbol has unknown section 6
>> >> bpf_load_program() err=Permission denied
>> >> 0: R1=ctx() R10=fp0
>> >> 0: (bf) r6 = r1 ; R1=ctx() R6_w=ctx()
>> >> 1: (62) *(u32 *)(r10 -4) = 0 ; R10=fp0 fp-8=0000????
>> >> 2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
>> >> 3: (18) r1 = 0xffff89ed1318f800 ; R1_w=map_ptr(ks=4,vs=16)
>> >> 5: (07) r2 += -4 ; R2_w=fp-4
>> >> 6: (85) call bpf_map_lookup_elem#1 ; R0_w=map_value(ks=4,vs=16)
>> >> 7: (bf) r4 = r0 ; R0_w=map_value(ks=4,vs=16) R4_w=map_value(ks=4,vs=16)
>> >> 8: (15) if r0 == 0x0 goto pc+7 ; R0_w=map_value(ks=4,vs=16)
>> >> 9: (61) r0 = *(u32 *)(r6 +0) ; R0_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R6_w=ctx()
>> >> 10: (bf) r1 = r0 ;
>> >> R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>> >> 0xffffffff))
>> >> R1_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>> >> 0xffffffff))
>> >> 11: (bf) r2 = r0 ;
>> >> R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>> >> 0xffffffff))
>> >> R2_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>> >> 0xffffffff))
>> >> 12: (54) w1 &= -16777216 ; R1_w=scalar(smin=0,smax=umax=umax32=0xff000000,smax32=0x7f000000,var_off=(0x0; 0xff000000))
>> >> 13: (54) w2 &= -33554432 ; R2=scalar(smin=0,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
>> >> 14: (16) if w2 == 0x0 goto pc+3 ; R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
>> >> 15: (16) if w1 == 0x3000000 goto pc+31 47:
>> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> >> R1=0x3000000
>> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
>> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R6=ctx() R10=fp0 fp-8=0000????
>> >> 47: (61) r5 = *(u32 *)(r4 +8) ; R4=map_value(ks=4,vs=16) R5_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> >> 48: (16) if w5 == 0x1 goto pc+7 56:
>> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> >> R1=0x3000000
>> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
>> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R5_w=1 R6=ctx() R10=fp0
>> >> fp-8=0000????
>> >> 56: (57) r0 &= 16777215 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
>> >> 57: (b6) if w0 <= 0x960 goto pc+22 ; R0_w=scalar(smin=umin=smin32=umin32=2401,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
>> >> 58: (61) r1 = *(u32 *)(r4 +12) ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R4=map_value(ks=4,vs=16)
>> >> 59: (04) w1 += -4 ; R1=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>> >> 60: (26) if w1 > 0x1 goto pc-11 ; R1=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1))
>> >> 61: (79) r3 = *(u64 *)(r4 +0) ; R3_w=scalar() R4=map_value(ks=4,vs=16)
>> >> 62: (57) r3 &= 15 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=15,var_off=(0x0; 0xf))
>> >> 63: (07) r3 += -1 ; R3_w=scalar(smin=smin32=-1,smax=smax32=14)
>> >> 64: (25) if r3 > 0xe goto pc+46 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=14,var_off=(0x0; 0xf))
>> >> 65: (67) r3 <<= 2 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
>> >> 66: (18) r2 = 0x3c ; R2_w=60
>> >> 68: (18) r9 = 0x0 ; R9_w=0
>> >> 70: (0f) r2 += r3 ;
>> >> R2_w=scalar(smin=umin=smin32=umin32=60,smax=umax=smax32=umax32=116,var_off=(0x0;
>> >> 0x7c))
>> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> >> 0x3c))
>> >> 71: (0f) r9 += r3 ;
>> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> >> 0x3c))
>> >> R9_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>> >> 0x3c))
>> >> 72: (81) r2 = *(s32 *)(r2 +0)
>> >> R2 invalid mem access 'scalar'
>> >> processed 40 insns (limit 1000000) max_states_per_insn 0 total_states 3 peak_states 3 mark_read 1
>> >
>> > I'll have a look. Thanks.
>>
>> OK, I can't reproduce it yet because I don't have the hardware (using
>> loopback doesn't seem to be sufficient, even with Clang).
>>
>> Could you get the full bpf-* gcc invocation with `ninja --verbose`, and
>> then append -save-temps to it, and attach the .i it makes?
>
> Works fine with rc-loopback.
>
Huh, okay. I couldn't get the verify failure to spit out.
> The problem is that gcc compiles this down to a lookup table which is then
> stored in the .rodata section.
>
> https://git.linuxtv.org/v4l-utils.git/tree/utils/keytable/bpf_protocols/imon_rsc.c#n97
>
> Then ir-keytable fails to load and relocate the rodata section. Note the
> error:
>
> symbol has unknown section 6
>
> section 6 is the rodata section.
>
> ir-keytable simply has no handling for .rodata right now. I am not sure how
> bpf handles .rodata (if at all), needs more investigation.
I'd spotted that and naively assumed it was unrelated given I couldn't
get the verify failure even with Clang. Mea culpa!
>
>
> Sean
sam
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-06 21:09 ` Sam James
@ 2025-08-08 1:19 ` Sam James
2025-08-08 12:42 ` Sean Young
0 siblings, 1 reply; 13+ messages in thread
From: Sam James @ 2025-08-08 1:19 UTC (permalink / raw)
To: Sean Young; +Cc: James Le Cuirot, linux-media
Sam James <sam@gentoo.org> writes:
> Sean Young <sean@mess.org> writes:
>
>> On Tue, Aug 05, 2025 at 11:32:54PM +0100, Sam James wrote:
>>> Sam James <sam@gentoo.org> writes:
>>>
>>> > Sean Young <sean@mess.org> writes:
>>> >
>>> >> On Mon, Aug 04, 2025 at 10:13:18AM +0100, Sean Young wrote:
>>> >>> On Sun, Aug 03, 2025 at 09:17:59AM +0100, James Le Cuirot wrote:
>>> >>> > Disclaimer: I haven't actually tested the result of the GCC build.
>>> >>>
>>> >>> Let me test this.
>>> >>
>>> >> It doesn't work:
>>> >>
>>> >> # ir-keytable -p ./imon_rsc.o
>>> >> Protocols changed to
>>> >> symbol has unknown section 6
>>> >> bpf_load_program() err=Permission denied
>>> >> 0: R1=ctx() R10=fp0
>>> >> 0: (bf) r6 = r1 ; R1=ctx() R6_w=ctx()
>>> >> 1: (62) *(u32 *)(r10 -4) = 0 ; R10=fp0 fp-8=0000????
>>> >> 2: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
>>> >> 3: (18) r1 = 0xffff89ed1318f800 ; R1_w=map_ptr(ks=4,vs=16)
>>> >> 5: (07) r2 += -4 ; R2_w=fp-4
>>> >> 6: (85) call bpf_map_lookup_elem#1 ; R0_w=map_value(ks=4,vs=16)
>>> >> 7: (bf) r4 = r0 ; R0_w=map_value(ks=4,vs=16) R4_w=map_value(ks=4,vs=16)
>>> >> 8: (15) if r0 == 0x0 goto pc+7 ; R0_w=map_value(ks=4,vs=16)
>>> >> 9: (61) r0 = *(u32 *)(r6 +0) ; R0_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R6_w=ctx()
>>> >> 10: (bf) r1 = r0 ;
>>> >> R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>>> >> 0xffffffff))
>>> >> R1_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>>> >> 0xffffffff))
>>> >> 11: (bf) r2 = r0 ;
>>> >> R0_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>>> >> 0xffffffff))
>>> >> R2_w=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0;
>>> >> 0xffffffff))
>>> >> 12: (54) w1 &= -16777216 ; R1_w=scalar(smin=0,smax=umax=umax32=0xff000000,smax32=0x7f000000,var_off=(0x0; 0xff000000))
>>> >> 13: (54) w2 &= -33554432 ; R2=scalar(smin=0,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
>>> >> 14: (16) if w2 == 0x0 goto pc+3 ; R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0; 0xfe000000))
>>> >> 15: (16) if w1 == 0x3000000 goto pc+31 47:
>>> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>>> >> R1=0x3000000
>>> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
>>> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R6=ctx() R10=fp0 fp-8=0000????
>>> >> 47: (61) r5 = *(u32 *)(r4 +8) ; R4=map_value(ks=4,vs=16) R5_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>>> >> 48: (16) if w5 == 0x1 goto pc+7 56:
>>> >> R0=scalar(id=1,smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>>> >> R1=0x3000000
>>> >> R2=scalar(smin=umin=umin32=1,smax=umax=umax32=0xfe000000,smax32=0x7e000000,var_off=(0x0;
>>> >> 0xfe000000)) R4=map_value(ks=4,vs=16) R5_w=1 R6=ctx() R10=fp0
>>> >> fp-8=0000????
>>> >> 56: (57) r0 &= 16777215 ; R0_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
>>> >> 57: (b6) if w0 <= 0x960 goto pc+22 ; R0_w=scalar(smin=umin=smin32=umin32=2401,smax=umax=smax32=umax32=0xffffff,var_off=(0x0; 0xffffff))
>>> >> 58: (61) r1 = *(u32 *)(r4 +12) ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R4=map_value(ks=4,vs=16)
>>> >> 59: (04) w1 += -4 ; R1=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
>>> >> 60: (26) if w1 > 0x1 goto pc-11 ; R1=scalar(smin=smin32=0,smax=umax=smax32=umax32=1,var_off=(0x0; 0x1))
>>> >> 61: (79) r3 = *(u64 *)(r4 +0) ; R3_w=scalar() R4=map_value(ks=4,vs=16)
>>> >> 62: (57) r3 &= 15 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=15,var_off=(0x0; 0xf))
>>> >> 63: (07) r3 += -1 ; R3_w=scalar(smin=smin32=-1,smax=smax32=14)
>>> >> 64: (25) if r3 > 0xe goto pc+46 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=14,var_off=(0x0; 0xf))
>>> >> 65: (67) r3 <<= 2 ; R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0; 0x3c))
>>> >> 66: (18) r2 = 0x3c ; R2_w=60
>>> >> 68: (18) r9 = 0x0 ; R9_w=0
>>> >> 70: (0f) r2 += r3 ;
>>> >> R2_w=scalar(smin=umin=smin32=umin32=60,smax=umax=smax32=umax32=116,var_off=(0x0;
>>> >> 0x7c))
>>> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>>> >> 0x3c))
>>> >> 71: (0f) r9 += r3 ;
>>> >> R3_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>>> >> 0x3c))
>>> >> R9_w=scalar(smin=smin32=0,smax=umax=smax32=umax32=56,var_off=(0x0;
>>> >> 0x3c))
>>> >> 72: (81) r2 = *(s32 *)(r2 +0)
>>> >> R2 invalid mem access 'scalar'
>>> >> processed 40 insns (limit 1000000) max_states_per_insn 0 total_states 3 peak_states 3 mark_read 1
>>> >
>>> > I'll have a look. Thanks.
>>>
>>> OK, I can't reproduce it yet because I don't have the hardware (using
>>> loopback doesn't seem to be sufficient, even with Clang).
>>>
>>> Could you get the full bpf-* gcc invocation with `ninja --verbose`, and
>>> then append -save-temps to it, and attach the .i it makes?
>>
>> Works fine with rc-loopback.
>>
>
> Huh, okay. I couldn't get the verify failure to spit out.
Nevermind, I got there, I was missing a kernel config option.
>
>> The problem is that gcc compiles this down to a lookup table which is then
>> stored in the .rodata section.
>>
>> https://git.linuxtv.org/v4l-utils.git/tree/utils/keytable/bpf_protocols/imon_rsc.c#n97
>>
>> Then ir-keytable fails to load and relocate the rodata section. Note the
>> error:
>>
>> symbol has unknown section 6
>>
>> section 6 is the rodata section.
>>
>> ir-keytable simply has no handling for .rodata right now. I am not sure how
>> bpf handles .rodata (if at all), needs more investigation.
>
With -fno-tree-switch-conversion, the program loads for me.
> I'd spotted that and naively assumed it was unrelated given I couldn't
> get the verify failure even with Clang. Mea culpa!
>
>>
>>
>> Sean
>
> sam
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] meson: Allow BPF code to be built with GCC
2025-08-08 1:19 ` Sam James
@ 2025-08-08 12:42 ` Sean Young
0 siblings, 0 replies; 13+ messages in thread
From: Sean Young @ 2025-08-08 12:42 UTC (permalink / raw)
To: Sam James; +Cc: James Le Cuirot, linux-media
On Fri, Aug 08, 2025 at 02:19:33AM +0100, Sam James wrote:
> Sam James <sam@gentoo.org> writes:
> > Sean Young <sean@mess.org> writes:
> >> The problem is that gcc compiles this down to a lookup table which is then
> >> stored in the .rodata section.
> >>
> >> https://git.linuxtv.org/v4l-utils.git/tree/utils/keytable/bpf_protocols/imon_rsc.c#n97
> >>
> >> Then ir-keytable fails to load and relocate the rodata section. Note the
> >> error:
> >>
> >> symbol has unknown section 6
> >>
> >> section 6 is the rodata section.
> >>
> >> ir-keytable simply has no handling for .rodata right now. I am not sure how
> >> bpf handles .rodata (if at all), needs more investigation.
> >
>
> With -fno-tree-switch-conversion, the program loads for me.
Yes, that works. Let's use that in meson.build.
Thanks,
Sean
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2] meson: Allow BPF code to be built with GCC
2025-08-03 8:17 [PATCH] meson: Allow BPF code to be built with GCC James Le Cuirot
2025-08-04 9:13 ` Sean Young
@ 2025-08-10 14:20 ` James Le Cuirot
2025-08-12 13:48 ` Sean Young
1 sibling, 1 reply; 13+ messages in thread
From: James Le Cuirot @ 2025-08-10 14:20 UTC (permalink / raw)
To: linux-media; +Cc: Sam James, James Le Cuirot
GCC can also target BPF, but it does not understand the "-target bpf"
arguments passed to Clang.
Detect it as either bpf-gcc, bpf-none-gcc, or bpf-unknown-none-gcc, the
same as systemd does.
Determine the include paths with the compiler used by the rest of the
build rather than Clang, which might not be installed or might not give
the right answer, especially when cross-compiling.
Check whether Clang actually supports the BPF target so that
auto-detection doesn't cause the build to fail when it doesn't.
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
---
meson.build | 25 ++++++++++++++++++-
.../keytable/bpf_protocols/cc_sys_includes.sh | 10 ++++++++
.../bpf_protocols/clang_sys_includes.sh | 9 -------
utils/keytable/bpf_protocols/meson.build | 12 ++++-----
utils/keytable/meson.build | 2 +-
5 files changed, 41 insertions(+), 17 deletions(-)
create mode 100755 utils/keytable/bpf_protocols/cc_sys_includes.sh
delete mode 100755 utils/keytable/bpf_protocols/clang_sys_includes.sh
This revision adds the -ftree-switch-conversion flag for GCC, which
reportedly fixes the "invalid mem access" error. I couldn't figure out
how to test without any hardware, so I wasn't able to reproduce the
issue myself, but I trust that it works now.
diff --git a/meson.build b/meson.build
index 88781e59..62d271b4 100644
--- a/meson.build
+++ b/meson.build
@@ -83,11 +83,34 @@ endif
v4l2_utils_incdir = include_directories(v4l2_utils_incdir_arr)
prog_bash = find_program('bash')
-prog_clang = find_program('clang', required : get_option('bpf'))
prog_doxygen = find_program('doxygen', required : get_option('doxygen-doc'))
prog_grep = find_program('grep')
prog_perl = find_program('perl')
+if get_option('bpf').allowed()
+ bpf_args = []
+ prog_bpf = find_program('bpf-gcc',
+ 'bpf-none-gcc',
+ 'bpf-unknown-none-gcc',
+ required : false)
+
+ if prog_bpf.found()
+ bpf_args += ['-fno-tree-switch-conversion']
+ else
+ prog_bpf = find_program('clang', required : get_option('bpf'))
+ if prog_bpf.found()
+ target_bpf = run_command(prog_bpf, '-target', 'bpf', '--print-supported-cpus', check : get_option('bpf').enabled())
+ if target_bpf.returncode() == 0
+ bpf_args += ['-target', 'bpf']
+ else
+ prog_bpf = disabler()
+ endif
+ endif
+ endif
+else
+ prog_bpf = disabler()
+endif
+
dep_alsa = dependency('alsa', required : false)
if dep_alsa.found()
conf.set('HAVE_ALSA', 1)
diff --git a/utils/keytable/bpf_protocols/cc_sys_includes.sh b/utils/keytable/bpf_protocols/cc_sys_includes.sh
new file mode 100755
index 00000000..0a8fa277
--- /dev/null
+++ b/utils/keytable/bpf_protocols/cc_sys_includes.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Get C compiler's default includes on this system, as the BPF toolchain
+# generally doesn't see the Linux headers. This fixes "missing" files on some
+# architectures/distros, such as asm/byteorder.h, asm/socket.h, asm/sockios.h,
+# sys/cdefs.h etc.
+#
+# Use '-idirafter': Don't interfere with include mechanics except where the
+# build would have failed anyways.
+"$@" -v -E - </dev/null 2>&1 \
+ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
diff --git a/utils/keytable/bpf_protocols/clang_sys_includes.sh b/utils/keytable/bpf_protocols/clang_sys_includes.sh
deleted file mode 100755
index 9dc4af12..00000000
--- a/utils/keytable/bpf_protocols/clang_sys_includes.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-# Get Clang's default includes on this system, as opposed to those seen by
-# '-target bpf'. This fixes "missing" files on some architectures/distros,
-# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
-#
-# Use '-idirafter': Don't interfere with include mechanics except where the
-# build would have failed anyways.
-$CLANG -v -E - </dev/null 2>&1 \
- | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
diff --git a/utils/keytable/bpf_protocols/meson.build b/utils/keytable/bpf_protocols/meson.build
index 1e4f0064..dbb926c4 100644
--- a/utils/keytable/bpf_protocols/meson.build
+++ b/utils/keytable/bpf_protocols/meson.build
@@ -10,9 +10,9 @@ bpf_protocols_files = [
'xbox-dvd',
]
-clang_sys_includes = run_command('clang_sys_includes.sh',
- check : true,
- env : ['CLANG=' + prog_clang.full_path()])
+bpf_args += run_command('cc_sys_includes.sh',
+ cc.cmd_array(),
+ check : true).stdout().split()
foreach file : bpf_protocols_files
output = file + '.o'
@@ -21,9 +21,9 @@ foreach file : bpf_protocols_files
output : output,
input : input,
command : [
- prog_clang,
- clang_sys_includes.stdout().split(),
- '-D__linux__', '-fno-stack-protector', '-target', 'bpf',
+ prog_bpf,
+ bpf_args,
+ '-D__linux__', '-fno-stack-protector',
'-O2', '-c', '@INPUT@', '-o', '@OUTPUT@',
],
install : true,
diff --git a/utils/keytable/meson.build b/utils/keytable/meson.build
index e214e0b5..56e61a79 100644
--- a/utils/keytable/meson.build
+++ b/utils/keytable/meson.build
@@ -22,7 +22,7 @@ ir_keytable_c_args = [
'-DIR_KEYTABLE_USER_DIR="@0@"'.format(ir_keytable_user_dir),
]
-ir_bpf_enabled = prog_clang.found() and dep_libbpf.found() and dep_libelf.found()
+ir_bpf_enabled = prog_bpf.found() and dep_libbpf.found() and dep_libelf.found()
if ir_bpf_enabled
ir_keytable_sources += files(
--
2.50.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2] meson: Allow BPF code to be built with GCC
2025-08-10 14:20 ` [PATCH v2] " James Le Cuirot
@ 2025-08-12 13:48 ` Sean Young
0 siblings, 0 replies; 13+ messages in thread
From: Sean Young @ 2025-08-12 13:48 UTC (permalink / raw)
To: James Le Cuirot; +Cc: linux-media, Sam James
On Sun, Aug 10, 2025 at 03:20:06PM +0100, James Le Cuirot wrote:
> GCC can also target BPF, but it does not understand the "-target bpf"
> arguments passed to Clang.
>
> Detect it as either bpf-gcc, bpf-none-gcc, or bpf-unknown-none-gcc, the
> same as systemd does.
>
> Determine the include paths with the compiler used by the rest of the
> build rather than Clang, which might not be installed or might not give
> the right answer, especially when cross-compiling.
>
> Check whether Clang actually supports the BPF target so that
> auto-detection doesn't cause the build to fail when it doesn't.
>
> Signed-off-by: James Le Cuirot <chewi@gentoo.org>
Applied. Thank you very much!
Sean
> ---
> meson.build | 25 ++++++++++++++++++-
> .../keytable/bpf_protocols/cc_sys_includes.sh | 10 ++++++++
> .../bpf_protocols/clang_sys_includes.sh | 9 -------
> utils/keytable/bpf_protocols/meson.build | 12 ++++-----
> utils/keytable/meson.build | 2 +-
> 5 files changed, 41 insertions(+), 17 deletions(-)
> create mode 100755 utils/keytable/bpf_protocols/cc_sys_includes.sh
> delete mode 100755 utils/keytable/bpf_protocols/clang_sys_includes.sh
>
> This revision adds the -ftree-switch-conversion flag for GCC, which
> reportedly fixes the "invalid mem access" error. I couldn't figure out
> how to test without any hardware, so I wasn't able to reproduce the
> issue myself, but I trust that it works now.
>
> diff --git a/meson.build b/meson.build
> index 88781e59..62d271b4 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -83,11 +83,34 @@ endif
> v4l2_utils_incdir = include_directories(v4l2_utils_incdir_arr)
>
> prog_bash = find_program('bash')
> -prog_clang = find_program('clang', required : get_option('bpf'))
> prog_doxygen = find_program('doxygen', required : get_option('doxygen-doc'))
> prog_grep = find_program('grep')
> prog_perl = find_program('perl')
>
> +if get_option('bpf').allowed()
> + bpf_args = []
> + prog_bpf = find_program('bpf-gcc',
> + 'bpf-none-gcc',
> + 'bpf-unknown-none-gcc',
> + required : false)
> +
> + if prog_bpf.found()
> + bpf_args += ['-fno-tree-switch-conversion']
> + else
> + prog_bpf = find_program('clang', required : get_option('bpf'))
> + if prog_bpf.found()
> + target_bpf = run_command(prog_bpf, '-target', 'bpf', '--print-supported-cpus', check : get_option('bpf').enabled())
> + if target_bpf.returncode() == 0
> + bpf_args += ['-target', 'bpf']
> + else
> + prog_bpf = disabler()
> + endif
> + endif
> + endif
> +else
> + prog_bpf = disabler()
> +endif
> +
> dep_alsa = dependency('alsa', required : false)
> if dep_alsa.found()
> conf.set('HAVE_ALSA', 1)
> diff --git a/utils/keytable/bpf_protocols/cc_sys_includes.sh b/utils/keytable/bpf_protocols/cc_sys_includes.sh
> new file mode 100755
> index 00000000..0a8fa277
> --- /dev/null
> +++ b/utils/keytable/bpf_protocols/cc_sys_includes.sh
> @@ -0,0 +1,10 @@
> +#!/bin/sh
> +# Get C compiler's default includes on this system, as the BPF toolchain
> +# generally doesn't see the Linux headers. This fixes "missing" files on some
> +# architectures/distros, such as asm/byteorder.h, asm/socket.h, asm/sockios.h,
> +# sys/cdefs.h etc.
> +#
> +# Use '-idirafter': Don't interfere with include mechanics except where the
> +# build would have failed anyways.
> +"$@" -v -E - </dev/null 2>&1 \
> + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
> diff --git a/utils/keytable/bpf_protocols/clang_sys_includes.sh b/utils/keytable/bpf_protocols/clang_sys_includes.sh
> deleted file mode 100755
> index 9dc4af12..00000000
> --- a/utils/keytable/bpf_protocols/clang_sys_includes.sh
> +++ /dev/null
> @@ -1,9 +0,0 @@
> -#!/bin/sh
> -# Get Clang's default includes on this system, as opposed to those seen by
> -# '-target bpf'. This fixes "missing" files on some architectures/distros,
> -# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
> -#
> -# Use '-idirafter': Don't interfere with include mechanics except where the
> -# build would have failed anyways.
> -$CLANG -v -E - </dev/null 2>&1 \
> - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }'
> diff --git a/utils/keytable/bpf_protocols/meson.build b/utils/keytable/bpf_protocols/meson.build
> index 1e4f0064..dbb926c4 100644
> --- a/utils/keytable/bpf_protocols/meson.build
> +++ b/utils/keytable/bpf_protocols/meson.build
> @@ -10,9 +10,9 @@ bpf_protocols_files = [
> 'xbox-dvd',
> ]
>
> -clang_sys_includes = run_command('clang_sys_includes.sh',
> - check : true,
> - env : ['CLANG=' + prog_clang.full_path()])
> +bpf_args += run_command('cc_sys_includes.sh',
> + cc.cmd_array(),
> + check : true).stdout().split()
>
> foreach file : bpf_protocols_files
> output = file + '.o'
> @@ -21,9 +21,9 @@ foreach file : bpf_protocols_files
> output : output,
> input : input,
> command : [
> - prog_clang,
> - clang_sys_includes.stdout().split(),
> - '-D__linux__', '-fno-stack-protector', '-target', 'bpf',
> + prog_bpf,
> + bpf_args,
> + '-D__linux__', '-fno-stack-protector',
> '-O2', '-c', '@INPUT@', '-o', '@OUTPUT@',
> ],
> install : true,
> diff --git a/utils/keytable/meson.build b/utils/keytable/meson.build
> index e214e0b5..56e61a79 100644
> --- a/utils/keytable/meson.build
> +++ b/utils/keytable/meson.build
> @@ -22,7 +22,7 @@ ir_keytable_c_args = [
> '-DIR_KEYTABLE_USER_DIR="@0@"'.format(ir_keytable_user_dir),
> ]
>
> -ir_bpf_enabled = prog_clang.found() and dep_libbpf.found() and dep_libelf.found()
> +ir_bpf_enabled = prog_bpf.found() and dep_libbpf.found() and dep_libelf.found()
>
> if ir_bpf_enabled
> ir_keytable_sources += files(
> --
> 2.50.1
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-08-12 13:48 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-03 8:17 [PATCH] meson: Allow BPF code to be built with GCC James Le Cuirot
2025-08-04 9:13 ` Sean Young
2025-08-04 20:22 ` Sam James
2025-08-04 20:34 ` James Le Cuirot
2025-08-05 11:32 ` Sean Young
2025-08-05 15:03 ` Sam James
2025-08-05 22:32 ` Sam James
2025-08-06 20:53 ` Sean Young
2025-08-06 21:09 ` Sam James
2025-08-08 1:19 ` Sam James
2025-08-08 12:42 ` Sean Young
2025-08-10 14:20 ` [PATCH v2] " James Le Cuirot
2025-08-12 13:48 ` Sean Young
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).