xdp-newbies.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Clang target bpf compile issue/fail on Ubuntu and Debian
@ 2020-07-29 19:13 Jesper Dangaard Brouer
  2020-08-03 16:28 ` Yonghong Song
  0 siblings, 1 reply; 2+ messages in thread
From: Jesper Dangaard Brouer @ 2020-07-29 19:13 UTC (permalink / raw)
  To: Yonghong Song, Andrii Nakryiko, Alexei Starovoitov,
	Daniel Borkmann, BPF-dev-list, iovisor-dev
  Cc: brouer, xdp-newbies, Arnaldo Carvalho de Melo, Jiri Olsa,
	Shaun Crampton, steve.langasek, wookey, Yonghong Song


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Clang target bpf compile issue/fail on Ubuntu and Debian
  2020-07-29 19:13 Clang target bpf compile issue/fail on Ubuntu and Debian Jesper Dangaard Brouer
@ 2020-08-03 16:28 ` Yonghong Song
  0 siblings, 0 replies; 2+ messages in thread
From: Yonghong Song @ 2020-08-03 16:28 UTC (permalink / raw)
  To: Jesper Dangaard Brouer, Andrii Nakryiko, Alexei Starovoitov,
	Daniel Borkmann, BPF-dev-list, iovisor-dev
  Cc: xdp-newbies, Arnaldo Carvalho de Melo, Jiri Olsa, Shaun Crampton,
	steve.langasek, wookey, Yonghong Song



On 7/29/20 12:13 PM, Jesper Dangaard Brouer wrote:
> 
> 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 .

How about non x86 architecture? It will be something like 
/usr/include/aarch64-linux-gnu? Do you think we could have some header 
file conflict
since this directory may contain a lot other header files as well?

> Or (2) install the package gcc-multilib on Ubuntu.

I think having a /usr/include/bpf-unknown-none and the distro add this
path to the compiler has target bpf. In this way, only necessary header
files will be put there. Less potential issues.

But in either case, it will be good if this level of details are
hidden from the user.

I am not super familiar with the distro packaging of a particular 
compiler and its include directories. The above is just my 2 cents.

> 
> 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://urldefense.proofpoint.com/v2/url?u=https-3A__wiki.ubuntu.com_MultiarchSpec&d=DwICAg&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=ZEguArah72427WZMt53NXZa8LuQEGJKvCOgjH96NggQ&s=5xL0VWya8ULHcj4pfw6oxqHoKWIXNfJnj2G7rdaQyR8&e=
> [3] https://urldefense.proofpoint.com/v2/url?u=https-3A__wiki.osdev.org_Target-5FTriplet&d=DwICAg&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=ZEguArah72427WZMt53NXZa8LuQEGJKvCOgjH96NggQ&s=mym8eKus7o0PzfkC2-IMyPU84OwVb2_A4ky2JHcdexQ&e=
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-03 16:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 19:13 Clang target bpf compile issue/fail on Ubuntu and Debian Jesper Dangaard Brouer
2020-08-03 16:28 ` Yonghong Song

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