public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 14/17] genksyms: fix syntax error for attribute after 'struct'
Date: Tue, 14 Jan 2025 00:00:52 +0900	[thread overview]
Message-ID: <20250113150253.3097820-15-masahiroy@kernel.org> (raw)
In-Reply-To: <20250113150253.3097820-1-masahiroy@kernel.org>

A longstanding issue with genksyms is that it has hidden syntax errors.

When a syntax error occurs, yyerror() is called. However,
error_with_pos() is a no-op unless the -w option is provided.

You can observe syntax errors by manually passing the -w option.

For example, with CONFIG_MODVERSIONS=y on v6.13-rc1:

    $ make -s KCFLAGS=-D__GENKSYMS__ arch/x86/kernel/cpu/mshyperv.i
    $ cat arch/x86/kernel/cpu/mshyperv.i | scripts/genksyms/genksyms -w
        [ snip ]
    ./arch/x86/include/asm/svm.h:122: syntax error

The syntax error occurs in the following code in arch/x86/include/asm/svm.h:

    struct __attribute__ ((__packed__)) vmcb_control_area {
            [ snip ]
    };

The issue arises from __attribute__ immediately after the 'struct'
keyword.

This commit allows the 'struct' keyword to be followed by attributes.

The lexer must be adjusted because dont_want_brace_phase should not be
decremented while processing attributes.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/genksyms/lex.l   |  7 ++++++-
 scripts/genksyms/parse.y | 10 +++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l
index e886133af578..a1f969dcf24f 100644
--- a/scripts/genksyms/lex.l
+++ b/scripts/genksyms/lex.l
@@ -438,7 +438,12 @@ fini:
 
   if (suppress_type_lookup > 0)
     --suppress_type_lookup;
-  if (dont_want_brace_phrase > 0)
+
+  /*
+   *  __attribute__() can be placed immediately after the 'struct' keyword.
+   *  e.g.) struct __attribute__((__packed__)) foo { ... };
+   */
+  if (token != ATTRIBUTE_PHRASE && dont_want_brace_phrase > 0)
     --dont_want_brace_phrase;
 
   yylval = &next_node->next;
diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
index 82774df50642..33639232a709 100644
--- a/scripts/genksyms/parse.y
+++ b/scripts/genksyms/parse.y
@@ -234,16 +234,16 @@ type_specifier:
 
 	/* References to s/u/e's defined elsewhere.  Rearrange things
 	   so that it is easier to expand the definition fully later.  */
-	| STRUCT_KEYW IDENT
-		{ remove_node($1); (*$2)->tag = SYM_STRUCT; $$ = $2; }
+	| STRUCT_KEYW attribute_opt IDENT
+		{ remove_node($1); (*$3)->tag = SYM_STRUCT; $$ = $3; }
 	| UNION_KEYW IDENT
 		{ remove_node($1); (*$2)->tag = SYM_UNION; $$ = $2; }
 	| ENUM_KEYW IDENT
 		{ remove_node($1); (*$2)->tag = SYM_ENUM; $$ = $2; }
 
 	/* Full definitions of an s/u/e.  Record it.  */
-	| STRUCT_KEYW IDENT class_body
-		{ record_compound($1, $2, $3, SYM_STRUCT); $$ = $3; }
+	| STRUCT_KEYW attribute_opt IDENT class_body
+		{ record_compound($1, $3, $4, SYM_STRUCT); $$ = $4; }
 	| UNION_KEYW IDENT class_body
 		{ record_compound($1, $2, $3, SYM_UNION); $$ = $3; }
 	| ENUM_KEYW IDENT enum_body
@@ -254,7 +254,7 @@ type_specifier:
 	| ENUM_KEYW enum_body
 		{ add_symbol(NULL, SYM_ENUM, NULL, 0); $$ = $2; }
 	/* Anonymous s/u definitions.  Nothing needs doing.  */
-	| STRUCT_KEYW class_body			{ $$ = $2; }
+	| STRUCT_KEYW attribute_opt class_body		{ $$ = $3; }
 	| UNION_KEYW class_body				{ $$ = $2; }
 	;
 
-- 
2.43.0


  parent reply	other threads:[~2025-01-13 15:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 15:00 [PATCH 00/17] genksyms: fix conflicts and syntax errors in parser Masahiro Yamada
2025-01-13 15:00 ` [PATCH 01/17] genksyms: rename m_abstract_declarator to abstract_declarator Masahiro Yamada
2025-01-13 15:00 ` [PATCH 02/17] genksyms: rename cvar_qualifier to type_qualifier Masahiro Yamada
2025-01-13 15:00 ` [PATCH 03/17] genksyms: reduce type_qualifier directly to decl_specifier Masahiro Yamada
2025-01-13 15:00 ` [PATCH 04/17] genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts Masahiro Yamada
2025-01-14  1:23   ` Masahiro Yamada
2025-01-13 15:00 ` [PATCH 05/17] genksyms: fix last 3 shift/reduce conflicts Masahiro Yamada
2025-01-13 15:00 ` [PATCH 06/17] genksyms: remove Makefile hack Masahiro Yamada
2025-01-13 15:00 ` [PATCH 07/17] genksyms: restrict direct-abstract-declarator to take one parameter-type-list Masahiro Yamada
2025-01-13 15:00 ` [PATCH 08/17] genksyms: restrict direct-declarator " Masahiro Yamada
2025-01-13 15:00 ` [PATCH 09/17] genksyms: record attributes consistently for init-declarator Masahiro Yamada
2025-01-13 15:00 ` [PATCH 10/17] genksyms: decouple ATTRIBUTE_PHRASE from type-qualifier Masahiro Yamada
2025-01-13 15:00 ` [PATCH 11/17] genksyms: fix syntax error for attribute before abstract_declarator Masahiro Yamada
2025-01-13 15:00 ` [PATCH 12/17] genksyms: fix syntax error for attribute before nested_declarator Masahiro Yamada
2025-01-13 15:00 ` [PATCH 13/17] genksyms: fix syntax error for attribute after abstact_declarator Masahiro Yamada
2025-01-13 15:00 ` Masahiro Yamada [this message]
2025-01-13 15:00 ` [PATCH 15/17] genksyms: fix syntax error for attribute after 'union' Masahiro Yamada
2025-01-13 15:00 ` [PATCH 16/17] genksyms: fix syntax error for builtin (u)int*x*_t types Masahiro Yamada
2025-01-13 15:00 ` [PATCH 17/17] genksyms: fix syntax error for attribute before init-declarator Masahiro Yamada
2025-01-14 20:33 ` [PATCH 00/17] genksyms: fix conflicts and syntax errors in parser Nicolas Schier

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=20250113150253.3097820-15-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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