diff options
author | Paul Mundt <lethal@linux-sh.org> | 2011-01-13 01:06:28 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2011-01-13 01:06:28 -0500 |
commit | f43dc23d5ea91fca257be02138a255f02d98e806 (patch) | |
tree | b29722f6e965316e90ac97abf79923ced250dc21 /scripts/mod/modpost.c | |
parent | f8e53553f452dcbf67cb89c8cba63a1cd6eb4cc0 (diff) | |
parent | 4162cf64973df51fc885825bc9ca4d055891c49f (diff) |
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 into common/serial-rework
Conflicts:
arch/sh/kernel/cpu/sh2/setup-sh7619.c
arch/sh/kernel/cpu/sh2a/setup-mxg.c
arch/sh/kernel/cpu/sh2a/setup-sh7201.c
arch/sh/kernel/cpu/sh2a/setup-sh7203.c
arch/sh/kernel/cpu/sh2a/setup-sh7206.c
arch/sh/kernel/cpu/sh3/setup-sh7705.c
arch/sh/kernel/cpu/sh3/setup-sh770x.c
arch/sh/kernel/cpu/sh3/setup-sh7710.c
arch/sh/kernel/cpu/sh3/setup-sh7720.c
arch/sh/kernel/cpu/sh4/setup-sh4-202.c
arch/sh/kernel/cpu/sh4/setup-sh7750.c
arch/sh/kernel/cpu/sh4/setup-sh7760.c
arch/sh/kernel/cpu/sh4a/setup-sh7343.c
arch/sh/kernel/cpu/sh4a/setup-sh7366.c
arch/sh/kernel/cpu/sh4a/setup-sh7722.c
arch/sh/kernel/cpu/sh4a/setup-sh7723.c
arch/sh/kernel/cpu/sh4a/setup-sh7724.c
arch/sh/kernel/cpu/sh4a/setup-sh7763.c
arch/sh/kernel/cpu/sh4a/setup-sh7770.c
arch/sh/kernel/cpu/sh4a/setup-sh7780.c
arch/sh/kernel/cpu/sh4a/setup-sh7785.c
arch/sh/kernel/cpu/sh4a/setup-sh7786.c
arch/sh/kernel/cpu/sh4a/setup-shx3.c
arch/sh/kernel/cpu/sh5/setup-sh5.c
drivers/serial/sh-sci.c
drivers/serial/sh-sci.h
include/linux/serial_sci.h
Diffstat (limited to 'scripts/mod/modpost.c')
-rw-r--r-- | scripts/mod/modpost.c | 521 |
1 files changed, 245 insertions, 276 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 4522948a012e..97d2259ae999 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -14,9 +14,19 @@ | |||
14 | #define _GNU_SOURCE | 14 | #define _GNU_SOURCE |
15 | #include <stdio.h> | 15 | #include <stdio.h> |
16 | #include <ctype.h> | 16 | #include <ctype.h> |
17 | #include <string.h> | ||
17 | #include "modpost.h" | 18 | #include "modpost.h" |
19 | #include "../../include/generated/autoconf.h" | ||
18 | #include "../../include/linux/license.h" | 20 | #include "../../include/linux/license.h" |
19 | 21 | ||
22 | /* Some toolchains use a `_' prefix for all user symbols. */ | ||
23 | #ifdef CONFIG_SYMBOL_PREFIX | ||
24 | #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX | ||
25 | #else | ||
26 | #define MODULE_SYMBOL_PREFIX "" | ||
27 | #endif | ||
28 | |||
29 | |||
20 | /* Are we using CONFIG_MODVERSIONS? */ | 30 | /* Are we using CONFIG_MODVERSIONS? */ |
21 | int modversions = 0; | 31 | int modversions = 0; |
22 | /* Warn about undefined symbols? (do so if we have vmlinux) */ | 32 | /* Warn about undefined symbols? (do so if we have vmlinux) */ |
@@ -244,7 +254,7 @@ static enum export export_no(const char *s) | |||
244 | return export_unknown; | 254 | return export_unknown; |
245 | } | 255 | } |
246 | 256 | ||
247 | static enum export export_from_sec(struct elf_info *elf, Elf_Section sec) | 257 | static enum export export_from_sec(struct elf_info *elf, unsigned int sec) |
248 | { | 258 | { |
249 | if (sec == elf->export_sec) | 259 | if (sec == elf->export_sec) |
250 | return export_plain; | 260 | return export_plain; |
@@ -364,6 +374,8 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
364 | Elf_Ehdr *hdr; | 374 | Elf_Ehdr *hdr; |
365 | Elf_Shdr *sechdrs; | 375 | Elf_Shdr *sechdrs; |
366 | Elf_Sym *sym; | 376 | Elf_Sym *sym; |
377 | const char *secstrings; | ||
378 | unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U; | ||
367 | 379 | ||
368 | hdr = grab_file(filename, &info->size); | 380 | hdr = grab_file(filename, &info->size); |
369 | if (!hdr) { | 381 | if (!hdr) { |
@@ -408,8 +420,27 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
408 | return 0; | 420 | return 0; |
409 | } | 421 | } |
410 | 422 | ||
423 | if (hdr->e_shnum == 0) { | ||
424 | /* | ||
425 | * There are more than 64k sections, | ||
426 | * read count from .sh_size. | ||
427 | * note: it doesn't need shndx2secindex() | ||
428 | */ | ||
429 | info->num_sections = TO_NATIVE(sechdrs[0].sh_size); | ||
430 | } | ||
431 | else { | ||
432 | info->num_sections = hdr->e_shnum; | ||
433 | } | ||
434 | if (hdr->e_shstrndx == SHN_XINDEX) { | ||
435 | info->secindex_strings = | ||
436 | shndx2secindex(TO_NATIVE(sechdrs[0].sh_link)); | ||
437 | } | ||
438 | else { | ||
439 | info->secindex_strings = hdr->e_shstrndx; | ||
440 | } | ||
441 | |||
411 | /* Fix endianness in section headers */ | 442 | /* Fix endianness in section headers */ |
412 | for (i = 0; i < hdr->e_shnum; i++) { | 443 | for (i = 0; i < info->num_sections; i++) { |
413 | sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name); | 444 | sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name); |
414 | sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type); | 445 | sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type); |
415 | sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags); | 446 | sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags); |
@@ -422,9 +453,8 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
422 | sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize); | 453 | sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize); |
423 | } | 454 | } |
424 | /* Find symbol table. */ | 455 | /* Find symbol table. */ |
425 | for (i = 1; i < hdr->e_shnum; i++) { | 456 | secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset; |
426 | const char *secstrings | 457 | for (i = 1; i < info->num_sections; i++) { |
427 | = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; | ||
428 | const char *secname; | 458 | const char *secname; |
429 | int nobits = sechdrs[i].sh_type == SHT_NOBITS; | 459 | int nobits = sechdrs[i].sh_type == SHT_NOBITS; |
430 | 460 | ||
@@ -451,17 +481,27 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
451 | info->export_unused_gpl_sec = i; | 481 | info->export_unused_gpl_sec = i; |
452 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) | 482 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) |
453 | info->export_gpl_future_sec = i; | 483 | info->export_gpl_future_sec = i; |
454 | else if (strcmp(secname, "__markers_strings") == 0) | ||
455 | info->markers_strings_sec = i; | ||
456 | 484 | ||
457 | if (sechdrs[i].sh_type != SHT_SYMTAB) | 485 | if (sechdrs[i].sh_type == SHT_SYMTAB) { |
458 | continue; | 486 | unsigned int sh_link_idx; |
487 | symtab_idx = i; | ||
488 | info->symtab_start = (void *)hdr + | ||
489 | sechdrs[i].sh_offset; | ||
490 | info->symtab_stop = (void *)hdr + | ||
491 | sechdrs[i].sh_offset + sechdrs[i].sh_size; | ||
492 | sh_link_idx = shndx2secindex(sechdrs[i].sh_link); | ||
493 | info->strtab = (void *)hdr + | ||
494 | sechdrs[sh_link_idx].sh_offset; | ||
495 | } | ||
459 | 496 | ||
460 | info->symtab_start = (void *)hdr + sechdrs[i].sh_offset; | 497 | /* 32bit section no. table? ("more than 64k sections") */ |
461 | info->symtab_stop = (void *)hdr + sechdrs[i].sh_offset | 498 | if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) { |
462 | + sechdrs[i].sh_size; | 499 | symtab_shndx_idx = i; |
463 | info->strtab = (void *)hdr + | 500 | info->symtab_shndx_start = (void *)hdr + |
464 | sechdrs[sechdrs[i].sh_link].sh_offset; | 501 | sechdrs[i].sh_offset; |
502 | info->symtab_shndx_stop = (void *)hdr + | ||
503 | sechdrs[i].sh_offset + sechdrs[i].sh_size; | ||
504 | } | ||
465 | } | 505 | } |
466 | if (!info->symtab_start) | 506 | if (!info->symtab_start) |
467 | fatal("%s has no symtab?\n", filename); | 507 | fatal("%s has no symtab?\n", filename); |
@@ -473,6 +513,21 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
473 | sym->st_value = TO_NATIVE(sym->st_value); | 513 | sym->st_value = TO_NATIVE(sym->st_value); |
474 | sym->st_size = TO_NATIVE(sym->st_size); | 514 | sym->st_size = TO_NATIVE(sym->st_size); |
475 | } | 515 | } |
516 | |||
517 | if (symtab_shndx_idx != ~0U) { | ||
518 | Elf32_Word *p; | ||
519 | if (symtab_idx != | ||
520 | shndx2secindex(sechdrs[symtab_shndx_idx].sh_link)) | ||
521 | fatal("%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n", | ||
522 | filename, | ||
523 | shndx2secindex(sechdrs[symtab_shndx_idx].sh_link), | ||
524 | symtab_idx); | ||
525 | /* Fix endianness */ | ||
526 | for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; | ||
527 | p++) | ||
528 | *p = TO_NATIVE(*p); | ||
529 | } | ||
530 | |||
476 | return 1; | 531 | return 1; |
477 | } | 532 | } |
478 | 533 | ||
@@ -496,6 +551,11 @@ static int ignore_undef_symbol(struct elf_info *info, const char *symname) | |||
496 | strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 || | 551 | strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 || |
497 | strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0) | 552 | strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0) |
498 | return 1; | 553 | return 1; |
554 | if (info->hdr->e_machine == EM_PPC64) | ||
555 | /* Special register function linked on all modules during final link of .ko */ | ||
556 | if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 || | ||
557 | strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0) | ||
558 | return 1; | ||
499 | /* Do not ignore this symbol */ | 559 | /* Do not ignore this symbol */ |
500 | return 0; | 560 | return 0; |
501 | } | 561 | } |
@@ -507,7 +567,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
507 | Elf_Sym *sym, const char *symname) | 567 | Elf_Sym *sym, const char *symname) |
508 | { | 568 | { |
509 | unsigned int crc; | 569 | unsigned int crc; |
510 | enum export export = export_from_sec(info, sym->st_shndx); | 570 | enum export export = export_from_sec(info, get_secindex(info, sym)); |
511 | 571 | ||
512 | switch (sym->st_shndx) { | 572 | switch (sym->st_shndx) { |
513 | case SHN_COMMON: | 573 | case SHN_COMMON: |
@@ -515,7 +575,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
515 | break; | 575 | break; |
516 | case SHN_ABS: | 576 | case SHN_ABS: |
517 | /* CRC'd symbol */ | 577 | /* CRC'd symbol */ |
518 | if (memcmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { | 578 | if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { |
519 | crc = (unsigned int) sym->st_value; | 579 | crc = (unsigned int) sym->st_value; |
520 | sym_update_crc(symname + strlen(CRC_PFX), mod, crc, | 580 | sym_update_crc(symname + strlen(CRC_PFX), mod, crc, |
521 | export); | 581 | export); |
@@ -559,7 +619,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
559 | break; | 619 | break; |
560 | default: | 620 | default: |
561 | /* All exported symbols */ | 621 | /* All exported symbols */ |
562 | if (memcmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { | 622 | if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { |
563 | sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, | 623 | sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, |
564 | export); | 624 | export); |
565 | } | 625 | } |
@@ -649,19 +709,19 @@ static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) | |||
649 | return "(unknown)"; | 709 | return "(unknown)"; |
650 | } | 710 | } |
651 | 711 | ||
652 | static const char *sec_name(struct elf_info *elf, int shndx) | 712 | static const char *sec_name(struct elf_info *elf, int secindex) |
653 | { | 713 | { |
654 | Elf_Shdr *sechdrs = elf->sechdrs; | 714 | Elf_Shdr *sechdrs = elf->sechdrs; |
655 | return (void *)elf->hdr + | 715 | return (void *)elf->hdr + |
656 | elf->sechdrs[elf->hdr->e_shstrndx].sh_offset + | 716 | elf->sechdrs[elf->secindex_strings].sh_offset + |
657 | sechdrs[shndx].sh_name; | 717 | sechdrs[secindex].sh_name; |
658 | } | 718 | } |
659 | 719 | ||
660 | static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr) | 720 | static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr) |
661 | { | 721 | { |
662 | return (void *)elf->hdr + | 722 | return (void *)elf->hdr + |
663 | elf->sechdrs[elf->hdr->e_shstrndx].sh_offset + | 723 | elf->sechdrs[elf->secindex_strings].sh_offset + |
664 | sechdr->sh_name; | 724 | sechdr->sh_name; |
665 | } | 725 | } |
666 | 726 | ||
667 | /* if sym is empty or point to a string | 727 | /* if sym is empty or point to a string |
@@ -691,7 +751,7 @@ static int number_prefix(const char *sym) | |||
691 | * The $ syntax is for sections where ld append a dot number | 751 | * The $ syntax is for sections where ld append a dot number |
692 | * to make section name unique. | 752 | * to make section name unique. |
693 | */ | 753 | */ |
694 | int match(const char *sym, const char * const pat[]) | 754 | static int match(const char *sym, const char * const pat[]) |
695 | { | 755 | { |
696 | const char *p; | 756 | const char *p; |
697 | while (*pat) { | 757 | while (*pat) { |
@@ -730,6 +790,8 @@ static const char *section_white_list[] = | |||
730 | { | 790 | { |
731 | ".comment*", | 791 | ".comment*", |
732 | ".debug*", | 792 | ".debug*", |
793 | ".zdebug*", /* Compressed debug sections. */ | ||
794 | ".GCC-command-line", /* mn10300 */ | ||
733 | ".mdebug*", /* alpha, score, mips etc. */ | 795 | ".mdebug*", /* alpha, score, mips etc. */ |
734 | ".pdr", /* alpha, score, mips etc. */ | 796 | ".pdr", /* alpha, score, mips etc. */ |
735 | ".stab*", | 797 | ".stab*", |
@@ -774,10 +836,13 @@ static void check_section(const char *modname, struct elf_info *elf, | |||
774 | #define ALL_EXIT_TEXT_SECTIONS \ | 836 | #define ALL_EXIT_TEXT_SECTIONS \ |
775 | ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$" | 837 | ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$" |
776 | 838 | ||
777 | #define ALL_INIT_SECTIONS INIT_SECTIONS, DEV_INIT_SECTIONS, \ | 839 | #define ALL_XXXINIT_SECTIONS DEV_INIT_SECTIONS, CPU_INIT_SECTIONS, \ |
778 | CPU_INIT_SECTIONS, MEM_INIT_SECTIONS | 840 | MEM_INIT_SECTIONS |
779 | #define ALL_EXIT_SECTIONS EXIT_SECTIONS, DEV_EXIT_SECTIONS, \ | 841 | #define ALL_XXXEXIT_SECTIONS DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, \ |
780 | CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS | 842 | MEM_EXIT_SECTIONS |
843 | |||
844 | #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS | ||
845 | #define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS | ||
781 | 846 | ||
782 | #define DATA_SECTIONS ".data$", ".data.rel$" | 847 | #define DATA_SECTIONS ".data$", ".data.rel$" |
783 | #define TEXT_SECTIONS ".text$" | 848 | #define TEXT_SECTIONS ".text$" |
@@ -807,33 +872,29 @@ static const char *data_sections[] = { DATA_SECTIONS, NULL }; | |||
807 | 872 | ||
808 | 873 | ||
809 | /* symbols in .data that may refer to init/exit sections */ | 874 | /* symbols in .data that may refer to init/exit sections */ |
810 | static const char *symbol_white_list[] = | 875 | #define DEFAULT_SYMBOL_WHITE_LIST \ |
811 | { | 876 | "*driver", \ |
812 | "*driver", | 877 | "*_template", /* scsi uses *_template a lot */ \ |
813 | "*_template", /* scsi uses *_template a lot */ | 878 | "*_timer", /* arm uses ops structures named _timer a lot */ \ |
814 | "*_timer", /* arm uses ops structures named _timer a lot */ | 879 | "*_sht", /* scsi also used *_sht to some extent */ \ |
815 | "*_sht", /* scsi also used *_sht to some extent */ | 880 | "*_ops", \ |
816 | "*_ops", | 881 | "*_probe", \ |
817 | "*_probe", | 882 | "*_probe_one", \ |
818 | "*_probe_one", | 883 | "*_console" |
819 | "*_console", | ||
820 | NULL | ||
821 | }; | ||
822 | 884 | ||
823 | static const char *head_sections[] = { ".head.text*", NULL }; | 885 | static const char *head_sections[] = { ".head.text*", NULL }; |
824 | static const char *linker_symbols[] = | 886 | static const char *linker_symbols[] = |
825 | { "__init_begin", "_sinittext", "_einittext", NULL }; | 887 | { "__init_begin", "_sinittext", "_einittext", NULL }; |
826 | 888 | ||
827 | enum mismatch { | 889 | enum mismatch { |
828 | NO_MISMATCH, | 890 | TEXT_TO_ANY_INIT, |
829 | TEXT_TO_INIT, | 891 | DATA_TO_ANY_INIT, |
830 | DATA_TO_INIT, | 892 | TEXT_TO_ANY_EXIT, |
831 | TEXT_TO_EXIT, | 893 | DATA_TO_ANY_EXIT, |
832 | DATA_TO_EXIT, | 894 | XXXINIT_TO_SOME_INIT, |
833 | XXXINIT_TO_INIT, | 895 | XXXEXIT_TO_SOME_EXIT, |
834 | XXXEXIT_TO_EXIT, | 896 | ANY_INIT_TO_ANY_EXIT, |
835 | INIT_TO_EXIT, | 897 | ANY_EXIT_TO_ANY_INIT, |
836 | EXIT_TO_INIT, | ||
837 | EXPORT_TO_INIT_EXIT, | 898 | EXPORT_TO_INIT_EXIT, |
838 | }; | 899 | }; |
839 | 900 | ||
@@ -841,6 +902,7 @@ struct sectioncheck { | |||
841 | const char *fromsec[20]; | 902 | const char *fromsec[20]; |
842 | const char *tosec[20]; | 903 | const char *tosec[20]; |
843 | enum mismatch mismatch; | 904 | enum mismatch mismatch; |
905 | const char *symbol_white_list[20]; | ||
844 | }; | 906 | }; |
845 | 907 | ||
846 | const struct sectioncheck sectioncheck[] = { | 908 | const struct sectioncheck sectioncheck[] = { |
@@ -850,80 +912,103 @@ const struct sectioncheck sectioncheck[] = { | |||
850 | { | 912 | { |
851 | .fromsec = { TEXT_SECTIONS, NULL }, | 913 | .fromsec = { TEXT_SECTIONS, NULL }, |
852 | .tosec = { ALL_INIT_SECTIONS, NULL }, | 914 | .tosec = { ALL_INIT_SECTIONS, NULL }, |
853 | .mismatch = TEXT_TO_INIT, | 915 | .mismatch = TEXT_TO_ANY_INIT, |
916 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
854 | }, | 917 | }, |
855 | { | 918 | { |
856 | .fromsec = { DATA_SECTIONS, NULL }, | 919 | .fromsec = { DATA_SECTIONS, NULL }, |
857 | .tosec = { ALL_INIT_SECTIONS, NULL }, | 920 | .tosec = { ALL_XXXINIT_SECTIONS, NULL }, |
858 | .mismatch = DATA_TO_INIT, | 921 | .mismatch = DATA_TO_ANY_INIT, |
922 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
923 | }, | ||
924 | { | ||
925 | .fromsec = { DATA_SECTIONS, NULL }, | ||
926 | .tosec = { INIT_SECTIONS, NULL }, | ||
927 | .mismatch = DATA_TO_ANY_INIT, | ||
928 | .symbol_white_list = { | ||
929 | "*_template", "*_timer", "*_sht", "*_ops", | ||
930 | "*_probe", "*_probe_one", "*_console", NULL | ||
931 | }, | ||
859 | }, | 932 | }, |
860 | { | 933 | { |
861 | .fromsec = { TEXT_SECTIONS, NULL }, | 934 | .fromsec = { TEXT_SECTIONS, NULL }, |
862 | .tosec = { ALL_EXIT_SECTIONS, NULL }, | 935 | .tosec = { ALL_EXIT_SECTIONS, NULL }, |
863 | .mismatch = TEXT_TO_EXIT, | 936 | .mismatch = TEXT_TO_ANY_EXIT, |
937 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
864 | }, | 938 | }, |
865 | { | 939 | { |
866 | .fromsec = { DATA_SECTIONS, NULL }, | 940 | .fromsec = { DATA_SECTIONS, NULL }, |
867 | .tosec = { ALL_EXIT_SECTIONS, NULL }, | 941 | .tosec = { ALL_EXIT_SECTIONS, NULL }, |
868 | .mismatch = DATA_TO_EXIT, | 942 | .mismatch = DATA_TO_ANY_EXIT, |
943 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
869 | }, | 944 | }, |
870 | /* Do not reference init code/data from devinit/cpuinit/meminit code/data */ | 945 | /* Do not reference init code/data from devinit/cpuinit/meminit code/data */ |
871 | { | 946 | { |
872 | .fromsec = { DEV_INIT_SECTIONS, CPU_INIT_SECTIONS, MEM_INIT_SECTIONS, NULL }, | 947 | .fromsec = { ALL_XXXINIT_SECTIONS, NULL }, |
873 | .tosec = { INIT_SECTIONS, NULL }, | 948 | .tosec = { INIT_SECTIONS, NULL }, |
874 | .mismatch = XXXINIT_TO_INIT, | 949 | .mismatch = XXXINIT_TO_SOME_INIT, |
950 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
875 | }, | 951 | }, |
876 | /* Do not reference cpuinit code/data from meminit code/data */ | 952 | /* Do not reference cpuinit code/data from meminit code/data */ |
877 | { | 953 | { |
878 | .fromsec = { MEM_INIT_SECTIONS, NULL }, | 954 | .fromsec = { MEM_INIT_SECTIONS, NULL }, |
879 | .tosec = { CPU_INIT_SECTIONS, NULL }, | 955 | .tosec = { CPU_INIT_SECTIONS, NULL }, |
880 | .mismatch = XXXINIT_TO_INIT, | 956 | .mismatch = XXXINIT_TO_SOME_INIT, |
957 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
881 | }, | 958 | }, |
882 | /* Do not reference meminit code/data from cpuinit code/data */ | 959 | /* Do not reference meminit code/data from cpuinit code/data */ |
883 | { | 960 | { |
884 | .fromsec = { CPU_INIT_SECTIONS, NULL }, | 961 | .fromsec = { CPU_INIT_SECTIONS, NULL }, |
885 | .tosec = { MEM_INIT_SECTIONS, NULL }, | 962 | .tosec = { MEM_INIT_SECTIONS, NULL }, |
886 | .mismatch = XXXINIT_TO_INIT, | 963 | .mismatch = XXXINIT_TO_SOME_INIT, |
964 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
887 | }, | 965 | }, |
888 | /* Do not reference exit code/data from devexit/cpuexit/memexit code/data */ | 966 | /* Do not reference exit code/data from devexit/cpuexit/memexit code/data */ |
889 | { | 967 | { |
890 | .fromsec = { DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS, NULL }, | 968 | .fromsec = { ALL_XXXEXIT_SECTIONS, NULL }, |
891 | .tosec = { EXIT_SECTIONS, NULL }, | 969 | .tosec = { EXIT_SECTIONS, NULL }, |
892 | .mismatch = XXXEXIT_TO_EXIT, | 970 | .mismatch = XXXEXIT_TO_SOME_EXIT, |
971 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
893 | }, | 972 | }, |
894 | /* Do not reference cpuexit code/data from memexit code/data */ | 973 | /* Do not reference cpuexit code/data from memexit code/data */ |
895 | { | 974 | { |
896 | .fromsec = { MEM_EXIT_SECTIONS, NULL }, | 975 | .fromsec = { MEM_EXIT_SECTIONS, NULL }, |
897 | .tosec = { CPU_EXIT_SECTIONS, NULL }, | 976 | .tosec = { CPU_EXIT_SECTIONS, NULL }, |
898 | .mismatch = XXXEXIT_TO_EXIT, | 977 | .mismatch = XXXEXIT_TO_SOME_EXIT, |
978 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
899 | }, | 979 | }, |
900 | /* Do not reference memexit code/data from cpuexit code/data */ | 980 | /* Do not reference memexit code/data from cpuexit code/data */ |
901 | { | 981 | { |
902 | .fromsec = { CPU_EXIT_SECTIONS, NULL }, | 982 | .fromsec = { CPU_EXIT_SECTIONS, NULL }, |
903 | .tosec = { MEM_EXIT_SECTIONS, NULL }, | 983 | .tosec = { MEM_EXIT_SECTIONS, NULL }, |
904 | .mismatch = XXXEXIT_TO_EXIT, | 984 | .mismatch = XXXEXIT_TO_SOME_EXIT, |
985 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
905 | }, | 986 | }, |
906 | /* Do not use exit code/data from init code */ | 987 | /* Do not use exit code/data from init code */ |
907 | { | 988 | { |
908 | .fromsec = { ALL_INIT_SECTIONS, NULL }, | 989 | .fromsec = { ALL_INIT_SECTIONS, NULL }, |
909 | .tosec = { ALL_EXIT_SECTIONS, NULL }, | 990 | .tosec = { ALL_EXIT_SECTIONS, NULL }, |
910 | .mismatch = INIT_TO_EXIT, | 991 | .mismatch = ANY_INIT_TO_ANY_EXIT, |
992 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
911 | }, | 993 | }, |
912 | /* Do not use init code/data from exit code */ | 994 | /* Do not use init code/data from exit code */ |
913 | { | 995 | { |
914 | .fromsec = { ALL_EXIT_SECTIONS, NULL }, | 996 | .fromsec = { ALL_EXIT_SECTIONS, NULL }, |
915 | .tosec = { ALL_INIT_SECTIONS, NULL }, | 997 | .tosec = { ALL_INIT_SECTIONS, NULL }, |
916 | .mismatch = EXIT_TO_INIT, | 998 | .mismatch = ANY_EXIT_TO_ANY_INIT, |
999 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
917 | }, | 1000 | }, |
918 | /* Do not export init/exit functions or data */ | 1001 | /* Do not export init/exit functions or data */ |
919 | { | 1002 | { |
920 | .fromsec = { "__ksymtab*", NULL }, | 1003 | .fromsec = { "__ksymtab*", NULL }, |
921 | .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, | 1004 | .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, |
922 | .mismatch = EXPORT_TO_INIT_EXIT | 1005 | .mismatch = EXPORT_TO_INIT_EXIT, |
1006 | .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, | ||
923 | } | 1007 | } |
924 | }; | 1008 | }; |
925 | 1009 | ||
926 | static int section_mismatch(const char *fromsec, const char *tosec) | 1010 | static const struct sectioncheck *section_mismatch( |
1011 | const char *fromsec, const char *tosec) | ||
927 | { | 1012 | { |
928 | int i; | 1013 | int i; |
929 | int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck); | 1014 | int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck); |
@@ -932,10 +1017,10 @@ static int section_mismatch(const char *fromsec, const char *tosec) | |||
932 | for (i = 0; i < elems; i++) { | 1017 | for (i = 0; i < elems; i++) { |
933 | if (match(fromsec, check->fromsec) && | 1018 | if (match(fromsec, check->fromsec) && |
934 | match(tosec, check->tosec)) | 1019 | match(tosec, check->tosec)) |
935 | return check->mismatch; | 1020 | return check; |
936 | check++; | 1021 | check++; |
937 | } | 1022 | } |
938 | return NO_MISMATCH; | 1023 | return NULL; |
939 | } | 1024 | } |
940 | 1025 | ||
941 | /** | 1026 | /** |
@@ -951,10 +1036,17 @@ static int section_mismatch(const char *fromsec, const char *tosec) | |||
951 | * fromsec = .data* | 1036 | * fromsec = .data* |
952 | * atsym =__param* | 1037 | * atsym =__param* |
953 | * | 1038 | * |
1039 | * Pattern 1a: | ||
1040 | * module_param_call() ops can refer to __init set function if permissions=0 | ||
1041 | * The pattern is identified by: | ||
1042 | * tosec = .init.text | ||
1043 | * fromsec = .data* | ||
1044 | * atsym = __param_ops_* | ||
1045 | * | ||
954 | * Pattern 2: | 1046 | * Pattern 2: |
955 | * Many drivers utilise a *driver container with references to | 1047 | * Many drivers utilise a *driver container with references to |
956 | * add, remove, probe functions etc. | 1048 | * add, remove, probe functions etc. |
957 | * These functions may often be marked __init and we do not want to | 1049 | * These functions may often be marked __devinit and we do not want to |
958 | * warn here. | 1050 | * warn here. |
959 | * the pattern is identified by: | 1051 | * the pattern is identified by: |
960 | * tosec = init or exit section | 1052 | * tosec = init or exit section |
@@ -975,7 +1067,8 @@ static int section_mismatch(const char *fromsec, const char *tosec) | |||
975 | * refsymname = __init_begin, _sinittext, _einittext | 1067 | * refsymname = __init_begin, _sinittext, _einittext |
976 | * | 1068 | * |
977 | **/ | 1069 | **/ |
978 | static int secref_whitelist(const char *fromsec, const char *fromsym, | 1070 | static int secref_whitelist(const struct sectioncheck *mismatch, |
1071 | const char *fromsec, const char *fromsym, | ||
979 | const char *tosec, const char *tosym) | 1072 | const char *tosec, const char *tosym) |
980 | { | 1073 | { |
981 | /* Check for pattern 1 */ | 1074 | /* Check for pattern 1 */ |
@@ -984,10 +1077,16 @@ static int secref_whitelist(const char *fromsec, const char *fromsym, | |||
984 | (strncmp(fromsym, "__param", strlen("__param")) == 0)) | 1077 | (strncmp(fromsym, "__param", strlen("__param")) == 0)) |
985 | return 0; | 1078 | return 0; |
986 | 1079 | ||
1080 | /* Check for pattern 1a */ | ||
1081 | if (strcmp(tosec, ".init.text") == 0 && | ||
1082 | match(fromsec, data_sections) && | ||
1083 | (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0)) | ||
1084 | return 0; | ||
1085 | |||
987 | /* Check for pattern 2 */ | 1086 | /* Check for pattern 2 */ |
988 | if (match(tosec, init_exit_sections) && | 1087 | if (match(tosec, init_exit_sections) && |
989 | match(fromsec, data_sections) && | 1088 | match(fromsec, data_sections) && |
990 | match(fromsym, symbol_white_list)) | 1089 | match(fromsym, mismatch->symbol_white_list)) |
991 | return 0; | 1090 | return 0; |
992 | 1091 | ||
993 | /* Check for pattern 3 */ | 1092 | /* Check for pattern 3 */ |
@@ -1016,11 +1115,14 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr, | |||
1016 | Elf_Sym *near = NULL; | 1115 | Elf_Sym *near = NULL; |
1017 | Elf64_Sword distance = 20; | 1116 | Elf64_Sword distance = 20; |
1018 | Elf64_Sword d; | 1117 | Elf64_Sword d; |
1118 | unsigned int relsym_secindex; | ||
1019 | 1119 | ||
1020 | if (relsym->st_name != 0) | 1120 | if (relsym->st_name != 0) |
1021 | return relsym; | 1121 | return relsym; |
1122 | |||
1123 | relsym_secindex = get_secindex(elf, relsym); | ||
1022 | for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { | 1124 | for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { |
1023 | if (sym->st_shndx != relsym->st_shndx) | 1125 | if (get_secindex(elf, sym) != relsym_secindex) |
1024 | continue; | 1126 | continue; |
1025 | if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) | 1127 | if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) |
1026 | continue; | 1128 | continue; |
@@ -1082,9 +1184,9 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr, | |||
1082 | for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { | 1184 | for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { |
1083 | const char *symsec; | 1185 | const char *symsec; |
1084 | 1186 | ||
1085 | if (sym->st_shndx >= SHN_LORESERVE) | 1187 | if (is_shndx_special(sym->st_shndx)) |
1086 | continue; | 1188 | continue; |
1087 | symsec = sec_name(elf, sym->st_shndx); | 1189 | symsec = sec_name(elf, get_secindex(elf, sym)); |
1088 | if (strcmp(symsec, sec) != 0) | 1190 | if (strcmp(symsec, sec) != 0) |
1089 | continue; | 1191 | continue; |
1090 | if (!is_valid_name(elf, sym)) | 1192 | if (!is_valid_name(elf, sym)) |
@@ -1107,6 +1209,9 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr, | |||
1107 | * .cpuinit.data => __cpudata | 1209 | * .cpuinit.data => __cpudata |
1108 | * .memexitconst => __memconst | 1210 | * .memexitconst => __memconst |
1109 | * etc. | 1211 | * etc. |
1212 | * | ||
1213 | * The memory of returned value has been allocated on a heap. The user of this | ||
1214 | * method should free it after usage. | ||
1110 | */ | 1215 | */ |
1111 | static char *sec2annotation(const char *s) | 1216 | static char *sec2annotation(const char *s) |
1112 | { | 1217 | { |
@@ -1129,9 +1234,9 @@ static char *sec2annotation(const char *s) | |||
1129 | strcat(p, "data "); | 1234 | strcat(p, "data "); |
1130 | else | 1235 | else |
1131 | strcat(p, " "); | 1236 | strcat(p, " "); |
1132 | return r; /* we leak her but we do not care */ | 1237 | return r; |
1133 | } else { | 1238 | } else { |
1134 | return ""; | 1239 | return strdup(""); |
1135 | } | 1240 | } |
1136 | } | 1241 | } |
1137 | 1242 | ||
@@ -1148,7 +1253,8 @@ static int is_function(Elf_Sym *sym) | |||
1148 | * Try to find symbols near it so user can find it. | 1253 | * Try to find symbols near it so user can find it. |
1149 | * Check whitelist before warning - it may be a false positive. | 1254 | * Check whitelist before warning - it may be a false positive. |
1150 | */ | 1255 | */ |
1151 | static void report_sec_mismatch(const char *modname, enum mismatch mismatch, | 1256 | static void report_sec_mismatch(const char *modname, |
1257 | const struct sectioncheck *mismatch, | ||
1152 | const char *fromsec, | 1258 | const char *fromsec, |
1153 | unsigned long long fromaddr, | 1259 | unsigned long long fromaddr, |
1154 | const char *fromsym, | 1260 | const char *fromsym, |
@@ -1158,6 +1264,8 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch, | |||
1158 | { | 1264 | { |
1159 | const char *from, *from_p; | 1265 | const char *from, *from_p; |
1160 | const char *to, *to_p; | 1266 | const char *to, *to_p; |
1267 | char *prl_from; | ||
1268 | char *prl_to; | ||
1161 | 1269 | ||
1162 | switch (from_is_func) { | 1270 | switch (from_is_func) { |
1163 | case 0: from = "variable"; from_p = ""; break; | 1271 | case 0: from = "variable"; from_p = ""; break; |
@@ -1179,64 +1287,80 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch, | |||
1179 | modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec, | 1287 | modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec, |
1180 | tosym, to_p); | 1288 | tosym, to_p); |
1181 | 1289 | ||
1182 | switch (mismatch) { | 1290 | switch (mismatch->mismatch) { |
1183 | case TEXT_TO_INIT: | 1291 | case TEXT_TO_ANY_INIT: |
1292 | prl_from = sec2annotation(fromsec); | ||
1293 | prl_to = sec2annotation(tosec); | ||
1184 | fprintf(stderr, | 1294 | fprintf(stderr, |
1185 | "The function %s%s() references\n" | 1295 | "The function %s%s() references\n" |
1186 | "the %s %s%s%s.\n" | 1296 | "the %s %s%s%s.\n" |
1187 | "This is often because %s lacks a %s\n" | 1297 | "This is often because %s lacks a %s\n" |
1188 | "annotation or the annotation of %s is wrong.\n", | 1298 | "annotation or the annotation of %s is wrong.\n", |
1189 | sec2annotation(fromsec), fromsym, | 1299 | prl_from, fromsym, |
1190 | to, sec2annotation(tosec), tosym, to_p, | 1300 | to, prl_to, tosym, to_p, |
1191 | fromsym, sec2annotation(tosec), tosym); | 1301 | fromsym, prl_to, tosym); |
1302 | free(prl_from); | ||
1303 | free(prl_to); | ||
1192 | break; | 1304 | break; |
1193 | case DATA_TO_INIT: { | 1305 | case DATA_TO_ANY_INIT: { |
1194 | const char **s = symbol_white_list; | 1306 | prl_to = sec2annotation(tosec); |
1307 | const char *const *s = mismatch->symbol_white_list; | ||
1195 | fprintf(stderr, | 1308 | fprintf(stderr, |
1196 | "The variable %s references\n" | 1309 | "The variable %s references\n" |
1197 | "the %s %s%s%s\n" | 1310 | "the %s %s%s%s\n" |
1198 | "If the reference is valid then annotate the\n" | 1311 | "If the reference is valid then annotate the\n" |
1199 | "variable with __init* or __refdata (see linux/init.h) " | 1312 | "variable with __init* or __refdata (see linux/init.h) " |
1200 | "or name the variable:\n", | 1313 | "or name the variable:\n", |
1201 | fromsym, to, sec2annotation(tosec), tosym, to_p); | 1314 | fromsym, to, prl_to, tosym, to_p); |
1202 | while (*s) | 1315 | while (*s) |
1203 | fprintf(stderr, "%s, ", *s++); | 1316 | fprintf(stderr, "%s, ", *s++); |
1204 | fprintf(stderr, "\n"); | 1317 | fprintf(stderr, "\n"); |
1318 | free(prl_to); | ||
1205 | break; | 1319 | break; |
1206 | } | 1320 | } |
1207 | case TEXT_TO_EXIT: | 1321 | case TEXT_TO_ANY_EXIT: |
1322 | prl_to = sec2annotation(tosec); | ||
1208 | fprintf(stderr, | 1323 | fprintf(stderr, |
1209 | "The function %s() references a %s in an exit section.\n" | 1324 | "The function %s() references a %s in an exit section.\n" |
1210 | "Often the %s %s%s has valid usage outside the exit section\n" | 1325 | "Often the %s %s%s has valid usage outside the exit section\n" |
1211 | "and the fix is to remove the %sannotation of %s.\n", | 1326 | "and the fix is to remove the %sannotation of %s.\n", |
1212 | fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym); | 1327 | fromsym, to, to, tosym, to_p, prl_to, tosym); |
1328 | free(prl_to); | ||
1213 | break; | 1329 | break; |
1214 | case DATA_TO_EXIT: { | 1330 | case DATA_TO_ANY_EXIT: { |
1215 | const char **s = symbol_white_list; | 1331 | prl_to = sec2annotation(tosec); |
1332 | const char *const *s = mismatch->symbol_white_list; | ||
1216 | fprintf(stderr, | 1333 | fprintf(stderr, |
1217 | "The variable %s references\n" | 1334 | "The variable %s references\n" |
1218 | "the %s %s%s%s\n" | 1335 | "the %s %s%s%s\n" |
1219 | "If the reference is valid then annotate the\n" | 1336 | "If the reference is valid then annotate the\n" |
1220 | "variable with __exit* (see linux/init.h) or " | 1337 | "variable with __exit* (see linux/init.h) or " |
1221 | "name the variable:\n", | 1338 | "name the variable:\n", |
1222 | fromsym, to, sec2annotation(tosec), tosym, to_p); | 1339 | fromsym, to, prl_to, tosym, to_p); |
1223 | while (*s) | 1340 | while (*s) |
1224 | fprintf(stderr, "%s, ", *s++); | 1341 | fprintf(stderr, "%s, ", *s++); |
1225 | fprintf(stderr, "\n"); | 1342 | fprintf(stderr, "\n"); |
1343 | free(prl_to); | ||
1226 | break; | 1344 | break; |
1227 | } | 1345 | } |
1228 | case XXXINIT_TO_INIT: | 1346 | case XXXINIT_TO_SOME_INIT: |
1229 | case XXXEXIT_TO_EXIT: | 1347 | case XXXEXIT_TO_SOME_EXIT: |
1348 | prl_from = sec2annotation(fromsec); | ||
1349 | prl_to = sec2annotation(tosec); | ||
1230 | fprintf(stderr, | 1350 | fprintf(stderr, |
1231 | "The %s %s%s%s references\n" | 1351 | "The %s %s%s%s references\n" |
1232 | "a %s %s%s%s.\n" | 1352 | "a %s %s%s%s.\n" |
1233 | "If %s is only used by %s then\n" | 1353 | "If %s is only used by %s then\n" |
1234 | "annotate %s with a matching annotation.\n", | 1354 | "annotate %s with a matching annotation.\n", |
1235 | from, sec2annotation(fromsec), fromsym, from_p, | 1355 | from, prl_from, fromsym, from_p, |
1236 | to, sec2annotation(tosec), tosym, to_p, | 1356 | to, prl_to, tosym, to_p, |
1237 | tosym, fromsym, tosym); | 1357 | tosym, fromsym, tosym); |
1358 | free(prl_from); | ||
1359 | free(prl_to); | ||
1238 | break; | 1360 | break; |
1239 | case INIT_TO_EXIT: | 1361 | case ANY_INIT_TO_ANY_EXIT: |
1362 | prl_from = sec2annotation(fromsec); | ||
1363 | prl_to = sec2annotation(tosec); | ||
1240 | fprintf(stderr, | 1364 | fprintf(stderr, |
1241 | "The %s %s%s%s references\n" | 1365 | "The %s %s%s%s references\n" |
1242 | "a %s %s%s%s.\n" | 1366 | "a %s %s%s%s.\n" |
@@ -1245,11 +1369,15 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch, | |||
1245 | "uses functionality in the exit path.\n" | 1369 | "uses functionality in the exit path.\n" |
1246 | "The fix is often to remove the %sannotation of\n" | 1370 | "The fix is often to remove the %sannotation of\n" |
1247 | "%s%s so it may be used outside an exit section.\n", | 1371 | "%s%s so it may be used outside an exit section.\n", |
1248 | from, sec2annotation(fromsec), fromsym, from_p, | 1372 | from, prl_from, fromsym, from_p, |
1249 | to, sec2annotation(tosec), tosym, to_p, | 1373 | to, prl_to, tosym, to_p, |
1250 | sec2annotation(tosec), tosym, to_p); | 1374 | prl_to, tosym, to_p); |
1375 | free(prl_from); | ||
1376 | free(prl_to); | ||
1251 | break; | 1377 | break; |
1252 | case EXIT_TO_INIT: | 1378 | case ANY_EXIT_TO_ANY_INIT: |
1379 | prl_from = sec2annotation(fromsec); | ||
1380 | prl_to = sec2annotation(tosec); | ||
1253 | fprintf(stderr, | 1381 | fprintf(stderr, |
1254 | "The %s %s%s%s references\n" | 1382 | "The %s %s%s%s references\n" |
1255 | "a %s %s%s%s.\n" | 1383 | "a %s %s%s%s.\n" |
@@ -1258,18 +1386,20 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch, | |||
1258 | "uses functionality in the init path.\n" | 1386 | "uses functionality in the init path.\n" |
1259 | "The fix is often to remove the %sannotation of\n" | 1387 | "The fix is often to remove the %sannotation of\n" |
1260 | "%s%s so it may be used outside an init section.\n", | 1388 | "%s%s so it may be used outside an init section.\n", |
1261 | from, sec2annotation(fromsec), fromsym, from_p, | 1389 | from, prl_from, fromsym, from_p, |
1262 | to, sec2annotation(tosec), tosym, to_p, | 1390 | to, prl_to, tosym, to_p, |
1263 | sec2annotation(tosec), tosym, to_p); | 1391 | prl_to, tosym, to_p); |
1392 | free(prl_from); | ||
1393 | free(prl_to); | ||
1264 | break; | 1394 | break; |
1265 | case EXPORT_TO_INIT_EXIT: | 1395 | case EXPORT_TO_INIT_EXIT: |
1396 | prl_to = sec2annotation(tosec); | ||
1266 | fprintf(stderr, | 1397 | fprintf(stderr, |
1267 | "The symbol %s is exported and annotated %s\n" | 1398 | "The symbol %s is exported and annotated %s\n" |
1268 | "Fix this by removing the %sannotation of %s " | 1399 | "Fix this by removing the %sannotation of %s " |
1269 | "or drop the export.\n", | 1400 | "or drop the export.\n", |
1270 | tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); | 1401 | tosym, prl_to, prl_to, tosym); |
1271 | case NO_MISMATCH: | 1402 | free(prl_to); |
1272 | /* To get warnings on missing members */ | ||
1273 | break; | 1403 | break; |
1274 | } | 1404 | } |
1275 | fprintf(stderr, "\n"); | 1405 | fprintf(stderr, "\n"); |
@@ -1279,11 +1409,11 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf, | |||
1279 | Elf_Rela *r, Elf_Sym *sym, const char *fromsec) | 1409 | Elf_Rela *r, Elf_Sym *sym, const char *fromsec) |
1280 | { | 1410 | { |
1281 | const char *tosec; | 1411 | const char *tosec; |
1282 | enum mismatch mismatch; | 1412 | const struct sectioncheck *mismatch; |
1283 | 1413 | ||
1284 | tosec = sec_name(elf, sym->st_shndx); | 1414 | tosec = sec_name(elf, get_secindex(elf, sym)); |
1285 | mismatch = section_mismatch(fromsec, tosec); | 1415 | mismatch = section_mismatch(fromsec, tosec); |
1286 | if (mismatch != NO_MISMATCH) { | 1416 | if (mismatch) { |
1287 | Elf_Sym *to; | 1417 | Elf_Sym *to; |
1288 | Elf_Sym *from; | 1418 | Elf_Sym *from; |
1289 | const char *tosym; | 1419 | const char *tosym; |
@@ -1295,7 +1425,8 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf, | |||
1295 | tosym = sym_name(elf, to); | 1425 | tosym = sym_name(elf, to); |
1296 | 1426 | ||
1297 | /* check whitelist - we may ignore it */ | 1427 | /* check whitelist - we may ignore it */ |
1298 | if (secref_whitelist(fromsec, fromsym, tosec, tosym)) { | 1428 | if (secref_whitelist(mismatch, |
1429 | fromsec, fromsym, tosec, tosym)) { | ||
1299 | report_sec_mismatch(modname, mismatch, | 1430 | report_sec_mismatch(modname, mismatch, |
1300 | fromsec, r->r_offset, fromsym, | 1431 | fromsec, r->r_offset, fromsym, |
1301 | is_function(from), tosec, tosym, | 1432 | is_function(from), tosec, tosym, |
@@ -1308,10 +1439,10 @@ static unsigned int *reloc_location(struct elf_info *elf, | |||
1308 | Elf_Shdr *sechdr, Elf_Rela *r) | 1439 | Elf_Shdr *sechdr, Elf_Rela *r) |
1309 | { | 1440 | { |
1310 | Elf_Shdr *sechdrs = elf->sechdrs; | 1441 | Elf_Shdr *sechdrs = elf->sechdrs; |
1311 | int section = sechdr->sh_info; | 1442 | int section = shndx2secindex(sechdr->sh_info); |
1312 | 1443 | ||
1313 | return (void *)elf->hdr + sechdrs[section].sh_offset + | 1444 | return (void *)elf->hdr + sechdrs[section].sh_offset + |
1314 | (r->r_offset - sechdrs[section].sh_addr); | 1445 | r->r_offset; |
1315 | } | 1446 | } |
1316 | 1447 | ||
1317 | static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) | 1448 | static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) |
@@ -1416,7 +1547,7 @@ static void section_rela(const char *modname, struct elf_info *elf, | |||
1416 | r.r_addend = TO_NATIVE(rela->r_addend); | 1547 | r.r_addend = TO_NATIVE(rela->r_addend); |
1417 | sym = elf->symtab_start + r_sym; | 1548 | sym = elf->symtab_start + r_sym; |
1418 | /* Skip special sections */ | 1549 | /* Skip special sections */ |
1419 | if (sym->st_shndx >= SHN_LORESERVE) | 1550 | if (is_shndx_special(sym->st_shndx)) |
1420 | continue; | 1551 | continue; |
1421 | check_section_mismatch(modname, elf, &r, sym, fromsec); | 1552 | check_section_mismatch(modname, elf, &r, sym, fromsec); |
1422 | } | 1553 | } |
@@ -1474,7 +1605,7 @@ static void section_rel(const char *modname, struct elf_info *elf, | |||
1474 | } | 1605 | } |
1475 | sym = elf->symtab_start + r_sym; | 1606 | sym = elf->symtab_start + r_sym; |
1476 | /* Skip special sections */ | 1607 | /* Skip special sections */ |
1477 | if (sym->st_shndx >= SHN_LORESERVE) | 1608 | if (is_shndx_special(sym->st_shndx)) |
1478 | continue; | 1609 | continue; |
1479 | check_section_mismatch(modname, elf, &r, sym, fromsec); | 1610 | check_section_mismatch(modname, elf, &r, sym, fromsec); |
1480 | } | 1611 | } |
@@ -1499,7 +1630,7 @@ static void check_sec_ref(struct module *mod, const char *modname, | |||
1499 | Elf_Shdr *sechdrs = elf->sechdrs; | 1630 | Elf_Shdr *sechdrs = elf->sechdrs; |
1500 | 1631 | ||
1501 | /* Walk through all sections */ | 1632 | /* Walk through all sections */ |
1502 | for (i = 0; i < elf->hdr->e_shnum; i++) { | 1633 | for (i = 0; i < elf->num_sections; i++) { |
1503 | check_section(modname, elf, &elf->sechdrs[i]); | 1634 | check_section(modname, elf, &elf->sechdrs[i]); |
1504 | /* We want to process only relocation sections and not .init */ | 1635 | /* We want to process only relocation sections and not .init */ |
1505 | if (sechdrs[i].sh_type == SHT_RELA) | 1636 | if (sechdrs[i].sh_type == SHT_RELA) |
@@ -1509,62 +1640,6 @@ static void check_sec_ref(struct module *mod, const char *modname, | |||
1509 | } | 1640 | } |
1510 | } | 1641 | } |
1511 | 1642 | ||
1512 | static void get_markers(struct elf_info *info, struct module *mod) | ||
1513 | { | ||
1514 | const Elf_Shdr *sh = &info->sechdrs[info->markers_strings_sec]; | ||
1515 | const char *strings = (const char *) info->hdr + sh->sh_offset; | ||
1516 | const Elf_Sym *sym, *first_sym, *last_sym; | ||
1517 | size_t n; | ||
1518 | |||
1519 | if (!info->markers_strings_sec) | ||
1520 | return; | ||
1521 | |||
1522 | /* | ||
1523 | * First count the strings. We look for all the symbols defined | ||
1524 | * in the __markers_strings section named __mstrtab_*. For | ||
1525 | * these local names, the compiler puts a random .NNN suffix on, | ||
1526 | * so the names don't correspond exactly. | ||
1527 | */ | ||
1528 | first_sym = last_sym = NULL; | ||
1529 | n = 0; | ||
1530 | for (sym = info->symtab_start; sym < info->symtab_stop; sym++) | ||
1531 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT && | ||
1532 | sym->st_shndx == info->markers_strings_sec && | ||
1533 | !strncmp(info->strtab + sym->st_name, | ||
1534 | "__mstrtab_", sizeof "__mstrtab_" - 1)) { | ||
1535 | if (first_sym == NULL) | ||
1536 | first_sym = sym; | ||
1537 | last_sym = sym; | ||
1538 | ++n; | ||
1539 | } | ||
1540 | |||
1541 | if (n == 0) | ||
1542 | return; | ||
1543 | |||
1544 | /* | ||
1545 | * Now collect each name and format into a line for the output. | ||
1546 | * Lines look like: | ||
1547 | * marker_name vmlinux marker %s format %d | ||
1548 | * The format string after the second \t can use whitespace. | ||
1549 | */ | ||
1550 | mod->markers = NOFAIL(malloc(sizeof mod->markers[0] * n)); | ||
1551 | mod->nmarkers = n; | ||
1552 | |||
1553 | n = 0; | ||
1554 | for (sym = first_sym; sym <= last_sym; sym++) | ||
1555 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT && | ||
1556 | sym->st_shndx == info->markers_strings_sec && | ||
1557 | !strncmp(info->strtab + sym->st_name, | ||
1558 | "__mstrtab_", sizeof "__mstrtab_" - 1)) { | ||
1559 | const char *name = strings + sym->st_value; | ||
1560 | const char *fmt = strchr(name, '\0') + 1; | ||
1561 | char *line = NULL; | ||
1562 | asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt); | ||
1563 | NOFAIL(line); | ||
1564 | mod->markers[n++] = line; | ||
1565 | } | ||
1566 | } | ||
1567 | |||
1568 | static void read_symbols(char *modname) | 1643 | static void read_symbols(char *modname) |
1569 | { | 1644 | { |
1570 | const char *symname; | 1645 | const char *symname; |
@@ -1620,8 +1695,6 @@ static void read_symbols(char *modname) | |||
1620 | get_src_version(modname, mod->srcversion, | 1695 | get_src_version(modname, mod->srcversion, |
1621 | sizeof(mod->srcversion)-1); | 1696 | sizeof(mod->srcversion)-1); |
1622 | 1697 | ||
1623 | get_markers(&info, mod); | ||
1624 | |||
1625 | parse_elf_finish(&info); | 1698 | parse_elf_finish(&info); |
1626 | 1699 | ||
1627 | /* Our trick to get versioning for module struct etc. - it's | 1700 | /* Our trick to get versioning for module struct etc. - it's |
@@ -1746,7 +1819,7 @@ static void add_header(struct buffer *b, struct module *mod) | |||
1746 | buf_printf(b, "};\n"); | 1819 | buf_printf(b, "};\n"); |
1747 | } | 1820 | } |
1748 | 1821 | ||
1749 | void add_staging_flag(struct buffer *b, const char *name) | 1822 | static void add_staging_flag(struct buffer *b, const char *name) |
1750 | { | 1823 | { |
1751 | static const char *staging_dir = "drivers/staging"; | 1824 | static const char *staging_dir = "drivers/staging"; |
1752 | 1825 | ||
@@ -1976,96 +2049,6 @@ static void write_dump(const char *fname) | |||
1976 | write_if_changed(&buf, fname); | 2049 | write_if_changed(&buf, fname); |
1977 | } | 2050 | } |
1978 | 2051 | ||
1979 | static void add_marker(struct module *mod, const char *name, const char *fmt) | ||
1980 | { | ||
1981 | char *line = NULL; | ||
1982 | asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt); | ||
1983 | NOFAIL(line); | ||
1984 | |||
1985 | mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) * | ||
1986 | sizeof mod->markers[0]))); | ||
1987 | mod->markers[mod->nmarkers++] = line; | ||
1988 | } | ||
1989 | |||
1990 | static void read_markers(const char *fname) | ||
1991 | { | ||
1992 | unsigned long size, pos = 0; | ||
1993 | void *file = grab_file(fname, &size); | ||
1994 | char *line; | ||
1995 | |||
1996 | if (!file) /* No old markers, silently ignore */ | ||
1997 | return; | ||
1998 | |||
1999 | while ((line = get_next_line(&pos, file, size))) { | ||
2000 | char *marker, *modname, *fmt; | ||
2001 | struct module *mod; | ||
2002 | |||
2003 | marker = line; | ||
2004 | modname = strchr(marker, '\t'); | ||
2005 | if (!modname) | ||
2006 | goto fail; | ||
2007 | *modname++ = '\0'; | ||
2008 | fmt = strchr(modname, '\t'); | ||
2009 | if (!fmt) | ||
2010 | goto fail; | ||
2011 | *fmt++ = '\0'; | ||
2012 | if (*marker == '\0' || *modname == '\0') | ||
2013 | goto fail; | ||
2014 | |||
2015 | mod = find_module(modname); | ||
2016 | if (!mod) { | ||
2017 | mod = new_module(modname); | ||
2018 | mod->skip = 1; | ||
2019 | } | ||
2020 | if (is_vmlinux(modname)) { | ||
2021 | have_vmlinux = 1; | ||
2022 | mod->skip = 0; | ||
2023 | } | ||
2024 | |||
2025 | if (!mod->skip) | ||
2026 | add_marker(mod, marker, fmt); | ||
2027 | } | ||
2028 | release_file(file, size); | ||
2029 | return; | ||
2030 | fail: | ||
2031 | fatal("parse error in markers list file\n"); | ||
2032 | } | ||
2033 | |||
2034 | static int compare_strings(const void *a, const void *b) | ||
2035 | { | ||
2036 | return strcmp(*(const char **) a, *(const char **) b); | ||
2037 | } | ||
2038 | |||
2039 | static void write_markers(const char *fname) | ||
2040 | { | ||
2041 | struct buffer buf = { }; | ||
2042 | struct module *mod; | ||
2043 | size_t i; | ||
2044 | |||
2045 | for (mod = modules; mod; mod = mod->next) | ||
2046 | if ((!external_module || !mod->skip) && mod->markers != NULL) { | ||
2047 | /* | ||
2048 | * Sort the strings so we can skip duplicates when | ||
2049 | * we write them out. | ||
2050 | */ | ||
2051 | qsort(mod->markers, mod->nmarkers, | ||
2052 | sizeof mod->markers[0], &compare_strings); | ||
2053 | for (i = 0; i < mod->nmarkers; ++i) { | ||
2054 | char *line = mod->markers[i]; | ||
2055 | buf_write(&buf, line, strlen(line)); | ||
2056 | while (i + 1 < mod->nmarkers && | ||
2057 | !strcmp(mod->markers[i], | ||
2058 | mod->markers[i + 1])) | ||
2059 | free(mod->markers[i++]); | ||
2060 | free(mod->markers[i]); | ||
2061 | } | ||
2062 | free(mod->markers); | ||
2063 | mod->markers = NULL; | ||
2064 | } | ||
2065 | |||
2066 | write_if_changed(&buf, fname); | ||
2067 | } | ||
2068 | |||
2069 | struct ext_sym_list { | 2052 | struct ext_sym_list { |
2070 | struct ext_sym_list *next; | 2053 | struct ext_sym_list *next; |
2071 | const char *file; | 2054 | const char *file; |
@@ -2077,8 +2060,6 @@ int main(int argc, char **argv) | |||
2077 | struct buffer buf = { }; | 2060 | struct buffer buf = { }; |
2078 | char *kernel_read = NULL, *module_read = NULL; | 2061 | char *kernel_read = NULL, *module_read = NULL; |
2079 | char *dump_write = NULL; | 2062 | char *dump_write = NULL; |
2080 | char *markers_read = NULL; | ||
2081 | char *markers_write = NULL; | ||
2082 | int opt; | 2063 | int opt; |
2083 | int err; | 2064 | int err; |
2084 | struct ext_sym_list *extsym_iter; | 2065 | struct ext_sym_list *extsym_iter; |
@@ -2122,12 +2103,6 @@ int main(int argc, char **argv) | |||
2122 | case 'w': | 2103 | case 'w': |
2123 | warn_unresolved = 1; | 2104 | warn_unresolved = 1; |
2124 | break; | 2105 | break; |
2125 | case 'M': | ||
2126 | markers_write = optarg; | ||
2127 | break; | ||
2128 | case 'K': | ||
2129 | markers_read = optarg; | ||
2130 | break; | ||
2131 | default: | 2106 | default: |
2132 | exit(1); | 2107 | exit(1); |
2133 | } | 2108 | } |
@@ -2182,11 +2157,5 @@ int main(int argc, char **argv) | |||
2182 | "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", | 2157 | "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", |
2183 | sec_mismatch_count); | 2158 | sec_mismatch_count); |
2184 | 2159 | ||
2185 | if (markers_read) | ||
2186 | read_markers(markers_read); | ||
2187 | |||
2188 | if (markers_write) | ||
2189 | write_markers(markers_write); | ||
2190 | |||
2191 | return err; | 2160 | return err; |
2192 | } | 2161 | } |