Skip to content

Commit 82db1c2

Browse files
committed
genksyms: fix syntax error for attribute after 'struct'
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> Acked-by: Nicolas Schier <n.schier@avm.de>
1 parent 2ac068c commit 82db1c2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

scripts/genksyms/lex.l

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,12 @@ fini:
438438
439439
if (suppress_type_lookup > 0)
440440
--suppress_type_lookup;
441-
if (dont_want_brace_phrase > 0)
441+
442+
/*
443+
* __attribute__() can be placed immediately after the 'struct' keyword.
444+
* e.g.) struct __attribute__((__packed__)) foo { ... };
445+
*/
446+
if (token != ATTRIBUTE_PHRASE && dont_want_brace_phrase > 0)
442447
--dont_want_brace_phrase;
443448
444449
yylval = &next_node->next;

scripts/genksyms/parse.y

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,16 @@ type_specifier:
234234

235235
/* References to s/u/e's defined elsewhere. Rearrange things
236236
so that it is easier to expand the definition fully later. */
237-
| STRUCT_KEYW IDENT
238-
{ remove_node($1); (*$2)->tag = SYM_STRUCT; $$ = $2; }
237+
| STRUCT_KEYW attribute_opt IDENT
238+
{ remove_node($1); (*$3)->tag = SYM_STRUCT; $$ = $3; }
239239
| UNION_KEYW IDENT
240240
{ remove_node($1); (*$2)->tag = SYM_UNION; $$ = $2; }
241241
| ENUM_KEYW IDENT
242242
{ remove_node($1); (*$2)->tag = SYM_ENUM; $$ = $2; }
243243

244244
/* Full definitions of an s/u/e. Record it. */
245-
| STRUCT_KEYW IDENT class_body
246-
{ record_compound($1, $2, $3, SYM_STRUCT); $$ = $3; }
245+
| STRUCT_KEYW attribute_opt IDENT class_body
246+
{ record_compound($1, $3, $4, SYM_STRUCT); $$ = $4; }
247247
| UNION_KEYW IDENT class_body
248248
{ record_compound($1, $2, $3, SYM_UNION); $$ = $3; }
249249
| ENUM_KEYW IDENT enum_body
@@ -254,7 +254,7 @@ type_specifier:
254254
| ENUM_KEYW enum_body
255255
{ add_symbol(NULL, SYM_ENUM, NULL, 0); $$ = $2; }
256256
/* Anonymous s/u definitions. Nothing needs doing. */
257-
| STRUCT_KEYW class_body { $$ = $2; }
257+
| STRUCT_KEYW attribute_opt class_body { $$ = $3; }
258258
| UNION_KEYW class_body { $$ = $2; }
259259
;
260260

0 commit comments

Comments
 (0)