Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Replace deprecated -target with --target= for Clang

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

authored by

Fangrui Song and committed by
Daniel Borkmann
bbaf1ff0 da1a055d

+35 -35
+5 -5
Documentation/bpf/bpf_devel_QA.rst
··· 635 635 636 636 Q: clang flag for target bpf? 637 637 ----------------------------- 638 - Q: In some cases clang flag ``-target bpf`` is used but in other cases the 638 + Q: In some cases clang flag ``--target=bpf`` is used but in other cases the 639 639 default clang target, which matches the underlying architecture, is used. 640 640 What is the difference and when I should use which? 641 641 642 642 A: Although LLVM IR generation and optimization try to stay architecture 643 - independent, ``-target <arch>`` still has some impact on generated code: 643 + independent, ``--target=<arch>`` still has some impact on generated code: 644 644 645 645 - BPF program may recursively include header file(s) with file scope 646 646 inline assembly codes. The default target can handle this well, ··· 658 658 The clang option ``-fno-jump-tables`` can be used to disable 659 659 switch table generation. 660 660 661 - - For clang ``-target bpf``, it is guaranteed that pointer or long / 661 + - For clang ``--target=bpf``, it is guaranteed that pointer or long / 662 662 unsigned long types will always have a width of 64 bit, no matter 663 663 whether underlying clang binary or default target (or kernel) is 664 664 32 bit. However, when native clang target is used, then it will ··· 668 668 while the BPF LLVM back end still operates in 64 bit. The native 669 669 target is mostly needed in tracing for the case of walking ``pt_regs`` 670 670 or other kernel structures where CPU's register width matters. 671 - Otherwise, ``clang -target bpf`` is generally recommended. 671 + Otherwise, ``clang --target=bpf`` is generally recommended. 672 672 673 673 You should use default target when: 674 674 ··· 685 685 into these structures is verified by the BPF verifier and may result 686 686 in verification failures if the native architecture is not aligned with 687 687 the BPF architecture, e.g. 64-bit. An example of this is 688 - BPF_PROG_TYPE_SK_MSG require ``-target bpf`` 688 + BPF_PROG_TYPE_SK_MSG require ``--target=bpf`` 689 689 690 690 691 691 .. Links
+2 -2
Documentation/bpf/btf.rst
··· 990 990 } g2; 991 991 int main() { return 0; } 992 992 int test() { return 0; } 993 - -bash-4.4$ clang -c -g -O2 -target bpf t2.c 993 + -bash-4.4$ clang -c -g -O2 --target=bpf t2.c 994 994 -bash-4.4$ readelf -S t2.o 995 995 ...... 996 996 [ 8] .BTF PROGBITS 0000000000000000 00000247 ··· 1000 1000 [10] .rel.BTF.ext REL 0000000000000000 000007e0 1001 1001 0000000000000040 0000000000000010 16 9 8 1002 1002 ...... 1003 - -bash-4.4$ clang -S -g -O2 -target bpf t2.c 1003 + -bash-4.4$ clang -S -g -O2 --target=bpf t2.c 1004 1004 -bash-4.4$ cat t2.s 1005 1005 ...... 1006 1006 .section .BTF,"",@progbits
+3 -3
Documentation/bpf/llvm_reloc.rst
··· 28 28 return g1 + g2 + l1 + l2; 29 29 } 30 30 31 - Compiled with ``clang -target bpf -O2 -c test.c``, the following is 31 + Compiled with ``clang --target=bpf -O2 -c test.c``, the following is 32 32 the code with ``llvm-objdump -dr test.o``:: 33 33 34 34 0: 18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll ··· 157 157 return gfunc(a, b) + lfunc(a, b) + global; 158 158 } 159 159 160 - Compiled with ``clang -target bpf -O2 -c test.c``, we will have 160 + Compiled with ``clang --target=bpf -O2 -c test.c``, we will have 161 161 following code with `llvm-objdump -dr test.o``:: 162 162 163 163 Disassembly of section .text: ··· 203 203 int global() { return 0; } 204 204 struct t { void *g; } gbl = { global }; 205 205 206 - Compiled with ``clang -target bpf -O2 -g -c test.c``, we will see a 206 + Compiled with ``clang --target=bpf -O2 -g -c test.c``, we will see a 207 207 relocation below in ``.data`` section with command 208 208 ``llvm-readelf -r test.o``:: 209 209
+1 -1
drivers/hid/bpf/entrypoints/Makefile
··· 58 58 59 59 $(OUTPUT)/entrypoints.bpf.o: entrypoints.bpf.c $(OUTPUT)/vmlinux.h $(BPFOBJ) | $(OUTPUT) 60 60 $(call msg,BPF,$@) 61 - $(Q)$(CLANG) -g -O2 -target bpf $(INCLUDES) \ 61 + $(Q)$(CLANG) -g -O2 --target=bpf $(INCLUDES) \ 62 62 -c $(filter %.c,$^) -o $@ && \ 63 63 $(LLVM_STRIP) -g $@ 64 64
+1 -1
kernel/bpf/preload/iterators/Makefile
··· 50 50 $(OUTPUT)/%/iterators.bpf.o: iterators.bpf.c $(BPFOBJ) | $(OUTPUT) 51 51 $(call msg,BPF,$@) 52 52 $(Q)mkdir -p $(@D) 53 - $(Q)$(CLANG) -g -O2 -target bpf -m$* $(INCLUDES) \ 53 + $(Q)$(CLANG) -g -O2 --target=bpf -m$* $(INCLUDES) \ 54 54 -c $(filter %.c,$^) -o $@ && \ 55 55 $(LLVM_STRIP) -g $@ 56 56
+3 -3
samples/bpf/Makefile
··· 248 248 BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF) 249 249 BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm') 250 250 BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \ 251 - $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \ 251 + $(CLANG) --target=bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \ 252 252 $(LLVM_READELF) -S ./llvm_btf_verify.o | grep BTF; \ 253 253 /bin/rm -f ./llvm_btf_verify.o) 254 254 ··· 370 370 clean-files += vmlinux.h 371 371 372 372 # Get Clang's default includes on this system, as opposed to those seen by 373 - # '-target bpf'. This fixes "missing" files on some architectures/distros, 373 + # '--target=bpf'. This fixes "missing" files on some architectures/distros, 374 374 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 375 375 # 376 376 # Use '-idirafter': Don't interfere with include mechanics except where the ··· 392 392 393 393 $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h 394 394 @echo " CLANG-BPF " $@ 395 - $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(SRCARCH) \ 395 + $(Q)$(CLANG) -g -O2 --target=bpf -D__TARGET_ARCH_$(SRCARCH) \ 396 396 -Wno-compare-distinct-pointer-types -I$(srctree)/include \ 397 397 -I$(srctree)/samples/bpf -I$(srctree)/tools/include \ 398 398 -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) \
+1 -1
samples/bpf/gnu/stubs.h
··· 1 - /* dummy .h to trick /usr/include/features.h to work with 'clang -target bpf' */ 1 + /* dummy .h to trick /usr/include/features.h to work with 'clang --target=bpf' */
+1 -1
samples/bpf/test_lwt_bpf.sh
··· 376 376 SRC_MAC=$(lookup_mac $VETH0) 377 377 DST_IFINDEX=$(cat /sys/class/net/$VETH0/ifindex) 378 378 379 - CLANG_OPTS="-O2 -target bpf -I ../include/" 379 + CLANG_OPTS="-O2 --target=bpf -I ../include/" 380 380 CLANG_OPTS+=" -DSRC_MAC=$SRC_MAC -DDST_MAC=$DST_MAC -DDST_IFINDEX=$DST_IFINDEX" 381 381 clang $CLANG_OPTS -c $PROG_SRC -o $BPF_PROG 382 382
+3 -3
samples/hid/Makefile
··· 86 86 BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF) 87 87 BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm') 88 88 BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \ 89 - $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \ 89 + $(CLANG) --target=bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \ 90 90 $(LLVM_READELF) -S ./llvm_btf_verify.o | grep BTF; \ 91 91 /bin/rm -f ./llvm_btf_verify.o) 92 92 ··· 181 181 clean-files += vmlinux.h 182 182 183 183 # Get Clang's default includes on this system, as opposed to those seen by 184 - # '-target bpf'. This fixes "missing" files on some architectures/distros, 184 + # '--target=bpf'. This fixes "missing" files on some architectures/distros, 185 185 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 186 186 # 187 187 # Use '-idirafter': Don't interfere with include mechanics except where the ··· 198 198 199 199 $(obj)/%.bpf.o: $(src)/%.bpf.c $(EXTRA_BPF_HEADERS_SRC) $(obj)/vmlinux.h 200 200 @echo " CLANG-BPF " $@ 201 - $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(SRCARCH) \ 201 + $(Q)$(CLANG) -g -O2 --target=bpf -D__TARGET_ARCH_$(SRCARCH) \ 202 202 -Wno-compare-distinct-pointer-types -I$(srctree)/include \ 203 203 -I$(srctree)/samples/bpf -I$(srctree)/tools/include \ 204 204 -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) \
+2 -2
tools/bpf/bpftool/Documentation/bpftool-gen.rst
··· 260 260 This is example BPF application with two BPF programs and a mix of BPF maps 261 261 and global variables. Source code is split across two source code files. 262 262 263 - **$ clang -target bpf -g example1.bpf.c -o example1.bpf.o** 263 + **$ clang --target=bpf -g example1.bpf.c -o example1.bpf.o** 264 264 265 - **$ clang -target bpf -g example2.bpf.c -o example2.bpf.o** 265 + **$ clang --target=bpf -g example2.bpf.c -o example2.bpf.o** 266 266 267 267 **$ bpftool gen object example.bpf.o example1.bpf.o example2.bpf.o** 268 268
+1 -1
tools/bpf/bpftool/Makefile
··· 216 216 -I$(srctree)/tools/include/uapi/ \ 217 217 -I$(LIBBPF_BOOTSTRAP_INCLUDE) \ 218 218 -g -O2 -Wall -fno-stack-protector \ 219 - -target bpf -c $< -o $@ 219 + --target=bpf -c $< -o $@ 220 220 $(Q)$(LLVM_STRIP) -g $@ 221 221 222 222 $(OUTPUT)%.skel.h: $(OUTPUT)%.bpf.o $(BPFTOOL_BOOTSTRAP)
+1 -1
tools/bpf/runqslower/Makefile
··· 62 62 $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@ 63 63 64 64 $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT) 65 - $(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES) \ 65 + $(QUIET_GEN)$(CLANG) -g -O2 --target=bpf $(INCLUDES) \ 66 66 -c $(filter %.c,$^) -o $@ && \ 67 67 $(LLVM_STRIP) -g $@ 68 68
+1 -1
tools/build/feature/Makefile
··· 372 372 $(BUILD) -lzstd 373 373 374 374 $(OUTPUT)test-clang-bpf-co-re.bin: 375 - $(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) | \ 375 + $(CLANG) -S -g --target=bpf -o - $(patsubst %.bin,%.c,$(@F)) | \ 376 376 grep BTF_KIND_VAR 377 377 378 378 $(OUTPUT)test-file-handle.bin:
+3 -3
tools/testing/selftests/bpf/Makefile
··· 331 331 OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ) 332 332 333 333 # Get Clang's default includes on this system, as opposed to those seen by 334 - # '-target bpf'. This fixes "missing" files on some architectures/distros, 334 + # '--target=bpf'. This fixes "missing" files on some architectures/distros, 335 335 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 336 336 # 337 337 # Use '-idirafter': Don't interfere with include mechanics except where the ··· 372 372 # $3 - CFLAGS 373 373 define CLANG_BPF_BUILD_RULE 374 374 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 375 - $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v3 -o $2 375 + $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v3 -o $2 376 376 endef 377 377 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32 378 378 define CLANG_NOALU32_BPF_BUILD_RULE 379 379 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 380 - $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v2 -o $2 380 + $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v2 -o $2 381 381 endef 382 382 # Build BPF object using GCC 383 383 define GCC_BPF_BUILD_RULE
+1 -1
tools/testing/selftests/bpf/gnu/stubs.h
··· 1 - /* dummy .h to trick /usr/include/features.h to work with 'clang -target bpf' */ 1 + /* dummy .h to trick /usr/include/features.h to work with 'clang --target=bpf' */
+3 -3
tools/testing/selftests/hid/Makefile
··· 167 167 OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ) 168 168 169 169 # Get Clang's default includes on this system, as opposed to those seen by 170 - # '-target bpf'. This fixes "missing" files on some architectures/distros, 170 + # '--target=bpf'. This fixes "missing" files on some architectures/distros, 171 171 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 172 172 # 173 173 # Use '-idirafter': Don't interfere with include mechanics except where the ··· 196 196 # $3 - CFLAGS 197 197 define CLANG_BPF_BUILD_RULE 198 198 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 199 - $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v3 -o $2 199 + $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v3 -o $2 200 200 endef 201 201 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32 202 202 define CLANG_NOALU32_BPF_BUILD_RULE 203 203 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 204 - $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v2 -o $2 204 + $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v2 -o $2 205 205 endef 206 206 # Build BPF object using GCC 207 207 define GCC_BPF_BUILD_RULE
+2 -2
tools/testing/selftests/net/Makefile
··· 113 113 mkdir -p $@ 114 114 115 115 # Get Clang's default includes on this system, as opposed to those seen by 116 - # '-target bpf'. This fixes "missing" files on some architectures/distros, 116 + # '--target=bpf'. This fixes "missing" files on some architectures/distros, 117 117 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 118 118 # 119 119 # Use '-idirafter': Don't interfere with include mechanics except where the ··· 131 131 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) 132 132 133 133 $(OUTPUT)/nat6to4.o: nat6to4.c $(BPFOBJ) | $(MAKE_DIRS) 134 - $(CLANG) -O2 -target bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@ 134 + $(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@ 135 135 136 136 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ 137 137 $(APIDIR)/linux/bpf.h \
+1 -1
tools/testing/selftests/tc-testing/Makefile
··· 24 24 25 25 $(OUTPUT)/%.o: %.c 26 26 $(CLANG) $(CLANG_FLAGS) \ 27 - -O2 -target bpf -emit-llvm -c $< -o - | \ 27 + -O2 --target=bpf -emit-llvm -c $< -o - | \ 28 28 $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@ 29 29 30 30 TEST_PROGS += ./tdc.sh