From patchwork Wed Sep 4 21:22:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 173078 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp454879ilq; Wed, 4 Sep 2019 14:23:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGmpfs2qG6T0WdlC3x1wvdbR42/o5a2SrbDVg0GBZ0V1NILfTK8cjS6DKsK/6avWuVYWij X-Received: by 2002:a63:d90f:: with SMTP id r15mr150130pgg.259.1567632195871; Wed, 04 Sep 2019 14:23:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567632195; cv=none; d=google.com; s=arc-20160816; b=eWF9o8qt5pBb+yeQIg54T04g3vA5p6fLHyKh1ypnjg8Uyrrxt4sPyAcNVX2VE1Ugi8 6fNIJBdtn/rrdbu3R8Gvpove5eeM/wtXFsAmznp6N7tZJMRbUKx/cKu67h3KNiZYteop RSbNhl7DvQcOCe/WvvF8EKJPbbOAT7aG013kmZ70vGfbVBY4ywKsxrPKrAHF3wWEFgdO b04/JuWzDKi9xkSSsgkx5VMIbBCtzo61EryxGi/1TEA4t/FspwE2ClPe5Yn2ATUqEDFW PYskJCrbuu3hNhOAMS25Anho4CxYx/e4Qej9qxQ4rRzhWpM/E+aUNtSinGb2gw3eWOFk sT6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=LT/VbQvHwKdykK+LZeZdbR4ubTJg9E+tpSt48zuAEBQ=; b=HLXougENVjlVxkzG1Z07D+oJ7nLoa9p1/1OJQlvBpWtEA2EiMQhgYy2SGVR/S0NPEO MX7JKeZ3jt0UVJN/keGoX8pcgoZOzgF+8c0qRmqPM7BawMcsciiQXRR1biZM6MGWr3ip TE0r8XM/gTbMe0QaTgBcaZrT1hynHyYJG+tbnIkAaO2ESXjo5E+gGOih2pj0mnJ/YMse QrVLhYIMqJH8wJGVxlQ9E+onDD+NVgCbpFyvoyT2ryEyJ1nvdujh7mVwovZj/lK7iWty Y+/3eng2D+8Cyq/VdAxiI7da8XcfHzczBfCZivTrbVHcHh8HXrDoCK9JS+xjGhxXYVCE pL+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c+pDBYNm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y186si17766399pgd.440.2019.09.04.14.23.15; Wed, 04 Sep 2019 14:23:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c+pDBYNm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730778AbfIDVXO (ORCPT + 28 others); Wed, 4 Sep 2019 17:23:14 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:47013 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730599AbfIDVXN (ORCPT ); Wed, 4 Sep 2019 17:23:13 -0400 Received: by mail-lj1-f193.google.com with SMTP id e17so147813ljf.13 for ; Wed, 04 Sep 2019 14:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LT/VbQvHwKdykK+LZeZdbR4ubTJg9E+tpSt48zuAEBQ=; b=c+pDBYNmGKQOLh8g4Xd+cJoZUuLqBQFVNtkw6u+Eu6w3Ib4JBhGO5EUPHYjHm15ia6 PwYR+OpAOG2O2VFgoSPtAlYIT4D2b1bIO0WD2nzAAgGgUlnQ5BF1Y4b2kxjCcLbkRYEO PlB13F4S5OCPe6G7haHW0Rs5+FZujk3N1dVxybykSrBtr17I830Mhwt6A9pFQBBeE5xb tgANQJXzB0nyYGPSOmpnsI6qqL2iGljn3JFIgaEj1IycW3W+yxGyUR5I3Q3gCtF/pyeA Q6vPERylcsqOXEgoq0yteAsDc2GX/aSKXHMlRW/QxOAO93BemfJmAX3NxRfrkvBHwJhj EGOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LT/VbQvHwKdykK+LZeZdbR4ubTJg9E+tpSt48zuAEBQ=; b=Pa2Gkj0wIFntyrdi7kXamXqdDAmvzPvgsxgnOwYVOo6uYIdJZeT3QXJtVtN9s1a6ZE CMnNma/0QQNhJ5rZ0n+Wm+OOdCZTVKMEnE82EIqI6NQvg5M9TWvhtEu0QHuaiPMAjNGx AlH23wodiVjRsOP2ul7O9aDLcVAbwyFvkIaW2VibCpq91r2x+PyNzAzvyPLTxi9t7NgR Q9U7jl+TvWdKvHf0fsvvHuV48abi9jD5UrA7YFd7Hl0Kod2B+lR6q/msfukO0DQVCof2 2wQ6BZ7DnnBo88/jkzJoEnhtGulP6OGbZ47HZVZJoDHGQTqCuvXt+lxlx98pO0LVOI/9 WN3A== X-Gm-Message-State: APjAAAVmcAThtJhxfcgWOpf++CZ8BRW4CGq9cUOVK8g94/bCySwPtQ5I nRlnlBRioCTk9D+32uT1NoPG/w== X-Received: by 2002:a2e:8510:: with SMTP id j16mr24485327lji.174.1567632190563; Wed, 04 Sep 2019 14:23:10 -0700 (PDT) Received: from localhost.localdomain (168-200-94-178.pool.ukrtel.net. [178.94.200.168]) by smtp.gmail.com with ESMTPSA id s8sm3540836ljd.94.2019.09.04.14.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 14:23:10 -0700 (PDT) From: Ivan Khoronzhuk To: ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, davem@davemloft.net, jakub.kicinski@netronome.com, hawk@kernel.org, john.fastabend@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, clang-built-linux@googlegroups.com, Ivan Khoronzhuk Subject: [PATCH bpf-next 8/8] samples: bpf: Makefile: base progs build on Makefile.progs Date: Thu, 5 Sep 2019 00:22:12 +0300 Message-Id: <20190904212212.13052-9-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904212212.13052-1-ivan.khoronzhuk@linaro.org> References: <20190904212212.13052-1-ivan.khoronzhuk@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The main reason for that - HOSTCC and CC have different aims. It was tested for arm cross compilation, based on linaro toolchain, but should work for others. In order to split cross compilation with host build, base bpf samples on Makefile.progs. It's also convenient when NFC is used: export ARCH=arm export CROSS_COMPILE=arm-linux-gnueabihf- make samples/bpf/ SYSROOT="path/to/sysroot" Sysroot contains correct headers installed ofc. Signed-off-by: Ivan Khoronzhuk --- samples/bpf/Makefile | 164 ++++++++++++++++++++++++----------------- samples/bpf/README.rst | 7 ++ 2 files changed, 102 insertions(+), 69 deletions(-) -- 2.17.1 diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 043f9cc14cdd..ed7131851172 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -4,55 +4,53 @@ BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src)) TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools # List of programs to build -hostprogs-y := test_lru_dist -hostprogs-y += sock_example -hostprogs-y += fds_example -hostprogs-y += sockex1 -hostprogs-y += sockex2 -hostprogs-y += sockex3 -hostprogs-y += tracex1 -hostprogs-y += tracex2 -hostprogs-y += tracex3 -hostprogs-y += tracex4 -hostprogs-y += tracex5 -hostprogs-y += tracex6 -hostprogs-y += tracex7 -hostprogs-y += test_probe_write_user -hostprogs-y += trace_output -hostprogs-y += lathist -hostprogs-y += offwaketime -hostprogs-y += spintest -hostprogs-y += map_perf_test -hostprogs-y += test_overhead -hostprogs-y += test_cgrp2_array_pin -hostprogs-y += test_cgrp2_attach -hostprogs-y += test_cgrp2_sock -hostprogs-y += test_cgrp2_sock2 -hostprogs-y += xdp1 -hostprogs-y += xdp2 -hostprogs-y += xdp_router_ipv4 -hostprogs-y += test_current_task_under_cgroup -hostprogs-y += trace_event -hostprogs-y += sampleip -hostprogs-y += tc_l2_redirect -hostprogs-y += lwt_len_hist -hostprogs-y += xdp_tx_iptunnel -hostprogs-y += test_map_in_map -hostprogs-y += per_socket_stats_example -hostprogs-y += xdp_redirect -hostprogs-y += xdp_redirect_map -hostprogs-y += xdp_redirect_cpu -hostprogs-y += xdp_monitor -hostprogs-y += xdp_rxq_info -hostprogs-y += syscall_tp -hostprogs-y += cpustat -hostprogs-y += xdp_adjust_tail -hostprogs-y += xdpsock -hostprogs-y += xdp_fwd -hostprogs-y += task_fd_query -hostprogs-y += xdp_sample_pkts -hostprogs-y += ibumad -hostprogs-y += hbm +progs-y := test_lru_dist +progs-y += sock_example +progs-y += fds_example +progs-y += sockex1 +progs-y += sockex2 +progs-y += sockex3 +progs-y += tracex1 +progs-y += tracex2 +progs-y += tracex3 +progs-y += tracex4 +progs-y += tracex5 +progs-y += tracex6 +progs-y += tracex7 +progs-y += test_probe_write_user +progs-y += trace_output +progs-y += lathist +progs-y += offwaketime +progs-y += spintest +progs-y += map_perf_test +progs-y += test_overhead +progs-y += test_cgrp2_array_pin +progs-y += test_cgrp2_attach +progs-y += test_cgrp2_sock +progs-y += test_cgrp2_sock2 +progs-y += xdp1 +progs-y += xdp2 +progs-y += xdp_router_ipv4 +progs-y += test_current_task_under_cgroup +progs-y += trace_event +progs-y += sampleip +progs-y += tc_l2_redirect +progs-y += lwt_len_hist +progs-y += xdp_tx_iptunnel +progs-y += test_map_in_map +progs-y += xdp_redirect_map +progs-y += xdp_redirect_cpu +progs-y += xdp_monitor +progs-y += xdp_rxq_info +progs-y += syscall_tp +progs-y += cpustat +progs-y += xdp_adjust_tail +progs-y += xdpsock +progs-y += xdp_fwd +progs-y += task_fd_query +progs-y += xdp_sample_pkts +progs-y += ibumad +progs-y += hbm # Libbpf dependencies 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) # Tell kbuild to always build the programs -always := $(hostprogs-y) +always := $(progs-y) always += sockex1_kern.o always += sockex2_kern.o always += sockex3_kern.o @@ -171,26 +169,51 @@ always += ibumad_kern.o always += hbm_out_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 += -I$(objtree)/usr/include -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 - # Strip all expet -D options needed to handle linux headers # for arm it's __LINUX_ARM_ARCH__ and potentially others fork vars D_OPTIONS = $(shell echo "$(KBUILD_CFLAGS) " | sed 's/[[:blank:]]/\n/g' | \ sed '/^-D/!d' | tr '\n' ' ') +ifdef SYSROOT +ccflags-y += --sysroot=${SYSROOT} +ccflags-y += -I${SYSROOT}/usr/include +CLANG_EXTRA_CFLAGS := $(ccflags-y) +PROGS_LDFLAGS := -L${SYSROOT}/usr/lib +endif + +ccflags-y += -I$(srctree)/tools/lib/bpf/ +ccflags-y += -I$(srctree)/tools/testing/selftests/bpf/ +ccflags-y += -I$(srctree)/tools/lib/ +ccflags-y += -I$(srctree)/tools/perf + +ccflags-y += $(D_OPTIONS) +ccflags-y += -Wall +ccflags-y += -Wmissing-prototypes +ccflags-y += -Wstrict-prototypes +ccflags-y += -fomit-frame-pointer + +PROGS_CFLAGS := $(ccflags-y) + +ccflags-y += -I$(objtree)/usr/include +ccflags-y += -I$(srctree)/tools/include + +PROGCFLAGS_bpf_load.o += -I$(objtree)/usr/include -I$(srctree)/tools/include \ + -Wno-unused-variable +PROGCFLAGS_sampleip_user.o += -I$(srctree)/tools/include +PROGCFLAGS_task_fd_query_user.o += -I$(srctree)/tools/include +PROGCFLAGS_trace_event_user.o += -I$(srctree)/tools/include +PROGCFLAGS_trace_output_user.o += -I$(srctree)/tools/include +PROGCFLAGS_tracex6_user.o += -I$(srctree)/tools/include +PROGCFLAGS_xdp_sample_pkts_user.o += -I$(srctree)/tools/include +PROGCFLAGS_xdpsock_user.o += -I$(srctree)/tools/include + +PROGS_LDLIBS := $(LIBBPF) -lelf +PROGLDLIBS_tracex4 += -lrt +PROGLDLIBS_trace_output += -lrt +PROGLDLIBS_map_perf_test += -lrt +PROGLDLIBS_test_overhead += -lrt +PROGLDLIBS_xdpsock += -pthread + CLANG_EXTRA_CFLAGS += $(D_OPTIONS) # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: @@ -202,15 +225,14 @@ BTF_PAHOLE ?= pahole # Detect that we're cross compiling and use the cross compiler ifdef CROSS_COMPILE -HOSTCC = $(CROSS_COMPILE)gcc CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%)) endif # Don't evaluate probes and warnings if we need to run make recursively ifneq ($(src),) HDR_PROBE := $(shell printf "\#include \n struct list_head { int a; }; int main() { return 0; }" | \ - $(HOSTCC) $(KBUILD_HOSTCFLAGS) -x c - -o /dev/null 2>/dev/null && \ - echo okay) + $(CC) $(PROGS_CFLAGS) $(PROGS_LDFLAGS) -x c - -o /dev/null \ + 2>/dev/null && echo okay) ifeq ($(HDR_PROBE),) $(warning WARNING: Detected possible issues with include path.) @@ -246,7 +268,9 @@ clean: $(LIBBPF): FORCE # Fix up variables inherited from Kbuild that tools/ build system won't like - $(MAKE) -C $(dir $@) RM='rm -rf' LDFLAGS= srctree=$(BPF_SAMPLES_PATH)/../../ O= + $(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(ccflags-y)" \ + EXTRA_CXXFLAGS="$(ccflags-y)" LDFLAGS=$(PROGS_LDFLAGS) \ + srctree=$(BPF_SAMPLES_PATH)/../../ O= $(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE $(call filechk,offsets,__SYSCALL_NRS_H__) @@ -283,6 +307,8 @@ $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h $(obj)/hbm.o: $(src)/hbm.h $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h +-include $(BPF_SAMPLES_PATH)/Makefile.prog + # 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 # useless for BPF samples. diff --git a/samples/bpf/README.rst b/samples/bpf/README.rst index 5f27e4faca50..6b5e4eace977 100644 --- a/samples/bpf/README.rst +++ b/samples/bpf/README.rst @@ -74,3 +74,10 @@ samples for the cross target. export ARCH=arm64 export CROSS_COMPILE="aarch64-linux-gnu-" make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang + +If need to use environment of target board, the SYSROOT also can be set, +pointing on FS of target board: + +make samples/bpf/ LLC=~/git/llvm/build/bin/llc \ + CLANG=~/git/llvm/build/bin/clang \ + SYSROOT=~/some_sdk/linux-devkit/sysroots/aarch64-linux-gnu