1 /* vi: set sw=4 ts=4: */
3 * Mini insmod implementation for busybox
5 * Copyright (C) 1999,2000 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>
7 * and Ron Alder <alder@lineo.com>
9 * Modified by Bryan Rittmeyer <bryan@ixiacom.com> to support SH4
10 * and (theoretically) SH3. I have only tested SH4 in little endian mode.
12 * Modified by Alcove, Julien Gaulmin <julien.gaulmin@alcove.fr> and
13 * Nicolas Ferre <nicolas.ferre@alcove.fr> to support ARM7TDMI. Only
14 * very minor changes required to also work with StrongArm and presumably
15 * all ARM based systems.
17 * Based almost entirely on the Linux modutils-2.3.11 implementation.
18 * Copyright 1996, 1997 Linux International.
19 * New implementation contributed by Richard Henderson <rth@tamu.edu>
20 * Based on original work by Bjorn Ekwall <bj0rn@blox.se>
21 * Restructured (and partly rewritten) by:
22 * Björn Ekwall <bj0rn@blox.se> February 1999
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50 #include <sys/utsname.h>
52 //----------------------------------------------------------------------------
53 //--------modutils module.h, lines 45-242
54 //----------------------------------------------------------------------------
56 /* Definitions for the Linux module syscall interface.
57 Copyright 1996, 1997 Linux International.
59 Contributed by Richard Henderson <rth@tamu.edu>
61 This file is part of the Linux modutils.
63 This program is free software; you can redistribute it and/or modify it
64 under the terms of the GNU General Public License as published by the
65 Free Software Foundation; either version 2 of the License, or (at your
66 option) any later version.
68 This program is distributed in the hope that it will be useful, but
69 WITHOUT ANY WARRANTY; without even the implied warranty of
70 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71 General Public License for more details.
73 You should have received a copy of the GNU General Public License
74 along with this program; if not, write to the Free Software Foundation,
75 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
78 #ifndef MODUTILS_MODULE_H
79 static const int MODUTILS_MODULE_H = 1;
81 #ident "$Id: insmod.c,v 1.39 2001/01/24 23:59:50 andersen Exp $"
83 /* This file contains the structures used by the 2.0 and 2.1 kernels.
84 We do not use the kernel headers directly because we do not wish
85 to be dependant on a particular kernel version to compile insmod. */
88 /*======================================================================*/
89 /* The structures used by Linux 2.0. */
91 /* The symbol format used by get_kernel_syms(2). */
100 unsigned long module; /* kernel addresses */
104 struct old_module_symbol
110 struct old_symbol_table
112 int size; /* total, including string table!!! */
115 struct old_module_symbol symbol[0]; /* actual size defined by n_symbols */
116 struct old_module_ref ref[0]; /* actual size defined by n_refs */
119 struct old_mod_routines
122 unsigned long cleanup;
128 unsigned long ref; /* the list of modules that refer to me */
129 unsigned long symtab;
131 int size; /* size of module in pages */
132 unsigned long addr; /* address of module */
134 unsigned long cleanup; /* cleanup routine */
137 /* Sent to init_module(2) or'ed into the code size parameter. */
138 static const int OLD_MOD_AUTOCLEAN = 0x40000000; /* big enough, but no sign problems... */
140 int get_kernel_syms(struct old_kernel_sym *);
141 int old_sys_init_module(const char *name, char *code, unsigned codesize,
142 struct old_mod_routines *, struct old_symbol_table *);
144 /*======================================================================*/
145 /* For sizeof() which are related to the module platform and not to the
146 environment isnmod is running in, use sizeof_xx instead of sizeof(xx). */
148 #define tgt_sizeof_char sizeof(char)
149 #define tgt_sizeof_short sizeof(short)
150 #define tgt_sizeof_int sizeof(int)
151 #define tgt_sizeof_long sizeof(long)
152 #define tgt_sizeof_char_p sizeof(char *)
153 #define tgt_sizeof_void_p sizeof(void *)
154 #define tgt_long long
156 #if defined(__sparc__) && !defined(__sparc_v9__) && defined(ARCH_sparc64)
157 #undef tgt_sizeof_long
158 #undef tgt_sizeof_char_p
159 #undef tgt_sizeof_void_p
161 static const int tgt_sizeof_long = 8;
162 static const int tgt_sizeof_char_p = 8;
163 static const int tgt_sizeof_void_p = 8;
164 #define tgt_long long long
167 /*======================================================================*/
168 /* The structures used in Linux 2.1. */
170 /* Note: new_module_symbol does not use tgt_long intentionally */
171 struct new_module_symbol
177 struct new_module_persist;
179 struct new_module_ref
181 unsigned tgt_long dep; /* kernel addresses */
182 unsigned tgt_long ref;
183 unsigned tgt_long next_ref;
188 unsigned tgt_long size_of_struct; /* == sizeof(module) */
189 unsigned tgt_long next;
190 unsigned tgt_long name;
191 unsigned tgt_long size;
194 unsigned tgt_long flags; /* AUTOCLEAN et al */
199 unsigned tgt_long syms;
200 unsigned tgt_long deps;
201 unsigned tgt_long refs;
202 unsigned tgt_long init;
203 unsigned tgt_long cleanup;
204 unsigned tgt_long ex_table_start;
205 unsigned tgt_long ex_table_end;
207 unsigned tgt_long gp;
209 /* Everything after here is extension. */
210 unsigned tgt_long persist_start;
211 unsigned tgt_long persist_end;
212 unsigned tgt_long can_unload;
213 unsigned tgt_long runsize;
216 struct new_module_info
224 /* Bits of module.flags. */
225 static const int NEW_MOD_RUNNING = 1;
226 static const int NEW_MOD_DELETED = 2;
227 static const int NEW_MOD_AUTOCLEAN = 4;
228 static const int NEW_MOD_VISITED = 8;
229 static const int NEW_MOD_USED_ONCE = 16;
231 int new_sys_init_module(const char *name, const struct new_module *);
232 int query_module(const char *name, int which, void *buf, size_t bufsize,
235 /* Values for query_module's which. */
237 static const int QM_MODULES = 1;
238 static const int QM_DEPS = 2;
239 static const int QM_REFS = 3;
240 static const int QM_SYMBOLS = 4;
241 static const int QM_INFO = 5;
243 /*======================================================================*/
244 /* The system calls unchanged between 2.0 and 2.1. */
246 unsigned long create_module(const char *, size_t);
247 int delete_module(const char *);
250 #endif /* module.h */
252 //----------------------------------------------------------------------------
253 //--------end of modutils module.h
254 //----------------------------------------------------------------------------
258 //----------------------------------------------------------------------------
259 //--------modutils obj.h, lines 253-462
260 //----------------------------------------------------------------------------
262 /* Elf object file loading and relocation routines.
263 Copyright 1996, 1997 Linux International.
265 Contributed by Richard Henderson <rth@tamu.edu>
267 This file is part of the Linux modutils.
269 This program is free software; you can redistribute it and/or modify it
270 under the terms of the GNU General Public License as published by the
271 Free Software Foundation; either version 2 of the License, or (at your
272 option) any later version.
274 This program is distributed in the hope that it will be useful, but
275 WITHOUT ANY WARRANTY; without even the implied warranty of
276 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
277 General Public License for more details.
279 You should have received a copy of the GNU General Public License
280 along with this program; if not, write to the Free Software Foundation,
281 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
284 #ifndef MODUTILS_OBJ_H
285 static const int MODUTILS_OBJ_H = 1;
287 #ident "$Id: insmod.c,v 1.39 2001/01/24 23:59:50 andersen Exp $"
289 /* The relocatable object is manipulated using elfin types. */
295 /* Machine-specific elf macros for i386 et al. */
297 /* the SH changes have only been tested on the SH4 in =little endian= mode */
298 /* I'm not sure about big endian, so let's warn: */
300 #if (defined(__SH4__) || defined(__SH3__)) && defined(__BIG_ENDIAN__)
301 #error insmod.c may require changes for use on big endian SH4/SH3
304 /* it may or may not work on the SH1/SH2... So let's error on those
306 #if (defined(__sh__) && (!(defined(__SH3__) || defined(__SH4__))))
307 #error insmod.c may require changes for non-SH3/SH4 use
310 #define ELFCLASSM ELFCLASS32
311 #define ELFDATAM ELFDATA2LSB
317 #define MATCH_MACHINE(x) (x == EM_SH)
318 #define SHT_RELM SHT_RELA
319 #define Elf32_RelM Elf32_Rela
321 #elif defined(__arm__)
323 #define MATCH_MACHINE(x) (x == EM_ARM)
324 #define SHT_RELM SHT_REL
325 #define Elf32_RelM Elf32_Rel
327 #elif defined(__i386__)
329 /* presumably we can use these for anything but the SH and ARM*/
330 /* this is the previous behavior, but it does result in
331 insmod.c being broken on anything except i386 */
333 #define MATCH_MACHINE(x) (x == EM_386)
335 #define MATCH_MACHINE(x) (x == EM_386 || x == EM_486)
338 #define SHT_RELM SHT_REL
339 #define Elf32_RelM Elf32_Rel
342 #error insmod.c no platform specified
346 # if ELFCLASSM == ELFCLASS32
347 # define ElfW(x) Elf32_ ## x
348 # define ELFW(x) ELF32_ ## x
350 # define ElfW(x) Elf64_ ## x
351 # define ELFW(x) ELF64_ ## x
355 /* For some reason this is missing from libc5. */
356 #ifndef ELF32_ST_INFO
357 # define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
360 #ifndef ELF64_ST_INFO
361 # define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
364 struct obj_string_patch;
365 struct obj_symbol_patch;
372 struct obj_section *load_next;
378 struct obj_symbol *next; /* hash table link */
382 int secidx; /* the defining section index/module */
384 int ksymidx; /* for export to the kernel symtab */
385 int referenced; /* actually used in the link */
388 /* Hardcode the hash table size. We shouldn't be needing so many
389 symbols that we begin to degrade performance, and we get a big win
390 by giving the compiler a constant divisor. */
392 #define HASH_BUCKETS 521
398 struct obj_section **sections;
399 struct obj_section *load_order;
400 struct obj_section **load_order_search_start;
401 struct obj_string_patch *string_patches;
402 struct obj_symbol_patch *symbol_patches;
403 int (*symbol_cmp)(const char *, const char *);
404 unsigned long (*symbol_hash)(const char *);
405 unsigned long local_symtab_size;
406 struct obj_symbol **local_symtab;
407 struct obj_symbol *symtab[HASH_BUCKETS];
418 struct obj_string_patch
420 struct obj_string_patch *next;
422 ElfW(Addr) reloc_offset;
423 ElfW(Addr) string_offset;
426 struct obj_symbol_patch
428 struct obj_symbol_patch *next;
430 ElfW(Addr) reloc_offset;
431 struct obj_symbol *sym;
435 /* Generic object manipulation routines. */
437 unsigned long obj_elf_hash(const char *);
439 unsigned long obj_elf_hash_n(const char *, unsigned long len);
441 struct obj_symbol *obj_add_symbol (struct obj_file *f, const char *name,
442 unsigned long symidx, int info, int secidx,
443 ElfW(Addr) value, unsigned long size);
445 struct obj_symbol *obj_find_symbol (struct obj_file *f,
448 ElfW(Addr) obj_symbol_final_value(struct obj_file *f,
449 struct obj_symbol *sym);
451 void obj_set_symbol_compare(struct obj_file *f,
452 int (*cmp)(const char *, const char *),
453 unsigned long (*hash)(const char *));
455 struct obj_section *obj_find_section (struct obj_file *f,
458 void obj_insert_section_load_order (struct obj_file *f,
459 struct obj_section *sec);
461 struct obj_section *obj_create_alloced_section (struct obj_file *f,
466 struct obj_section *obj_create_alloced_section_first (struct obj_file *f,
471 void *obj_extend_section (struct obj_section *sec, unsigned long more);
473 int obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
476 int obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
477 struct obj_symbol *sym);
479 int obj_check_undefineds(struct obj_file *f);
481 void obj_allocate_commons(struct obj_file *f);
483 unsigned long obj_load_size (struct obj_file *f);
485 int obj_relocate (struct obj_file *f, ElfW(Addr) base);
487 struct obj_file *obj_load(FILE *f);
489 int obj_create_image (struct obj_file *f, char *image);
491 /* Architecture specific manipulation routines. */
493 struct obj_file *arch_new_file (void);
495 struct obj_section *arch_new_section (void);
497 struct obj_symbol *arch_new_symbol (void);
499 enum obj_reloc arch_apply_relocation (struct obj_file *f,
500 struct obj_section *targsec,
501 struct obj_section *symsec,
502 struct obj_symbol *sym,
503 ElfW(RelM) *rel, ElfW(Addr) value);
505 int arch_create_got (struct obj_file *f);
508 int arch_init_module (struct obj_file *f, struct new_module *);
511 //----------------------------------------------------------------------------
512 //--------end of modutils obj.h
513 //----------------------------------------------------------------------------
519 #define _PATH_MODULES "/lib/modules"
520 static const int STRVERSIONLEN = 32;
522 /*======================================================================*/
524 int flag_force_load = 0;
525 int flag_autoclean = 0;
526 int flag_verbose = 0;
530 /*======================================================================*/
532 /* previously, these were named i386_* but since we could be
533 compiling for the sh, I've renamed them to the more general
534 arch_* These structures are the same between the x86 and SH,
535 and we can't support anything else right now anyway. In the
536 future maybe they should be #if defined'd */
545 int inited:1; /* has been set up */
549 struct arch_got_entry {
551 unsigned offset_done:1;
552 unsigned reloc_done:1;
556 struct obj_file root;
558 struct obj_section *plt;
560 struct obj_section *got;
564 struct obj_symbol root;
566 struct arm_plt_entry pltent;
568 struct arch_got_entry gotent;
572 struct external_module {
577 struct new_module_symbol *syms;
580 struct new_module_symbol *ksyms;
583 struct external_module *ext_modules;
585 int n_ext_modules_used;
589 /* Some firendly syscalls to cheer everyone's day... */
590 #define __NR_new_sys_init_module __NR_init_module
591 _syscall2(int, new_sys_init_module, const char *, name,
592 const struct new_module *, info)
593 #define __NR_old_sys_init_module __NR_init_module
594 _syscall5(int, old_sys_init_module, const char *, name, char *, code,
595 unsigned, codesize, struct old_mod_routines *, routines,
596 struct old_symbol_table *, symtab)
598 _syscall1(int, delete_module, const char *, name)
600 extern int delete_module(const char *);
603 /* This is kind of troublesome. See, we don't actually support
604 the m68k or the arm the same way we support i386 and (now)
605 sh. In doing my SH patch, I just assumed that whatever works
606 for i386 also works for m68k and arm since currently insmod.c
607 does nothing special for them. If this isn't true, the below
608 line is rather misleading IMHO, and someone should either
609 change it or add more proper architecture-dependent support
612 -- Bryan Rittmeyer <bryan@ixiacom.com> */
614 #ifdef BB_FEATURE_OLD_MODULE_INTERFACE
615 _syscall1(int, get_kernel_syms, struct old_kernel_sym *, ks)
618 #if defined(__i386__) || defined(__m68k__) || defined(__arm__)
619 /* Jump through hoops to fixup error return codes */
620 #define __NR__create_module __NR_create_module
621 static inline _syscall2(long, _create_module, const char *, name, size_t,
623 unsigned long create_module(const char *name, size_t size)
625 long ret = _create_module(name, size);
627 if (ret == -1 && errno > 125) {
634 _syscall2(unsigned long, create_module, const char *, name, size_t, size)
636 static char m_filename[BUFSIZ + 1] = "\0";
637 static char m_fullName[BUFSIZ + 1] = "\0";
639 /*======================================================================*/
642 static int findNamedModule(const char *fileName, struct stat *statbuf,
645 char *fullName = (char *) userDate;
648 if (fullName[0] == '\0')
651 char *tmp = strrchr((char *) fileName, '/');
654 tmp = (char *) fileName;
657 if (check_wildcard_match(tmp, fullName) == TRUE) {
658 /* Stop searching if we find a match */
659 memcpy(m_filename, fileName, strlen(fileName)+1);
667 /*======================================================================*/
669 struct obj_file *arch_new_file(void)
672 f = xmalloc(sizeof(*f));
677 struct obj_section *arch_new_section(void)
679 return xmalloc(sizeof(struct obj_section));
682 struct obj_symbol *arch_new_symbol(void)
684 struct arch_symbol *sym;
685 sym = xmalloc(sizeof(*sym));
686 memset(&sym->gotent, 0, sizeof(sym->gotent));
691 arch_apply_relocation(struct obj_file *f,
692 struct obj_section *targsec,
693 struct obj_section *symsec,
694 struct obj_symbol *sym,
695 ElfW(RelM) *rel, ElfW(Addr) v)
697 struct arch_file *ifile = (struct arch_file *) f;
698 struct arch_symbol *isym = (struct arch_symbol *) sym;
700 ElfW(Addr) *loc = (ElfW(Addr) *) (targsec->contents + rel->r_offset);
701 ElfW(Addr) dot = targsec->header.sh_addr + rel->r_offset;
702 ElfW(Addr) got = ifile->got ? ifile->got->header.sh_addr : 0;
704 ElfW(Addr) plt = ifile->plt ? ifile->plt->header.sh_addr : 0;
706 struct arm_plt_entry *pe;
710 enum obj_reloc ret = obj_reloc_ok;
712 switch (ELF32_R_TYPE(rel->r_info)) {
714 /* even though these constants seem to be the same for
715 the i386 and the sh, we "#if define" them for clarity
716 and in case that ever changes */
719 #elif defined(__arm__)
721 #elif defined(__i386__)
728 #elif defined(__arm__)
730 #elif defined(__i386__)
737 #elif defined(__sh__)
741 #elif defined(__i386__)
752 #elif defined(__arm__)
755 /* find the plt entry and initialize it if necessary */
756 assert(isym != NULL);
757 pe = (struct arm_plt_entry*) &isym->pltent;
759 ip = (unsigned long *) (ifile->plt->contents + pe->offset);
760 ip[0] = 0xe51ff004; /* ldr pc,[pc,#-4] */
761 ip[1] = v; /* sym@ */
765 /* relative distance to target */
767 /* if the target is too far away.... */
768 if ((int)v < -0x02000000 || (int)v >= 0x02000000) {
770 v = plt + pe->offset - dot;
773 ret = obj_reloc_dangerous;
775 /* Convert to words. */
778 /* merge the offset into the instruction. */
779 *loc = (*loc & ~0x00ffffff) | ((v + *loc) & 0x00ffffff);
781 #elif defined(__i386__)
786 #elif defined(__sh__)
791 #elif defined(__i386__)
799 #elif defined(__sh__)
801 *loc += f->baseaddr + rel->r_addend;
803 #elif defined(__i386__)
811 #elif defined(__arm__)
813 #elif defined(__i386__)
818 *loc += got - dot + rel->r_addend;;
819 #elif defined(__i386__) || defined(__arm__)
826 #elif defined(__arm__)
828 #elif defined(__i386__)
831 assert(isym != NULL);
832 /* needs an entry in the .got: set it, once */
833 if (!isym->gotent.reloc_done) {
834 isym->gotent.reloc_done = 1;
835 *(ElfW(Addr) *) (ifile->got->contents + isym->gotent.offset) = v;
837 /* make the reloc with_respect_to_.got */
839 *loc += isym->gotent.offset + rel->r_addend;
840 #elif defined(__i386__) || defined(__arm__)
841 *loc += isym->gotent.offset;
845 /* address relative to the got */
848 #elif defined(__arm__)
850 #elif defined(__i386__)
858 printf("Warning: unhandled reloc %d\n",(int)ELF32_R_TYPE(rel->r_info));
859 ret = obj_reloc_unhandled;
866 int arch_create_got(struct obj_file *f)
868 struct arch_file *ifile = (struct arch_file *) f;
869 int i, got_offset = 0, gotneeded = 0;
871 int plt_offset = 0, pltneeded = 0;
873 struct obj_section *relsec, *symsec, *strsec;
874 ElfW(RelM) *rel, *relend;
875 ElfW(Sym) *symtab, *extsym;
876 const char *strtab, *name;
877 struct arch_symbol *intsym;
879 for (i = 0; i < f->header.e_shnum; ++i) {
880 relsec = f->sections[i];
881 if (relsec->header.sh_type != SHT_RELM)
884 symsec = f->sections[relsec->header.sh_link];
885 strsec = f->sections[symsec->header.sh_link];
887 rel = (ElfW(RelM) *) relsec->contents;
888 relend = rel + (relsec->header.sh_size / sizeof(ElfW(RelM)));
889 symtab = (ElfW(Sym) *) symsec->contents;
890 strtab = (const char *) strsec->contents;
892 for (; rel < relend; ++rel) {
893 extsym = &symtab[ELF32_R_SYM(rel->r_info)];
895 switch (ELF32_R_TYPE(rel->r_info)) {
898 #elif defined(__sh__)
900 #elif defined(__i386__)
916 #elif defined(__sh__)
920 #elif defined(__i386__)
930 if (extsym->st_name != 0) {
931 name = strtab + extsym->st_name;
933 name = f->sections[extsym->st_shndx]->name;
935 intsym = (struct arch_symbol *) obj_find_symbol(f, name);
937 if (!intsym->gotent.offset_done) {
938 intsym->gotent.offset_done = 1;
939 intsym->gotent.offset = got_offset;
943 if (pltneeded && intsym->pltent.allocated == 0) {
944 intsym->pltent.allocated = 1;
945 intsym->pltent.offset = plt_offset;
947 intsym->pltent.inited = 0;
956 struct obj_section* relsec = obj_find_section(f, ".got");
959 obj_extend_section(relsec, got_offset);
961 relsec = obj_create_alloced_section(f, ".got", 8, got_offset);
969 ifile->plt = obj_create_alloced_section(f, ".plt", 8, plt_offset);
971 if (got_offset > 0 || gotneeded)
972 ifile->got = obj_create_alloced_section(f, ".got", 4, got_offset);
978 int arch_init_module(struct obj_file *f, struct new_module *mod)
984 /*======================================================================*/
986 /* Standard ELF hash function. */
987 inline unsigned long obj_elf_hash_n(const char *name, unsigned long n)
996 if ((g = (h & 0xf0000000)) != 0) {
1005 unsigned long obj_elf_hash(const char *name)
1007 return obj_elf_hash_n(name, strlen(name));
1010 #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING
1011 /* Get the kernel version in the canonical integer form. */
1013 static int get_kernel_version(char str[STRVERSIONLEN])
1015 struct utsname uts_info;
1019 if (uname(&uts_info) < 0)
1021 strncpy(str, uts_info.release, STRVERSIONLEN);
1022 p = uts_info.release;
1024 a = strtoul(p, &p, 10);
1027 b = strtoul(p + 1, &p, 10);
1030 c = strtoul(p + 1, &q, 10);
1034 return a << 16 | b << 8 | c;
1037 /* String comparison for non-co-versioned kernel and module. */
1039 static int ncv_strcmp(const char *a, const char *b)
1041 size_t alen = strlen(a), blen = strlen(b);
1043 if (blen == alen + 10 && b[alen] == '_' && b[alen + 1] == 'R')
1044 return strncmp(a, b, alen);
1045 else if (alen == blen + 10 && a[blen] == '_' && a[blen + 1] == 'R')
1046 return strncmp(a, b, blen);
1048 return strcmp(a, b);
1051 /* String hashing for non-co-versioned kernel and module. Here
1052 we are simply forced to drop the crc from the hash. */
1054 static unsigned long ncv_symbol_hash(const char *str)
1056 size_t len = strlen(str);
1057 if (len > 10 && str[len - 10] == '_' && str[len - 9] == 'R')
1059 return obj_elf_hash_n(str, len);
1063 obj_set_symbol_compare(struct obj_file *f,
1064 int (*cmp) (const char *, const char *),
1065 unsigned long (*hash) (const char *))
1068 f->symbol_cmp = cmp;
1070 struct obj_symbol *tmptab[HASH_BUCKETS], *sym, *next;
1073 f->symbol_hash = hash;
1075 memcpy(tmptab, f->symtab, sizeof(tmptab));
1076 memset(f->symtab, 0, sizeof(f->symtab));
1078 for (i = 0; i < HASH_BUCKETS; ++i)
1079 for (sym = tmptab[i]; sym; sym = next) {
1080 unsigned long h = hash(sym->name) % HASH_BUCKETS;
1082 sym->next = f->symtab[h];
1088 #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */
1091 struct obj_symbol *obj_add_symbol(struct obj_file *f, const char *name,
1092 unsigned long symidx, int info,
1093 int secidx, ElfW(Addr) value,
1096 struct obj_symbol *sym;
1097 unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS;
1098 int n_type = ELFW(ST_TYPE) (info);
1099 int n_binding = ELFW(ST_BIND) (info);
1101 for (sym = f->symtab[hash]; sym; sym = sym->next)
1102 if (f->symbol_cmp(sym->name, name) == 0) {
1103 int o_secidx = sym->secidx;
1104 int o_info = sym->info;
1105 int o_type = ELFW(ST_TYPE) (o_info);
1106 int o_binding = ELFW(ST_BIND) (o_info);
1108 /* A redefinition! Is it legal? */
1110 if (secidx == SHN_UNDEF)
1112 else if (o_secidx == SHN_UNDEF)
1114 else if (n_binding == STB_GLOBAL && o_binding == STB_LOCAL) {
1115 /* Cope with local and global symbols of the same name
1116 in the same object file, as might have been created
1117 by ld -r. The only reason locals are now seen at this
1118 level at all is so that we can do semi-sensible things
1121 struct obj_symbol *nsym, **p;
1123 nsym = arch_new_symbol();
1124 nsym->next = sym->next;
1127 /* Excise the old (local) symbol from the hash chain. */
1128 for (p = &f->symtab[hash]; *p != sym; p = &(*p)->next)
1132 } else if (n_binding == STB_LOCAL) {
1133 /* Another symbol of the same name has already been defined.
1134 Just add this to the local table. */
1135 sym = arch_new_symbol();
1138 f->local_symtab[symidx] = sym;
1140 } else if (n_binding == STB_WEAK)
1142 else if (o_binding == STB_WEAK)
1144 /* Don't unify COMMON symbols with object types the programmer
1146 else if (secidx == SHN_COMMON
1147 && (o_type == STT_NOTYPE || o_type == STT_OBJECT))
1149 else if (o_secidx == SHN_COMMON
1150 && (n_type == STT_NOTYPE || n_type == STT_OBJECT))
1153 /* Don't report an error if the symbol is coming from
1154 the kernel or some external module. */
1155 if (secidx <= SHN_HIRESERVE)
1156 error_msg("%s multiply defined\n", name);
1161 /* Completely new symbol. */
1162 sym = arch_new_symbol();
1163 sym->next = f->symtab[hash];
1164 f->symtab[hash] = sym;
1167 if (ELFW(ST_BIND) (info) == STB_LOCAL)
1168 f->local_symtab[symidx] = sym;
1174 sym->secidx = secidx;
1180 struct obj_symbol *obj_find_symbol(struct obj_file *f, const char *name)
1182 struct obj_symbol *sym;
1183 unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS;
1185 for (sym = f->symtab[hash]; sym; sym = sym->next)
1186 if (f->symbol_cmp(sym->name, name) == 0)
1193 obj_symbol_final_value(struct obj_file * f, struct obj_symbol * sym)
1196 if (sym->secidx >= SHN_LORESERVE)
1199 return sym->value + f->sections[sym->secidx]->header.sh_addr;
1201 /* As a special case, a NULL sym has value zero. */
1206 struct obj_section *obj_find_section(struct obj_file *f, const char *name)
1208 int i, n = f->header.e_shnum;
1210 for (i = 0; i < n; ++i)
1211 if (strcmp(f->sections[i]->name, name) == 0)
1212 return f->sections[i];
1217 static int obj_load_order_prio(struct obj_section *a)
1219 unsigned long af, ac;
1221 af = a->header.sh_flags;
1224 if (a->name[0] != '.' || strlen(a->name) != 10 ||
1225 strcmp(a->name + 5, ".init"))
1229 if (!(af & SHF_WRITE))
1231 if (af & SHF_EXECINSTR)
1233 if (a->header.sh_type != SHT_NOBITS)
1240 obj_insert_section_load_order(struct obj_file *f, struct obj_section *sec)
1242 struct obj_section **p;
1243 int prio = obj_load_order_prio(sec);
1244 for (p = f->load_order_search_start; *p; p = &(*p)->load_next)
1245 if (obj_load_order_prio(*p) < prio)
1247 sec->load_next = *p;
1251 struct obj_section *obj_create_alloced_section(struct obj_file *f,
1253 unsigned long align,
1256 int newidx = f->header.e_shnum++;
1257 struct obj_section *sec;
1259 f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec));
1260 f->sections[newidx] = sec = arch_new_section();
1262 memset(sec, 0, sizeof(*sec));
1263 sec->header.sh_type = SHT_PROGBITS;
1264 sec->header.sh_flags = SHF_WRITE | SHF_ALLOC;
1265 sec->header.sh_size = size;
1266 sec->header.sh_addralign = align;
1270 sec->contents = xmalloc(size);
1272 obj_insert_section_load_order(f, sec);
1277 struct obj_section *obj_create_alloced_section_first(struct obj_file *f,
1279 unsigned long align,
1282 int newidx = f->header.e_shnum++;
1283 struct obj_section *sec;
1285 f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec));
1286 f->sections[newidx] = sec = arch_new_section();
1288 memset(sec, 0, sizeof(*sec));
1289 sec->header.sh_type = SHT_PROGBITS;
1290 sec->header.sh_flags = SHF_WRITE | SHF_ALLOC;
1291 sec->header.sh_size = size;
1292 sec->header.sh_addralign = align;
1296 sec->contents = xmalloc(size);
1298 sec->load_next = f->load_order;
1299 f->load_order = sec;
1300 if (f->load_order_search_start == &f->load_order)
1301 f->load_order_search_start = &sec->load_next;
1306 void *obj_extend_section(struct obj_section *sec, unsigned long more)
1308 unsigned long oldsize = sec->header.sh_size;
1309 sec->contents = xrealloc(sec->contents, sec->header.sh_size += more);
1310 return sec->contents + oldsize;
1315 /* Conditionally add the symbols from the given symbol set to the
1321 int idx, struct new_module_symbol *syms, size_t nsyms)
1323 struct new_module_symbol *s;
1327 for (i = 0, s = syms; i < nsyms; ++i, ++s) {
1329 /* Only add symbols that are already marked external. If we
1330 override locals we may cause problems for argument initialization.
1331 We will also create a false dependency on the module. */
1332 struct obj_symbol *sym;
1334 sym = obj_find_symbol(f, (char *) s->name);
1335 if (sym && !ELFW(ST_BIND) (sym->info) == STB_LOCAL) {
1336 sym = obj_add_symbol(f, (char *) s->name, -1,
1337 ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE),
1339 /* Did our symbol just get installed? If so, mark the
1340 module as "used". */
1341 if (sym->secidx == idx)
1349 static void add_kernel_symbols(struct obj_file *f)
1351 struct external_module *m;
1354 /* Add module symbols first. */
1356 for (i = 0, m = ext_modules; i < n_ext_modules; ++i, ++m)
1358 && add_symbols_from(f, SHN_HIRESERVE + 2 + i, m->syms,
1359 m->nsyms)) m->used = 1, ++nused;
1361 n_ext_modules_used = nused;
1363 /* And finally the symbols from the kernel proper. */
1366 add_symbols_from(f, SHN_HIRESERVE + 1, ksyms, nksyms);
1369 static char *get_modinfo_value(struct obj_file *f, const char *key)
1371 struct obj_section *sec;
1372 char *p, *v, *n, *ep;
1373 size_t klen = strlen(key);
1375 sec = obj_find_section(f, ".modinfo");
1379 ep = p + sec->header.sh_size;
1382 n = strchr(p, '\0');
1384 if (p + klen == v && strncmp(p, key, klen) == 0)
1387 if (p + klen == n && strcmp(p, key) == 0)
1397 /*======================================================================*/
1398 /* Functions relating to module loading in pre 2.1 kernels. */
1401 old_process_module_arguments(struct obj_file *f, int argc, char **argv)
1405 struct obj_symbol *sym;
1409 if ((q = strchr(p, '=')) == NULL) {
1415 sym = obj_find_symbol(f, p);
1417 /* Also check that the parameter was not resolved from the kernel. */
1418 if (sym == NULL || sym->secidx > SHN_HIRESERVE) {
1419 error_msg("symbol for parameter %s not found\n", p);
1423 loc = (int *) (f->sections[sym->secidx]->contents + sym->value);
1425 /* Do C quoting if we begin with a ". */
1429 str = alloca(strlen(q));
1430 for (r = str, q++; *q != '"'; ++q, ++r) {
1432 error_msg("improperly terminated string argument for %s\n", p);
1434 } else if (*q == '\\')
1468 if (q[1] >= '0' && q[1] <= '7') {
1469 c = (c * 8) + *++q - '0';
1470 if (q[1] >= '0' && q[1] <= '7')
1471 c = (c * 8) + *++q - '0';
1484 obj_string_patch(f, sym->secidx, sym->value, str);
1485 } else if (*q >= '0' && *q <= '9') {
1487 *loc++ = strtoul(q, &q, 0);
1488 while (*q++ == ',');
1490 char *contents = f->sections[sym->secidx]->contents;
1491 char *loc = contents + sym->value;
1492 char *r; /* To search for commas */
1494 /* Break the string with comas */
1495 while ((r = strchr(q, ',')) != (char *) NULL) {
1497 obj_string_patch(f, sym->secidx, loc - contents, q);
1498 loc += sizeof(char *);
1503 obj_string_patch(f, sym->secidx, loc - contents, q);
1512 #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING
1513 static int old_is_module_checksummed(struct obj_file *f)
1515 return obj_find_symbol(f, "Using_Versions") != NULL;
1517 /* Get the module's kernel version in the canonical integer form. */
1520 old_get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
1522 struct obj_symbol *sym;
1526 sym = obj_find_symbol(f, "kernel_version");
1530 p = f->sections[sym->secidx]->contents + sym->value;
1531 strncpy(str, p, STRVERSIONLEN);
1533 a = strtoul(p, &p, 10);
1536 b = strtoul(p + 1, &p, 10);
1539 c = strtoul(p + 1, &q, 10);
1543 return a << 16 | b << 8 | c;
1546 #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */
1548 #ifdef BB_FEATURE_OLD_MODULE_INTERFACE
1550 /* Fetch all the symbols and divvy them up as appropriate for the modules. */
1552 static int old_get_kernel_symbols(const char *m_name)
1554 struct old_kernel_sym *ks, *k;
1555 struct new_module_symbol *s;
1556 struct external_module *mod;
1557 int nks, nms, nmod, i;
1559 nks = get_kernel_syms(NULL);
1561 perror_msg("get_kernel_syms: %s", m_name);
1565 ks = k = xmalloc(nks * sizeof(*ks));
1567 if (get_kernel_syms(ks) != nks) {
1568 perror("inconsistency with get_kernel_syms -- is someone else "
1569 "playing with modules?");
1574 /* Collect the module information. */
1579 while (k->name[0] == '#' && k->name[1]) {
1580 struct old_kernel_sym *k2;
1581 struct new_module_symbol *s;
1583 /* Find out how many symbols this module has. */
1584 for (k2 = k + 1; k2->name[0] != '#'; ++k2)
1588 mod = xrealloc(mod, (++nmod + 1) * sizeof(*mod));
1589 mod[nmod].name = k->name + 1;
1590 mod[nmod].addr = k->value;
1592 mod[nmod].nsyms = nms;
1593 mod[nmod].syms = s = (nms ? xmalloc(nms * sizeof(*s)) : NULL);
1595 for (i = 0, ++k; i < nms; ++i, ++s, ++k) {
1596 s->name = (unsigned long) k->name;
1597 s->value = k->value;
1604 n_ext_modules = nmod + 1;
1606 /* Now collect the symbols for the kernel proper. */
1608 if (k->name[0] == '#')
1611 nksyms = nms = nks - (k - ks);
1612 ksyms = s = (nms ? xmalloc(nms * sizeof(*s)) : NULL);
1614 for (i = 0; i < nms; ++i, ++s, ++k) {
1615 s->name = (unsigned long) k->name;
1616 s->value = k->value;
1622 /* Return the kernel symbol checksum version, or zero if not used. */
1624 static int old_is_kernel_checksummed(void)
1626 /* Using_Versions is the first symbol. */
1628 && strcmp((char *) ksyms[0].name,
1629 "Using_Versions") == 0) return ksyms[0].value;
1635 static int old_create_mod_use_count(struct obj_file *f)
1637 struct obj_section *sec;
1639 sec = obj_create_alloced_section_first(f, ".moduse", sizeof(long),
1642 obj_add_symbol(f, "mod_use_count_", -1,
1643 ELFW(ST_INFO) (STB_LOCAL, STT_OBJECT), sec->idx, 0,
1650 old_init_module(const char *m_name, struct obj_file *f,
1651 unsigned long m_size)
1654 struct old_mod_routines routines;
1655 struct old_symbol_table *symtab;
1658 /* Create the symbol table */
1660 int nsyms = 0, strsize = 0, total;
1662 /* Size things first... */
1665 for (i = 0; i < HASH_BUCKETS; ++i) {
1666 struct obj_symbol *sym;
1667 for (sym = f->symtab[i]; sym; sym = sym->next)
1668 if (ELFW(ST_BIND) (sym->info) != STB_LOCAL
1669 && sym->secidx <= SHN_HIRESERVE)
1671 sym->ksymidx = nsyms++;
1672 strsize += strlen(sym->name) + 1;
1677 total = (sizeof(struct old_symbol_table)
1678 + nsyms * sizeof(struct old_module_symbol)
1679 + n_ext_modules_used * sizeof(struct old_module_ref)
1681 symtab = xmalloc(total);
1682 symtab->size = total;
1683 symtab->n_symbols = nsyms;
1684 symtab->n_refs = n_ext_modules_used;
1686 if (flag_export && nsyms) {
1687 struct old_module_symbol *ksym;
1691 ksym = symtab->symbol;
1692 str = ((char *) ksym + nsyms * sizeof(struct old_module_symbol)
1693 + n_ext_modules_used * sizeof(struct old_module_ref));
1695 for (i = 0; i < HASH_BUCKETS; ++i) {
1696 struct obj_symbol *sym;
1697 for (sym = f->symtab[i]; sym; sym = sym->next)
1698 if (sym->ksymidx >= 0) {
1699 ksym->addr = obj_symbol_final_value(f, sym);
1701 (unsigned long) str - (unsigned long) symtab;
1703 strcpy(str, sym->name);
1704 str += strlen(sym->name) + 1;
1710 if (n_ext_modules_used) {
1711 struct old_module_ref *ref;
1714 ref = (struct old_module_ref *)
1715 ((char *) symtab->symbol + nsyms * sizeof(struct old_module_symbol));
1717 for (i = 0; i < n_ext_modules; ++i)
1718 if (ext_modules[i].used)
1719 ref++->module = ext_modules[i].addr;
1723 /* Fill in routines. */
1726 obj_symbol_final_value(f, obj_find_symbol(f, "init_module"));
1728 obj_symbol_final_value(f, obj_find_symbol(f, "cleanup_module"));
1730 /* Whew! All of the initialization is complete. Collect the final
1731 module image and give it to the kernel. */
1733 image = xmalloc(m_size);
1734 obj_create_image(f, image);
1736 /* image holds the complete relocated module, accounting correctly for
1737 mod_use_count. However the old module kernel support assume that
1738 it is receiving something which does not contain mod_use_count. */
1739 ret = old_sys_init_module(m_name, image + sizeof(long),
1740 m_size | (flag_autoclean ? OLD_MOD_AUTOCLEAN
1741 : 0), &routines, symtab);
1743 perror_msg("init_module: %s", m_name);
1753 #define old_create_mod_use_count(x) TRUE
1754 #define old_init_module(x, y, z) TRUE
1756 #endif /* BB_FEATURE_OLD_MODULE_INTERFACE */
1760 /*======================================================================*/
1761 /* Functions relating to module loading after 2.1.18. */
1764 new_process_module_arguments(struct obj_file *f, int argc, char **argv)
1768 struct obj_symbol *sym;
1769 char *contents, *loc;
1773 if ((q = strchr(p, '=')) == NULL) {
1778 key = alloca(q - p + 6);
1779 memcpy(key, "parm_", 5);
1780 memcpy(key + 5, p, q - p);
1783 p = get_modinfo_value(f, key);
1786 error_msg("invalid parameter %s\n", key);
1790 sym = obj_find_symbol(f, key);
1792 /* Also check that the parameter was not resolved from the kernel. */
1793 if (sym == NULL || sym->secidx > SHN_HIRESERVE) {
1794 error_msg("symbol for parameter %s not found\n", key);
1799 min = strtoul(p, &p, 10);
1801 max = strtoul(p + 1, &p, 10);
1807 contents = f->sections[sym->secidx]->contents;
1808 loc = contents + sym->value;
1812 if ((*p == 's') || (*p == 'c')) {
1815 /* Do C quoting if we begin with a ", else slurp the lot. */
1819 str = alloca(strlen(q));
1820 for (r = str, q++; *q != '"'; ++q, ++r) {
1822 error_msg("improperly terminated string argument for %s\n",
1825 } else if (*q == '\\')
1859 if (q[1] >= '0' && q[1] <= '7') {
1860 c = (c * 8) + *++q - '0';
1861 if (q[1] >= '0' && q[1] <= '7')
1862 c = (c * 8) + *++q - '0';
1879 /* In this case, the string is not quoted. We will break
1880 it using the coma (like for ints). If the user wants to
1881 include comas in a string, he just has to quote it */
1883 /* Search the next coma */
1887 if (r != (char *) NULL) {
1888 /* Recopy the current field */
1889 str = alloca(r - q + 1);
1890 memcpy(str, q, r - q);
1892 /* I don't know if it is usefull, as the previous case
1893 doesn't null terminate the string ??? */
1896 /* Keep next fields */
1907 obj_string_patch(f, sym->secidx, loc - contents, str);
1908 loc += tgt_sizeof_char_p;
1910 /* Array of chars (in fact, matrix !) */
1911 unsigned long charssize; /* size of each member */
1913 /* Get the size of each member */
1914 /* Probably we should do that outside the loop ? */
1915 if (!isdigit(*(p + 1))) {
1916 error_msg("parameter type 'c' for %s must be followed by"
1917 " the maximum size\n", key);
1920 charssize = strtoul(p + 1, (char **) NULL, 10);
1923 if (strlen(str) >= charssize) {
1924 error_msg("string too long for %s (max %ld)\n", key,
1929 /* Copy to location */
1930 strcpy((char *) loc, str);
1934 long v = strtoul(q, &q, 0);
1941 loc += tgt_sizeof_short;
1945 loc += tgt_sizeof_int;
1949 loc += tgt_sizeof_long;
1953 error_msg("unknown parameter type '%c' for %s\n", *p, key);
1968 goto retry_end_of_value;
1972 error_msg("too many values for %s (max %d)\n", key, max);
1979 error_msg("invalid argument syntax for %s\n", key);
1986 error_msg("too few values for %s (min %d)\n", key, min);
1996 #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING
1997 static int new_is_module_checksummed(struct obj_file *f)
1999 const char *p = get_modinfo_value(f, "using_checksums");
2006 /* Get the module's kernel version in the canonical integer form. */
2009 new_get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
2014 p = get_modinfo_value(f, "kernel_version");
2017 strncpy(str, p, STRVERSIONLEN);
2019 a = strtoul(p, &p, 10);
2022 b = strtoul(p + 1, &p, 10);
2025 c = strtoul(p + 1, &q, 10);
2029 return a << 16 | b << 8 | c;
2032 #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */
2035 #ifdef BB_FEATURE_NEW_MODULE_INTERFACE
2037 /* Fetch the loaded modules, and all currently exported symbols. */
2039 static int new_get_kernel_symbols(void)
2041 char *module_names, *mn;
2042 struct external_module *modules, *m;
2043 struct new_module_symbol *syms, *s;
2044 size_t ret, bufsize, nmod, nsyms, i, j;
2046 /* Collect the loaded modules. */
2048 module_names = xmalloc(bufsize = 256);
2050 if (query_module(NULL, QM_MODULES, module_names, bufsize, &ret)) {
2051 if (errno == ENOSPC) {
2052 module_names = xrealloc(module_names, bufsize = ret);
2053 goto retry_modules_load;
2055 perror_msg("QM_MODULES");
2059 n_ext_modules = nmod = ret;
2060 ext_modules = modules = xmalloc(nmod * sizeof(*modules));
2061 memset(modules, 0, nmod * sizeof(*modules));
2063 /* Collect the modules' symbols. */
2065 for (i = 0, mn = module_names, m = modules;
2066 i < nmod; ++i, ++m, mn += strlen(mn) + 1) {
2067 struct new_module_info info;
2069 if (query_module(mn, QM_INFO, &info, sizeof(info), &ret)) {
2070 if (errno == ENOENT) {
2071 /* The module was removed out from underneath us. */
2074 perror_msg("query_module: QM_INFO: %s", mn);
2078 syms = xmalloc(bufsize = 1024);
2080 if (query_module(mn, QM_SYMBOLS, syms, bufsize, &ret)) {
2083 syms = xrealloc(syms, bufsize = ret);
2084 goto retry_mod_sym_load;
2086 /* The module was removed out from underneath us. */
2089 perror_msg("query_module: QM_SYMBOLS: %s", mn);
2096 m->addr = info.addr;
2100 for (j = 0, s = syms; j < nsyms; ++j, ++s) {
2101 s->name += (unsigned long) syms;
2105 /* Collect the kernel's symbols. */
2107 syms = xmalloc(bufsize = 16 * 1024);
2108 retry_kern_sym_load:
2109 if (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) {
2110 if (errno == ENOSPC) {
2111 syms = xrealloc(syms, bufsize = ret);
2112 goto retry_kern_sym_load;
2114 perror_msg("kernel: QM_SYMBOLS");
2117 nksyms = nsyms = ret;
2120 for (j = 0, s = syms; j < nsyms; ++j, ++s) {
2121 s->name += (unsigned long) syms;
2127 /* Return the kernel symbol checksum version, or zero if not used. */
2129 static int new_is_kernel_checksummed(void)
2131 struct new_module_symbol *s;
2134 /* Using_Versions is not the first symbol, but it should be in there. */
2136 for (i = 0, s = ksyms; i < nksyms; ++i, ++s)
2137 if (strcmp((char *) s->name, "Using_Versions") == 0)
2144 static int new_create_this_module(struct obj_file *f, const char *m_name)
2146 struct obj_section *sec;
2148 sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long,
2149 sizeof(struct new_module));
2150 memset(sec->contents, 0, sizeof(struct new_module));
2152 obj_add_symbol(f, "__this_module", -1,
2153 ELFW(ST_INFO) (STB_LOCAL, STT_OBJECT), sec->idx, 0,
2154 sizeof(struct new_module));
2156 obj_string_patch(f, sec->idx, offsetof(struct new_module, name),
2163 static int new_create_module_ksymtab(struct obj_file *f)
2165 struct obj_section *sec;
2168 /* We must always add the module references. */
2170 if (n_ext_modules_used) {
2171 struct new_module_ref *dep;
2172 struct obj_symbol *tm;
2174 sec = obj_create_alloced_section(f, ".kmodtab", tgt_sizeof_void_p,
2175 (sizeof(struct new_module_ref)
2176 * n_ext_modules_used));
2180 tm = obj_find_symbol(f, "__this_module");
2181 dep = (struct new_module_ref *) sec->contents;
2182 for (i = 0; i < n_ext_modules; ++i)
2183 if (ext_modules[i].used) {
2184 dep->dep = ext_modules[i].addr;
2185 obj_symbol_patch(f, sec->idx,
2186 (char *) &dep->ref - sec->contents, tm);
2192 if (flag_export && !obj_find_section(f, "__ksymtab")) {
2197 obj_create_alloced_section(f, "__ksymtab", tgt_sizeof_void_p,
2200 /* We don't want to export symbols residing in sections that
2201 aren't loaded. There are a number of these created so that
2202 we make sure certain module options don't appear twice. */
2204 loaded = alloca(sizeof(int) * (i = f->header.e_shnum));
2206 loaded[i] = (f->sections[i]->header.sh_flags & SHF_ALLOC) != 0;
2208 for (nsyms = i = 0; i < HASH_BUCKETS; ++i) {
2209 struct obj_symbol *sym;
2210 for (sym = f->symtab[i]; sym; sym = sym->next)
2211 if (ELFW(ST_BIND) (sym->info) != STB_LOCAL
2212 && sym->secidx <= SHN_HIRESERVE
2213 && (sym->secidx >= SHN_LORESERVE
2214 || loaded[sym->secidx])) {
2215 ElfW(Addr) ofs = nsyms * 2 * tgt_sizeof_void_p;
2217 obj_symbol_patch(f, sec->idx, ofs, sym);
2218 obj_string_patch(f, sec->idx, ofs + tgt_sizeof_void_p,
2225 obj_extend_section(sec, nsyms * 2 * tgt_sizeof_char_p);
2233 new_init_module(const char *m_name, struct obj_file *f,
2234 unsigned long m_size)
2236 struct new_module *module;
2237 struct obj_section *sec;
2242 sec = obj_find_section(f, ".this");
2243 module = (struct new_module *) sec->contents;
2244 m_addr = sec->header.sh_addr;
2246 module->size_of_struct = sizeof(*module);
2247 module->size = m_size;
2248 module->flags = flag_autoclean ? NEW_MOD_AUTOCLEAN : 0;
2250 sec = obj_find_section(f, "__ksymtab");
2251 if (sec && sec->header.sh_size) {
2252 module->syms = sec->header.sh_addr;
2253 module->nsyms = sec->header.sh_size / (2 * tgt_sizeof_char_p);
2256 if (n_ext_modules_used) {
2257 sec = obj_find_section(f, ".kmodtab");
2258 module->deps = sec->header.sh_addr;
2259 module->ndeps = n_ext_modules_used;
2263 obj_symbol_final_value(f, obj_find_symbol(f, "init_module"));
2265 obj_symbol_final_value(f, obj_find_symbol(f, "cleanup_module"));
2267 sec = obj_find_section(f, "__ex_table");
2269 module->ex_table_start = sec->header.sh_addr;
2270 module->ex_table_end = sec->header.sh_addr + sec->header.sh_size;
2273 sec = obj_find_section(f, ".text.init");
2275 module->runsize = sec->header.sh_addr - m_addr;
2277 sec = obj_find_section(f, ".data.init");
2279 if (!module->runsize ||
2280 module->runsize > sec->header.sh_addr - m_addr)
2281 module->runsize = sec->header.sh_addr - m_addr;
2284 if (!arch_init_module(f, module))
2287 /* Whew! All of the initialization is complete. Collect the final
2288 module image and give it to the kernel. */
2290 image = xmalloc(m_size);
2291 obj_create_image(f, image);
2293 ret = new_sys_init_module(m_name, (struct new_module *) image);
2295 perror_msg("init_module: %s", m_name);
2304 #define new_init_module(x, y, z) TRUE
2305 #define new_create_this_module(x, y) 0
2306 #define new_create_module_ksymtab(x)
2307 #define query_module(v, w, x, y, z) -1
2309 #endif /* BB_FEATURE_NEW_MODULE_INTERFACE */
2312 /*======================================================================*/
2315 obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
2318 struct obj_string_patch *p;
2319 struct obj_section *strsec;
2320 size_t len = strlen(string) + 1;
2323 p = xmalloc(sizeof(*p));
2324 p->next = f->string_patches;
2325 p->reloc_secidx = secidx;
2326 p->reloc_offset = offset;
2327 f->string_patches = p;
2329 strsec = obj_find_section(f, ".kstrtab");
2330 if (strsec == NULL) {
2331 strsec = obj_create_alloced_section(f, ".kstrtab", 1, len);
2332 p->string_offset = 0;
2333 loc = strsec->contents;
2335 p->string_offset = strsec->header.sh_size;
2336 loc = obj_extend_section(strsec, len);
2338 memcpy(loc, string, len);
2344 obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
2345 struct obj_symbol *sym)
2347 struct obj_symbol_patch *p;
2349 p = xmalloc(sizeof(*p));
2350 p->next = f->symbol_patches;
2351 p->reloc_secidx = secidx;
2352 p->reloc_offset = offset;
2354 f->symbol_patches = p;
2359 int obj_check_undefineds(struct obj_file *f)
2364 for (i = 0; i < HASH_BUCKETS; ++i) {
2365 struct obj_symbol *sym;
2366 for (sym = f->symtab[i]; sym; sym = sym->next)
2367 if (sym->secidx == SHN_UNDEF) {
2368 if (ELFW(ST_BIND) (sym->info) == STB_WEAK) {
2369 sym->secidx = SHN_ABS;
2372 error_msg("unresolved symbol %s\n", sym->name);
2381 void obj_allocate_commons(struct obj_file *f)
2383 struct common_entry {
2384 struct common_entry *next;
2385 struct obj_symbol *sym;
2386 } *common_head = NULL;
2390 for (i = 0; i < HASH_BUCKETS; ++i) {
2391 struct obj_symbol *sym;
2392 for (sym = f->symtab[i]; sym; sym = sym->next)
2393 if (sym->secidx == SHN_COMMON) {
2394 /* Collect all COMMON symbols and sort them by size so as to
2395 minimize space wasted by alignment requirements. */
2397 struct common_entry **p, *n;
2398 for (p = &common_head; *p; p = &(*p)->next)
2399 if (sym->size <= (*p)->sym->size)
2402 n = alloca(sizeof(*n));
2410 for (i = 1; i < f->local_symtab_size; ++i) {
2411 struct obj_symbol *sym = f->local_symtab[i];
2412 if (sym && sym->secidx == SHN_COMMON) {
2413 struct common_entry **p, *n;
2414 for (p = &common_head; *p; p = &(*p)->next)
2415 if (sym == (*p)->sym)
2417 else if (sym->size < (*p)->sym->size) {
2418 n = alloca(sizeof(*n));
2428 /* Find the bss section. */
2429 for (i = 0; i < f->header.e_shnum; ++i)
2430 if (f->sections[i]->header.sh_type == SHT_NOBITS)
2433 /* If for some reason there hadn't been one, create one. */
2434 if (i == f->header.e_shnum) {
2435 struct obj_section *sec;
2437 f->sections = xrealloc(f->sections, (i + 1) * sizeof(sec));
2438 f->sections[i] = sec = arch_new_section();
2439 f->header.e_shnum = i + 1;
2441 memset(sec, 0, sizeof(*sec));
2442 sec->header.sh_type = SHT_PROGBITS;
2443 sec->header.sh_flags = SHF_WRITE | SHF_ALLOC;
2448 /* Allocate the COMMONS. */
2450 ElfW(Addr) bss_size = f->sections[i]->header.sh_size;
2451 ElfW(Addr) max_align = f->sections[i]->header.sh_addralign;
2452 struct common_entry *c;
2454 for (c = common_head; c; c = c->next) {
2455 ElfW(Addr) align = c->sym->value;
2457 if (align > max_align)
2459 if (bss_size & (align - 1))
2460 bss_size = (bss_size | (align - 1)) + 1;
2463 c->sym->value = bss_size;
2465 bss_size += c->sym->size;
2468 f->sections[i]->header.sh_size = bss_size;
2469 f->sections[i]->header.sh_addralign = max_align;
2473 /* For the sake of patch relocation and parameter initialization,
2474 allocate zeroed data for NOBITS sections now. Note that after
2475 this we cannot assume NOBITS are really empty. */
2476 for (i = 0; i < f->header.e_shnum; ++i) {
2477 struct obj_section *s = f->sections[i];
2478 if (s->header.sh_type == SHT_NOBITS) {
2479 if (s->header.sh_size != 0)
2480 s->contents = memset(xmalloc(s->header.sh_size),
2481 0, s->header.sh_size);
2485 s->header.sh_type = SHT_PROGBITS;
2490 unsigned long obj_load_size(struct obj_file *f)
2492 unsigned long dot = 0;
2493 struct obj_section *sec;
2495 /* Finalize the positions of the sections relative to one another. */
2497 for (sec = f->load_order; sec; sec = sec->load_next) {
2500 align = sec->header.sh_addralign;
2501 if (align && (dot & (align - 1)))
2502 dot = (dot | (align - 1)) + 1;
2504 sec->header.sh_addr = dot;
2505 dot += sec->header.sh_size;
2511 int obj_relocate(struct obj_file *f, ElfW(Addr) base)
2513 int i, n = f->header.e_shnum;
2516 /* Finalize the addresses of the sections. */
2519 for (i = 0; i < n; ++i)
2520 f->sections[i]->header.sh_addr += base;
2522 /* And iterate over all of the relocations. */
2524 for (i = 0; i < n; ++i) {
2525 struct obj_section *relsec, *symsec, *targsec, *strsec;
2526 ElfW(RelM) * rel, *relend;
2530 relsec = f->sections[i];
2531 if (relsec->header.sh_type != SHT_RELM)
2534 symsec = f->sections[relsec->header.sh_link];
2535 targsec = f->sections[relsec->header.sh_info];
2536 strsec = f->sections[symsec->header.sh_link];
2538 rel = (ElfW(RelM) *) relsec->contents;
2539 relend = rel + (relsec->header.sh_size / sizeof(ElfW(RelM)));
2540 symtab = (ElfW(Sym) *) symsec->contents;
2541 strtab = (const char *) strsec->contents;
2543 for (; rel < relend; ++rel) {
2544 ElfW(Addr) value = 0;
2545 struct obj_symbol *intsym = NULL;
2546 unsigned long symndx;
2547 ElfW(Sym) * extsym = 0;
2550 /* Attempt to find a value to use for this relocation. */
2552 symndx = ELFW(R_SYM) (rel->r_info);
2554 /* Note we've already checked for undefined symbols. */
2556 extsym = &symtab[symndx];
2557 if (ELFW(ST_BIND) (extsym->st_info) == STB_LOCAL) {
2558 /* Local symbols we look up in the local table to be sure
2559 we get the one that is really intended. */
2560 intsym = f->local_symtab[symndx];
2562 /* Others we look up in the hash table. */
2564 if (extsym->st_name)
2565 name = strtab + extsym->st_name;
2567 name = f->sections[extsym->st_shndx]->name;
2568 intsym = obj_find_symbol(f, name);
2571 value = obj_symbol_final_value(f, intsym);
2572 intsym->referenced = 1;
2574 #if SHT_RELM == SHT_RELA
2575 #if defined(__alpha__) && defined(AXP_BROKEN_GAS)
2576 /* Work around a nasty GAS bug, that is fixed as of 2.7.0.9. */
2577 if (!extsym || !extsym->st_name ||
2578 ELFW(ST_BIND) (extsym->st_info) != STB_LOCAL)
2580 value += rel->r_addend;
2584 switch (arch_apply_relocation
2585 (f, targsec, symsec, intsym, rel, value)) {
2589 case obj_reloc_overflow:
2590 errmsg = "Relocation overflow";
2592 case obj_reloc_dangerous:
2593 errmsg = "Dangerous relocation";
2595 case obj_reloc_unhandled:
2596 errmsg = "Unhandled relocation";
2599 error_msg("%s of type %ld for %s\n", errmsg,
2600 (long) ELFW(R_TYPE) (rel->r_info),
2601 strtab + extsym->st_name);
2603 error_msg("%s of type %ld\n", errmsg,
2604 (long) ELFW(R_TYPE) (rel->r_info));
2612 /* Finally, take care of the patches. */
2614 if (f->string_patches) {
2615 struct obj_string_patch *p;
2616 struct obj_section *strsec;
2617 ElfW(Addr) strsec_base;
2618 strsec = obj_find_section(f, ".kstrtab");
2619 strsec_base = strsec->header.sh_addr;
2621 for (p = f->string_patches; p; p = p->next) {
2622 struct obj_section *targsec = f->sections[p->reloc_secidx];
2623 *(ElfW(Addr) *) (targsec->contents + p->reloc_offset)
2624 = strsec_base + p->string_offset;
2628 if (f->symbol_patches) {
2629 struct obj_symbol_patch *p;
2631 for (p = f->symbol_patches; p; p = p->next) {
2632 struct obj_section *targsec = f->sections[p->reloc_secidx];
2633 *(ElfW(Addr) *) (targsec->contents + p->reloc_offset)
2634 = obj_symbol_final_value(f, p->sym);
2641 int obj_create_image(struct obj_file *f, char *image)
2643 struct obj_section *sec;
2644 ElfW(Addr) base = f->baseaddr;
2646 for (sec = f->load_order; sec; sec = sec->load_next) {
2649 if (sec->header.sh_size == 0)
2652 secimg = image + (sec->header.sh_addr - base);
2654 /* Note that we allocated data for NOBITS sections earlier. */
2655 memcpy(secimg, sec->contents, sec->header.sh_size);
2661 /*======================================================================*/
2663 struct obj_file *obj_load(FILE * fp)
2666 ElfW(Shdr) * section_headers;
2670 /* Read the file header. */
2672 f = arch_new_file();
2673 memset(f, 0, sizeof(*f));
2674 f->symbol_cmp = strcmp;
2675 f->symbol_hash = obj_elf_hash;
2676 f->load_order_search_start = &f->load_order;
2678 fseek(fp, 0, SEEK_SET);
2679 if (fread(&f->header, sizeof(f->header), 1, fp) != 1) {
2680 perror_msg("error reading ELF header");
2684 if (f->header.e_ident[EI_MAG0] != ELFMAG0
2685 || f->header.e_ident[EI_MAG1] != ELFMAG1
2686 || f->header.e_ident[EI_MAG2] != ELFMAG2
2687 || f->header.e_ident[EI_MAG3] != ELFMAG3) {
2688 error_msg("not an ELF file\n");
2691 if (f->header.e_ident[EI_CLASS] != ELFCLASSM
2692 || f->header.e_ident[EI_DATA] != ELFDATAM
2693 || f->header.e_ident[EI_VERSION] != EV_CURRENT
2694 || !MATCH_MACHINE(f->header.e_machine)) {
2695 error_msg("ELF file not for this architecture\n");
2698 if (f->header.e_type != ET_REL) {
2699 error_msg("ELF file not a relocatable object\n");
2703 /* Read the section headers. */
2705 if (f->header.e_shentsize != sizeof(ElfW(Shdr))) {
2706 error_msg("section header size mismatch: %lu != %lu\n",
2707 (unsigned long) f->header.e_shentsize,
2708 (unsigned long) sizeof(ElfW(Shdr)));
2712 shnum = f->header.e_shnum;
2713 f->sections = xmalloc(sizeof(struct obj_section *) * shnum);
2714 memset(f->sections, 0, sizeof(struct obj_section *) * shnum);
2716 section_headers = alloca(sizeof(ElfW(Shdr)) * shnum);
2717 fseek(fp, f->header.e_shoff, SEEK_SET);
2718 if (fread(section_headers, sizeof(ElfW(Shdr)), shnum, fp) != shnum) {
2719 perror_msg("error reading ELF section headers");
2723 /* Read the section data. */
2725 for (i = 0; i < shnum; ++i) {
2726 struct obj_section *sec;
2728 f->sections[i] = sec = arch_new_section();
2729 memset(sec, 0, sizeof(*sec));
2731 sec->header = section_headers[i];
2734 switch (sec->header.sh_type) {
2745 if (sec->header.sh_size > 0) {
2746 sec->contents = xmalloc(sec->header.sh_size);
2747 fseek(fp, sec->header.sh_offset, SEEK_SET);
2748 if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) {
2749 perror_msg("error reading ELF section data");
2753 sec->contents = NULL;
2757 #if SHT_RELM == SHT_REL
2759 error_msg("RELA relocations not supported on this architecture\n");
2763 error_msg("REL relocations not supported on this architecture\n");
2768 if (sec->header.sh_type >= SHT_LOPROC) {
2769 /* Assume processor specific section types are debug
2770 info and can safely be ignored. If this is ever not
2771 the case (Hello MIPS?), don't put ifdefs here but
2772 create an arch_load_proc_section(). */
2776 error_msg("can't handle sections of type %ld\n",
2777 (long) sec->header.sh_type);
2782 /* Do what sort of interpretation as needed by each section. */
2784 shstrtab = f->sections[f->header.e_shstrndx]->contents;
2786 for (i = 0; i < shnum; ++i) {
2787 struct obj_section *sec = f->sections[i];
2788 sec->name = shstrtab + sec->header.sh_name;
2791 for (i = 0; i < shnum; ++i) {
2792 struct obj_section *sec = f->sections[i];
2794 if (sec->header.sh_flags & SHF_ALLOC)
2795 obj_insert_section_load_order(f, sec);
2797 switch (sec->header.sh_type) {
2800 unsigned long nsym, j;
2804 if (sec->header.sh_entsize != sizeof(ElfW(Sym))) {
2805 error_msg("symbol size mismatch: %lu != %lu\n",
2806 (unsigned long) sec->header.sh_entsize,
2807 (unsigned long) sizeof(ElfW(Sym)));
2811 nsym = sec->header.sh_size / sizeof(ElfW(Sym));
2812 strtab = f->sections[sec->header.sh_link]->contents;
2813 sym = (ElfW(Sym) *) sec->contents;
2815 /* Allocate space for a table of local symbols. */
2816 j = f->local_symtab_size = sec->header.sh_info;
2817 f->local_symtab = xmalloc(j *=
2818 sizeof(struct obj_symbol *));
2819 memset(f->local_symtab, 0, j);
2821 /* Insert all symbols into the hash table. */
2822 for (j = 1, ++sym; j < nsym; ++j, ++sym) {
2825 name = strtab + sym->st_name;
2827 name = f->sections[sym->st_shndx]->name;
2829 obj_add_symbol(f, name, j, sym->st_info, sym->st_shndx,
2830 sym->st_value, sym->st_size);
2836 if (sec->header.sh_entsize != sizeof(ElfW(RelM))) {
2837 error_msg("relocation entry size mismatch: %lu != %lu\n",
2838 (unsigned long) sec->header.sh_entsize,
2839 (unsigned long) sizeof(ElfW(RelM)));
2849 static void hide_special_symbols(struct obj_file *f)
2851 static const char *const specials[] = {
2858 struct obj_symbol *sym;
2859 const char *const *p;
2861 for (p = specials; *p; ++p)
2862 if ((sym = obj_find_symbol(f, *p)) != NULL)
2864 ELFW(ST_INFO) (STB_LOCAL, ELFW(ST_TYPE) (sym->info));
2869 extern int insmod_main( int argc, char **argv)
2876 unsigned long m_size;
2880 char m_name[BUFSIZ + 1] = "\0";
2881 int exit_status = EXIT_FAILURE;
2883 #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING
2885 char k_strversion[STRVERSIONLEN];
2886 char m_strversion[STRVERSIONLEN];
2891 /* Parse any options */
2892 while ((opt = getopt(argc, argv, "fkvxL")) > 0) {
2894 case 'f': /* force loading */
2895 flag_force_load = 1;
2897 case 'k': /* module loaded by kerneld, auto-cleanable */
2900 case 'v': /* verbose output */
2903 case 'x': /* do not export externs */
2906 case 'L': /* Stub warning */
2907 /* This is needed for compatibility with modprobe.
2908 * In theory, this does locking, but we don't do
2909 * that. So be careful and plan your life around not
2910 * loading the same module 50 times concurrently. */
2913 usage(insmod_usage);
2917 if (argv[optind] == NULL) {
2918 usage(insmod_usage);
2921 /* Grab the module name */
2922 if ((tmp = strrchr(argv[optind], '/')) != NULL) {
2929 if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o')
2931 memcpy(m_name, tmp, len);
2932 strcpy(m_fullName, m_name);
2933 strcat(m_fullName, ".o");
2935 /* Get a filedesc for the module */
2936 if ((fp = fopen(argv[optind], "r")) == NULL) {
2937 /* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */
2938 if (recursive_action(_PATH_MODULES, TRUE, FALSE, FALSE,
2939 findNamedModule, 0, m_fullName) == FALSE)
2941 if (m_filename[0] == '\0'
2942 || ((fp = fopen(m_filename, "r")) == NULL))
2944 error_msg("No module named '%s' found in '%s'\n", m_fullName, _PATH_MODULES);
2945 return EXIT_FAILURE;
2948 error_msg_and_die("No module named '%s' found in '%s'\n", m_fullName, _PATH_MODULES);
2950 memcpy(m_filename, argv[optind], strlen(argv[optind]));
2953 if ((f = obj_load(fp)) == NULL)
2954 perror_msg_and_die("Could not load the module");
2956 if (get_modinfo_value(f, "kernel_version") == NULL)
2961 #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING
2962 /* Version correspondence? */
2964 k_version = get_kernel_version(k_strversion);
2965 if (m_has_modinfo) {
2966 m_version = new_get_module_version(f, m_strversion);
2968 m_version = old_get_module_version(f, m_strversion);
2969 if (m_version == -1) {
2970 error_msg("couldn't find the kernel version the module was "
2976 if (strncmp(k_strversion, m_strversion, STRVERSIONLEN) != 0) {
2977 if (flag_force_load) {
2978 error_msg("Warning: kernel-module version mismatch\n"
2979 "\t%s was compiled for kernel version %s\n"
2980 "\twhile this kernel is version %s\n",
2981 m_filename, m_strversion, k_strversion);
2983 error_msg("kernel-module version mismatch\n"
2984 "\t%s was compiled for kernel version %s\n"
2985 "\twhile this kernel is version %s.\n",
2986 m_filename, m_strversion, k_strversion);
2991 #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */
2993 k_new_syscalls = !query_module(NULL, 0, NULL, 0, NULL);
2995 if (k_new_syscalls) {
2996 #ifdef BB_FEATURE_NEW_MODULE_INTERFACE
2997 if (!new_get_kernel_symbols())
2999 k_crcs = new_is_kernel_checksummed();
3001 error_msg("Not configured to support new kernels\n");
3005 #ifdef BB_FEATURE_OLD_MODULE_INTERFACE
3006 if (!old_get_kernel_symbols(m_name))
3008 k_crcs = old_is_kernel_checksummed();
3010 error_msg("Not configured to support old kernels\n");
3015 #ifdef BB_FEATURE_INSMOD_VERSION_CHECKING
3017 m_crcs = new_is_module_checksummed(f);
3019 m_crcs = old_is_module_checksummed(f);
3021 if (m_crcs != k_crcs)
3022 obj_set_symbol_compare(f, ncv_strcmp, ncv_symbol_hash);
3023 #endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */
3025 /* Let the module know about the kernel symbols. */
3026 add_kernel_symbols(f);
3028 /* Allocate common symbols, symbol tables, and string tables. */
3031 ? !new_create_this_module(f, m_name)
3032 : !old_create_mod_use_count(f))
3037 if (!obj_check_undefineds(f)) {
3040 obj_allocate_commons(f);
3042 /* done with the module name, on to the optional var=value arguments */
3045 if (optind < argc) {
3047 ? !new_process_module_arguments(f, argc - optind, argv + optind)
3048 : !old_process_module_arguments(f, argc - optind, argv + optind))
3055 hide_special_symbols(f);
3058 new_create_module_ksymtab(f);
3060 /* Find current size of the module */
3061 m_size = obj_load_size(f);
3064 m_addr = create_module(m_name, m_size);
3065 if (m_addr==-1) switch (errno) {
3067 error_msg("A module named %s already exists\n", m_name);
3070 error_msg("Can't allocate kernel memory for module; needed %lu bytes\n",
3074 perror_msg("create_module: %s", m_name);
3078 if (!obj_relocate(f, m_addr)) {
3079 delete_module(m_name);
3084 ? !new_init_module(m_name, f, m_size)
3085 : !old_init_module(m_name, f, m_size))
3087 delete_module(m_name);
3091 exit_status = EXIT_SUCCESS;
3095 return(exit_status);