This will be useful when we want to have special handlers which need to go through more hops to print useful information to the user.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -930,6 +930,10 @@ struct sectioncheck { · 929 unmodified lines | ||
| 930 | 930 | const char *good_tosec[20]; |
| 931 | 931 | enum mismatch mismatch; |
| 932 | 932 | const char *symbol_white_list[20]; |
| 933 | + void (*handler)(const char *modname, struct elf_info *elf, | |
| 934 | + const struct sectioncheck* const mismatch, | |
| 935 | + Elf_Rela *r, Elf_Sym *sym, const char *fromsec); | |
| 936 | + | |
| 933 | 937 | }; |
| 934 | 938 | |
| 935 | 939 | static const struct sectioncheck sectioncheck[] = { |
| @@ -1417,37 +1421,49 @@ static void report_sec_mismatch(const char *modname, · 481 unmodified lines | ||
| 1417 | 1421 | fprintf(stderr, "\n"); |
| 1418 | 1422 | } |
| 1419 | 1423 | |
| 1420 | −static void check_section_mismatch(const char *modname, struct elf_info *elf, | |
| 1421 | − Elf_Rela *r, Elf_Sym *sym, const char *fromsec) | |
| 1424 | +static void default_mismatch_handler(const char *modname, struct elf_info *elf, | |
| 1425 | + const struct sectioncheck* const mismatch, | |
| 1426 | + Elf_Rela *r, Elf_Sym *sym, const char *fromsec) | |
| 1422 | 1427 | { |
| 1423 | 1428 | const char *tosec; |
| 1424 | − const struct sectioncheck *mismatch; | |
| 1429 | + Elf_Sym *to; | |
| 1430 | + Elf_Sym *from; | |
| 1431 | + const char *tosym; | |
| 1432 | + const char *fromsym; | |
| 1425 | 1433 | |
| 1426 | 1434 | tosec = sec_name(elf, get_secindex(elf, sym)); |
| 1427 | − mismatch = section_mismatch(fromsec, tosec); | |
| 1435 | + from = find_elf_symbol2(elf, r->r_offset, fromsec); | |
| 1436 | + fromsym = sym_name(elf, from); | |
| 1437 | + to = find_elf_symbol(elf, r->r_addend, sym); | |
| 1438 | + tosym = sym_name(elf, to); | |
| 1439 | + | |
| 1440 | + if (!strncmp(fromsym, "reference___initcall", | |
| 1441 | + sizeof("reference___initcall")-1)) | |
| 1442 | + return; | |
| 1443 | + | |
| 1444 | + /* check whitelist - we may ignore it */ | |
| 1445 | + if (secref_whitelist(mismatch, | |
| 1446 | + fromsec, fromsym, tosec, tosym)) { | |
| 1447 | + report_sec_mismatch(modname, mismatch, | |
| 1448 | + fromsec, r->r_offset, fromsym, | |
| 1449 | + is_function(from), tosec, tosym, | |
| 1450 | + is_function(to)); | |
| 1451 | + } | |
| 1452 | +} | |
| 1453 | + | |
| 1454 | +static void check_section_mismatch(const char *modname, struct elf_info *elf, | |
| 1455 | + Elf_Rela *r, Elf_Sym *sym, const char *fromsec) | |
| 1456 | +{ | |
| 1457 | + const char *tosec = sec_name(elf, get_secindex(elf, sym));; | |
| 1458 | + const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec); | |
| 1459 | + | |
| 1428 | 1460 | if (mismatch) { |
| 1429 | − Elf_Sym *to; | |
| 1430 | − Elf_Sym *from; | |
| 1431 | − const char *tosym; | |
| 1432 | − const char *fromsym; | |
| 1433 | − | |
| 1434 | − from = find_elf_symbol2(elf, r->r_offset, fromsec); | |
| 1435 | − fromsym = sym_name(elf, from); | |
| 1436 | − to = find_elf_symbol(elf, r->r_addend, sym); | |
| 1437 | − tosym = sym_name(elf, to); | |
| 1438 | − | |
| 1439 | − if (!strncmp(fromsym, "reference___initcall", | |
| 1440 | − sizeof("reference___initcall")-1)) | |
| 1441 | − return; | |
| 1442 | − | |
| 1443 | − /* check whitelist - we may ignore it */ | |
| 1444 | − if (secref_whitelist(mismatch, | |
| 1445 | − fromsec, fromsym, tosec, tosym)) { | |
| 1446 | − report_sec_mismatch(modname, mismatch, | |
| 1447 | − fromsec, r->r_offset, fromsym, | |
| 1448 | − is_function(from), tosec, tosym, | |
| 1449 | − is_function(to)); | |
| 1450 | − } | |
| 1461 | + if (mismatch->handler) | |
| 1462 | + mismatch->handler(modname, elf, mismatch, | |
| 1463 | + r, sym, fromsec); | |
| 1464 | + else | |
| 1465 | + default_mismatch_handler(modname, elf, mismatch, | |
| 1466 | + r, sym, fromsec); | |
| 1451 | 1467 | } |
| 1452 | 1468 | } |
| 1453 | 1469 | |