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

tools: Factor Clang, LLC and LLVM utils definitions

When dealing with BPF/BTF/pahole and DWARF v5 I wanted to build bpftool.

While looking into the source code I found duplicate assignments in misc tools
for the LLVM eco system, e.g. clang and llvm-objcopy.

Move the Clang, LLC and/or LLVM utils definitions to tools/scripts/Makefile.include
file and add missing includes where needed. Honestly, I was inspired by the commit
c8a950d0d3b9 ("tools: Factor HOSTCC, HOSTLD, HOSTAR definitions").

I tested with bpftool and perf on Debian/testing AMD64 and LLVM/Clang v11.1.0-rc1.

Build instructions:

[ make and make-options ]
MAKE="make V=1"
MAKE_OPTS="HOSTCC=clang HOSTCXX=clang++ HOSTLD=ld.lld CC=clang LD=ld.lld LLVM=1 LLVM_IAS=1"
MAKE_OPTS="$MAKE_OPTS PAHOLE=/opt/pahole/bin/pahole"

[ clean-up ]
$MAKE $MAKE_OPTS -C tools/ clean

[ bpftool ]
$MAKE $MAKE_OPTS -C tools/bpf/bpftool/

[ perf ]
PYTHON=python3 $MAKE $MAKE_OPTS -C tools/perf/

I was careful with respecting the user's wish to override custom compiler, linker,
GNU/binutils and/or LLVM utils settings.

Signed-off-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com> # tools/build and tools/perf
Link: https://lore.kernel.org/bpf/20210128015117.20515-1-sedat.dilek@gmail.com

authored by

Sedat Dilek and committed by
Daniel Borkmann
211a741c 8259fdeb

+10 -12
-2
tools/bpf/bpftool/Makefile
··· 75 75 76 76 INSTALL ?= install 77 77 RM ?= rm -f 78 - CLANG ?= clang 79 - LLVM_STRIP ?= llvm-strip 80 78 81 79 FEATURE_USER = .bpftool 82 80 FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib libcap \
-3
tools/bpf/runqslower/Makefile
··· 3 3 4 4 OUTPUT ?= $(abspath .output)/ 5 5 6 - CLANG ?= clang 7 - LLC ?= llc 8 - LLVM_STRIP ?= llvm-strip 9 6 BPFTOOL_OUTPUT := $(OUTPUT)bpftool/ 10 7 DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bpftool 11 8 BPFTOOL ?= $(DEFAULT_BPFTOOL)
+2 -2
tools/build/feature/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + include ../../scripts/Makefile.include 3 + 2 4 FILES= \ 3 5 test-all.bin \ 4 6 test-backtrace.bin \ ··· 78 76 FILES := $(addprefix $(OUTPUT),$(FILES)) 79 77 80 78 PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config 81 - LLVM_CONFIG ?= llvm-config 82 - CLANG ?= clang 83 79 84 80 all: $(FILES) 85 81
-1
tools/perf/Makefile.perf
··· 176 176 LD += $(EXTRA_LDFLAGS) 177 177 178 178 PKG_CONFIG = $(CROSS_COMPILE)pkg-config 179 - LLVM_CONFIG ?= llvm-config 180 179 181 180 RM = rm -f 182 181 LN = ln -f
+7
tools/scripts/Makefile.include
··· 69 69 HOSTLD ?= ld 70 70 endif 71 71 72 + # Some tools require Clang, LLC and/or LLVM utils 73 + CLANG ?= clang 74 + LLC ?= llc 75 + LLVM_CONFIG ?= llvm-config 76 + LLVM_OBJCOPY ?= llvm-objcopy 77 + LLVM_STRIP ?= llvm-strip 78 + 72 79 ifeq ($(CC_NO_CLANG), 1) 73 80 EXTRA_WARNINGS += -Wstrict-aliasing=3 74 81 endif
-2
tools/testing/selftests/bpf/Makefile
··· 19 19 GENFLAGS := -DHAVE_GENHDR 20 20 endif 21 21 22 - CLANG ?= clang 23 - LLVM_OBJCOPY ?= llvm-objcopy 24 22 BPF_GCC ?= $(shell command -v bpf-gcc;) 25 23 SAN_CFLAGS ?= 26 24 CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) $(SAN_CFLAGS) \
+1 -2
tools/testing/selftests/tc-testing/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + include ../../../scripts/Makefile.include 2 3 3 4 top_srcdir = $(abspath ../../../..) 4 5 APIDIR := $(top_scrdir)/include/uapi ··· 8 7 KSFT_KHDR_INSTALL := 1 9 8 include ../lib.mk 10 9 11 - CLANG ?= clang 12 - LLC ?= llc 13 10 PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1) 14 11 15 12 ifeq ($(PROBE),)