Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5303888ybc; Wed, 27 Nov 2019 01:52:16 -0800 (PST) X-Google-Smtp-Source: APXvYqxh/eDa9mi/5TOlziLaLnwqxcj5d2t4Cjdy3Fnr7OzFB/n7ZTTY/A7tyUrljwSmYebx2WR5 X-Received: by 2002:a17:907:110f:: with SMTP id qu15mr48387134ejb.179.1574848336257; Wed, 27 Nov 2019 01:52:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574848336; cv=none; d=google.com; s=arc-20160816; b=HTEUnDX3atE5XJ0Bk6qaejfdQNu3TxuP2aPa7J4XZKnE3wKe2YNT9y635uK8rn5LNr Yij7bSDiF6CAqrjlLtqMmKwDLV8GtQA3WQG79/4lGIPHMoczrXaouJgq4ybi4HT1pOyB OFNDqI1IpOVCFtrBaqgyYxPFkAdrxGiK50l/cj2WDsSvlwfmTwNIc4Ee+1vIsVBY1pMO 6D1+mCNR7PuxyieEYrxHDnhmv7q8jEc1bY/uUQgFKo9UeOcK0poCmkqWffbLzrDMAmJ+ 4lLUfa2EFMCA9zEenyVCcQ75QjBTwyTrX09y2RSfNrVFgtt1JV0FVpfKjMnmWodXDHkC Xl1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=YcogwH7SAcn3V6tRDm97eH9q7EB08vaT1wdKN5gFOWI=; b=efZmdmVhqy2DaOqaacRFrKnfTPy6yh0yFBY/2rP6vomMmrSyi5LpO7qIUB+NSp4RkX 7XYm1QbiPrNebhbetmNps++fnxGkZt5coZVWxsbw5bVNszurtxhGDKWAXA16skQKW7KR 3ll7956x1xjNWw48FSa+yHt4fQ485/qkjwXwV+74tsynh0LlkpCDenNsz9+2a+jv2hd5 zOG8bZFro6PupFO4EZHZhW6sAT6e55oBkHzoGPIzksDwmO7d27n80nEaDLG35iqUAp1t JmDwgmC9xMbbDnoQR/snuWDPlFORkIiq9eUVJxn2m+m3fsw+NyGjokL7xWE8Jcs7Y/GH wpxQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23si4084588edq.421.2019.11.27.01.51.49; Wed, 27 Nov 2019 01:52:16 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727071AbfK0JtF convert rfc822-to-8bit (ORCPT + 99 others); Wed, 27 Nov 2019 04:49:05 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53927 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726920AbfK0JtC (ORCPT ); Wed, 27 Nov 2019 04:49:02 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-N8QNudZsNuOKTM7DqNQzcw-1; Wed, 27 Nov 2019 04:49:00 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB3FB107ACE3; Wed, 27 Nov 2019 09:48:57 +0000 (UTC) Received: from krava.redhat.com (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id A52305D6C8; Wed, 27 Nov 2019 09:48:54 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , netdev@vger.kernel.org, bpf@vger.kernel.org, Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Jesper Dangaard Brouer , Daniel Borkmann , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko Subject: [PATCH 3/3] bpftool: Allow to link libbpf dynamically Date: Wed, 27 Nov 2019 10:48:37 +0100 Message-Id: <20191127094837.4045-4-jolsa@kernel.org> In-Reply-To: <20191127094837.4045-1-jolsa@kernel.org> References: <20191127094837.4045-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: N8QNudZsNuOKTM7DqNQzcw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we support only static linking with kernel's libbpf (tools/lib/bpf). This patch adds LIBBPF_DYNAMIC compile variable that triggers libbpf detection and bpf dynamic linking: $ make -C tools/bpf/bpftool make LIBBPF_DYNAMIC=1 If libbpf is not installed, build (with LIBBPF_DYNAMIC=1) stops with: $ make -C tools/bpf/bpftool LIBBPF_DYNAMIC=1 Auto-detecting system features: ... libbfd: [ on ] ... disassembler-four-args: [ on ] ... zlib: [ on ] ... libbpf: [ OFF ] Makefile:102: *** Error: libbpf-devel is missing, please install it. Stop. Adding specific bpftool's libbpf check for libbpf_netlink_open (LIBBPF_0.0.6) which is the latest we need for bpftool at the moment. Adding LIBBPF_DIR compile variable to allow linking with libbpf installed into specific directory: $ make -C tools/lib/bpf/ prefix=/tmp/libbpf/ install_lib install_headers $ make -C tools/bpf/bpftool/ LIBBPF_DYNAMIC=1 LIBBPF_DIR=/tmp/libbpf/ It might be needed to clean build tree first because features framework does not detect the change properly: $ make -C tools/build/feature clean $ make -C tools/bpf/bpftool/ clean Signed-off-by: Jiri Olsa --- tools/bpf/bpftool/Makefile | 40 ++++++++++++++++++++++++++++++- tools/build/feature/test-libbpf.c | 9 +++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index 39bc6f0f4f0b..2b6ed08cb31e 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile @@ -1,6 +1,15 @@ # SPDX-License-Identifier: GPL-2.0-only +# LIBBPF_DYNAMIC to enable libbpf dynamic linking. + include ../../scripts/Makefile.include include ../../scripts/utilities.mak +include ../../scripts/Makefile.arch + +ifeq ($(LP64), 1) + libdir_relative = lib64 +else + libdir_relative = lib +endif ifeq ($(srctree),) srctree := $(patsubst %/,%,$(dir $(CURDIR))) @@ -55,7 +64,7 @@ ifneq ($(EXTRA_LDFLAGS),) LDFLAGS += $(EXTRA_LDFLAGS) endif -LIBS = $(LIBBPF) -lelf -lz +LIBS = -lelf -lz INSTALL ?= install RM ?= rm -f @@ -64,6 +73,23 @@ FEATURE_USER = .bpftool FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib FEATURE_DISPLAY = libbfd disassembler-four-args zlib +ifdef LIBBPF_DYNAMIC + # Add libbpf check with the flags to ensure bpftool + # specific version is detected. + FEATURE_CHECK_CFLAGS-libbpf := -DBPFTOOL + FEATURE_TESTS += libbpf + FEATURE_DISPLAY += libbpf + + # for linking with debug library run: + # make LIBBPF_DYNAMIC=1 LIBBPF_DIR=/opt/libbpf + ifdef LIBBPF_DIR + LIBBPF_CFLAGS := -I$(LIBBPF_DIR)/include + LIBBPF_LDFLAGS := -L$(LIBBPF_DIR)/$(libdir_relative) + FEATURE_CHECK_CFLAGS-libbpf := $(LIBBPF_CFLAGS) + FEATURE_CHECK_LDFLAGS-libbpf := $(LIBBPF_LDFLAGS) + endif +endif + check_feat := 1 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall ifdef MAKECMDGOALS @@ -88,6 +114,18 @@ ifeq ($(feature-reallocarray), 0) CFLAGS += -DCOMPAT_NEED_REALLOCARRAY endif +ifdef LIBBPF_DYNAMIC + ifeq ($(feature-libbpf), 1) + LIBS += -lbpf + CFLAGS += $(LIBBPF_CFLAGS) + LDFLAGS += $(LIBBPF_LDFLAGS) + else + dummy := $(error Error: No libbpf devel library found, please install libbpf-devel) + endif +else + LIBS += $(LIBBPF) +endif + include $(wildcard $(OUTPUT)*.d) all: $(OUTPUT)bpftool diff --git a/tools/build/feature/test-libbpf.c b/tools/build/feature/test-libbpf.c index a508756cf4cc..93566d105a64 100644 --- a/tools/build/feature/test-libbpf.c +++ b/tools/build/feature/test-libbpf.c @@ -3,5 +3,14 @@ int main(void) { +#ifdef BPFTOOL + /* + * libbpf_netlink_open (LIBBPF_0.0.6) is the latest + * we need for bpftool at the moment + */ + libbpf_netlink_open(NULL); + return 0; +#else return bpf_object__open("test") ? 0 : -1; +#endif } -- 2.21.0