diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-31 23:33:54 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-31 23:33:54 +0000 |
commit | 49325969e75dd85366d9a149625f75c323163723 (patch) | |
tree | fd8b63452925f369f526ab1358810bb9faebddcb | |
parent | 4acdb46ff17a3dd966ddccdc149cda5a18d51a48 (diff) | |
download | busybox-w32-49325969e75dd85366d9a149625f75c323163723.tar.gz busybox-w32-49325969e75dd85366d9a149625f75c323163723.tar.bz2 busybox-w32-49325969e75dd85366d9a149625f75c323163723.zip |
modutils-24: code shrink
function old new delta
helper_create_alloced_section - 117 +117
print_load_map 474 450 -24
bb_init_module_24 4615 4545 -70
obj_create_alloced_section 131 30 -101
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 117/-195) Total: -78 bytes
-rw-r--r-- | modutils/modutils-24.c | 67 |
1 files changed, 30 insertions, 37 deletions
diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c index 4e112a06f..451975ab9 100644 --- a/modutils/modutils-24.c +++ b/modutils/modutils-24.c | |||
@@ -2135,7 +2135,7 @@ obj_insert_section_load_order(struct obj_file *f, struct obj_section *sec) | |||
2135 | *p = sec; | 2135 | *p = sec; |
2136 | } | 2136 | } |
2137 | 2137 | ||
2138 | static struct obj_section *obj_create_alloced_section(struct obj_file *f, | 2138 | static struct obj_section *helper_create_alloced_section(struct obj_file *f, |
2139 | const char *name, | 2139 | const char *name, |
2140 | unsigned long align, | 2140 | unsigned long align, |
2141 | unsigned long size) | 2141 | unsigned long size) |
@@ -2155,31 +2155,29 @@ static struct obj_section *obj_create_alloced_section(struct obj_file *f, | |||
2155 | if (size) | 2155 | if (size) |
2156 | sec->contents = xzalloc(size); | 2156 | sec->contents = xzalloc(size); |
2157 | 2157 | ||
2158 | obj_insert_section_load_order(f, sec); | ||
2159 | |||
2160 | return sec; | 2158 | return sec; |
2161 | } | 2159 | } |
2162 | 2160 | ||
2163 | static struct obj_section *obj_create_alloced_section_first(struct obj_file *f, | 2161 | static struct obj_section *obj_create_alloced_section(struct obj_file *f, |
2164 | const char *name, | 2162 | const char *name, |
2165 | unsigned long align, | 2163 | unsigned long align, |
2166 | unsigned long size) | 2164 | unsigned long size) |
2167 | { | 2165 | { |
2168 | int newidx = f->header.e_shnum++; | ||
2169 | struct obj_section *sec; | 2166 | struct obj_section *sec; |
2170 | 2167 | ||
2171 | f->sections = xrealloc_vector(f->sections, 2, newidx); | 2168 | sec = helper_create_alloced_section(f, name, align, size); |
2172 | f->sections[newidx] = sec = arch_new_section(); | 2169 | obj_insert_section_load_order(f, sec); |
2170 | return sec; | ||
2171 | } | ||
2173 | 2172 | ||
2174 | sec->header.sh_type = SHT_PROGBITS; | 2173 | static struct obj_section *obj_create_alloced_section_first(struct obj_file *f, |
2175 | sec->header.sh_flags = SHF_WRITE | SHF_ALLOC; | 2174 | const char *name, |
2176 | sec->header.sh_size = size; | 2175 | unsigned long align, |
2177 | sec->header.sh_addralign = align; | 2176 | unsigned long size) |
2178 | sec->name = name; | 2177 | { |
2179 | sec->idx = newidx; | 2178 | struct obj_section *sec; |
2180 | if (size) | ||
2181 | sec->contents = xzalloc(size); | ||
2182 | 2179 | ||
2180 | sec = helper_create_alloced_section(f, name, align, size); | ||
2183 | sec->load_next = f->load_order; | 2181 | sec->load_next = f->load_order; |
2184 | f->load_order = sec; | 2182 | f->load_order = sec; |
2185 | if (f->load_order_search_start == &f->load_order) | 2183 | if (f->load_order_search_start == &f->load_order) |
@@ -2202,15 +2200,16 @@ static void *obj_extend_section(struct obj_section *sec, unsigned long more) | |||
2202 | /* Conditionally add the symbols from the given symbol set to the | 2200 | /* Conditionally add the symbols from the given symbol set to the |
2203 | new module. */ | 2201 | new module. */ |
2204 | 2202 | ||
2205 | static int | 2203 | static int add_symbols_from(struct obj_file *f, |
2206 | add_symbols_from( struct obj_file *f, | 2204 | int idx, |
2207 | int idx, struct new_module_symbol *syms, size_t nsyms) | 2205 | struct new_module_symbol *syms, |
2206 | size_t nsyms) | ||
2208 | { | 2207 | { |
2209 | struct new_module_symbol *s; | 2208 | struct new_module_symbol *s; |
2210 | size_t i; | 2209 | size_t i; |
2211 | int used = 0; | 2210 | int used = 0; |
2212 | #ifdef SYMBOL_PREFIX | 2211 | #ifdef SYMBOL_PREFIX |
2213 | char *name_buf = 0; | 2212 | char *name_buf = NULL; |
2214 | size_t name_alloced_size = 0; | 2213 | size_t name_alloced_size = 0; |
2215 | #endif | 2214 | #endif |
2216 | #if ENABLE_FEATURE_CHECK_TAINTED_MODULE | 2215 | #if ENABLE_FEATURE_CHECK_TAINTED_MODULE |
@@ -2900,7 +2899,7 @@ static void obj_check_undefineds(struct obj_file *f) | |||
2900 | 2899 | ||
2901 | for (i = 0; i < HASH_BUCKETS; ++i) { | 2900 | for (i = 0; i < HASH_BUCKETS; ++i) { |
2902 | struct obj_symbol *sym; | 2901 | struct obj_symbol *sym; |
2903 | for (sym = f->symtab[i]; sym; sym = sym->next) | 2902 | for (sym = f->symtab[i]; sym; sym = sym->next) { |
2904 | if (sym->secidx == SHN_UNDEF) { | 2903 | if (sym->secidx == SHN_UNDEF) { |
2905 | if (ELF_ST_BIND(sym->info) == STB_WEAK) { | 2904 | if (ELF_ST_BIND(sym->info) == STB_WEAK) { |
2906 | sym->secidx = SHN_ABS; | 2905 | sym->secidx = SHN_ABS; |
@@ -2910,6 +2909,7 @@ static void obj_check_undefineds(struct obj_file *f) | |||
2910 | bb_error_msg_and_die("unresolved symbol %s", sym->name); | 2909 | bb_error_msg_and_die("unresolved symbol %s", sym->name); |
2911 | } | 2910 | } |
2912 | } | 2911 | } |
2912 | } | ||
2913 | } | 2913 | } |
2914 | } | 2914 | } |
2915 | 2915 | ||
@@ -3074,7 +3074,7 @@ static int obj_relocate(struct obj_file *f, ElfW(Addr) base) | |||
3074 | ElfW(Addr) value = 0; | 3074 | ElfW(Addr) value = 0; |
3075 | struct obj_symbol *intsym = NULL; | 3075 | struct obj_symbol *intsym = NULL; |
3076 | unsigned long symndx; | 3076 | unsigned long symndx; |
3077 | ElfW(Sym) * extsym = 0; | 3077 | ElfW(Sym) *extsym = NULL; |
3078 | const char *errmsg; | 3078 | const char *errmsg; |
3079 | 3079 | ||
3080 | /* Attempt to find a value to use for this relocation. */ | 3080 | /* Attempt to find a value to use for this relocation. */ |
@@ -3634,7 +3634,8 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename, | |||
3634 | version = get_module_version(f, str); /* -1 if not found */ | 3634 | version = get_module_version(f, str); /* -1 if not found */ |
3635 | name = xasprintf("%s%s_O%s_M%0*lX_V%d", | 3635 | name = xasprintf("%s%s_O%s_M%0*lX_V%d", |
3636 | symprefix, m_name, absolute_filename, | 3636 | symprefix, m_name, absolute_filename, |
3637 | (int)(2 * sizeof(statbuf.st_mtime)), statbuf.st_mtime, | 3637 | (int)(2 * sizeof(statbuf.st_mtime)), |
3638 | (long)statbuf.st_mtime, | ||
3638 | version); | 3639 | version); |
3639 | sym = obj_add_symbol(f, name, -1, | 3640 | sym = obj_add_symbol(f, name, -1, |
3640 | ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE), | 3641 | ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE), |
@@ -3645,7 +3646,6 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename, | |||
3645 | free(absolute_filename); | 3646 | free(absolute_filename); |
3646 | #ifdef _NOT_SUPPORTED_ | 3647 | #ifdef _NOT_SUPPORTED_ |
3647 | /* record where the persistent data is going, same address as previous symbol */ | 3648 | /* record where the persistent data is going, same address as previous symbol */ |
3648 | |||
3649 | if (f->persist) { | 3649 | if (f->persist) { |
3650 | name = xasprintf("%s%s_P%s", | 3650 | name = xasprintf("%s%s_P%s", |
3651 | symprefix, m_name, f->persist); | 3651 | symprefix, m_name, f->persist); |
@@ -3656,7 +3656,6 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename, | |||
3656 | } | 3656 | } |
3657 | #endif | 3657 | #endif |
3658 | /* tag the desired sections if size is non-zero */ | 3658 | /* tag the desired sections if size is non-zero */ |
3659 | |||
3660 | for (i = 0; i < ARRAY_SIZE(section_names); ++i) { | 3659 | for (i = 0; i < ARRAY_SIZE(section_names); ++i) { |
3661 | sec = obj_find_section(f, section_names[i]); | 3660 | sec = obj_find_section(f, section_names[i]); |
3662 | if (sec && sec->header.sh_size) { | 3661 | if (sec && sec->header.sh_size) { |
@@ -3678,11 +3677,11 @@ static void print_load_map(struct obj_file *f) | |||
3678 | struct obj_section *sec; | 3677 | struct obj_section *sec; |
3679 | #if ENABLE_FEATURE_INSMOD_LOAD_MAP_FULL | 3678 | #if ENABLE_FEATURE_INSMOD_LOAD_MAP_FULL |
3680 | struct obj_symbol **all, **p; | 3679 | struct obj_symbol **all, **p; |
3681 | int i, nsyms, *loaded; | 3680 | int i, nsyms; |
3681 | char *loaded; /* array of booleans */ | ||
3682 | struct obj_symbol *sym; | 3682 | struct obj_symbol *sym; |
3683 | #endif | 3683 | #endif |
3684 | /* Report on the section layout. */ | 3684 | /* Report on the section layout. */ |
3685 | |||
3686 | printf("Sections: Size %-*s Align\n", | 3685 | printf("Sections: Size %-*s Align\n", |
3687 | (int) (2 * sizeof(void *)), "Address"); | 3686 | (int) (2 * sizeof(void *)), "Address"); |
3688 | 3687 | ||
@@ -3704,14 +3703,12 @@ static void print_load_map(struct obj_file *f) | |||
3704 | } | 3703 | } |
3705 | #if ENABLE_FEATURE_INSMOD_LOAD_MAP_FULL | 3704 | #if ENABLE_FEATURE_INSMOD_LOAD_MAP_FULL |
3706 | /* Quick reference which section indices are loaded. */ | 3705 | /* Quick reference which section indices are loaded. */ |
3707 | |||
3708 | i = f->header.e_shnum; | 3706 | i = f->header.e_shnum; |
3709 | loaded = alloca(sizeof(int) * i); | 3707 | loaded = alloca(i * sizeof(loaded[0])); |
3710 | while (--i >= 0) | 3708 | while (--i >= 0) |
3711 | loaded[i] = ((f->sections[i]->header.sh_flags & SHF_ALLOC) != 0); | 3709 | loaded[i] = ((f->sections[i]->header.sh_flags & SHF_ALLOC) != 0); |
3712 | 3710 | ||
3713 | /* Collect the symbols we'll be listing. */ | 3711 | /* Collect the symbols we'll be listing. */ |
3714 | |||
3715 | for (nsyms = i = 0; i < HASH_BUCKETS; ++i) | 3712 | for (nsyms = i = 0; i < HASH_BUCKETS; ++i) |
3716 | for (sym = f->symtab[i]; sym; sym = sym->next) | 3713 | for (sym = f->symtab[i]; sym; sym = sym->next) |
3717 | if (sym->secidx <= SHN_HIRESERVE | 3714 | if (sym->secidx <= SHN_HIRESERVE |
@@ -3720,7 +3717,7 @@ static void print_load_map(struct obj_file *f) | |||
3720 | ++nsyms; | 3717 | ++nsyms; |
3721 | } | 3718 | } |
3722 | 3719 | ||
3723 | all = alloca(nsyms * sizeof(struct obj_symbol *)); | 3720 | all = alloca(nsyms * sizeof(all[0])); |
3724 | 3721 | ||
3725 | for (i = 0, p = all; i < HASH_BUCKETS; ++i) | 3722 | for (i = 0, p = all; i < HASH_BUCKETS; ++i) |
3726 | for (sym = f->symtab[i]; sym; sym = sym->next) | 3723 | for (sym = f->symtab[i]; sym; sym = sym->next) |
@@ -3760,7 +3757,7 @@ static void print_load_map(struct obj_file *f) | |||
3760 | } | 3757 | } |
3761 | 3758 | ||
3762 | if (ELF_ST_BIND(sym->info) == STB_LOCAL) | 3759 | if (ELF_ST_BIND(sym->info) == STB_LOCAL) |
3763 | type = tolower(type); | 3760 | type |= 0x20; /* tolower. safe for '?' too */ |
3764 | 3761 | ||
3765 | printf("%0*lx %c %s\n", (int) (2 * sizeof(void *)), value, | 3762 | printf("%0*lx %c %s\n", (int) (2 * sizeof(void *)), value, |
3766 | type, sym->name); | 3763 | type, sym->name); |
@@ -3799,10 +3796,7 @@ int FAST_FUNC bb_init_module_24(const char *m_filename, const char *options) | |||
3799 | 3796 | ||
3800 | f = obj_load(fp, LOADBITS); | 3797 | f = obj_load(fp, LOADBITS); |
3801 | 3798 | ||
3802 | if (get_modinfo_value(f, "kernel_version") == NULL) | 3799 | m_has_modinfo = (get_modinfo_value(f, "kernel_version") != NULL); |
3803 | m_has_modinfo = 0; | ||
3804 | else | ||
3805 | m_has_modinfo = 1; | ||
3806 | 3800 | ||
3807 | #if ENABLE_FEATURE_INSMOD_VERSION_CHECKING | 3801 | #if ENABLE_FEATURE_INSMOD_VERSION_CHECKING |
3808 | /* Version correspondence? */ | 3802 | /* Version correspondence? */ |
@@ -3846,13 +3840,12 @@ int FAST_FUNC bb_init_module_24(const char *m_filename, const char *options) | |||
3846 | add_kernel_symbols(f); | 3840 | add_kernel_symbols(f); |
3847 | 3841 | ||
3848 | /* Allocate common symbols, symbol tables, and string tables. */ | 3842 | /* Allocate common symbols, symbol tables, and string tables. */ |
3849 | |||
3850 | new_create_this_module(f, m_name); | 3843 | new_create_this_module(f, m_name); |
3851 | obj_check_undefineds(f); | 3844 | obj_check_undefineds(f); |
3852 | obj_allocate_commons(f); | 3845 | obj_allocate_commons(f); |
3853 | check_tainted_module(f, m_name); | 3846 | check_tainted_module(f, m_name); |
3854 | 3847 | ||
3855 | /* done with the module name, on to the optional var=value arguments */ | 3848 | /* Done with the module name, on to the optional var=value arguments */ |
3856 | new_process_module_arguments(f, options); | 3849 | new_process_module_arguments(f, options); |
3857 | 3850 | ||
3858 | arch_create_got(f); | 3851 | arch_create_got(f); |