xdp-project / xdp-tools

Utilities and example programs for use with XDP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found

vincentmli opened this issue · comments

here is compiling error on Ubuntu 18.04
root@vincent-desktop:/usr/src/xdp-tools# ./configure
libbpf support: submodule
ELF support: yes
zlib support: yes
root@vincent-desktop:/usr/src/xdp-tools# make

lib

util
CC params.o
CC logging.o
CC util.o
CC stats.o

xdp-filter
CLANG xdpfilt_blk_udp.o
In file included from xdpfilt_blk_udp.c:10:
In file included from ./xdpfilt_prog.h:10:
In file included from ../lib/../headers/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
#include <asm/types.h>
^~~~~~~~~~~~~
1 error generated.
../lib/common.mk:77: recipe for target 'xdpfilt_blk_udp.o' failed
make[1]: *** [xdpfilt_blk_udp.o] Error 1
Makefile:19: recipe for target 'all' failed
make: *** [all] Error 2

this error is similar to issue addressed in https://code.forksand.com/oisf/suricata/commit/7906c521cdde5b1d0eb3ce379b8e343c3055653f
I added diff below to fix the error, maybe similar patch needed for xdp-tools ?

diff --git a/lib/common.mk b/lib/common.mk
index dd71535..6127450 100644
--- a/lib/common.mk
+++ b/lib/common.mk
@@ -75,6 +75,7 @@ $(USER_TARGETS): %: %.c  $(OBJECT_LIBBPF) $(LIBMK) $(LIB_OBJS) $(KERN_USER_H) $(
 
 $(XDP_OBJ): %.o: %.c $(KERN_USER_H) $(EXTRA_DEPS) $(BPF_HEADERS) $(LIBMK)
        $(QUIET_CLANG)$(CLANG) -S \
+           -I/usr/include/x86_64-linux-gnu/ \
            -target bpf \
            -D __BPF_TRACING__ \
            $(BPF_CFLAGS) \

I was building this on Pi and ran into the same issue. Updating the lib/common.mk didn't help. Installing gcc-multilib-arm-linux-gnueabihf didn't help.

I located the file "asm/types.h". It was under /usr/include/aarch64-linux-gnu/. I added the path to C_INCLUDE_PATH
export C_INCLUDE_PATH=/usr/include/aarch64-linux-gnu/

ubuntu@ubuntu:~/dev/git/xdp-tools$ make clean all

lib

  libbpf
    CC       libbpf/src/libbpf.a
    INSTALL  libbpf/src/libbpf.a

  util
    CC       params.o
    CC       logging.o
    CC       util.o
    CC       stats.o
    CC       xpcapng.o

  libxdp
    CC       staticobjs/libxdp.o
    LINK     libxdp.a
    CC       sharedobjs/libxdp.o
    LINK     libxdp.so.1.1.0
    M4       xdp-dispatcher.c
    CLANG    xdp-dispatcher.o
In file included from xdp-dispatcher.c:3:
In file included from ../../headers/linux/bpf.h:11:
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
#include <asm/types.h>
         ^~~~~~~~~~~~~
1 error generated.
make[2]: *** [Makefile:129: xdp-dispatcher.o] Error 1
make[1]: *** [Makefile:10: all] Error 2
make: *** [Makefile:25: lib] Error 2
ubuntu@ubuntu:~/dev/git/xdp-tools$ export C_INCLUDE_PATH=/usr/include/aarch64-linux-gnu/
ubuntu@ubuntu:~/dev/git/xdp-tools$ make all

lib

  util
make[2]: Nothing to be done for 'all'.

  libxdp
    CLANG    xdp-dispatcher.o
    LLC      xdp-dispatcher.o

  testing
    CLANG    test_long_func_name.o
    LLC      test_long_func_name.o
    CLANG    xdp_drop.o
    LLC      xdp_drop.o
    CLANG    xdp_pass.o
    LLC      xdp_pass.o
    LINK     xdp-dispatcher.o

xdp-filter
    CLANG    xdpfilt_dny_udp.o
    LLC      xdpfilt_dny_udp.o
    CLANG    xdpfilt_dny_tcp.o
    LLC      xdpfilt_dny_tcp.o
    CLANG    xdpfilt_dny_ip.o
    LLC      xdpfilt_dny_ip.o
    CLANG    xdpfilt_dny_eth.o
    LLC      xdpfilt_dny_eth.o
    CLANG    xdpfilt_dny_all.o
    LLC      xdpfilt_dny_all.o
    CLANG    xdpfilt_alw_udp.o
    LLC      xdpfilt_alw_udp.o
    CLANG    xdpfilt_alw_tcp.o
    LLC      xdpfilt_alw_tcp.o
    CLANG    xdpfilt_alw_ip.o
    LLC      xdpfilt_alw_ip.o
    CLANG    xdpfilt_alw_eth.o
    LLC      xdpfilt_alw_eth.o
    CLANG    xdpfilt_alw_all.o
    LLC      xdpfilt_alw_all.o
    CC       xdp-filter
    LINK     xdp-dispatcher.o

xdp-loader
    CC       xdp-loader
    LINK     xdp-dispatcher.o

xdp-dump
    CC       xdpdump
    CLANG    xdpdump_bpf.o
    LLC      xdpdump_bpf.o
    CLANG    xdpdump_xdp.o
    LLC      xdpdump_xdp.o
    LINK     xdp-dispatcher.o
ubuntu@ubuntu:~/dev/git/xdp-tools$
ubuntu@ubuntu:~/dev/git/xdp-tools$ uname -a
Linux ubuntu 5.8.0-1015-raspi #18-Ubuntu SMP PREEMPT Fri Feb 5 06:09:58 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
ubuntu@ubuntu:~/dev/git/xdp-tools$
sudo apt-get install -y gcc-multilib

On x86_64 PC, the gcc-multilib debian package makes a symbol link at "/usr/include/asm" to "/usr/include/x86_64-linux-gnu".
I guess that on the ARM32 system (Raspbian) /usr/include/asm might linked to /usr/include/aarch64-linux-gnu or arm-linux-gnueabihf

Wanted to share all dependencies I needed to get xdp-tools to build on Ubuntu 20.04

sudo apt install pkg-config
sudo apt install m4
sudo apt install libelf-dev
sudo apt install libpcap-dev
sudo apt install gcc-multilib

configure seems to cover all of these except gcc-multilib, recommend adding a check for this if its required.

Note, however, that the kernel doesn't currently support the features we
use for the XDP dispatcher on any other archs than x86_64; so you can't
actually load multiple programs on a single interface on an Arm box, and
I don't believe xdpdump will work either...

@tohojo is this still true on the latest 18.04 HWE kernel (5.4.0) for arm64?

I was able to get this to compile but as noted in two comments above, since gcc-multilib is not available on ARM64, you have to symlink /usr/include/asm to /usr/include/aarch64-linux-gnu/asm yourself and also add -I/usr/include/aarch64-linux-gnu to clang if you get the types.h as well as other subsequent errors.

Heh, yeah, 5.4 doesn't even support it on x86.

If you'd care to open a PR to fix the include issue, feel free :)

Hi, I ran into this issue where gcc-multilib can not be identified by Ubuntu 20.04. What exactly is the fix? Should I download and install the required files manually?

gcc-multilib is available in 20.04 for amd64, its not available for ARM architecture. The fix I mentioned above makes it work for ARM64. I have got XDP programs correctly compiling with normal gcc package and loading on ARM64 in AWS (though havent taken it through a full functiional test yet).

[Edit] following up on my above answer, I have tested a single XDP program and got it loading and functioning correctly on Ubuntu 18.04 with the HWE kernel on a RPi 4 and in an AWS Graviton ARM64 instance.

Example answer/notes for myself when running on Linux 5.10.103-v7l+ #1529 SMP Tue Mar 8 12:24:00 GMT 2022 armv7l.

clang-11 -O2 -target bpf -c xdp_drop_all.c -o xdp_drop_all.o -I/usr/include/arm-linux-gnueabihf/
sudo apt-get install -y gcc-multilib

On x86_64 PC, the gcc-multilib debian package makes a symbol link at "/usr/include/asm" to "/usr/include/x86_64-linux-gnu". I guess that on the ARM32 system (Raspbian) /usr/include/asm might linked to /usr/include/aarch64-linux-gnu or arm-linux-gnueabihf

Does this really make sense for people who are cross-compiling? Shouldn't the target's asm/types.h be included instead?

Does this really make sense for people who are cross-compiling? Shouldn't the target's asm/types.h be included instead?

Sure, but I don't believe we're talking about cross compilation here? I'd expect anyone doing cross compilation would have all appropriate header paths set by the build environment?

Yeah, sorry. I came here from the openwrt issue, should have posted there.