aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mod
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/mod')
-rw-r--r--scripts/mod/file2alias.c2
-rw-r--r--scripts/mod/modpost.c168
2 files changed, 94 insertions, 76 deletions
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index a3344285ccf4..40e0045876ee 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -641,7 +641,7 @@ static int do_virtio_entry(const char *filename, struct virtio_device_id *id,
641 id->vendor = TO_NATIVE(id->vendor); 641 id->vendor = TO_NATIVE(id->vendor);
642 642
643 strcpy(alias, "virtio:"); 643 strcpy(alias, "virtio:");
644 ADD(alias, "d", 1, id->device); 644 ADD(alias, "d", id->device != VIRTIO_DEV_ANY_ID, id->device);
645 ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor); 645 ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor);
646 646
647 add_wildcard(alias); 647 add_wildcard(alias);
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index df6e6286a065..4522948a012e 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -384,11 +384,19 @@ static int parse_elf(struct elf_info *info, const char *filename)
384 return 0; 384 return 0;
385 } 385 }
386 /* Fix endianness in ELF header */ 386 /* Fix endianness in ELF header */
387 hdr->e_shoff = TO_NATIVE(hdr->e_shoff); 387 hdr->e_type = TO_NATIVE(hdr->e_type);
388 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); 388 hdr->e_machine = TO_NATIVE(hdr->e_machine);
389 hdr->e_shnum = TO_NATIVE(hdr->e_shnum); 389 hdr->e_version = TO_NATIVE(hdr->e_version);
390 hdr->e_machine = TO_NATIVE(hdr->e_machine); 390 hdr->e_entry = TO_NATIVE(hdr->e_entry);
391 hdr->e_type = TO_NATIVE(hdr->e_type); 391 hdr->e_phoff = TO_NATIVE(hdr->e_phoff);
392 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
393 hdr->e_flags = TO_NATIVE(hdr->e_flags);
394 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize);
395 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize);
396 hdr->e_phnum = TO_NATIVE(hdr->e_phnum);
397 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize);
398 hdr->e_shnum = TO_NATIVE(hdr->e_shnum);
399 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
392 sechdrs = (void *)hdr + hdr->e_shoff; 400 sechdrs = (void *)hdr + hdr->e_shoff;
393 info->sechdrs = sechdrs; 401 info->sechdrs = sechdrs;
394 402
@@ -402,13 +410,16 @@ static int parse_elf(struct elf_info *info, const char *filename)
402 410
403 /* Fix endianness in section headers */ 411 /* Fix endianness in section headers */
404 for (i = 0; i < hdr->e_shnum; i++) { 412 for (i = 0; i < hdr->e_shnum; i++) {
405 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type); 413 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name);
406 sechdrs[i].sh_offset = TO_NATIVE(sechdrs[i].sh_offset); 414 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type);
407 sechdrs[i].sh_size = TO_NATIVE(sechdrs[i].sh_size); 415 sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags);
408 sechdrs[i].sh_link = TO_NATIVE(sechdrs[i].sh_link); 416 sechdrs[i].sh_addr = TO_NATIVE(sechdrs[i].sh_addr);
409 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name); 417 sechdrs[i].sh_offset = TO_NATIVE(sechdrs[i].sh_offset);
410 sechdrs[i].sh_info = TO_NATIVE(sechdrs[i].sh_info); 418 sechdrs[i].sh_size = TO_NATIVE(sechdrs[i].sh_size);
411 sechdrs[i].sh_addr = TO_NATIVE(sechdrs[i].sh_addr); 419 sechdrs[i].sh_link = TO_NATIVE(sechdrs[i].sh_link);
420 sechdrs[i].sh_info = TO_NATIVE(sechdrs[i].sh_info);
421 sechdrs[i].sh_addralign = TO_NATIVE(sechdrs[i].sh_addralign);
422 sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize);
412 } 423 }
413 /* Find symbol table. */ 424 /* Find symbol table. */
414 for (i = 1; i < hdr->e_shnum; i++) { 425 for (i = 1; i < hdr->e_shnum; i++) {
@@ -716,46 +727,44 @@ int match(const char *sym, const char * const pat[])
716 727
717/* sections that we do not want to do full section mismatch check on */ 728/* sections that we do not want to do full section mismatch check on */
718static const char *section_white_list[] = 729static const char *section_white_list[] =
719 { ".debug*", ".stab*", ".note*", ".got*", ".toc*", NULL }; 730{
731 ".comment*",
732 ".debug*",
733 ".mdebug*", /* alpha, score, mips etc. */
734 ".pdr", /* alpha, score, mips etc. */
735 ".stab*",
736 ".note*",
737 ".got*",
738 ".toc*",
739 NULL
740};
720 741
721/* 742/*
722 * Is this section one we do not want to check? 743 * This is used to find sections missing the SHF_ALLOC flag.
723 * This is often debug sections.
724 * If we are going to check this section then
725 * test if section name ends with a dot and a number.
726 * This is used to find sections where the linker have
727 * appended a dot-number to make the name unique.
728 * The cause of this is often a section specified in assembler 744 * The cause of this is often a section specified in assembler
729 * without "ax" / "aw" and the same section used in .c 745 * without "ax" / "aw".
730 * code where gcc add these.
731 */ 746 */
732static int check_section(const char *modname, const char *sec) 747static void check_section(const char *modname, struct elf_info *elf,
733{ 748 Elf_Shdr *sechdr)
734 const char *e = sec + strlen(sec) - 1; 749{
735 if (match(sec, section_white_list)) 750 const char *sec = sech_name(elf, sechdr);
736 return 1; 751
737 752 if (sechdr->sh_type == SHT_PROGBITS &&
738 if (*e && isdigit(*e)) { 753 !(sechdr->sh_flags & SHF_ALLOC) &&
739 /* consume all digits */ 754 !match(sec, section_white_list)) {
740 while (*e && e != sec && isdigit(*e)) 755 warn("%s (%s): unexpected non-allocatable section.\n"
741 e--; 756 "Did you forget to use \"ax\"/\"aw\" in a .S file?\n"
742 if (*e == '.' && !strstr(sec, ".linkonce")) { 757 "Note that for example <linux/init.h> contains\n"
743 warn("%s (%s): unexpected section name.\n" 758 "section definitions for use in .S files.\n\n",
744 "The (.[number]+) following section name are " 759 modname, sec);
745 "ld generated and not expected.\n"
746 "Did you forget to use \"ax\"/\"aw\" "
747 "in a .S file?\n"
748 "Note that for example <linux/init.h> contains\n"
749 "section definitions for use in .S files.\n\n",
750 modname, sec);
751 }
752 } 760 }
753 return 0;
754} 761}
755 762
756 763
757 764
758#define ALL_INIT_DATA_SECTIONS \ 765#define ALL_INIT_DATA_SECTIONS \
766 ".init.setup$", ".init.rodata$", \
767 ".devinit.rodata$", ".cpuinit.rodata$", ".meminit.rodata$" \
759 ".init.data$", ".devinit.data$", ".cpuinit.data$", ".meminit.data$" 768 ".init.data$", ".devinit.data$", ".cpuinit.data$", ".meminit.data$"
760#define ALL_EXIT_DATA_SECTIONS \ 769#define ALL_EXIT_DATA_SECTIONS \
761 ".exit.data$", ".devexit.data$", ".cpuexit.data$", ".memexit.data$" 770 ".exit.data$", ".devexit.data$", ".cpuexit.data$", ".memexit.data$"
@@ -765,21 +774,23 @@ static int check_section(const char *modname, const char *sec)
765#define ALL_EXIT_TEXT_SECTIONS \ 774#define ALL_EXIT_TEXT_SECTIONS \
766 ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$" 775 ".exit.text$", ".devexit.text$", ".cpuexit.text$", ".memexit.text$"
767 776
768#define ALL_INIT_SECTIONS ALL_INIT_DATA_SECTIONS, ALL_INIT_TEXT_SECTIONS 777#define ALL_INIT_SECTIONS INIT_SECTIONS, DEV_INIT_SECTIONS, \
769#define ALL_EXIT_SECTIONS ALL_EXIT_DATA_SECTIONS, ALL_EXIT_TEXT_SECTIONS 778 CPU_INIT_SECTIONS, MEM_INIT_SECTIONS
779#define ALL_EXIT_SECTIONS EXIT_SECTIONS, DEV_EXIT_SECTIONS, \
780 CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS
770 781
771#define DATA_SECTIONS ".data$", ".data.rel$" 782#define DATA_SECTIONS ".data$", ".data.rel$"
772#define TEXT_SECTIONS ".text$" 783#define TEXT_SECTIONS ".text$"
773 784
774#define INIT_SECTIONS ".init.data$", ".init.text$" 785#define INIT_SECTIONS ".init.*"
775#define DEV_INIT_SECTIONS ".devinit.data$", ".devinit.text$" 786#define DEV_INIT_SECTIONS ".devinit.*"
776#define CPU_INIT_SECTIONS ".cpuinit.data$", ".cpuinit.text$" 787#define CPU_INIT_SECTIONS ".cpuinit.*"
777#define MEM_INIT_SECTIONS ".meminit.data$", ".meminit.text$" 788#define MEM_INIT_SECTIONS ".meminit.*"
778 789
779#define EXIT_SECTIONS ".exit.data$", ".exit.text$" 790#define EXIT_SECTIONS ".exit.*"
780#define DEV_EXIT_SECTIONS ".devexit.data$", ".devexit.text$" 791#define DEV_EXIT_SECTIONS ".devexit.*"
781#define CPU_EXIT_SECTIONS ".cpuexit.data$", ".cpuexit.text$" 792#define CPU_EXIT_SECTIONS ".cpuexit.*"
782#define MEM_EXIT_SECTIONS ".memexit.data$", ".memexit.text$" 793#define MEM_EXIT_SECTIONS ".memexit.*"
783 794
784/* init data sections */ 795/* init data sections */
785static const char *init_data_sections[] = { ALL_INIT_DATA_SECTIONS, NULL }; 796static const char *init_data_sections[] = { ALL_INIT_DATA_SECTIONS, NULL };
@@ -794,15 +805,6 @@ static const char *init_exit_sections[] =
794/* data section */ 805/* data section */
795static const char *data_sections[] = { DATA_SECTIONS, NULL }; 806static const char *data_sections[] = { DATA_SECTIONS, NULL };
796 807
797/* sections that may refer to an init/exit section with no warning */
798static const char *initref_sections[] =
799{
800 ".text.init.refok*",
801 ".exit.text.refok*",
802 ".data.init.refok*",
803 NULL
804};
805
806 808
807/* symbols in .data that may refer to init/exit sections */ 809/* symbols in .data that may refer to init/exit sections */
808static const char *symbol_white_list[] = 810static const char *symbol_white_list[] =
@@ -871,12 +873,36 @@ const struct sectioncheck sectioncheck[] = {
871 .tosec = { INIT_SECTIONS, NULL }, 873 .tosec = { INIT_SECTIONS, NULL },
872 .mismatch = XXXINIT_TO_INIT, 874 .mismatch = XXXINIT_TO_INIT,
873}, 875},
876/* Do not reference cpuinit code/data from meminit code/data */
877{
878 .fromsec = { MEM_INIT_SECTIONS, NULL },
879 .tosec = { CPU_INIT_SECTIONS, NULL },
880 .mismatch = XXXINIT_TO_INIT,
881},
882/* Do not reference meminit code/data from cpuinit code/data */
883{
884 .fromsec = { CPU_INIT_SECTIONS, NULL },
885 .tosec = { MEM_INIT_SECTIONS, NULL },
886 .mismatch = XXXINIT_TO_INIT,
887},
874/* Do not reference exit code/data from devexit/cpuexit/memexit code/data */ 888/* Do not reference exit code/data from devexit/cpuexit/memexit code/data */
875{ 889{
876 .fromsec = { DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS, NULL }, 890 .fromsec = { DEV_EXIT_SECTIONS, CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS, NULL },
877 .tosec = { EXIT_SECTIONS, NULL }, 891 .tosec = { EXIT_SECTIONS, NULL },
878 .mismatch = XXXEXIT_TO_EXIT, 892 .mismatch = XXXEXIT_TO_EXIT,
879}, 893},
894/* Do not reference cpuexit code/data from memexit code/data */
895{
896 .fromsec = { MEM_EXIT_SECTIONS, NULL },
897 .tosec = { CPU_EXIT_SECTIONS, NULL },
898 .mismatch = XXXEXIT_TO_EXIT,
899},
900/* Do not reference memexit code/data from cpuexit code/data */
901{
902 .fromsec = { CPU_EXIT_SECTIONS, NULL },
903 .tosec = { MEM_EXIT_SECTIONS, NULL },
904 .mismatch = XXXEXIT_TO_EXIT,
905},
880/* Do not use exit code/data from init code */ 906/* Do not use exit code/data from init code */
881{ 907{
882 .fromsec = { ALL_INIT_SECTIONS, NULL }, 908 .fromsec = { ALL_INIT_SECTIONS, NULL },
@@ -915,11 +941,6 @@ static int section_mismatch(const char *fromsec, const char *tosec)
915/** 941/**
916 * Whitelist to allow certain references to pass with no warning. 942 * Whitelist to allow certain references to pass with no warning.
917 * 943 *
918 * Pattern 0:
919 * Do not warn if funtion/data are marked with __init_refok/__initdata_refok.
920 * The pattern is identified by:
921 * fromsec = .text.init.refok* | .data.init.refok*
922 *
923 * Pattern 1: 944 * Pattern 1:
924 * If a module parameter is declared __initdata and permissions=0 945 * If a module parameter is declared __initdata and permissions=0
925 * then this is legal despite the warning generated. 946 * then this is legal despite the warning generated.
@@ -942,8 +963,7 @@ static int section_mismatch(const char *fromsec, const char *tosec)
942 * *probe_one, *_console, *_timer 963 * *probe_one, *_console, *_timer
943 * 964 *
944 * Pattern 3: 965 * Pattern 3:
945 * Whitelist all refereces from .text.head to .init.data 966 * Whitelist all references from .head.text to any init section
946 * Whitelist all refereces from .text.head to .init.text
947 * 967 *
948 * Pattern 4: 968 * Pattern 4:
949 * Some symbols belong to init section but still it is ok to reference 969 * Some symbols belong to init section but still it is ok to reference
@@ -958,10 +978,6 @@ static int section_mismatch(const char *fromsec, const char *tosec)
958static int secref_whitelist(const char *fromsec, const char *fromsym, 978static int secref_whitelist(const char *fromsec, const char *fromsym,
959 const char *tosec, const char *tosym) 979 const char *tosec, const char *tosym)
960{ 980{
961 /* Check for pattern 0 */
962 if (match(fromsec, initref_sections))
963 return 0;
964
965 /* Check for pattern 1 */ 981 /* Check for pattern 1 */
966 if (match(tosec, init_data_sections) && 982 if (match(tosec, init_data_sections) &&
967 match(fromsec, data_sections) && 983 match(fromsec, data_sections) &&
@@ -1180,7 +1196,7 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch,
1180 "The variable %s references\n" 1196 "The variable %s references\n"
1181 "the %s %s%s%s\n" 1197 "the %s %s%s%s\n"
1182 "If the reference is valid then annotate the\n" 1198 "If the reference is valid then annotate the\n"
1183 "variable with __init* (see linux/init.h) " 1199 "variable with __init* or __refdata (see linux/init.h) "
1184 "or name the variable:\n", 1200 "or name the variable:\n",
1185 fromsym, to, sec2annotation(tosec), tosym, to_p); 1201 fromsym, to, sec2annotation(tosec), tosym, to_p);
1186 while (*s) 1202 while (*s)
@@ -1377,7 +1393,7 @@ static void section_rela(const char *modname, struct elf_info *elf,
1377 fromsec = sech_name(elf, sechdr); 1393 fromsec = sech_name(elf, sechdr);
1378 fromsec += strlen(".rela"); 1394 fromsec += strlen(".rela");
1379 /* if from section (name) is know good then skip it */ 1395 /* if from section (name) is know good then skip it */
1380 if (check_section(modname, fromsec)) 1396 if (match(fromsec, section_white_list))
1381 return; 1397 return;
1382 1398
1383 for (rela = start; rela < stop; rela++) { 1399 for (rela = start; rela < stop; rela++) {
@@ -1421,7 +1437,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
1421 fromsec = sech_name(elf, sechdr); 1437 fromsec = sech_name(elf, sechdr);
1422 fromsec += strlen(".rel"); 1438 fromsec += strlen(".rel");
1423 /* if from section (name) is know good then skip it */ 1439 /* if from section (name) is know good then skip it */
1424 if (check_section(modname, fromsec)) 1440 if (match(fromsec, section_white_list))
1425 return; 1441 return;
1426 1442
1427 for (rel = start; rel < stop; rel++) { 1443 for (rel = start; rel < stop; rel++) {
@@ -1484,6 +1500,7 @@ static void check_sec_ref(struct module *mod, const char *modname,
1484 1500
1485 /* Walk through all sections */ 1501 /* Walk through all sections */
1486 for (i = 0; i < elf->hdr->e_shnum; i++) { 1502 for (i = 0; i < elf->hdr->e_shnum; i++) {
1503 check_section(modname, elf, &elf->sechdrs[i]);
1487 /* We want to process only relocation sections and not .init */ 1504 /* We want to process only relocation sections and not .init */
1488 if (sechdrs[i].sh_type == SHT_RELA) 1505 if (sechdrs[i].sh_type == SHT_RELA)
1489 section_rela(modname, elf, &elf->sechdrs[i]); 1506 section_rela(modname, elf, &elf->sechdrs[i]);
@@ -2008,6 +2025,7 @@ static void read_markers(const char *fname)
2008 if (!mod->skip) 2025 if (!mod->skip)
2009 add_marker(mod, marker, fmt); 2026 add_marker(mod, marker, fmt);
2010 } 2027 }
2028 release_file(file, size);
2011 return; 2029 return;
2012fail: 2030fail:
2013 fatal("parse error in markers list file\n"); 2031 fatal("parse error in markers list file\n");