Skip to content

Commit 89ad742

Browse files
Andrew Delgadilloanakryiko
Andrew Delgadillo
authored andcommitted
selftests/bpf: Drop the need for LLVM's llc
LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end. Additionally, simplify the Makefile by removing the CLANG_NATIVE_BPF_BUILD_RULE as it is not being use, stop passing dwarfris attr since elfutils/libdw now supports the bpf backend (which should work with any recent pahole), and stop passing alu32 since -mcpu=v3 implies alu32. Signed-off-by: Andrew Delgadillo <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a67079b commit 89ad742

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ifneq ($(wildcard $(GENHDR)),)
1919
endif
2020

2121
CLANG ?= clang
22-
LLC ?= llc
2322
LLVM_OBJCOPY ?= llvm-objcopy
2423
BPF_GCC ?= $(shell command -v bpf-gcc;)
2524
SAN_CFLAGS ?=
@@ -253,31 +252,19 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
253252
# $1 - input .c file
254253
# $2 - output .o file
255254
# $3 - CFLAGS
256-
# $4 - LDFLAGS
257255
define CLANG_BPF_BUILD_RULE
258-
$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
259-
$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm \
260-
-c $1 -o - || echo "BPF obj compilation failed") | \
261-
$(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
256+
$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
257+
$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v3
262258
endef
263259
# Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
264260
define CLANG_NOALU32_BPF_BUILD_RULE
265-
$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
266-
$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm \
267-
-c $1 -o - || echo "BPF obj compilation failed") | \
268-
$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
269-
endef
270-
# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
271-
define CLANG_NATIVE_BPF_BUILD_RULE
272261
$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
273-
$(Q)($(CLANG) $3 -O2 -emit-llvm \
274-
-c $1 -o - || echo "BPF obj compilation failed") | \
275-
$(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
262+
$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2
276263
endef
277264
# Build BPF object using GCC
278265
define GCC_BPF_BUILD_RULE
279266
$(call msg,GCC-BPF,$(TRUNNER_BINARY),$2)
280-
$(Q)$(BPF_GCC) $3 $4 -O2 -c $1 -o $2
267+
$(Q)$(BPF_GCC) $3 -O2 -c $1 -o $2
281268
endef
282269

283270
SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
@@ -332,8 +319,7 @@ $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \
332319
$$(INCLUDE_DIR)/vmlinux.h \
333320
$(wildcard $(BPFDIR)/bpf_*.h) | $(TRUNNER_OUTPUT)
334321
$$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \
335-
$(TRUNNER_BPF_CFLAGS), \
336-
$(TRUNNER_BPF_LDFLAGS))
322+
$(TRUNNER_BPF_CFLAGS))
337323

338324
$(TRUNNER_BPF_SKELS): $(TRUNNER_OUTPUT)/%.skel.h: \
339325
$(TRUNNER_OUTPUT)/%.o \
@@ -401,19 +387,16 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \
401387
$(wildcard progs/btf_dump_test_case_*.c)
402388
TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
403389
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
404-
TRUNNER_BPF_LDFLAGS := -mattr=+alu32
405390
$(eval $(call DEFINE_TEST_RUNNER,test_progs))
406391

407392
# Define test_progs-no_alu32 test runner.
408393
TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
409-
TRUNNER_BPF_LDFLAGS :=
410394
$(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
411395

412396
# Define test_progs BPF-GCC-flavored test runner.
413397
ifneq ($(BPF_GCC),)
414398
TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
415399
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
416-
TRUNNER_BPF_LDFLAGS :=
417400
$(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
418401
endif
419402

@@ -424,7 +407,6 @@ TRUNNER_EXTRA_SOURCES := test_maps.c
424407
TRUNNER_EXTRA_FILES :=
425408
TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
426409
TRUNNER_BPF_CFLAGS :=
427-
TRUNNER_BPF_LDFLAGS :=
428410
$(eval $(call DEFINE_TEST_RUNNER,test_maps))
429411

430412
# Define test_verifier test runner.

0 commit comments

Comments
 (0)