samples/bpf: Base target programs rules on Makefile.target

The main reason for that - HOSTCC and CC have different aims.
HOSTCC is used to build programs running on host, that can
cross-comple target programs with CC. It was tested for arm and arm64
cross compilation, based on linaro toolchain, but should work for
others.

So, in order to split cross compilation (CC) with host build (HOSTCC),
lets base samples on Makefile.target. It allows to cross-compile
samples/bpf programs with CC while auxialry tools running on host
built with HOSTCC.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20191011002808.28206-9-ivan.khoronzhuk@linaro.org
This commit is contained in:
Ivan Khoronzhuk 2019-10-11 03:28:01 +03:00 committed by Alexei Starovoitov
parent 752677e89f
commit 1d97c6c251
1 changed files with 69 additions and 66 deletions

View File

@ -4,55 +4,53 @@ BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
# List of programs to build # List of programs to build
hostprogs-y := test_lru_dist tprogs-y := test_lru_dist
hostprogs-y += sock_example tprogs-y += sock_example
hostprogs-y += fds_example tprogs-y += fds_example
hostprogs-y += sockex1 tprogs-y += sockex1
hostprogs-y += sockex2 tprogs-y += sockex2
hostprogs-y += sockex3 tprogs-y += sockex3
hostprogs-y += tracex1 tprogs-y += tracex1
hostprogs-y += tracex2 tprogs-y += tracex2
hostprogs-y += tracex3 tprogs-y += tracex3
hostprogs-y += tracex4 tprogs-y += tracex4
hostprogs-y += tracex5 tprogs-y += tracex5
hostprogs-y += tracex6 tprogs-y += tracex6
hostprogs-y += tracex7 tprogs-y += tracex7
hostprogs-y += test_probe_write_user tprogs-y += test_probe_write_user
hostprogs-y += trace_output tprogs-y += trace_output
hostprogs-y += lathist tprogs-y += lathist
hostprogs-y += offwaketime tprogs-y += offwaketime
hostprogs-y += spintest tprogs-y += spintest
hostprogs-y += map_perf_test tprogs-y += map_perf_test
hostprogs-y += test_overhead tprogs-y += test_overhead
hostprogs-y += test_cgrp2_array_pin tprogs-y += test_cgrp2_array_pin
hostprogs-y += test_cgrp2_attach tprogs-y += test_cgrp2_attach
hostprogs-y += test_cgrp2_sock tprogs-y += test_cgrp2_sock
hostprogs-y += test_cgrp2_sock2 tprogs-y += test_cgrp2_sock2
hostprogs-y += xdp1 tprogs-y += xdp1
hostprogs-y += xdp2 tprogs-y += xdp2
hostprogs-y += xdp_router_ipv4 tprogs-y += xdp_router_ipv4
hostprogs-y += test_current_task_under_cgroup tprogs-y += test_current_task_under_cgroup
hostprogs-y += trace_event tprogs-y += trace_event
hostprogs-y += sampleip tprogs-y += sampleip
hostprogs-y += tc_l2_redirect tprogs-y += tc_l2_redirect
hostprogs-y += lwt_len_hist tprogs-y += lwt_len_hist
hostprogs-y += xdp_tx_iptunnel tprogs-y += xdp_tx_iptunnel
hostprogs-y += test_map_in_map tprogs-y += test_map_in_map
hostprogs-y += per_socket_stats_example tprogs-y += xdp_redirect_map
hostprogs-y += xdp_redirect tprogs-y += xdp_redirect_cpu
hostprogs-y += xdp_redirect_map tprogs-y += xdp_monitor
hostprogs-y += xdp_redirect_cpu tprogs-y += xdp_rxq_info
hostprogs-y += xdp_monitor tprogs-y += syscall_tp
hostprogs-y += xdp_rxq_info tprogs-y += cpustat
hostprogs-y += syscall_tp tprogs-y += xdp_adjust_tail
hostprogs-y += cpustat tprogs-y += xdpsock
hostprogs-y += xdp_adjust_tail tprogs-y += xdp_fwd
hostprogs-y += xdpsock tprogs-y += task_fd_query
hostprogs-y += xdp_fwd tprogs-y += xdp_sample_pkts
hostprogs-y += task_fd_query tprogs-y += ibumad
hostprogs-y += xdp_sample_pkts tprogs-y += hbm
hostprogs-y += ibumad
hostprogs-y += hbm
# Libbpf dependencies # Libbpf dependencies
LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
@ -111,7 +109,7 @@ ibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS)
hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS) hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS)
# Tell kbuild to always build the programs # Tell kbuild to always build the programs
always := $(hostprogs-y) always := $(tprogs-y)
always += sockex1_kern.o always += sockex1_kern.o
always += sockex2_kern.o always += sockex2_kern.o
always += sockex3_kern.o always += sockex3_kern.o
@ -170,29 +168,32 @@ always += ibumad_kern.o
always += hbm_out_kern.o always += hbm_out_kern.o
always += hbm_edt_kern.o always += hbm_edt_kern.o
KBUILD_HOSTCFLAGS += -I$(objtree)/usr/include
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/bpf/
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
HOSTCFLAGS_bpf_load.o += -Wno-unused-variable
KBUILD_HOSTLDLIBS += $(LIBBPF) -lelf
HOSTLDLIBS_tracex4 += -lrt
HOSTLDLIBS_trace_output += -lrt
HOSTLDLIBS_map_perf_test += -lrt
HOSTLDLIBS_test_overhead += -lrt
HOSTLDLIBS_xdpsock += -pthread
ifeq ($(ARCH), arm) ifeq ($(ARCH), arm)
# Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux # Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux
# headers when arm instruction set identification is requested. # headers when arm instruction set identification is requested.
ARM_ARCH_SELECTOR := $(filter -D__LINUX_ARM_ARCH__%, $(KBUILD_CFLAGS)) ARM_ARCH_SELECTOR := $(filter -D__LINUX_ARM_ARCH__%, $(KBUILD_CFLAGS))
BPF_EXTRA_CFLAGS := $(ARM_ARCH_SELECTOR) BPF_EXTRA_CFLAGS := $(ARM_ARCH_SELECTOR)
KBUILD_HOSTCFLAGS += $(ARM_ARCH_SELECTOR) TPROGS_CFLAGS += $(ARM_ARCH_SELECTOR)
endif endif
TPROGS_LDLIBS := $(KBUILD_HOSTLDLIBS)
TPROGS_CFLAGS += $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS)
TPROGS_CFLAGS += -I$(objtree)/usr/include
TPROGS_CFLAGS += -I$(srctree)/tools/lib/bpf/
TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
TPROGS_CFLAGS += -I$(srctree)/tools/lib/
TPROGS_CFLAGS += -I$(srctree)/tools/include
TPROGS_CFLAGS += -I$(srctree)/tools/perf
TPROGCFLAGS_bpf_load.o += -Wno-unused-variable
TPROGS_LDLIBS += $(LIBBPF) -lelf
TPROGLDLIBS_tracex4 += -lrt
TPROGLDLIBS_trace_output += -lrt
TPROGLDLIBS_map_perf_test += -lrt
TPROGLDLIBS_test_overhead += -lrt
TPROGLDLIBS_xdpsock += -pthread
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang # make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
LLC ?= llc LLC ?= llc
@ -283,6 +284,8 @@ $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
$(obj)/hbm.o: $(src)/hbm.h $(obj)/hbm.o: $(src)/hbm.h
$(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
-include $(BPF_SAMPLES_PATH)/Makefile.target
# asm/sysreg.h - inline assembly used by it is incompatible with llvm. # asm/sysreg.h - inline assembly used by it is incompatible with llvm.
# But, there is no easy way to fix it, so just exclude it since it is # But, there is no easy way to fix it, so just exclude it since it is
# useless for BPF samples. # useless for BPF samples.