perf build fixes
Subsystems (2)
PATCH 2/3 perf parse-events: Make YYDEBUG dependent on doing a debug build
In reply to Florian FainelliFrom: Ian Rogers <[email protected]>
commit d4ce60190e08d84f88937019defa5e3d23409ac1 upstream
YYDEBUG enables line numbers and other error helpers in the generated parse-events-bison.c. These shouldn't be generated when debugging isn't enabled.
--- tools/perf/util/parse-events.y | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/parse-events.y +2 -0
@@ -6,7 +6,9 @@ %{ +#ifndef NDEBUG #define YYDEBUG 1 +#endif #include <fnmatch.h> #include <stdio.h>
Signature · 1 line
2.34.1
Quoted 25 lines · Florian Fainelli
This patch series contains "perf" build fixes specific to 6.1. We have seen occasional build failures in our CI looking like these:
util/parse-events-bison.c: In function 'yy_symbol_print':util/parse-events-bison.c:901: error: unterminated #if
901 | #if YYDEBUG|
util/parse-events-bison.c:1020:62: error: '_p' undeclared (first use in this function)
1020 |yy_symbol_value_print(yyo, yykind, yyvaluep, yylocationp,_parse_state, scanner);
| ^~util/parse-events-bison.c:1020:62: note: each undeclared identifier is reported only once for each function it appears inutil/parse-events-bison.c:1020:64: error: expected ')' at end of input1020 | yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, _parse_state, scanner); | ~ ^ | ) 1021 | YYFPRINTF (yyo, ")"); | util/parse-events-bison.c:1020:3: error: too few arguments to function 'yy_symbol_value_print' 1020 | yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, _parse_state, scanner); | ^~~~~~~~~~~~~~~~~~~~~ util/parse-events-bison.c:991:1: note: declared here 991 | yy_symbol_value_print (FILE *yyo, | ^~~~~~~~~~~~~~~~~~~~~
Quoted 1 line
which are resolved by these patches.
Lgtm, but the changes should be unnecessary as perf from Linux 7.1 should run on Linux 6.1 and with more and better features.
Thanks,
Ian
Quoted 15 lines
Ian Rogers (3):
perf build: Conditionally define NDEBUG
perf parse-events: Make YYDEBUG dependent on doing a debug build perf build: Disable fewer bison warningstools/perf/Makefile.config | 1 + tools/perf/util/Build | 12 ++++++++---- tools/perf/util/expr.y | 4 +++- tools/perf/util/parse-events.y | 3 +++ tools/perf/util/pmu.y | 3 +++ 5 files changed, 18 insertions(+), 5 deletions(-)--
2.34.1
PATCH 3/3 perf build: Disable fewer bison warnings
In reply to Florian FainelliFrom: Ian Rogers <[email protected]>
commit ddc8e4c966923ad1137790817157c8a5f0301aec upstream
If bison is version 3.8.2, reduce the number of bison C warnings disabled. Earlier bison versions have all C warnings disabled. Avoid implicit declarations of yylex by adding the declaration in the C file. A header can't be included as a circular dependency would occur due to the lexer using the bison defined tokens.
Committer notes:
Some recent versions of gcc and clang (noticed on Alpine Linux 3.17, edge, clearlinux, fedora 37, etc.
[florian: Remove non-existent tools/perf/util/bpf-filter.y in 6.1.y, adjusted perf_pmu_lex() signature]
--- tools/perf/util/Build | 12 ++++++++---- tools/perf/util/expr.y | 4 +++- tools/perf/util/parse-events.y | 1 + tools/perf/util/pmu.y | 3 +++ 4 files changed, 15 insertions(+), 5 deletions(-)
tools/perf/util/Build +8 -4
@@ -269,10 +269,14 @@ CFLAGS_parse-events-flex.o += $(flex_flags) CFLAGS_pmu-flex.o += $(flex_flags) CFLAGS_expr-flex.o += $(flex_flags) -bison_flags := -DYYENABLE_NLS=0 -BISON_GE_35 := $(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\)/\1\2/g') \>\= 35) -ifeq ($(BISON_GE_35),1) - bison_flags += -Wno-unused-parameter -Wno-nested-externs -Wno-implicit-function-declaration -Wno-switch-enum -Wno-unused-but-set-variable -Wno-unknown-warning-option +# Some newer clang and gcc version complain about this +# util/parse-events-bison.c:1317:9: error: variable 'parse_events_nerrs' set but not used [-Werror,-Wunused-but-set-variable] +# int yynerrs = 0; + +bison_flags := -DYYENABLE_NLS=0 -Wno-unused-but-set-variable +BISON_GE_382 := $(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 382) +ifeq ($(BISON_GE_382),1) + bison_flags += -Wno-switch-enum else bison_flags += -w endif
tools/perf/util/expr.y +3 -1
@@ -7,6 +7,8 @@ #include "util/debug.h" #define IN_EXPR_Y 1 #include "expr.h" +#include "expr-bison.h" +int expr_lex(YYSTYPE * yylval_param , void *yyscanner); %} %define api.pure full
@@ -56,7 +58,7 @@ static void expr_error(double *final_val __maybe_unused, struct expr_parse_ctx *ctx __maybe_unused, bool compute_ids __maybe_unused, - void *scanner, + void *scanner __maybe_unused, const char *s) { pr_debug("%s\n", s);
tools/perf/util/parse-events.y +1 -0
@@ -20,6 +20,7 @@ #include "parse-events.h" #include "parse-events-bison.h" +int parse_events_lex(YYSTYPE * yylval_param, YYLTYPE * yylloc_param , void *yyscanner); void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); #define ABORT_ON(val) \
tools/perf/util/pmu.y +3 -0
@@ -9,6 +9,9 @@ #include <linux/bitmap.h> #include <string.h> #include "pmu.h" +#include "pmu-bison.h" + +int perf_pmu_lex(void); #define ABORT_ON(val) \ do { \
Signature · 1 line
2.34.1
cover perf build fixes
This patch series contains "perf" build fixes specific to 6.1. We have seen occasional build failures in our CI looking like these:
util/parse-events-bison.c: In function 'yy_symbol_print':util/parse-events-bison.c:901: error: unterminated #if
901 | #if YYDEBUG
|
util/parse-events-bison.c:1020:62: error: '_p' undeclared (first use in this function)
1020 | yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, _parse_state, scanner);
| ^~util/parse-events-bison.c:1020:62: note: each undeclared identifier is reported only once for each function it appears in util/parse-events-bison.c:1020:64: error: expected ')' at end of input
1020 | yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, _parse_state, scanner);
| ~ ^
| )
1021 | YYFPRINTF (yyo, ")");
|
util/parse-events-bison.c:1020:3: error: too few arguments to function 'yy_symbol_value_print'
1020 | yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, _parse_state, scanner);
| ^~~~~~~~~~~~~~~~~~~~~
util/parse-events-bison.c:991:1: note: declared here
991 | yy_symbol_value_print (FILE *yyo,
| ^~~~~~~~~~~~~~~~~~~~~which are resolved by these patches.
Ian Rogers (3):
perf build: Conditionally define NDEBUG
perf parse-events: Make YYDEBUG dependent on doing a debug build perf build: Disable fewer bison warnings
tools/perf/Makefile.config | 1 + tools/perf/util/Build | 12 ++++++++---- tools/perf/util/expr.y | 4 +++- tools/perf/util/parse-events.y | 3 +++ tools/perf/util/pmu.y | 3 +++ 5 files changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 perf build: Conditionally define NDEBUG
From: Ian Rogers <[email protected]>
commit 616b14b47a86d880ba21a363440f20f82152d8f2 upstream
When a build is done without DEBUG=1 then define NDEBUG. This will compile out asserts and other debug code.
--- tools/perf/Makefile.config | 1 + 1 file changed, 1 insertion(+)
tools/perf/Makefile.config +1 -0
@@ -228,6 +228,7 @@ ifndef DEBUG endif ifeq ($(DEBUG),0) +CORE_CFLAGS += -DNDEBUG=1 ifeq ($(CC_NO_CLANG), 0) CORE_CFLAGS += -O3 else
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH stable 6.1 1/3] perf build: Conditionally define NDEBUG
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] Defining NDEBUG removes the side-effecting `bfd_check_format()` call inside `assert()`, leaving…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Defining NDEBUG removes the side-effecting bfd_check_format() call inside assert(), leaving the bfd object uninitialized.
- [Medium] Compiling out assert() removes critical runtime validation, leading to deadlocks and NULL pointer dereferences.
- [Low] Defining NDEBUG causes variables only used in assert() to trigger unused-but-set build failures.
--
commit 34a3ad3c8a3c7ed93c69e4b84492292fae1cb400
Author: Ian Rogers <[email protected]>
perf build: Conditionally define NDEBUG
When a build is done without DEBUG=1 then define NDEBUG. This will compile out asserts and other debug code.
tools/perf/Makefile.config ifndef DEBUG · line 231
Quoted 9 lines
tools/perf/Makefile.config +1
-0@@ -228,6 +228,7 @@ ifndef DEBUG endif ifeq ($(DEBUG),0) +CORE_CFLAGS += -DNDEBUG=1
[Severity: Medium]
Will this cause a regression in tools/perf/util/annotate.c? The function bfd_check_format() is called directly inside an assert() macro there.
Since this function has side effects (identifying the binary format and initializing the architecture and machine state), compiling it out will leave the bfd structure uninitialized.
Subsequent calls like bfd_get_arch(bfdf) operate on uninitialized bfdf state, leading to NULL pointer dereferences and crashes during perf annotate.
[Severity: Low]
Will this also cause build regressions due to unused variables? Variables such as old in tools/perf/util/block-range.c are initialized and assigned values but are only read inside assert() macros.
Compiling out assert() leaves these variables assigned but never read, which triggers unused-but-set build failures because the perf build uses -Werror.
[Severity: Medium]
Does compiling out assert() remove required runtime validation elsewhere? The codebase currently relies on assert() for handling expected runtime failures.
For example, in bench_sched_pipe() (tools/perf/bench/sched-pipe.c), assert(pid >= 0) checks for fork() failures. Without it, a fork failure causes the parent to execute the child's logic, reading from an empty pipe and deadlocking indefinitely.
Similarly, in tools/perf/builtin-timechart.c (assert(cursor != NULL)) and tools/perf/builtin-top.c (evlist__id2evsel), allocation and lookup failures proceed without aborting, leading to immediate NULL pointer dereferences on subsequent lines.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 27 lines · Ian Rogers
Quoted 25 lines · Florian Fainelli
This patch series contains "perf" build fixes specific to 6.1. We have seen occasional build failures in our CI looking like these:
util/parse-events-bison.c: In function 'yy_symbol_print':util/parse-events-bison.c:901: error: unterminated #if
901 | #if YYDEBUG|
util/parse-events-bison.c:1020:62: error: '_p' undeclared (first use in this function)
1020 |yy_symbol_value_print(yyo, yykind, yyvaluep, yylocationp,_parse_state, scanner);
| ^~util/parse-events-bison.c:1020:62: note: each undeclared identifier is reported only once for each function it appears inutil/parse-events-bison.c:1020:64: error: expected ')' at end of input1020 | yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, _parse_state, scanner); | ~ ^ | ) 1021 | YYFPRINTF (yyo, ")"); | util/parse-events-bison.c:1020:3: error: too few arguments to function 'yy_symbol_value_print' 1020 | yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, _parse_state, scanner); | ^~~~~~~~~~~~~~~~~~~~~ util/parse-events-bison.c:991:1: note: declared here 991 | yy_symbol_value_print (FILE *yyo, | ^~~~~~~~~~~~~~~~~~~~~
Quoted 4 lines
Quoted 1 line
which are resolved by these patches.
Lgtm, but the changes should be unnecessary as perf from Linux 7.1 should run on Linux 6.1 and with more and better features.
That's a bit harder to ship logistically for us and likely for others as well where we expect a single source to build the kernel and its companion tools.
Signature · 1 line
Florian
[email protected]
AI reviewRe: [PATCH stable 6.1 3/3] perf build: Disable fewer bison warnings
In reply to Florian FainelliThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The updated `sed` regex for parsing the bison version strictly requires three numeric components…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The updated sed regex for parsing the bison version strictly requires three numeric components, causing a shell syntax error for two-component versions. --
commit e696603d6c95e1ec405be3442c49513276f5ee86
Author: Ian Rogers <[email protected]>
perf build: Disable fewer bison warnings
This commit reduces the number of disabled bison C warnings for bison versions 3.8.2 and later. It also avoids implicit declarations of yylex by adding declarations directly in the C files.
Quoted 8 lines
tools/perf/util/Build +0
-0@@ -269,10 +269,14 @@ CFLAGS_parse-events-flex.o += $(flex_flags) CFLAGS_pmu-flex.o += $(flex_flags) CFLAGS_expr-flex.o += $(flex_flags)
tools/perf/util/Build CFLAGS_parse-events-flex.o += $(flex_flags) · line 277
Quoted 10 lines
tools/perf/util/Build +6
-4-bison_flags := -DYYENABLE_NLS=0 -BISON_GE_35 := $(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\)/\1\2/g') \>\= 35) -ifeq ($(BISON_GE_35),1) - bison_flags += -Wno-unused-parameter -Wno-nested-externs -Wno-implicit-function-declaration -Wno-switch-enum -Wno-unused-but-set-variable -Wno-unknown-warning-option +# Some newer clang and gcc version complain about this +# util/parse-events-bison.c:1317:9: error: variable 'parse_events_nerrs' set but not used [-Werror,-Wunused-but-set-variable] +# int yynerrs = 0; + +bison_flags := -DYYENABLE_NLS=0 -Wno-unused-but-set-variable +BISON_GE_382 := $(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 382)
[Severity: Low]
Will this new regex cause shell syntax errors for two-component version strings like "bison (GNU Bison) 3.8"?
If the sed pattern strictly requires three numeric components, it will fail to match a two-component string and output the unmodified string instead.
When make passes this raw string containing unescaped parentheses to expr, it will cause the shell to abort with a syntax error like 'sh: Syntax error: "(" unexpected' and fail the version check.
Quoted 5 lines
tools/perf/util/Build +2
-0+ifeq ($(BISON_GE_382),1) + bison_flags += -Wno-switch-enum else bison_flags += -w endif
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Sasha Levin
maintainerQuoted 2 lines
This patch series contains "perf" build fixes specific to 6.1. We have seen occasional build failures in our CI looking like these:
[...]
Quoted 4 lines
Ian Rogers (3):
perf build: Conditionally define NDEBUG
perf parse-events: Make YYDEBUG dependent on doing a debug build perf build: Disable fewer bison warnings
Thanks for the series.
Patch 3/3 (ddc8e4c96692) has an upstream Fixes: follow-up, 878460e8d0ff8 ("perf build: Remove -Wno-unused-but-set-variable from the flex flags when building with clang < 13.0.0"), which we need on 6.1 alongside 3/3 to keep clang<13 perf builds working. Without it, 3/3 unconditionally adds -Wno-unused-but-set-variable and drops the -Wno-unknown-warning-option guard that was previously gated by BISON_GE_35, so clang 11/12 fails under WERROR=1.
878460e8d0ff8 does not cherry-pick cleanly onto 6.1 - it references the 'version-lt3' make macro (introduced by a9b451509565d, not in 6.1) and bpf-filter-flex.o (no such file in 6.1's tools/perf). I wasn't comfortable resolving that conflict blind on a 6.1-only perf change.
Could you send a v2 6.1 series that includes 878460e8d0ff8 adapted to 6.1 (or an equivalent 6.1-specific patch that preserves the -Wno-unknown-warning-option guard for clang<13)? I'll queue the whole thing once that piece is in.
--
Thanks,
Sasha