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

variable 'echo_reply' set but not used

Open Alt-Shivam opened this issue 3 years ago • 4 comments

When I try to run make in directory packet03-redirecting. It throws this error:

xdp_prog_kern.c:60:8: error: variable 'echo_reply' set but not used [-Werror,-Wunused-but-set-variable]
        __u16 echo_reply;
              ^
1 error generated.
make: *** [../common/common.mk:111: xdp_prog_kern.o] Error 1

OS: Fedora 36 kernel: 5.18.16-200.fc36.x86_64 Clang: 14.0.0 (Fedora 14.0.0-1.fc36)

Thanks,

Alt-Shivam avatar Aug 13 '22 05:08 Alt-Shivam

It's a tutorial - the code is deliberately incomplete. You're supposed to fix the code to make use of the variable (see the comment hint)...

tohojo avatar Aug 14 '22 13:08 tohojo

Hey @tohojo Thanks for the reply, Ik this is a tutorial, and Basically this is a compilation error, That comes with clang 12 or above, and I've resolved this error,

All we need to do is: change this flag in common.mk file: ~~-Wno-unused-value~~ to -Wno-unused-but-set-variable

$(XDP_OBJ): %.o: %.c  Makefile $(COMMON_MK) $(KERN_USER_H) $(EXTRA_DEPS) $(OBJECT_LIBBPF)
        $(CLANG) -S \
            -target bpf \
            -D __BPF_TRACING__ \
            $(BPF_CFLAGS) \
            -Wall \
            -Wno-unused-but-set-variable \
            -Wno-pointer-sign \
            -Wno-compare-distinct-pointer-types \
            -Werror \
            -O2 -emit-llvm -c -g -o ${@:.o=.ll} $<
        $(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll}

Alt-Shivam avatar Aug 15 '22 09:08 Alt-Shivam

If this change is feasible, Do let me know, will open a PR to fix this.

Alt-Shivam avatar Aug 15 '22 09:08 Alt-Shivam

No, it's telling you the variable is set but not used because you haven't added the code that uses it yet. See this comment: https://github.com/xdp-project/xdp-tutorial/blob/master/packet03-redirecting/xdp_prog_kern.c#L104-L105

tohojo avatar Aug 15 '22 13:08 tohojo