Skip to content

Commit dc53324

Browse files
jbeulichtorvalds
authored andcommitted
genksyms: fix typeof() handling
Recent increased use of typeof() throughout the tree resulted in a number of symbols (25 in a typical distro config of ours) not getting a proper CRC calculated for them anymore, due to the parser in genksyms not coping with several of these uses (interestingly in the majority of [if not all] cases the problem is due to the use of typeof() in code preceding a certain export, not in the declaration/definition of the exported function/object itself; I wasn't able to find a way to address this more general parser shortcoming). The use of parameter_declaration is a little more relaxed than would be ideal (permitting not just a bare type specification, but also one with identifier), but since the same code is being passed through an actual compiler, there's no apparent risk of allowing through any broken code. Otoh using parameter_declaration instead of the ad hoc "decl_specifier_seq '*'" / "decl_specifier_seq" pair allows all types to be handled rather than just plain ones and pointers to plain ones. Signed-off-by: Jan Beulich <[email protected]> Cc: Michal Marek <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d507816 commit dc53324

File tree

7 files changed

+498
-384
lines changed

7 files changed

+498
-384
lines changed

scripts/genksyms/keywords.gperf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ __inline, INLINE_KEYW
2323
__inline__, INLINE_KEYW
2424
__signed, SIGNED_KEYW
2525
__signed__, SIGNED_KEYW
26+
__typeof, TYPEOF_KEYW
27+
__typeof__, TYPEOF_KEYW
2628
__volatile, VOLATILE_KEYW
2729
__volatile__, VOLATILE_KEYW
2830
# According to rth, c99 defines _Bool, __restrict, __restrict__, restrict. KAO
@@ -51,9 +53,8 @@ signed, SIGNED_KEYW
5153
static, STATIC_KEYW
5254
struct, STRUCT_KEYW
5355
typedef, TYPEDEF_KEYW
56+
typeof, TYPEOF_KEYW
5457
union, UNION_KEYW
5558
unsigned, UNSIGNED_KEYW
5659
void, VOID_KEYW
5760
volatile, VOLATILE_KEYW
58-
typeof, TYPEOF_KEYW
59-
__typeof__, TYPEOF_KEYW

scripts/genksyms/keywords.hash.c_shipped

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct resword;
3434
static const struct resword *is_reserved_word(register const char *str, register unsigned int len);
3535
#line 8 "scripts/genksyms/keywords.gperf"
3636
struct resword { const char *name; int token; };
37-
/* maximum key range = 64, duplicates = 0 */
37+
/* maximum key range = 98, duplicates = 0 */
3838

3939
#ifdef __GNUC__
4040
__inline
@@ -48,32 +48,32 @@ is_reserved_hash (register const char *str, register unsigned int len)
4848
{
4949
static const unsigned char asso_values[] =
5050
{
51-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
52-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
53-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
54-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
55-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
56-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
57-
67, 67, 67, 67, 67, 67, 67, 67, 67, 0,
58-
67, 67, 67, 67, 67, 67, 15, 67, 67, 67,
59-
0, 67, 67, 67, 67, 67, 67, 67, 67, 67,
60-
67, 67, 67, 67, 67, 0, 67, 0, 67, 5,
61-
25, 20, 15, 30, 67, 15, 67, 67, 10, 0,
62-
10, 40, 20, 67, 10, 5, 0, 10, 15, 67,
63-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
64-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
65-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
66-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
67-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
68-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
69-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
70-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
71-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
72-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
73-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
74-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
75-
67, 67, 67, 67, 67, 67, 67, 67, 67, 67,
76-
67, 67, 67, 67, 67, 67
51+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
52+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
53+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
54+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
55+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
56+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
57+
101, 101, 101, 101, 101, 101, 101, 101, 101, 0,
58+
101, 101, 101, 101, 101, 101, 15, 101, 101, 101,
59+
0, 101, 101, 101, 101, 101, 101, 101, 101, 101,
60+
101, 101, 101, 101, 101, 0, 101, 0, 101, 5,
61+
25, 20, 55, 30, 101, 15, 101, 101, 10, 0,
62+
10, 40, 10, 101, 10, 5, 0, 10, 15, 101,
63+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
64+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
65+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
66+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
67+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
68+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
69+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
70+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
71+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
72+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
73+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
74+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
75+
101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
76+
101, 101, 101, 101, 101, 101
7777
};
7878
return len + asso_values[(unsigned char)str[2]] + asso_values[(unsigned char)str[0]] + asso_values[(unsigned char)str[len - 1]];
7979
}
@@ -89,17 +89,17 @@ is_reserved_word (register const char *str, register unsigned int len)
8989
{
9090
enum
9191
{
92-
TOTAL_KEYWORDS = 45,
92+
TOTAL_KEYWORDS = 46,
9393
MIN_WORD_LENGTH = 3,
9494
MAX_WORD_LENGTH = 24,
9595
MIN_HASH_VALUE = 3,
96-
MAX_HASH_VALUE = 66
96+
MAX_HASH_VALUE = 100
9797
};
9898

9999
static const struct resword wordlist[] =
100100
{
101101
{""}, {""}, {""},
102-
#line 33 "scripts/genksyms/keywords.gperf"
102+
#line 35 "scripts/genksyms/keywords.gperf"
103103
{"asm", ASM_KEYW},
104104
{""},
105105
#line 15 "scripts/genksyms/keywords.gperf"
@@ -108,7 +108,7 @@ is_reserved_word (register const char *str, register unsigned int len)
108108
#line 16 "scripts/genksyms/keywords.gperf"
109109
{"__asm__", ASM_KEYW},
110110
{""}, {""},
111-
#line 59 "scripts/genksyms/keywords.gperf"
111+
#line 27 "scripts/genksyms/keywords.gperf"
112112
{"__typeof__", TYPEOF_KEYW},
113113
{""},
114114
#line 19 "scripts/genksyms/keywords.gperf"
@@ -119,31 +119,31 @@ is_reserved_word (register const char *str, register unsigned int len)
119119
{"__const__", CONST_KEYW},
120120
#line 25 "scripts/genksyms/keywords.gperf"
121121
{"__signed__", SIGNED_KEYW},
122-
#line 51 "scripts/genksyms/keywords.gperf"
122+
#line 53 "scripts/genksyms/keywords.gperf"
123123
{"static", STATIC_KEYW},
124124
{""},
125-
#line 46 "scripts/genksyms/keywords.gperf"
125+
#line 48 "scripts/genksyms/keywords.gperf"
126126
{"int", INT_KEYW},
127-
#line 39 "scripts/genksyms/keywords.gperf"
127+
#line 41 "scripts/genksyms/keywords.gperf"
128128
{"char", CHAR_KEYW},
129-
#line 40 "scripts/genksyms/keywords.gperf"
129+
#line 42 "scripts/genksyms/keywords.gperf"
130130
{"const", CONST_KEYW},
131-
#line 52 "scripts/genksyms/keywords.gperf"
131+
#line 54 "scripts/genksyms/keywords.gperf"
132132
{"struct", STRUCT_KEYW},
133-
#line 31 "scripts/genksyms/keywords.gperf"
133+
#line 33 "scripts/genksyms/keywords.gperf"
134134
{"__restrict__", RESTRICT_KEYW},
135-
#line 32 "scripts/genksyms/keywords.gperf"
135+
#line 34 "scripts/genksyms/keywords.gperf"
136136
{"restrict", RESTRICT_KEYW},
137137
#line 12 "scripts/genksyms/keywords.gperf"
138138
{"EXPORT_SYMBOL_GPL_FUTURE", EXPORT_SYMBOL_KEYW},
139139
#line 23 "scripts/genksyms/keywords.gperf"
140140
{"__inline__", INLINE_KEYW},
141141
{""},
142-
#line 27 "scripts/genksyms/keywords.gperf"
142+
#line 29 "scripts/genksyms/keywords.gperf"
143143
{"__volatile__", VOLATILE_KEYW},
144144
#line 10 "scripts/genksyms/keywords.gperf"
145145
{"EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW},
146-
#line 30 "scripts/genksyms/keywords.gperf"
146+
#line 32 "scripts/genksyms/keywords.gperf"
147147
{"_restrict", RESTRICT_KEYW},
148148
{""},
149149
#line 17 "scripts/genksyms/keywords.gperf"
@@ -152,56 +152,65 @@ is_reserved_word (register const char *str, register unsigned int len)
152152
{"EXPORT_SYMBOL_GPL", EXPORT_SYMBOL_KEYW},
153153
#line 21 "scripts/genksyms/keywords.gperf"
154154
{"__extension__", EXTENSION_KEYW},
155-
#line 42 "scripts/genksyms/keywords.gperf"
155+
#line 44 "scripts/genksyms/keywords.gperf"
156156
{"enum", ENUM_KEYW},
157157
#line 13 "scripts/genksyms/keywords.gperf"
158158
{"EXPORT_UNUSED_SYMBOL", EXPORT_SYMBOL_KEYW},
159-
#line 43 "scripts/genksyms/keywords.gperf"
159+
#line 45 "scripts/genksyms/keywords.gperf"
160160
{"extern", EXTERN_KEYW},
161161
{""},
162162
#line 24 "scripts/genksyms/keywords.gperf"
163163
{"__signed", SIGNED_KEYW},
164164
#line 14 "scripts/genksyms/keywords.gperf"
165165
{"EXPORT_UNUSED_SYMBOL_GPL", EXPORT_SYMBOL_KEYW},
166-
#line 54 "scripts/genksyms/keywords.gperf"
166+
#line 57 "scripts/genksyms/keywords.gperf"
167167
{"union", UNION_KEYW},
168-
#line 58 "scripts/genksyms/keywords.gperf"
169-
{"typeof", TYPEOF_KEYW},
170-
#line 53 "scripts/genksyms/keywords.gperf"
171-
{"typedef", TYPEDEF_KEYW},
168+
{""}, {""},
172169
#line 22 "scripts/genksyms/keywords.gperf"
173170
{"__inline", INLINE_KEYW},
174-
#line 38 "scripts/genksyms/keywords.gperf"
171+
#line 40 "scripts/genksyms/keywords.gperf"
175172
{"auto", AUTO_KEYW},
176-
#line 26 "scripts/genksyms/keywords.gperf"
173+
#line 28 "scripts/genksyms/keywords.gperf"
177174
{"__volatile", VOLATILE_KEYW},
178175
{""}, {""},
179-
#line 55 "scripts/genksyms/keywords.gperf"
176+
#line 58 "scripts/genksyms/keywords.gperf"
180177
{"unsigned", UNSIGNED_KEYW},
181178
{""},
182-
#line 49 "scripts/genksyms/keywords.gperf"
179+
#line 51 "scripts/genksyms/keywords.gperf"
183180
{"short", SHORT_KEYW},
184-
#line 45 "scripts/genksyms/keywords.gperf"
181+
#line 47 "scripts/genksyms/keywords.gperf"
185182
{"inline", INLINE_KEYW},
186183
{""},
187-
#line 57 "scripts/genksyms/keywords.gperf"
184+
#line 60 "scripts/genksyms/keywords.gperf"
188185
{"volatile", VOLATILE_KEYW},
189-
#line 47 "scripts/genksyms/keywords.gperf"
186+
#line 49 "scripts/genksyms/keywords.gperf"
190187
{"long", LONG_KEYW},
191-
#line 29 "scripts/genksyms/keywords.gperf"
188+
#line 31 "scripts/genksyms/keywords.gperf"
192189
{"_Bool", BOOL_KEYW},
193190
{""}, {""},
194-
#line 48 "scripts/genksyms/keywords.gperf"
191+
#line 50 "scripts/genksyms/keywords.gperf"
195192
{"register", REGISTER_KEYW},
196-
#line 56 "scripts/genksyms/keywords.gperf"
193+
#line 59 "scripts/genksyms/keywords.gperf"
197194
{"void", VOID_KEYW},
198-
#line 44 "scripts/genksyms/keywords.gperf"
199-
{"float", FLOAT_KEYW},
200-
#line 41 "scripts/genksyms/keywords.gperf"
195+
{""},
196+
#line 43 "scripts/genksyms/keywords.gperf"
201197
{"double", DOUBLE_KEYW},
198+
{""},
199+
#line 26 "scripts/genksyms/keywords.gperf"
200+
{"__typeof", TYPEOF_KEYW},
201+
{""}, {""},
202+
#line 52 "scripts/genksyms/keywords.gperf"
203+
{"signed", SIGNED_KEYW},
202204
{""}, {""}, {""}, {""},
203-
#line 50 "scripts/genksyms/keywords.gperf"
204-
{"signed", SIGNED_KEYW}
205+
#line 56 "scripts/genksyms/keywords.gperf"
206+
{"typeof", TYPEOF_KEYW},
207+
#line 55 "scripts/genksyms/keywords.gperf"
208+
{"typedef", TYPEDEF_KEYW},
209+
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
210+
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
211+
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
212+
#line 46 "scripts/genksyms/keywords.gperf"
213+
{"float", FLOAT_KEYW}
205214
};
206215

207216
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)

scripts/genksyms/lex.l

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ int
129129
yylex(void)
130130
{
131131
static enum {
132-
ST_NOTSTARTED, ST_NORMAL, ST_ATTRIBUTE, ST_ASM, ST_BRACKET, ST_BRACE,
133-
ST_EXPRESSION, ST_TABLE_1, ST_TABLE_2, ST_TABLE_3, ST_TABLE_4,
132+
ST_NOTSTARTED, ST_NORMAL, ST_ATTRIBUTE, ST_ASM, ST_TYPEOF, ST_TYPEOF_1,
133+
ST_BRACKET, ST_BRACE, ST_EXPRESSION,
134+
ST_TABLE_1, ST_TABLE_2, ST_TABLE_3, ST_TABLE_4,
134135
ST_TABLE_5, ST_TABLE_6
135136
} lexstate = ST_NOTSTARTED;
136137
@@ -198,6 +199,10 @@ repeat:
198199
lexstate = ST_ASM;
199200
count = 0;
200201
goto repeat;
202+
case TYPEOF_KEYW:
203+
lexstate = ST_TYPEOF;
204+
count = 0;
205+
goto repeat;
201206
202207
case STRUCT_KEYW:
203208
case UNION_KEYW:
@@ -284,6 +289,48 @@ repeat:
284289
}
285290
break;
286291
292+
case ST_TYPEOF:
293+
switch (token)
294+
{
295+
case '(':
296+
if ( ++count == 1 )
297+
lexstate = ST_TYPEOF_1;
298+
else
299+
APP;
300+
goto repeat;
301+
case ')':
302+
APP;
303+
if (--count == 0)
304+
{
305+
lexstate = ST_NORMAL;
306+
token = TYPEOF_PHRASE;
307+
break;
308+
}
309+
goto repeat;
310+
default:
311+
APP;
312+
goto repeat;
313+
}
314+
break;
315+
316+
case ST_TYPEOF_1:
317+
if (token == IDENT)
318+
{
319+
if (is_reserved_word(yytext, yyleng)
320+
|| find_symbol(yytext, SYM_TYPEDEF, 1))
321+
{
322+
yyless(0);
323+
unput('(');
324+
lexstate = ST_NORMAL;
325+
token = TYPEOF_KEYW;
326+
break;
327+
}
328+
_APP("(", 1);
329+
}
330+
APP;
331+
lexstate = ST_TYPEOF;
332+
goto repeat;
333+
287334
case ST_BRACKET:
288335
APP;
289336
switch (token)

scripts/genksyms/lex.lex.c_shipped

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,9 @@ int
19381938
yylex(void)
19391939
{
19401940
static enum {
1941-
ST_NOTSTARTED, ST_NORMAL, ST_ATTRIBUTE, ST_ASM, ST_BRACKET, ST_BRACE,
1942-
ST_EXPRESSION, ST_TABLE_1, ST_TABLE_2, ST_TABLE_3, ST_TABLE_4,
1941+
ST_NOTSTARTED, ST_NORMAL, ST_ATTRIBUTE, ST_ASM, ST_TYPEOF, ST_TYPEOF_1,
1942+
ST_BRACKET, ST_BRACE, ST_EXPRESSION,
1943+
ST_TABLE_1, ST_TABLE_2, ST_TABLE_3, ST_TABLE_4,
19431944
ST_TABLE_5, ST_TABLE_6
19441945
} lexstate = ST_NOTSTARTED;
19451946

@@ -2007,6 +2008,10 @@ repeat:
20072008
lexstate = ST_ASM;
20082009
count = 0;
20092010
goto repeat;
2011+
case TYPEOF_KEYW:
2012+
lexstate = ST_TYPEOF;
2013+
count = 0;
2014+
goto repeat;
20102015

20112016
case STRUCT_KEYW:
20122017
case UNION_KEYW:
@@ -2093,6 +2098,48 @@ repeat:
20932098
}
20942099
break;
20952100

2101+
case ST_TYPEOF:
2102+
switch (token)
2103+
{
2104+
case '(':
2105+
if ( ++count == 1 )
2106+
lexstate = ST_TYPEOF_1;
2107+
else
2108+
APP;
2109+
goto repeat;
2110+
case ')':
2111+
APP;
2112+
if (--count == 0)
2113+
{
2114+
lexstate = ST_NORMAL;
2115+
token = TYPEOF_PHRASE;
2116+
break;
2117+
}
2118+
goto repeat;
2119+
default:
2120+
APP;
2121+
goto repeat;
2122+
}
2123+
break;
2124+
2125+
case ST_TYPEOF_1:
2126+
if (token == IDENT)
2127+
{
2128+
if (is_reserved_word(yytext, yyleng)
2129+
|| find_symbol(yytext, SYM_TYPEDEF, 1))
2130+
{
2131+
yyless(0);
2132+
unput('(');
2133+
lexstate = ST_NORMAL;
2134+
token = TYPEOF_KEYW;
2135+
break;
2136+
}
2137+
_APP("(", 1);
2138+
}
2139+
APP;
2140+
lexstate = ST_TYPEOF;
2141+
goto repeat;
2142+
20962143
case ST_BRACKET:
20972144
APP;
20982145
switch (token)

0 commit comments

Comments
 (0)