linux/scripts/genksyms
Petr Pavlu c50a04f8f4 genksyms: Fix enum consts from a reference affecting new values
Enumeration constants read from a symbol reference file can incorrectly
affect new enumeration constants parsed from an actual input file.

Example:

 $ cat test.c
 enum { E_A, E_B, E_MAX };
 struct bar { int mem[E_MAX]; };
 int foo(struct bar *a) {}
 __GENKSYMS_EXPORT_SYMBOL(foo);

 $ cat test.c | ./scripts/genksyms/genksyms -T test.0.symtypes
 #SYMVER foo 0x070d854d

 $ cat test.0.symtypes
 E#E_MAX 2
 s#bar struct bar { int mem [ E#E_MAX ] ; }
 foo int foo ( s#bar * )

 $ cat test.c | ./scripts/genksyms/genksyms -T test.1.symtypes -r test.0.symtypes
 <stdin>:4: warning: foo: modversion changed because of changes in enum constant E_MAX
 #SYMVER foo 0x9c9dfd81

 $ cat test.1.symtypes
 E#E_MAX ( 2 ) + 3
 s#bar struct bar { int mem [ E#E_MAX ] ; }
 foo int foo ( s#bar * )

The __add_symbol() function includes logic to handle the incrementation of
enumeration values, but this code is also invoked when reading a reference
file. As a result, the variables last_enum_expr and enum_counter might be
incorrectly set after reading the reference file, which later affects
parsing of the actual input.

Fix the problem by splitting the logic for the incrementation of
enumeration values into a separate function process_enum() and call it from
__add_symbol() only when processing non-reference data.

Fixes: e37ddb8250 ("genksyms: Track changes to enum constants")
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2025-06-07 14:38:07 +09:00
..
.gitignore .gitignore: prefix local generated files with a slash 2021-05-02 00:43:35 +09:00
genksyms.c genksyms: Fix enum consts from a reference affecting new values 2025-06-07 14:38:07 +09:00
genksyms.h genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts 2025-01-18 09:11:38 +09:00
keywords.c genksyms: Handle typeof_unqual keyword and __seg_{fs,gs} qualifiers 2025-04-14 09:19:04 +02:00
lex.l genksyms: factor out APP for the ST_NORMAL state 2025-03-15 21:16:21 +09:00
Makefile genksyms: remove Makefile hack 2025-01-18 09:11:46 +09:00
parse.y genksyms: Handle typeof_unqual keyword and __seg_{fs,gs} qualifiers 2025-04-14 09:19:04 +02:00