patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Demi Marie Obenour <demiobenour@gmail.com>
To: Spectrum OS Development <devel@spectrum-os.org>
Cc: Alyssa Ross <hi@alyssa.is>, Yureka <yuka@yuka.dev>
Subject: Re: [PATCH RFC DOESNOTBUILD v2] tools/xdp-forwarder: Do not include libc headers in eBPF programs
Date: Mon, 6 Oct 2025 03:45:41 -0400	[thread overview]
Message-ID: <9d8f1506-d4d7-41cf-a6a6-04a3cc0d3e43@gmail.com> (raw)
In-Reply-To: <20251006-fix-forwarder-build-v2-1-6fdd7e05cb14@gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 2199 bytes --]

On 10/6/25 03:30, Demi Marie Obenour wrote:
> The build happened to work on arm64 because the glibc arm64 headers
> don't support multilib.  On x86_64, glibc headers assume that BPF is a
> 32-bit platform (because __x86_64__ isn't defined) and fail to find the
> 32-bit headers.  This is not a glibc bug.  Rather, BPF programs should
> not be including glibc headers.
> 
> Most Linux headers are not trivial to include in BPF programs.  The
> version of the headers meant for userspace use do include glibc headers,
> and that isn't supported in BPF.  The version meant for building
> kernel modules does not, but using it requires much more complicated
> build system.
> 
> Solve this problem by only including headers intended for use in BPF
> programs.  These headers include declarations explicitly intended for
> use in BPF programs, so if they do pull in libc headers that is a bug.
> This also allows using an unwrapped clang.  Nix's wrapped clang is not
> suitable when a target is explicitly specified, so this is another a
> bug fix.
> 
> This prevents vendoring the example headers, so replace them with a
> header that only includes common functionality common to both eBPF
> programs.  A single struct including both Ethernet II and 802.1Q headers
> is used, massively simplifying the code.
> 
> Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>

Build failures are because the compiler can't find <linux/bpf.h>.
It appears that libbpf does not provide its own version of that file,
and in any case the include path to find it is wrong.  Using a wrapped
compiler is wrong but might fix this.  Another option, which I think
is probably best, is to move this to vm/sys/net and build it against
the headers from vm/sys/net's kernel.  The build only requires the
UAPI headers, which are stable, so any kernel build that is not truly
ancient can be used.  The correct include directory is

    "${kernel-pkg.dev}/lib/modules/${kernel-pkg.version}/source/include/uapi"

where kernel-pkg is the Nix kernel package derivation.

Also, Yureka, can you look at the (massive) changes to the C code?
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2025-10-06  7:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-03 17:14 [PATCH] tools/xdp-forwarder: Fix build Demi Marie Obenour
2025-10-04 15:47 ` Alyssa Ross
2025-10-05  3:36   ` Demi Marie Obenour
2025-10-06  7:30 ` [PATCH RFC DOESNOTBUILD v2] tools/xdp-forwarder: Do not include libc headers in eBPF programs Demi Marie Obenour
2025-10-06  7:45   ` Demi Marie Obenour [this message]
2025-10-08 17:22   ` [PATCH v3] " Demi Marie Obenour
2025-10-18 10:56     ` Alyssa Ross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d8f1506-d4d7-41cf-a6a6-04a3cc0d3e43@gmail.com \
    --to=demiobenour@gmail.com \
    --cc=devel@spectrum-os.org \
    --cc=hi@alyssa.is \
    --cc=yuka@yuka.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

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).