When you put .section ".foo" in an assembly file instead of .section "foo", "ax" , one of the possible symptoms is that modpost will see an ld-generated section name ".foo.1" in section_rel() or section_rela(). But this heuristic has two problems: it will miss a bad section that has no relocations, and it will incorrectly flag many gcc-generated sections as bad when compiling with -ffunction-sections -fdata-sections. On mips it fixes a lot of bogus warnings with gcc 4.4.0 lije this one: WARNING: crypto/cryptd.o (.text.T.349): unexpected section name. So instead of checking whether the section name matches a particular pattern, we directly check for a missing SHF_ALLOC in the section flags.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -716,41 +716,27 @@ int match(const char *sym, const char * const pat[]) · 715 unmodified lines | ||
| 716 | 716 | |
| 717 | 717 | /* sections that we do not want to do full section mismatch check on */ |
| 718 | 718 | static const char *section_white_list[] = |
| 719 | − { ".debug*", ".stab*", ".note*", ".got*", ".toc*", NULL }; | |
| 719 | + { ".comment", ".debug*", ".stab*", ".note*", ".got*", ".toc*", NULL }; | |
| 720 | 720 | |
| 721 | 721 | /* |
| 722 | − * Is this section one we do not want to check? | |
| 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. | |
| 722 | + * This is used to find sections missing the SHF_ALLOC flag. | |
| 728 | 723 | * The cause of this is often a section specified in assembler |
| 729 | − * without "ax" / "aw" and the same section used in .c | |
| 730 | − * code where gcc add these. | |
| 724 | + * without "ax" / "aw". | |
| 731 | 725 | */ |
| 732 | −static int check_section(const char *modname, const char *sec) | |
| 733 | −{ | |
| 734 | − const char *e = sec + strlen(sec) - 1; | |
| 735 | − if (match(sec, section_white_list)) | |
| 736 | − return 1; | |
| 737 | − | |
| 738 | − if (*e && isdigit(*e)) { | |
| 739 | − /* consume all digits */ | |
| 740 | − while (*e && e != sec && isdigit(*e)) | |
| 741 | − e--; | |
| 742 | − if (*e == '.' && !strstr(sec, ".linkonce")) { | |
| 743 | − warn("%s (%s): unexpected section name.\n" | |
| 744 | − "The (.[number]+) following section name are " | |
| 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 | − } | |
| 726 | +static void check_section(const char *modname, struct elf_info *elf, | |
| 727 | + Elf_Shdr *sechdr) | |
| 728 | +{ | |
| 729 | + const char *sec = sech_name(elf, sechdr); | |
| 730 | + | |
| 731 | + if (sechdr->sh_type == SHT_PROGBITS && | |
| 732 | + !(sechdr->sh_flags & SHF_ALLOC) && | |
| 733 | + !match(sec, section_white_list)) { | |
| 734 | + warn("%s (%s): unexpected non-allocatable section.\n" | |
| 735 | + "Did you forget to use \"ax\"/\"aw\" in a .S file?\n" | |
| 736 | + "Note that for example <linux/init.h> contains\n" | |
| 737 | + "section definitions for use in .S files.\n\n", | |
| 738 | + modname, sec); | |
| 752 | 739 | } |
| 753 | − return 0; | |
| 754 | 740 | } |
| 755 | 741 | |
| 756 | 742 | |
| @@ -1358,7 +1344,7 @@ static void section_rela(const char *modname, struct elf_info *elf, · 601 unmodified lines | ||
| 1358 | 1344 | fromsec = sech_name(elf, sechdr); |
| 1359 | 1345 | fromsec += strlen(".rela"); |
| 1360 | 1346 | /* if from section (name) is know good then skip it */ |
| 1361 | − if (check_section(modname, fromsec)) | |
| 1347 | + if (match(fromsec, section_white_list)) | |
| 1362 | 1348 | return; |
| 1363 | 1349 | |
| 1364 | 1350 | for (rela = start; rela < stop; rela++) { |
| @@ -1402,7 +1388,7 @@ static void section_rel(const char *modname, struct elf_info *elf, · 37 unmodified lines | ||
| 1402 | 1388 | fromsec = sech_name(elf, sechdr); |
| 1403 | 1389 | fromsec += strlen(".rel"); |
| 1404 | 1390 | /* if from section (name) is know good then skip it */ |
| 1405 | − if (check_section(modname, fromsec)) | |
| 1391 | + if (match(fromsec, section_white_list)) | |
| 1406 | 1392 | return; |
| 1407 | 1393 | |
| 1408 | 1394 | for (rel = start; rel < stop; rel++) { |
| @@ -1465,6 +1451,7 @@ static void check_sec_ref(struct module *mod, const char *modname, · 56 unmodified lines | ||
| 1465 | 1451 | |
| 1466 | 1452 | /* Walk through all sections */ |
| 1467 | 1453 | for (i = 0; i < elf->hdr->e_shnum; i++) { |
| 1454 | + check_section(modname, elf, &elf->sechdrs[i]); | |
| 1468 | 1455 | /* We want to process only relocation sections and not .init */ |
| 1469 | 1456 | if (sechdrs[i].sh_type == SHT_RELA) |
| 1470 | 1457 | section_rela(modname, elf, &elf->sechdrs[i]); |