Skip to content

Commit

Permalink
bpftool: Only build bpftool-prog-profile if supported by clang
Browse files Browse the repository at this point in the history
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: Song Liu <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Reviewed-by: Quentin Monnet <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
liu-song-6 authored and borkmann committed Mar 12, 2020
1 parent fe4eb06 commit 14e5728
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
15 changes: 11 additions & 4 deletions tools/bpf/bpftool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ RM ?= rm -f
CLANG ?= clang

FEATURE_USER = .bpftool
FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib
FEATURE_DISPLAY = libbfd disassembler-four-args zlib
FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib \
clang-bpf-global-var
FEATURE_DISPLAY = libbfd disassembler-four-args zlib clang-bpf-global-var

check_feat := 1
NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
Expand Down Expand Up @@ -113,6 +114,12 @@ endif
OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.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
$(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $<

Expand All @@ -136,8 +143,8 @@ $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c

$(OUTPUT)feature.o: | zdep

$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
$(OUTPUT)bpftool: $(__OBJS) $(LIBBPF)
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(__OBJS) $(LIBS)

$(OUTPUT)%.o: %.c
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
Expand Down
1 change: 1 addition & 0 deletions tools/bpf/bpftool/prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,7 @@ static int do_loadall(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;
}

Expand Down
9 changes: 8 additions & 1 deletion tools/build/feature/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ FILES= \
test-llvm.bin \
test-llvm-version.bin \
test-libaio.bin \
test-libzstd.bin
test-libzstd.bin \
test-clang-bpf-global-var.bin

FILES := $(addprefix $(OUTPUT),$(FILES))

CC ?= $(CROSS_COMPILE)gcc
CXX ?= $(CROSS_COMPILE)g++
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
LLVM_CONFIG ?= llvm-config
CLANG ?= clang

all: $(FILES)

Expand Down Expand Up @@ -321,6 +323,11 @@ $(OUTPUT)test-libaio.bin:
$(OUTPUT)test-libzstd.bin:
$(BUILD) -lzstd

$(OUTPUT)test-clang-bpf-global-var.bin:
$(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) | \
grep BTF_KIND_VAR


###############################

clean:
Expand Down
4 changes: 4 additions & 0 deletions tools/build/feature/test-clang-bpf-global-var.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 Facebook

volatile int global_value_for_test = 1;

0 comments on commit 14e5728

Please sign in to comment.