1. 23 Apr, 2021 21 commits
  2. 22 Apr, 2021 2 commits
  3. 20 Apr, 2021 6 commits
  4. 19 Apr, 2021 7 commits
  5. 15 Apr, 2021 4 commits
    • Alexei Starovoitov's avatar
      Merge branch 'bpf: tools: support build selftests/bpf with clang' · cdf0e80e
      Alexei Starovoitov authored
      Yonghong Song says:
      
      ====================
      
      To build kernel with clang, people typically use
        make -j60 LLVM=1 LLVM_IAS=1
      LLVM_IAS=1 is not required for non-LTO build but
      is required for LTO build. In my environment,
      I am always having LLVM_IAS=1 regardless of
      whether LTO is enabled or not.
      
      After kernel is build with clang, the following command
      can be used to build selftests with clang:
        make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1
      
      I am using latest bpf-next kernel code base and
      latest clang built from source from
        https://github.com/llvm/llvm-project.git
      Using earlier version of llvm may have compilation errors, see
        tools/testing/selftests/bpf
      due to continuous development in llvm bpf features and selftests
      to use these features.
      
      To run bpf selftest properly, you need have certain necessary
      kernel configs like at:
        bpf-next:tools/testing/selftests/bpf/config
      (not that this is not a complete .config file and some other configs
       might still be needed.)
      
      Currently, using the above command, some compilations
      still use gcc and there are also compilation errors and warnings.
      This patch set intends to fix these issues.
      Patch #1 and #2 fixed the issue so clang/clang++ is
      used instead of gcc/g++. Patch #3 fixed a compilation
      failure. Patch #4 and #5 fixed various compiler warnings.
      
      Changelog:
        v2 -> v3:
          . more test environment description in cover letter. (Sedat)
          . use a different fix, but similar to other use in selftests/bpf
            Makefile, to exclude header files from CXX compilation command
            line. (Andrii)
          . fix codes instead of adding -Wno-format-security. (Andrii)
        v1 -> v2:
          . add -Wno-unused-command-line-argument and -Wno-format-security
            for clang only as (1). gcc does not exhibit those
            warnings, and (2). -Wno-unused-command-line-argument is
            only supported by clang. (Sedat)
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      cdf0e80e
    • Yonghong Song's avatar
      bpftool: Fix a clang compilation warning · 8af50142
      Yonghong Song authored
      With clang compiler:
        make -j60 LLVM=1 LLVM_IAS=1  <=== compile kernel
        # build selftests/bpf or bpftool
        make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1
        make -j60 -C tools/bpf/bpftool LLVM=1 LLVM_IAS=1
      the following compilation warning showed up,
        net.c:160:37: warning: comparison of integers of different signs: '__u32' (aka 'unsigned int') and 'int' [-Wsign-compare]
                      for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len);
                                                        ^~~~~~~~~~~~~~~~~
        .../tools/include/uapi/linux/netlink.h:99:24: note: expanded from macro 'NLMSG_OK'
                                 (nlh)->nlmsg_len <= (len))
                                 ~~~~~~~~~~~~~~~~ ^   ~~~
      
      In this particular case, "len" is defined as "int" and (nlh)->nlmsg_len is "unsigned int".
      The macro NLMSG_OK is defined as below in uapi/linux/netlink.h.
        #define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
                                   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
                                   (nlh)->nlmsg_len <= (len))
      
      The clang compiler complains the comparision "(nlh)->nlmsg_len <= (len))",
      but in bpftool/net.c, it is already ensured that "len > 0" must be true.
      So theoretically the compiler could deduce that comparison of
      "(nlh)->nlmsg_len" and "len" is okay, but this really depends on compiler
      internals. Let us add an explicit type conversion (from "int" to "unsigned int")
      for "len" in NLMSG_OK to silence this warning right now.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210413153435.3029635-1-yhs@fb.com
      8af50142
    • Yonghong Song's avatar
      selftests/bpf: Silence clang compilation warnings · ef998589
      Yonghong Song authored
      With clang compiler:
        make -j60 LLVM=1 LLVM_IAS=1  <=== compile kernel
        make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1
      Some linker flags are not used/effective for some binaries and
      we have warnings like:
        warning: -lelf: 'linker' input unused [-Wunused-command-line-argument]
      
      We also have warnings like:
        .../selftests/bpf/prog_tests/ns_current_pid_tgid.c:74:57: note: treat the string as an argument to avoid this
              if (CHECK(waitpid(cpid, &wstatus, 0) == -1, "waitpid", strerror(errno)))
                                                                     ^
                                                                     "%s",
        .../selftests/bpf/test_progs.h:129:35: note: expanded from macro 'CHECK'
              _CHECK(condition, tag, duration, format)
                                               ^
        .../selftests/bpf/test_progs.h:108:21: note: expanded from macro '_CHECK'
                      fprintf(stdout, ##format);                              \
                                        ^
      The first warning can be silenced with clang option -Wno-unused-command-line-argument.
      For the second warning, source codes are modified as suggested by the compiler
      to silence the warning. Since gcc does not support the option
      -Wno-unused-command-line-argument and the warning only happens with clang
      compiler, the option -Wno-unused-command-line-argument is enabled only when
      clang compiler is used.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210413153429.3029377-1-yhs@fb.com
      ef998589
    • Yonghong Song's avatar
      selftests/bpf: Fix test_cpp compilation failure with clang · a22c0c81
      Yonghong Song authored
      With clang compiler:
        make -j60 LLVM=1 LLVM_IAS=1  <=== compile kernel
        make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1
      the test_cpp build failed due to the failure:
        warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
        clang-13: error: cannot specify -o when generating multiple output files
      
      test_cpp compilation flag looks like:
        clang++ -g -Og -rdynamic -Wall -I<...> ... \
        -Dbpf_prog_load=bpf_prog_test_load -Dbpf_load_program=bpf_test_load_program \
        test_cpp.cpp <...>/test_core_extern.skel.h <...>/libbpf.a <...>/test_stub.o \
        -lcap -lelf -lz -lrt -lpthread -o <...>/test_cpp
      
      The clang++ compiler complains the header file in the command line and
      also failed the compilation due to this.
      Let us remove the header file from the command line which is not intended
      any way, and this fixed the compilation problem.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210413153424.3028986-1-yhs@fb.com
      a22c0c81