aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/genksyms
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/genksyms')
-rw-r--r--scripts/genksyms/genksyms.c80
-rw-r--r--scripts/genksyms/genksyms.h57
2 files changed, 43 insertions, 94 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
39static struct symbol *symtab[HASH_BUCKETS]; 39static struct symbol *symtab[HASH_BUCKETS];
40FILE *debugfile; 40static FILE *debugfile;
41 41
42int cur_line = 1; 42int cur_line = 1;
43char *cur_filename, *output_directory; 43char *cur_filename;
44 44
45int flag_debug, flag_dump_defs, flag_warnings; 45static int flag_debug, flag_dump_defs, flag_warnings;
46const char *arch = ""; 46static const char *arch = "";
47const char *mod_prefix = ""; 47static const char *mod_prefix = "";
48 48
49static int errors; 49static int errors;
50static int nsyms; 50static 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
58static int equal_list(struct string_list *a, struct string_list *b);
59static void print_list(FILE * f, struct string_list *list);
60
58/*----------------------------------------------------------------------*/ 61/*----------------------------------------------------------------------*/
59 62
60static const unsigned int crctab32[] = { 63static const unsigned int crctab32[] = {
@@ -112,27 +115,26 @@ static const unsigned int crctab32[] = {
112 0x2d02ef8dU 115 0x2d02ef8dU
113}; 116};
114 117
115static inline unsigned long 118static unsigned long partial_crc32_one(unsigned char c, unsigned long crc)
116partial_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
121static inline unsigned long partial_crc32(const char *s, unsigned long crc) 123static 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
128static inline unsigned long crc32(const char *s) 130static 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
135static inline enum symbol_type map_to_ns(enum symbol_type t) 137static 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
196inline void free_node(struct string_list *node) 199void 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
211inline struct string_list *copy_node(struct string_list *node) 214struct 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
222struct string_list *copy_list(struct string_list *s, struct string_list *e) 225static 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
237int 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
249static inline void print_node(FILE * f, struct string_list *list) 237static 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
273void print_list(FILE * f, struct string_list *list) 261static 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
302static unsigned long 290static unsigned long expand_and_crc_list(struct string_list *list,
303expand_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
441void 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
455void error_with_pos(const char *fmt, ...) 427void 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
472void genksyms_usage(void) 444static 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__
diff --git a/scripts/genksyms/genksyms.h b/scripts/genksyms/genksyms.h
index f09af47ab281..ab6f34f38735 100644
--- a/scripts/genksyms/genksyms.h
+++ b/scripts/genksyms/genksyms.h
@@ -20,74 +20,51 @@
20 along with this program; if not, write to the Free Software Foundation, 20 along with this program; if not, write to the Free Software Foundation,
21 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 21 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 22
23
24#ifndef MODUTILS_GENKSYMS_H 23#ifndef MODUTILS_GENKSYMS_H
25#define MODUTILS_GENKSYMS_H 1 24#define MODUTILS_GENKSYMS_H 1
26 25
27#include <stdio.h> 26#include <stdio.h>
28 27
29 28enum symbol_type {
30enum symbol_type 29 SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION
31{
32 SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION
33}; 30};
34 31
35struct string_list 32struct string_list {
36{ 33 struct string_list *next;
37 struct string_list *next; 34 enum symbol_type tag;
38 enum symbol_type tag; 35 char *string;
39 char *string;
40}; 36};
41 37
42struct symbol 38struct symbol {
43{ 39 struct symbol *hash_next;
44 struct symbol *hash_next; 40 const char *name;
45 const char *name; 41 enum symbol_type type;
46 enum symbol_type type; 42 struct string_list *defn;
47 struct string_list *defn; 43 struct symbol *expansion_trail;
48 struct symbol *expansion_trail; 44 int is_extern;
49 int is_extern;
50}; 45};
51 46
52typedef struct string_list **yystype; 47typedef struct string_list **yystype;
53#define YYSTYPE yystype 48#define YYSTYPE yystype
54 49
55extern FILE *outfile, *debugfile;
56
57extern int cur_line; 50extern int cur_line;
58extern char *cur_filename, *output_directory; 51extern char *cur_filename;
59
60extern int flag_debug, flag_dump_defs, flag_warnings;
61extern int checksum_version, kernel_version;
62
63extern int want_brace_phrase, want_exp_phrase, discard_phrase_contents;
64extern struct string_list *current_list, *next_list;
65
66 52
67struct symbol *find_symbol(const char *name, enum symbol_type ns); 53struct symbol *find_symbol(const char *name, enum symbol_type ns);
68struct symbol *add_symbol(const char *name, enum symbol_type type, 54struct symbol *add_symbol(const char *name, enum symbol_type type,
69 struct string_list *defn, int is_extern); 55 struct string_list *defn, int is_extern);
70void export_symbol(const char *); 56void export_symbol(const char *);
71 57
72struct string_list *reset_list(void);
73void free_list(struct string_list *s, struct string_list *e);
74void free_node(struct string_list *list); 58void free_node(struct string_list *list);
59void free_list(struct string_list *s, struct string_list *e);
75struct string_list *copy_node(struct string_list *); 60struct string_list *copy_node(struct string_list *);
76struct string_list *copy_list(struct string_list *s, struct string_list *e);
77int equal_list(struct string_list *a, struct string_list *b);
78void print_list(FILE *, struct string_list *list);
79 61
80int yylex(void); 62int yylex(void);
81int yyparse(void); 63int yyparse(void);
82 64
83void error_with_pos(const char *, ...); 65void error_with_pos(const char *, ...);
84 66
85#define version(a,b,c) ((a << 16) | (b << 8) | (c))
86
87/*----------------------------------------------------------------------*/ 67/*----------------------------------------------------------------------*/
88
89#define MODUTILS_VERSION "<in-kernel>"
90
91#define xmalloc(size) ({ void *__ptr = malloc(size); \ 68#define xmalloc(size) ({ void *__ptr = malloc(size); \
92 if(!__ptr && size != 0) { \ 69 if(!__ptr && size != 0) { \
93 fprintf(stderr, "out of memory\n"); \ 70 fprintf(stderr, "out of memory\n"); \
@@ -101,4 +78,4 @@ void error_with_pos(const char *, ...);
101 } \ 78 } \
102 __str; }) 79 __str; })
103 80
104#endif /* genksyms.h */ 81#endif /* genksyms.h */