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.c190
1 files changed, 145 insertions, 45 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 3318692e4e76..e8fba959fffb 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
256static enum export export_from_sec(struct elf_info *elf, Elf_Section sec) 257static 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
@@ -503,6 +551,11 @@ static int ignore_undef_symbol(struct elf_info *info, const char *symname)
503 strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 || 551 strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 ||
504 strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0) 552 strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0)
505 return 1; 553 return 1;
554 if (info->hdr->e_machine == EM_PPC64)
555 /* Special register function linked on all modules during final link of .ko */
556 if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 ||
557 strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0)
558 return 1;
506 /* Do not ignore this symbol */ 559 /* Do not ignore this symbol */
507 return 0; 560 return 0;
508} 561}
@@ -514,7 +567,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
514 Elf_Sym *sym, const char *symname) 567 Elf_Sym *sym, const char *symname)
515{ 568{
516 unsigned int crc; 569 unsigned int crc;
517 enum export export = export_from_sec(info, sym->st_shndx); 570 enum export export = export_from_sec(info, get_secindex(info, sym));
518 571
519 switch (sym->st_shndx) { 572 switch (sym->st_shndx) {
520 case SHN_COMMON: 573 case SHN_COMMON:
@@ -656,19 +709,19 @@ static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
656 return "(unknown)"; 709 return "(unknown)";
657} 710}
658 711
659static const char *sec_name(struct elf_info *elf, int shndx) 712static const char *sec_name(struct elf_info *elf, int secindex)
660{ 713{
661 Elf_Shdr *sechdrs = elf->sechdrs; 714 Elf_Shdr *sechdrs = elf->sechdrs;
662 return (void *)elf->hdr + 715 return (void *)elf->hdr +
663 elf->sechdrs[elf->hdr->e_shstrndx].sh_offset + 716 elf->sechdrs[elf->secindex_strings].sh_offset +
664 sechdrs[shndx].sh_name; 717 sechdrs[secindex].sh_name;
665} 718}
666 719
667static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr) 720static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr)
668{ 721{
669 return (void *)elf->hdr + 722 return (void *)elf->hdr +
670 elf->sechdrs[elf->hdr->e_shstrndx].sh_offset + 723 elf->sechdrs[elf->secindex_strings].sh_offset +
671 sechdr->sh_name; 724 sechdr->sh_name;
672} 725}
673 726
674/* if sym is empty or point to a string 727/* if sym is empty or point to a string
@@ -737,6 +790,8 @@ static const char *section_white_list[] =
737{ 790{
738 ".comment*", 791 ".comment*",
739 ".debug*", 792 ".debug*",
793 ".zdebug*", /* Compressed debug sections. */
794 ".GCC-command-line", /* mn10300 */
740 ".mdebug*", /* alpha, score, mips etc. */ 795 ".mdebug*", /* alpha, score, mips etc. */
741 ".pdr", /* alpha, score, mips etc. */ 796 ".pdr", /* alpha, score, mips etc. */
742 ".stab*", 797 ".stab*",
@@ -981,6 +1036,13 @@ static const struct sectioncheck *section_mismatch(
981 * fromsec = .data* 1036 * fromsec = .data*
982 * atsym =__param* 1037 * atsym =__param*
983 * 1038 *
1039 * Pattern 1a:
1040 * module_param_call() ops can refer to __init set function if permissions=0
1041 * The pattern is identified by:
1042 * tosec = .init.text
1043 * fromsec = .data*
1044 * atsym = __param_ops_*
1045 *
984 * Pattern 2: 1046 * Pattern 2:
985 * Many drivers utilise a *driver container with references to 1047 * Many drivers utilise a *driver container with references to
986 * add, remove, probe functions etc. 1048 * add, remove, probe functions etc.
@@ -1015,6 +1077,12 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
1015 (strncmp(fromsym, "__param", strlen("__param")) == 0)) 1077 (strncmp(fromsym, "__param", strlen("__param")) == 0))
1016 return 0; 1078 return 0;
1017 1079
1080 /* Check for pattern 1a */
1081 if (strcmp(tosec, ".init.text") == 0 &&
1082 match(fromsec, data_sections) &&
1083 (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0))
1084 return 0;
1085
1018 /* Check for pattern 2 */ 1086 /* Check for pattern 2 */
1019 if (match(tosec, init_exit_sections) && 1087 if (match(tosec, init_exit_sections) &&
1020 match(fromsec, data_sections) && 1088 match(fromsec, data_sections) &&
@@ -1047,11 +1115,14 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1047 Elf_Sym *near = NULL; 1115 Elf_Sym *near = NULL;
1048 Elf64_Sword distance = 20; 1116 Elf64_Sword distance = 20;
1049 Elf64_Sword d; 1117 Elf64_Sword d;
1118 unsigned int relsym_secindex;
1050 1119
1051 if (relsym->st_name != 0) 1120 if (relsym->st_name != 0)
1052 return relsym; 1121 return relsym;
1122
1123 relsym_secindex = get_secindex(elf, relsym);
1053 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { 1124 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1054 if (sym->st_shndx != relsym->st_shndx) 1125 if (get_secindex(elf, sym) != relsym_secindex)
1055 continue; 1126 continue;
1056 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) 1127 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
1057 continue; 1128 continue;
@@ -1113,9 +1184,9 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1113 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { 1184 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1114 const char *symsec; 1185 const char *symsec;
1115 1186
1116 if (sym->st_shndx >= SHN_LORESERVE) 1187 if (is_shndx_special(sym->st_shndx))
1117 continue; 1188 continue;
1118 symsec = sec_name(elf, sym->st_shndx); 1189 symsec = sec_name(elf, get_secindex(elf, sym));
1119 if (strcmp(symsec, sec) != 0) 1190 if (strcmp(symsec, sec) != 0)
1120 continue; 1191 continue;
1121 if (!is_valid_name(elf, sym)) 1192 if (!is_valid_name(elf, sym))
@@ -1138,6 +1209,9 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1138 * .cpuinit.data => __cpudata 1209 * .cpuinit.data => __cpudata
1139 * .memexitconst => __memconst 1210 * .memexitconst => __memconst
1140 * etc. 1211 * etc.
1212 *
1213 * The memory of returned value has been allocated on a heap. The user of this
1214 * method should free it after usage.
1141*/ 1215*/
1142static char *sec2annotation(const char *s) 1216static char *sec2annotation(const char *s)
1143{ 1217{
@@ -1160,9 +1234,9 @@ static char *sec2annotation(const char *s)
1160 strcat(p, "data "); 1234 strcat(p, "data ");
1161 else 1235 else
1162 strcat(p, " "); 1236 strcat(p, " ");
1163 return r; /* we leak her but we do not care */ 1237 return r;
1164 } else { 1238 } else {
1165 return ""; 1239 return strdup("");
1166 } 1240 }
1167} 1241}
1168 1242
@@ -1190,6 +1264,8 @@ static void report_sec_mismatch(const char *modname,
1190{ 1264{
1191 const char *from, *from_p; 1265 const char *from, *from_p;
1192 const char *to, *to_p; 1266 const char *to, *to_p;
1267 char *prl_from;
1268 char *prl_to;
1193 1269
1194 switch (from_is_func) { 1270 switch (from_is_func) {
1195 case 0: from = "variable"; from_p = ""; break; 1271 case 0: from = "variable"; from_p = ""; break;
@@ -1213,16 +1289,21 @@ static void report_sec_mismatch(const char *modname,
1213 1289
1214 switch (mismatch->mismatch) { 1290 switch (mismatch->mismatch) {
1215 case TEXT_TO_ANY_INIT: 1291 case TEXT_TO_ANY_INIT:
1292 prl_from = sec2annotation(fromsec);
1293 prl_to = sec2annotation(tosec);
1216 fprintf(stderr, 1294 fprintf(stderr,
1217 "The function %s%s() references\n" 1295 "The function %s%s() references\n"
1218 "the %s %s%s%s.\n" 1296 "the %s %s%s%s.\n"
1219 "This is often because %s lacks a %s\n" 1297 "This is often because %s lacks a %s\n"
1220 "annotation or the annotation of %s is wrong.\n", 1298 "annotation or the annotation of %s is wrong.\n",
1221 sec2annotation(fromsec), fromsym, 1299 prl_from, fromsym,
1222 to, sec2annotation(tosec), tosym, to_p, 1300 to, prl_to, tosym, to_p,
1223 fromsym, sec2annotation(tosec), tosym); 1301 fromsym, prl_to, tosym);
1302 free(prl_from);
1303 free(prl_to);
1224 break; 1304 break;
1225 case DATA_TO_ANY_INIT: { 1305 case DATA_TO_ANY_INIT: {
1306 prl_to = sec2annotation(tosec);
1226 const char *const *s = mismatch->symbol_white_list; 1307 const char *const *s = mismatch->symbol_white_list;
1227 fprintf(stderr, 1308 fprintf(stderr,
1228 "The variable %s references\n" 1309 "The variable %s references\n"
@@ -1230,20 +1311,24 @@ static void report_sec_mismatch(const char *modname,
1230 "If the reference is valid then annotate the\n" 1311 "If the reference is valid then annotate the\n"
1231 "variable with __init* or __refdata (see linux/init.h) " 1312 "variable with __init* or __refdata (see linux/init.h) "
1232 "or name the variable:\n", 1313 "or name the variable:\n",
1233 fromsym, to, sec2annotation(tosec), tosym, to_p); 1314 fromsym, to, prl_to, tosym, to_p);
1234 while (*s) 1315 while (*s)
1235 fprintf(stderr, "%s, ", *s++); 1316 fprintf(stderr, "%s, ", *s++);
1236 fprintf(stderr, "\n"); 1317 fprintf(stderr, "\n");
1318 free(prl_to);
1237 break; 1319 break;
1238 } 1320 }
1239 case TEXT_TO_ANY_EXIT: 1321 case TEXT_TO_ANY_EXIT:
1322 prl_to = sec2annotation(tosec);
1240 fprintf(stderr, 1323 fprintf(stderr,
1241 "The function %s() references a %s in an exit section.\n" 1324 "The function %s() references a %s in an exit section.\n"
1242 "Often the %s %s%s has valid usage outside the exit section\n" 1325 "Often the %s %s%s has valid usage outside the exit section\n"
1243 "and the fix is to remove the %sannotation of %s.\n", 1326 "and the fix is to remove the %sannotation of %s.\n",
1244 fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym); 1327 fromsym, to, to, tosym, to_p, prl_to, tosym);
1328 free(prl_to);
1245 break; 1329 break;
1246 case DATA_TO_ANY_EXIT: { 1330 case DATA_TO_ANY_EXIT: {
1331 prl_to = sec2annotation(tosec);
1247 const char *const *s = mismatch->symbol_white_list; 1332 const char *const *s = mismatch->symbol_white_list;
1248 fprintf(stderr, 1333 fprintf(stderr,
1249 "The variable %s references\n" 1334 "The variable %s references\n"
@@ -1251,24 +1336,31 @@ static void report_sec_mismatch(const char *modname,
1251 "If the reference is valid then annotate the\n" 1336 "If the reference is valid then annotate the\n"
1252 "variable with __exit* (see linux/init.h) or " 1337 "variable with __exit* (see linux/init.h) or "
1253 "name the variable:\n", 1338 "name the variable:\n",
1254 fromsym, to, sec2annotation(tosec), tosym, to_p); 1339 fromsym, to, prl_to, tosym, to_p);
1255 while (*s) 1340 while (*s)
1256 fprintf(stderr, "%s, ", *s++); 1341 fprintf(stderr, "%s, ", *s++);
1257 fprintf(stderr, "\n"); 1342 fprintf(stderr, "\n");
1343 free(prl_to);
1258 break; 1344 break;
1259 } 1345 }
1260 case XXXINIT_TO_SOME_INIT: 1346 case XXXINIT_TO_SOME_INIT:
1261 case XXXEXIT_TO_SOME_EXIT: 1347 case XXXEXIT_TO_SOME_EXIT:
1348 prl_from = sec2annotation(fromsec);
1349 prl_to = sec2annotation(tosec);
1262 fprintf(stderr, 1350 fprintf(stderr,
1263 "The %s %s%s%s references\n" 1351 "The %s %s%s%s references\n"
1264 "a %s %s%s%s.\n" 1352 "a %s %s%s%s.\n"
1265 "If %s is only used by %s then\n" 1353 "If %s is only used by %s then\n"
1266 "annotate %s with a matching annotation.\n", 1354 "annotate %s with a matching annotation.\n",
1267 from, sec2annotation(fromsec), fromsym, from_p, 1355 from, prl_from, fromsym, from_p,
1268 to, sec2annotation(tosec), tosym, to_p, 1356 to, prl_to, tosym, to_p,
1269 tosym, fromsym, tosym); 1357 tosym, fromsym, tosym);
1358 free(prl_from);
1359 free(prl_to);
1270 break; 1360 break;
1271 case ANY_INIT_TO_ANY_EXIT: 1361 case ANY_INIT_TO_ANY_EXIT:
1362 prl_from = sec2annotation(fromsec);
1363 prl_to = sec2annotation(tosec);
1272 fprintf(stderr, 1364 fprintf(stderr,
1273 "The %s %s%s%s references\n" 1365 "The %s %s%s%s references\n"
1274 "a %s %s%s%s.\n" 1366 "a %s %s%s%s.\n"
@@ -1277,11 +1369,15 @@ static void report_sec_mismatch(const char *modname,
1277 "uses functionality in the exit path.\n" 1369 "uses functionality in the exit path.\n"
1278 "The fix is often to remove the %sannotation of\n" 1370 "The fix is often to remove the %sannotation of\n"
1279 "%s%s so it may be used outside an exit section.\n", 1371 "%s%s so it may be used outside an exit section.\n",
1280 from, sec2annotation(fromsec), fromsym, from_p, 1372 from, prl_from, fromsym, from_p,
1281 to, sec2annotation(tosec), tosym, to_p, 1373 to, prl_to, tosym, to_p,
1282 sec2annotation(tosec), tosym, to_p); 1374 prl_to, tosym, to_p);
1375 free(prl_from);
1376 free(prl_to);
1283 break; 1377 break;
1284 case ANY_EXIT_TO_ANY_INIT: 1378 case ANY_EXIT_TO_ANY_INIT:
1379 prl_from = sec2annotation(fromsec);
1380 prl_to = sec2annotation(tosec);
1285 fprintf(stderr, 1381 fprintf(stderr,
1286 "The %s %s%s%s references\n" 1382 "The %s %s%s%s references\n"
1287 "a %s %s%s%s.\n" 1383 "a %s %s%s%s.\n"
@@ -1290,16 +1386,20 @@ static void report_sec_mismatch(const char *modname,
1290 "uses functionality in the init path.\n" 1386 "uses functionality in the init path.\n"
1291 "The fix is often to remove the %sannotation of\n" 1387 "The fix is often to remove the %sannotation of\n"
1292 "%s%s so it may be used outside an init section.\n", 1388 "%s%s so it may be used outside an init section.\n",
1293 from, sec2annotation(fromsec), fromsym, from_p, 1389 from, prl_from, fromsym, from_p,
1294 to, sec2annotation(tosec), tosym, to_p, 1390 to, prl_to, tosym, to_p,
1295 sec2annotation(tosec), tosym, to_p); 1391 prl_to, tosym, to_p);
1392 free(prl_from);
1393 free(prl_to);
1296 break; 1394 break;
1297 case EXPORT_TO_INIT_EXIT: 1395 case EXPORT_TO_INIT_EXIT:
1396 prl_to = sec2annotation(tosec);
1298 fprintf(stderr, 1397 fprintf(stderr,
1299 "The symbol %s is exported and annotated %s\n" 1398 "The symbol %s is exported and annotated %s\n"
1300 "Fix this by removing the %sannotation of %s " 1399 "Fix this by removing the %sannotation of %s "
1301 "or drop the export.\n", 1400 "or drop the export.\n",
1302 tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); 1401 tosym, prl_to, prl_to, tosym);
1402 free(prl_to);
1303 break; 1403 break;
1304 } 1404 }
1305 fprintf(stderr, "\n"); 1405 fprintf(stderr, "\n");
@@ -1311,7 +1411,7 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf,
1311 const char *tosec; 1411 const char *tosec;
1312 const struct sectioncheck *mismatch; 1412 const struct sectioncheck *mismatch;
1313 1413
1314 tosec = sec_name(elf, sym->st_shndx); 1414 tosec = sec_name(elf, get_secindex(elf, sym));
1315 mismatch = section_mismatch(fromsec, tosec); 1415 mismatch = section_mismatch(fromsec, tosec);
1316 if (mismatch) { 1416 if (mismatch) {
1317 Elf_Sym *to; 1417 Elf_Sym *to;
@@ -1339,10 +1439,10 @@ static unsigned int *reloc_location(struct elf_info *elf,
1339 Elf_Shdr *sechdr, Elf_Rela *r) 1439 Elf_Shdr *sechdr, Elf_Rela *r)
1340{ 1440{
1341 Elf_Shdr *sechdrs = elf->sechdrs; 1441 Elf_Shdr *sechdrs = elf->sechdrs;
1342 int section = sechdr->sh_info; 1442 int section = shndx2secindex(sechdr->sh_info);
1343 1443
1344 return (void *)elf->hdr + sechdrs[section].sh_offset + 1444 return (void *)elf->hdr + sechdrs[section].sh_offset +
1345 (r->r_offset - sechdrs[section].sh_addr); 1445 r->r_offset;
1346} 1446}
1347 1447
1348static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) 1448static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
@@ -1447,7 +1547,7 @@ static void section_rela(const char *modname, struct elf_info *elf,
1447 r.r_addend = TO_NATIVE(rela->r_addend); 1547 r.r_addend = TO_NATIVE(rela->r_addend);
1448 sym = elf->symtab_start + r_sym; 1548 sym = elf->symtab_start + r_sym;
1449 /* Skip special sections */ 1549 /* Skip special sections */
1450 if (sym->st_shndx >= SHN_LORESERVE) 1550 if (is_shndx_special(sym->st_shndx))
1451 continue; 1551 continue;
1452 check_section_mismatch(modname, elf, &r, sym, fromsec); 1552 check_section_mismatch(modname, elf, &r, sym, fromsec);
1453 } 1553 }
@@ -1505,7 +1605,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
1505 } 1605 }
1506 sym = elf->symtab_start + r_sym; 1606 sym = elf->symtab_start + r_sym;
1507 /* Skip special sections */ 1607 /* Skip special sections */
1508 if (sym->st_shndx >= SHN_LORESERVE) 1608 if (is_shndx_special(sym->st_shndx))
1509 continue; 1609 continue;
1510 check_section_mismatch(modname, elf, &r, sym, fromsec); 1610 check_section_mismatch(modname, elf, &r, sym, fromsec);
1511 } 1611 }
@@ -1515,7 +1615,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
1515 * A module includes a number of sections that are discarded 1615 * A module includes a number of sections that are discarded
1516 * either when loaded or when used as built-in. 1616 * either when loaded or when used as built-in.
1517 * For loaded modules all functions marked __init and all data 1617 * For loaded modules all functions marked __init and all data
1518 * marked __initdata will be discarded when the module has been intialized. 1618 * marked __initdata will be discarded when the module has been initialized.
1519 * Likewise for modules used built-in the sections marked __exit 1619 * Likewise for modules used built-in the sections marked __exit
1520 * are discarded because __exit marked function are supposed to be called 1620 * are discarded because __exit marked function are supposed to be called
1521 * only when a module is unloaded which never happens for built-in modules. 1621 * only when a module is unloaded which never happens for built-in modules.
@@ -1530,7 +1630,7 @@ static void check_sec_ref(struct module *mod, const char *modname,
1530 Elf_Shdr *sechdrs = elf->sechdrs; 1630 Elf_Shdr *sechdrs = elf->sechdrs;
1531 1631
1532 /* Walk through all sections */ 1632 /* Walk through all sections */
1533 for (i = 0; i < elf->hdr->e_shnum; i++) { 1633 for (i = 0; i < elf->num_sections; i++) {
1534 check_section(modname, elf, &elf->sechdrs[i]); 1634 check_section(modname, elf, &elf->sechdrs[i]);
1535 /* We want to process only relocation sections and not .init */ 1635 /* We want to process only relocation sections and not .init */
1536 if (sechdrs[i].sh_type == SHT_RELA) 1636 if (sechdrs[i].sh_type == SHT_RELA)