bpf: Replace deprecated -target with --target= for Clang
authorFangrui Song <maskray@google.com>
Sat, 24 Jun 2023 00:18:56 +0000 (00:18 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 29 Jun 2023 13:46:17 +0000 (15:46 +0200)
The -target option has been deprecated since clang 3.4 in 2013. Therefore, use
the preferred --target=bpf form instead. This also matches how we use --target=
in scripts/Makefile.clang.

Signed-off-by: Fangrui Song <maskray@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Quentin Monnet <quentin@isovalent.com>
Link: https://github.com/llvm/llvm-project/commit/274b6f0c87a6a1798de0a68135afc7f95def6277
Link: https://lore.kernel.org/bpf/20230624001856.1903733-1-maskray@google.com
18 files changed:
Documentation/bpf/bpf_devel_QA.rst
Documentation/bpf/btf.rst
Documentation/bpf/llvm_reloc.rst
drivers/hid/bpf/entrypoints/Makefile
kernel/bpf/preload/iterators/Makefile
samples/bpf/Makefile
samples/bpf/gnu/stubs.h
samples/bpf/test_lwt_bpf.sh
samples/hid/Makefile
tools/bpf/bpftool/Documentation/bpftool-gen.rst
tools/bpf/bpftool/Makefile
tools/bpf/runqslower/Makefile
tools/build/feature/Makefile
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/bpf/gnu/stubs.h
tools/testing/selftests/hid/Makefile
tools/testing/selftests/net/Makefile
tools/testing/selftests/tc-testing/Makefile

index 609b71f5747d704e1fedec38a00152a089bc6b9c..de27e1620821c48f4d810b8b1e837da0602b3515 100644 (file)
@@ -635,12 +635,12 @@ test coverage.
 
 Q: clang flag for target bpf?
 -----------------------------
-Q: In some cases clang flag ``-target bpf`` is used but in other cases the
+Q: In some cases clang flag ``--target=bpf`` is used but in other cases the
 default clang target, which matches the underlying architecture, is used.
 What is the difference and when I should use which?
 
 A: Although LLVM IR generation and optimization try to stay architecture
-independent, ``-target <arch>`` still has some impact on generated code:
+independent, ``--target=<arch>`` still has some impact on generated code:
 
 - BPF program may recursively include header file(s) with file scope
   inline assembly codes. The default target can handle this well,
@@ -658,7 +658,7 @@ independent, ``-target <arch>`` still has some impact on generated code:
   The clang option ``-fno-jump-tables`` can be used to disable
   switch table generation.
 
-- For clang ``-target bpf``, it is guaranteed that pointer or long /
+- For clang ``--target=bpf``, it is guaranteed that pointer or long /
   unsigned long types will always have a width of 64 bit, no matter
   whether underlying clang binary or default target (or kernel) is
   32 bit. However, when native clang target is used, then it will
@@ -668,7 +668,7 @@ independent, ``-target <arch>`` still has some impact on generated code:
   while the BPF LLVM back end still operates in 64 bit. The native
   target is mostly needed in tracing for the case of walking ``pt_regs``
   or other kernel structures where CPU's register width matters.
-  Otherwise, ``clang -target bpf`` is generally recommended.
+  Otherwise, ``clang --target=bpf`` is generally recommended.
 
 You should use default target when:
 
@@ -685,7 +685,7 @@ when:
   into these structures is verified by the BPF verifier and may result
   in verification failures if the native architecture is not aligned with
   the BPF architecture, e.g. 64-bit. An example of this is
-  BPF_PROG_TYPE_SK_MSG require ``-target bpf``
+  BPF_PROG_TYPE_SK_MSG require ``--target=bpf``
 
 
 .. Links
index 7cd7c5415a99272102b288724295c040dd99719b..f32db1f44ae90fc2f2004e1e84145430f5089e96 100644 (file)
@@ -990,7 +990,7 @@ format.::
     } g2;
     int main() { return 0; }
     int test() { return 0; }
-    -bash-4.4$ clang -c -g -O2 -target bpf t2.c
+    -bash-4.4$ clang -c -g -O2 --target=bpf t2.c
     -bash-4.4$ readelf -S t2.o
       ......
       [ 8] .BTF              PROGBITS         0000000000000000  00000247
@@ -1000,7 +1000,7 @@ format.::
       [10] .rel.BTF.ext      REL              0000000000000000  000007e0
            0000000000000040  0000000000000010          16     9     8
       ......
-    -bash-4.4$ clang -S -g -O2 -target bpf t2.c
+    -bash-4.4$ clang -S -g -O2 --target=bpf t2.c
     -bash-4.4$ cat t2.s
       ......
             .section        .BTF,"",@progbits
index e4a777a6a3a24ba977e0100cb6d53db6a294d28d..450e6403fe3dec0edf983b582b426a420c09075e 100644 (file)
@@ -28,7 +28,7 @@ For example, for the following code::
     return g1 + g2 + l1 + l2;
   }
 
-Compiled with ``clang -target bpf -O2 -c test.c``, the following is
+Compiled with ``clang --target=bpf -O2 -c test.c``, the following is
 the code with ``llvm-objdump -dr test.o``::
 
        0:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll
@@ -157,7 +157,7 @@ and ``call`` instructions. For example::
     return gfunc(a, b) +  lfunc(a, b) + global;
   }
 
-Compiled with ``clang -target bpf -O2 -c test.c``, we will have
+Compiled with ``clang --target=bpf -O2 -c test.c``, we will have
 following code with `llvm-objdump -dr test.o``::
 
   Disassembly of section .text:
@@ -203,7 +203,7 @@ The following is an example to show how R_BPF_64_ABS64 could be generated::
   int global() { return 0; }
   struct t { void *g; } gbl = { global };
 
-Compiled with ``clang -target bpf -O2 -g -c test.c``, we will see a
+Compiled with ``clang --target=bpf -O2 -g -c test.c``, we will see a
 relocation below in ``.data`` section with command
 ``llvm-readelf -r test.o``::
 
index a12edcfa4fe3d607f3e5aa652ae46cc7e961ee95..43b99b5575cfe1a667935978e2524804f3aeea29 100644 (file)
@@ -58,7 +58,7 @@ entrypoints.lskel.h: $(OUTPUT)/entrypoints.bpf.o | $(BPFTOOL)
 
 $(OUTPUT)/entrypoints.bpf.o: entrypoints.bpf.c $(OUTPUT)/vmlinux.h $(BPFOBJ) | $(OUTPUT)
        $(call msg,BPF,$@)
-       $(Q)$(CLANG) -g -O2 -target bpf $(INCLUDES)                           \
+       $(Q)$(CLANG) -g -O2 --target=bpf $(INCLUDES)                          \
                 -c $(filter %.c,$^) -o $@ &&                                 \
        $(LLVM_STRIP) -g $@
 
index 8937dc6bc8d0c75ef13691601e318653039eb21a..b83c2f5e9be147b2536293ea5d7091e1d8d3e676 100644 (file)
@@ -50,7 +50,7 @@ iterators.lskel-%.h: $(OUTPUT)/%/iterators.bpf.o | $(BPFTOOL)
 $(OUTPUT)/%/iterators.bpf.o: iterators.bpf.c $(BPFOBJ) | $(OUTPUT)
        $(call msg,BPF,$@)
        $(Q)mkdir -p $(@D)
-       $(Q)$(CLANG) -g -O2 -target bpf -m$* $(INCLUDES)                      \
+       $(Q)$(CLANG) -g -O2 --target=bpf -m$* $(INCLUDES)                     \
                 -c $(filter %.c,$^) -o $@ &&                                 \
        $(LLVM_STRIP) -g $@
 
index 615f24ebc49cc0a3f91aa60d02d737a0b3da4b24..595b98d825cee40bad9e4eb7db25099e90f57648 100644 (file)
@@ -248,7 +248,7 @@ BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
 BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
 BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
 BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \
-                         $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
+                         $(CLANG) --target=bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
                          $(LLVM_READELF) -S ./llvm_btf_verify.o | grep BTF; \
                          /bin/rm -f ./llvm_btf_verify.o)
 
@@ -370,7 +370,7 @@ endif
 clean-files += vmlinux.h
 
 # Get Clang's default includes on this system, as opposed to those seen by
-# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# '--target=bpf'. This fixes "missing" files on some architectures/distros,
 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
 #
 # Use '-idirafter': Don't interfere with include mechanics except where the
@@ -392,7 +392,7 @@ $(obj)/xdp_router_ipv4.bpf.o: $(obj)/xdp_sample.bpf.o
 
 $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h
        @echo "  CLANG-BPF " $@
-       $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(SRCARCH) \
+       $(Q)$(CLANG) -g -O2 --target=bpf -D__TARGET_ARCH_$(SRCARCH) \
                -Wno-compare-distinct-pointer-types -I$(srctree)/include \
                -I$(srctree)/samples/bpf -I$(srctree)/tools/include \
                -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) \
index 719225b1662697f90ab04d9a0f6562e9b4bc34d0..1c638d9dce1a4104d6029e18b9b5a18237bcc147 100644 (file)
@@ -1 +1 @@
-/* dummy .h to trick /usr/include/features.h to work with 'clang -target bpf' */
+/* dummy .h to trick /usr/include/features.h to work with 'clang --target=bpf' */
index 0bf2d0f6bf4ba8afdb1305ddc7670f8904bb5e98..148e2df6cdcec86b679c298ebd881553bd37f825 100755 (executable)
@@ -376,7 +376,7 @@ DST_MAC=$(lookup_mac $VETH1 $NS1)
 SRC_MAC=$(lookup_mac $VETH0)
 DST_IFINDEX=$(cat /sys/class/net/$VETH0/ifindex)
 
-CLANG_OPTS="-O2 -target bpf -I ../include/"
+CLANG_OPTS="-O2 --target=bpf -I ../include/"
 CLANG_OPTS+=" -DSRC_MAC=$SRC_MAC -DDST_MAC=$DST_MAC -DDST_IFINDEX=$DST_IFINDEX"
 clang $CLANG_OPTS -c $PROG_SRC -o $BPF_PROG
 
index 026288280a0356a6364b350bd82814e8b6a91271..9f7fe29dd7497c05cf94f5d3a683f029d83d10f6 100644 (file)
@@ -86,7 +86,7 @@ BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
 BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
 BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
 BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \
-                         $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
+                         $(CLANG) --target=bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
                          $(LLVM_READELF) -S ./llvm_btf_verify.o | grep BTF; \
                          /bin/rm -f ./llvm_btf_verify.o)
 
@@ -181,7 +181,7 @@ endif
 clean-files += vmlinux.h
 
 # Get Clang's default includes on this system, as opposed to those seen by
-# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# '--target=bpf'. This fixes "missing" files on some architectures/distros,
 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
 #
 # Use '-idirafter': Don't interfere with include mechanics except where the
@@ -198,7 +198,7 @@ EXTRA_BPF_HEADERS_SRC := $(addprefix $(src)/,$(EXTRA_BPF_HEADERS))
 
 $(obj)/%.bpf.o: $(src)/%.bpf.c $(EXTRA_BPF_HEADERS_SRC) $(obj)/vmlinux.h
        @echo "  CLANG-BPF " $@
-       $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(SRCARCH) \
+       $(Q)$(CLANG) -g -O2 --target=bpf -D__TARGET_ARCH_$(SRCARCH) \
                -Wno-compare-distinct-pointer-types -I$(srctree)/include \
                -I$(srctree)/samples/bpf -I$(srctree)/tools/include \
                -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) \
index 68454ef28f58e3e22c4628cf849738f249d0b61b..5006e724d1bc01c1afe5e13fb4ca29a33725a3ea 100644 (file)
@@ -260,9 +260,9 @@ EXAMPLES
 This is example BPF application with two BPF programs and a mix of BPF maps
 and global variables. Source code is split across two source code files.
 
-**$ clang -target bpf -g example1.bpf.c -o example1.bpf.o**
+**$ clang --target=bpf -g example1.bpf.c -o example1.bpf.o**
 
-**$ clang -target bpf -g example2.bpf.c -o example2.bpf.o**
+**$ clang --target=bpf -g example2.bpf.c -o example2.bpf.o**
 
 **$ bpftool gen object example.bpf.o example1.bpf.o example2.bpf.o**
 
index 681fbcc5ed5047ffc33623b463d538f2f7538598..e9154ace80fff6550168b5c61d49c790eeaa115f 100644 (file)
@@ -216,7 +216,7 @@ $(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF_BOOTSTRAP)
                -I$(srctree)/tools/include/uapi/ \
                -I$(LIBBPF_BOOTSTRAP_INCLUDE) \
                -g -O2 -Wall -fno-stack-protector \
-               -target bpf -c $< -o $@
+               --target=bpf -c $< -o $@
        $(Q)$(LLVM_STRIP) -g $@
 
 $(OUTPUT)%.skel.h: $(OUTPUT)%.bpf.o $(BPFTOOL_BOOTSTRAP)
index 47acf6936516fb0fe6f1498c08aa465e16b559e4..d8288936c9120f11e36de1481b02eba27c18f153 100644 (file)
@@ -62,7 +62,7 @@ $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
        $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
 
 $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
-       $(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES)                   \
+       $(QUIET_GEN)$(CLANG) -g -O2 --target=bpf $(INCLUDES)                  \
                 -c $(filter %.c,$^) -o $@ &&                                 \
        $(LLVM_STRIP) -g $@
 
index 0f0aa9b7d7b5e43cda14f4afe469719d0d513d93..6654b1a35ab322c2b9fb95d21902c45ec2e491ae 100644 (file)
@@ -372,7 +372,7 @@ $(OUTPUT)test-libzstd.bin:
        $(BUILD) -lzstd
 
 $(OUTPUT)test-clang-bpf-co-re.bin:
-       $(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) |   \
+       $(CLANG) -S -g --target=bpf -o - $(patsubst %.bin,%.c,$(@F)) |  \
                grep BTF_KIND_VAR
 
 $(OUTPUT)test-file-handle.bin:
index 538df8fb8c42ba88c0047af8cc2668e8f83f2b8a..ad6b585e0d7c1304cdeee2857b1b5e818e27a550 100644 (file)
@@ -331,7 +331,7 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids        \
                OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ)
 
 # Get Clang's default includes on this system, as opposed to those seen by
-# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# '--target=bpf'. This fixes "missing" files on some architectures/distros,
 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
 #
 # Use '-idirafter': Don't interfere with include mechanics except where the
@@ -372,12 +372,12 @@ $(OUTPUT)/cgroup_getset_retval_hooks.o: cgroup_getset_retval_hooks.h
 # $3 - CFLAGS
 define CLANG_BPF_BUILD_RULE
        $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-       $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v3 -o $2
+       $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v3 -o $2
 endef
 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
 define CLANG_NOALU32_BPF_BUILD_RULE
        $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-       $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v2 -o $2
+       $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v2 -o $2
 endef
 # Build BPF object using GCC
 define GCC_BPF_BUILD_RULE
index 719225b1662697f90ab04d9a0f6562e9b4bc34d0..1c638d9dce1a4104d6029e18b9b5a18237bcc147 100644 (file)
@@ -1 +1 @@
-/* dummy .h to trick /usr/include/features.h to work with 'clang -target bpf' */
+/* dummy .h to trick /usr/include/features.h to work with 'clang --target=bpf' */
index 01c0491d64daba6543fa5b70b0d8ead67aaf701b..2e986cbf1a463066b6d78f95951a9c8b5d920f84 100644 (file)
@@ -167,7 +167,7 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids        \
                OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ)
 
 # Get Clang's default includes on this system, as opposed to those seen by
-# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# '--target=bpf'. This fixes "missing" files on some architectures/distros,
 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
 #
 # Use '-idirafter': Don't interfere with include mechanics except where the
@@ -196,12 +196,12 @@ CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
 # $3 - CFLAGS
 define CLANG_BPF_BUILD_RULE
        $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-       $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v3 -o $2
+       $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v3 -o $2
 endef
 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
 define CLANG_NOALU32_BPF_BUILD_RULE
        $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-       $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v2 -o $2
+       $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v2 -o $2
 endef
 # Build BPF object using GCC
 define GCC_BPF_BUILD_RULE
index 7f3ab2a93ed6178a0e8808516c4d0dd9ac817229..2f69f7274e3d8058fe3e6bfccf7986a9f93e7084 100644 (file)
@@ -113,7 +113,7 @@ $(MAKE_DIRS):
        mkdir -p $@
 
 # Get Clang's default includes on this system, as opposed to those seen by
-# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# '--target=bpf'. This fixes "missing" files on some architectures/distros,
 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
 #
 # Use '-idirafter': Don't interfere with include mechanics except where the
@@ -131,7 +131,7 @@ endif
 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
 
 $(OUTPUT)/nat6to4.o: nat6to4.c $(BPFOBJ) | $(MAKE_DIRS)
-       $(CLANG) -O2 -target bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
+       $(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
 
 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)                    \
           $(APIDIR)/linux/bpf.h                                               \
index cb553eac9f419a38a2be6377d49b62da19f623cd..3c4b7fa05075c7cddcb9a40bc9433aea4ed0b461 100644 (file)
@@ -24,7 +24,7 @@ CLANG_FLAGS = -I. -I$(APIDIR) \
 
 $(OUTPUT)/%.o: %.c
        $(CLANG) $(CLANG_FLAGS) \
-                -O2 -target bpf -emit-llvm -c $< -o - |      \
+                -O2 --target=bpf -emit-llvm -c $< -o - |      \
        $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@
 
 TEST_PROGS += ./tdc.sh