Message ID | 20230726133642.750342-1-namhyung@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp430419vqo; Wed, 26 Jul 2023 07:10:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlGGwOOWsau+XXO9tz94lb5J6dTSafbOPiSjHZNNumKmh/+X8KbboZ4ADHJZfTtj0Gij6T8r X-Received: by 2002:a05:6a21:6da0:b0:133:c170:6ee9 with SMTP id wl32-20020a056a216da000b00133c1706ee9mr2705852pzb.42.1690380629734; Wed, 26 Jul 2023 07:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690380629; cv=none; d=google.com; s=arc-20160816; b=SejGOvtHusrNmO3vMTD3CcVtD41gW9cGOdjwQkpKmTc0uZmt08OJr45v5sh27Ak7/X VGjl9MvZAl6yYWgKocRAOzeZxSH+plHzvPFFn2L6pjgvoh+IVGWm/4wj2rxg5NFb5HsK WvHD+GM0G3T7QGSccipNFLjB1bZzM7lV63PfLIH/OBncM0dUWppnmKN4aj627kKfKGzG keP5teIJZY5t3AUseCqF48qUyLJopt2HbEauzPVPNt3LoaGHlB67I3xuF5jj1L+48/a+ x6gZ2Knl1bCsXRmbw7DPXEXa/4JsKsHihUD2hxzrgbkuxj9Ef6iuvmWs3MdjF+2hiuCv rwJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=gYgt2/L5v2iTxYlRyElhhZxpEQdszhBpRfoZ9bvFiQ0=; fh=0+7a5fu/FUeiIqPazwYnsTJzAAsSbc1CLnWMxuTAMQQ=; b=qJ24Yil+T3JQ1IbnF2T06k+LM85hJ+hDX0iFkDte1tzsEy9GF/HrE5aMvmOidOY3BY 0TBREiJOeXcqSNSWC+Irp8bJY7MWsJ4Ho0vI9RSOQm9ucKsKf/Q9CkmN2Fe7FhBxmRr+ 8V6Q0nHBlEAMelGEVYvZbGf5wUWDel0ot6a882Hk5f8v7/YaEY24Ps7Gabh04lRFVgM7 9GLOMahUqIqqD47fd29JebqDzJKTDCnzRlcrtrn6kKcyK+54AKG6ZtsJeohb1NioYMSo 1yYnWAetbJV1CJFlZTkzBjbpFvZFoJK0y9id9jrQK9wdfKu4mfwjaYFN8XOUIwjsGPKO QJ6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="cc+iIay/"; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cm25-20020a056a00339900b0067dd87a586esi12921519pfb.377.2023.07.26.07.10.12; Wed, 26 Jul 2023 07:10:29 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b="cc+iIay/"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233891AbjGZNgw (ORCPT <rfc822;hanasaki@gmail.com> + 99 others); Wed, 26 Jul 2023 09:36:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbjGZNgu (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 26 Jul 2023 09:36:50 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D6A1734; Wed, 26 Jul 2023 06:36:49 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bb81809ca8so35380325ad.3; Wed, 26 Jul 2023 06:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690378609; x=1690983409; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=gYgt2/L5v2iTxYlRyElhhZxpEQdszhBpRfoZ9bvFiQ0=; b=cc+iIay/ECUUq2pHo33gxd4ADnap2aPJzZM2OBywjK7f+VDRd1WJuOxS7c6n9Q7ZYX fR4V3H1u8u+4i4JlE5fZwItEwJ8c5gLPRtmyo4wIGDY4I74cL9fi0puRyvoPVDG5kchY MIdU+wVuzneuLtM5doFCVEuZuvGwpdAvIbcflbNd+WB+bVKPyaxKU46Y5Sw05gCDtmOJ l6anyIffgIvqiITu4Bns3vF7CAsi8KZFdlHTS8EPisT85e5Vxw+6grzUvglcRdOR0hKU bUxryPE8Il+DhsnQv6g9XDQA1JOca6j/I9LS6MN1zNm47Mdo9qab6hDwxGv0LsBnUtmU YGYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690378609; x=1690983409; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gYgt2/L5v2iTxYlRyElhhZxpEQdszhBpRfoZ9bvFiQ0=; b=G1NNdhkpQvkvtA2wkj2UO6RFn578CXuX0RCGF10UUiJ06jzFQZHkLa7bSqDMcOH1EF MAppjIX6LMqBSFeI0bUwq+IEvL2uk7AZEw3CfwsU6xse7lk+BRIPzftJNUlBQHqnXQNK m4xsnEPd3pcjmPBj9F5P6xfRZj/CLb9jv4KHhy3De9OvGWITWRHM78ItuEIo7xEX0rrD V06ZJA8XeOsr97zOmgjXPY0W3dX02C8QGfK1HGR2S8m0ilXOtrilfdpILpaDPhlb7iO5 7SmVZ8fiK6UX8OovQhRk/voH5haZ0wBmLy7goimgsANw+sYHFOvkUVmuw3wcUvIRuecG ZR/g== X-Gm-Message-State: ABy/qLZ+VJqXO07FbOM/N+Q4wcdM1hcC+xztI54NmJG08WVR8bKrCKXa 21G3tW4sHU9XfwtehH1ARZg= X-Received: by 2002:a17:902:b08a:b0:1b8:c972:606c with SMTP id p10-20020a170902b08a00b001b8c972606cmr1869361plr.57.1690378608925; Wed, 26 Jul 2023 06:36:48 -0700 (PDT) Received: from bangji.roam.corp.google.com ([114.129.115.132]) by smtp.gmail.com with ESMTPSA id q8-20020a170902b10800b001b8baa83639sm13206369plr.200.2023.07.26.06.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 06:36:48 -0700 (PDT) Sender: Namhyung Kim <namhyung@gmail.com> From: Namhyung Kim <namhyung@kernel.org> To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org> Cc: Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>, LKML <linux-kernel@vger.kernel.org>, linux-perf-users@vger.kernel.org, Anup Sharma <anupnewsmail@gmail.com>, stable@vger.kernel.org Subject: [PATCH 1/2] perf build: Update build rule for generated files Date: Wed, 26 Jul 2023 06:36:41 -0700 Message-ID: <20230726133642.750342-1-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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: INBOX X-GMAIL-THRID: 1772492559433017347 X-GMAIL-MSGID: 1772492559433017347 |
Series |
[1/2] perf build: Update build rule for generated files
|
|
Commit Message
Namhyung Kim
July 26, 2023, 1:36 p.m. UTC
The bison and flex generate C files from the source (.y and .l)
files. When O= option is used, they are saved in a separate directory
but the default build rule assumes the .C files are in the source
directory. So it might read invalid file if there are generated files
from an old version. The same is true for the pmu-events files.
For example, the following command would cause a build failure:
$ git checkout v6.3
$ make -C tools/perf # build in the same directory
$ git checkout v6.5-rc2
$ mkdir build # create a build directory
$ make -C tools/perf O=build # build in a different directory but it
# refers files in the source directory
Let's update the build rule to specify those cases explicitly to depend
on the files in the output directory.
Note that it's not a complete fix and it needs the next patch for the
include path too.
Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file")
Cc: stable@vger.kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/build/Makefile.build | 8 ++++++++
tools/perf/pmu-events/Build | 4 ++++
2 files changed, 12 insertions(+)
Comments
On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim <namhyung@kernel.org> wrote: > > The bison and flex generate C files from the source (.y and .l) > files. When O= option is used, they are saved in a separate directory > but the default build rule assumes the .C files are in the source > directory. So it might read invalid file if there are generated files > from an old version. The same is true for the pmu-events files. > > For example, the following command would cause a build failure: > > $ git checkout v6.3 > $ make -C tools/perf # build in the same directory > > $ git checkout v6.5-rc2 > $ mkdir build # create a build directory > $ make -C tools/perf O=build # build in a different directory but it > # refers files in the source directory > > Let's update the build rule to specify those cases explicitly to depend > on the files in the output directory. > > Note that it's not a complete fix and it needs the next patch for the > include path too. > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > Cc: stable@vger.kernel.org > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > --- > tools/build/Makefile.build | 8 ++++++++ > tools/perf/pmu-events/Build | 4 ++++ > 2 files changed, 12 insertions(+) > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > index 89430338a3d9..f9396696fcbf 100644 > --- a/tools/build/Makefile.build > +++ b/tools/build/Makefile.build > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > $(call rule_mkdir) > $(call if_changed_dep,cc_s_c) > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > + $(call rule_mkdir) > + $(call if_changed_dep,$(host)cc_o_c) > + > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > + $(call rule_mkdir) > + $(call if_changed_dep,$(host)cc_o_c) > + Hi Namhyung, as we have: ``` $(OUTPUT)%.o: %.c FORCE $(call rule_mkdir) $(call if_changed_dep,$(host)cc_o_c) ``` I'm not sure what the 2 additional rules achieve. > # Gather build data: > # obj-y - list of build objects > # subdir-y - list of directories to nest > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > index 150765f2baee..f38a27765604 100644 > --- a/tools/perf/pmu-events/Build > +++ b/tools/perf/pmu-events/Build > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > $(call rule_mkdir) > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > endif > + > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > + $(call rule_mkdir) > + $(call if_changed_dep,$(host)cc_o_c) If we add this, do the Makefile.build changes still need to happen? Thanks, Ian > -- > 2.41.0.487.g6d72f3e995-goog >
Hi Ian, On Wed, Jul 26, 2023 at 8:48 AM Ian Rogers <irogers@google.com> wrote: > > On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim <namhyung@kernel.org> wrote: > > > > The bison and flex generate C files from the source (.y and .l) > > files. When O= option is used, they are saved in a separate directory > > but the default build rule assumes the .C files are in the source > > directory. So it might read invalid file if there are generated files > > from an old version. The same is true for the pmu-events files. > > > > For example, the following command would cause a build failure: > > > > $ git checkout v6.3 > > $ make -C tools/perf # build in the same directory > > > > $ git checkout v6.5-rc2 > > $ mkdir build # create a build directory > > $ make -C tools/perf O=build # build in a different directory but it > > # refers files in the source directory > > > > Let's update the build rule to specify those cases explicitly to depend > > on the files in the output directory. > > > > Note that it's not a complete fix and it needs the next patch for the > > include path too. > > > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > > Cc: stable@vger.kernel.org > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > --- > > tools/build/Makefile.build | 8 ++++++++ > > tools/perf/pmu-events/Build | 4 ++++ > > 2 files changed, 12 insertions(+) > > > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > > index 89430338a3d9..f9396696fcbf 100644 > > --- a/tools/build/Makefile.build > > +++ b/tools/build/Makefile.build > > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > > $(call rule_mkdir) > > $(call if_changed_dep,cc_s_c) > > > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > > + $(call rule_mkdir) > > + $(call if_changed_dep,$(host)cc_o_c) > > + > > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > > + $(call rule_mkdir) > > + $(call if_changed_dep,$(host)cc_o_c) > > + > > Hi Namhyung, > > as we have: > ``` > $(OUTPUT)%.o: %.c FORCE > $(call rule_mkdir) > $(call if_changed_dep,$(host)cc_o_c) > ``` > I'm not sure what the 2 additional rules achieve. The above rule assumes the .c files are in the source directory (without $(OUTPUT) prefix). It caused a trouble when the flex and bison files are generated in the output directory and you have an old version of them in the source directory. > > > # Gather build data: > > # obj-y - list of build objects > > # subdir-y - list of directories to nest > > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > > index 150765f2baee..f38a27765604 100644 > > --- a/tools/perf/pmu-events/Build > > +++ b/tools/perf/pmu-events/Build > > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > > $(call rule_mkdir) > > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > > endif > > + > > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > > + $(call rule_mkdir) > > + $(call if_changed_dep,$(host)cc_o_c) > > If we add this, do the Makefile.build changes still need to happen? The Makefile.build changes are specific to flex and bison files. So yes, we need this for pmu-events.c to work properly with O= option. Thanks, Namhyung
On Wed, Jul 26, 2023 at 3:57 PM Namhyung Kim <namhyung@kernel.org> wrote: > > Hi Ian, > > On Wed, Jul 26, 2023 at 8:48 AM Ian Rogers <irogers@google.com> wrote: > > > > On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > The bison and flex generate C files from the source (.y and .l) > > > files. When O= option is used, they are saved in a separate directory > > > but the default build rule assumes the .C files are in the source > > > directory. So it might read invalid file if there are generated files > > > from an old version. The same is true for the pmu-events files. > > > > > > For example, the following command would cause a build failure: > > > > > > $ git checkout v6.3 > > > $ make -C tools/perf # build in the same directory > > > > > > $ git checkout v6.5-rc2 > > > $ mkdir build # create a build directory > > > $ make -C tools/perf O=build # build in a different directory but it > > > # refers files in the source directory > > > > > > Let's update the build rule to specify those cases explicitly to depend > > > on the files in the output directory. > > > > > > Note that it's not a complete fix and it needs the next patch for the > > > include path too. > > > > > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > > --- > > > tools/build/Makefile.build | 8 ++++++++ > > > tools/perf/pmu-events/Build | 4 ++++ > > > 2 files changed, 12 insertions(+) > > > > > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > > > index 89430338a3d9..f9396696fcbf 100644 > > > --- a/tools/build/Makefile.build > > > +++ b/tools/build/Makefile.build > > > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > > > $(call rule_mkdir) > > > $(call if_changed_dep,cc_s_c) > > > > > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > > > + $(call rule_mkdir) > > > + $(call if_changed_dep,$(host)cc_o_c) > > > + > > > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > > > + $(call rule_mkdir) > > > + $(call if_changed_dep,$(host)cc_o_c) > > > + > > > > Hi Namhyung, > > > > as we have: > > ``` > > $(OUTPUT)%.o: %.c FORCE > > $(call rule_mkdir) > > $(call if_changed_dep,$(host)cc_o_c) > > ``` > > I'm not sure what the 2 additional rules achieve. > > The above rule assumes the .c files are in the source directory > (without $(OUTPUT) prefix). It caused a trouble when the > flex and bison files are generated in the output directory and > you have an old version of them in the source directory. > > > > > > > # Gather build data: > > > # obj-y - list of build objects > > > # subdir-y - list of directories to nest > > > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > > > index 150765f2baee..f38a27765604 100644 > > > --- a/tools/perf/pmu-events/Build > > > +++ b/tools/perf/pmu-events/Build > > > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > > > $(call rule_mkdir) > > > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > > > endif > > > + > > > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > > > + $(call rule_mkdir) > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > If we add this, do the Makefile.build changes still need to happen? > > The Makefile.build changes are specific to flex and bison files. > So yes, we need this for pmu-events.c to work properly with O= > option. Got it, you are right I was confusing the flex/bison with the jevents case. Can we get away with a single rule then: ``` $(OUTPUT)%.o: $(OUTPUT)%.c FORCE $(call rule_mkdir) $(call if_changed_dep,$(host)cc_o_c) ``` Thanks, Ian > Thanks, > Namhyung
On Wed, Jul 26, 2023 at 5:36 PM Ian Rogers <irogers@google.com> wrote: > > On Wed, Jul 26, 2023 at 3:57 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > Hi Ian, > > > > On Wed, Jul 26, 2023 at 8:48 AM Ian Rogers <irogers@google.com> wrote: > > > > > > On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > The bison and flex generate C files from the source (.y and .l) > > > > files. When O= option is used, they are saved in a separate directory > > > > but the default build rule assumes the .C files are in the source > > > > directory. So it might read invalid file if there are generated files > > > > from an old version. The same is true for the pmu-events files. > > > > > > > > For example, the following command would cause a build failure: > > > > > > > > $ git checkout v6.3 > > > > $ make -C tools/perf # build in the same directory > > > > > > > > $ git checkout v6.5-rc2 > > > > $ mkdir build # create a build directory > > > > $ make -C tools/perf O=build # build in a different directory but it > > > > # refers files in the source directory > > > > > > > > Let's update the build rule to specify those cases explicitly to depend > > > > on the files in the output directory. > > > > > > > > Note that it's not a complete fix and it needs the next patch for the > > > > include path too. > > > > > > > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > > > > Cc: stable@vger.kernel.org > > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > > > --- > > > > tools/build/Makefile.build | 8 ++++++++ > > > > tools/perf/pmu-events/Build | 4 ++++ > > > > 2 files changed, 12 insertions(+) > > > > > > > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > > > > index 89430338a3d9..f9396696fcbf 100644 > > > > --- a/tools/build/Makefile.build > > > > +++ b/tools/build/Makefile.build > > > > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > > > > $(call rule_mkdir) > > > > $(call if_changed_dep,cc_s_c) > > > > > > > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > > > > + $(call rule_mkdir) > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > + > > > > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > > > > + $(call rule_mkdir) > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > + > > > > > > Hi Namhyung, > > > > > > as we have: > > > ``` > > > $(OUTPUT)%.o: %.c FORCE > > > $(call rule_mkdir) > > > $(call if_changed_dep,$(host)cc_o_c) > > > ``` > > > I'm not sure what the 2 additional rules achieve. > > > > The above rule assumes the .c files are in the source directory > > (without $(OUTPUT) prefix). It caused a trouble when the > > flex and bison files are generated in the output directory and > > you have an old version of them in the source directory. > > > > > > > > > > > # Gather build data: > > > > # obj-y - list of build objects > > > > # subdir-y - list of directories to nest > > > > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > > > > index 150765f2baee..f38a27765604 100644 > > > > --- a/tools/perf/pmu-events/Build > > > > +++ b/tools/perf/pmu-events/Build > > > > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > > > > $(call rule_mkdir) > > > > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > > > > endif > > > > + > > > > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > > > > + $(call rule_mkdir) > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > If we add this, do the Makefile.build changes still need to happen? > > > > The Makefile.build changes are specific to flex and bison files. > > So yes, we need this for pmu-events.c to work properly with O= > > option. > > Got it, you are right I was confusing the flex/bison with the jevents > case. Can we get away with a single rule then: > ``` > $(OUTPUT)%.o: $(OUTPUT)%.c FORCE > $(call rule_mkdir) > $(call if_changed_dep,$(host)cc_o_c) > ``` Probably, but I wonder if it affects the normal .c files expecting them in the OUTPUT directory. Thanks, Namhyung
On Wed, Jul 26, 2023 at 6:01 PM Namhyung Kim <namhyung@kernel.org> wrote: > > On Wed, Jul 26, 2023 at 5:36 PM Ian Rogers <irogers@google.com> wrote: > > > > On Wed, Jul 26, 2023 at 3:57 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > Hi Ian, > > > > > > On Wed, Jul 26, 2023 at 8:48 AM Ian Rogers <irogers@google.com> wrote: > > > > > > > > On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > > > The bison and flex generate C files from the source (.y and .l) > > > > > files. When O= option is used, they are saved in a separate directory > > > > > but the default build rule assumes the .C files are in the source > > > > > directory. So it might read invalid file if there are generated files > > > > > from an old version. The same is true for the pmu-events files. > > > > > > > > > > For example, the following command would cause a build failure: > > > > > > > > > > $ git checkout v6.3 > > > > > $ make -C tools/perf # build in the same directory > > > > > > > > > > $ git checkout v6.5-rc2 > > > > > $ mkdir build # create a build directory > > > > > $ make -C tools/perf O=build # build in a different directory but it > > > > > # refers files in the source directory > > > > > > > > > > Let's update the build rule to specify those cases explicitly to depend > > > > > on the files in the output directory. > > > > > > > > > > Note that it's not a complete fix and it needs the next patch for the > > > > > include path too. > > > > > > > > > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > > > > > Cc: stable@vger.kernel.org > > > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > > > > --- > > > > > tools/build/Makefile.build | 8 ++++++++ > > > > > tools/perf/pmu-events/Build | 4 ++++ > > > > > 2 files changed, 12 insertions(+) > > > > > > > > > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > > > > > index 89430338a3d9..f9396696fcbf 100644 > > > > > --- a/tools/build/Makefile.build > > > > > +++ b/tools/build/Makefile.build > > > > > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > > > > > $(call rule_mkdir) > > > > > $(call if_changed_dep,cc_s_c) > > > > > > > > > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > > > > > + $(call rule_mkdir) > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > + > > > > > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > > > > > + $(call rule_mkdir) > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > + > > > > > > > > Hi Namhyung, > > > > > > > > as we have: > > > > ``` > > > > $(OUTPUT)%.o: %.c FORCE > > > > $(call rule_mkdir) > > > > $(call if_changed_dep,$(host)cc_o_c) > > > > ``` > > > > I'm not sure what the 2 additional rules achieve. > > > > > > The above rule assumes the .c files are in the source directory > > > (without $(OUTPUT) prefix). It caused a trouble when the > > > flex and bison files are generated in the output directory and > > > you have an old version of them in the source directory. > > > > > > > > > > > > > > > # Gather build data: > > > > > # obj-y - list of build objects > > > > > # subdir-y - list of directories to nest > > > > > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > > > > > index 150765f2baee..f38a27765604 100644 > > > > > --- a/tools/perf/pmu-events/Build > > > > > +++ b/tools/perf/pmu-events/Build > > > > > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > > > > > $(call rule_mkdir) > > > > > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > > > > > endif > > > > > + > > > > > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > > > > > + $(call rule_mkdir) > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > > If we add this, do the Makefile.build changes still need to happen? > > > > > > The Makefile.build changes are specific to flex and bison files. > > > So yes, we need this for pmu-events.c to work properly with O= > > > option. > > > > Got it, you are right I was confusing the flex/bison with the jevents > > case. Can we get away with a single rule then: > > ``` > > $(OUTPUT)%.o: $(OUTPUT)%.c FORCE > > $(call rule_mkdir) > > $(call if_changed_dep,$(host)cc_o_c) > > ``` > > Probably, but I wonder if it affects the normal .c files expecting > them in the OUTPUT directory. Hmm.. I think the longer matches may be necessary to trigger the "more specific" ordering: https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html I'm not keen on these extra rules that mirror existing rules, it is a bit cryptic what is going on. I wonder if it would be cleaner just to fail the build if the bogus pmu-events.c exists. For example: ``` --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -12,6 +12,14 @@ EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c PMU_EVENTS_C = $(OUTPUT)pmu-events/pmu-events.c METRIC_TEST_LOG = $(OUTPUT)pmu-events/metric_test.log +ifneq ($(OUTPUT),) +ifneq ($(wildcard pmu-events/pmu-events.c),) +dummy := $(error OUTPUT set but tools/perf/pmu-events/pmu-events.c exists. \ + This can mean the generated version of pmu-events.c is not compiled. \ + Try 'cd tools/perf; make clean; cd -' and then rebuilding.) +endif +endif + ifeq ($(JEVENTS_ARCH),) JEVENTS_ARCH=$(SRCARCH) endif ``` Thanks, Ian > Thanks, > Namhyung
On Wed, Jul 26, 2023 at 9:48 PM Ian Rogers <irogers@google.com> wrote: > > On Wed, Jul 26, 2023 at 6:01 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > On Wed, Jul 26, 2023 at 5:36 PM Ian Rogers <irogers@google.com> wrote: > > > > > > On Wed, Jul 26, 2023 at 3:57 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > Hi Ian, > > > > > > > > On Wed, Jul 26, 2023 at 8:48 AM Ian Rogers <irogers@google.com> wrote: > > > > > > > > > > On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > > > > > The bison and flex generate C files from the source (.y and .l) > > > > > > files. When O= option is used, they are saved in a separate directory > > > > > > but the default build rule assumes the .C files are in the source > > > > > > directory. So it might read invalid file if there are generated files > > > > > > from an old version. The same is true for the pmu-events files. > > > > > > > > > > > > For example, the following command would cause a build failure: > > > > > > > > > > > > $ git checkout v6.3 > > > > > > $ make -C tools/perf # build in the same directory > > > > > > > > > > > > $ git checkout v6.5-rc2 > > > > > > $ mkdir build # create a build directory > > > > > > $ make -C tools/perf O=build # build in a different directory but it > > > > > > # refers files in the source directory > > > > > > > > > > > > Let's update the build rule to specify those cases explicitly to depend > > > > > > on the files in the output directory. > > > > > > > > > > > > Note that it's not a complete fix and it needs the next patch for the > > > > > > include path too. > > > > > > > > > > > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > > > > > > Cc: stable@vger.kernel.org > > > > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > > > > > --- > > > > > > tools/build/Makefile.build | 8 ++++++++ > > > > > > tools/perf/pmu-events/Build | 4 ++++ > > > > > > 2 files changed, 12 insertions(+) > > > > > > > > > > > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > > > > > > index 89430338a3d9..f9396696fcbf 100644 > > > > > > --- a/tools/build/Makefile.build > > > > > > +++ b/tools/build/Makefile.build > > > > > > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > > > > > > $(call rule_mkdir) > > > > > > $(call if_changed_dep,cc_s_c) > > > > > > > > > > > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > > > > > > + $(call rule_mkdir) > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > + > > > > > > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > > > > > > + $(call rule_mkdir) > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > + > > > > > > > > > > Hi Namhyung, > > > > > > > > > > as we have: > > > > > ``` > > > > > $(OUTPUT)%.o: %.c FORCE > > > > > $(call rule_mkdir) > > > > > $(call if_changed_dep,$(host)cc_o_c) > > > > > ``` > > > > > I'm not sure what the 2 additional rules achieve. > > > > > > > > The above rule assumes the .c files are in the source directory > > > > (without $(OUTPUT) prefix). It caused a trouble when the > > > > flex and bison files are generated in the output directory and > > > > you have an old version of them in the source directory. > > > > > > > > > > > > > > > > > > > # Gather build data: > > > > > > # obj-y - list of build objects > > > > > > # subdir-y - list of directories to nest > > > > > > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > > > > > > index 150765f2baee..f38a27765604 100644 > > > > > > --- a/tools/perf/pmu-events/Build > > > > > > +++ b/tools/perf/pmu-events/Build > > > > > > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > > > > > > $(call rule_mkdir) > > > > > > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > > > > > > endif > > > > > > + > > > > > > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > > > > > > + $(call rule_mkdir) > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > > > > If we add this, do the Makefile.build changes still need to happen? > > > > > > > > The Makefile.build changes are specific to flex and bison files. > > > > So yes, we need this for pmu-events.c to work properly with O= > > > > option. > > > > > > Got it, you are right I was confusing the flex/bison with the jevents > > > case. Can we get away with a single rule then: > > > ``` > > > $(OUTPUT)%.o: $(OUTPUT)%.c FORCE > > > $(call rule_mkdir) > > > $(call if_changed_dep,$(host)cc_o_c) > > > ``` > > > > Probably, but I wonder if it affects the normal .c files expecting > > them in the OUTPUT directory. > > Hmm.. I think the longer matches may be necessary to trigger the "more > specific" ordering: > https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html > > I'm not keen on these extra rules that mirror existing rules, it is a > bit cryptic what is going on. I wonder if it would be cleaner just to > fail the build if the bogus pmu-events.c exists. For example: I prefer just making it build instead of failing. But not strongly against your idea. It'd be nice to hear what others think.. Arnaldo? > ``` > --- a/tools/perf/pmu-events/Build > +++ b/tools/perf/pmu-events/Build > @@ -12,6 +12,14 @@ EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c > PMU_EVENTS_C = $(OUTPUT)pmu-events/pmu-events.c > METRIC_TEST_LOG = $(OUTPUT)pmu-events/metric_test.log > > +ifneq ($(OUTPUT),) > +ifneq ($(wildcard pmu-events/pmu-events.c),) > +dummy := $(error OUTPUT set but tools/perf/pmu-events/pmu-events.c exists. \ > + This can mean the generated version of pmu-events.c is not > compiled. \ > + Try 'cd tools/perf; make clean; cd -' and then rebuilding.) I've tested this and this message is buried in the stream of parallel build outputs. :( Thanks, Namhyung > +endif > +endif > + > ifeq ($(JEVENTS_ARCH),) > JEVENTS_ARCH=$(SRCARCH) > endif > ```
Em Wed, Jul 26, 2023 at 11:45:44PM -0700, Namhyung Kim escreveu: > On Wed, Jul 26, 2023 at 9:48 PM Ian Rogers <irogers@google.com> wrote: > > On Wed, Jul 26, 2023 at 6:01 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > On Wed, Jul 26, 2023 at 5:36 PM Ian Rogers <irogers@google.com> wrote: > > > > On Wed, Jul 26, 2023 at 3:57 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > On Wed, Jul 26, 2023 at 8:48 AM Ian Rogers <irogers@google.com> wrote: > > > > > > On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > The bison and flex generate C files from the source (.y and .l) > > > > > > > files. When O= option is used, they are saved in a separate directory > > > > > > > but the default build rule assumes the .C files are in the source > > > > > > > directory. So it might read invalid file if there are generated files > > > > > > > from an old version. The same is true for the pmu-events files. > > > > > > > > > > > > > > For example, the following command would cause a build failure: > > > > > > > > > > > > > > $ git checkout v6.3 > > > > > > > $ make -C tools/perf # build in the same directory > > > > > > > > > > > > > > $ git checkout v6.5-rc2 > > > > > > > $ mkdir build # create a build directory > > > > > > > $ make -C tools/perf O=build # build in a different directory but it > > > > > > > # refers files in the source directory > > > > > > > > > > > > > > Let's update the build rule to specify those cases explicitly to depend > > > > > > > on the files in the output directory. > > > > > > > > > > > > > > Note that it's not a complete fix and it needs the next patch for the > > > > > > > include path too. > > > > > > > > > > > > > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > > > > > > > Cc: stable@vger.kernel.org > > > > > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > > > > > > --- > > > > > > > tools/build/Makefile.build | 8 ++++++++ > > > > > > > tools/perf/pmu-events/Build | 4 ++++ > > > > > > > 2 files changed, 12 insertions(+) > > > > > > > > > > > > > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > > > > > > > index 89430338a3d9..f9396696fcbf 100644 > > > > > > > --- a/tools/build/Makefile.build > > > > > > > +++ b/tools/build/Makefile.build > > > > > > > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > > > > > > > $(call rule_mkdir) > > > > > > > $(call if_changed_dep,cc_s_c) > > > > > > > > > > > > > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > > > > > > > + $(call rule_mkdir) > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > + > > > > > > > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > > > > > > > + $(call rule_mkdir) > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > + > > > > > > > > > > > > Hi Namhyung, > > > > > > > > > > > > as we have: > > > > > > ``` > > > > > > $(OUTPUT)%.o: %.c FORCE > > > > > > $(call rule_mkdir) > > > > > > $(call if_changed_dep,$(host)cc_o_c) > > > > > > ``` > > > > > > I'm not sure what the 2 additional rules achieve. > > > > > > > > > > The above rule assumes the .c files are in the source directory > > > > > (without $(OUTPUT) prefix). It caused a trouble when the > > > > > flex and bison files are generated in the output directory and > > > > > you have an old version of them in the source directory. > > > > > > > > > > > > # Gather build data: > > > > > > > # obj-y - list of build objects > > > > > > > # subdir-y - list of directories to nest > > > > > > > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > > > > > > > index 150765f2baee..f38a27765604 100644 > > > > > > > --- a/tools/perf/pmu-events/Build > > > > > > > +++ b/tools/perf/pmu-events/Build > > > > > > > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > > > > > > > $(call rule_mkdir) > > > > > > > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > > > > > > > endif > > > > > > > + > > > > > > > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > > > > > > > + $(call rule_mkdir) > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > > > > > > If we add this, do the Makefile.build changes still need to happen? > > > > > > > > > > The Makefile.build changes are specific to flex and bison files. > > > > > So yes, we need this for pmu-events.c to work properly with O= > > > > > option. > > > > > > > > Got it, you are right I was confusing the flex/bison with the jevents > > > > case. Can we get away with a single rule then: > > > > ``` > > > > $(OUTPUT)%.o: $(OUTPUT)%.c FORCE > > > > $(call rule_mkdir) > > > > $(call if_changed_dep,$(host)cc_o_c) > > > > ``` > > > > > > Probably, but I wonder if it affects the normal .c files expecting > > > them in the OUTPUT directory. > > > > Hmm.. I think the longer matches may be necessary to trigger the "more > > specific" ordering: > > https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html > > > > I'm not keen on these extra rules that mirror existing rules, it is a > > bit cryptic what is going on. I wonder if it would be cleaner just to > > fail the build if the bogus pmu-events.c exists. For example: > > I prefer just making it build instead of failing. But not strongly > against your idea. It'd be nice to hear what others think.. Arnaldo? I think that we should just ignore any build files in the source tree when using 'O=', i.e.: make -C tools/perf genereated files (in the source tree) should not be used when, right after running it, we run: make -C tools/perf O=/some/build/dir If we run 'make -C tools/perf' and there is a pmu-events.c, use it if its timestamp is more recent than the files from which it was generated, as usual for a make managed build. - Arnaldo > > ``` > > --- a/tools/perf/pmu-events/Build > > +++ b/tools/perf/pmu-events/Build > > @@ -12,6 +12,14 @@ EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c > > PMU_EVENTS_C = $(OUTPUT)pmu-events/pmu-events.c > > METRIC_TEST_LOG = $(OUTPUT)pmu-events/metric_test.log > > > > +ifneq ($(OUTPUT),) > > +ifneq ($(wildcard pmu-events/pmu-events.c),) > > +dummy := $(error OUTPUT set but tools/perf/pmu-events/pmu-events.c exists. \ > > + This can mean the generated version of pmu-events.c is not > > compiled. \ > > + Try 'cd tools/perf; make clean; cd -' and then rebuilding.) > > I've tested this and this message is buried in the stream of > parallel build outputs. :( > > Thanks, > Namhyung > > > > +endif > > +endif > > + > > ifeq ($(JEVENTS_ARCH),) > > JEVENTS_ARCH=$(SRCARCH) > > endif > > ```
Hi Arnaldo, On Thu, Jul 27, 2023 at 4:31 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > Em Wed, Jul 26, 2023 at 11:45:44PM -0700, Namhyung Kim escreveu: > > On Wed, Jul 26, 2023 at 9:48 PM Ian Rogers <irogers@google.com> wrote: > > > On Wed, Jul 26, 2023 at 6:01 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > On Wed, Jul 26, 2023 at 5:36 PM Ian Rogers <irogers@google.com> wrote: > > > > > On Wed, Jul 26, 2023 at 3:57 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > On Wed, Jul 26, 2023 at 8:48 AM Ian Rogers <irogers@google.com> wrote: > > > > > > > On Wed, Jul 26, 2023 at 6:36 AM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > The bison and flex generate C files from the source (.y and .l) > > > > > > > > files. When O= option is used, they are saved in a separate directory > > > > > > > > but the default build rule assumes the .C files are in the source > > > > > > > > directory. So it might read invalid file if there are generated files > > > > > > > > from an old version. The same is true for the pmu-events files. > > > > > > > > > > > > > > > > For example, the following command would cause a build failure: > > > > > > > > > > > > > > > > $ git checkout v6.3 > > > > > > > > $ make -C tools/perf # build in the same directory > > > > > > > > > > > > > > > > $ git checkout v6.5-rc2 > > > > > > > > $ mkdir build # create a build directory > > > > > > > > $ make -C tools/perf O=build # build in a different directory but it > > > > > > > > # refers files in the source directory > > > > > > > > > > > > > > > > Let's update the build rule to specify those cases explicitly to depend > > > > > > > > on the files in the output directory. > > > > > > > > > > > > > > > > Note that it's not a complete fix and it needs the next patch for the > > > > > > > > include path too. > > > > > > > > > > > > > > > > Fixes: 80eeb67fe577 ("perf jevents: Program to convert JSON file") > > > > > > > > Cc: stable@vger.kernel.org > > > > > > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > > > > > > > --- > > > > > > > > tools/build/Makefile.build | 8 ++++++++ > > > > > > > > tools/perf/pmu-events/Build | 4 ++++ > > > > > > > > 2 files changed, 12 insertions(+) > > > > > > > > > > > > > > > > diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build > > > > > > > > index 89430338a3d9..f9396696fcbf 100644 > > > > > > > > --- a/tools/build/Makefile.build > > > > > > > > +++ b/tools/build/Makefile.build > > > > > > > > @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE > > > > > > > > $(call rule_mkdir) > > > > > > > > $(call if_changed_dep,cc_s_c) > > > > > > > > > > > > > > > > +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE > > > > > > > > + $(call rule_mkdir) > > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > > + > > > > > > > > +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE > > > > > > > > + $(call rule_mkdir) > > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > > + > > > > > > > > > > > > > > Hi Namhyung, > > > > > > > > > > > > > > as we have: > > > > > > > ``` > > > > > > > $(OUTPUT)%.o: %.c FORCE > > > > > > > $(call rule_mkdir) > > > > > > > $(call if_changed_dep,$(host)cc_o_c) > > > > > > > ``` > > > > > > > I'm not sure what the 2 additional rules achieve. > > > > > > > > > > > > The above rule assumes the .c files are in the source directory > > > > > > (without $(OUTPUT) prefix). It caused a trouble when the > > > > > > flex and bison files are generated in the output directory and > > > > > > you have an old version of them in the source directory. > > > > > > > > > > > > > > # Gather build data: > > > > > > > > # obj-y - list of build objects > > > > > > > > # subdir-y - list of directories to nest > > > > > > > > diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build > > > > > > > > index 150765f2baee..f38a27765604 100644 > > > > > > > > --- a/tools/perf/pmu-events/Build > > > > > > > > +++ b/tools/perf/pmu-events/Build > > > > > > > > @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L > > > > > > > > $(call rule_mkdir) > > > > > > > > $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ > > > > > > > > endif > > > > > > > > + > > > > > > > > +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) > > > > > > > > + $(call rule_mkdir) > > > > > > > > + $(call if_changed_dep,$(host)cc_o_c) > > > > > > > > > > > > > > If we add this, do the Makefile.build changes still need to happen? > > > > > > > > > > > > The Makefile.build changes are specific to flex and bison files. > > > > > > So yes, we need this for pmu-events.c to work properly with O= > > > > > > option. > > > > > > > > > > Got it, you are right I was confusing the flex/bison with the jevents > > > > > case. Can we get away with a single rule then: > > > > > ``` > > > > > $(OUTPUT)%.o: $(OUTPUT)%.c FORCE > > > > > $(call rule_mkdir) > > > > > $(call if_changed_dep,$(host)cc_o_c) > > > > > ``` > > > > > > > > Probably, but I wonder if it affects the normal .c files expecting > > > > them in the OUTPUT directory. > > > > > > Hmm.. I think the longer matches may be necessary to trigger the "more > > > specific" ordering: > > > https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html > > > > > > I'm not keen on these extra rules that mirror existing rules, it is a > > > bit cryptic what is going on. I wonder if it would be cleaner just to > > > fail the build if the bogus pmu-events.c exists. For example: > > > > I prefer just making it build instead of failing. But not strongly > > against your idea. It'd be nice to hear what others think.. Arnaldo? > > I think that we should just ignore any build files in the source tree > when using 'O=', i.e.: > > make -C tools/perf > > genereated files (in the source tree) should not be used when, right > after running it, we run: > > make -C tools/perf O=/some/build/dir > > If we run 'make -C tools/perf' and there is a pmu-events.c, use it if > its timestamp is more recent than the files from which it was generated, > as usual for a make managed build. Right, this is what my patch does by adding specific rules for generated files. I'll add a comment to describe why it's needed. Thanks, Namhyung
diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build index 89430338a3d9..f9396696fcbf 100644 --- a/tools/build/Makefile.build +++ b/tools/build/Makefile.build @@ -117,6 +117,14 @@ $(OUTPUT)%.s: %.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_s_c) +$(OUTPUT)%-bison.o: $(OUTPUT)%-bison.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,$(host)cc_o_c) + +$(OUTPUT)%-flex.o: $(OUTPUT)%-flex.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,$(host)cc_o_c) + # Gather build data: # obj-y - list of build objects # subdir-y - list of directories to nest diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index 150765f2baee..f38a27765604 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -35,3 +35,7 @@ $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_L $(call rule_mkdir) $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ endif + +$(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) + $(call rule_mkdir) + $(call if_changed_dep,$(host)cc_o_c)