Re: [PATCH v1 4/6] perf build: Disable fewer flex warnings

From: Arnaldo Carvalho de Melo
Date: Mon Jul 31 2023 - 17:16:47 EST


Em Fri, Jul 28, 2023 at 12:05:56PM -0700, Ian Rogers escreveu:
> On Fri, Jul 28, 2023, 11:43 AM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> > > I haven't checked, lemme do it now.

> > It comes directly from flex's m4 files:

> > https://github.com/westes/flex/blob/master/src/c99-flex.skl#L2044

> > So I'll keep the -Wno-misleading-indentation, ok?

> Makes sense, yes.

continuing, changed the version check to:

commit f4da4419574536691c6b7843b6c48a3f97240404
Author: Ian Rogers <irogers@xxxxxxxxxx>
Date: Thu Jul 27 23:49:15 2023 -0700

perf build: Disable fewer flex warnings

If flex is version 2.6.4, reduce the number of flex C warnings
disabled. Earlier flex versions have all C warnings disabled.

Committer notes:

Added this to the list of ignored warnings to get it building on
a Fedora 36 machine with flex 2.6.4:

-Wno-misleading-indentation

Noticed when building with:

$ make LLVM=1 -C tools/perf NO_BPF_SKEL=1 DEBUG=1

Take two:

We can't just try to canonicalize flex versions by just removing the
dots, as we end up with:

2.6.4 >= 2.5.37

becoming:

264 >= 2537

Failing the build on flex 2.5.37, so instead use the back to the past
added $(call version_ge3,2.6.4,$(FLEX_VERSION)) variant to check for
that.

Making sure $(FLEX_VERSION) keeps the dots as we may want to use 'sort
-V' or something nicer when available everywhere.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: Andrii Nakryiko <andrii@xxxxxxxxxx>
Cc: Eduard Zingerman <eddyz87@xxxxxxxxx>
Cc: Gaosheng Cui <cuigaosheng1@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Rob Herring <robh@xxxxxxxxxx>
Cc: Tom Rix <trix@xxxxxxxxxx>
Cc: bpf@xxxxxxxxxxxxxxx
Cc: llvm@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/r/20230728064917.767761-5-irogers@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index bb08149179e405ac..ae91e2786f1a4f55 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -1,3 +1,5 @@
+include $(srctree)/tools/scripts/utilities.mak
+
perf-y += arm64-frame-pointer-unwind-support.o
perf-y += addr_location.o
perf-y += annotate.o
@@ -279,13 +281,11 @@ $(OUTPUT)util/bpf-filter-bison.c $(OUTPUT)util/bpf-filter-bison.h: util/bpf-filt
$(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) $(BISON_FILE_PREFIX_MAP) \
-o $(OUTPUT)util/bpf-filter-bison.c -p perf_bpf_filter_

-FLEX_GE_26 := $(shell expr $(shell $(FLEX) --version | sed -e 's/flex \([0-9]\+\).\([0-9]\+\)/\1\2/g') \>\= 26)
-ifeq ($(FLEX_GE_26),1)
- flex_flags := -Wno-switch-enum -Wno-switch-default -Wno-unused-function -Wno-redundant-decls -Wno-sign-compare -Wno-unused-parameter -Wno-missing-prototypes -Wno-missing-declarations
- CC_HASNT_MISLEADING_INDENTATION := $(shell echo "int main(void) { return 0 }" | $(CC) -Werror -Wno-misleading-indentation -o /dev/null -xc - 2>&1 | grep -q -- -Wno-misleading-indentation ; echo $$?)
- ifeq ($(CC_HASNT_MISLEADING_INDENTATION), 1)
- flex_flags += -Wno-misleading-indentation
- endif
+FLEX_VERSION := $(shell $(FLEX) --version | cut -d' ' -f2)
+
+FLEX_GE_264 := $(call version_ge3,2.6.4,$(FLEX_VERSION))
+ifeq ($(FLEX_GE_264),1)
+ flex_flags := -Wno-redundant-decls -Wno-switch-default -Wno-unused-function -Wno-misleading-indentation
else
flex_flags := -w
endif

--------------------------------------------------------------------------

with version_ge3 being:

commit aa9e655a4d755c3c75eb3d200d87a3b695f602cf
Author: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Date: Mon Jul 31 16:19:21 2023 -0300

tools build: Add a 3-component greater or equal version comparator

The next cset needs to compare if a flex version is greater or equal
than another, but since there is no canonical, generally available way
to compare versions in the command line (sort -V, yeah, but...), just
use awk to canonicalize the versions like is also done in
scripts/rust_is_available.sh.

Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Ian Rogers <irogers@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

diff --git a/tools/scripts/utilities.mak b/tools/scripts/utilities.mak
index 172e47273b5d995a..568a6541ecf98075 100644
--- a/tools/scripts/utilities.mak
+++ b/tools/scripts/utilities.mak
@@ -177,3 +177,13 @@ $(if $($(1)),$(call _ge_attempt,$($(1)),$(1)),$(call _ge_attempt,$(2)))
endef
_ge_attempt = $(or $(get-executable),$(call _gea_err,$(2)))
_gea_err = $(if $(1),$(error Please set '$(1)' appropriately))
+
+# version-ge3
+#
+# Usage $(call version_ge3,2.6.4,$(FLEX_VERSION))
+#
+# To compare if a 3 component version is greater or equal to anoter, first use
+# was to check the flex version to see if we can use compiler warnings as
+# errors for one of the cases flex generates code C compilers complains about.
+#
+version_ge3 = $(shell awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) >= (10000000 * $$4 + 10000 * $$5 + $$6)) }' <<< "$(1).$(2)")