diff options
Diffstat (limited to 'scripts/genksyms/genksyms.c')
-rw-r--r-- | scripts/genksyms/genksyms.c | 80 |
1 files changed, 26 insertions, 54 deletions
diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c index b798e284e1fc..5b0344e20d61 100644 --- a/scripts/genksyms/genksyms.c +++ b/scripts/genksyms/genksyms.c | |||
@@ -37,14 +37,14 @@ | |||
37 | #define HASH_BUCKETS 4096 | 37 | #define HASH_BUCKETS 4096 |
38 | 38 | ||
39 | static struct symbol *symtab[HASH_BUCKETS]; | 39 | static struct symbol *symtab[HASH_BUCKETS]; |
40 | FILE *debugfile; | 40 | static FILE *debugfile; |
41 | 41 | ||
42 | int cur_line = 1; | 42 | int cur_line = 1; |
43 | char *cur_filename, *output_directory; | 43 | char *cur_filename; |
44 | 44 | ||
45 | int flag_debug, flag_dump_defs, flag_warnings; | 45 | static int flag_debug, flag_dump_defs, flag_warnings; |
46 | const char *arch = ""; | 46 | static const char *arch = ""; |
47 | const char *mod_prefix = ""; | 47 | static const char *mod_prefix = ""; |
48 | 48 | ||
49 | static int errors; | 49 | static int errors; |
50 | static int nsyms; | 50 | static int nsyms; |
@@ -55,6 +55,9 @@ static const char *const symbol_type_name[] = { | |||
55 | "normal", "typedef", "enum", "struct", "union" | 55 | "normal", "typedef", "enum", "struct", "union" |
56 | }; | 56 | }; |
57 | 57 | ||
58 | static int equal_list(struct string_list *a, struct string_list *b); | ||
59 | static void print_list(FILE * f, struct string_list *list); | ||
60 | |||
58 | /*----------------------------------------------------------------------*/ | 61 | /*----------------------------------------------------------------------*/ |
59 | 62 | ||
60 | static const unsigned int crctab32[] = { | 63 | static const unsigned int crctab32[] = { |
@@ -112,27 +115,26 @@ static const unsigned int crctab32[] = { | |||
112 | 0x2d02ef8dU | 115 | 0x2d02ef8dU |
113 | }; | 116 | }; |
114 | 117 | ||
115 | static inline unsigned long | 118 | static unsigned long partial_crc32_one(unsigned char c, unsigned long crc) |
116 | partial_crc32_one(unsigned char c, unsigned long crc) | ||
117 | { | 119 | { |
118 | return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8); | 120 | return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8); |
119 | } | 121 | } |
120 | 122 | ||
121 | static inline unsigned long partial_crc32(const char *s, unsigned long crc) | 123 | static unsigned long partial_crc32(const char *s, unsigned long crc) |
122 | { | 124 | { |
123 | while (*s) | 125 | while (*s) |
124 | crc = partial_crc32_one(*s++, crc); | 126 | crc = partial_crc32_one(*s++, crc); |
125 | return crc; | 127 | return crc; |
126 | } | 128 | } |
127 | 129 | ||
128 | static inline unsigned long crc32(const char *s) | 130 | static unsigned long crc32(const char *s) |
129 | { | 131 | { |
130 | return partial_crc32(s, 0xffffffff) ^ 0xffffffff; | 132 | return partial_crc32(s, 0xffffffff) ^ 0xffffffff; |
131 | } | 133 | } |
132 | 134 | ||
133 | /*----------------------------------------------------------------------*/ | 135 | /*----------------------------------------------------------------------*/ |
134 | 136 | ||
135 | static inline enum symbol_type map_to_ns(enum symbol_type t) | 137 | static enum symbol_type map_to_ns(enum symbol_type t) |
136 | { | 138 | { |
137 | if (t == SYM_TYPEDEF) | 139 | if (t == SYM_TYPEDEF) |
138 | t = SYM_NORMAL; | 140 | t = SYM_NORMAL; |
@@ -147,8 +149,8 @@ struct symbol *find_symbol(const char *name, enum symbol_type ns) | |||
147 | struct symbol *sym; | 149 | struct symbol *sym; |
148 | 150 | ||
149 | for (sym = symtab[h]; sym; sym = sym->hash_next) | 151 | for (sym = symtab[h]; sym; sym = sym->hash_next) |
150 | if (map_to_ns(sym->type) == map_to_ns(ns) | 152 | if (map_to_ns(sym->type) == map_to_ns(ns) && |
151 | && strcmp(name, sym->name) == 0) | 153 | strcmp(name, sym->name) == 0) |
152 | break; | 154 | break; |
153 | 155 | ||
154 | return sym; | 156 | return sym; |
@@ -160,13 +162,14 @@ struct symbol *add_symbol(const char *name, enum symbol_type type, | |||
160 | unsigned long h = crc32(name) % HASH_BUCKETS; | 162 | unsigned long h = crc32(name) % HASH_BUCKETS; |
161 | struct symbol *sym; | 163 | struct symbol *sym; |
162 | 164 | ||
163 | for (sym = symtab[h]; sym; sym = sym->hash_next) | 165 | for (sym = symtab[h]; sym; sym = sym->hash_next) { |
164 | if (map_to_ns(sym->type) == map_to_ns(type) | 166 | if (map_to_ns(sym->type) == map_to_ns(type) |
165 | && strcmp(name, sym->name) == 0) { | 167 | && strcmp(name, sym->name) == 0) { |
166 | if (!equal_list(sym->defn, defn)) | 168 | if (!equal_list(sym->defn, defn)) |
167 | error_with_pos("redefinition of %s", name); | 169 | error_with_pos("redefinition of %s", name); |
168 | return sym; | 170 | return sym; |
169 | } | 171 | } |
172 | } | ||
170 | 173 | ||
171 | sym = xmalloc(sizeof(*sym)); | 174 | sym = xmalloc(sizeof(*sym)); |
172 | sym->name = name; | 175 | sym->name = name; |
@@ -193,7 +196,7 @@ struct symbol *add_symbol(const char *name, enum symbol_type type, | |||
193 | 196 | ||
194 | /*----------------------------------------------------------------------*/ | 197 | /*----------------------------------------------------------------------*/ |
195 | 198 | ||
196 | inline void free_node(struct string_list *node) | 199 | void free_node(struct string_list *node) |
197 | { | 200 | { |
198 | free(node->string); | 201 | free(node->string); |
199 | free(node); | 202 | free(node); |
@@ -208,7 +211,7 @@ void free_list(struct string_list *s, struct string_list *e) | |||
208 | } | 211 | } |
209 | } | 212 | } |
210 | 213 | ||
211 | inline struct string_list *copy_node(struct string_list *node) | 214 | struct string_list *copy_node(struct string_list *node) |
212 | { | 215 | { |
213 | struct string_list *newnode; | 216 | struct string_list *newnode; |
214 | 217 | ||
@@ -219,22 +222,7 @@ inline struct string_list *copy_node(struct string_list *node) | |||
219 | return newnode; | 222 | return newnode; |
220 | } | 223 | } |
221 | 224 | ||
222 | struct string_list *copy_list(struct string_list *s, struct string_list *e) | 225 | static int equal_list(struct string_list *a, struct string_list *b) |
223 | { | ||
224 | struct string_list *h, *p; | ||
225 | |||
226 | if (s == e) | ||
227 | return NULL; | ||
228 | |||
229 | p = h = copy_node(s); | ||
230 | while ((s = s->next) != e) | ||
231 | p = p->next = copy_node(s); | ||
232 | p->next = NULL; | ||
233 | |||
234 | return h; | ||
235 | } | ||
236 | |||
237 | int equal_list(struct string_list *a, struct string_list *b) | ||
238 | { | 226 | { |
239 | while (a && b) { | 227 | while (a && b) { |
240 | if (a->tag != b->tag || strcmp(a->string, b->string)) | 228 | if (a->tag != b->tag || strcmp(a->string, b->string)) |
@@ -246,7 +234,7 @@ int equal_list(struct string_list *a, struct string_list *b) | |||
246 | return !a && !b; | 234 | return !a && !b; |
247 | } | 235 | } |
248 | 236 | ||
249 | static inline void print_node(FILE * f, struct string_list *list) | 237 | static void print_node(FILE * f, struct string_list *list) |
250 | { | 238 | { |
251 | switch (list->tag) { | 239 | switch (list->tag) { |
252 | case SYM_STRUCT: | 240 | case SYM_STRUCT: |
@@ -270,7 +258,7 @@ static inline void print_node(FILE * f, struct string_list *list) | |||
270 | } | 258 | } |
271 | } | 259 | } |
272 | 260 | ||
273 | void print_list(FILE * f, struct string_list *list) | 261 | static void print_list(FILE * f, struct string_list *list) |
274 | { | 262 | { |
275 | struct string_list **e, **b; | 263 | struct string_list **e, **b; |
276 | struct string_list *tmp, **tmp2; | 264 | struct string_list *tmp, **tmp2; |
@@ -299,8 +287,8 @@ void print_list(FILE * f, struct string_list *list) | |||
299 | } | 287 | } |
300 | } | 288 | } |
301 | 289 | ||
302 | static unsigned long | 290 | static unsigned long expand_and_crc_list(struct string_list *list, |
303 | expand_and_crc_list(struct string_list *list, unsigned long crc) | 291 | unsigned long crc) |
304 | { | 292 | { |
305 | struct string_list **e, **b; | 293 | struct string_list **e, **b; |
306 | struct string_list *tmp, **tmp2; | 294 | struct string_list *tmp, **tmp2; |
@@ -386,9 +374,8 @@ expand_and_crc_list(struct string_list *list, unsigned long crc) | |||
386 | cur->string); | 374 | cur->string); |
387 | } | 375 | } |
388 | 376 | ||
389 | crc = | 377 | crc = partial_crc32(symbol_type_name[cur->tag], |
390 | partial_crc32(symbol_type_name[cur->tag], | 378 | crc); |
391 | crc); | ||
392 | crc = partial_crc32_one(' ', crc); | 379 | crc = partial_crc32_one(' ', crc); |
393 | crc = partial_crc32(cur->string, crc); | 380 | crc = partial_crc32(cur->string, crc); |
394 | crc = partial_crc32_one(' ', crc); | 381 | crc = partial_crc32_one(' ', crc); |
@@ -437,21 +424,6 @@ void export_symbol(const char *name) | |||
437 | } | 424 | } |
438 | 425 | ||
439 | /*----------------------------------------------------------------------*/ | 426 | /*----------------------------------------------------------------------*/ |
440 | |||
441 | void error(const char *fmt, ...) | ||
442 | { | ||
443 | va_list args; | ||
444 | |||
445 | if (flag_warnings) { | ||
446 | va_start(args, fmt); | ||
447 | vfprintf(stderr, fmt, args); | ||
448 | va_end(args); | ||
449 | putc('\n', stderr); | ||
450 | |||
451 | errors++; | ||
452 | } | ||
453 | } | ||
454 | |||
455 | void error_with_pos(const char *fmt, ...) | 427 | void error_with_pos(const char *fmt, ...) |
456 | { | 428 | { |
457 | va_list args; | 429 | va_list args; |
@@ -469,7 +441,7 @@ void error_with_pos(const char *fmt, ...) | |||
469 | } | 441 | } |
470 | } | 442 | } |
471 | 443 | ||
472 | void genksyms_usage(void) | 444 | static void genksyms_usage(void) |
473 | { | 445 | { |
474 | fputs("Usage:\n" "genksyms [-dDwqhV] > /path/to/.tmp_obj.ver\n" "\n" | 446 | fputs("Usage:\n" "genksyms [-dDwqhV] > /path/to/.tmp_obj.ver\n" "\n" |
475 | #ifdef __GNU_LIBRARY__ | 447 | #ifdef __GNU_LIBRARY__ |