diff options
-rw-r--r-- | scripts/mod/modpost.c | 124 |
1 files changed, 54 insertions, 70 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index a3c57ec7d54a..4a2f2e38d27f 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -21,8 +21,7 @@ int have_vmlinux = 0; | |||
21 | /* Is CONFIG_MODULE_SRCVERSION_ALL set? */ | 21 | /* Is CONFIG_MODULE_SRCVERSION_ALL set? */ |
22 | static int all_versions = 0; | 22 | static int all_versions = 0; |
23 | 23 | ||
24 | void | 24 | void fatal(const char *fmt, ...) |
25 | fatal(const char *fmt, ...) | ||
26 | { | 25 | { |
27 | va_list arglist; | 26 | va_list arglist; |
28 | 27 | ||
@@ -35,8 +34,7 @@ fatal(const char *fmt, ...) | |||
35 | exit(1); | 34 | exit(1); |
36 | } | 35 | } |
37 | 36 | ||
38 | void | 37 | void warn(const char *fmt, ...) |
39 | warn(const char *fmt, ...) | ||
40 | { | 38 | { |
41 | va_list arglist; | 39 | va_list arglist; |
42 | 40 | ||
@@ -59,8 +57,7 @@ void *do_nofail(void *ptr, const char *expr) | |||
59 | 57 | ||
60 | static struct module *modules; | 58 | static struct module *modules; |
61 | 59 | ||
62 | struct module * | 60 | static struct module *find_module(char *modname) |
63 | find_module(char *modname) | ||
64 | { | 61 | { |
65 | struct module *mod; | 62 | struct module *mod; |
66 | 63 | ||
@@ -70,8 +67,7 @@ find_module(char *modname) | |||
70 | return mod; | 67 | return mod; |
71 | } | 68 | } |
72 | 69 | ||
73 | struct module * | 70 | static struct module *new_module(char *modname) |
74 | new_module(char *modname) | ||
75 | { | 71 | { |
76 | struct module *mod; | 72 | struct module *mod; |
77 | char *p, *s; | 73 | char *p, *s; |
@@ -122,11 +118,12 @@ static inline unsigned int tdb_hash(const char *name) | |||
122 | return (1103515243 * value + 12345); | 118 | return (1103515243 * value + 12345); |
123 | } | 119 | } |
124 | 120 | ||
125 | /* Allocate a new symbols for use in the hash of exported symbols or | 121 | /** |
126 | * the list of unresolved symbols per module */ | 122 | * Allocate a new symbols for use in the hash of exported symbols or |
127 | 123 | * the list of unresolved symbols per module | |
128 | struct symbol * | 124 | **/ |
129 | alloc_symbol(const char *name, unsigned int weak, struct symbol *next) | 125 | static struct symbol *alloc_symbol(const char *name, unsigned int weak, |
126 | struct symbol *next) | ||
130 | { | 127 | { |
131 | struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); | 128 | struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); |
132 | 129 | ||
@@ -138,9 +135,8 @@ alloc_symbol(const char *name, unsigned int weak, struct symbol *next) | |||
138 | } | 135 | } |
139 | 136 | ||
140 | /* For the hash of exported symbols */ | 137 | /* For the hash of exported symbols */ |
141 | 138 | static void new_symbol(const char *name, struct module *module, | |
142 | void | 139 | unsigned int *crc) |
143 | new_symbol(const char *name, struct module *module, unsigned int *crc) | ||
144 | { | 140 | { |
145 | unsigned int hash; | 141 | unsigned int hash; |
146 | struct symbol *new; | 142 | struct symbol *new; |
@@ -154,8 +150,7 @@ new_symbol(const char *name, struct module *module, unsigned int *crc) | |||
154 | } | 150 | } |
155 | } | 151 | } |
156 | 152 | ||
157 | struct symbol * | 153 | static struct symbol *find_symbol(const char *name) |
158 | find_symbol(const char *name) | ||
159 | { | 154 | { |
160 | struct symbol *s; | 155 | struct symbol *s; |
161 | 156 | ||
@@ -170,10 +165,12 @@ find_symbol(const char *name) | |||
170 | return NULL; | 165 | return NULL; |
171 | } | 166 | } |
172 | 167 | ||
173 | /* Add an exported symbol - it may have already been added without a | 168 | /** |
174 | * CRC, in this case just update the CRC */ | 169 | * Add an exported symbol - it may have already been added without a |
175 | void | 170 | * CRC, in this case just update the CRC |
176 | add_exported_symbol(const char *name, struct module *module, unsigned int *crc) | 171 | **/ |
172 | static void add_exported_symbol(const char *name, struct module *module, | ||
173 | unsigned int *crc) | ||
177 | { | 174 | { |
178 | struct symbol *s = find_symbol(name); | 175 | struct symbol *s = find_symbol(name); |
179 | 176 | ||
@@ -187,8 +184,7 @@ add_exported_symbol(const char *name, struct module *module, unsigned int *crc) | |||
187 | } | 184 | } |
188 | } | 185 | } |
189 | 186 | ||
190 | void * | 187 | void *grab_file(const char *filename, unsigned long *size) |
191 | grab_file(const char *filename, unsigned long *size) | ||
192 | { | 188 | { |
193 | struct stat st; | 189 | struct stat st; |
194 | void *map; | 190 | void *map; |
@@ -207,13 +203,12 @@ grab_file(const char *filename, unsigned long *size) | |||
207 | return map; | 203 | return map; |
208 | } | 204 | } |
209 | 205 | ||
210 | /* | 206 | /** |
211 | Return a copy of the next line in a mmap'ed file. | 207 | * Return a copy of the next line in a mmap'ed file. |
212 | spaces in the beginning of the line is trimmed away. | 208 | * spaces in the beginning of the line is trimmed away. |
213 | Return a pointer to a static buffer. | 209 | * Return a pointer to a static buffer. |
214 | */ | 210 | **/ |
215 | char* | 211 | char* get_next_line(unsigned long *pos, void *file, unsigned long size) |
216 | get_next_line(unsigned long *pos, void *file, unsigned long size) | ||
217 | { | 212 | { |
218 | static char line[4096]; | 213 | static char line[4096]; |
219 | int skip = 1; | 214 | int skip = 1; |
@@ -243,14 +238,12 @@ get_next_line(unsigned long *pos, void *file, unsigned long size) | |||
243 | return NULL; | 238 | return NULL; |
244 | } | 239 | } |
245 | 240 | ||
246 | void | 241 | void release_file(void *file, unsigned long size) |
247 | release_file(void *file, unsigned long size) | ||
248 | { | 242 | { |
249 | munmap(file, size); | 243 | munmap(file, size); |
250 | } | 244 | } |
251 | 245 | ||
252 | void | 246 | static void parse_elf(struct elf_info *info, const char *filename) |
253 | parse_elf(struct elf_info *info, const char *filename) | ||
254 | { | 247 | { |
255 | unsigned int i; | 248 | unsigned int i; |
256 | Elf_Ehdr *hdr = info->hdr; | 249 | Elf_Ehdr *hdr = info->hdr; |
@@ -318,8 +311,7 @@ parse_elf(struct elf_info *info, const char *filename) | |||
318 | fatal("%s is truncated.\n", filename); | 311 | fatal("%s is truncated.\n", filename); |
319 | } | 312 | } |
320 | 313 | ||
321 | void | 314 | static void parse_elf_finish(struct elf_info *info) |
322 | parse_elf_finish(struct elf_info *info) | ||
323 | { | 315 | { |
324 | release_file(info->hdr, info->size); | 316 | release_file(info->hdr, info->size); |
325 | } | 317 | } |
@@ -327,9 +319,8 @@ parse_elf_finish(struct elf_info *info) | |||
327 | #define CRC_PFX "__crc_" | 319 | #define CRC_PFX "__crc_" |
328 | #define KSYMTAB_PFX "__ksymtab_" | 320 | #define KSYMTAB_PFX "__ksymtab_" |
329 | 321 | ||
330 | void | 322 | static void handle_modversions(struct module *mod, struct elf_info *info, |
331 | handle_modversions(struct module *mod, struct elf_info *info, | 323 | Elf_Sym *sym, const char *symname) |
332 | Elf_Sym *sym, const char *symname) | ||
333 | { | 324 | { |
334 | unsigned int crc; | 325 | unsigned int crc; |
335 | 326 | ||
@@ -397,8 +388,7 @@ handle_modversions(struct module *mod, struct elf_info *info, | |||
397 | } | 388 | } |
398 | } | 389 | } |
399 | 390 | ||
400 | int | 391 | static int is_vmlinux(const char *modname) |
401 | is_vmlinux(const char *modname) | ||
402 | { | 392 | { |
403 | const char *myname; | 393 | const char *myname; |
404 | 394 | ||
@@ -410,7 +400,9 @@ is_vmlinux(const char *modname) | |||
410 | return strcmp(myname, "vmlinux") == 0; | 400 | return strcmp(myname, "vmlinux") == 0; |
411 | } | 401 | } |
412 | 402 | ||
413 | /* Parse tag=value strings from .modinfo section */ | 403 | /** |
404 | * Parse tag=value strings from .modinfo section | ||
405 | **/ | ||
414 | static char *next_string(char *string, unsigned long *secsize) | 406 | static char *next_string(char *string, unsigned long *secsize) |
415 | { | 407 | { |
416 | /* Skip non-zero chars */ | 408 | /* Skip non-zero chars */ |
@@ -443,8 +435,7 @@ static char *get_modinfo(void *modinfo, unsigned long modinfo_len, | |||
443 | return NULL; | 435 | return NULL; |
444 | } | 436 | } |
445 | 437 | ||
446 | void | 438 | static void read_symbols(char *modname) |
447 | read_symbols(char *modname) | ||
448 | { | 439 | { |
449 | const char *symname; | 440 | const char *symname; |
450 | char *version; | 441 | char *version; |
@@ -496,8 +487,8 @@ read_symbols(char *modname) | |||
496 | * following helper, then compare to the file on disk and | 487 | * following helper, then compare to the file on disk and |
497 | * only update the later if anything changed */ | 488 | * only update the later if anything changed */ |
498 | 489 | ||
499 | void __attribute__((format(printf, 2, 3))) | 490 | void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf, |
500 | buf_printf(struct buffer *buf, const char *fmt, ...) | 491 | const char *fmt, ...) |
501 | { | 492 | { |
502 | char tmp[SZ]; | 493 | char tmp[SZ]; |
503 | int len; | 494 | int len; |
@@ -514,8 +505,7 @@ buf_printf(struct buffer *buf, const char *fmt, ...) | |||
514 | va_end(ap); | 505 | va_end(ap); |
515 | } | 506 | } |
516 | 507 | ||
517 | void | 508 | void buf_write(struct buffer *buf, const char *s, int len) |
518 | buf_write(struct buffer *buf, const char *s, int len) | ||
519 | { | 509 | { |
520 | if (buf->size - buf->pos < len) { | 510 | if (buf->size - buf->pos < len) { |
521 | buf->size += len; | 511 | buf->size += len; |
@@ -525,10 +515,10 @@ buf_write(struct buffer *buf, const char *s, int len) | |||
525 | buf->pos += len; | 515 | buf->pos += len; |
526 | } | 516 | } |
527 | 517 | ||
528 | /* Header for the generated file */ | 518 | /** |
529 | 519 | * Header for the generated file | |
530 | void | 520 | **/ |
531 | add_header(struct buffer *b, struct module *mod) | 521 | static void add_header(struct buffer *b, struct module *mod) |
532 | { | 522 | { |
533 | buf_printf(b, "#include <linux/module.h>\n"); | 523 | buf_printf(b, "#include <linux/module.h>\n"); |
534 | buf_printf(b, "#include <linux/vermagic.h>\n"); | 524 | buf_printf(b, "#include <linux/vermagic.h>\n"); |
@@ -548,10 +538,10 @@ add_header(struct buffer *b, struct module *mod) | |||
548 | buf_printf(b, "};\n"); | 538 | buf_printf(b, "};\n"); |
549 | } | 539 | } |
550 | 540 | ||
551 | /* Record CRCs for unresolved symbols */ | 541 | /** |
552 | 542 | * Record CRCs for unresolved symbols | |
553 | void | 543 | **/ |
554 | add_versions(struct buffer *b, struct module *mod) | 544 | static void add_versions(struct buffer *b, struct module *mod) |
555 | { | 545 | { |
556 | struct symbol *s, *exp; | 546 | struct symbol *s, *exp; |
557 | 547 | ||
@@ -591,8 +581,8 @@ add_versions(struct buffer *b, struct module *mod) | |||
591 | buf_printf(b, "};\n"); | 581 | buf_printf(b, "};\n"); |
592 | } | 582 | } |
593 | 583 | ||
594 | void | 584 | static void add_depends(struct buffer *b, struct module *mod, |
595 | add_depends(struct buffer *b, struct module *mod, struct module *modules) | 585 | struct module *modules) |
596 | { | 586 | { |
597 | struct symbol *s; | 587 | struct symbol *s; |
598 | struct module *m; | 588 | struct module *m; |
@@ -622,8 +612,7 @@ add_depends(struct buffer *b, struct module *mod, struct module *modules) | |||
622 | buf_printf(b, "\";\n"); | 612 | buf_printf(b, "\";\n"); |
623 | } | 613 | } |
624 | 614 | ||
625 | void | 615 | static void add_srcversion(struct buffer *b, struct module *mod) |
626 | add_srcversion(struct buffer *b, struct module *mod) | ||
627 | { | 616 | { |
628 | if (mod->srcversion[0]) { | 617 | if (mod->srcversion[0]) { |
629 | buf_printf(b, "\n"); | 618 | buf_printf(b, "\n"); |
@@ -632,8 +621,7 @@ add_srcversion(struct buffer *b, struct module *mod) | |||
632 | } | 621 | } |
633 | } | 622 | } |
634 | 623 | ||
635 | void | 624 | static void write_if_changed(struct buffer *b, const char *fname) |
636 | write_if_changed(struct buffer *b, const char *fname) | ||
637 | { | 625 | { |
638 | char *tmp; | 626 | char *tmp; |
639 | FILE *file; | 627 | FILE *file; |
@@ -677,8 +665,7 @@ write_if_changed(struct buffer *b, const char *fname) | |||
677 | fclose(file); | 665 | fclose(file); |
678 | } | 666 | } |
679 | 667 | ||
680 | void | 668 | static void read_dump(const char *fname) |
681 | read_dump(const char *fname) | ||
682 | { | 669 | { |
683 | unsigned long size, pos = 0; | 670 | unsigned long size, pos = 0; |
684 | void *file = grab_file(fname, &size); | 671 | void *file = grab_file(fname, &size); |
@@ -719,8 +706,7 @@ fail: | |||
719 | fatal("parse error in symbol dump file\n"); | 706 | fatal("parse error in symbol dump file\n"); |
720 | } | 707 | } |
721 | 708 | ||
722 | void | 709 | static void write_dump(const char *fname) |
723 | write_dump(const char *fname) | ||
724 | { | 710 | { |
725 | struct buffer buf = { }; | 711 | struct buffer buf = { }; |
726 | struct symbol *symbol; | 712 | struct symbol *symbol; |
@@ -744,8 +730,7 @@ write_dump(const char *fname) | |||
744 | write_if_changed(&buf, fname); | 730 | write_if_changed(&buf, fname); |
745 | } | 731 | } |
746 | 732 | ||
747 | int | 733 | int main(int argc, char **argv) |
748 | main(int argc, char **argv) | ||
749 | { | 734 | { |
750 | struct module *mod; | 735 | struct module *mod; |
751 | struct buffer buf = { }; | 736 | struct buffer buf = { }; |
@@ -800,4 +785,3 @@ main(int argc, char **argv) | |||
800 | 785 | ||
801 | return 0; | 786 | return 0; |
802 | } | 787 | } |
803 | |||