Commit 14e5728f authored by Song Liu's avatar Song Liu Committed by Daniel Borkmann

bpftool: Only build bpftool-prog-profile if supported by clang

bpftool-prog-profile requires clang to generate BTF for global variables.
When compared with older clang, skip this command. This is achieved by
adding a new feature, clang-bpf-global-var, to tools/build/feature.
Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20200312182332.3953408-2-songliubraving@fb.com
parent fe4eb069
...@@ -62,8 +62,9 @@ RM ?= rm -f ...@@ -62,8 +62,9 @@ RM ?= rm -f
CLANG ?= clang CLANG ?= clang
FEATURE_USER = .bpftool FEATURE_USER = .bpftool
FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib \
FEATURE_DISPLAY = libbfd disassembler-four-args zlib clang-bpf-global-var
FEATURE_DISPLAY = libbfd disassembler-four-args zlib clang-bpf-global-var
check_feat := 1 check_feat := 1
NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
...@@ -113,6 +114,12 @@ endif ...@@ -113,6 +114,12 @@ endif
OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
_OBJS = $(filter-out $(OUTPUT)prog.o,$(OBJS)) $(OUTPUT)_prog.o _OBJS = $(filter-out $(OUTPUT)prog.o,$(OBJS)) $(OUTPUT)_prog.o
ifeq ($(feature-clang-bpf-global-var),1)
__OBJS = $(OBJS)
else
__OBJS = $(_OBJS)
endif
$(OUTPUT)_prog.o: prog.c $(OUTPUT)_prog.o: prog.c
$(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $< $(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $<
...@@ -136,8 +143,8 @@ $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c ...@@ -136,8 +143,8 @@ $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
$(OUTPUT)feature.o: | zdep $(OUTPUT)feature.o: | zdep
$(OUTPUT)bpftool: $(OBJS) $(LIBBPF) $(OUTPUT)bpftool: $(__OBJS) $(LIBBPF)
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(__OBJS) $(LIBS)
$(OUTPUT)%.o: %.c $(OUTPUT)%.o: %.c
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
......
...@@ -1545,6 +1545,7 @@ static int do_loadall(int argc, char **argv) ...@@ -1545,6 +1545,7 @@ static int do_loadall(int argc, char **argv)
static int do_profile(int argc, char **argv) static int do_profile(int argc, char **argv)
{ {
p_err("bpftool prog profile command is not supported. Please build bpftool with clang >= 10.0.0");
return 0; return 0;
} }
......
...@@ -67,7 +67,8 @@ FILES= \ ...@@ -67,7 +67,8 @@ FILES= \
test-llvm.bin \ test-llvm.bin \
test-llvm-version.bin \ test-llvm-version.bin \
test-libaio.bin \ test-libaio.bin \
test-libzstd.bin test-libzstd.bin \
test-clang-bpf-global-var.bin
FILES := $(addprefix $(OUTPUT),$(FILES)) FILES := $(addprefix $(OUTPUT),$(FILES))
...@@ -75,6 +76,7 @@ CC ?= $(CROSS_COMPILE)gcc ...@@ -75,6 +76,7 @@ CC ?= $(CROSS_COMPILE)gcc
CXX ?= $(CROSS_COMPILE)g++ CXX ?= $(CROSS_COMPILE)g++
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
LLVM_CONFIG ?= llvm-config LLVM_CONFIG ?= llvm-config
CLANG ?= clang
all: $(FILES) all: $(FILES)
...@@ -321,6 +323,11 @@ $(OUTPUT)test-libaio.bin: ...@@ -321,6 +323,11 @@ $(OUTPUT)test-libaio.bin:
$(OUTPUT)test-libzstd.bin: $(OUTPUT)test-libzstd.bin:
$(BUILD) -lzstd $(BUILD) -lzstd
$(OUTPUT)test-clang-bpf-global-var.bin:
$(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) | \
grep BTF_KIND_VAR
############################### ###############################
clean: clean:
......
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 Facebook
volatile int global_value_for_test = 1;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment