linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Ian Rogers <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	"Justin M. Forbes" <jforbes@fedoraproject.org>
Subject: Re: [PATCH] perf: Avoid implicit function declarations in lexer/parse interface
Date: Tue, 25 Apr 2023 19:10:53 +0200	[thread overview]
Message-ID: <87wn1z7uqq.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CAP-5=fWGUcCrq0rHc0YRGWsgyXZDEAo03MaXXbR46Q7KZ3=-qQ@mail.gmail.com> (Ian Rogers's message of "Tue, 25 Apr 2023 08:18:23 -0700")

* Ian Rogers:

> On Tue, Apr 25, 2023 at 7:29 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> In future compilers, -Wno-implicit-function-declaration may not bring
>> back support for implicit function declarations, a feature that was
>> removed from the C language in C99.  Instead, declare the yylex
>> functions using the appropriate argument types.  The solution chosen
>> here is not ideal because the prototypes are not verified against
>> the function implementations, but the way bison and flex generate
>> code make it difficult to share the prototype.
>>
>> This change should prevent build failures with future compilers which
>> no longer support implicit function declarations by default.
>>
>> Signed-off-by: Florian Weimer <fweimer@redhat.com>
>
> This seems non-standard. Isn't the issue that we're not including the
> appropriate <...>-flex.h ? The use of yylex for the function name
> obfuscates this a bit. For example:
>
> pmu-flex.h:
> ...
> #ifdef yylex
> #define perf_pmu_lex_ALREADY_DEFINED
> #else
> #define yylex perf_pmu_lex
> #endif
> ...
> /* Default declaration of generated scanner - a define so the user can
> * easily add parameters.
> */
> #ifndef YY_DECL
> #define YY_DECL_IS_OURS 1
>
> extern int yylex \
>               (YYSTYPE * yylval_param , yyscan_t yyscanner);
>
> #define YY_DECL int yylex \
>               (YYSTYPE * yylval_param , yyscan_t yyscanner)
> #endif /* !YY_DECL */
> ...

I can try to get this to work.  We have to change tools/perf/util/Build
quite extensively because

$(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-flex.h: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
	$(call rule_mkdir)
	$(Q)$(call echo-cmd,flex)$(FLEX) -o $(OUTPUT)util/parse-events-flex.c \
		--header-file=$(OUTPUT)util/parse-events-flex.h $(PARSER_DEBUG_FLEX) $<

defines two independent rules which may run in parallel and clobber each
other's two output output files.  This becomes an issue once we add the
required

$(OUTPUT)parse-events-bison.o : $(OUTPUT)parse-events-flex.h

so that flex runs before compiling the bison output file, and the header
is actually available for inclusion when it's required.  Maybe it's
possible to avoid the issue by depending on
$(OUTPUT)parse-events-flex.c.

Anyway, the next problem is that if we include expr-flex.h too early,

diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y
index 635e562350c5..41c36dc3cf63 100644
--- a/tools/perf/util/expr.y
+++ b/tools/perf/util/expr.y
@@ -7,6 +7,7 @@
 #include "util/debug.h"
 #define IN_EXPR_Y 1
 #include "expr.h"
+#include "expr-flex.h"
 %}
 
 %define api.pure full

we get this:

In file included from util/expr.y:10:                                           util/expr-flex.h:496:1: error: unknown type name 'YYSTYPE'            
  496 | 
      | ^                               
util/expr-flex.h:498:19: error: unknown type name 'YYSTYPE'
  498 | 
      |                   ^      
util/expr-flex.h:546:17: error: unknown type name 'YYSTYPE'
  546 | extern int yylex \
      |                 ^~     
util/expr-bison.c: In function 'expr_parse':
util/expr-bison.c:69:25: error: implicit declaration of function 'expr_lex'
   69 | #define yylex           expr_lex 
      |                         ^~~~~~~~ 
util/expr-bison.c:1191:16: note: in expansion of macro 'yylex'
 1191 |       yychar = yylex (&yylval, scanner);
      |                ^~~~~

But expr.y seems to be the only one suffering from this, and moving the
#include a bit later appears to fix it:

diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y
index 635e562350c5..99581193ca4c 100644
--- a/tools/perf/util/expr.y
+++ b/tools/perf/util/expr.y
@@ -53,6 +53,8 @@
 %destructor { ids__free($$.ids); } <ids>
 
 %{
+#include "expr-flex.h"
+
 static void expr_error(double *final_val __maybe_unused,
                       struct expr_parse_ctx *ctx __maybe_unused,
                       bool compute_ids __maybe_unused,

It works with my bison/flex combination at least, but as a change, it's
going to be a little bit risiker (both the Makefile part, and the
#include placement and general header compatibility).

I'm going to send a v2, then you can look at both and see which one you
prefer.

Thanks,
Florian


      reply	other threads:[~2023-04-25 17:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <877cu0827a.fsf@oldenburg.str.redhat.com>
2023-04-25 15:18 ` [PATCH] perf: Avoid implicit function declarations in lexer/parse interface Ian Rogers
2023-04-25 17:10   ` Florian Weimer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wn1z7uqq.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jforbes@fedoraproject.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).