aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mod/modpost.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/mod/modpost.c')
-rw-r--r--scripts/mod/modpost.c100
1 files changed, 54 insertions, 46 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 8d46ea7d6715..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 */
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
@@ -928,8 +935,7 @@ static int section_mismatch(const char *fromsec, const char *tosec)
928 * *probe_one, *_console, *_timer 935 * *probe_one, *_console, *_timer
929 * 936 *
930 * Pattern 3: 937 * Pattern 3:
931 * Whitelist all refereces from .text.head to .init.data 938 * Whitelist all references from .head.text to any init section
932 * Whitelist all refereces from .text.head to .init.text
933 * 939 *
934 * Pattern 4: 940 * Pattern 4:
935 * 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
@@ -1359,7 +1365,7 @@ static void section_rela(const char *modname, struct elf_info *elf,
1359 fromsec = sech_name(elf, sechdr); 1365 fromsec = sech_name(elf, sechdr);
1360 fromsec += strlen(".rela"); 1366 fromsec += strlen(".rela");
1361 /* if from section (name) is know good then skip it */ 1367 /* if from section (name) is know good then skip it */
1362 if (check_section(modname, fromsec)) 1368 if (match(fromsec, section_white_list))
1363 return; 1369 return;
1364 1370
1365 for (rela = start; rela < stop; rela++) { 1371 for (rela = start; rela < stop; rela++) {
@@ -1403,7 +1409,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
1403 fromsec = sech_name(elf, sechdr); 1409 fromsec = sech_name(elf, sechdr);
1404 fromsec += strlen(".rel"); 1410 fromsec += strlen(".rel");
1405 /* if from section (name) is know good then skip it */ 1411 /* if from section (name) is know good then skip it */
1406 if (check_section(modname, fromsec)) 1412 if (match(fromsec, section_white_list))
1407 return; 1413 return;
1408 1414
1409 for (rel = start; rel < stop; rel++) { 1415 for (rel = start; rel < stop; rel++) {
@@ -1466,6 +1472,7 @@ static void check_sec_ref(struct module *mod, const char *modname,
1466 1472
1467 /* Walk through all sections */ 1473 /* Walk through all sections */
1468 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]);
1469 /* We want to process only relocation sections and not .init */ 1476 /* We want to process only relocation sections and not .init */
1470 if (sechdrs[i].sh_type == SHT_RELA) 1477 if (sechdrs[i].sh_type == SHT_RELA)
1471 section_rela(modname, elf, &elf->sechdrs[i]); 1478 section_rela(modname, elf, &elf->sechdrs[i]);
@@ -1990,6 +1997,7 @@ static void read_markers(const char *fname)
1990 if (!mod->skip) 1997 if (!mod->skip)
1991 add_marker(mod, marker, fmt); 1998 add_marker(mod, marker, fmt);
1992 } 1999 }
2000 release_file(file, size);
1993 return; 2001 return;
1994fail: 2002fail:
1995 fatal("parse error in markers list file\n"); 2003 fatal("parse error in markers list file\n");