diff mbox series

[v1,2/2] systemd: bpf-framework: pass STAGING_INCDIR to eBPF compiler

Message ID 20240609084321.1070686-1-johannes.schneider@leica-geosystems.com
State New
Headers show
Series None | expand

Commit Message

SCHNEIDER Johannes June 9, 2024, 8:43 a.m. UTC
The eBPFs are pre-compiled during the systemd-build with a different
compiler than the cross-compiler used to build systemd itself.

This is either a 'clang-native' or a gcc (bpf-unknown-none) which do
not see the BUILD_CFLAGS set -isystem ${STAGING_INCDIR}. For this the
meson.build file constructing the compiler call had to be patched to
handle this bitbake specific setup.

Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
---
 ...bitbake-pass-STAGING_INCDIR-to-clang.patch | 42 +++++++++++++++++++
 meta/recipes-core/systemd/systemd_255.6.bb    |  1 +
 2 files changed, 43 insertions(+)
 create mode 100644 meta/recipes-core/systemd/systemd/0023-bitbake-pass-STAGING_INCDIR-to-clang.patch

Comments

Ross Burton June 18, 2024, 4:57 p.m. UTC | #1
I went to have a quick look at this but can’t built bpftool:

ERROR: bpftool-native-1.0-r0 do_compile: oe_runmake failed
ERROR: bpftool-native-1.0-r0 do_compile: ExecutionError('/work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/temp/run.do_compi)
ERROR: Logfile of failure stored in: /work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/temp/log.do_compile.1052635
Log data follows:
| DEBUG: Executing shell function do_compile
| NOTE: make -j 64 V=1 -C /work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/bpf/bpftool O=/work/ross/build/tmp/work/aarcn
| make: Entering directory '/work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/bpf/bpftool'
| gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?
|
| Auto-detecting system features:
| ...                         clang-bpf-co-re: [ OFF ]
| ...                                    llvm: [ OFF ]
| ...                                  libcap: [ OFF ]
| ...                                  libbfd: [ OFF ]
|
| make -C /work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/lib/bpf OUTPUT=/work/ross/build/tmp/work/aarch64-linux/bpfto\
| 	DESTDIR=/work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/bpftool-1.0/libbpf prefix= /work/ross/build/tmp/work/aarchs
| make[1]: Entering directory '/work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/lib/bpf'
| gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?
| gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?

Looks like a problem with the host compiler being passed target flags.  Have you seen this?

Ross
Ross Burton June 18, 2024, 6:54 p.m. UTC | #2
On 18 Jun 2024, at 17:57, Ross Burton via lists.openembedded.org <ross.burton=arm.com@lists.openembedded.org> wrote:
> 
> I went to have a quick look at this but can’t built bpftool:
> 
> ERROR: bpftool-native-1.0-r0 do_compile: oe_runmake failed
> ERROR: bpftool-native-1.0-r0 do_compile: ExecutionError('/work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/temp/run.do_compi)
> ERROR: Logfile of failure stored in: /work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/temp/log.do_compile.1052635
> Log data follows:
> | DEBUG: Executing shell function do_compile
> | NOTE: make -j 64 V=1 -C /work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/bpf/bpftool O=/work/ross/build/tmp/work/aarcn
> | make: Entering directory '/work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/bpf/bpftool'
> | gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?
> |
> | Auto-detecting system features:
> | ...                         clang-bpf-co-re: [ OFF ]
> | ...                                    llvm: [ OFF ]
> | ...                                  libcap: [ OFF ]
> | ...                                  libbfd: [ OFF ]
> |
> | make -C /work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/lib/bpf OUTPUT=/work/ross/build/tmp/work/aarch64-linux/bpfto\
> | DESTDIR=/work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/bpftool-1.0/libbpf prefix= /work/ross/build/tmp/work/aarchs
> | make[1]: Entering directory '/work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/lib/bpf'
> | gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?
> | gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?
> 
> Looks like a problem with the host compiler being passed target flags.  Have you seen this?

Yes, bpftool is passing DEBUG_PREFIX_MAP to the host compiler when building natively, which won’t work.

I worked around that and had a look.  A less ugly and probably upstreamable solution might be to add —sysroot to propagate_cflags in meson.build, and add the sysroot to CFLAGS directly in the recipe.  For historical reasons we pass the sysroot via CC, but specifying it twice won’t hurt.

Ross
SCHNEIDER Johannes June 20, 2024, 10:23 a.m. UTC | #3
Hoi,

> >
> > I went to have a quick look at this but can’t built bpftool:
> >
> > ERROR: bpftool-native-1.0-r0 do_compile: oe_runmake failed
> > ERROR: bpftool-native-1.0-r0 do_compile: ExecutionError('/work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/temp/run.do_compi)
> > ERROR: Logfile of failure stored in: /work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/temp/log.do_compile.1052635
> > Log data follows:
> > | DEBUG: Executing shell function do_compile
> > | NOTE: make -j 64 V=1 -C /work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/bpf/bpftool O=/work/ross/build/tmp/work/aarcn
> > | make: Entering directory '/work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/bpf/bpftool'
> > | gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?
> > |
> > | Auto-detecting system features:
> > | ...                         clang-bpf-co-re: [ OFF ]
> > | ...                                    llvm: [ OFF ]
> > | ...                                  libcap: [ OFF ]
> > | ...                                  libbfd: [ OFF ]
> > |
> > | make -C /work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/lib/bpf OUTPUT=/work/ross/build/tmp/work/aarch64-linux/bpfto\
> > | DESTDIR=/work/ross/build/tmp/work/aarch64-linux/bpftool-native/1.0/bpftool-1.0/libbpf prefix= /work/ross/build/tmp/work/aarchs
> > | make[1]: Entering directory '/work/ross/build/tmp/work-shared/qemuarm64/kernel-source/tools/lib/bpf'
> > | gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?
> > | gcc: error: unrecognized command-line option ‘-fcanon-prefix-map’; did you mean ‘-fmacro-prefix-map=’?
> >
> > Looks like a problem with the host compiler being passed target flags.  Have you seen this?
>
> Yes, bpftool is passing DEBUG_PREFIX_MAP to the host compiler when building natively, which won’t work.
>
> I worked around that and had a look.  A less ugly and probably upstreamable solution might be to add —sysroot to propagate_cflags in meson.build, and add the sysroot to CFLAGS directly in the recipe.  For historical reasons we pass the sysroot via CC, but specifying it twice won’t hurt.
>
> Ross
>

just tried out your hint with the '--sysroot=`, works wonderfully
-> i'll rework the patchset into v2 to use that instead


thanks!

gruß
Johannes
diff mbox series

Patch

diff --git a/meta/recipes-core/systemd/systemd/0023-bitbake-pass-STAGING_INCDIR-to-clang.patch b/meta/recipes-core/systemd/systemd/0023-bitbake-pass-STAGING_INCDIR-to-clang.patch
new file mode 100644
index 0000000000..a6d4d7a81d
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0023-bitbake-pass-STAGING_INCDIR-to-clang.patch
@@ -0,0 +1,42 @@ 
+From 4f4b3d662e5475b375808cea3a6a90d61b6c9522 Mon Sep 17 00:00:00 2001
+From: Johannes Schneider <johannes.schneider@leica-geosystems.com>
+Date: Sat, 8 Jun 2024 18:19:39 +0200
+Subject: [PATCH] bitbake: pass STAGING_INCDIR to clang
+
+Pass bitbakes STAGING_INCDIR as header searchpath to clang/gcc, where
+it can&should look for the libbpf headers when it compiles the BPFs.
+
+This is "the least ugly hack", compared to other alternatives like for example
+what '-Defi-includedir=...' did (creating an extra option to smuggle in bitbake
+variables).
+
+Ideally the compiler would use the BUILD_CFLAGS set by bitbake, which
+set among other things also the corretc -isystem...; but haven't found
+a good way to do so in meson (yet) :-P
+
+Upstream-Status: Inappropriate [oe specific]
+Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
+---
+ meson.build | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/meson.build b/meson.build
+index 187e7b216d..dc1a464504 100644
+--- a/meson.build
++++ b/meson.build
+@@ -1746,7 +1746,11 @@ if conf.get('BPF_FRAMEWORK') == 1
+ 
+         bpf_o_unstripped_cmd += ['-I.']
+ 
+-        if not meson.is_cross_build()
++        if meson.is_cross_build()
++                ## point 'clang'/'gcc' to the bitbake recipe sysroot, to find the libbpf headers there.
++                staging_incdir = join_paths(meson.source_root(), '../recipe-sysroot/usr/include')
++                bpf_o_unstripped_cmd += [ '-isystem', staging_incdir ]
++        else
+                 target_triplet_cmd = run_command('gcc', '-dumpmachine', check: false)
+                 if target_triplet_cmd.returncode() == 0
+                         target_triplet = target_triplet_cmd.stdout().strip()
+-- 
+2.34.1
+
diff --git a/meta/recipes-core/systemd/systemd_255.6.bb b/meta/recipes-core/systemd/systemd_255.6.bb
index e70c9c738d..3fd4d5bc5b 100644
--- a/meta/recipes-core/systemd/systemd_255.6.bb
+++ b/meta/recipes-core/systemd/systemd_255.6.bb
@@ -28,6 +28,7 @@  SRC_URI += " \
            file://systemd-pager.sh \
            file://0002-binfmt-Don-t-install-dependency-links-at-install-tim.patch \
            file://0008-implment-systemd-sysv-install-for-OE.patch \
+           file://0023-bitbake-pass-STAGING_INCDIR-to-clang.patch \
            "
 
 # patches needed by musl