diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-22 20:18:37 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-22 20:18:37 +0000 |
commit | 3bc3f08370e9cf6a2fdeb24c767e0745348b688b (patch) | |
tree | 135763f865c31befc5e8f8f3a7d4fe2fef3b55fd /modutils/modutils-24.c | |
parent | 12ff9dc71465cdbb9be7418e293a6d43fdb60cda (diff) | |
download | busybox-w32-3bc3f08370e9cf6a2fdeb24c767e0745348b688b.tar.gz busybox-w32-3bc3f08370e9cf6a2fdeb24c767e0745348b688b.tar.bz2 busybox-w32-3bc3f08370e9cf6a2fdeb24c767e0745348b688b.zip |
modutils-24: small fixes by Harald Kuthe (harald-tuxbox AT arcor.de)
function old new delta
obj_load 819 832 +13
obj_allocate_commons 488 462 -26
bb_init_module_24 4800 4759 -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 13/-67) Total: -54 bytes
Diffstat (limited to 'modutils/modutils-24.c')
-rw-r--r-- | modutils/modutils-24.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c index ecab193ce..7c7568639 100644 --- a/modutils/modutils-24.c +++ b/modutils/modutils-24.c | |||
@@ -2153,7 +2153,7 @@ static struct obj_section *obj_create_alloced_section(struct obj_file *f, | |||
2153 | sec->name = name; | 2153 | sec->name = name; |
2154 | sec->idx = newidx; | 2154 | sec->idx = newidx; |
2155 | if (size) | 2155 | if (size) |
2156 | sec->contents = xmalloc(size); | 2156 | sec->contents = xzalloc(size); |
2157 | 2157 | ||
2158 | obj_insert_section_load_order(f, sec); | 2158 | obj_insert_section_load_order(f, sec); |
2159 | 2159 | ||
@@ -2168,7 +2168,7 @@ static struct obj_section *obj_create_alloced_section_first(struct obj_file *f, | |||
2168 | int newidx = f->header.e_shnum++; | 2168 | int newidx = f->header.e_shnum++; |
2169 | struct obj_section *sec; | 2169 | struct obj_section *sec; |
2170 | 2170 | ||
2171 | f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec)); | 2171 | f->sections = xrealloc_vector(f->sections, 2, newidx); |
2172 | f->sections[newidx] = sec = arch_new_section(); | 2172 | f->sections[newidx] = sec = arch_new_section(); |
2173 | 2173 | ||
2174 | sec->header.sh_type = SHT_PROGBITS; | 2174 | sec->header.sh_type = SHT_PROGBITS; |
@@ -2178,7 +2178,7 @@ static struct obj_section *obj_create_alloced_section_first(struct obj_file *f, | |||
2178 | sec->name = name; | 2178 | sec->name = name; |
2179 | sec->idx = newidx; | 2179 | sec->idx = newidx; |
2180 | if (size) | 2180 | if (size) |
2181 | sec->contents = xmalloc(size); | 2181 | sec->contents = xzalloc(size); |
2182 | 2182 | ||
2183 | sec->load_next = f->load_order; | 2183 | sec->load_next = f->load_order; |
2184 | f->load_order = sec; | 2184 | f->load_order = sec; |
@@ -2574,8 +2574,7 @@ static void new_get_kernel_symbols(void) | |||
2574 | /* Collect the modules' symbols. */ | 2574 | /* Collect the modules' symbols. */ |
2575 | 2575 | ||
2576 | if (nmod) { | 2576 | if (nmod) { |
2577 | ext_modules = modules = xmalloc(nmod * sizeof(*modules)); | 2577 | ext_modules = modules = xzalloc(nmod * sizeof(*modules)); |
2578 | memset(modules, 0, nmod * sizeof(*modules)); | ||
2579 | for (i = 0, mn = module_names, m = modules; | 2578 | for (i = 0, mn = module_names, m = modules; |
2580 | i < nmod; ++i, ++m, mn += strlen(mn) + 1) { | 2579 | i < nmod; ++i, ++m, mn += strlen(mn) + 1) { |
2581 | struct new_module_info info; | 2580 | struct new_module_info info; |
@@ -2655,13 +2654,14 @@ static int new_is_kernel_checksummed(void) | |||
2655 | } | 2654 | } |
2656 | 2655 | ||
2657 | 2656 | ||
2658 | static void new_create_this_module(struct obj_file *f, const char *m_name) | 2657 | static void new_create_this_module(struct obj_file *f, const char *m_name) |
2659 | { | 2658 | { |
2660 | struct obj_section *sec; | 2659 | struct obj_section *sec; |
2661 | 2660 | ||
2662 | sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long, | 2661 | sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long, |
2663 | sizeof(struct new_module)); | 2662 | sizeof(struct new_module)); |
2664 | memset(sec->contents, 0, sizeof(struct new_module)); | 2663 | /* done by obj_create_alloced_section_first: */ |
2664 | /*memset(sec->contents, 0, sizeof(struct new_module));*/ | ||
2665 | 2665 | ||
2666 | obj_add_symbol(f, SPFX "__this_module", -1, | 2666 | obj_add_symbol(f, SPFX "__this_module", -1, |
2667 | ELF_ST_INFO(STB_LOCAL, STT_OBJECT), sec->idx, 0, | 2667 | ELF_ST_INFO(STB_LOCAL, STT_OBJECT), sec->idx, 0, |
@@ -2750,16 +2750,14 @@ static int new_create_module_ksymtab(struct obj_file *f) | |||
2750 | struct obj_symbol *sym; | 2750 | struct obj_symbol *sym; |
2751 | for (sym = f->symtab[i]; sym; sym = sym->next) { | 2751 | for (sym = f->symtab[i]; sym; sym = sym->next) { |
2752 | if (ELF_ST_BIND(sym->info) != STB_LOCAL | 2752 | if (ELF_ST_BIND(sym->info) != STB_LOCAL |
2753 | && sym->secidx <= SHN_HIRESERVE | 2753 | && sym->secidx <= SHN_HIRESERVE |
2754 | && (sym->secidx >= SHN_LORESERVE | 2754 | && (sym->secidx >= SHN_LORESERVE || loaded[sym->secidx]) |
2755 | || loaded[sym->secidx]) | ||
2756 | ) { | 2755 | ) { |
2757 | ElfW(Addr) ofs = nsyms * 2 * tgt_sizeof_void_p; | 2756 | ElfW(Addr) ofs = nsyms * 2 * tgt_sizeof_void_p; |
2758 | 2757 | ||
2759 | obj_symbol_patch(f, sec->idx, ofs, sym); | 2758 | obj_symbol_patch(f, sec->idx, ofs, sym); |
2760 | obj_string_patch(f, sec->idx, ofs + tgt_sizeof_void_p, | 2759 | obj_string_patch(f, sec->idx, ofs + tgt_sizeof_void_p, |
2761 | sym->name); | 2760 | sym->name); |
2762 | |||
2763 | nsyms++; | 2761 | nsyms++; |
2764 | } | 2762 | } |
2765 | } | 2763 | } |
@@ -2972,9 +2970,9 @@ static void obj_allocate_commons(struct obj_file *f) | |||
2972 | if (i == f->header.e_shnum) { | 2970 | if (i == f->header.e_shnum) { |
2973 | struct obj_section *sec; | 2971 | struct obj_section *sec; |
2974 | 2972 | ||
2973 | f->header.e_shnum++; | ||
2975 | f->sections = xrealloc_vector(f->sections, 2, i); | 2974 | f->sections = xrealloc_vector(f->sections, 2, i); |
2976 | f->sections[i] = sec = arch_new_section(); | 2975 | f->sections[i] = sec = arch_new_section(); |
2977 | f->header.e_shnum = i + 1; | ||
2978 | 2976 | ||
2979 | sec->header.sh_type = SHT_PROGBITS; | 2977 | sec->header.sh_type = SHT_PROGBITS; |
2980 | sec->header.sh_flags = SHF_WRITE | SHF_ALLOC; | 2978 | sec->header.sh_flags = SHF_WRITE | SHF_ALLOC; |
@@ -3013,12 +3011,9 @@ static void obj_allocate_commons(struct obj_file *f) | |||
3013 | for (i = 0; i < f->header.e_shnum; ++i) { | 3011 | for (i = 0; i < f->header.e_shnum; ++i) { |
3014 | struct obj_section *s = f->sections[i]; | 3012 | struct obj_section *s = f->sections[i]; |
3015 | if (s->header.sh_type == SHT_NOBITS) { | 3013 | if (s->header.sh_type == SHT_NOBITS) { |
3014 | s->contents = NULL; | ||
3016 | if (s->header.sh_size != 0) | 3015 | if (s->header.sh_size != 0) |
3017 | s->contents = memset(xmalloc(s->header.sh_size), | 3016 | s->contents = xzalloc(s->header.sh_size); |
3018 | 0, s->header.sh_size); | ||
3019 | else | ||
3020 | s->contents = NULL; | ||
3021 | |||
3022 | s->header.sh_type = SHT_PROGBITS; | 3017 | s->header.sh_type = SHT_PROGBITS; |
3023 | } | 3018 | } |
3024 | } | 3019 | } |
@@ -3272,7 +3267,6 @@ static struct obj_file *obj_load(FILE *fp, int loadprogbits UNUSED_PARAM) | |||
3272 | case SHT_NOBITS: | 3267 | case SHT_NOBITS: |
3273 | /* ignore */ | 3268 | /* ignore */ |
3274 | break; | 3269 | break; |
3275 | |||
3276 | case SHT_PROGBITS: | 3270 | case SHT_PROGBITS: |
3277 | #if LOADBITS | 3271 | #if LOADBITS |
3278 | if (!loadprogbits) { | 3272 | if (!loadprogbits) { |
@@ -3283,17 +3277,15 @@ static struct obj_file *obj_load(FILE *fp, int loadprogbits UNUSED_PARAM) | |||
3283 | case SHT_SYMTAB: | 3277 | case SHT_SYMTAB: |
3284 | case SHT_STRTAB: | 3278 | case SHT_STRTAB: |
3285 | case SHT_RELM: | 3279 | case SHT_RELM: |
3280 | sec->contents = NULL; | ||
3286 | if (sec->header.sh_size > 0) { | 3281 | if (sec->header.sh_size > 0) { |
3287 | sec->contents = xmalloc(sec->header.sh_size); | 3282 | sec->contents = xmalloc(sec->header.sh_size); |
3288 | fseek(fp, sec->header.sh_offset, SEEK_SET); | 3283 | fseek(fp, sec->header.sh_offset, SEEK_SET); |
3289 | if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) { | 3284 | if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) { |
3290 | bb_perror_msg_and_die("error reading ELF section data"); | 3285 | bb_perror_msg_and_die("error reading ELF section data"); |
3291 | } | 3286 | } |
3292 | } else { | ||
3293 | sec->contents = NULL; | ||
3294 | } | 3287 | } |
3295 | break; | 3288 | break; |
3296 | |||
3297 | #if SHT_RELM == SHT_REL | 3289 | #if SHT_RELM == SHT_REL |
3298 | case SHT_RELA: | 3290 | case SHT_RELA: |
3299 | bb_error_msg_and_die("RELA relocations not supported on this architecture"); | 3291 | bb_error_msg_and_die("RELA relocations not supported on this architecture"); |