diff options
Diffstat (limited to 'scripts/mod/modpost.c')
| -rw-r--r-- | scripts/mod/modpost.c | 126 |
1 files changed, 58 insertions, 68 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 7e62303133dc..161b7846733e 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,41 +727,37 @@ 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 */ |
| 718 | static const char *section_white_list[] = | 729 | static 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 | */ |
| 732 | static int check_section(const char *modname, const char *sec) | 747 | static 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 | ||
| @@ -794,15 +801,6 @@ static const char *init_exit_sections[] = | |||
| 794 | /* data section */ | 801 | /* data section */ |
| 795 | static const char *data_sections[] = { DATA_SECTIONS, NULL }; | 802 | static const char *data_sections[] = { DATA_SECTIONS, NULL }; |
| 796 | 803 | ||
| 797 | /* sections that may refer to an init/exit section with no warning */ | ||
| 798 | static const char *initref_sections[] = | ||
| 799 | { | ||
| 800 | ".text.init.refok*", | ||
| 801 | ".exit.text.refok*", | ||
| 802 | ".data.init.refok*", | ||
| 803 | NULL | ||
| 804 | }; | ||
| 805 | |||
| 806 | 804 | ||
| 807 | /* symbols in .data that may refer to init/exit sections */ | 805 | /* symbols in .data that may refer to init/exit sections */ |
| 808 | static const char *symbol_white_list[] = | 806 | static const char *symbol_white_list[] = |
| @@ -915,11 +913,6 @@ static int section_mismatch(const char *fromsec, const char *tosec) | |||
| 915 | /** | 913 | /** |
| 916 | * Whitelist to allow certain references to pass with no warning. | 914 | * Whitelist to allow certain references to pass with no warning. |
| 917 | * | 915 | * |
| 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: | 916 | * Pattern 1: |
| 924 | * If a module parameter is declared __initdata and permissions=0 | 917 | * If a module parameter is declared __initdata and permissions=0 |
| 925 | * then this is legal despite the warning generated. | 918 | * then this is legal despite the warning generated. |
| @@ -942,8 +935,7 @@ static int section_mismatch(const char *fromsec, const char *tosec) | |||
| 942 | * *probe_one, *_console, *_timer | 935 | * *probe_one, *_console, *_timer |
| 943 | * | 936 | * |
| 944 | * Pattern 3: | 937 | * Pattern 3: |
| 945 | * Whitelist all refereces from .text.head to .init.data | 938 | * Whitelist all references from .head.text to any init section |
| 946 | * Whitelist all refereces from .text.head to .init.text | ||
| 947 | * | 939 | * |
| 948 | * Pattern 4: | 940 | * Pattern 4: |
| 949 | * Some symbols belong to init section but still it is ok to reference | 941 | * Some symbols belong to init section but still it is ok to reference |
| @@ -958,10 +950,6 @@ static int section_mismatch(const char *fromsec, const char *tosec) | |||
| 958 | static int secref_whitelist(const char *fromsec, const char *fromsym, | 950 | static int secref_whitelist(const char *fromsec, const char *fromsym, |
| 959 | const char *tosec, const char *tosym) | 951 | const char *tosec, const char *tosym) |
| 960 | { | 952 | { |
| 961 | /* Check for pattern 0 */ | ||
| 962 | if (match(fromsec, initref_sections)) | ||
| 963 | return 0; | ||
| 964 | |||
| 965 | /* Check for pattern 1 */ | 953 | /* Check for pattern 1 */ |
| 966 | if (match(tosec, init_data_sections) && | 954 | if (match(tosec, init_data_sections) && |
| 967 | match(fromsec, data_sections) && | 955 | match(fromsec, data_sections) && |
| @@ -1377,7 +1365,7 @@ static void section_rela(const char *modname, struct elf_info *elf, | |||
| 1377 | fromsec = sech_name(elf, sechdr); | 1365 | fromsec = sech_name(elf, sechdr); |
| 1378 | fromsec += strlen(".rela"); | 1366 | fromsec += strlen(".rela"); |
| 1379 | /* if from section (name) is know good then skip it */ | 1367 | /* if from section (name) is know good then skip it */ |
| 1380 | if (check_section(modname, fromsec)) | 1368 | if (match(fromsec, section_white_list)) |
| 1381 | return; | 1369 | return; |
| 1382 | 1370 | ||
| 1383 | for (rela = start; rela < stop; rela++) { | 1371 | for (rela = start; rela < stop; rela++) { |
| @@ -1421,7 +1409,7 @@ static void section_rel(const char *modname, struct elf_info *elf, | |||
| 1421 | fromsec = sech_name(elf, sechdr); | 1409 | fromsec = sech_name(elf, sechdr); |
| 1422 | fromsec += strlen(".rel"); | 1410 | fromsec += strlen(".rel"); |
| 1423 | /* if from section (name) is know good then skip it */ | 1411 | /* if from section (name) is know good then skip it */ |
| 1424 | if (check_section(modname, fromsec)) | 1412 | if (match(fromsec, section_white_list)) |
| 1425 | return; | 1413 | return; |
| 1426 | 1414 | ||
| 1427 | for (rel = start; rel < stop; rel++) { | 1415 | for (rel = start; rel < stop; rel++) { |
| @@ -1484,6 +1472,7 @@ static void check_sec_ref(struct module *mod, const char *modname, | |||
| 1484 | 1472 | ||
| 1485 | /* Walk through all sections */ | 1473 | /* Walk through all sections */ |
| 1486 | for (i = 0; i < elf->hdr->e_shnum; i++) { | 1474 | for (i = 0; i < elf->hdr->e_shnum; i++) { |
| 1475 | check_section(modname, elf, &elf->sechdrs[i]); | ||
| 1487 | /* We want to process only relocation sections and not .init */ | 1476 | /* We want to process only relocation sections and not .init */ |
| 1488 | if (sechdrs[i].sh_type == SHT_RELA) | 1477 | if (sechdrs[i].sh_type == SHT_RELA) |
| 1489 | section_rela(modname, elf, &elf->sechdrs[i]); | 1478 | section_rela(modname, elf, &elf->sechdrs[i]); |
| @@ -1607,12 +1596,12 @@ static void read_symbols(char *modname) | |||
| 1607 | 1596 | ||
| 1608 | parse_elf_finish(&info); | 1597 | parse_elf_finish(&info); |
| 1609 | 1598 | ||
| 1610 | /* Our trick to get versioning for struct_module - it's | 1599 | /* Our trick to get versioning for module struct etc. - it's |
| 1611 | * never passed as an argument to an exported function, so | 1600 | * never passed as an argument to an exported function, so |
| 1612 | * the automatic versioning doesn't pick it up, but it's really | 1601 | * the automatic versioning doesn't pick it up, but it's really |
| 1613 | * important anyhow */ | 1602 | * important anyhow */ |
| 1614 | if (modversions) | 1603 | if (modversions) |
| 1615 | mod->unres = alloc_symbol("struct_module", 0, mod->unres); | 1604 | mod->unres = alloc_symbol("module_layout", 0, mod->unres); |
| 1616 | } | 1605 | } |
| 1617 | 1606 | ||
| 1618 | #define SZ 500 | 1607 | #define SZ 500 |
| @@ -1913,7 +1902,7 @@ static void read_dump(const char *fname, unsigned int kernel) | |||
| 1913 | if (!mod) { | 1902 | if (!mod) { |
| 1914 | if (is_vmlinux(modname)) | 1903 | if (is_vmlinux(modname)) |
| 1915 | have_vmlinux = 1; | 1904 | have_vmlinux = 1; |
| 1916 | mod = new_module(NOFAIL(strdup(modname))); | 1905 | mod = new_module(modname); |
| 1917 | mod->skip = 1; | 1906 | mod->skip = 1; |
| 1918 | } | 1907 | } |
| 1919 | s = sym_add_exported(symname, mod, export_no(export)); | 1908 | s = sym_add_exported(symname, mod, export_no(export)); |
| @@ -1997,7 +1986,7 @@ static void read_markers(const char *fname) | |||
| 1997 | 1986 | ||
| 1998 | mod = find_module(modname); | 1987 | mod = find_module(modname); |
| 1999 | if (!mod) { | 1988 | if (!mod) { |
| 2000 | mod = new_module(NOFAIL(strdup(modname))); | 1989 | mod = new_module(modname); |
| 2001 | mod->skip = 1; | 1990 | mod->skip = 1; |
| 2002 | } | 1991 | } |
| 2003 | if (is_vmlinux(modname)) { | 1992 | if (is_vmlinux(modname)) { |
| @@ -2008,6 +1997,7 @@ static void read_markers(const char *fname) | |||
| 2008 | if (!mod->skip) | 1997 | if (!mod->skip) |
| 2009 | add_marker(mod, marker, fmt); | 1998 | add_marker(mod, marker, fmt); |
| 2010 | } | 1999 | } |
| 2000 | release_file(file, size); | ||
| 2011 | return; | 2001 | return; |
| 2012 | fail: | 2002 | fail: |
| 2013 | fatal("parse error in markers list file\n"); | 2003 | fatal("parse error in markers list file\n"); |
