Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/modutils/insmod.c

    r821 r1770  
    4141 *   written by Paul Mackerras, Copyright 1996, 1997 Linux International.
    4242 *   I've only tested the code on mpc8xx platforms in big-endian mode.
    43  *   Did some cleanup and added CONFIG_USE_xxx_ENTRIES...
     43 *   Did some cleanup and added USE_xxx_ENTRIES...
    4444 *
    4545 * Quinn Jensen <jensenq@lineo.com> added MIPS support 23-Feb-2001.
     
    5959 */
    6060
    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>
     61#include "libbb.h"
     62#include <libgen.h>
    7363#include <sys/utsname.h>
    7464
    75 #if !defined(CONFIG_FEATURE_2_4_MODULES) && \
    76     !defined(CONFIG_FEATURE_2_6_MODULES)
    77 #define CONFIG_FEATURE_2_4_MODULES
    78 #endif
    79 
    80 #if !defined(CONFIG_FEATURE_2_4_MODULES)
     65#if !ENABLE_FEATURE_2_4_MODULES && !ENABLE_FEATURE_2_6_MODULES
     66#undef ENABLE_FEATURE_2_4_MODULES
     67#define ENABLE_FEATURE_2_4_MODULES 1
     68#endif
     69
     70#if !ENABLE_FEATURE_2_4_MODULES
    8171#define insmod_ng_main insmod_main
    8272#endif
    8373
    84 #if defined(CONFIG_FEATURE_2_6_MODULES)
     74#if ENABLE_FEATURE_2_6_MODULES
    8575extern int insmod_ng_main( int argc, char **argv);
    8676#endif
    8777
    8878
    89 #if defined(CONFIG_FEATURE_2_4_MODULES)
    90 
    91 
    92 #ifdef CONFIG_FEATURE_INSMOD_LOADINKMEM
     79#if ENABLE_FEATURE_2_4_MODULES
     80
     81
     82#if ENABLE_FEATURE_INSMOD_LOADINKMEM
    9383#define LOADBITS 0
    9484#else
     
    111101#define Elf32_RelM  Elf32_Rel
    112102#define ELFCLASSM   ELFCLASS32
    113 #define CONFIG_USE_PLT_ENTRIES
    114 #define CONFIG_PLT_ENTRY_SIZE 8
    115 #define CONFIG_USE_GOT_ENTRIES
    116 #define CONFIG_GOT_ENTRY_SIZE 8
    117 #define CONFIG_USE_SINGLE
     103#define USE_PLT_ENTRIES
     104#define PLT_ENTRY_SIZE 8
     105#define USE_GOT_ENTRIES
     106#define GOT_ENTRY_SIZE 8
     107#define USE_SINGLE
    118108#endif
    119109
     
    145135#define Elf32_RelM  Elf32_Rela
    146136#define ELFCLASSM   ELFCLASS32
    147 #define CONFIG_USE_SINGLE
     137#define USE_SINGLE
    148138#define SYMBOL_PREFIX   "_"
    149139#endif
     
    172162#define Elf32_RelM  Elf32_Rel
    173163#define ELFCLASSM   ELFCLASS32
    174 #define CONFIG_USE_GOT_ENTRIES
    175 #define CONFIG_GOT_ENTRY_SIZE 4
    176 #define CONFIG_USE_SINGLE
     164#define USE_GOT_ENTRIES
     165#define GOT_ENTRY_SIZE 4
     166#define USE_SINGLE
    177167#endif
    178168
     
    191181#define Elf32_RelM  Elf32_Rela
    192182#define ELFCLASSM   ELFCLASS32
    193 #define CONFIG_USE_GOT_ENTRIES
    194 #define CONFIG_GOT_ENTRY_SIZE 4
    195 #define CONFIG_USE_SINGLE
     183#define USE_GOT_ENTRIES
     184#define GOT_ENTRY_SIZE 4
     185#define USE_SINGLE
    196186#endif
    197187
    198188/* Microblaze */
    199189#if defined(__microblaze__)
    200 #define CONFIG_USE_SINGLE
     190#define USE_SINGLE
    201191#define MATCH_MACHINE(x) (x == EM_XILINX_MICROBLAZE)
    202192#define SHT_RELM    SHT_RELA
     
    241231#define Elf32_RelM  Elf32_Rela
    242232#define ELFCLASSM   ELFCLASS32
    243 #define CONFIG_USE_PLT_ENTRIES
    244 #define CONFIG_PLT_ENTRY_SIZE 16
    245 #define CONFIG_USE_PLT_LIST
    246 #define CONFIG_LIST_ARCHTYPE ElfW(Addr)
    247 #define CONFIG_USE_LIST
     233#define USE_PLT_ENTRIES
     234#define PLT_ENTRY_SIZE 16
     235#define USE_PLT_LIST
     236#define LIST_ARCHTYPE ElfW(Addr)
     237#define USE_LIST
    248238#define ARCHDATAM       "__ftr_fixup"
    249239#endif
     
    255245#define Elf32_RelM  Elf32_Rela
    256246#define ELFCLASSM   ELFCLASS32
    257 #define CONFIG_USE_PLT_ENTRIES
    258 #define CONFIG_PLT_ENTRY_SIZE 8
    259 #define CONFIG_USE_GOT_ENTRIES
    260 #define CONFIG_GOT_ENTRY_SIZE 8
    261 #define CONFIG_USE_SINGLE
     247#define USE_PLT_ENTRIES
     248#define PLT_ENTRY_SIZE 8
     249#define USE_GOT_ENTRIES
     250#define GOT_ENTRY_SIZE 8
     251#define USE_SINGLE
    262252#endif
    263253
     
    268258#define Elf32_RelM  Elf32_Rela
    269259#define ELFCLASSM   ELFCLASS32
    270 #define CONFIG_USE_GOT_ENTRIES
    271 #define CONFIG_GOT_ENTRY_SIZE 4
    272 #define CONFIG_USE_SINGLE
     260#define USE_GOT_ENTRIES
     261#define GOT_ENTRY_SIZE 4
     262#define USE_SINGLE
    273263/* the SH changes have only been tested in =little endian= mode */
    274264/* I'm not sure about big endian, so let's warn: */
     
    291281
    292282/* v850e */
    293 #if defined (__v850e__)
     283#if defined(__v850e__)
    294284#define MATCH_MACHINE(x) ((x) == EM_V850 || (x) == EM_CYGNUS_V850)
    295285#define SHT_RELM    SHT_RELA
    296286#define Elf32_RelM  Elf32_Rela
    297287#define ELFCLASSM   ELFCLASS32
    298 #define CONFIG_USE_PLT_ENTRIES
    299 #define CONFIG_PLT_ENTRY_SIZE 8
    300 #define CONFIG_USE_SINGLE
     288#define USE_PLT_ENTRIES
     289#define PLT_ENTRY_SIZE 8
     290#define USE_SINGLE
    301291#ifndef EM_CYGNUS_V850  /* grumble */
    302292#define EM_CYGNUS_V850  0x9080
     
    309299#define MATCH_MACHINE(x) (x == EM_X86_64)
    310300#define SHT_RELM    SHT_RELA
    311 #define CONFIG_USE_GOT_ENTRIES
    312 #define CONFIG_GOT_ENTRY_SIZE 8
    313 #define CONFIG_USE_SINGLE
     301#define USE_GOT_ENTRIES
     302#define GOT_ENTRY_SIZE 8
     303#define USE_SINGLE
    314304#define Elf64_RelM  Elf64_Rela
    315305#define ELFCLASSM   ELFCLASS64
     
    348338
    349339#ifndef MODUTILS_MODULE_H
    350 /* Why? static const int MODUTILS_MODULE_H = 1;*/
    351 
    352 #ident "$Id: insmod.c,v 1.126 2004/12/26 09:13:32 vapier Exp $"
    353340
    354341/*======================================================================*/
     
    381368
    382369/* Note: new_module_symbol does not use tgt_long intentionally */
    383 struct new_module_symbol
    384 {
     370struct new_module_symbol {
    385371    unsigned long value;
    386372    unsigned long name;
     
    389375struct new_module_persist;
    390376
    391 struct new_module_ref
    392 {
     377struct new_module_ref {
    393378    unsigned tgt_long dep;      /* kernel addresses */
    394379    unsigned tgt_long ref;
     
    396381};
    397382
    398 struct new_module
    399 {
     383struct new_module {
    400384    unsigned tgt_long size_of_struct;   /* == sizeof(module) */
    401385    unsigned tgt_long next;
     
    439423
    440424
    441 struct new_module_info
    442 {
     425struct new_module_info {
    443426    unsigned long addr;
    444427    unsigned long size;
     
    511494
    512495#ifndef MODUTILS_OBJ_H
    513 /* Why? static const int MODUTILS_OBJ_H = 1; */
    514 
    515 #ident "$Id: insmod.c,v 1.126 2004/12/26 09:13:32 vapier Exp $"
    516496
    517497/* The relocatable object is manipulated using elfin types.  */
    518498
    519 #include <stdio.h>
    520499#include <elf.h>
    521500#include <endian.h>
     
    576555#define HASH_BUCKETS  521
    577556
    578 struct obj_file
    579 {
     557struct obj_file {
    580558    ElfW(Ehdr) header;
    581559    ElfW(Addr) baseaddr;
     
    592570};
    593571
    594 enum obj_reloc
    595 {
     572enum obj_reloc {
    596573    obj_reloc_ok,
    597574    obj_reloc_overflow,
     
    600577};
    601578
    602 struct obj_string_patch
    603 {
     579struct obj_string_patch {
    604580    struct obj_string_patch *next;
    605581    int reloc_secidx;
     
    608584};
    609585
    610 struct obj_symbol_patch
    611 {
     586struct obj_symbol_patch {
    612587    struct obj_symbol_patch *next;
    613588    int reloc_secidx;
     
    623598static unsigned long obj_elf_hash_n(const char *, unsigned long len);
    624599
    625 static struct obj_symbol *obj_find_symbol (struct obj_file *f,
     600static struct obj_symbol *obj_find_symbol(struct obj_file *f,
    626601                     const char *name);
    627602
     
    629604                  struct obj_symbol *sym);
    630605
    631 #ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING
     606#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
    632607static void obj_set_symbol_compare(struct obj_file *f,
    633608                int (*cmp)(const char *, const char *),
     
    635610#endif
    636611
    637 static struct obj_section *obj_find_section (struct obj_file *f,
     612static struct obj_section *obj_find_section(struct obj_file *f,
    638613                       const char *name);
    639614
    640 static void obj_insert_section_load_order (struct obj_file *f,
     615static void obj_insert_section_load_order(struct obj_file *f,
    641616                    struct obj_section *sec);
    642617
    643 static struct obj_section *obj_create_alloced_section (struct obj_file *f,
     618static struct obj_section *obj_create_alloced_section(struct obj_file *f,
    644619                        const char *name,
    645620                        unsigned long align,
    646621                        unsigned long size);
    647622
    648 static struct obj_section *obj_create_alloced_section_first (struct obj_file *f,
     623static struct obj_section *obj_create_alloced_section_first(struct obj_file *f,
    649624                              const char *name,
    650625                              unsigned long align,
    651626                              unsigned long size);
    652627
    653 static void *obj_extend_section (struct obj_section *sec, unsigned long more);
     628static void *obj_extend_section(struct obj_section *sec, unsigned long more);
    654629
    655630static int obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
     
    663638static void obj_allocate_commons(struct obj_file *f);
    664639
    665 static unsigned long obj_load_size (struct obj_file *f);
    666 
    667 static int obj_relocate (struct obj_file *f, ElfW(Addr) base);
     640static unsigned long obj_load_size(struct obj_file *f);
     641
     642static int obj_relocate(struct obj_file *f, ElfW(Addr) base);
    668643
    669644static struct obj_file *obj_load(FILE *f, int loadprogbits);
    670645
    671 static int obj_create_image (struct obj_file *f, char *image);
     646static int obj_create_image(struct obj_file *f, char *image);
    672647
    673648/* Architecture specific manipulation routines.  */
    674649
    675 static struct obj_file *arch_new_file (void);
    676 
    677 static struct obj_section *arch_new_section (void);
    678 
    679 static struct obj_symbol *arch_new_symbol (void);
    680 
    681 static enum obj_reloc arch_apply_relocation (struct obj_file *f,
     650static struct obj_file *arch_new_file(void);
     651
     652static struct obj_section *arch_new_section(void);
     653
     654static struct obj_symbol *arch_new_symbol(void);
     655
     656static enum obj_reloc arch_apply_relocation(struct obj_file *f,
    682657                      struct obj_section *targsec,
    683658                      struct obj_section *symsec,
     
    685660                      ElfW(RelM) *rel, ElfW(Addr) value);
    686661
    687 static void arch_create_got (struct obj_file *f);
     662static void arch_create_got(struct obj_file *f);
    688663#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
    689664static int obj_gpl_license(struct obj_file *f, const char **license);
    690 #endif /* ENABLE_FEATURE_CHECK_TAINTED_MODULE */
     665#endif /* FEATURE_CHECK_TAINTED_MODULE */
    691666#endif /* obj.h */
    692667//----------------------------------------------------------------------------
     
    704679
    705680#define _PATH_MODULES   "/lib/modules"
    706 enum { STRVERSIONLEN = 32 };
     681enum { STRVERSIONLEN = 64 };
    707682
    708683/*======================================================================*/
    709684
    710 static int flag_force_load = 0;
    711 static int flag_autoclean = 0;
    712 static int flag_verbose = 0;
    713 static int flag_quiet = 0;
    714 static int flag_export = 1;
    715 
     685#define OPTION_STR "sLo:fkvqx" USE_FEATURE_INSMOD_LOAD_MAP("m")
     686enum {
     687    OPT_s = 0x1, // -s /* log to syslog */
     688        /* Not supported but kernel needs this for request_module(),
     689           as this calls: modprobe -k -s -- <module>
     690           so silently ignore this flag */
     691    OPT_L = 0x2, // -L /* Stub warning */
     692        /* Compatibility with modprobe.
     693           In theory, this does locking, but we don't do
     694           that.  So be careful and plan your life around not
     695           loading the same module 50 times concurrently. */
     696    OPT_o = 0x4, // -o /* name the output module */
     697    OPT_f = 0x8, // -f /* force loading */
     698    OPT_k = 0x10, // -k /* module loaded by kerneld, auto-cleanable */
     699    OPT_v = 0x20, // -v /* verbose output */
     700    OPT_q = 0x40, // -q /* silent */
     701    OPT_x = 0x80, // -x /* do not export externs */
     702    OPT_m = 0x100, // -m /* print module load map */
     703};
     704#define flag_force_load (option_mask32 & OPT_f)
     705#define flag_autoclean (option_mask32 & OPT_k)
     706#define flag_verbose (option_mask32 & OPT_v)
     707#define flag_quiet (option_mask32 & OPT_q)
     708#define flag_noexport (option_mask32 & OPT_x)
     709#if ENABLE_FEATURE_INSMOD_LOAD_MAP
     710#define flag_print_load_map (option_mask32 & OPT_m)
     711#else
     712#define flag_print_load_map 0
     713#endif
    716714
    717715/*======================================================================*/
    718716
    719 #if defined(CONFIG_USE_LIST)
     717#if defined(USE_LIST)
    720718
    721719struct arch_list_entry
    722720{
    723721    struct arch_list_entry *next;
    724     CONFIG_LIST_ARCHTYPE addend;
     722    LIST_ARCHTYPE addend;
    725723    int offset;
    726724    int inited : 1;
     
    729727#endif
    730728
    731 #if defined(CONFIG_USE_SINGLE)
     729#if defined(USE_SINGLE)
    732730
    733731struct arch_single_entry
     
    751749struct arch_file {
    752750    struct obj_file root;
    753 #if defined(CONFIG_USE_PLT_ENTRIES)
     751#if defined(USE_PLT_ENTRIES)
    754752    struct obj_section *plt;
    755753#endif
    756 #if defined(CONFIG_USE_GOT_ENTRIES)
     754#if defined(USE_GOT_ENTRIES)
    757755    struct obj_section *got;
    758756#endif
     
    764762struct arch_symbol {
    765763    struct obj_symbol root;
    766 #if defined(CONFIG_USE_PLT_ENTRIES)
    767 #if defined(CONFIG_USE_PLT_LIST)
     764#if defined(USE_PLT_ENTRIES)
     765#if defined(USE_PLT_LIST)
    768766    struct arch_list_entry *pltent;
    769767#else
     
    771769#endif
    772770#endif
    773 #if defined(CONFIG_USE_GOT_ENTRIES)
     771#if defined(USE_GOT_ENTRIES)
    774772    struct arch_single_entry gotent;
    775773#endif
     
    797795
    798796
    799 
    800797/*======================================================================*/
    801798
    802799
    803800static int check_module_name_match(const char *filename, struct stat *statbuf,
    804                            void *userdata)
     801                void *userdata, int depth)
    805802{
    806803    char *fullname = (char *) userdata;
    807804
    808805    if (fullname[0] == '\0')
    809         return (FALSE);
     806        return FALSE;
    810807    else {
    811         char *tmp, *tmp1 = bb_xstrdup(filename);
     808        char *tmp, *tmp1 = xstrdup(filename);
    812809        tmp = bb_get_last_path_component(tmp1);
    813810        if (strcmp(tmp, fullname) == 0) {
    814811            free(tmp1);
    815812            /* Stop searching if we find a match */
    816             m_filename = bb_xstrdup(filename);
    817             return (FALSE);
     813            m_filename = xstrdup(filename);
     814            return FALSE;
    818815        }
    819816        free(tmp1);
    820817    }
    821     return (TRUE);
     818    return TRUE;
    822819}
    823820
     
    852849static enum obj_reloc
    853850arch_apply_relocation(struct obj_file *f,
    854                       struct obj_section *targsec,
    855                       struct obj_section *symsec,
    856                       struct obj_symbol *sym,
    857                       ElfW(RelM) *rel, ElfW(Addr) v)
     851                struct obj_section *targsec,
     852                struct obj_section *symsec,
     853                struct obj_symbol *sym,
     854                ElfW(RelM) *rel, ElfW(Addr) v)
    858855{
    859856    struct arch_file *ifile = (struct arch_file *) f;
     
    861858    ElfW(Addr) *loc = (ElfW(Addr) *) (targsec->contents + rel->r_offset);
    862859    ElfW(Addr) dot = targsec->header.sh_addr + rel->r_offset;
    863 #if defined(CONFIG_USE_GOT_ENTRIES) || defined(CONFIG_USE_PLT_ENTRIES)
     860#if defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES)
    864861    struct arch_symbol *isym = (struct arch_symbol *) sym;
    865862#endif
    866863#if defined(__arm__) || defined(__i386__) || defined(__mc68000__) || defined(__sh__) || defined(__s390__)
    867 #if defined(CONFIG_USE_GOT_ENTRIES)
     864#if defined(USE_GOT_ENTRIES)
    868865    ElfW(Addr) got = ifile->got ? ifile->got->header.sh_addr : 0;
    869866#endif
    870867#endif
    871 #if defined(CONFIG_USE_PLT_ENTRIES)
     868#if defined(USE_PLT_ENTRIES)
    872869    ElfW(Addr) plt = ifile->plt ? ifile->plt->header.sh_addr : 0;
    873870    unsigned long *ip;
    874 # if defined(CONFIG_USE_PLT_LIST)
     871# if defined(USE_PLT_LIST)
    875872    struct arch_list_entry *pe;
    876873# else
     
    898895             * but is full 32 bits relative */
    899896
    900             assert(got != 0);
    901897            *loc += got - dot;
    902898            break;
     
    907903
    908904        case R_ARM_GOTOFF: /* address relative to the got */
    909             assert(got != 0);
    910905            *loc += v - got;
    911906            break;
     
    977972
    978973        case R_386_GOTPC:
    979             assert(got != 0);
    980974            *loc += got - dot;
    981975            break;
     
    985979
    986980        case R_386_GOTOFF:
    987             assert(got != 0);
    988981            *loc += v - got;
    989982            break;
    990983
    991 #elif defined (__microblaze__)
     984#elif defined(__microblaze__)
    992985        case R_MICROBLAZE_NONE:
    993986        case R_MICROBLAZE_64_NONE:
     
    1000993             * v is the target symbol address.
    1001994             * So we need to extract the offset in the code,
    1002              * adding v, then subtrating the current address 
     995             * adding v, then subtrating the current address
    1003996             * of this instruction.
    1004997             * Ex: "IMM 0xFFFE  bralid 0x0000" = "bralid 0xFFFE0000"
     
    10091002                        (loc[1] & 0xFFFF);
    10101003
    1011             /* Adjust relative offset. -4 adjustment required 
     1004            /* Adjust relative offset. -4 adjustment required
    10121005             * because dot points to the IMM insn, but branch
    10131006             * is computed relative to the branch instruction itself.
     
    11071100# ifdef R_68K_GOTOFF
    11081101        case R_68K_GOTOFF:
    1109             assert(got != 0);
    11101102            *loc += v - got;
    11111103            break;
     
    11381130                   of the carry we need to add.  Save the information, and let LO16
    11391131                   do the actual relocation.  */
    1140                 n = (struct mips_hi16 *) xmalloc(sizeof *n);
     1132                n = xmalloc(sizeof *n);
    11411133                n->addr = loc;
    11421134                n->value = v;
     
    11611153                        struct mips_hi16 *next;
    11621154                        unsigned long insn;
    1163 
    1164                         /* The value for the HI16 had best be the same. */
    1165                         assert(v == l->value);
    11661155
    11671156                        /* Do the HI16 relocation.  Note that we actually don't
     
    14131402        case R_390_PLT16DBL:
    14141403            /* find the plt entry and initialize it.  */
    1415             assert(isym != NULL);
    14161404            pe = (struct arch_single_entry *) &isym->pltent;
    1417             assert(pe->allocated);
    14181405            if (pe->inited == 0) {
    14191406                ip = (unsigned long *)(ifile->plt->contents + pe->offset);
     
    14451432
    14461433        case R_390_GOTPC:
    1447             assert(got != 0);
    14481434            *(unsigned long *) loc += got - dot;
    14491435            break;
     
    14521438        case R_390_GOT16:
    14531439        case R_390_GOT32:
    1454             assert(isym != NULL);
    1455             assert(got != 0);
    14561440            if (!isym->gotent.inited)
    14571441            {
     
    14711455# endif
    14721456        case R_390_GOTOFF32:
    1473             assert(got != 0);
    14741457            *loc += v - got;
    14751458            break;
     
    15021485
    15031486        case R_SH_GOTPC:
    1504             assert(got != 0);
    15051487            *loc = got - dot + rel->r_addend;
    15061488            break;
     
    15101492
    15111493        case R_SH_GOTOFF:
    1512             assert(got != 0);
    15131494            *loc = v - got;
    15141495            break;
     
    15591540# endif /* __SH5__ */
    15601541
    1561 #elif defined (__v850e__)
     1542#elif defined(__v850e__)
    15621543
    15631544        case R_V850_NONE:
     
    16321613            goto bb_use_got;
    16331614# if 0
    1634             assert(isym != NULL);
    16351615            if (!isym->gotent.reloc_done)
    16361616            {
     
    16551635            break;
    16561636
    1657 #if defined(CONFIG_USE_PLT_ENTRIES)
     1637#if defined(USE_PLT_ENTRIES)
    16581638
    16591639bb_use_plt:
    16601640
    16611641            /* find the plt entry and initialize it if necessary */
    1662             assert(isym != NULL);
    1663 
    1664 #if defined(CONFIG_USE_PLT_LIST)
     1642
     1643#if defined(USE_PLT_LIST)
    16651644            for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;)
    16661645                pe = pe->next;
    1667             assert(pe != NULL);
    16681646#else
    16691647            pe = &isym->pltent;
     
    16851663                ip[3] = 0x4e800420;               /* bctr */
    16861664#endif
    1687 #if defined (__v850e__)
     1665#if defined(__v850e__)
    16881666                /* We have to trash a register, so we assume that any control
    16891667                   transfer more than 21-bits away must be a function call
     
    16981676            v -= dot;
    16991677            /* if the target is too far away.... */
    1700 #if defined (__arm__) || defined (__powerpc__)
     1678#if defined(__arm__) || defined(__powerpc__)
    17011679            if ((int)v < -0x02000000 || (int)v >= 0x02000000)
    1702 #elif defined (__v850e__)
     1680#elif defined(__v850e__)
    17031681                if ((ElfW(Sword))v > 0x1fffff || (ElfW(Sword))v < (ElfW(Sword))-0x200000)
    17041682#endif
     
    17061684                    v = plt + pe->offset - dot;
    17071685
    1708 #if defined (__v850e__)
     1686#if defined(__v850e__)
    17091687            if (v & 1)
    17101688#else
     
    17231701            *loc = (*loc & ~0x03fffffc) | (v & 0x03fffffc);
    17241702#endif
    1725 #if defined (__v850e__)
     1703#if defined(__v850e__)
    17261704            /* We write two shorts instead of a long because even 32-bit insns
    17271705               only need half-word alignment, but the 32-bit data write needs
     
    17341712#endif
    17351713            break;
    1736 #endif /* CONFIG_USE_PLT_ENTRIES */
    1737 
    1738 #if defined(CONFIG_USE_GOT_ENTRIES)
     1714#endif /* USE_PLT_ENTRIES */
     1715
     1716#if defined(USE_GOT_ENTRIES)
    17391717bb_use_got:
    17401718
    1741             assert(isym != NULL);
    17421719            /* needs an entry in the .got: set it, once */
    17431720            if (!isym->gotent.inited) {
     
    17531730            break;
    17541731
    1755 #endif /* CONFIG_USE_GOT_ENTRIES */
     1732#endif /* USE_GOT_ENTRIES */
    17561733    }
    17571734
     
    17601737
    17611738
    1762 #if defined(CONFIG_USE_LIST)
     1739#if defined(USE_LIST)
    17631740
    17641741static int arch_list_add(ElfW(RelM) *rel, struct arch_list_entry **list,
     
    17871764#endif
    17881765
    1789 #if defined(CONFIG_USE_SINGLE)
     1766#if defined(USE_SINGLE)
    17901767
    17911768static int arch_single_init(ElfW(RelM) *rel, struct arch_single_entry *single,
     
    18031780#endif
    18041781
    1805 #if defined(CONFIG_USE_GOT_ENTRIES) || defined(CONFIG_USE_PLT_ENTRIES)
    1806 
    1807 static struct obj_section *arch_xsect_init(struct obj_file *f, char *name,
     1782#if defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES)
     1783
     1784static struct obj_section *arch_xsect_init(struct obj_file *f, const char *name,
    18081785                       int offset, int size)
    18091786{
     
    18191796        myrelsec = obj_create_alloced_section(f, name,
    18201797                size, offset);
    1821         assert(myrelsec);
    18221798    }
    18231799
     
    18291805static void arch_create_got(struct obj_file *f)
    18301806{
    1831 #if defined(CONFIG_USE_GOT_ENTRIES) || defined(CONFIG_USE_PLT_ENTRIES)
     1807#if defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES)
    18321808    struct arch_file *ifile = (struct arch_file *) f;
    18331809    int i;
    1834 #if defined(CONFIG_USE_GOT_ENTRIES)
     1810#if defined(USE_GOT_ENTRIES)
    18351811    int got_offset = 0, got_needed = 0, got_allocate;
    18361812#endif
    1837 #if defined(CONFIG_USE_PLT_ENTRIES)
     1813#if defined(USE_PLT_ENTRIES)
    18381814    int plt_offset = 0, plt_needed = 0, plt_allocate;
    18391815#endif
     
    18601836            extsym = &symtab[ELF_R_SYM(rel->r_info)];
    18611837
    1862 #if defined(CONFIG_USE_GOT_ENTRIES)
     1838#if defined(USE_GOT_ENTRIES)
    18631839            got_allocate = 0;
    18641840#endif
    1865 #if defined(CONFIG_USE_PLT_ENTRIES)
     1841#if defined(USE_PLT_ENTRIES)
    18661842            plt_allocate = 0;
    18671843#endif
     
    18691845            switch (ELF_R_TYPE(rel->r_info)) {
    18701846#if defined(__arm__)
    1871                 case R_ARM_PC24:
    1872                 case R_ARM_PLT32:
    1873                     plt_allocate = 1;
    1874                     break;
    1875 
    1876                 case R_ARM_GOTOFF:
    1877                 case R_ARM_GOTPC:
    1878                     got_needed = 1;
    1879                     continue;
    1880 
    1881                 case R_ARM_GOT32:
    1882                     got_allocate = 1;
    1883                     break;
     1847            case R_ARM_PC24:
     1848            case R_ARM_PLT32:
     1849                plt_allocate = 1;
     1850                break;
     1851
     1852            case R_ARM_GOTOFF:
     1853            case R_ARM_GOTPC:
     1854                got_needed = 1;
     1855                continue;
     1856
     1857            case R_ARM_GOT32:
     1858                got_allocate = 1;
     1859                break;
    18841860
    18851861#elif defined(__i386__)
    1886                 case R_386_GOTPC:
    1887                 case R_386_GOTOFF:
    1888                     got_needed = 1;
    1889                     continue;
    1890 
    1891                 case R_386_GOT32:
    1892                     got_allocate = 1;
    1893                     break;
     1862            case R_386_GOTPC:
     1863            case R_386_GOTOFF:
     1864                got_needed = 1;
     1865                continue;
     1866
     1867            case R_386_GOT32:
     1868                got_allocate = 1;
     1869                break;
    18941870
    18951871#elif defined(__powerpc__)
    1896                 case R_PPC_REL24:
    1897                     plt_allocate = 1;
    1898                     break;
     1872            case R_PPC_REL24:
     1873                plt_allocate = 1;
     1874                break;
    18991875
    19001876#elif defined(__mc68000__)
    1901                 case R_68K_GOT32:
    1902                     got_allocate = 1;
    1903                     break;
     1877            case R_68K_GOT32:
     1878                got_allocate = 1;
     1879                break;
    19041880
    19051881#ifdef R_68K_GOTOFF
    1906                 case R_68K_GOTOFF:
    1907                     got_needed = 1;
    1908                     continue;
     1882            case R_68K_GOTOFF:
     1883                got_needed = 1;
     1884                continue;
    19091885#endif
    19101886
    19111887#elif defined(__sh__)
    1912                 case R_SH_GOT32:
    1913                     got_allocate = 1;
    1914                     break;
    1915 
    1916                 case R_SH_GOTPC:
    1917                 case R_SH_GOTOFF:
    1918                     got_needed = 1;
    1919                     continue;
    1920 
    1921 #elif defined (__v850e__)
    1922                 case R_V850_22_PCREL:
    1923                     plt_needed = 1;
    1924                     break;
    1925 
    1926 #endif
    1927                 default:
    1928                     continue;
     1888            case R_SH_GOT32:
     1889                got_allocate = 1;
     1890                break;
     1891
     1892            case R_SH_GOTPC:
     1893            case R_SH_GOTOFF:
     1894                got_needed = 1;
     1895                continue;
     1896
     1897#elif defined(__v850e__)
     1898            case R_V850_22_PCREL:
     1899                plt_needed = 1;
     1900                break;
     1901
     1902#endif
     1903            default:
     1904                continue;
    19291905            }
    19301906
     
    19351911            }
    19361912            intsym = (struct arch_symbol *) obj_find_symbol(f, name);
    1937 #if defined(CONFIG_USE_GOT_ENTRIES)
     1913#if defined(USE_GOT_ENTRIES)
    19381914            if (got_allocate) {
    19391915                got_offset += arch_single_init(
    19401916                        rel, &intsym->gotent,
    1941                         got_offset, CONFIG_GOT_ENTRY_SIZE);
     1917                        got_offset, GOT_ENTRY_SIZE);
    19421918
    19431919                got_needed = 1;
    19441920            }
    19451921#endif
    1946 #if defined(CONFIG_USE_PLT_ENTRIES)
     1922#if defined(USE_PLT_ENTRIES)
    19471923            if (plt_allocate) {
    1948 #if defined(CONFIG_USE_PLT_LIST)
     1924#if defined(USE_PLT_LIST)
    19491925                plt_offset += arch_list_add(
    19501926                        rel, &intsym->pltent,
    1951                         plt_offset, CONFIG_PLT_ENTRY_SIZE);
     1927                        plt_offset, PLT_ENTRY_SIZE);
    19521928#else
    19531929                plt_offset += arch_single_init(
    19541930                        rel, &intsym->pltent,
    1955                         plt_offset, CONFIG_PLT_ENTRY_SIZE);
     1931                        plt_offset, PLT_ENTRY_SIZE);
    19561932#endif
    19571933                plt_needed = 1;
     
    19611937    }
    19621938
    1963 #if defined(CONFIG_USE_GOT_ENTRIES)
     1939#if defined(USE_GOT_ENTRIES)
    19641940    if (got_needed) {
    19651941        ifile->got = arch_xsect_init(f, ".got", got_offset,
    1966                 CONFIG_GOT_ENTRY_SIZE);
    1967     }
    1968 #endif
    1969 
    1970 #if defined(CONFIG_USE_PLT_ENTRIES)
     1942                GOT_ENTRY_SIZE);
     1943    }
     1944#endif
     1945
     1946#if defined(USE_PLT_ENTRIES)
    19711947    if (plt_needed) {
    19721948        ifile->plt = arch_xsect_init(f, ".plt", plt_offset,
    1973                 CONFIG_PLT_ENTRY_SIZE);
    1974     }
    1975 #endif
    1976 
    1977 #endif /* defined(CONFIG_USE_GOT_ENTRIES) || defined(CONFIG_USE_PLT_ENTRIES) */
     1949                PLT_ENTRY_SIZE);
     1950    }
     1951#endif
     1952
     1953#endif /* defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES) */
    19781954}
    19791955
     
    19811957
    19821958/* Standard ELF hash function.  */
    1983 static inline unsigned long obj_elf_hash_n(const char *name, unsigned long n)
     1959static unsigned long obj_elf_hash_n(const char *name, unsigned long n)
    19841960{
    19851961    unsigned long h = 0;
     
    20041980}
    20051981
    2006 #ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING
     1982#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
    20071983/* String comparison for non-co-versioned kernel and module.  */
    20081984
     
    20562032}
    20572033
    2058 #endif                          /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */
     2034#endif /* FEATURE_INSMOD_VERSION_CHECKING */
    20592035
    20602036static struct obj_symbol *
    20612037obj_add_symbol(struct obj_file *f, const char *name,
    2062                                   unsigned long symidx, int info,
    2063                                   int secidx, ElfW(Addr) value,
    2064                                   unsigned long size)
     2038                unsigned long symidx, int info,
     2039                int secidx, ElfW(Addr) value,
     2040                unsigned long size)
    20652041{
    20662042    struct obj_symbol *sym;
     
    21662142}
    21672143
    2168 static ElfW(Addr)
    2169     obj_symbol_final_value(struct obj_file * f, struct obj_symbol * sym)
     2144static ElfW(Addr) obj_symbol_final_value(struct obj_file * f, struct obj_symbol * sym)
    21702145{
    21712146    if (sym) {
     
    22262201
    22272202static struct obj_section *obj_create_alloced_section(struct obj_file *f,
    2228                                                const char *name,
    2229                                                unsigned long align,
    2230                                                unsigned long size)
     2203                const char *name,
     2204                unsigned long align,
     2205                unsigned long size)
    22312206{
    22322207    int newidx = f->header.e_shnum++;
     
    22522227
    22532228static struct obj_section *obj_create_alloced_section_first(struct obj_file *f,
    2254                                                      const char *name,
    2255                                                      unsigned long align,
    2256                                                      unsigned long size)
     2229                const char *name,
     2230                unsigned long align,
     2231                unsigned long size)
    22572232{
    22582233    int newidx = f->header.e_shnum++;
     
    23042279    size_t name_alloced_size = 0;
    23052280#endif
    2306 #ifdef CONFIG_FEATURE_CHECK_TAINTED_MODULE
     2281#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
    23072282    int gpl;
    23082283
     
    23242299         */
    23252300        if (strncmp((char *)s->name, "GPLONLY_", 8) == 0) {
    2326 #ifdef CONFIG_FEATURE_CHECK_TAINTED_MODULE
     2301#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
    23272302            if (gpl)
    23282303                s->name += 8;
     
    23382313           reference `linker names').  */
    23392314        size_t extra = sizeof SYMBOL_PREFIX;
    2340         size_t name_size = strlen (name) + extra;
     2315        size_t name_size = strlen(name) + extra;
    23412316        if (name_size > name_alloced_size) {
    23422317            name_alloced_size = name_size * 2;
    2343             name_buf = alloca (name_alloced_size);
     2318            name_buf = alloca(name_alloced_size);
    23442319        }
    2345         strcpy (name_buf, SYMBOL_PREFIX);
    2346         strcpy (name_buf + extra - 1, name);
     2320        strcpy(name_buf, SYMBOL_PREFIX);
     2321        strcpy(name_buf + extra - 1, name);
    23472322        name = name_buf;
    23482323#endif /* SYMBOL_PREFIX */
     
    23522327#ifdef SYMBOL_PREFIX
    23532328            /* Put NAME_BUF into more permanent storage.  */
    2354             name = xmalloc (name_size);
    2355             strcpy (name, name_buf);
     2329            name = xmalloc(name_size);
     2330            strcpy(name, name_buf);
    23562331#endif
    23572332            sym = obj_add_symbol(f, name, -1,
     
    23762351    /* Add module symbols first.  */
    23772352
    2378     for (i = 0, m = ext_modules; i < n_ext_modules; ++i, ++m)
     2353    for (i = 0, m = ext_modules; i < n_ext_modules; ++i, ++m) {
    23792354        if (m->nsyms
    2380                 && add_symbols_from(f, SHN_HIRESERVE + 2 + i, m->syms,
    2381                     m->nsyms)) m->used = 1, ++nused;
     2355         && add_symbols_from(f, SHN_HIRESERVE + 2 + i, m->syms, m->nsyms)
     2356        ) {
     2357            m->used = 1;
     2358            ++nused;
     2359        }
     2360    }
    23822361
    23832362    n_ext_modules_used = nused;
     
    24482427
    24492428#ifdef SYMBOL_PREFIX
    2450         sym_name = alloca (strlen (key) + sizeof SYMBOL_PREFIX);
    2451         strcpy (sym_name, SYMBOL_PREFIX);
    2452         strcat (sym_name, key);
     2429        sym_name = alloca(strlen(key) + sizeof SYMBOL_PREFIX);
     2430        strcpy(sym_name, SYMBOL_PREFIX);
     2431        strcat(sym_name, key);
    24532432#else
    24542433        sym_name = key;
     
    24912470                        } else if (*q == '\\')
    24922471                            switch (*++q) {
    2493                                 case 'a':
    2494                                     *r = '\a';
    2495                                     break;
    2496                                 case 'b':
    2497                                     *r = '\b';
    2498                                     break;
    2499                                 case 'e':
    2500                                     *r = '\033';
    2501                                     break;
    2502                                 case 'f':
    2503                                     *r = '\f';
    2504                                     break;
    2505                                 case 'n':
    2506                                     *r = '\n';
    2507                                     break;
    2508                                 case 'r':
    2509                                     *r = '\r';
    2510                                     break;
    2511                                 case 't':
    2512                                     *r = '\t';
    2513                                     break;
    2514 
    2515                                 case '0':
    2516                                 case '1':
    2517                                 case '2':
    2518                                 case '3':
    2519                                 case '4':
    2520                                 case '5':
    2521                                 case '6':
    2522                                 case '7':
    2523                                     {
    2524                                         int c = *q - '0';
    2525                                         if (q[1] >= '0' && q[1] <= '7') {
     2472                            case 'a':
     2473                                *r = '\a';
     2474                                break;
     2475                            case 'b':
     2476                                *r = '\b';
     2477                                break;
     2478                            case 'e':
     2479                                *r = '\033';
     2480                                break;
     2481                            case 'f':
     2482                                *r = '\f';
     2483                                break;
     2484                            case 'n':
     2485                                *r = '\n';
     2486                                break;
     2487                            case 'r':
     2488                                *r = '\r';
     2489                                break;
     2490                            case 't':
     2491                                *r = '\t';
     2492                                break;
     2493
     2494                            case '0':
     2495                            case '1':
     2496                            case '2':
     2497                            case '3':
     2498                            case '4':
     2499                            case '5':
     2500                            case '6':
     2501                            case '7':
     2502                                {
     2503                                    int c = *q - '0';
     2504                                    if (q[1] >= '0' && q[1] <= '7') {
     2505                                        c = (c * 8) + *++q - '0';
     2506                                        if (q[1] >= '0' && q[1] <= '7')
    25262507                                            c = (c * 8) + *++q - '0';
    2527                                             if (q[1] >= '0' && q[1] <= '7')
    2528                                                 c = (c * 8) + *++q - '0';
    2529                                         }
    2530                                         *r = c;
    25312508                                    }
    2532                                     break;
    2533 
    2534                                 default:
    2535                                     *r = *q;
    2536                                     break;
     2509                                    *r = c;
     2510                                }
     2511                                break;
     2512
     2513                            default:
     2514                                *r = *q;
     2515                                break;
    25372516                            } else
    25382517                                *r = *q;
     
    25652544                        /* last string */
    25662545                        str = q;
    2567                         q = "";
     2546                        q = (char*)"";
    25682547                    }
    25692548                }
     
    25742553                    loc += tgt_sizeof_char_p;
    25752554                } else {
    2576                     /* Array of chars (in fact, matrix !) */
     2555                    /* Array of chars (in fact, matrix!) */
    25772556                    unsigned long charssize;    /* size of each member */
    25782557
     
    26002579                long v = strtoul(q, &q, 0);
    26012580                switch (*p) {
    2602                     case 'b':
    2603                         *loc++ = v;
    2604                         break;
    2605                     case 'h':
    2606                         *(short *) loc = v;
    2607                         loc += tgt_sizeof_short;
    2608                         break;
    2609                     case 'i':
    2610                         *(int *) loc = v;
    2611                         loc += tgt_sizeof_int;
    2612                         break;
    2613                     case 'l':
    2614                         *(long *) loc = v;
    2615                         loc += tgt_sizeof_long;
    2616                         break;
    2617 
    2618                     default:
    2619                         bb_error_msg("unknown parameter type '%c' for %s", *p, key);
    2620                         return 0;
     2581                case 'b':
     2582                    *loc++ = v;
     2583                    break;
     2584                case 'h':
     2585                    *(short *) loc = v;
     2586                    loc += tgt_sizeof_short;
     2587                    break;
     2588                case 'i':
     2589                    *(int *) loc = v;
     2590                    loc += tgt_sizeof_int;
     2591                    break;
     2592                case 'l':
     2593                    *(long *) loc = v;
     2594                    loc += tgt_sizeof_long;
     2595                    break;
     2596
     2597                default:
     2598                    bb_error_msg("unknown parameter type '%c' for %s", *p, key);
     2599                    return 0;
    26212600                }
    26222601            }
     
    26242603retry_end_of_value:
    26252604            switch (*q) {
    2626                 case '\0':
    2627                     goto end_of_arg;
    2628 
    2629                 case ' ':
    2630                 case '\t':
    2631                 case '\n':
    2632                 case '\r':
    2633                     ++q;
    2634                     goto retry_end_of_value;
    2635 
    2636                 case ',':
    2637                     if (++n > max) {
    2638                         bb_error_msg("too many values for %s (max %d)", key, max);
    2639                         return 0;
    2640                     }
    2641                     ++q;
    2642                     break;
    2643 
    2644                 default:
    2645                     bb_error_msg("invalid argument syntax for %s", key);
     2605            case '\0':
     2606                goto end_of_arg;
     2607
     2608            case ' ':
     2609            case '\t':
     2610            case '\n':
     2611            case '\r':
     2612                ++q;
     2613                goto retry_end_of_value;
     2614
     2615            case ',':
     2616                if (++n > max) {
     2617                    bb_error_msg("too many values for %s (max %d)", key, max);
    26462618                    return 0;
     2619                }
     2620                ++q;
     2621                break;
     2622
     2623            default:
     2624                bb_error_msg("invalid argument syntax for %s", key);
     2625                return 0;
    26472626            }
    26482627        }
     
    26602639}
    26612640
    2662 #ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING
     2641#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
    26632642static int new_is_module_checksummed(struct obj_file *f)
    26642643{
    26652644    const char *p = get_modinfo_value(f, "using_checksums");
    26662645    if (p)
    2667         return atoi(p);
     2646        return xatoi(p);
    26682647    else
    26692648        return 0;
     
    26962675}
    26972676
    2698 #endif   /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */
     2677#endif   /* FEATURE_INSMOD_VERSION_CHECKING */
    26992678
    27002679
     
    27252704    /* Collect the modules' symbols.  */
    27262705
    2727     if (nmod){
     2706    if (nmod) {
    27282707        ext_modules = modules = xmalloc(nmod * sizeof(*modules));
    27292708        memset(modules, 0, nmod * sizeof(*modules));
     
    28262805}
    28272806
    2828 #ifdef CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
     2807#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
    28292808/* add an entry to the __ksymtab section, creating it if necessary */
    28302809static void new_add_ksymtab(struct obj_file *f, struct obj_symbol *sym)
     
    28492828        return;
    28502829    sec->header.sh_flags |= SHF_ALLOC;
    2851     sec->header.sh_addralign = tgt_sizeof_void_p;   /* Empty section might
    2852                                                        be byte-aligned */
     2830    /* Empty section might be byte-aligned */
     2831    sec->header.sh_addralign = tgt_sizeof_void_p;
    28532832    ofs = sec->header.sh_size;
    28542833    obj_symbol_patch(f, sec->idx, ofs, sym);
     
    28562835    obj_extend_section(sec, 2 * tgt_sizeof_char_p);
    28572836}
    2858 #endif /* CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
     2837#endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
    28592838
    28602839static int new_create_module_ksymtab(struct obj_file *f)
     
    28872866    }
    28882867
    2889     if (flag_export && !obj_find_section(f, "__ksymtab")) {
     2868    if (!flag_noexport && !obj_find_section(f, "__ksymtab")) {
    28902869        size_t nsyms;
    28912870        int *loaded;
    28922871
    2893         sec =
    2894             obj_create_alloced_section(f, "__ksymtab", tgt_sizeof_void_p,
    2895                     0);
     2872        sec = obj_create_alloced_section(f, "__ksymtab", tgt_sizeof_void_p, 0);
    28962873
    28972874        /* We don't want to export symbols residing in sections that
     
    32823259            /* Do it! */
    32833260            switch (arch_apply_relocation
    3284                     (f, targsec, symsec, intsym, rel, value)) {
    3285                 case obj_reloc_ok:
    3286                     break;
    3287 
    3288                 case obj_reloc_overflow:
    3289                     errmsg = "Relocation overflow";
    3290                     goto bad_reloc;
    3291                 case obj_reloc_dangerous:
    3292                     errmsg = "Dangerous relocation";
    3293                     goto bad_reloc;
    3294                 case obj_reloc_unhandled:
    3295                     errmsg = "Unhandled relocation";
     3261                    (f, targsec, symsec, intsym, rel, value)
     3262            ) {
     3263            case obj_reloc_ok:
     3264                break;
     3265
     3266            case obj_reloc_overflow:
     3267                errmsg = "Relocation overflow";
     3268                goto bad_reloc;
     3269            case obj_reloc_dangerous:
     3270                errmsg = "Dangerous relocation";
     3271                goto bad_reloc;
     3272            case obj_reloc_unhandled:
     3273                errmsg = "Unhandled relocation";
    32963274bad_reloc:
    3297                     if (extsym) {
    3298                         bb_error_msg("%s of type %ld for %s", errmsg,
    3299                                 (long) ELF_R_TYPE(rel->r_info),
    3300                                 strtab + extsym->st_name);
    3301                     } else {
    3302                         bb_error_msg("%s of type %ld", errmsg,
    3303                                 (long) ELF_R_TYPE(rel->r_info));
    3304                     }
    3305                     ret = 0;
    3306                     break;
     3275                if (extsym) {
     3276                    bb_error_msg("%s of type %ld for %s", errmsg,
     3277                            (long) ELF_R_TYPE(rel->r_info),
     3278                            strtab + extsym->st_name);
     3279                } else {
     3280                    bb_error_msg("%s of type %ld", errmsg,
     3281                            (long) ELF_R_TYPE(rel->r_info));
     3282                }
     3283                ret = 0;
     3284                break;
    33073285            }
    33083286        }
     
    34323410        sec->idx = i;
    34333411
    3434         if(sec->header.sh_size) switch (sec->header.sh_type) {
     3412        if (sec->header.sh_size) {
     3413            switch (sec->header.sh_type) {
    34353414            case SHT_NULL:
    34363415            case SHT_NOTE:
     
    34833462                        (long) sec->header.sh_type);
    34843463                return NULL;
     3464            }
    34853465        }
    34863466    }
     
    35083488
    35093489        switch (sec->header.sh_type) {
    3510             case SHT_SYMTAB:
    3511                 {
    3512                     unsigned long nsym, j;
    3513                     char *strtab;
    3514                     ElfW(Sym) * sym;
    3515 
    3516                     if (sec->header.sh_entsize != sizeof(ElfW(Sym))) {
    3517                         bb_error_msg("symbol size mismatch: %lu != %lu",
    3518                                 (unsigned long) sec->header.sh_entsize,
    3519                                 (unsigned long) sizeof(ElfW(Sym)));
    3520                         return NULL;
    3521                     }
    3522 
    3523                     nsym = sec->header.sh_size / sizeof(ElfW(Sym));
    3524                     strtab = f->sections[sec->header.sh_link]->contents;
    3525                     sym = (ElfW(Sym) *) sec->contents;
    3526 
    3527                     /* Allocate space for a table of local symbols.  */
    3528                     j = f->local_symtab_size = sec->header.sh_info;
    3529                     f->local_symtab = xcalloc(j, sizeof(struct obj_symbol *));
    3530 
    3531                     /* Insert all symbols into the hash table.  */
    3532                     for (j = 1, ++sym; j < nsym; ++j, ++sym) {
    3533                         ElfW(Addr) val = sym->st_value;
    3534                         const char *name;
    3535                         if (sym->st_name)
    3536                             name = strtab + sym->st_name;
    3537                         else if (sym->st_shndx < shnum)
    3538                             name = f->sections[sym->st_shndx]->name;
    3539                         else
    3540                             continue;
    3541 
    3542 #if defined(__SH5__)
    3543                         /*
    3544                          * For sh64 it is possible that the target of a branch
    3545                          * requires a mode switch (32 to 16 and back again).
    3546                          *
    3547                          * This is implied by the lsb being set in the target
    3548                          * address for SHmedia mode and clear for SHcompact.
    3549                          */
    3550                         val |= sym->st_other & 4;
    3551 #endif
    3552 
    3553                         obj_add_symbol(f, name, j, sym->st_info, sym->st_shndx,
    3554                                 val, sym->st_size);
    3555                     }
    3556                 }
    3557                 break;
    3558 
    3559             case SHT_RELM:
    3560                 if (sec->header.sh_entsize != sizeof(ElfW(RelM))) {
    3561                     bb_error_msg("relocation entry size mismatch: %lu != %lu",
     3490        case SHT_SYMTAB:
     3491            {
     3492                unsigned long nsym, j;
     3493                char *strtab;
     3494                ElfW(Sym) * sym;
     3495
     3496                if (sec->header.sh_entsize != sizeof(ElfW(Sym))) {
     3497                    bb_error_msg("symbol size mismatch: %lu != %lu",
    35623498                            (unsigned long) sec->header.sh_entsize,
    3563                             (unsigned long) sizeof(ElfW(RelM)));
     3499                            (unsigned long) sizeof(ElfW(Sym)));
    35643500                    return NULL;
    35653501                }
    3566                 break;
    3567                 /* XXX  Relocation code from modutils-2.3.19 is not here.
    3568                  * Why?  That's about 20 lines of code from obj/obj_load.c,
    3569                  * which gets done in a second pass through the sections.
    3570                  * This BusyBox insmod does similar work in obj_relocate(). */
     3502
     3503                nsym = sec->header.sh_size / sizeof(ElfW(Sym));
     3504                strtab = f->sections[sec->header.sh_link]->contents;
     3505                sym = (ElfW(Sym) *) sec->contents;
     3506
     3507                /* Allocate space for a table of local symbols.  */
     3508                j = f->local_symtab_size = sec->header.sh_info;
     3509                f->local_symtab = xzalloc(j * sizeof(struct obj_symbol *));
     3510
     3511                /* Insert all symbols into the hash table.  */
     3512                for (j = 1, ++sym; j < nsym; ++j, ++sym) {
     3513                    ElfW(Addr) val = sym->st_value;
     3514                    const char *name;
     3515                    if (sym->st_name)
     3516                        name = strtab + sym->st_name;
     3517                    else if (sym->st_shndx < shnum)
     3518                        name = f->sections[sym->st_shndx]->name;
     3519                    else
     3520                        continue;
     3521#if defined(__SH5__)
     3522                    /*
     3523                     * For sh64 it is possible that the target of a branch
     3524                     * requires a mode switch (32 to 16 and back again).
     3525                     *
     3526                     * This is implied by the lsb being set in the target
     3527                     * address for SHmedia mode and clear for SHcompact.
     3528                     */
     3529                    val |= sym->st_other & 4;
     3530#endif
     3531
     3532                    obj_add_symbol(f, name, j, sym->st_info, sym->st_shndx,
     3533                            val, sym->st_size);
     3534                }
     3535            }
     3536            break;
     3537
     3538        case SHT_RELM:
     3539            if (sec->header.sh_entsize != sizeof(ElfW(RelM))) {
     3540                bb_error_msg("relocation entry size mismatch: %lu != %lu",
     3541                        (unsigned long) sec->header.sh_entsize,
     3542                        (unsigned long) sizeof(ElfW(RelM)));
     3543                return NULL;
     3544            }
     3545            break;
     3546            /* XXX  Relocation code from modutils-2.3.19 is not here.
     3547             * Why?  That's about 20 lines of code from obj/obj_load.c,
     3548             * which gets done in a second pass through the sections.
     3549             * This BusyBox insmod does similar work in obj_relocate(). */
    35713550        }
    35723551    }
     
    35753554}
    35763555
    3577 #ifdef CONFIG_FEATURE_INSMOD_LOADINKMEM
     3556#if ENABLE_FEATURE_INSMOD_LOADINKMEM
    35783557/*
    35793558 * load the unloaded sections directly into the memory allocated by
     
    35983577        fseek(fp, sec->header.sh_offset, SEEK_SET);
    35993578        if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) {
    3600             bb_error_msg("error reading ELF section data: %s\n", strerror(errno));
     3579            bb_perror_msg("error reading ELF section data");
    36013580            return 0;
    36023581        }
     
    36193598    const char *const *p;
    36203599
    3621     for (p = specials; *p; ++p)
    3622         if ((sym = obj_find_symbol(f, *p)) != NULL)
    3623             sym->info =
    3624                 ELF_ST_INFO(STB_LOCAL, ELF_ST_TYPE(sym->info));
    3625 }
    3626 
    3627 
    3628 #ifdef CONFIG_FEATURE_CHECK_TAINTED_MODULE
     3600    for (p = specials; *p; ++p) {
     3601        sym = obj_find_symbol(f, *p);
     3602        if (sym != NULL)
     3603            sym->info = ELF_ST_INFO(STB_LOCAL, ELF_ST_TYPE(sym->info));
     3604    }
     3605}
     3606
     3607
     3608#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
    36293609static int obj_gpl_license(struct obj_file *f, const char **license)
    36303610{
     
    36343614     * work, somebody will use "GPL sucks, this is proprietary".
    36353615     */
    3636     static const char * const gpl_licenses[] = {
     3616    static const char *const gpl_licenses[] = {
    36373617        "GPL",
    36383618        "GPL v2",
    36393619        "GPL and additional rights",
    36403620        "Dual BSD/GPL",
    3641         "Dual MPL/GPL",
     3621        "Dual MPL/GPL"
    36423622    };
    36433623
    3644     if ((sec = obj_find_section(f, ".modinfo"))) {
     3624    sec = obj_find_section(f, ".modinfo");
     3625    if (sec) {
    36453626        const char *value, *ptr, *endptr;
    36463627        ptr = sec->contents;
    36473628        endptr = ptr + sec->header.sh_size;
    36483629        while (ptr < endptr) {
    3649             if ((value = strchr(ptr, '=')) && strncmp(ptr, "license", value-ptr) == 0) {
     3630            value = strchr(ptr, '=');
     3631            if (value && strncmp(ptr, "license", value-ptr) == 0) {
    36503632                int i;
    36513633                if (license)
    36523634                    *license = value+1;
    3653                 for (i = 0; i < sizeof(gpl_licenses)/sizeof(gpl_licenses[0]); ++i) {
     3635                for (i = 0; i < ARRAY_SIZE(gpl_licenses); ++i) {
    36543636                    if (strcmp(value+1, gpl_licenses[i]) == 0)
    3655                         return(0);
     3637                        return 0;
    36563638                }
    3657                 return(2);
     3639                return 2;
    36583640            }
    36593641            if (strchr(ptr, '\0'))
     
    36633645        }
    36643646    }
    3665     return(1);
     3647    return 1;
    36663648}
    36673649
     
    36753657        int kernel_has_tainted, int taint, const char *text1, const char *text2)
    36763658{
     3659    static smallint printed_info;
     3660
    36773661    char buf[80];
    36783662    int oldval;
    3679     static int first = 1;
     3663
    36803664    if (fd < 0 && !kernel_has_tainted)
    36813665        return;     /* New modutils on old kernel */
    36823666    printf("Warning: loading %s will taint the kernel: %s%s\n",
    36833667            m_name, text1, text2);
    3684     if (first) {
     3668    if (!printed_info) {
    36853669        printf("  See %s for information about tainted modules\n", TAINT_URL);
    3686         first = 0;
     3670        printed_info = 1;
    36873671    }
    36883672    if (fd >= 0) {
     
    36983682static void check_tainted_module(struct obj_file *f, char *m_name)
    36993683{
    3700     static const char tainted_file[] = TAINT_FILENAME;
     3684    static const char tainted_file[] ALIGN1 = TAINT_FILENAME;
     3685
    37013686    int fd, kernel_has_tainted;
    37023687    const char *ptr;
    37033688
    37043689    kernel_has_tainted = 1;
    3705     if ((fd = open(tainted_file, O_RDWR)) < 0) {
     3690    fd = open(tainted_file, O_RDWR);
     3691    if (fd < 0) {
    37063692        if (errno == ENOENT)
    37073693            kernel_has_tainted = 0;
     
    37383724        close(fd);
    37393725}
    3740 #else /* CONFIG_FEATURE_CHECK_TAINTED_MODULE */
    3741 #define check_tainted_module(x, y) do { } while(0);
    3742 #endif /* CONFIG_FEATURE_CHECK_TAINTED_MODULE */
    3743 
    3744 #ifdef CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
     3726#else /* FEATURE_CHECK_TAINTED_MODULE */
     3727#define check_tainted_module(x, y) do { } while (0);
     3728#endif /* FEATURE_CHECK_TAINTED_MODULE */
     3729
     3730#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
    37453731/* add module source, timestamp, kernel version and a symbol for the
    37463732 * start of some sections.  this info is used by ksymoops to do better
     
    37503736get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
    37513737{
    3752 #ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING
     3738#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
    37533739    return new_get_module_version(f, str);
    3754 #else  /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */
     3740#else  /* FEATURE_INSMOD_VERSION_CHECKING */
    37553741    strncpy(str, "???", sizeof(str));
    37563742    return -1;
    3757 #endif /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */
     3743#endif /* FEATURE_INSMOD_VERSION_CHECKING */
    37583744}
    37593745
     
    37663752                 const char *m_name)
    37673753{
    3768     static const char symprefix[] = "__insmod_";
     3754    static const char symprefix[] ALIGN1 = "__insmod_";
     3755
    37693756    struct obj_section *sec;
    37703757    struct obj_symbol *sym;
     
    37833770
    37843771    if (realpath(filename, real)) {
    3785         absolute_filename = bb_xstrdup(real);
    3786     }
    3787     else {
    3788         int save_errno = errno;
    3789         bb_error_msg("cannot get realpath for %s", filename);
    3790         errno = save_errno;
    3791         perror("");
    3792         absolute_filename = bb_xstrdup(filename);
     3772        absolute_filename = xstrdup(real);
     3773    } else {
     3774        bb_perror_msg("cannot get realpath for %s", filename);
     3775        absolute_filename = xstrdup(filename);
    37933776    }
    37943777
     
    38003783     * "export all symbols" compatibility code will export these symbols later.
    38013784     */
    3802     use_ksymtab =  obj_find_section(f, "__ksymtab") || !flag_export;
    3803 
    3804     if ((sec = obj_find_section(f, ".this"))) {
     3785    use_ksymtab = obj_find_section(f, "__ksymtab") || flag_noexport;
     3786
     3787    sec = obj_find_section(f, ".this");
     3788    if (sec) {
    38053789        /* tag the module header with the object name, last modified
    38063790         * timestamp and module version.  worst case for module version
     
    38523836    /* tag the desired sections if size is non-zero */
    38533837
    3854     for (i = 0; i < sizeof(section_names)/sizeof(section_names[0]); ++i) {
    3855         if ((sec = obj_find_section(f, section_names[i])) &&
    3856                 sec->header.sh_size) {
     3838    for (i = 0; i < ARRAY_SIZE(section_names); ++i) {
     3839        sec = obj_find_section(f, section_names[i]);
     3840        if (sec && sec->header.sh_size) {
    38573841            l = sizeof(symprefix)+      /* "__insmod_" */
    38583842                lm_name+        /* module name */
     
    38733857    }
    38743858}
    3875 #endif /* CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
    3876 
    3877 #ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
     3859#endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
     3860
     3861#if ENABLE_FEATURE_INSMOD_LOAD_MAP
    38783862static void print_load_map(struct obj_file *f)
    38793863{
     3864    struct obj_section *sec;
     3865#if ENABLE_FEATURE_INSMOD_LOAD_MAP_FULL
     3866    struct obj_symbol **all, **p;
     3867    int i, nsyms, *loaded;
    38803868    struct obj_symbol *sym;
    3881     struct obj_symbol **all, **p;
    3882     struct obj_section *sec;
    3883     int i, nsyms, *loaded;
    3884 
     3869#endif
    38853870    /* Report on the section layout.  */
    38863871
     
    39043889                a);
    39053890    }
    3906 #ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL
     3891#if ENABLE_FEATURE_INSMOD_LOAD_MAP_FULL
    39073892    /* Quick reference which section indicies are loaded.  */
    39083893
     
    39643949#endif
    39653950}
    3966 
    3967 #endif
    3968 
     3951#else /* !FEATURE_INSMOD_LOAD_MAP */
     3952void print_load_map(struct obj_file *f);
     3953#endif
     3954
     3955int insmod_main( int argc, char **argv);
    39693956int insmod_main( int argc, char **argv)
    39703957{
    3971     int opt;
     3958    char *opt_o, *arg1;
    39723959    int len;
    39733960    int k_crcs;
     
    39803967    int exit_status = EXIT_FAILURE;
    39813968    int m_has_modinfo;
    3982 #ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING
     3969#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
    39833970    struct utsname uts_info;
    39843971    char m_strversion[STRVERSIONLEN];
    39853972    int m_version, m_crcs;
    39863973#endif
    3987 #ifdef CONFIG_FEATURE_CLEAN_UP
     3974#if ENABLE_FEATURE_CLEAN_UP
    39883975    FILE *fp = 0;
    39893976#else
    39903977    FILE *fp;
    39913978#endif
    3992 #ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
    3993     int flag_print_load_map = 0;
    3994 #endif
    39953979    int k_version = 0;
    39963980    struct utsname myuname;
    39973981
    39983982    /* Parse any options */
    3999 #ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
    4000     while ((opt = getopt(argc, argv, "fkqsvxmLo:")) > 0)
    4001 #else
    4002     while ((opt = getopt(argc, argv, "fkqsvxLo:")) > 0)
    4003 #endif
    4004         {
    4005             switch (opt) {
    4006                 case 'f':           /* force loading */
    4007                     flag_force_load = 1;
    4008                     break;
    4009                 case 'k':           /* module loaded by kerneld, auto-cleanable */
    4010                     flag_autoclean = 1;
    4011                     break;
    4012                 case 's':           /* log to syslog */
    4013                     /* log to syslog -- not supported              */
    4014                     /* but kernel needs this for request_module(), */
    4015                     /* as this calls: modprobe -k -s -- <module>   */
    4016                     /* so silently ignore this flag                */
    4017                     break;
    4018                 case 'v':           /* verbose output */
    4019                     flag_verbose = 1;
    4020                     break;
    4021                 case 'q':           /* silent */
    4022                     flag_quiet = 1;
    4023                     break;
    4024                 case 'x':           /* do not export externs */
    4025                     flag_export = 0;
    4026                     break;
    4027                 case 'o':           /* name the output module */
    4028                     free(m_name);
    4029                     m_name = bb_xstrdup(optarg);
    4030                     break;
    4031                 case 'L':           /* Stub warning */
    4032                     /* This is needed for compatibility with modprobe.
    4033                      * In theory, this does locking, but we don't do
    4034                      * that.  So be careful and plan your life around not
    4035                      * loading the same module 50 times concurrently. */
    4036                     break;
    4037 #ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
    4038                 case 'm':           /* print module load map */
    4039                     flag_print_load_map = 1;
    4040                     break;
    4041 #endif
    4042                 default:
    4043                     bb_show_usage();
    4044             }
    4045         }
    4046 
    4047     if (argv[optind] == NULL) {
     3983    getopt32(argv, OPTION_STR, &opt_o);
     3984    arg1 = argv[optind];
     3985    if (option_mask32 & OPT_o) { // -o /* name the output module */
     3986        free(m_name);
     3987        m_name = xstrdup(opt_o);
     3988    }
     3989
     3990    if (arg1 == NULL) {
    40483991        bb_show_usage();
    40493992    }
    40503993
    40513994    /* Grab the module name */
    4052     tmp1 = bb_xstrdup(argv[optind]);
     3995    tmp1 = xstrdup(arg1);
    40533996    tmp = basename(tmp1);
    40543997    len = strlen(tmp);
     
    40604003    }
    40614004
    4062 #if defined(CONFIG_FEATURE_2_6_MODULES)
    4063     if (k_version > 4 && len > 3 && tmp[len - 3] == '.' &&
    4064             tmp[len - 2] == 'k' && tmp[len - 1] == 'o') {
    4065         len-=3;
     4005#if ENABLE_FEATURE_2_6_MODULES
     4006    if (k_version > 4 && len > 3 && tmp[len - 3] == '.'
     4007     && tmp[len - 2] == 'k' && tmp[len - 1] == 'o'
     4008    ) {
     4009        len -= 3;
    40664010        tmp[len] = '\0';
    4067     }
    4068     else
     4011    } else
    40694012#endif
    40704013        if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') {
    4071             len-=2;
     4014            len -= 2;
    40724015            tmp[len] = '\0';
    40734016        }
    40744017
    40754018
    4076 #if defined(CONFIG_FEATURE_2_6_MODULES)
     4019#if ENABLE_FEATURE_2_6_MODULES
    40774020    if (k_version > 4)
    4078         m_fullName = bb_xasprintf("%s.ko", tmp);
     4021        m_fullName = xasprintf("%s.ko", tmp);
    40794022    else
    40804023#endif
    4081         m_fullName = bb_xasprintf("%s.o", tmp);
     4024        m_fullName = xasprintf("%s.o", tmp);
    40824025
    40834026    if (!m_name) {
     
    40894032
    40904033    /* Get a filedesc for the module.  Check we we have a complete path */
    4091     if (stat(argv[optind], &st) < 0 || !S_ISREG(st.st_mode) ||
    4092             (fp = fopen(argv[optind], "r")) == NULL) {
     4034    if (stat(arg1, &st) < 0 || !S_ISREG(st.st_mode)
     4035     || (fp = fopen(arg1, "r")) == NULL
     4036    ) {
    40934037        /* Hmm.  Could not open it.  First search under /lib/modules/`uname -r`,
    40944038         * but do not error out yet if we fail to find it... */
     
    41044048             * /lib/modules/`uname -r` dir, So resolve it ourselves
    41054049             * if it is a link... */
    4106             if (realpath (tmdn, real_module_dir) == NULL)
     4050            if (realpath(tmdn, real_module_dir) == NULL)
    41074051                module_dir = tmdn;
    41084052            else
    41094053                module_dir = real_module_dir;
    4110             recursive_action(module_dir, TRUE, FALSE, FALSE,
    4111                     check_module_name_match, 0, m_fullName);
     4054            recursive_action(module_dir, ACTION_RECURSE,
     4055                    check_module_name_match, 0, m_fullName, 0);
    41124056            free(tmdn);
    41134057        }
    41144058
    41154059        /* Check if we have found anything yet */
    4116         if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL))
    4117         {
     4060        if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL)) {
    41184061            char module_dir[FILENAME_MAX];
    41194062
     
    41244067            /* No module found under /lib/modules/`uname -r`, this
    41254068             * time cast the net a bit wider.  Search /lib/modules/ */
    4126             if (! recursive_action(module_dir, TRUE, FALSE, FALSE,
    4127                         check_module_name_match, 0, m_fullName))
    4128             {
     4069            if (!recursive_action(module_dir, ACTION_RECURSE,
     4070                            check_module_name_match, 0, m_fullName, 0)
     4071            ) {
    41294072                if (m_filename == 0
    4130                         || ((fp = fopen(m_filename, "r")) == NULL))
    4131                 {
     4073                 || ((fp = fopen(m_filename, "r")) == NULL)
     4074                ) {
    41324075                    bb_error_msg("%s: no module by that name found", m_fullName);
    41334076                    goto out;
     
    41374080        }
    41384081    } else
    4139         m_filename = bb_xstrdup(argv[optind]);
     4082        m_filename = xstrdup(arg1);
    41404083
    41414084    if (flag_verbose)
    41424085        printf("Using %s\n", m_filename);
    41434086
    4144 #ifdef CONFIG_FEATURE_2_6_MODULES
    4145     if (k_version > 4)
    4146     {
     4087#if ENABLE_FEATURE_2_6_MODULES
     4088    if (k_version > 4) {
     4089        argv[optind] = m_filename;
    41474090        optind--;
    4148         argv[optind + 1] = m_filename;
    41494091        return insmod_ng_main(argc - optind, argv + optind);
    41504092    }
    41514093#endif
    41524094
    4153     if ((f = obj_load(fp, LOADBITS)) == NULL)
    4154         bb_perror_msg_and_die("Could not load the module");
     4095    f = obj_load(fp, LOADBITS);
     4096    if (f == NULL)
     4097        bb_perror_msg_and_die("cannot load the module");
    41554098
    41564099    if (get_modinfo_value(f, "kernel_version") == NULL)
     
    41594102        m_has_modinfo = 1;
    41604103
    4161 #ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING
     4104#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
    41624105    /* Version correspondence?  */
    41634106    if (!flag_quiet) {
     
    41674110            m_version = new_get_module_version(f, m_strversion);
    41684111            if (m_version == -1) {
    4169                 bb_error_msg("couldn't find the kernel version the module was "
     4112                bb_error_msg("cannot find the kernel version the module was "
    41704113                        "compiled for");
    41714114                goto out;
     
    41744117
    41754118        if (strncmp(uts_info.release, m_strversion, STRVERSIONLEN) != 0) {
    4176             if (flag_force_load) {
    4177                 bb_error_msg("Warning: kernel-module version mismatch\n"
    4178                         "\t%s was compiled for kernel version %s\n"
    4179                         "\twhile this kernel is version %s",
    4180                         m_filename, m_strversion, uts_info.release);
    4181             } else {
    4182                 bb_error_msg("kernel-module version mismatch\n"
    4183                         "\t%s was compiled for kernel version %s\n"
    4184                         "\twhile this kernel is version %s.",
    4185                         m_filename, m_strversion, uts_info.release);
     4119            bb_error_msg("%skernel-module version mismatch\n"
     4120                "\t%s was compiled for kernel version %s\n"
     4121                "\twhile this kernel is version %s",
     4122                flag_force_load ? "warning: " : "",
     4123                m_filename, m_strversion, uts_info.release);
     4124            if (!flag_force_load)
    41864125                goto out;
    4187             }
    41884126        }
    41894127    }
    41904128    k_crcs = 0;
    4191 #endif                          /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */
     4129#endif /* FEATURE_INSMOD_VERSION_CHECKING */
    41924130
    41934131    if (!query_module(NULL, 0, NULL, 0, NULL)) {
     
    41964134        k_crcs = new_is_kernel_checksummed();
    41974135    } else {
    4198         bb_error_msg("Not configured to support old kernels");
     4136        bb_error_msg("not configured to support old kernels");
    41994137        goto out;
    42004138    }
    42014139
    4202 #ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING
     4140#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
    42034141    m_crcs = 0;
    42044142    if (m_has_modinfo)
     
    42074145    if (m_crcs != k_crcs)
    42084146        obj_set_symbol_compare(f, ncv_strcmp, ncv_symbol_hash);
    4209 #endif                          /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */
     4147#endif /* FEATURE_INSMOD_VERSION_CHECKING */
    42104148
    42114149    /* Let the module know about the kernel symbols.  */
     
    42144152    /* Allocate common symbols, symbol tables, and string tables.  */
    42154153
    4216     if (!new_create_this_module(f, m_name))
    4217     {
     4154    if (!new_create_this_module(f, m_name)) {
    42184155        goto out;
    42194156    }
     
    42274164    /* done with the module name, on to the optional var=value arguments */
    42284165    ++optind;
    4229 
    42304166    if (optind < argc) {
    4231         if (!new_process_module_arguments(f, argc - optind, argv + optind))
    4232         {
     4167        if (!new_process_module_arguments(f, argc - optind, argv + optind)) {
    42334168            goto out;
    42344169        }
     
    42384173    hide_special_symbols(f);
    42394174
    4240 #ifdef CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
     4175#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
    42414176    add_ksymoops_symbols(f, m_filename, m_name);
    4242 #endif /* CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
     4177#endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
    42434178
    42444179    new_create_module_ksymtab(f);
     
    42514186    if (m_addr == -1) switch (errno) {
    42524187        case EEXIST:
    4253             bb_error_msg("A module named %s already exists", m_name);
     4188            bb_error_msg("a module named %s already exists", m_name);
    42544189            goto out;
    42554190        case ENOMEM:
    4256             bb_error_msg("Can't allocate kernel memory for module; needed %lu bytes",
     4191            bb_error_msg("can't allocate kernel memory for module; needed %lu bytes",
    42574192                    m_size);
    42584193            goto out;
     
    42784213    }
    42794214
    4280     if (!new_init_module(m_name, f, m_size))
    4281     {
     4215    if (!new_init_module(m_name, f, m_size)) {
    42824216        delete_module(m_name);
    42834217        goto out;
    42844218    }
    42854219
    4286 #ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
    4287     if(flag_print_load_map)
     4220    if (flag_print_load_map)
    42884221        print_load_map(f);
    4289 #endif
    42904222
    42914223    exit_status = EXIT_SUCCESS;
    42924224
    42934225out:
    4294 #ifdef CONFIG_FEATURE_CLEAN_UP
    4295     if(fp)
     4226#if ENABLE_FEATURE_CLEAN_UP
     4227    if (fp)
    42964228        fclose(fp);
    42974229    free(tmp1);
    4298     if(!tmp1) {
     4230    if (!tmp1)
    42994231        free(m_name);
    4300     }
    43014232    free(m_filename);
    43024233#endif
    4303     return(exit_status);
    4304 }
    4305 
    4306 
    4307 #endif
    4308 
    4309 
    4310 #ifdef CONFIG_FEATURE_2_6_MODULES
     4234    return exit_status;
     4235}
     4236
     4237
     4238#endif
     4239
     4240
     4241#if ENABLE_FEATURE_2_6_MODULES
    43114242
    43124243#include <sys/mman.h>
     
    43184249{
    43194250    switch (err) {
    4320         case ENOEXEC:
    4321             return "Invalid module format";
    4322         case ENOENT:
    4323             return "Unknown symbol in module";
    4324         case ESRCH:
    4325             return "Module has wrong symbol version";
    4326         case EINVAL:
    4327             return "Invalid parameters";
    4328         default:
    4329             return strerror(err);
    4330     }
    4331 }
    4332 
    4333 int insmod_ng_main( int argc, char **argv)
    4334 {
    4335     int i;
     4251    case ENOEXEC:
     4252        return "Invalid module format";
     4253    case ENOENT:
     4254        return "Unknown symbol in module";
     4255    case ESRCH:
     4256        return "Module has wrong symbol version";
     4257    case EINVAL:
     4258        return "Invalid parameters";
     4259    default:
     4260        return strerror(err);
     4261    }
     4262}
     4263
     4264int insmod_ng_main(int argc, char **argv);
     4265int insmod_ng_main(int argc, char **argv)
     4266{
     4267    long ret;
     4268    size_t len;
     4269    int optlen;
     4270    void *map;
     4271    char *filename, *options;
     4272
     4273    filename = *++argv;
     4274    if (!filename)
     4275        bb_show_usage();
     4276
     4277    /* Rest is options */
     4278    options = xzalloc(1);
     4279    optlen = 0;
     4280    while (*++argv) {
     4281        options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
     4282        /* Spaces handled by "" pairs, but no way of escaping quotes */
     4283        optlen += sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv);
     4284    }
     4285
     4286#if 0
     4287    /* Any special reason why mmap? It isn't performace critical... */
    43364288    int fd;
    4337     long int ret;
    43384289    struct stat st;
    43394290    unsigned long len;
    4340     void *map;
    4341     char *filename, *options = bb_xstrdup("");
    4342 
    4343     filename = argv[1];
    4344     if (!filename) {
    4345         bb_show_usage();
    4346         return -1;
    4347     }
    4348 
    4349     /* Rest is options */
    4350     for (i = 2; i < argc; i++) {
    4351         options = xrealloc(options, strlen(options) + 2 + strlen(argv[i]) + 2);
    4352         /* Spaces handled by "" pairs, but no way of escaping quotes */
    4353         if (strchr(argv[i], ' ')) {
    4354             strcat(options, "\"");
    4355             strcat(options, argv[i]);
    4356             strcat(options, "\"");
    4357         } else {
    4358             strcat(options, argv[i]);
    4359         }
    4360         strcat(options, " ");
    4361     }
    4362 
    4363     fd = bb_xopen3(filename, O_RDONLY, 0);
    4364 
     4291    fd = xopen(filename, O_RDONLY);
    43654292    fstat(fd, &st);
    43664293    len = st.st_size;
    43674294    map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
    43684295    if (map == MAP_FAILED) {
    4369         bb_perror_msg_and_die("cannot mmap `%s'", filename);
    4370     }
     4296        bb_perror_msg_and_die("cannot mmap '%s'", filename);
     4297    }
     4298
     4299    /* map == NULL on Blackfin, probably on other MMU-less systems too. Workaround. */
     4300    if (map == NULL) {
     4301        map = xmalloc(len);
     4302        xread(fd, map, len);
     4303    }
     4304#else
     4305    len = MAXINT(ssize_t);
     4306    map = xmalloc_open_read_close(filename, &len);
     4307#endif
    43714308
    43724309    ret = syscall(__NR_init_module, map, len, options);
    43734310    if (ret != 0) {
    4374         bb_perror_msg_and_die("cannot insert `%s': %s (%li)",
     4311        bb_perror_msg_and_die("cannot insert '%s': %s (%li)",
    43754312                filename, moderror(errno), ret);
    43764313    }
Note: See TracChangeset for help on using the changeset viewer.