Message ID | 20230105172243.7238-1-mike.leach@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp413564wrt; Thu, 5 Jan 2023 09:30:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXs8AhCwgDZCyU5t1131e64hhigaEE/eNchU6s4NtuL/TZR0671u5TPMICt7glWsL9wcUM5a X-Received: by 2002:a17:907:8b12:b0:78d:f457:1062 with SMTP id sz18-20020a1709078b1200b0078df4571062mr44969286ejc.31.1672939852461; Thu, 05 Jan 2023 09:30:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672939852; cv=none; d=google.com; s=arc-20160816; b=s8nAKLmyolu/zTsOxQW4usY9igPfd1rewmPz/WQ0c5zIW7UPSkyVsUqftmV7hrc/Yb yfXozioNoaWA0MWNxlYSVEMgI5V5P2V8NvhkbmqNUZoNVP5XZibg1KQ6ZZqxfDU7AsCf 3tYr/sCvHizvfUFVBJfuzOUpy+NkO/pcRRyanacFuonk75/34JtArfpAYNz6TD+gAY7n 7Bs0IsqHMjYKjCfnVnIat2bUSoFtRuodRSLZE4sf5OPTusu3cLQRe9HcItjab9HWgmfY AW4ZaMzK+pkBzgsp9hJj3sBQAX1tVobvvbbfIV2oo+8p35ozc50Mv2Azusnu1UhCDAj+ qHSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=XcfKvBPEIZCBpfejnS73x0WwQlLjDoYOq2loLUX6TbU=; b=RxbCQJlCD9sfsOET1lMGNUQRHN+3SVS366tvOQMPy54aWvta1V1KDkCAbKoAzD6Z20 9678twhucX3ccnjEiiGSLfMXBr1OGM9CkTEeMuOmg3DWhk+Gws63EpkxzpNVcebXeLHx +KH3pY4g4EpsYAPvA//fS+Lk6yknK4eszZVDQPf+iTi2apcPRjNInXMsiCOobSlb2h/4 S2L5tqhggtx1YmfSIhgBkqsjrRSyYrF9nH8Ttym206j/HXs8OqIgmDuLhYWCUIu+Dv7W ZBa7r0dco8IPxttDGixXDtuI0hwzAAo1ZzvpiTDNXSf6BRz6IsBhel4WzSz1IvvY69RM TS6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="KwTi/H99"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw15-20020a170906478f00b008244db32413si35262183ejc.445.2023.01.05.09.30.28; Thu, 05 Jan 2023 09:30:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="KwTi/H99"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235383AbjAER1f (ORCPT <rfc822;tmhikaru@gmail.com> + 99 others); Thu, 5 Jan 2023 12:27:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235408AbjAER1B (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 5 Jan 2023 12:27:01 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F2EA59D23 for <linux-kernel@vger.kernel.org>; Thu, 5 Jan 2023 09:23:00 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id bs20so34704671wrb.3 for <linux-kernel@vger.kernel.org>; Thu, 05 Jan 2023 09:23:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XcfKvBPEIZCBpfejnS73x0WwQlLjDoYOq2loLUX6TbU=; b=KwTi/H999k5fva2x4E5wBta5Rx9fvc3JiOCJaif8gKrNStViCRTQIJjqOJ+RkI+kjG bM32qjnNVWALAET3QCG4YDk0O705dgkfl2PfMRQSiKS3cX4asOWiKDNABJ51/Nrp41gg fVGpKaGTnNqm8/+uSoIDeG9rZQpdb8V5uGEBQIBWoxCTWSg+0HNSjXEoy9eXdJgQJ6vC qVPjg/atlKyDzrkoDWHxsykXvOfgYXqolFnE5HF9jwpodI04uIu8Vn6LMa9H71Xeypmf WcIcTR4hfxQ17/9nJ2Xf+ANDx++GsspwhdR256Vf/Fgq9oyh6/wGQuOXh3ZHtAswozK2 kajg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XcfKvBPEIZCBpfejnS73x0WwQlLjDoYOq2loLUX6TbU=; b=u4771WuS+GKdtOGuesF90Njpxl4OCFXCedEdFDlc7ULoZLUfuDjOrbq6x9Rt1D5TYt xaoCqMyheLeax49+IUiVDWoik2KSQrNS9cWYsxdVa2jIZ7w96Y1TL3JcGVbWAwznnBzQ FzBh5Agef/yK+MRYkYuOdBtt8basAHxTl2HmrGkPZhYDv5SovBaXIdco6nIAQi5piL+9 lz9TEbFN2axydlHb9P5Z3qC6xncqx+PffXMan2QWal43kebiRjzhKq/QsOBHF3J90m+W 7hQ+7vP6v+ju6IeItMLqJcYLHvxA90K+9Z6m8w32iEdIEpUlL+dYaCA39qSkHrjvlFDS uUdQ== X-Gm-Message-State: AFqh2kqL9BUuz8BVvQMizLifz8of9P5L3hJR7BVGrLRyjFOsCo4xSNH7 lF3d5AmPQTp43qGLXdBln/JQmIlmXSh+ibAz X-Received: by 2002:adf:9dd1:0:b0:242:f3f:28df with SMTP id q17-20020adf9dd1000000b002420f3f28dfmr32911549wre.58.1672939379261; Thu, 05 Jan 2023 09:22:59 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:dca6:3efa:4e3:1e42]) by smtp.gmail.com with ESMTPSA id s13-20020adfdb0d000000b002420dba6447sm37871273wri.59.2023.01.05.09.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 09:22:58 -0800 (PST) From: Mike Leach <mike.leach@linaro.org> To: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, acme@kernel.org, irogers@google.com Cc: peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, Mike Leach <mike.leach@linaro.org> Subject: [PATCH] perf build: Fix build error when NO_LIBBPF=1 Date: Thu, 5 Jan 2023 17:22:43 +0000 Message-Id: <20230105172243.7238-1-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754204578741239046?= X-GMAIL-MSGID: =?utf-8?q?1754204578741239046?= |
Series |
perf build: Fix build error when NO_LIBBPF=1
|
|
Commit Message
Mike Leach
Jan. 5, 2023, 5:22 p.m. UTC
Recent updates to perf build result in the following output when cross
compiling to aarch64, with libelf unavailable, and therefore
NO_LIBBPF=1 set.
```
$make -C tools/perf
<cut>
Makefile.config:428: No libelf found. Disables 'probe' tool, jvmti
and BPF support in 'perf record'. Please install libelf-dev,
libelf-devel or elfutils-libelf-devel
<cut>
libbpf.c:46:10: fatal error: libelf.h: No such file or directory
46 | #include <libelf.h>
| ^~~~~~~~~~
compilation terminated.
./tools/build/Makefile.build:96: recipe for target
'.tools/perf/libbpf/staticobjs/libbpf.o' failed
```
plus one other include error for <gelf.h>
The issue is that the commit noted below adds libbpf to the prepare:
target but no longer accounts for the NO_LIBBPF define. Additionally
changing the include directories means that even if the libbpf target
build is prevented, bpf headers are missing in other parts of the build.
This patch ensures that in the case of NO_LIBBPF=1, the build target is
changed to a header only target, and the headers are installed, without
attempting to build the libbpf.a target.
Applies to perf/core
Fixes: 746bd29e348f ("perf build: Use tools/lib headers from install path")
Signed-off-by: Mike Leach <mike.leach@linaro.org>
---
tools/perf/Makefile.perf | 10 ++++++++++
1 file changed, 10 insertions(+)
Comments
On Thu, Jan 5, 2023 at 9:22 AM Mike Leach <mike.leach@linaro.org> wrote: > > Recent updates to perf build result in the following output when cross > compiling to aarch64, with libelf unavailable, and therefore > NO_LIBBPF=1 set. > > ``` > $make -C tools/perf > > <cut> > > Makefile.config:428: No libelf found. Disables 'probe' tool, jvmti > and BPF support in 'perf record'. Please install libelf-dev, > libelf-devel or elfutils-libelf-devel > > <cut> > > libbpf.c:46:10: fatal error: libelf.h: No such file or directory > 46 | #include <libelf.h> > | ^~~~~~~~~~ > compilation terminated. > > ./tools/build/Makefile.build:96: recipe for target > '.tools/perf/libbpf/staticobjs/libbpf.o' failed > > ``` > > plus one other include error for <gelf.h> Ouch, apologies for the breakage. You wouldn't happen to have something like a way with say a docker image to repro the problem? The make line above is somewhat minimal. > The issue is that the commit noted below adds libbpf to the prepare: > target but no longer accounts for the NO_LIBBPF define. Additionally > changing the include directories means that even if the libbpf target > build is prevented, bpf headers are missing in other parts of the build. > > This patch ensures that in the case of NO_LIBBPF=1, the build target is > changed to a header only target, and the headers are installed, without > attempting to build the libbpf.a target. > > Applies to perf/core > > Fixes: 746bd29e348f ("perf build: Use tools/lib headers from install path") > Signed-off-by: Mike Leach <mike.leach@linaro.org> > --- > tools/perf/Makefile.perf | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > index 13e7d26e77f0..ee08ecf469f6 100644 > --- a/tools/perf/Makefile.perf > +++ b/tools/perf/Makefile.perf > @@ -305,7 +305,11 @@ else > endif > LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) > LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include > +ifndef NO_LIBBPF > LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a > +else > +LIBBPF = $(LIBBPF_INCLUDE)/bpf/bpf.h This seems strange, don't we want to avoid libbpf targets? > +endif > CFLAGS += -I$(LIBBPF_OUTPUT)/include > > ifneq ($(OUTPUT),) > @@ -826,10 +830,16 @@ $(LIBAPI)-clean: > $(call QUIET_CLEAN, libapi) > $(Q)$(RM) -r -- $(LIBAPI_OUTPUT) > > +ifndef NO_LIBBPF > $(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > $(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \ > O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= \ > $@ install_headers > +else > +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > + $(Q)$(MAKE) -C $(LIBBPF_DIR) OUTPUT=$(LIBBPF_OUTPUT)/ \ > + DESTDIR=$(LIBBPF_DESTDIR) prefix= install_headers > +endif Shouldn't we just be able to conditionalize having $(LIBBPF) as a dependency for the perf binary? If there is no dependency then the targets won't be built and we shouldn't need to conditionalize here. Thanks! Ian > $(LIBBPF)-clean: > $(call QUIET_CLEAN, libbpf) > -- > 2.17.1 >
Hi, On Thu, 5 Jan 2023 at 19:03, Ian Rogers <irogers@google.com> wrote: > > On Thu, Jan 5, 2023 at 9:22 AM Mike Leach <mike.leach@linaro.org> wrote: > > > > Recent updates to perf build result in the following output when cross > > compiling to aarch64, with libelf unavailable, and therefore > > NO_LIBBPF=1 set. > > > > ``` > > $make -C tools/perf > > > > <cut> > > > > Makefile.config:428: No libelf found. Disables 'probe' tool, jvmti > > and BPF support in 'perf record'. Please install libelf-dev, > > libelf-devel or elfutils-libelf-devel > > > > <cut> > > > > libbpf.c:46:10: fatal error: libelf.h: No such file or directory > > 46 | #include <libelf.h> > > | ^~~~~~~~~~ > > compilation terminated. > > > > ./tools/build/Makefile.build:96: recipe for target > > '.tools/perf/libbpf/staticobjs/libbpf.o' failed > > > > ``` > > > > plus one other include error for <gelf.h> > > Ouch, apologies for the breakage. You wouldn't happen to have > something like a way with say a docker image to repro the problem? The > make line above is somewhat minimal. > Unfortunately not - I was cross compiling on my main workstation. However, in theory $make -C tools/perf NO_LIBBPF=1 should explicitly exclude the library from the build - which without the fix it does not. > > The issue is that the commit noted below adds libbpf to the prepare: > > target but no longer accounts for the NO_LIBBPF define. Additionally > > changing the include directories means that even if the libbpf target > > build is prevented, bpf headers are missing in other parts of the build. > > > > This patch ensures that in the case of NO_LIBBPF=1, the build target is > > changed to a header only target, and the headers are installed, without > > attempting to build the libbpf.a target. > > > > Applies to perf/core > > > > Fixes: 746bd29e348f ("perf build: Use tools/lib headers from install path") > > Signed-off-by: Mike Leach <mike.leach@linaro.org> > > --- > > tools/perf/Makefile.perf | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > > index 13e7d26e77f0..ee08ecf469f6 100644 > > --- a/tools/perf/Makefile.perf > > +++ b/tools/perf/Makefile.perf > > @@ -305,7 +305,11 @@ else > > endif > > LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) > > LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include > > +ifndef NO_LIBBPF > > LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a > > +else > > +LIBBPF = $(LIBBPF_INCLUDE)/bpf/bpf.h > > This seems strange, don't we want to avoid libbpf targets? > This is a header only target - see my continuation comment below.... > > +endif > > CFLAGS += -I$(LIBBPF_OUTPUT)/include > > > > ifneq ($(OUTPUT),) > > @@ -826,10 +830,16 @@ $(LIBAPI)-clean: > > $(call QUIET_CLEAN, libapi) > > $(Q)$(RM) -r -- $(LIBAPI_OUTPUT) > > > > +ifndef NO_LIBBPF > > $(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > > $(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \ > > O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= \ > > $@ install_headers > > +else > > +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > > + $(Q)$(MAKE) -C $(LIBBPF_DIR) OUTPUT=$(LIBBPF_OUTPUT)/ \ > > + DESTDIR=$(LIBBPF_DESTDIR) prefix= install_headers > > +endif > > Shouldn't we just be able to conditionalize having $(LIBBPF) as a > dependency for the perf binary? If there is no dependency then the > targets won't be built and we shouldn't need to conditionalize here. > I did try doing just that, but the build process does two things when building libbpf a) builds the library b) installs the bpf headers in the libbpf output location. Now what the original patch - "perf build: Use tools/lib headers from install path" - does is to also change the include paths to the compiler to pick up the headers, removing the line: INC_FLAGS += -I$(srctree)/tools/lib/ from tools/perf/Makefile.config and adding the line CFLAGS += -I$(LIBBPF_OUTPUT)/include in tools/perf/Makefile.perf (along with similar lines for libperf, libapi etc) The result of this is that if you only remove the library build, the headers are not installed and other compilation units fail as the headers are still included even if the library is not in use. These were originally satisfied by the now removed INC_FLAGS += -I$(srctree)/tools/lib. Thus when NO_LIBBPF=1 even though we do not build the library - we still need to install the headers to retain the consistency - hence a "header only" target, that only installs the headers without building the library. This avoids restoring the original -I$(srctree)/tools/lib/, which would potentially mess up the oher library builds that have changed their header include paths. Regards Mike > Thanks! > Ian > > > $(LIBBPF)-clean: > > $(call QUIET_CLEAN, libbpf) > > -- > > 2.17.1 > > -- Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK
On Thu, Jan 5, 2023 at 3:40 PM Mike Leach <mike.leach@linaro.org> wrote: > > Hi, > > On Thu, 5 Jan 2023 at 19:03, Ian Rogers <irogers@google.com> wrote: > > > > On Thu, Jan 5, 2023 at 9:22 AM Mike Leach <mike.leach@linaro.org> wrote: > > > > > > Recent updates to perf build result in the following output when cross > > > compiling to aarch64, with libelf unavailable, and therefore > > > NO_LIBBPF=1 set. > > > > > > ``` > > > $make -C tools/perf > > > > > > <cut> > > > > > > Makefile.config:428: No libelf found. Disables 'probe' tool, jvmti > > > and BPF support in 'perf record'. Please install libelf-dev, > > > libelf-devel or elfutils-libelf-devel > > > > > > <cut> > > > > > > libbpf.c:46:10: fatal error: libelf.h: No such file or directory > > > 46 | #include <libelf.h> > > > | ^~~~~~~~~~ > > > compilation terminated. > > > > > > ./tools/build/Makefile.build:96: recipe for target > > > '.tools/perf/libbpf/staticobjs/libbpf.o' failed > > > > > > ``` > > > > > > plus one other include error for <gelf.h> > > > > Ouch, apologies for the breakage. You wouldn't happen to have > > something like a way with say a docker image to repro the problem? The > > make line above is somewhat minimal. > > > > Unfortunately not - I was cross compiling on my main workstation. > However, in theory > $make -C tools/perf NO_LIBBPF=1 > should explicitly exclude the library from the build - which without > the fix it does not. > > > > The issue is that the commit noted below adds libbpf to the prepare: > > > target but no longer accounts for the NO_LIBBPF define. Additionally > > > changing the include directories means that even if the libbpf target > > > build is prevented, bpf headers are missing in other parts of the build. > > > > > > This patch ensures that in the case of NO_LIBBPF=1, the build target is > > > changed to a header only target, and the headers are installed, without > > > attempting to build the libbpf.a target. > > > > > > Applies to perf/core > > > > > > Fixes: 746bd29e348f ("perf build: Use tools/lib headers from install path") > > > Signed-off-by: Mike Leach <mike.leach@linaro.org> > > > --- > > > tools/perf/Makefile.perf | 10 ++++++++++ > > > 1 file changed, 10 insertions(+) > > > > > > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > > > index 13e7d26e77f0..ee08ecf469f6 100644 > > > --- a/tools/perf/Makefile.perf > > > +++ b/tools/perf/Makefile.perf > > > @@ -305,7 +305,11 @@ else > > > endif > > > LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) > > > LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include > > > +ifndef NO_LIBBPF > > > LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a > > > +else > > > +LIBBPF = $(LIBBPF_INCLUDE)/bpf/bpf.h > > > > This seems strange, don't we want to avoid libbpf targets? > > > > This is a header only target - see my continuation comment below.... > > > > +endif > > > CFLAGS += -I$(LIBBPF_OUTPUT)/include > > > > > > ifneq ($(OUTPUT),) > > > @@ -826,10 +830,16 @@ $(LIBAPI)-clean: > > > $(call QUIET_CLEAN, libapi) > > > $(Q)$(RM) -r -- $(LIBAPI_OUTPUT) > > > > > > +ifndef NO_LIBBPF > > > $(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > > > $(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \ > > > O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= \ > > > $@ install_headers > > > +else > > > +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > > > + $(Q)$(MAKE) -C $(LIBBPF_DIR) OUTPUT=$(LIBBPF_OUTPUT)/ \ > > > + DESTDIR=$(LIBBPF_DESTDIR) prefix= install_headers > > > +endif > > > > Shouldn't we just be able to conditionalize having $(LIBBPF) as a > > dependency for the perf binary? If there is no dependency then the > > targets won't be built and we shouldn't need to conditionalize here. > > > > I did try doing just that, but the build process does two things when > building libbpf > a) builds the library > b) installs the bpf headers in the libbpf output location. > > Now what the original patch - "perf build: Use tools/lib headers from > install path" - does is to also change the include paths to the > compiler to pick up the headers, > removing the line: > > INC_FLAGS += -I$(srctree)/tools/lib/ > > from tools/perf/Makefile.config and adding the line > > CFLAGS += -I$(LIBBPF_OUTPUT)/include > > in tools/perf/Makefile.perf (along with similar lines for libperf, libapi etc) > > The result of this is that if you only remove the library build, the > headers are not installed and other compilation units fail as the > headers are still included even if the library is not in use. > These were originally satisfied by the now removed INC_FLAGS += > -I$(srctree)/tools/lib. > > Thus when NO_LIBBPF=1 even though we do not build the library - we > still need to install the headers to retain the consistency - hence a > "header only" target, that only installs the headers without building > the library. > > This avoids restoring the original -I$(srctree)/tools/lib/, which > would potentially mess up the oher library builds that have changed > their header include paths. > > Regards > > Mike Thanks Mike, The -I is needed for the libbpf headers but if NO_LIBBPF is enabled then the C define HAVE_LIBBPF_SUPPORT isn't and we shouldn't include any of these headers. This means updating the CFLAGS for libbpf should only be done if we actually build the static libbpf.a, the dynamic version's headers should already be on the include path. I sent out a variant of this fix doing that here: https://lore.kernel.org/lkml/20230106061631.571659-1-irogers@google.com/ Apologies again for the breakage, I can buy you a beer the next time I'm home in Manchester. Ian > > > Thanks! > > Ian > > > > > $(LIBBPF)-clean: > > > $(call QUIET_CLEAN, libbpf) > > > -- > > > 2.17.1 > > > > > > > -- > Mike Leach > Principal Engineer, ARM Ltd. > Manchester Design Centre. UK
Hi Ian, On Fri, 6 Jan 2023 at 06:24, Ian Rogers <irogers@google.com> wrote: > > On Thu, Jan 5, 2023 at 3:40 PM Mike Leach <mike.leach@linaro.org> wrote: > > > > Hi, > > > > On Thu, 5 Jan 2023 at 19:03, Ian Rogers <irogers@google.com> wrote: > > > > > > On Thu, Jan 5, 2023 at 9:22 AM Mike Leach <mike.leach@linaro.org> wrote: > > > > > > > > Recent updates to perf build result in the following output when cross > > > > compiling to aarch64, with libelf unavailable, and therefore > > > > NO_LIBBPF=1 set. > > > > > > > > ``` > > > > $make -C tools/perf > > > > > > > > <cut> > > > > > > > > Makefile.config:428: No libelf found. Disables 'probe' tool, jvmti > > > > and BPF support in 'perf record'. Please install libelf-dev, > > > > libelf-devel or elfutils-libelf-devel > > > > > > > > <cut> > > > > > > > > libbpf.c:46:10: fatal error: libelf.h: No such file or directory > > > > 46 | #include <libelf.h> > > > > | ^~~~~~~~~~ > > > > compilation terminated. > > > > > > > > ./tools/build/Makefile.build:96: recipe for target > > > > '.tools/perf/libbpf/staticobjs/libbpf.o' failed > > > > > > > > ``` > > > > > > > > plus one other include error for <gelf.h> > > > > > > Ouch, apologies for the breakage. You wouldn't happen to have > > > something like a way with say a docker image to repro the problem? The > > > make line above is somewhat minimal. > > > > > > > Unfortunately not - I was cross compiling on my main workstation. > > However, in theory > > $make -C tools/perf NO_LIBBPF=1 > > should explicitly exclude the library from the build - which without > > the fix it does not. > > > > > > The issue is that the commit noted below adds libbpf to the prepare: > > > > target but no longer accounts for the NO_LIBBPF define. Additionally > > > > changing the include directories means that even if the libbpf target > > > > build is prevented, bpf headers are missing in other parts of the build. > > > > > > > > This patch ensures that in the case of NO_LIBBPF=1, the build target is > > > > changed to a header only target, and the headers are installed, without > > > > attempting to build the libbpf.a target. > > > > > > > > Applies to perf/core > > > > > > > > Fixes: 746bd29e348f ("perf build: Use tools/lib headers from install path") > > > > Signed-off-by: Mike Leach <mike.leach@linaro.org> > > > > --- > > > > tools/perf/Makefile.perf | 10 ++++++++++ > > > > 1 file changed, 10 insertions(+) > > > > > > > > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > > > > index 13e7d26e77f0..ee08ecf469f6 100644 > > > > --- a/tools/perf/Makefile.perf > > > > +++ b/tools/perf/Makefile.perf > > > > @@ -305,7 +305,11 @@ else > > > > endif > > > > LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) > > > > LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include > > > > +ifndef NO_LIBBPF > > > > LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a > > > > +else > > > > +LIBBPF = $(LIBBPF_INCLUDE)/bpf/bpf.h > > > > > > This seems strange, don't we want to avoid libbpf targets? > > > > > > > This is a header only target - see my continuation comment below.... > > > > > > +endif > > > > CFLAGS += -I$(LIBBPF_OUTPUT)/include > > > > > > > > ifneq ($(OUTPUT),) > > > > @@ -826,10 +830,16 @@ $(LIBAPI)-clean: > > > > $(call QUIET_CLEAN, libapi) > > > > $(Q)$(RM) -r -- $(LIBAPI_OUTPUT) > > > > > > > > +ifndef NO_LIBBPF > > > > $(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > > > > $(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \ > > > > O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= \ > > > > $@ install_headers > > > > +else > > > > +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > > > > + $(Q)$(MAKE) -C $(LIBBPF_DIR) OUTPUT=$(LIBBPF_OUTPUT)/ \ > > > > + DESTDIR=$(LIBBPF_DESTDIR) prefix= install_headers > > > > +endif > > > > > > Shouldn't we just be able to conditionalize having $(LIBBPF) as a > > > dependency for the perf binary? If there is no dependency then the > > > targets won't be built and we shouldn't need to conditionalize here. > > > > > > > I did try doing just that, but the build process does two things when > > building libbpf > > a) builds the library > > b) installs the bpf headers in the libbpf output location. > > > > Now what the original patch - "perf build: Use tools/lib headers from > > install path" - does is to also change the include paths to the > > compiler to pick up the headers, > > removing the line: > > > > INC_FLAGS += -I$(srctree)/tools/lib/ > > > > from tools/perf/Makefile.config and adding the line > > > > CFLAGS += -I$(LIBBPF_OUTPUT)/include > > > > in tools/perf/Makefile.perf (along with similar lines for libperf, libapi etc) > > > > The result of this is that if you only remove the library build, the > > headers are not installed and other compilation units fail as the > > headers are still included even if the library is not in use. > > These were originally satisfied by the now removed INC_FLAGS += > > -I$(srctree)/tools/lib. > > > > Thus when NO_LIBBPF=1 even though we do not build the library - we > > still need to install the headers to retain the consistency - hence a > > "header only" target, that only installs the headers without building > > the library. > > > > This avoids restoring the original -I$(srctree)/tools/lib/, which > > would potentially mess up the oher library builds that have changed > > their header include paths. > > > > Regards > > > > Mike > > > Thanks Mike, > > The -I is needed for the libbpf headers but if NO_LIBBPF is enabled > then the C define HAVE_LIBBPF_SUPPORT isn't and we shouldn't include > any of these headers. This means updating the CFLAGS for libbpf should > only be done if we actually build the static libbpf.a, the dynamic > version's headers should already be on the include path. I sent out a > variant of this fix doing that here: > https://lore.kernel.org/lkml/20230106061631.571659-1-irogers@google.com/ > > Apologies again for the breakage, I can buy you a beer the next time > I'm home in Manchester. > Ian > Applying your new patch to perf/core and building I get:- CC builtin-stat.o In file included from builtin-stat.c:71: util/bpf_counter.h:7:10: fatal error: bpf/bpf.h: No such file or directory 7 | #include <bpf/bpf.h> | ^~~~~~~~~~~ compilation terminated. /datadisk/mike/work/kernel-ups/tools/build/Makefile.build:96: recipe for target 'builtin-stat.o' failed make[3]: *** [builtin-stat.o] Error 1 make[3]: *** Waiting for unfinished jobs.... LD pmu-events/pmu-events-in.o Makefile.perf:673: recipe for target 'perf-in.o' failed make[2]: *** [perf-in.o] Error 2 Makefile.perf:235: recipe for target 'sub-make' failed make[1]: *** [sub-make] Error 2 Makefile:69: recipe for target 'all' failed make: *** [all] Error 2 which is a result of the bpf headers not being installed in their new location and the removal of the -I from the old location as mentioned in my last. So perhaps the issue is less about the build operations and more about the lack of #ifdef HAVE_LIBBPF_SUPPORT in certain other source files. However, if I put the #ifdef HAVE_LIBBPF_SUPPORT around the #include of util/bpf_counter.h, then compilation fails with multiple builtin-stat.c: In function ‘read_bpf_map_counters’: builtin-stat.c:463:9: error: implicit declaration of function ‘bpf_counter__read’; did you mean ‘refcount_read’? [-Werror=implicit-function-declaration] 463 | err = bpf_counter__read(counter); | ^~~~~~~~~~~~~~~~~ | refcount_read type errors. Turns out that bpf_counter.h has inline stubs for these functions bracketed by #ifdef HAVE_BPF_SKEL / #else / #endif, which I presume are used in the non-bpf case. I can get a clean build with your patch if I adjust the HAVE_BFP_SKEL bracketing to encompass everything (including header includes, struct defines and other functions) other than the stubs in the #ifdef case and only the stubs in the #else case - but I have no idea if this will have an adverse effect on other tools which may use the same header. Thanks and Regards Mike > > > > > Thanks! > > > Ian > > > > > > > $(LIBBPF)-clean: > > > > $(call QUIET_CLEAN, libbpf) > > > > -- > > > > 2.17.1 > > > > > > > > > > > > -- > > Mike Leach > > Principal Engineer, ARM Ltd. > > Manchester Design Centre. UK
On Fri, Jan 6, 2023 at 1:58 AM Mike Leach <mike.leach@linaro.org> wrote: > > Hi Ian, > > On Fri, 6 Jan 2023 at 06:24, Ian Rogers <irogers@google.com> wrote: > > > > On Thu, Jan 5, 2023 at 3:40 PM Mike Leach <mike.leach@linaro.org> wrote: > > > > > > Hi, > > > > > > On Thu, 5 Jan 2023 at 19:03, Ian Rogers <irogers@google.com> wrote: > > > > > > > > On Thu, Jan 5, 2023 at 9:22 AM Mike Leach <mike.leach@linaro.org> wrote: > > > > > > > > > > Recent updates to perf build result in the following output when cross > > > > > compiling to aarch64, with libelf unavailable, and therefore > > > > > NO_LIBBPF=1 set. > > > > > > > > > > ``` > > > > > $make -C tools/perf > > > > > > > > > > <cut> > > > > > > > > > > Makefile.config:428: No libelf found. Disables 'probe' tool, jvmti > > > > > and BPF support in 'perf record'. Please install libelf-dev, > > > > > libelf-devel or elfutils-libelf-devel > > > > > > > > > > <cut> > > > > > > > > > > libbpf.c:46:10: fatal error: libelf.h: No such file or directory > > > > > 46 | #include <libelf.h> > > > > > | ^~~~~~~~~~ > > > > > compilation terminated. > > > > > > > > > > ./tools/build/Makefile.build:96: recipe for target > > > > > '.tools/perf/libbpf/staticobjs/libbpf.o' failed > > > > > > > > > > ``` > > > > > > > > > > plus one other include error for <gelf.h> > > > > > > > > Ouch, apologies for the breakage. You wouldn't happen to have > > > > something like a way with say a docker image to repro the problem? The > > > > make line above is somewhat minimal. > > > > > > > > > > Unfortunately not - I was cross compiling on my main workstation. > > > However, in theory > > > $make -C tools/perf NO_LIBBPF=1 > > > should explicitly exclude the library from the build - which without > > > the fix it does not. > > > > > > > > The issue is that the commit noted below adds libbpf to the prepare: > > > > > target but no longer accounts for the NO_LIBBPF define. Additionally > > > > > changing the include directories means that even if the libbpf target > > > > > build is prevented, bpf headers are missing in other parts of the build. > > > > > > > > > > This patch ensures that in the case of NO_LIBBPF=1, the build target is > > > > > changed to a header only target, and the headers are installed, without > > > > > attempting to build the libbpf.a target. > > > > > > > > > > Applies to perf/core > > > > > > > > > > Fixes: 746bd29e348f ("perf build: Use tools/lib headers from install path") > > > > > Signed-off-by: Mike Leach <mike.leach@linaro.org> > > > > > --- > > > > > tools/perf/Makefile.perf | 10 ++++++++++ > > > > > 1 file changed, 10 insertions(+) > > > > > > > > > > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > > > > > index 13e7d26e77f0..ee08ecf469f6 100644 > > > > > --- a/tools/perf/Makefile.perf > > > > > +++ b/tools/perf/Makefile.perf > > > > > @@ -305,7 +305,11 @@ else > > > > > endif > > > > > LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) > > > > > LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include > > > > > +ifndef NO_LIBBPF > > > > > LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a > > > > > +else > > > > > +LIBBPF = $(LIBBPF_INCLUDE)/bpf/bpf.h > > > > > > > > This seems strange, don't we want to avoid libbpf targets? > > > > > > > > > > This is a header only target - see my continuation comment below.... > > > > > > > > +endif > > > > > CFLAGS += -I$(LIBBPF_OUTPUT)/include > > > > > > > > > > ifneq ($(OUTPUT),) > > > > > @@ -826,10 +830,16 @@ $(LIBAPI)-clean: > > > > > $(call QUIET_CLEAN, libapi) > > > > > $(Q)$(RM) -r -- $(LIBAPI_OUTPUT) > > > > > > > > > > +ifndef NO_LIBBPF > > > > > $(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > > > > > $(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \ > > > > > O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= \ > > > > > $@ install_headers > > > > > +else > > > > > +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT) > > > > > + $(Q)$(MAKE) -C $(LIBBPF_DIR) OUTPUT=$(LIBBPF_OUTPUT)/ \ > > > > > + DESTDIR=$(LIBBPF_DESTDIR) prefix= install_headers > > > > > +endif > > > > > > > > Shouldn't we just be able to conditionalize having $(LIBBPF) as a > > > > dependency for the perf binary? If there is no dependency then the > > > > targets won't be built and we shouldn't need to conditionalize here. > > > > > > > > > > I did try doing just that, but the build process does two things when > > > building libbpf > > > a) builds the library > > > b) installs the bpf headers in the libbpf output location. > > > > > > Now what the original patch - "perf build: Use tools/lib headers from > > > install path" - does is to also change the include paths to the > > > compiler to pick up the headers, > > > removing the line: > > > > > > INC_FLAGS += -I$(srctree)/tools/lib/ > > > > > > from tools/perf/Makefile.config and adding the line > > > > > > CFLAGS += -I$(LIBBPF_OUTPUT)/include > > > > > > in tools/perf/Makefile.perf (along with similar lines for libperf, libapi etc) > > > > > > The result of this is that if you only remove the library build, the > > > headers are not installed and other compilation units fail as the > > > headers are still included even if the library is not in use. > > > These were originally satisfied by the now removed INC_FLAGS += > > > -I$(srctree)/tools/lib. > > > > > > Thus when NO_LIBBPF=1 even though we do not build the library - we > > > still need to install the headers to retain the consistency - hence a > > > "header only" target, that only installs the headers without building > > > the library. > > > > > > This avoids restoring the original -I$(srctree)/tools/lib/, which > > > would potentially mess up the oher library builds that have changed > > > their header include paths. > > > > > > Regards > > > > > > Mike > > > > > > Thanks Mike, > > > > The -I is needed for the libbpf headers but if NO_LIBBPF is enabled > > then the C define HAVE_LIBBPF_SUPPORT isn't and we shouldn't include > > any of these headers. This means updating the CFLAGS for libbpf should > > only be done if we actually build the static libbpf.a, the dynamic > > version's headers should already be on the include path. I sent out a > > variant of this fix doing that here: > > https://lore.kernel.org/lkml/20230106061631.571659-1-irogers@google.com/ > > > > Apologies again for the breakage, I can buy you a beer the next time > > I'm home in Manchester. > > Ian > > > > Applying your new patch to perf/core and building I get:- > > CC builtin-stat.o > In file included from builtin-stat.c:71: > util/bpf_counter.h:7:10: fatal error: bpf/bpf.h: No such file or directory > 7 | #include <bpf/bpf.h> > | ^~~~~~~~~~~ > compilation terminated. > /datadisk/mike/work/kernel-ups/tools/build/Makefile.build:96: recipe > for target 'builtin-stat.o' failed > make[3]: *** [builtin-stat.o] Error 1 > make[3]: *** Waiting for unfinished jobs.... > LD pmu-events/pmu-events-in.o > Makefile.perf:673: recipe for target 'perf-in.o' failed > make[2]: *** [perf-in.o] Error 2 > Makefile.perf:235: recipe for target 'sub-make' failed > make[1]: *** [sub-make] Error 2 > Makefile:69: recipe for target 'all' failed > make: *** [all] Error 2 > > which is a result of the bpf headers not being installed in their new > location and the removal of the -I from the old location as mentioned > in my last. > So perhaps the issue is less about the build operations and more about > the lack of #ifdef HAVE_LIBBPF_SUPPORT in certain other source files. > > However, if I put the #ifdef HAVE_LIBBPF_SUPPORT around the #include > of util/bpf_counter.h, then compilation fails with multiple > > builtin-stat.c: In function ‘read_bpf_map_counters’: > builtin-stat.c:463:9: error: implicit declaration of function > ‘bpf_counter__read’; did you mean ‘refcount_read’? > [-Werror=implicit-function-declaration] > 463 | err = bpf_counter__read(counter); > | ^~~~~~~~~~~~~~~~~ > | refcount_read > > type errors. > > Turns out that bpf_counter.h has inline stubs for these functions > bracketed by #ifdef HAVE_BPF_SKEL / #else / #endif, which I presume > are used in the non-bpf case. > > I can get a clean build with your patch if I adjust the HAVE_BFP_SKEL > bracketing to encompass everything (including header includes, struct > defines and other functions) other than the stubs in the #ifdef case > and only the stubs in the #else case - but I have no idea if this > will have an adverse effect on other tools which may use the same > header. > > Thanks and Regards > > Mike Thanks Mike, With "apt remove libbpf-devel" I was able to repro this and I've sent out a v2 [1] adding the guards and moving the helper functions under HAVE_BPF_SKEL as you say. The patch was sufficient to fix the build for me, could you double check it? The builtin-trace fix addresses a missing guard not present since November 2018 in '744fafc787de perf trace: See if there is a map named "filtered_pids"' but builtin-trace has some optionality around whether it is included in a build so I didn't include the Fixes tag. Thanks, Ian [1] https://lore.kernel.org/lkml/20230106142537.607399-2-irogers@google.com/ > > > > > > > Thanks! > > > > Ian > > > > > > > > > $(LIBBPF)-clean: > > > > > $(call QUIET_CLEAN, libbpf) > > > > > -- > > > > > 2.17.1 > > > > > > > > > > > > > > > > > -- > > > Mike Leach > > > Principal Engineer, ARM Ltd. > > > Manchester Design Centre. UK > > > > -- > Mike Leach > Principal Engineer, ARM Ltd. > Manchester Design Centre. UK
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 13e7d26e77f0..ee08ecf469f6 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -305,7 +305,11 @@ else endif LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include +ifndef NO_LIBBPF LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a +else +LIBBPF = $(LIBBPF_INCLUDE)/bpf/bpf.h +endif CFLAGS += -I$(LIBBPF_OUTPUT)/include ifneq ($(OUTPUT),) @@ -826,10 +830,16 @@ $(LIBAPI)-clean: $(call QUIET_CLEAN, libapi) $(Q)$(RM) -r -- $(LIBAPI_OUTPUT) +ifndef NO_LIBBPF $(LIBBPF): FORCE | $(LIBBPF_OUTPUT) $(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \ O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= \ $@ install_headers +else +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT) + $(Q)$(MAKE) -C $(LIBBPF_DIR) OUTPUT=$(LIBBPF_OUTPUT)/ \ + DESTDIR=$(LIBBPF_DESTDIR) prefix= install_headers +endif $(LIBBPF)-clean: $(call QUIET_CLEAN, libbpf)