Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1609636rwl; Thu, 5 Jan 2023 16:44:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXtLSXWoDN0WPtRFqKIyXspWYfbZ4zhLKe2WmP7qScZR26XRvKmh3uGkD4vRHDswp/9c9cjk X-Received: by 2002:a05:6a21:3a94:b0:9d:efbe:52c3 with SMTP id zv20-20020a056a213a9400b0009defbe52c3mr65290357pzb.51.1672965841084; Thu, 05 Jan 2023 16:44:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672965841; cv=none; d=google.com; s=arc-20160816; b=ETnPuPMxIJfL3N24v6T1iCglnJL+okeLUZ1xorpxy91JAlUYzh36fOkvSp8DkeS6kX E/f4FgyiUVZBp4RzP33GaEsP+HHqxgeB/hIyUWJ5QcX13D0OEvJlg20HWWt6JcwS32WP cyPYZZWeW61x0foA2aUt/hih4OEMwpyPCQN8sT+EjprjCKCylQfBlP6ZfBCjr8mI5dm/ uuioX3ydCmMt51zHesP1UMjsExfdMX8e7ignZQCSqqxKWgS2ieI1Rsd2/uP6OH2x7czl 5i2gidHVFWa9vt7ApoiGDax/TB1fZmKU9rYPVNY+TPVwRJztWiCqsPrgQuQtQEuE7WQT 55Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=igut5By295ohhbEPdn0DgsM5vVo3aXkJJjZjswdn8UY=; b=EIqwvqDuX1RQJAEXcGGPoZIAgcqtCmi/s1OgOrgPLjZpJ/YFz/6nTuZzZE+CoFF9zI PNMIufEMIOfx0E2t2VRIfwFnbvtBd7mRflBQWv6JdcX+WwasHoBQUwfFsi0b/6Os7ZJA M1sta15yfUtUD7iuoZmQxnjX1AN+SGu32gCDa//gW1bAyswqr66n2BDYhis2dKAhTLrT 5jsOE/tfk16W/fC9dqjI3GBbE4GtOPdlFDU1q+Ost6VtBrljyCH5Q25rhK4OWdeZwamq dsU1z+8G4L5SYHja8VufecqOtpjQO9OT36xbkNtTA4k0zL67S6YGPKVNEYRv1pXu//zw k3Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qs7RYzkr; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i184-20020a6387c1000000b004a804c6d77dsi2366672pge.186.2023.01.05.16.43.54; Thu, 05 Jan 2023 16:44:01 -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=qs7RYzkr; 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 S235888AbjAEXm7 (ORCPT + 55 others); Thu, 5 Jan 2023 18:42:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235740AbjAEXml (ORCPT ); Thu, 5 Jan 2023 18:42:41 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3286D506 for ; Thu, 5 Jan 2023 15:41:06 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id g20so18275857pfb.3 for ; Thu, 05 Jan 2023 15:41:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=igut5By295ohhbEPdn0DgsM5vVo3aXkJJjZjswdn8UY=; b=qs7RYzkrlMT2Nl3hQIAyrmGqJrH24pdSDWZlzwhTjCY6nATSPnjRz6EfHi3wfuetnN s60wR3yXY1JTF3+3oy0LRNs2OCgvBKmrI8RAuy/+Pz9om7nxUUri4oTIYe33DCI328W1 7ryeq28hbWdZ9/1juDX2pd2fmLoVn8kc1Nm6Mo4clL6dwVGc2jbU3ExkwTEn8R/+5WaM ykrs8HgNXaOE8vMgwYRm8WLtugNefPG006dIHMsyK2sB0yIsckEdT87Q6QpGOyVE+/Cm 6at3ZsZixNLe0txQl5RwwBd5hKe1AE9P3mwZ3oKcyFoU0sCdEjBli4T3/7L2lA/qAmr1 nBxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=igut5By295ohhbEPdn0DgsM5vVo3aXkJJjZjswdn8UY=; b=22eGJptLLQvPjqPtCHzP78RBgzDXZeQrqnU+ygHnalUj1IGZRPCdvxKCzF9CgIvbDk aKxVDtEyJzCOj4yvF9NNkF/wuBQpInaJf/DyrcZNiEXzB9dAaHoIjyBP0kGXeTSQFx4s Fx4LZ8bqrDXlTOzToR1f6PHpz9YPpe9HVXv4/JcYLmnMBU1K0SLCvNWh5VbEPqwAfjeK w29edALmvow54QqaUlbgypgpXmraZBRxalMCjnFD7xo77nJ+1gPYUrbtVw9o/WTDNZ+x 0E2VL197X8qDEvIbL72eIU4x4k115rfxPyKtiz6MyCtgHaQk2qBfzIR3WEwSap8ev9gG neCQ== X-Gm-Message-State: AFqh2koNdQTMKl6hXLNTiuVXAqZNNmxxEPf40euhSeEm72sJPuJx6SOJ ilzuTWEUkXcXF26DdZmDGwxhY5nuyGVH8KcL0FOdpw== X-Received: by 2002:a63:5241:0:b0:4a3:9414:d667 with SMTP id s1-20020a635241000000b004a39414d667mr881249pgl.573.1672962053655; Thu, 05 Jan 2023 15:40:53 -0800 (PST) MIME-Version: 1.0 References: <20230105172243.7238-1-mike.leach@linaro.org> In-Reply-To: From: Mike Leach Date: Thu, 5 Jan 2023 23:40:42 +0000 Message-ID: Subject: Re: [PATCH] perf build: Fix build error when NO_LIBBPF=1 To: Ian Rogers Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, acme@kernel.org, peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org Content-Type: text/plain; charset="UTF-8" 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=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, 5 Jan 2023 at 19:03, Ian Rogers wrote: > > On Thu, Jan 5, 2023 at 9:22 AM Mike Leach 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 > > > > > > > > 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 > > > > > > > > libbpf.c:46:10: fatal error: libelf.h: No such file or directory > > 46 | #include > > | ^~~~~~~~~~ > > compilation terminated. > > > > ./tools/build/Makefile.build:96: recipe for target > > '.tools/perf/libbpf/staticobjs/libbpf.o' failed > > > > ``` > > > > plus one other include error for > > 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 > > --- > > 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