30 #ifdef __GNU_LIBRARY__
37 #define HASH_BUCKETS 4096
40 static FILE *debugfile;
46 static int flag_debug, flag_dump_defs, flag_reference, flag_dump_types,
47 flag_preserve, flag_warnings;
48 static const char *
arch =
"";
49 static const char *mod_prefix =
"";
55 static struct symbol *visited_symbols;
72 static struct string_list *mk_node(
const char *
string);
73 static void print_location(
void);
78 static const unsigned int crctab32[] = {
79 0x00000000
U, 0x77073096
U, 0xee0e612c
U, 0x990951ba
U, 0x076dc419
U,
80 0x706af48f
U, 0xe963a535
U, 0x9e6495a3
U, 0x0edb8832
U, 0x79dcb8a4
U,
81 0xe0d5e91e
U, 0x97d2d988
U, 0x09b64c2b
U, 0x7eb17cbd
U, 0xe7b82d07
U,
82 0x90bf1d91
U, 0x1db71064
U, 0x6ab020f2
U, 0xf3b97148
U, 0x84be41de
U,
83 0x1adad47d
U, 0x6ddde4eb
U, 0xf4d4b551
U, 0x83d385c7
U, 0x136c9856
U,
84 0x646ba8c0
U, 0xfd62f97a
U, 0x8a65c9ec
U, 0x14015c4f
U, 0x63066cd9
U,
85 0xfa0f3d63
U, 0x8d080df5
U, 0x3b6e20c8
U, 0x4c69105e
U, 0xd56041e4
U,
86 0xa2677172
U, 0x3c03e4d1
U, 0x4b04d447
U, 0xd20d85fd
U, 0xa50ab56b
U,
87 0x35b5a8fa
U, 0x42b2986c
U, 0xdbbbc9d6
U, 0xacbcf940
U, 0x32d86ce3
U,
88 0x45df5c75
U, 0xdcd60dcf
U, 0xabd13d59
U, 0x26d930ac
U, 0x51de003a
U,
89 0xc8d75180
U, 0xbfd06116
U, 0x21b4f4b5
U, 0x56b3c423
U, 0xcfba9599
U,
90 0xb8bda50f
U, 0x2802b89e
U, 0x5f058808
U, 0xc60cd9b2
U, 0xb10be924
U,
91 0x2f6f7c87
U, 0x58684c11
U, 0xc1611dab
U, 0xb6662d3d
U, 0x76dc4190
U,
92 0x01db7106
U, 0x98d220bc
U, 0xefd5102a
U, 0x71b18589
U, 0x06b6b51f
U,
93 0x9fbfe4a5
U, 0xe8b8d433
U, 0x7807c9a2
U, 0x0f00f934
U, 0x9609a88e
U,
94 0xe10e9818
U, 0x7f6a0dbb
U, 0x086d3d2d
U, 0x91646c97
U, 0xe6635c01
U,
95 0x6b6b51f4
U, 0x1c6c6162
U, 0x856530d8
U, 0xf262004e
U, 0x6c0695ed
U,
96 0x1b01a57b
U, 0x8208f4c1
U, 0xf50fc457
U, 0x65b0d9c6
U, 0x12b7e950
U,
97 0x8bbeb8ea
U, 0xfcb9887c
U, 0x62dd1ddf
U, 0x15da2d49
U, 0x8cd37cf3
U,
98 0xfbd44c65
U, 0x4db26158
U, 0x3ab551ce
U, 0xa3bc0074
U, 0xd4bb30e2
U,
99 0x4adfa541
U, 0x3dd895d7
U, 0xa4d1c46d
U, 0xd3d6f4fb
U, 0x4369e96a
U,
100 0x346ed9fc
U, 0xad678846
U, 0xda60b8d0
U, 0x44042d73
U, 0x33031de5
U,
101 0xaa0a4c5f
U, 0xdd0d7cc9
U, 0x5005713c
U, 0x270241aa
U, 0xbe0b1010
U,
102 0xc90c2086
U, 0x5768b525
U, 0x206f85b3
U, 0xb966d409
U, 0xce61e49f
U,
103 0x5edef90e
U, 0x29d9c998
U, 0xb0d09822
U, 0xc7d7a8b4
U, 0x59b33d17
U,
104 0x2eb40d81
U, 0xb7bd5c3b
U, 0xc0ba6cad
U, 0xedb88320
U, 0x9abfb3b6
U,
105 0x03b6e20c
U, 0x74b1d29a
U, 0xead54739
U, 0x9dd277af
U, 0x04db2615
U,
106 0x73dc1683
U, 0xe3630b12
U, 0x94643b84
U, 0x0d6d6a3e
U, 0x7a6a5aa8
U,
107 0xe40ecf0b
U, 0x9309ff9d
U, 0x0a00ae27
U, 0x7d079eb1
U, 0xf00f9344
U,
108 0x8708a3d2
U, 0x1e01f268
U, 0x6906c2fe
U, 0xf762575d
U, 0x806567cb
U,
109 0x196c3671
U, 0x6e6b06e7
U, 0xfed41b76
U, 0x89d32be0
U, 0x10da7a5a
U,
110 0x67dd4acc
U, 0xf9b9df6f
U, 0x8ebeeff9
U, 0x17b7be43
U, 0x60b08ed5
U,
111 0xd6d6a3e8
U, 0xa1d1937e
U, 0x38d8c2c4
U, 0x4fdff252
U, 0xd1bb67f1
U,
112 0xa6bc5767
U, 0x3fb506dd
U, 0x48b2364b
U, 0xd80d2bda
U, 0xaf0a1b4c
U,
113 0x36034af6
U, 0x41047a60
U, 0xdf60efc3
U, 0xa867df55
U, 0x316e8eef
U,
114 0x4669be79
U, 0xcb61b38c
U, 0xbc66831a
U, 0x256fd2a0
U, 0x5268e236
U,
115 0xcc0c7795
U, 0xbb0b4703
U, 0x220216b9
U, 0x5505262f
U, 0xc5ba3bbe
U,
116 0xb2bd0b28
U, 0x2bb45a92
U, 0x5cb36a04
U, 0xc2d7ffa7
U, 0xb5d0cf31
U,
117 0x2cd99e8b
U, 0x5bdeae1d
U, 0x9b64c2b0
U, 0xec63f226
U, 0x756aa39c
U,
118 0x026d930a
U, 0x9c0906a9
U, 0xeb0e363f
U, 0x72076785
U, 0x05005713
U,
119 0x95bf4a82
U, 0xe2b87a14
U, 0x7bb12bae
U, 0x0cb61b38
U, 0x92d28e9b
U,
120 0xe5d5be0d
U, 0x7cdcefb7
U, 0x0bdbdf21
U, 0x86d3d2d4
U, 0xf1d4e242
U,
121 0x68ddb3f8
U, 0x1fda836e
U, 0x81be16cd
U, 0xf6b9265b
U, 0x6fb077e1
U,
122 0x18b74777
U, 0x88085ae6
U, 0xff0f6a70
U, 0x66063bca
U, 0x11010b5c
U,
123 0x8f659eff
U, 0xf862ae69
U, 0x616bffd3
U, 0x166ccf45
U, 0xa00ae278
U,
124 0xd70dd2ee
U, 0x4e048354
U, 0x3903b3c2
U, 0xa7672661
U, 0xd06016f7
U,
125 0x4969474d
U, 0x3e6e77db
U, 0xaed16a4a
U, 0xd9d65adc
U, 0x40df0b66
U,
126 0x37d83bf0
U, 0xa9bcae53
U, 0xdebb9ec5
U, 0x47b2cf7f
U, 0x30b5ffe9
U,
127 0xbdbdf21c
U, 0xcabac28a
U, 0x53b39330
U, 0x24b4a3a6
U, 0xbad03605
U,
128 0xcdd70693
U, 0x54de5729
U, 0x23d967bf
U, 0xb3667a2e
U, 0xc4614ab8
U,
129 0x5d681b02
U, 0x2a6f2b94
U, 0xb40bbe37
U, 0xc30c8ea1
U, 0x5a05df1b
U,
133 static unsigned long partial_crc32_one(
unsigned char c,
unsigned long crc)
135 return crctab32[(crc ^
c) & 0xff] ^ (crc >> 8);
138 static unsigned long partial_crc32(
const char *
s,
unsigned long crc)
141 crc = partial_crc32_one(*s++, crc);
145 static unsigned long crc32(
const char *s)
147 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
172 for (sym = symtab[h]; sym; sym = sym->
hash_next)
173 if (map_to_ns(sym->
type) == map_to_ns(ns) &&
178 if (exact && sym && sym->
type != ns)
183 static int is_unknown_symbol(
struct symbol *sym)
209 static int enum_counter;
221 snprintf(buf,
sizeof(buf),
"%d", enum_counter++);
222 if (last_enum_expr) {
224 defn = concat_list(mk_node(
"("),
235 last_enum_expr =
NULL;
243 for (sym = symtab[h]; sym; sym = sym->
hash_next) {
244 if (map_to_ns(sym->
type) == map_to_ns(type) &&
248 else if (sym->
type == type &&
249 equal_list(sym->
defn, defn)) {
252 print_type_name(type, name);
253 fprintf(stderr,
" modversion is "
262 print_type_name(type, name);
263 fprintf(stderr,
" modversion change\n");
267 status = is_unknown_symbol(sym) ?
281 for (psym = &symtab[h]; *psym; psym = &(*psym)->
hash_next) {
306 if (symbol_types[type].name)
307 fprintf(debugfile,
"Defn for %s %s == <",
308 symbol_types[type].name, name);
310 fprintf(debugfile,
"Defn for type%d %s == <",
313 fputs(
"extern ", debugfile);
314 print_list(debugfile, defn);
315 fputs(
">\n", debugfile);
325 return __add_symbol(name, type, defn, is_extern, 0);
328 static struct symbol *add_reference_symbol(
const char *name,
enum symbol_type type,
331 return __add_symbol(name, type, defn, is_extern, 1);
351 static struct string_list *mk_node(
const char *
string)
355 newnode =
xmalloc(
sizeof(*newnode));
371 for (n2 = n; n2->
next; n2 = n2->
next)
384 newnode =
xmalloc(
sizeof(*newnode));
399 for (start = start->
next; start != end; start = start->
next) {
419 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
429 while ((c = fgetc(f)) !=
EOF) {
431 if (node.
string == buffer)
434 }
else if (c ==
'\n') {
435 if (node.
string == buffer)
440 if (node.
string >= buffer +
sizeof(buffer) - 1) {
441 fprintf(stderr,
"Token too long\n");
446 if (node.
string == buffer)
451 if (node.
string[1] ==
'#') {
454 for (n = 0; n <
ARRAY_SIZE(symbol_types); n++) {
455 if (node.
string[0] == symbol_types[n].n) {
467 static void read_reference(FILE *
f)
472 int is_extern = 0, is_override = 0;
505 if (symbol_types[list->
tag].n) {
506 putc(symbol_types[list->
tag].n, f);
512 static void print_list(FILE * f,
struct string_list *list)
527 b = alloca(elem *
sizeof(*e));
541 static unsigned long expand_and_crc_sym(
struct symbol *sym,
unsigned long crc)
555 b = alloca(elem *
sizeof(*e));
572 crc = partial_crc32(cur->
string, crc);
573 crc = partial_crc32_one(
' ', crc);
583 crc = partial_crc32(cur->
string, crc);
584 crc = partial_crc32_one(
' ', crc);
587 expansion_trail = subsym;
588 crc = expand_and_crc_sym(subsym, crc);
600 symbol_types[cur->
tag].name,
602 n = concat_list(mk_node
603 (symbol_types[cur->
tag].name),
612 if (flag_dump_defs) {
614 symbol_types[cur->
tag].name,
618 crc = partial_crc32(symbol_types[cur->
tag].name,
620 crc = partial_crc32_one(
' ', crc);
621 crc = partial_crc32(cur->
string, crc);
622 crc = partial_crc32_one(
' ', crc);
625 expansion_trail = subsym;
626 crc = expand_and_crc_sym(subsym, crc);
633 static struct symbol **
end = &visited_symbols;
657 fprintf(debugfile,
"Export %s == <", name);
659 expansion_trail = (
struct symbol *)-1
L;
662 expansion_trail = sym;
663 crc = expand_and_crc_sym(sym, 0xffffffff) ^ 0xffffffff;
666 while (sym != (
struct symbol *)-1
L) {
672 fprintf(stderr,
"%s: %s: modversion "
673 "changed because of changes "
674 "in ", flag_preserve ?
"error" :
678 print_type_name(sym->
type, sym->
name);
680 fprintf(stderr,
" (became defined)");
692 fputs(
">\n", debugfile);
695 printf(
"%s__crc_%s = 0x%08lx ;\n", mod_prefix, name, crc);
701 static void print_location(
void)
706 static void print_type_name(
enum symbol_type type,
const char *name)
708 if (symbol_types[type].name)
709 fprintf(stderr,
"%s %s", symbol_types[type].name, name);
730 static void genksyms_usage(
void)
732 fputs(
"Usage:\n" "genksyms [-adDTwqhV] > /path/to/.tmp_obj.ver\n" "\n"
733 #ifdef __GNU_LIBRARY__
734 " -a, --arch Select architecture\n"
735 " -d, --debug Increment the debug level (repeatable)\n"
736 " -D, --dump Dump expanded symbol defs (for debugging only)\n"
737 " -r, --reference file Read reference symbols from a file\n"
738 " -T, --dump-types file Dump expanded types into file\n"
739 " -p, --preserve Preserve reference modversions or fail\n"
740 " -w, --warnings Enable warnings\n"
741 " -q, --quiet Disable warnings (default)\n"
742 " -h, --help Print this message\n"
743 " -V, --version Print the release version\n"
745 " -a Select architecture\n"
746 " -d Increment the debug level (repeatable)\n"
747 " -D Dump expanded symbol defs (for debugging only)\n"
748 " -r file Read reference symbols from a file\n"
749 " -T file Dump expanded types into file\n"
750 " -p Preserve reference modversions or fail\n"
751 " -w Enable warnings\n"
752 " -q Disable warnings (default)\n"
753 " -h Print this message\n"
754 " -V Print the release version\n"
761 FILE *dumpfile =
NULL, *ref_file =
NULL;
764 #ifdef __GNU_LIBRARY__
765 struct option long_opts[] = {
767 {
"debug", 0, 0,
'd'},
768 {
"warnings", 0, 0,
'w'},
769 {
"quiet", 0, 0,
'q'},
771 {
"reference", 1, 0,
'r'},
772 {
"dump-types", 1, 0,
'T'},
773 {
"preserve", 0, 0,
'p'},
774 {
"version", 0, 0,
'V'},
779 while ((o = getopt_long(argc, argv,
"a:dwqVDr:T:ph",
782 while ((o = getopt(argc, argv,
"a:dwqVDr:T:ph")) !=
EOF)
798 fputs(
"genksyms version 2.5.60\n", stderr);
805 ref_file = fopen(optarg,
"r");
813 dumpfile = fopen(optarg,
"w");
833 extern int yy_flex_debug;
835 yydebug = (flag_debug > 1);
836 yy_flex_debug = (flag_debug > 2);
842 if (flag_reference) {
843 read_reference(ref_file);
849 if (flag_dump_types && visited_symbols) {
850 while (visited_symbols != (
struct symbol *)-1
L) {
851 struct symbol *sym = visited_symbols;
854 fputs(
"override ", dumpfile);
855 if (symbol_types[sym->
type].n) {
856 putc(symbol_types[sym->
type].n, dumpfile);
859 fputs(sym->
name, dumpfile);
862 fputs(
"extern ", dumpfile);
863 print_list(dumpfile, sym->
defn);
864 putc(
'\n', dumpfile);
866 visited_symbols = sym->
visited;
872 fprintf(debugfile,
"Hash table occupancy %d/%d = %g\n",