xdp-tutorial icon indicating copy to clipboard operation
xdp-tutorial copied to clipboard

Compilation error: unused function <func> [-Werror,-Wunused-function]

Open imgrass opened this issue 5 years ago • 1 comments

In commit "dcdc6836f237c8a1a36b2d699c171475a7c4d07e" with branch "origin/master", the following compilation error would occur like that:

In file included from xdp_prog_kern.c:8: ./../common/parsing_helpers.h:156:28: error: unused function 'parse_icmp6hdr' [-Werror,-Wunused-function] static __always_inline int parse_icmp6hdr(struct hdr_cursor *nh,
./../common/parsing_helpers.h:171:28: error: unused function 'parse_icmphdr' [-Werror,-Wunused-function] static __always_inline int parse_icmphdr(struct hdr_cursor *nh,
./../common/parsing_helpers.h:204:28: error: unused function 'parse_udphdr' [-Werror,-Wunused-function] static __always_inline int parse_udphdr(struct hdr_cursor *nh,
./../common/parsing_helpers.h:227:28: error: unused function 'parse_tcphdr' [-Werror,-Wunused-function] static __always_inline int parse_tcphdr(struct hdr_cursor *nh,
4 errors generated.

I added "__maybe_unused" marco to these function definitions shown as below, then these errors disappeared

diff --git a/common/parsing_helpers.h b/common/parsing_helpers.h index c129ea5..5397f86 100644 --- a/common/parsing_helpers.h +++ b/common/parsing_helpers.h @@ -29,6 +29,9 @@ #include <linux/udp.h> #include <linux/tcp.h> +#define __maybe_unused __attribute__((__unused__)) + + /* Header cursor to keep track of current parsing position */ struct hdr_cursor { void *pos; @@ -59,7 +62,7 @@ struct icmphdr_common { #define VLAN_MAX_DEPTH 4 #endif -static __always_inline int proto_is_vlan(__u16 h_proto) +static __always_inline __maybe_unused int proto_is_vlan(__u16 h_proto) ...

This is my system info:

xdp-tutorial(14:33>master* uname -a Linux docker 4.4.0-179-generic #209-Ubuntu SMP Fri Apr 24 17:48:44 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux xdp-tutorial(14:33>master* gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.12' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)

Is this a bug? Or there are other steps need to be done firstly?

imgrass avatar Jul 29 '20 06:07 imgrass