Skip to content

Commit c50a04f

Browse files
petrpavlumasahir0y
authored andcommitted
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: e37ddb8 ("genksyms: Track changes to enum constants") Signed-off-by: Petr Pavlu <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent e21efe8 commit c50a04f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

scripts/genksyms/genksyms.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,9 @@ static int is_unknown_symbol(struct symbol *sym)
181181
strcmp(defn->string, "{") == 0);
182182
}
183183

184-
static struct symbol *__add_symbol(const char *name, enum symbol_type type,
185-
struct string_list *defn, int is_extern,
186-
int is_reference)
184+
static struct string_list *process_enum(const char *name, enum symbol_type type,
185+
struct string_list *defn)
187186
{
188-
unsigned long h;
189-
struct symbol *sym;
190-
enum symbol_status status = STATUS_UNCHANGED;
191187
/* The parser adds symbols in the order their declaration completes,
192188
* so it is safe to store the value of the previous enum constant in
193189
* a static variable.
@@ -216,7 +212,7 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
216212
defn = mk_node(buf);
217213
}
218214
}
219-
} else if (type == SYM_ENUM) {
215+
} else {
220216
free_list(last_enum_expr, NULL);
221217
last_enum_expr = NULL;
222218
enum_counter = 0;
@@ -225,6 +221,23 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
225221
return NULL;
226222
}
227223

224+
return defn;
225+
}
226+
227+
static struct symbol *__add_symbol(const char *name, enum symbol_type type,
228+
struct string_list *defn, int is_extern,
229+
int is_reference)
230+
{
231+
unsigned long h;
232+
struct symbol *sym;
233+
enum symbol_status status = STATUS_UNCHANGED;
234+
235+
if ((type == SYM_ENUM_CONST || type == SYM_ENUM) && !is_reference) {
236+
defn = process_enum(name, type, defn);
237+
if (defn == NULL)
238+
return NULL;
239+
}
240+
228241
h = crc32(name);
229242
hash_for_each_possible(symbol_hashtable, sym, hnode, h) {
230243
if (map_to_ns(sym->type) != map_to_ns(type) ||

0 commit comments

Comments
 (0)