[RFC PATCH] perf: parse-events: Fix compilation error while defining DEBUG_PARSER

Clément Le Goffic posted 1 patch 1 year, 8 months ago
tools/perf/util/expr.c         | 4 ----
tools/perf/util/parse-events.c | 3 ---
2 files changed, 7 deletions(-)
[RFC PATCH] perf: parse-events: Fix compilation error while defining DEBUG_PARSER
Posted by Clément Le Goffic 1 year, 8 months ago
Compiling perf tool with 'DEBUG_PARSER=1' leads to errors:

$> make -C tools/perf PARSER_DEBUG=1 NO_LIBTRACEEVENT=1
...
  CC      util/expr-flex.o
  CC      util/expr.o
util/parse-events.c:33:12: error: redundant redeclaration of ‘parse_events_debug’ [-Werror=redundant-decls]
   33 | extern int parse_events_debug;
      |            ^~~~~~~~~~~~~~~~~~
In file included from util/parse-events.c:18:
util/parse-events-bison.h:43:12: note: previous declaration of ‘parse_events_debug’ with type ‘int’
   43 | extern int parse_events_debug;
      |            ^~~~~~~~~~~~~~~~~~
util/expr.c:27:12: error: redundant redeclaration of ‘expr_debug’ [-Werror=redundant-decls]
   27 | extern int expr_debug;
      |            ^~~~~~~~~~
In file included from util/expr.c:11:
util/expr-bison.h:43:12: note: previous declaration of ‘expr_debug’ with type ‘int’
   43 | extern int expr_debug;
      |            ^~~~~~~~~~
cc-1: all warnings being treated as errors

Remove extern declaration from the parse-envents.c file as there is a
conflict with the ones generated using bison and yacc tools from the file
parse-events.[ly].

Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com>
---
I don't know how bison and yacc work together.
To me if those symbols are already generated (I don't know how), we
should get rid of them in the source file `parse-events.c`.
For my knowledge, if someone has the explanation of how they are
generated, I am interested as I didn't find any link to some part of
parse-events.[yl] files.

To: Peter Zijlstra <peterz@infradead.org>
To: Ingo Molnar <mingo@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Jiri Olsa <jolsa@kernel.org>
To: Ian Rogers <irogers@google.com>
To: Adrian Hunter <adrian.hunter@intel.com>
To: "Liang, Kan" <kan.liang@linux.intel.com>
To: John Garry <john.g.garry@oracle.com>
To: James Clark <james.clark@arm.com>
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 tools/perf/util/expr.c         | 4 ----
 tools/perf/util/parse-events.c | 3 ---
 2 files changed, 7 deletions(-)

diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
index b8875aac8f87..b2536a59c44e 100644
--- a/tools/perf/util/expr.c
+++ b/tools/perf/util/expr.c
@@ -25,10 +25,6 @@
 #include <math.h>
 #include "pmu.h"

-#ifdef PARSER_DEBUG
-extern int expr_debug;
-#endif
-
 struct expr_id_data {
 	union {
 		struct {
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6ed0f9c5581d..8d5fb05f20c2 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -31,9 +31,6 @@

 #define MAX_NAME_LEN 100

-#ifdef PARSER_DEBUG
-extern int parse_events_debug;
-#endif
 static int get_config_terms(const struct parse_events_terms *head_config,
 			    struct list_head *head_terms);
 static int parse_events_terms__copy(const struct parse_events_terms *src,

base-commit: c3f38fa61af77b49866b006939479069cd451173
--
2.34.1

Re: [RFC PATCH] perf: parse-events: Fix compilation error while defining DEBUG_PARSER
Posted by Namhyung Kim 1 year, 8 months ago
On Wed, 05 Jun 2024 16:04:53 +0200, Clément Le Goffic wrote:

> Compiling perf tool with 'DEBUG_PARSER=1' leads to errors:
> 
> $> make -C tools/perf PARSER_DEBUG=1 NO_LIBTRACEEVENT=1
> ...
>   CC      util/expr-flex.o
>   CC      util/expr.o
> util/parse-events.c:33:12: error: redundant redeclaration of ‘parse_events_debug’ [-Werror=redundant-decls]
>    33 | extern int parse_events_debug;
>       |            ^~~~~~~~~~~~~~~~~~
> In file included from util/parse-events.c:18:
> util/parse-events-bison.h:43:12: note: previous declaration of ‘parse_events_debug’ with type ‘int’
>    43 | extern int parse_events_debug;
>       |            ^~~~~~~~~~~~~~~~~~
> util/expr.c:27:12: error: redundant redeclaration of ‘expr_debug’ [-Werror=redundant-decls]
>    27 | extern int expr_debug;
>       |            ^~~~~~~~~~
> In file included from util/expr.c:11:
> util/expr-bison.h:43:12: note: previous declaration of ‘expr_debug’ with type ‘int’
>    43 | extern int expr_debug;
>       |            ^~~~~~~~~~
> cc-1: all warnings being treated as errors
> 
> [...]

Applied to perf-tools-next, thanks!


Best regards,
Namhyung
Re: [RFC PATCH] perf: parse-events: Fix compilation error while defining DEBUG_PARSER
Posted by Ian Rogers 1 year, 8 months ago
On Wed, Jun 5, 2024 at 7:06 AM Clément Le Goffic
<clement.legoffic@foss.st.com> wrote:
>
> Compiling perf tool with 'DEBUG_PARSER=1' leads to errors:
>
> $> make -C tools/perf PARSER_DEBUG=1 NO_LIBTRACEEVENT=1
> ...
>   CC      util/expr-flex.o
>   CC      util/expr.o
> util/parse-events.c:33:12: error: redundant redeclaration of ‘parse_events_debug’ [-Werror=redundant-decls]
>    33 | extern int parse_events_debug;
>       |            ^~~~~~~~~~~~~~~~~~
> In file included from util/parse-events.c:18:
> util/parse-events-bison.h:43:12: note: previous declaration of ‘parse_events_debug’ with type ‘int’
>    43 | extern int parse_events_debug;
>       |            ^~~~~~~~~~~~~~~~~~
> util/expr.c:27:12: error: redundant redeclaration of ‘expr_debug’ [-Werror=redundant-decls]
>    27 | extern int expr_debug;
>       |            ^~~~~~~~~~
> In file included from util/expr.c:11:
> util/expr-bison.h:43:12: note: previous declaration of ‘expr_debug’ with type ‘int’
>    43 | extern int expr_debug;
>       |            ^~~~~~~~~~
> cc-1: all warnings being treated as errors
>
> Remove extern declaration from the parse-envents.c file as there is a
> conflict with the ones generated using bison and yacc tools from the file
> parse-events.[ly].

I encounter the same problem and routinely just do a local change to
comment out the declaration. The definition comes from the original
patch adding debug support, Commit 82ba1f2f6148 ("perf tools: Add
support for displaying event parser debug info") and so I believe
older flex/yacc tools needed the declaration. I think the right thing
to do is to remove them.

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com>
> ---
> I don't know how bison and yacc work together.
> To me if those symbols are already generated (I don't know how), we
> should get rid of them in the source file `parse-events.c`.
> For my knowledge, if someone has the explanation of how they are
> generated, I am interested as I didn't find any link to some part of
> parse-events.[yl] files.
>
> To: Peter Zijlstra <peterz@infradead.org>
> To: Ingo Molnar <mingo@redhat.com>
> To: Arnaldo Carvalho de Melo <acme@kernel.org>
> To: Namhyung Kim <namhyung@kernel.org>
> To: Mark Rutland <mark.rutland@arm.com>
> To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> To: Jiri Olsa <jolsa@kernel.org>
> To: Ian Rogers <irogers@google.com>
> To: Adrian Hunter <adrian.hunter@intel.com>
> To: "Liang, Kan" <kan.liang@linux.intel.com>
> To: John Garry <john.g.garry@oracle.com>
> To: James Clark <james.clark@arm.com>
> Cc: linux-perf-users@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  tools/perf/util/expr.c         | 4 ----
>  tools/perf/util/parse-events.c | 3 ---
>  2 files changed, 7 deletions(-)
>
> diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
> index b8875aac8f87..b2536a59c44e 100644
> --- a/tools/perf/util/expr.c
> +++ b/tools/perf/util/expr.c
> @@ -25,10 +25,6 @@
>  #include <math.h>
>  #include "pmu.h"
>
> -#ifdef PARSER_DEBUG
> -extern int expr_debug;
> -#endif
> -
>  struct expr_id_data {
>         union {
>                 struct {
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 6ed0f9c5581d..8d5fb05f20c2 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -31,9 +31,6 @@
>
>  #define MAX_NAME_LEN 100
>
> -#ifdef PARSER_DEBUG
> -extern int parse_events_debug;
> -#endif
>  static int get_config_terms(const struct parse_events_terms *head_config,
>                             struct list_head *head_terms);
>  static int parse_events_terms__copy(const struct parse_events_terms *src,
>
> base-commit: c3f38fa61af77b49866b006939479069cd451173
> --
> 2.34.1
>