diff options
Diffstat (limited to 'scripts/mod/modpost.c')
-rw-r--r-- | scripts/mod/modpost.c | 175 |
1 files changed, 133 insertions, 42 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index f6127b9f5aca..1ec7158b6c1f 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -14,6 +14,7 @@ | |||
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" |
18 | #include "../../include/generated/autoconf.h" | 19 | #include "../../include/generated/autoconf.h" |
19 | #include "../../include/linux/license.h" | 20 | #include "../../include/linux/license.h" |
@@ -253,7 +254,7 @@ static enum export export_no(const char *s) | |||
253 | return export_unknown; | 254 | return export_unknown; |
254 | } | 255 | } |
255 | 256 | ||
256 | 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) |
257 | { | 258 | { |
258 | if (sec == elf->export_sec) | 259 | if (sec == elf->export_sec) |
259 | return export_plain; | 260 | return export_plain; |
@@ -373,6 +374,8 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
373 | Elf_Ehdr *hdr; | 374 | Elf_Ehdr *hdr; |
374 | Elf_Shdr *sechdrs; | 375 | Elf_Shdr *sechdrs; |
375 | Elf_Sym *sym; | 376 | Elf_Sym *sym; |
377 | const char *secstrings; | ||
378 | unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U; | ||
376 | 379 | ||
377 | hdr = grab_file(filename, &info->size); | 380 | hdr = grab_file(filename, &info->size); |
378 | if (!hdr) { | 381 | if (!hdr) { |
@@ -417,8 +420,27 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
417 | return 0; | 420 | return 0; |
418 | } | 421 | } |
419 | 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 | |||
420 | /* Fix endianness in section headers */ | 442 | /* Fix endianness in section headers */ |
421 | for (i = 0; i < hdr->e_shnum; i++) { | 443 | for (i = 0; i < info->num_sections; i++) { |
422 | sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name); | 444 | sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name); |
423 | sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type); | 445 | sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type); |
424 | sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags); | 446 | sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags); |
@@ -431,9 +453,8 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
431 | sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize); | 453 | sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize); |
432 | } | 454 | } |
433 | /* Find symbol table. */ | 455 | /* Find symbol table. */ |
434 | for (i = 1; i < hdr->e_shnum; i++) { | 456 | secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset; |
435 | const char *secstrings | 457 | for (i = 1; i < info->num_sections; i++) { |
436 | = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; | ||
437 | const char *secname; | 458 | const char *secname; |
438 | int nobits = sechdrs[i].sh_type == SHT_NOBITS; | 459 | int nobits = sechdrs[i].sh_type == SHT_NOBITS; |
439 | 460 | ||
@@ -461,14 +482,26 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
461 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) | 482 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) |
462 | info->export_gpl_future_sec = i; | 483 | info->export_gpl_future_sec = i; |
463 | 484 | ||
464 | if (sechdrs[i].sh_type != SHT_SYMTAB) | 485 | if (sechdrs[i].sh_type == SHT_SYMTAB) { |
465 | 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 | } | ||
466 | 496 | ||
467 | info->symtab_start = (void *)hdr + sechdrs[i].sh_offset; | 497 | /* 32bit section no. table? ("more than 64k sections") */ |
468 | info->symtab_stop = (void *)hdr + sechdrs[i].sh_offset | 498 | if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) { |
469 | + sechdrs[i].sh_size; | 499 | symtab_shndx_idx = i; |
470 | info->strtab = (void *)hdr + | 500 | info->symtab_shndx_start = (void *)hdr + |
471 | 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 | } | ||
472 | } | 505 | } |
473 | if (!info->symtab_start) | 506 | if (!info->symtab_start) |
474 | fatal("%s has no symtab?\n", filename); | 507 | fatal("%s has no symtab?\n", filename); |
@@ -480,6 +513,21 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
480 | sym->st_value = TO_NATIVE(sym->st_value); | 513 | sym->st_value = TO_NATIVE(sym->st_value); |
481 | sym->st_size = TO_NATIVE(sym->st_size); | 514 | sym->st_size = TO_NATIVE(sym->st_size); |
482 | } | 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 | |||
483 | return 1; | 531 | return 1; |
484 | } | 532 | } |
485 | 533 | ||
@@ -519,7 +567,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
519 | Elf_Sym *sym, const char *symname) | 567 | Elf_Sym *sym, const char *symname) |
520 | { | 568 | { |
521 | unsigned int crc; | 569 | unsigned int crc; |
522 | enum export export = export_from_sec(info, sym->st_shndx); | 570 | enum export export = export_from_sec(info, get_secindex(info, sym)); |
523 | 571 | ||
524 | switch (sym->st_shndx) { | 572 | switch (sym->st_shndx) { |
525 | case SHN_COMMON: | 573 | case SHN_COMMON: |
@@ -661,19 +709,19 @@ static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) | |||
661 | return "(unknown)"; | 709 | return "(unknown)"; |
662 | } | 710 | } |
663 | 711 | ||
664 | static const char *sec_name(struct elf_info *elf, int shndx) | 712 | static const char *sec_name(struct elf_info *elf, int secindex) |
665 | { | 713 | { |
666 | Elf_Shdr *sechdrs = elf->sechdrs; | 714 | Elf_Shdr *sechdrs = elf->sechdrs; |
667 | return (void *)elf->hdr + | 715 | return (void *)elf->hdr + |
668 | elf->sechdrs[elf->hdr->e_shstrndx].sh_offset + | 716 | elf->sechdrs[elf->secindex_strings].sh_offset + |
669 | sechdrs[shndx].sh_name; | 717 | sechdrs[secindex].sh_name; |
670 | } | 718 | } |
671 | 719 | ||
672 | 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) |
673 | { | 721 | { |
674 | return (void *)elf->hdr + | 722 | return (void *)elf->hdr + |
675 | elf->sechdrs[elf->hdr->e_shstrndx].sh_offset + | 723 | elf->sechdrs[elf->secindex_strings].sh_offset + |
676 | sechdr->sh_name; | 724 | sechdr->sh_name; |
677 | } | 725 | } |
678 | 726 | ||
679 | /* if sym is empty or point to a string | 727 | /* if sym is empty or point to a string |
@@ -742,6 +790,7 @@ static const char *section_white_list[] = | |||
742 | { | 790 | { |
743 | ".comment*", | 791 | ".comment*", |
744 | ".debug*", | 792 | ".debug*", |
793 | ".GCC-command-line", /* mn10300 */ | ||
745 | ".mdebug*", /* alpha, score, mips etc. */ | 794 | ".mdebug*", /* alpha, score, mips etc. */ |
746 | ".pdr", /* alpha, score, mips etc. */ | 795 | ".pdr", /* alpha, score, mips etc. */ |
747 | ".stab*", | 796 | ".stab*", |
@@ -986,6 +1035,13 @@ static const struct sectioncheck *section_mismatch( | |||
986 | * fromsec = .data* | 1035 | * fromsec = .data* |
987 | * atsym =__param* | 1036 | * atsym =__param* |
988 | * | 1037 | * |
1038 | * Pattern 1a: | ||
1039 | * module_param_call() ops can refer to __init set function if permissions=0 | ||
1040 | * The pattern is identified by: | ||
1041 | * tosec = .init.text | ||
1042 | * fromsec = .data* | ||
1043 | * atsym = __param_ops_* | ||
1044 | * | ||
989 | * Pattern 2: | 1045 | * Pattern 2: |
990 | * Many drivers utilise a *driver container with references to | 1046 | * Many drivers utilise a *driver container with references to |
991 | * add, remove, probe functions etc. | 1047 | * add, remove, probe functions etc. |
@@ -1020,6 +1076,12 @@ static int secref_whitelist(const struct sectioncheck *mismatch, | |||
1020 | (strncmp(fromsym, "__param", strlen("__param")) == 0)) | 1076 | (strncmp(fromsym, "__param", strlen("__param")) == 0)) |
1021 | return 0; | 1077 | return 0; |
1022 | 1078 | ||
1079 | /* Check for pattern 1a */ | ||
1080 | if (strcmp(tosec, ".init.text") == 0 && | ||
1081 | match(fromsec, data_sections) && | ||
1082 | (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0)) | ||
1083 | return 0; | ||
1084 | |||
1023 | /* Check for pattern 2 */ | 1085 | /* Check for pattern 2 */ |
1024 | if (match(tosec, init_exit_sections) && | 1086 | if (match(tosec, init_exit_sections) && |
1025 | match(fromsec, data_sections) && | 1087 | match(fromsec, data_sections) && |
@@ -1052,11 +1114,14 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr, | |||
1052 | Elf_Sym *near = NULL; | 1114 | Elf_Sym *near = NULL; |
1053 | Elf64_Sword distance = 20; | 1115 | Elf64_Sword distance = 20; |
1054 | Elf64_Sword d; | 1116 | Elf64_Sword d; |
1117 | unsigned int relsym_secindex; | ||
1055 | 1118 | ||
1056 | if (relsym->st_name != 0) | 1119 | if (relsym->st_name != 0) |
1057 | return relsym; | 1120 | return relsym; |
1121 | |||
1122 | relsym_secindex = get_secindex(elf, relsym); | ||
1058 | for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { | 1123 | for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { |
1059 | if (sym->st_shndx != relsym->st_shndx) | 1124 | if (get_secindex(elf, sym) != relsym_secindex) |
1060 | continue; | 1125 | continue; |
1061 | if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) | 1126 | if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) |
1062 | continue; | 1127 | continue; |
@@ -1118,9 +1183,9 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr, | |||
1118 | for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { | 1183 | for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { |
1119 | const char *symsec; | 1184 | const char *symsec; |
1120 | 1185 | ||
1121 | if (sym->st_shndx >= SHN_LORESERVE) | 1186 | if (is_shndx_special(sym->st_shndx)) |
1122 | continue; | 1187 | continue; |
1123 | symsec = sec_name(elf, sym->st_shndx); | 1188 | symsec = sec_name(elf, get_secindex(elf, sym)); |
1124 | if (strcmp(symsec, sec) != 0) | 1189 | if (strcmp(symsec, sec) != 0) |
1125 | continue; | 1190 | continue; |
1126 | if (!is_valid_name(elf, sym)) | 1191 | if (!is_valid_name(elf, sym)) |
@@ -1167,7 +1232,7 @@ static char *sec2annotation(const char *s) | |||
1167 | strcat(p, " "); | 1232 | strcat(p, " "); |
1168 | return r; /* we leak her but we do not care */ | 1233 | return r; /* we leak her but we do not care */ |
1169 | } else { | 1234 | } else { |
1170 | return ""; | 1235 | return strdup(""); |
1171 | } | 1236 | } |
1172 | } | 1237 | } |
1173 | 1238 | ||
@@ -1195,6 +1260,8 @@ static void report_sec_mismatch(const char *modname, | |||
1195 | { | 1260 | { |
1196 | const char *from, *from_p; | 1261 | const char *from, *from_p; |
1197 | const char *to, *to_p; | 1262 | const char *to, *to_p; |
1263 | char *prl_from; | ||
1264 | char *prl_to; | ||
1198 | 1265 | ||
1199 | switch (from_is_func) { | 1266 | switch (from_is_func) { |
1200 | case 0: from = "variable"; from_p = ""; break; | 1267 | case 0: from = "variable"; from_p = ""; break; |
@@ -1218,16 +1285,21 @@ static void report_sec_mismatch(const char *modname, | |||
1218 | 1285 | ||
1219 | switch (mismatch->mismatch) { | 1286 | switch (mismatch->mismatch) { |
1220 | case TEXT_TO_ANY_INIT: | 1287 | case TEXT_TO_ANY_INIT: |
1288 | prl_from = sec2annotation(fromsec); | ||
1289 | prl_to = sec2annotation(tosec); | ||
1221 | fprintf(stderr, | 1290 | fprintf(stderr, |
1222 | "The function %s%s() references\n" | 1291 | "The function %s%s() references\n" |
1223 | "the %s %s%s%s.\n" | 1292 | "the %s %s%s%s.\n" |
1224 | "This is often because %s lacks a %s\n" | 1293 | "This is often because %s lacks a %s\n" |
1225 | "annotation or the annotation of %s is wrong.\n", | 1294 | "annotation or the annotation of %s is wrong.\n", |
1226 | sec2annotation(fromsec), fromsym, | 1295 | prl_from, fromsym, |
1227 | to, sec2annotation(tosec), tosym, to_p, | 1296 | to, prl_to, tosym, to_p, |
1228 | fromsym, sec2annotation(tosec), tosym); | 1297 | fromsym, prl_to, tosym); |
1298 | free(prl_from); | ||
1299 | free(prl_to); | ||
1229 | break; | 1300 | break; |
1230 | case DATA_TO_ANY_INIT: { | 1301 | case DATA_TO_ANY_INIT: { |
1302 | prl_to = sec2annotation(tosec); | ||
1231 | const char *const *s = mismatch->symbol_white_list; | 1303 | const char *const *s = mismatch->symbol_white_list; |
1232 | fprintf(stderr, | 1304 | fprintf(stderr, |
1233 | "The variable %s references\n" | 1305 | "The variable %s references\n" |
@@ -1235,20 +1307,24 @@ static void report_sec_mismatch(const char *modname, | |||
1235 | "If the reference is valid then annotate the\n" | 1307 | "If the reference is valid then annotate the\n" |
1236 | "variable with __init* or __refdata (see linux/init.h) " | 1308 | "variable with __init* or __refdata (see linux/init.h) " |
1237 | "or name the variable:\n", | 1309 | "or name the variable:\n", |
1238 | fromsym, to, sec2annotation(tosec), tosym, to_p); | 1310 | fromsym, to, prl_to, tosym, to_p); |
1239 | while (*s) | 1311 | while (*s) |
1240 | fprintf(stderr, "%s, ", *s++); | 1312 | fprintf(stderr, "%s, ", *s++); |
1241 | fprintf(stderr, "\n"); | 1313 | fprintf(stderr, "\n"); |
1314 | free(prl_to); | ||
1242 | break; | 1315 | break; |
1243 | } | 1316 | } |
1244 | case TEXT_TO_ANY_EXIT: | 1317 | case TEXT_TO_ANY_EXIT: |
1318 | prl_to = sec2annotation(tosec); | ||
1245 | fprintf(stderr, | 1319 | fprintf(stderr, |
1246 | "The function %s() references a %s in an exit section.\n" | 1320 | "The function %s() references a %s in an exit section.\n" |
1247 | "Often the %s %s%s has valid usage outside the exit section\n" | 1321 | "Often the %s %s%s has valid usage outside the exit section\n" |
1248 | "and the fix is to remove the %sannotation of %s.\n", | 1322 | "and the fix is to remove the %sannotation of %s.\n", |
1249 | fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym); | 1323 | fromsym, to, to, tosym, to_p, prl_to, tosym); |
1324 | free(prl_to); | ||
1250 | break; | 1325 | break; |
1251 | case DATA_TO_ANY_EXIT: { | 1326 | case DATA_TO_ANY_EXIT: { |
1327 | prl_to = sec2annotation(tosec); | ||
1252 | const char *const *s = mismatch->symbol_white_list; | 1328 | const char *const *s = mismatch->symbol_white_list; |
1253 | fprintf(stderr, | 1329 | fprintf(stderr, |
1254 | "The variable %s references\n" | 1330 | "The variable %s references\n" |
@@ -1256,24 +1332,31 @@ static void report_sec_mismatch(const char *modname, | |||
1256 | "If the reference is valid then annotate the\n" | 1332 | "If the reference is valid then annotate the\n" |
1257 | "variable with __exit* (see linux/init.h) or " | 1333 | "variable with __exit* (see linux/init.h) or " |
1258 | "name the variable:\n", | 1334 | "name the variable:\n", |
1259 | fromsym, to, sec2annotation(tosec), tosym, to_p); | 1335 | fromsym, to, prl_to, tosym, to_p); |
1260 | while (*s) | 1336 | while (*s) |
1261 | fprintf(stderr, "%s, ", *s++); | 1337 | fprintf(stderr, "%s, ", *s++); |
1262 | fprintf(stderr, "\n"); | 1338 | fprintf(stderr, "\n"); |
1339 | free(prl_to); | ||
1263 | break; | 1340 | break; |
1264 | } | 1341 | } |
1265 | case XXXINIT_TO_SOME_INIT: | 1342 | case XXXINIT_TO_SOME_INIT: |
1266 | case XXXEXIT_TO_SOME_EXIT: | 1343 | case XXXEXIT_TO_SOME_EXIT: |
1344 | prl_from = sec2annotation(fromsec); | ||
1345 | prl_to = sec2annotation(tosec); | ||
1267 | fprintf(stderr, | 1346 | fprintf(stderr, |
1268 | "The %s %s%s%s references\n" | 1347 | "The %s %s%s%s references\n" |
1269 | "a %s %s%s%s.\n" | 1348 | "a %s %s%s%s.\n" |
1270 | "If %s is only used by %s then\n" | 1349 | "If %s is only used by %s then\n" |
1271 | "annotate %s with a matching annotation.\n", | 1350 | "annotate %s with a matching annotation.\n", |
1272 | from, sec2annotation(fromsec), fromsym, from_p, | 1351 | from, prl_from, fromsym, from_p, |
1273 | to, sec2annotation(tosec), tosym, to_p, | 1352 | to, prl_to, tosym, to_p, |
1274 | tosym, fromsym, tosym); | 1353 | tosym, fromsym, tosym); |
1354 | free(prl_from); | ||
1355 | free(prl_to); | ||
1275 | break; | 1356 | break; |
1276 | case ANY_INIT_TO_ANY_EXIT: | 1357 | case ANY_INIT_TO_ANY_EXIT: |
1358 | prl_from = sec2annotation(fromsec); | ||
1359 | prl_to = sec2annotation(tosec); | ||
1277 | fprintf(stderr, | 1360 | fprintf(stderr, |
1278 | "The %s %s%s%s references\n" | 1361 | "The %s %s%s%s references\n" |
1279 | "a %s %s%s%s.\n" | 1362 | "a %s %s%s%s.\n" |
@@ -1282,11 +1365,15 @@ static void report_sec_mismatch(const char *modname, | |||
1282 | "uses functionality in the exit path.\n" | 1365 | "uses functionality in the exit path.\n" |
1283 | "The fix is often to remove the %sannotation of\n" | 1366 | "The fix is often to remove the %sannotation of\n" |
1284 | "%s%s so it may be used outside an exit section.\n", | 1367 | "%s%s so it may be used outside an exit section.\n", |
1285 | from, sec2annotation(fromsec), fromsym, from_p, | 1368 | from, prl_from, fromsym, from_p, |
1286 | to, sec2annotation(tosec), tosym, to_p, | 1369 | to, prl_to, tosym, to_p, |
1287 | sec2annotation(tosec), tosym, to_p); | 1370 | prl_to, tosym, to_p); |
1371 | free(prl_from); | ||
1372 | free(prl_to); | ||
1288 | break; | 1373 | break; |
1289 | case ANY_EXIT_TO_ANY_INIT: | 1374 | case ANY_EXIT_TO_ANY_INIT: |
1375 | prl_from = sec2annotation(fromsec); | ||
1376 | prl_to = sec2annotation(tosec); | ||
1290 | fprintf(stderr, | 1377 | fprintf(stderr, |
1291 | "The %s %s%s%s references\n" | 1378 | "The %s %s%s%s references\n" |
1292 | "a %s %s%s%s.\n" | 1379 | "a %s %s%s%s.\n" |
@@ -1295,16 +1382,20 @@ static void report_sec_mismatch(const char *modname, | |||
1295 | "uses functionality in the init path.\n" | 1382 | "uses functionality in the init path.\n" |
1296 | "The fix is often to remove the %sannotation of\n" | 1383 | "The fix is often to remove the %sannotation of\n" |
1297 | "%s%s so it may be used outside an init section.\n", | 1384 | "%s%s so it may be used outside an init section.\n", |
1298 | from, sec2annotation(fromsec), fromsym, from_p, | 1385 | from, prl_from, fromsym, from_p, |
1299 | to, sec2annotation(tosec), tosym, to_p, | 1386 | to, prl_to, tosym, to_p, |
1300 | sec2annotation(tosec), tosym, to_p); | 1387 | prl_to, tosym, to_p); |
1388 | free(prl_from); | ||
1389 | free(prl_to); | ||
1301 | break; | 1390 | break; |
1302 | case EXPORT_TO_INIT_EXIT: | 1391 | case EXPORT_TO_INIT_EXIT: |
1392 | prl_to = sec2annotation(tosec); | ||
1303 | fprintf(stderr, | 1393 | fprintf(stderr, |
1304 | "The symbol %s is exported and annotated %s\n" | 1394 | "The symbol %s is exported and annotated %s\n" |
1305 | "Fix this by removing the %sannotation of %s " | 1395 | "Fix this by removing the %sannotation of %s " |
1306 | "or drop the export.\n", | 1396 | "or drop the export.\n", |
1307 | tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); | 1397 | tosym, prl_to, prl_to, tosym); |
1398 | free(prl_to); | ||
1308 | break; | 1399 | break; |
1309 | } | 1400 | } |
1310 | fprintf(stderr, "\n"); | 1401 | fprintf(stderr, "\n"); |
@@ -1316,7 +1407,7 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf, | |||
1316 | const char *tosec; | 1407 | const char *tosec; |
1317 | const struct sectioncheck *mismatch; | 1408 | const struct sectioncheck *mismatch; |
1318 | 1409 | ||
1319 | tosec = sec_name(elf, sym->st_shndx); | 1410 | tosec = sec_name(elf, get_secindex(elf, sym)); |
1320 | mismatch = section_mismatch(fromsec, tosec); | 1411 | mismatch = section_mismatch(fromsec, tosec); |
1321 | if (mismatch) { | 1412 | if (mismatch) { |
1322 | Elf_Sym *to; | 1413 | Elf_Sym *to; |
@@ -1344,7 +1435,7 @@ static unsigned int *reloc_location(struct elf_info *elf, | |||
1344 | Elf_Shdr *sechdr, Elf_Rela *r) | 1435 | Elf_Shdr *sechdr, Elf_Rela *r) |
1345 | { | 1436 | { |
1346 | Elf_Shdr *sechdrs = elf->sechdrs; | 1437 | Elf_Shdr *sechdrs = elf->sechdrs; |
1347 | int section = sechdr->sh_info; | 1438 | int section = shndx2secindex(sechdr->sh_info); |
1348 | 1439 | ||
1349 | return (void *)elf->hdr + sechdrs[section].sh_offset + | 1440 | return (void *)elf->hdr + sechdrs[section].sh_offset + |
1350 | r->r_offset - sechdrs[section].sh_addr; | 1441 | r->r_offset - sechdrs[section].sh_addr; |
@@ -1452,7 +1543,7 @@ static void section_rela(const char *modname, struct elf_info *elf, | |||
1452 | r.r_addend = TO_NATIVE(rela->r_addend); | 1543 | r.r_addend = TO_NATIVE(rela->r_addend); |
1453 | sym = elf->symtab_start + r_sym; | 1544 | sym = elf->symtab_start + r_sym; |
1454 | /* Skip special sections */ | 1545 | /* Skip special sections */ |
1455 | if (sym->st_shndx >= SHN_LORESERVE) | 1546 | if (is_shndx_special(sym->st_shndx)) |
1456 | continue; | 1547 | continue; |
1457 | check_section_mismatch(modname, elf, &r, sym, fromsec); | 1548 | check_section_mismatch(modname, elf, &r, sym, fromsec); |
1458 | } | 1549 | } |
@@ -1510,7 +1601,7 @@ static void section_rel(const char *modname, struct elf_info *elf, | |||
1510 | } | 1601 | } |
1511 | sym = elf->symtab_start + r_sym; | 1602 | sym = elf->symtab_start + r_sym; |
1512 | /* Skip special sections */ | 1603 | /* Skip special sections */ |
1513 | if (sym->st_shndx >= SHN_LORESERVE) | 1604 | if (is_shndx_special(sym->st_shndx)) |
1514 | continue; | 1605 | continue; |
1515 | check_section_mismatch(modname, elf, &r, sym, fromsec); | 1606 | check_section_mismatch(modname, elf, &r, sym, fromsec); |
1516 | } | 1607 | } |
@@ -1535,7 +1626,7 @@ static void check_sec_ref(struct module *mod, const char *modname, | |||
1535 | Elf_Shdr *sechdrs = elf->sechdrs; | 1626 | Elf_Shdr *sechdrs = elf->sechdrs; |
1536 | 1627 | ||
1537 | /* Walk through all sections */ | 1628 | /* Walk through all sections */ |
1538 | for (i = 0; i < elf->hdr->e_shnum; i++) { | 1629 | for (i = 0; i < elf->num_sections; i++) { |
1539 | check_section(modname, elf, &elf->sechdrs[i]); | 1630 | check_section(modname, elf, &elf->sechdrs[i]); |
1540 | /* We want to process only relocation sections and not .init */ | 1631 | /* We want to process only relocation sections and not .init */ |
1541 | if (sechdrs[i].sh_type == SHT_RELA) | 1632 | if (sechdrs[i].sh_type == SHT_RELA) |