Skip to content

Commit 2966b66

Browse files
committed
genksyms: fix syntax error for attribute before abstract_declarator
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__ init/main.i $ cat init/main.i | scripts/genksyms/genksyms -w [ snip ] ./include/linux/efi.h:1225: syntax error The syntax error occurs in the following code in include/linux/efi.h: efi_status_t efi_call_acpi_prm_handler(efi_status_t (__efiapi *handler_addr)(u64, void *), u64 param_buffer_addr, void *context); The issue arises from __efiapi, which is defined as either __attribute__((ms_abi)) or __attribute__((regparm(0))). This commit allows abstract_declarator to be prefixed with attributes. To avoid conflicts, I tweaked the rule for decl_specifier_seq. Due to this change, a standalone attribute cannot become decl_specifier_seq. Otherwise, I do not know how to resolve the conflicts. The following code, which was previously accepted by genksyms, will now result in a syntax error: void my_func(__attribute__((unused))x); I do not think it is a big deal because GCC also fails to parse it. $ echo 'void my_func(__attribute__((unused))x);' | gcc -c -x c - <stdin>:1:37: error: unknown type name 'x' Signed-off-by: Masahiro Yamada <[email protected]> Acked-by: Nicolas Schier <[email protected]>
1 parent ec28bff commit 2966b66

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scripts/genksyms/parse.y

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ decl_specifier_seq_opt:
203203
;
204204

205205
decl_specifier_seq:
206-
decl_specifier { decl_spec = *$1; }
206+
attribute_opt decl_specifier { decl_spec = *$2; }
207207
| decl_specifier_seq decl_specifier { decl_spec = *$2; }
208+
| decl_specifier_seq ATTRIBUTE_PHRASE { decl_spec = *$2; }
208209
;
209210

210211
decl_specifier:
@@ -216,7 +217,6 @@ decl_specifier:
216217
}
217218
| type_specifier { dont_want_type_specifier = true; $$ = $1; }
218219
| type_qualifier
219-
| ATTRIBUTE_PHRASE
220220
;
221221

222222
storage_class_specifier:
@@ -406,8 +406,8 @@ direct_abstract_declarator1:
406406
{ $$ = $4; }
407407
| direct_abstract_declarator1 BRACKET_PHRASE
408408
{ $$ = $2; }
409-
| open_paren abstract_declarator ')'
410-
{ $$ = $3; }
409+
| open_paren attribute_opt abstract_declarator ')'
410+
{ $$ = $4; }
411411
| open_paren error ')'
412412
{ $$ = $3; }
413413
| BRACKET_PHRASE

0 commit comments

Comments
 (0)