BPF List
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Yonghong Song <yhs@fb.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <borkmann@iogearbox.net>,
	BPF-dev-list <bpf@vger.kernel.org>,
	"iovisor-dev@lists.iovisor.org" <iovisor-dev@lists.iovisor.org>
Cc: brouer@redhat.com,
	"xdp-newbies@vger.kernel.org" <xdp-newbies@vger.kernel.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Jiri Olsa <jolsa@redhat.com>, Shaun Crampton <shaun@tigera.io>,
	steve.langasek@canonical.com, wookey@debian.org,
	Yonghong Song <ys114321@gmail.com>
Subject: Clang target bpf compile issue/fail on Ubuntu and Debian
Date: Wed, 29 Jul 2020 21:13:41 +0200	[thread overview]
Message-ID: <20200729211341.1a713559@carbon> (raw)


The BPF UAPI header file <linux/bpf.h> includes <linux/types.h>, which gives
BPF-programs access to types e.g. __u32, __u64, __u8, etc.

On Ubuntu/Debian when compiling with clang option[1] "-target bpf" the
compile fails because it cannot find the file <asm/types.h>, which is
included from <linux/types.h>. This is because Ubuntu/Debian tries to
support multiple architectures on a single system[2]. On x86_64 the file
<asm/types.h> is located in /usr/include/x86_64-linux-gnu/, which the distro
compiler will add to it's search path (/usr/include/<triplet> [3]). Note, it
works if not specifying target bpf, but as explained in kernel doc[1] the
clang target bpf should really be used (to avoid other issues).

There are two workarounds: (1) To have an extra include dir on Ubuntu (which
seems too x86 specific) like: CFLAGS += -I/usr/include/x86_64-linux-gnu .
Or (2) install the package gcc-multilib on Ubuntu.

The question is: Should Ubuntu/Debian have a /usr/include/<triplet>
directory for BPF? (as part of their multi-arch approach)

Or should clang use the compile-host's triplet for the /usr/include/triplet
path even when giving clang -target bpf option?

p.s. GCC choose 'bpf-unknown-none' target triplet for BPF.


Links:
[1] https://www.kernel.org/doc/html/latest/bpf/bpf_devel_QA.html#q-clang-flag-for-target-bpf
[2] https://wiki.ubuntu.com/MultiarchSpec
[3] https://wiki.osdev.org/Target_Triplet
-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer


             reply	other threads:[~2020-07-29 19:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 19:13 Jesper Dangaard Brouer [this message]
2020-08-03 16:28 ` Clang target bpf compile issue/fail on Ubuntu and Debian Yonghong Song

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=20200729211341.1a713559@carbon \
    --to=brouer@redhat.com \
    --cc=acme@redhat.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=borkmann@iogearbox.net \
    --cc=bpf@vger.kernel.org \
    --cc=iovisor-dev@lists.iovisor.org \
    --cc=jolsa@redhat.com \
    --cc=shaun@tigera.io \
    --cc=steve.langasek@canonical.com \
    --cc=wookey@debian.org \
    --cc=xdp-newbies@vger.kernel.org \
    --cc=yhs@fb.com \
    --cc=ys114321@gmail.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox