diff options
Diffstat (limited to 'modutils/insmod.c')
-rw-r--r-- | modutils/insmod.c | 54 |
1 files changed, 11 insertions, 43 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c index 3113f7446..be41e4449 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -59,17 +59,6 @@ | |||
59 | */ | 59 | */ |
60 | 60 | ||
61 | #include "busybox.h" | 61 | #include "busybox.h" |
62 | #include <stdlib.h> | ||
63 | #include <stdio.h> | ||
64 | #include <stddef.h> | ||
65 | #include <errno.h> | ||
66 | #include <unistd.h> | ||
67 | #include <dirent.h> | ||
68 | #include <ctype.h> | ||
69 | #include <assert.h> | ||
70 | #include <string.h> | ||
71 | #include <getopt.h> | ||
72 | #include <fcntl.h> | ||
73 | #include <sys/utsname.h> | 62 | #include <sys/utsname.h> |
74 | 63 | ||
75 | #if !defined(CONFIG_FEATURE_2_4_MODULES) && \ | 64 | #if !defined(CONFIG_FEATURE_2_4_MODULES) && \ |
@@ -804,12 +793,12 @@ static int check_module_name_match(const char *filename, struct stat *statbuf, | |||
804 | if (fullname[0] == '\0') | 793 | if (fullname[0] == '\0') |
805 | return (FALSE); | 794 | return (FALSE); |
806 | else { | 795 | else { |
807 | char *tmp, *tmp1 = bb_xstrdup(filename); | 796 | char *tmp, *tmp1 = xstrdup(filename); |
808 | tmp = bb_get_last_path_component(tmp1); | 797 | tmp = bb_get_last_path_component(tmp1); |
809 | if (strcmp(tmp, fullname) == 0) { | 798 | if (strcmp(tmp, fullname) == 0) { |
810 | free(tmp1); | 799 | free(tmp1); |
811 | /* Stop searching if we find a match */ | 800 | /* Stop searching if we find a match */ |
812 | m_filename = bb_xstrdup(filename); | 801 | m_filename = xstrdup(filename); |
813 | return (FALSE); | 802 | return (FALSE); |
814 | } | 803 | } |
815 | free(tmp1); | 804 | free(tmp1); |
@@ -893,7 +882,6 @@ arch_apply_relocation(struct obj_file *f, | |||
893 | * (which is .got) similar to branch, | 882 | * (which is .got) similar to branch, |
894 | * but is full 32 bits relative */ | 883 | * but is full 32 bits relative */ |
895 | 884 | ||
896 | assert(got != 0); | ||
897 | *loc += got - dot; | 885 | *loc += got - dot; |
898 | break; | 886 | break; |
899 | 887 | ||
@@ -902,7 +890,6 @@ arch_apply_relocation(struct obj_file *f, | |||
902 | goto bb_use_plt; | 890 | goto bb_use_plt; |
903 | 891 | ||
904 | case R_ARM_GOTOFF: /* address relative to the got */ | 892 | case R_ARM_GOTOFF: /* address relative to the got */ |
905 | assert(got != 0); | ||
906 | *loc += v - got; | 893 | *loc += v - got; |
907 | break; | 894 | break; |
908 | 895 | ||
@@ -972,7 +959,6 @@ arch_apply_relocation(struct obj_file *f, | |||
972 | break; | 959 | break; |
973 | 960 | ||
974 | case R_386_GOTPC: | 961 | case R_386_GOTPC: |
975 | assert(got != 0); | ||
976 | *loc += got - dot; | 962 | *loc += got - dot; |
977 | break; | 963 | break; |
978 | 964 | ||
@@ -980,7 +966,6 @@ arch_apply_relocation(struct obj_file *f, | |||
980 | goto bb_use_got; | 966 | goto bb_use_got; |
981 | 967 | ||
982 | case R_386_GOTOFF: | 968 | case R_386_GOTOFF: |
983 | assert(got != 0); | ||
984 | *loc += v - got; | 969 | *loc += v - got; |
985 | break; | 970 | break; |
986 | 971 | ||
@@ -1102,7 +1087,6 @@ arch_apply_relocation(struct obj_file *f, | |||
1102 | 1087 | ||
1103 | # ifdef R_68K_GOTOFF | 1088 | # ifdef R_68K_GOTOFF |
1104 | case R_68K_GOTOFF: | 1089 | case R_68K_GOTOFF: |
1105 | assert(got != 0); | ||
1106 | *loc += v - got; | 1090 | *loc += v - got; |
1107 | break; | 1091 | break; |
1108 | # endif | 1092 | # endif |
@@ -1157,9 +1141,6 @@ arch_apply_relocation(struct obj_file *f, | |||
1157 | struct mips_hi16 *next; | 1141 | struct mips_hi16 *next; |
1158 | unsigned long insn; | 1142 | unsigned long insn; |
1159 | 1143 | ||
1160 | /* The value for the HI16 had best be the same. */ | ||
1161 | assert(v == l->value); | ||
1162 | |||
1163 | /* Do the HI16 relocation. Note that we actually don't | 1144 | /* Do the HI16 relocation. Note that we actually don't |
1164 | need to know anything about the LO16 itself, except where | 1145 | need to know anything about the LO16 itself, except where |
1165 | to find the low 16 bits of the addend needed by the LO16. */ | 1146 | to find the low 16 bits of the addend needed by the LO16. */ |
@@ -1408,9 +1389,7 @@ arch_apply_relocation(struct obj_file *f, | |||
1408 | case R_390_PLT32: | 1389 | case R_390_PLT32: |
1409 | case R_390_PLT16DBL: | 1390 | case R_390_PLT16DBL: |
1410 | /* find the plt entry and initialize it. */ | 1391 | /* find the plt entry and initialize it. */ |
1411 | assert(isym != NULL); | ||
1412 | pe = (struct arch_single_entry *) &isym->pltent; | 1392 | pe = (struct arch_single_entry *) &isym->pltent; |
1413 | assert(pe->allocated); | ||
1414 | if (pe->inited == 0) { | 1393 | if (pe->inited == 0) { |
1415 | ip = (unsigned long *)(ifile->plt->contents + pe->offset); | 1394 | ip = (unsigned long *)(ifile->plt->contents + pe->offset); |
1416 | ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */ | 1395 | ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */ |
@@ -1440,15 +1419,12 @@ arch_apply_relocation(struct obj_file *f, | |||
1440 | break; | 1419 | break; |
1441 | 1420 | ||
1442 | case R_390_GOTPC: | 1421 | case R_390_GOTPC: |
1443 | assert(got != 0); | ||
1444 | *(unsigned long *) loc += got - dot; | 1422 | *(unsigned long *) loc += got - dot; |
1445 | break; | 1423 | break; |
1446 | 1424 | ||
1447 | case R_390_GOT12: | 1425 | case R_390_GOT12: |
1448 | case R_390_GOT16: | 1426 | case R_390_GOT16: |
1449 | case R_390_GOT32: | 1427 | case R_390_GOT32: |
1450 | assert(isym != NULL); | ||
1451 | assert(got != 0); | ||
1452 | if (!isym->gotent.inited) | 1428 | if (!isym->gotent.inited) |
1453 | { | 1429 | { |
1454 | isym->gotent.inited = 1; | 1430 | isym->gotent.inited = 1; |
@@ -1466,7 +1442,6 @@ arch_apply_relocation(struct obj_file *f, | |||
1466 | # define R_390_GOTOFF32 R_390_GOTOFF | 1442 | # define R_390_GOTOFF32 R_390_GOTOFF |
1467 | # endif | 1443 | # endif |
1468 | case R_390_GOTOFF32: | 1444 | case R_390_GOTOFF32: |
1469 | assert(got != 0); | ||
1470 | *loc += v - got; | 1445 | *loc += v - got; |
1471 | break; | 1446 | break; |
1472 | 1447 | ||
@@ -1497,7 +1472,6 @@ arch_apply_relocation(struct obj_file *f, | |||
1497 | break; | 1472 | break; |
1498 | 1473 | ||
1499 | case R_SH_GOTPC: | 1474 | case R_SH_GOTPC: |
1500 | assert(got != 0); | ||
1501 | *loc = got - dot + rel->r_addend; | 1475 | *loc = got - dot + rel->r_addend; |
1502 | break; | 1476 | break; |
1503 | 1477 | ||
@@ -1505,7 +1479,6 @@ arch_apply_relocation(struct obj_file *f, | |||
1505 | goto bb_use_got; | 1479 | goto bb_use_got; |
1506 | 1480 | ||
1507 | case R_SH_GOTOFF: | 1481 | case R_SH_GOTOFF: |
1508 | assert(got != 0); | ||
1509 | *loc = v - got; | 1482 | *loc = v - got; |
1510 | break; | 1483 | break; |
1511 | 1484 | ||
@@ -1627,7 +1600,6 @@ arch_apply_relocation(struct obj_file *f, | |||
1627 | case R_X86_64_GOTPCREL: | 1600 | case R_X86_64_GOTPCREL: |
1628 | goto bb_use_got; | 1601 | goto bb_use_got; |
1629 | # if 0 | 1602 | # if 0 |
1630 | assert(isym != NULL); | ||
1631 | if (!isym->gotent.reloc_done) | 1603 | if (!isym->gotent.reloc_done) |
1632 | { | 1604 | { |
1633 | isym->gotent.reloc_done = 1; | 1605 | isym->gotent.reloc_done = 1; |
@@ -1655,12 +1627,10 @@ arch_apply_relocation(struct obj_file *f, | |||
1655 | bb_use_plt: | 1627 | bb_use_plt: |
1656 | 1628 | ||
1657 | /* find the plt entry and initialize it if necessary */ | 1629 | /* find the plt entry and initialize it if necessary */ |
1658 | assert(isym != NULL); | ||
1659 | 1630 | ||
1660 | #if defined(CONFIG_USE_PLT_LIST) | 1631 | #if defined(CONFIG_USE_PLT_LIST) |
1661 | for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;) | 1632 | for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;) |
1662 | pe = pe->next; | 1633 | pe = pe->next; |
1663 | assert(pe != NULL); | ||
1664 | #else | 1634 | #else |
1665 | pe = &isym->pltent; | 1635 | pe = &isym->pltent; |
1666 | #endif | 1636 | #endif |
@@ -1734,7 +1704,6 @@ bb_use_plt: | |||
1734 | #if defined(CONFIG_USE_GOT_ENTRIES) | 1704 | #if defined(CONFIG_USE_GOT_ENTRIES) |
1735 | bb_use_got: | 1705 | bb_use_got: |
1736 | 1706 | ||
1737 | assert(isym != NULL); | ||
1738 | /* needs an entry in the .got: set it, once */ | 1707 | /* needs an entry in the .got: set it, once */ |
1739 | if (!isym->gotent.inited) { | 1708 | if (!isym->gotent.inited) { |
1740 | isym->gotent.inited = 1; | 1709 | isym->gotent.inited = 1; |
@@ -1814,7 +1783,6 @@ static struct obj_section *arch_xsect_init(struct obj_file *f, char *name, | |||
1814 | } else { | 1783 | } else { |
1815 | myrelsec = obj_create_alloced_section(f, name, | 1784 | myrelsec = obj_create_alloced_section(f, name, |
1816 | size, offset); | 1785 | size, offset); |
1817 | assert(myrelsec); | ||
1818 | } | 1786 | } |
1819 | 1787 | ||
1820 | return myrelsec; | 1788 | return myrelsec; |
@@ -3778,14 +3746,14 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename, | |||
3778 | }; | 3746 | }; |
3779 | 3747 | ||
3780 | if (realpath(filename, real)) { | 3748 | if (realpath(filename, real)) { |
3781 | absolute_filename = bb_xstrdup(real); | 3749 | absolute_filename = xstrdup(real); |
3782 | } | 3750 | } |
3783 | else { | 3751 | else { |
3784 | int save_errno = errno; | 3752 | int save_errno = errno; |
3785 | bb_error_msg("cannot get realpath for %s", filename); | 3753 | bb_error_msg("cannot get realpath for %s", filename); |
3786 | errno = save_errno; | 3754 | errno = save_errno; |
3787 | perror(""); | 3755 | perror(""); |
3788 | absolute_filename = bb_xstrdup(filename); | 3756 | absolute_filename = xstrdup(filename); |
3789 | } | 3757 | } |
3790 | 3758 | ||
3791 | lm_name = strlen(m_name); | 3759 | lm_name = strlen(m_name); |
@@ -4022,7 +3990,7 @@ int insmod_main( int argc, char **argv) | |||
4022 | break; | 3990 | break; |
4023 | case 'o': /* name the output module */ | 3991 | case 'o': /* name the output module */ |
4024 | free(m_name); | 3992 | free(m_name); |
4025 | m_name = bb_xstrdup(optarg); | 3993 | m_name = xstrdup(optarg); |
4026 | break; | 3994 | break; |
4027 | case 'L': /* Stub warning */ | 3995 | case 'L': /* Stub warning */ |
4028 | /* This is needed for compatibility with modprobe. | 3996 | /* This is needed for compatibility with modprobe. |
@@ -4045,7 +4013,7 @@ int insmod_main( int argc, char **argv) | |||
4045 | } | 4013 | } |
4046 | 4014 | ||
4047 | /* Grab the module name */ | 4015 | /* Grab the module name */ |
4048 | tmp1 = bb_xstrdup(argv[optind]); | 4016 | tmp1 = xstrdup(argv[optind]); |
4049 | tmp = basename(tmp1); | 4017 | tmp = basename(tmp1); |
4050 | len = strlen(tmp); | 4018 | len = strlen(tmp); |
4051 | 4019 | ||
@@ -4071,10 +4039,10 @@ int insmod_main( int argc, char **argv) | |||
4071 | 4039 | ||
4072 | #if defined(CONFIG_FEATURE_2_6_MODULES) | 4040 | #if defined(CONFIG_FEATURE_2_6_MODULES) |
4073 | if (k_version > 4) | 4041 | if (k_version > 4) |
4074 | m_fullName = bb_xasprintf("%s.ko", tmp); | 4042 | m_fullName = xasprintf("%s.ko", tmp); |
4075 | else | 4043 | else |
4076 | #endif | 4044 | #endif |
4077 | m_fullName = bb_xasprintf("%s.o", tmp); | 4045 | m_fullName = xasprintf("%s.o", tmp); |
4078 | 4046 | ||
4079 | if (!m_name) { | 4047 | if (!m_name) { |
4080 | m_name = tmp; | 4048 | m_name = tmp; |
@@ -4132,7 +4100,7 @@ int insmod_main( int argc, char **argv) | |||
4132 | bb_error_msg_and_die("%s: no module by that name found", m_fullName); | 4100 | bb_error_msg_and_die("%s: no module by that name found", m_fullName); |
4133 | } | 4101 | } |
4134 | } else | 4102 | } else |
4135 | m_filename = bb_xstrdup(argv[optind]); | 4103 | m_filename = xstrdup(argv[optind]); |
4136 | 4104 | ||
4137 | if (flag_verbose) | 4105 | if (flag_verbose) |
4138 | printf("Using %s\n", m_filename); | 4106 | printf("Using %s\n", m_filename); |
@@ -4334,7 +4302,7 @@ int insmod_ng_main( int argc, char **argv) | |||
4334 | struct stat st; | 4302 | struct stat st; |
4335 | unsigned long len; | 4303 | unsigned long len; |
4336 | void *map; | 4304 | void *map; |
4337 | char *filename, *options = bb_xstrdup(""); | 4305 | char *filename, *options = xstrdup(""); |
4338 | 4306 | ||
4339 | filename = argv[1]; | 4307 | filename = argv[1]; |
4340 | if (!filename) { | 4308 | if (!filename) { |
@@ -4356,7 +4324,7 @@ int insmod_ng_main( int argc, char **argv) | |||
4356 | strcat(options, " "); | 4324 | strcat(options, " "); |
4357 | } | 4325 | } |
4358 | 4326 | ||
4359 | fd = bb_xopen3(filename, O_RDONLY, 0); | 4327 | fd = xopen3(filename, O_RDONLY, 0); |
4360 | 4328 | ||
4361 | fstat(fd, &st); | 4329 | fstat(fd, &st); |
4362 | len = st.st_size; | 4330 | len = st.st_size; |