Re: Build perf with clang, failure with libperf

From: Sedat Dilek
Date: Thu Apr 07 2022 - 13:12:39 EST


On Thu, Apr 7, 2022 at 6:25 PM Sedat Dilek <sedat.dilek@xxxxxxxxx> wrote:
>
> On Thu, Apr 7, 2022 at 5:03 PM Nathan Chancellor <nathan@xxxxxxxxxx> wrote:
> >
> > On Thu, Apr 07, 2022 at 12:27:14PM +0200, Sedat Dilek wrote:
> > > On Mon, Apr 4, 2022 at 11:53 PM Nathan Chancellor <nathan@xxxxxxxxxx> wrote:
> > > >
> > > > Hi Arnaldo,
> > > >
> > > > On Mon, Apr 04, 2022 at 05:43:11PM -0300, Arnaldo Carvalho de Melo wrote:
> > > > > Hi,
> > > > >
> > > > > Trying to apply Sedat's patch something changed in my system,
> > > > > and that patch wasn't enough, so I had to first apply this one:
> > > > >
> > > > > commit 173b552663419f40bcd3cf9df4f68285cac72727
> > > > > Author: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> > > > > Date: Mon Apr 4 17:28:48 2022 -0300
> > > > >
> > > > > tools build: Use $(shell ) instead of `` to get embedded libperl's ccopts
> > > > >
> > > > > Just like its done for ldopts and for both in tools/perf/Makefile.config.
> > > > >
> > > > > Using `` to initialize PERL_EMBED_CCOPTS somehow precludes using:
> > > > >
> > > > > $(filter-out SOMETHING_TO_FILTER,$(PERL_EMBED_CCOPTS))
> > > > >
> > > > > And we need to do it to allow for building with versions of clang where
> > > > > some gcc options selected by distros are not available.
> > > > >
> > > > > Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
> > > > > Cc: Fangrui Song <maskray@xxxxxxxxxx>
> > > > > Cc: Florian Fainelli <f.fainelli@xxxxxxxxx>
> > > > > Cc: Ian Rogers <irogers@xxxxxxxxxx>
> > > > > Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> > > > > Cc: John Keeping <john@xxxxxxxxxxxx>
> > > > > Cc: Leo Yan <leo.yan@xxxxxxxxxx>
> > > > > Cc: Michael Petlan <mpetlan@xxxxxxxxxx>
> > > > > Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> > > > > Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
> > > > > Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
> > > > > Cc: Sedat Dilek <sedat.dilek@xxxxxxxxx>
> > > > > Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> > > > >
> > > > > diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> > > > > index 1480910c792e2cb3..90774b60d31b2b8e 100644
> > > > > --- a/tools/build/feature/Makefile
> > > > > +++ b/tools/build/feature/Makefile
> > > > > @@ -217,7 +217,7 @@ strip-libs = $(filter-out -l%,$(1))
> > > > > PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
> > > > > PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
> > > > > PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
> > > > > -PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
> > > > > +PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
> > > > > FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
> > > > >
> > > > > $(OUTPUT)test-libperl.bin:
> > > > >
> > > > > ----------------------------------------------------- 8< -------------------
> > > > >
> > > > > After this I go on filtering out some of the gcc options that clang
> > > > > doesn't grok:
> > > > >
> > > > > diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> > > > > index 90774b60d31b2b8e..bbc5e263e02385ed 100644
> > > > > --- a/tools/build/feature/Makefile
> > > > > +++ b/tools/build/feature/Makefile
> > > > > @@ -215,9 +215,12 @@ grep-libs = $(filter -l%,$(1))
> > > > > strip-libs = $(filter-out -l%,$(1))
> > > > >
> > > > > PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
> > > > > +PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
> > > > > PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
> > > > > PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
> > > > > PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
> > > > > +PERL_EMBED_CCOPTS := $(filter-out -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
> > > > > +PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
> > > > > FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
> > > > >
> > > > > $(OUTPUT)test-libperl.bin:
> > > > >
> > > > > ----------------------------------------------------- 8< -------------------
> > > > >
> > > > > And then get to the problems at the end of this message, which seem
> > > > > similar to the problem described here:
> > > > >
> > > > > From Nathan Chancellor <>
> > > > > Subject [PATCH] mwifiex: Remove unnecessary braces from HostCmd_SET_SEQ_NO_BSS_INFO
> > > > >
> > > > > https://lkml.org/lkml/2020/9/1/135
> > > > >
> > > > > So perhaps in this case its better to disable that
> > > > > -Werror,-Wcompound-token-split-by-macro when building with clang?
> > > >
> > > > Yes, I think that is probably the best solution. As far as I can tell,
> > > > at least in this file and context, the warning appears harmless, as the
> > > > "create a GNU C statement expression from two different macros" is very
> > > > much intentional, based on the presence of PERL_USE_GCC_BRACE_GROUPS.
> > > > The warning is fixed in upstream Perl by just avoiding creating GNU C
> > > > statement expressions using STMT_START and STMT_END:
> > > >
> > > > https://github.com/Perl/perl5/issues/18780
> > > > https://github.com/Perl/perl5/pull/18984
> > > >
> > > > If I am reading the source code correctly, an alternative to disabling
> > > > the warning would be specifying -DPERL_GCC_BRACE_GROUPS_FORBIDDEN but it
> > > > seems like that might end up impacting more than just this site,
> > > > according to the issue discussion above.
> > > >
> > >
> > > Thanks for the pointer Nathan.
> > >
> > > As said I hit the problem with Debian's perl v5.34.
> > >
> > > Checking perl5 Git reveals:
> > >
> > > "skip using gcc brace groups for STMT_START/END"
> > > https://github.com/Perl/perl5/commit/7169efc77525df70484a824bff4ceebd1fafc760
> >
> > GitHub says this is in 5.35.2, so it would make sense that 5.34 still
> > shows the issue.
> >
> > > "Partially Revert "skip using gcc brace groups for STMT_START/END""
> > > https://github.com/Perl/perl5/commit/e08ee3cb66f362c4901846a46014cfdfcd60326c
> > >
> > > Perl v5.34.x seems not to have these changes:
> > > https://github.com/Perl/perl5/compare/v5.34.0...v5.34.1
> > >

To summarize the diff between those 2 changes is related to perl.h only.

# git diff /usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h.orig
/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h
diff --git a/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h.orig
b/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h
index 17a21a1c4..bd575fe08 100644
--- a/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h.orig
+++ b/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h
@@ -733,13 +733,8 @@ Example usage:
Trying to select a version that gives no warnings...
*/
#if !(defined(STMT_START) && defined(STMT_END))
-# ifdef PERL_USE_GCC_BRACE_GROUPS
-# define STMT_START (void)( /* gcc supports "({ STATEMENTS; })" */
-# define STMT_END )
-# else
# define STMT_START do
# define STMT_END while (0)
-# endif
#endif

#ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */

With this applied plus removing -Wno-compound-token-split-by-macro
from ACME's patchset ...

$ git log --oneline -2
bccc88d26f1f (HEAD -> 5.17.1-6-amd64-clang14-lto) tools build: Filter
out options and warnings not supported by clang
19b1b5c6614c tools build: Use $(shell ) instead of `` to get embedded
libperl's ccopts

$ git diff tools/
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index de66e1cc0734..7e3854a07643 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -224,7 +224,6 @@ ifeq ($(CC_NO_CLANG), 0)
PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects,
$(PERL_EMBED_CCOPTS))
PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
- FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro
endif

$(OUTPUT)test-libperl.bin:
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 312a7a5906ee..913bf509bd17 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -790,9 +790,6 @@ else
LDFLAGS += $(PERL_EMBED_LDFLAGS)
EXTLIBS += $(PERL_EMBED_LIBADD)
CFLAGS += -DHAVE_LIBPERL_SUPPORT
- ifeq ($(CC_NO_CLANG), 0)
- CFLAGS += -Wno-compound-token-split-by-macro
- endif
$(call detected,CONFIG_LIBPERL)
endif
endif

...I am able to build successfully with Debian's LLVM-14 and perl-5.34.

Both diffs are attached as Gmail might truncate the formatting.

Might be worth writing a Debian bug-report.

- Sedat -
diff --git a/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h.orig b/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h
index 17a21a1c4..bd575fe08 100644
--- a/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h.orig
+++ b/usr/lib/x86_64-linux-gnu/perl/5.34.0/CORE/perl.h
@@ -733,13 +733,8 @@ Example usage:
Trying to select a version that gives no warnings...
*/
#if !(defined(STMT_START) && defined(STMT_END))
-# ifdef PERL_USE_GCC_BRACE_GROUPS
-# define STMT_START (void)( /* gcc supports "({ STATEMENTS; })" */
-# define STMT_END )
-# else
# define STMT_START do
# define STMT_END while (0)
-# endif
#endif

#ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index de66e1cc0734..7e3854a07643 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -224,7 +224,6 @@ ifeq ($(CC_NO_CLANG), 0)
PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
- FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro
endif

$(OUTPUT)test-libperl.bin:
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 312a7a5906ee..913bf509bd17 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -790,9 +790,6 @@ else
LDFLAGS += $(PERL_EMBED_LDFLAGS)
EXTLIBS += $(PERL_EMBED_LIBADD)
CFLAGS += -DHAVE_LIBPERL_SUPPORT
- ifeq ($(CC_NO_CLANG), 0)
- CFLAGS += -Wno-compound-token-split-by-macro
- endif
$(call detected,CONFIG_LIBPERL)
endif
endif