2000-02-08 19:58:47 +00:00
|
|
|
|
/* vi: set sw=4 ts=4: */
|
1999-12-17 18:57:34 +00:00
|
|
|
|
/*
|
|
|
|
|
* Mini insmod implementation for busybox
|
2001-07-25 16:58:58 +00:00
|
|
|
|
*
|
2004-09-02 23:03:25 +00:00
|
|
|
|
* This version of insmod supports ARM, CRIS, H8/300, x86, ia64, x86_64,
|
|
|
|
|
* m68k, MIPS, PowerPC, S390, SH3/4/5, Sparc, v850e, and x86_64.
|
2001-07-25 16:58:58 +00:00
|
|
|
|
*
|
2004-03-15 08:29:22 +00:00
|
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2000-06-12 23:11:16 +00:00
|
|
|
|
* and Ron Alder <alder@lineo.com>
|
|
|
|
|
*
|
2004-08-19 19:17:30 +00:00
|
|
|
|
* Rodney Radford <rradford@mindspring.com> 17-Aug-2004.
|
|
|
|
|
* Added x86_64 support.
|
|
|
|
|
*
|
2002-04-01 14:25:51 +00:00
|
|
|
|
* Miles Bader <miles@gnu.org> added NEC V850E support.
|
2002-04-01 09:34:25 +00:00
|
|
|
|
*
|
2000-09-24 03:44:29 +00:00
|
|
|
|
* Modified by Bryan Rittmeyer <bryan@ixiacom.com> to support SH4
|
2000-12-06 18:18:26 +00:00
|
|
|
|
* and (theoretically) SH3. I have only tested SH4 in little endian mode.
|
|
|
|
|
*
|
|
|
|
|
* Modified by Alcove, Julien Gaulmin <julien.gaulmin@alcove.fr> and
|
|
|
|
|
* Nicolas Ferre <nicolas.ferre@alcove.fr> to support ARM7TDMI. Only
|
|
|
|
|
* very minor changes required to also work with StrongArm and presumably
|
|
|
|
|
* all ARM based systems.
|
2000-09-24 03:44:29 +00:00
|
|
|
|
*
|
2004-05-26 11:38:46 +00:00
|
|
|
|
* Yoshinori Sato <ysato@users.sourceforge.jp> 19-May-2004.
|
|
|
|
|
* added Renesas H8/300 support.
|
|
|
|
|
*
|
2003-08-13 19:56:33 +00:00
|
|
|
|
* Paul Mundt <lethal@linux-sh.org> 08-Aug-2003.
|
|
|
|
|
* Integrated support for sh64 (SH-5), from preliminary modutils
|
|
|
|
|
* patches from Benedict Gaster <benedict.gaster@superh.com>.
|
|
|
|
|
* Currently limited to support for 32bit ABI.
|
|
|
|
|
*
|
2002-05-24 06:50:15 +00:00
|
|
|
|
* Magnus Damm <damm@opensource.se> 22-May-2002.
|
|
|
|
|
* The plt and got code are now using the same structs.
|
|
|
|
|
* Added generic linked list code to fully support PowerPC.
|
|
|
|
|
* Replaced the mess in arch_apply_relocation() with architecture blocks.
|
|
|
|
|
* The arch_create_got() function got cleaned up with architecture blocks.
|
|
|
|
|
* These blocks should be easy maintain and sync with obj_xxx.c in modutils.
|
|
|
|
|
*
|
2001-02-20 20:47:08 +00:00
|
|
|
|
* Magnus Damm <damm@opensource.se> added PowerPC support 20-Feb-2001.
|
2004-03-15 08:29:22 +00:00
|
|
|
|
* PowerPC specific code stolen from modutils-2.3.16,
|
2001-02-20 20:47:08 +00:00
|
|
|
|
* written by Paul Mackerras, Copyright 1996, 1997 Linux International.
|
|
|
|
|
* I've only tested the code on mpc8xx platforms in big-endian mode.
|
2006-11-21 14:12:53 +00:00
|
|
|
|
* Did some cleanup and added USE_xxx_ENTRIES...
|
2001-02-20 20:47:08 +00:00
|
|
|
|
*
|
2001-02-24 20:01:53 +00:00
|
|
|
|
* Quinn Jensen <jensenq@lineo.com> added MIPS support 23-Feb-2001.
|
|
|
|
|
* based on modutils-2.4.2
|
|
|
|
|
* MIPS specific support for Elf loading and relocation.
|
|
|
|
|
* Copyright 1996, 1997 Linux International.
|
|
|
|
|
* Contributed by Ralf Baechle <ralf@gnu.ai.mit.edu>
|
|
|
|
|
*
|
2000-06-12 23:11:16 +00:00
|
|
|
|
* Based almost entirely on the Linux modutils-2.3.11 implementation.
|
|
|
|
|
* Copyright 1996, 1997 Linux International.
|
|
|
|
|
* New implementation contributed by Richard Henderson <rth@tamu.edu>
|
|
|
|
|
* Based on original work by Bjorn Ekwall <bj0rn@blox.se>
|
|
|
|
|
* Restructured (and partly rewritten) by:
|
|
|
|
|
* Bj<EFBFBD>rn Ekwall <bj0rn@blox.se> February 1999
|
1999-12-17 18:57:34 +00:00
|
|
|
|
*
|
2006-04-13 12:45:04 +00:00
|
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
1999-12-17 18:57:34 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
|
#include "libbb.h"
|
2006-08-09 20:56:23 +00:00
|
|
|
|
#include <libgen.h>
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if !ENABLE_FEATURE_2_4_MODULES && !ENABLE_FEATURE_2_6_MODULES
|
2006-12-30 17:57:03 +00:00
|
|
|
|
#undef ENABLE_FEATURE_2_4_MODULES
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define ENABLE_FEATURE_2_4_MODULES 1
|
2003-12-11 01:42:13 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
/*
|
|
|
|
|
* Big piece of 2.4-specific code
|
|
|
|
|
*/
|
|
|
|
|
#if ENABLE_FEATURE_2_4_MODULES
|
2003-12-11 01:42:13 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_2_6_MODULES
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static int insmod_ng_main(int argc, char **argv);
|
2003-12-11 01:42:13 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_LOADINKMEM
|
2004-03-15 08:29:22 +00:00
|
|
|
|
#define LOADBITS 0
|
2001-05-21 16:09:18 +00:00
|
|
|
|
#else
|
|
|
|
|
#define LOADBITS 1
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-12-26 09:13:32 +00:00
|
|
|
|
/* Alpha */
|
2005-10-02 07:14:06 +00:00
|
|
|
|
#if defined(__alpha__)
|
2004-12-26 09:13:32 +00:00
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_ALPHA)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf64_RelM Elf64_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS64
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* ARM support */
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#if defined(__arm__)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_ARM)
|
|
|
|
|
#define SHT_RELM SHT_REL
|
|
|
|
|
#define Elf32_RelM Elf32_Rel
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_PLT_ENTRIES
|
|
|
|
|
#define PLT_ENTRY_SIZE 8
|
|
|
|
|
#define USE_GOT_ENTRIES
|
|
|
|
|
#define GOT_ENTRY_SIZE 8
|
|
|
|
|
#define USE_SINGLE
|
2004-09-02 23:03:25 +00:00
|
|
|
|
#endif
|
2003-01-23 06:02:39 +00:00
|
|
|
|
|
2006-06-06 06:15:52 +00:00
|
|
|
|
/* blackfin */
|
|
|
|
|
#if defined(BFIN)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_BLACKFIN)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* CRIS */
|
|
|
|
|
#if defined(__cris__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_CRIS)
|
2003-01-23 06:02:39 +00:00
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2004-09-02 23:03:25 +00:00
|
|
|
|
#ifndef EM_CRIS
|
|
|
|
|
#define EM_CRIS 76
|
|
|
|
|
#define R_CRIS_NONE 0
|
|
|
|
|
#define R_CRIS_32 3
|
|
|
|
|
#endif
|
2003-01-23 06:02:39 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
/* H8/300 */
|
|
|
|
|
#if defined(__H8300H__) || defined(__H8300S__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_H8_300)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_SINGLE
|
2005-10-02 07:50:49 +00:00
|
|
|
|
#define SYMBOL_PREFIX "_"
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-12-26 09:13:32 +00:00
|
|
|
|
/* PA-RISC / HP-PA */
|
|
|
|
|
#if defined(__hppa__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_PARISC)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#if defined(__LP64__)
|
|
|
|
|
#define Elf64_RelM Elf64_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS64
|
|
|
|
|
#else
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* x86 */
|
|
|
|
|
#if defined(__i386__)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#ifndef EM_486
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_386)
|
|
|
|
|
#else
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_386 || x == EM_486)
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#define SHT_RELM SHT_REL
|
|
|
|
|
#define Elf32_RelM Elf32_Rel
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_GOT_ENTRIES
|
|
|
|
|
#define GOT_ENTRY_SIZE 4
|
|
|
|
|
#define USE_SINGLE
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* IA64, aka Itanium */
|
|
|
|
|
#if defined(__ia64__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_IA_64)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf64_RelM Elf64_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS64
|
2004-08-19 19:17:30 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* m68k */
|
2004-03-15 08:29:22 +00:00
|
|
|
|
#if defined(__mc68000__)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_68K)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
2004-03-19 12:17:04 +00:00
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_GOT_ENTRIES
|
|
|
|
|
#define GOT_ENTRY_SIZE 4
|
|
|
|
|
#define USE_SINGLE
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-06-06 06:15:52 +00:00
|
|
|
|
/* Microblaze */
|
|
|
|
|
#if defined(__microblaze__)
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_SINGLE
|
2006-06-06 06:15:52 +00:00
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_XILINX_MICROBLAZE)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* MIPS */
|
2001-02-24 20:01:53 +00:00
|
|
|
|
#if defined(__mips__)
|
2004-09-02 23:03:25 +00:00
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_MIPS || x == EM_MIPS_RS3_LE)
|
|
|
|
|
#define SHT_RELM SHT_REL
|
|
|
|
|
#define Elf32_RelM Elf32_Rel
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2002-05-24 06:50:15 +00:00
|
|
|
|
/* Account for ELF spec changes. */
|
|
|
|
|
#ifndef EM_MIPS_RS3_LE
|
|
|
|
|
#ifdef EM_MIPS_RS4_BE
|
|
|
|
|
#define EM_MIPS_RS3_LE EM_MIPS_RS4_BE
|
|
|
|
|
#else
|
|
|
|
|
#define EM_MIPS_RS3_LE 10
|
|
|
|
|
#endif
|
|
|
|
|
#endif /* !EM_MIPS_RS3_LE */
|
|
|
|
|
#define ARCHDATAM "__dbe_table"
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-01-04 00:11:26 +00:00
|
|
|
|
/* Nios II */
|
|
|
|
|
#if defined(__nios2__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_ALTERA_NIOS2)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* PowerPC */
|
2005-09-14 00:07:26 +00:00
|
|
|
|
#if defined(__powerpc64__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_PPC64)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf64_RelM Elf64_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS64
|
|
|
|
|
#elif defined(__powerpc__)
|
2004-09-02 23:03:25 +00:00
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_PPC)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_PLT_ENTRIES
|
|
|
|
|
#define PLT_ENTRY_SIZE 16
|
|
|
|
|
#define USE_PLT_LIST
|
|
|
|
|
#define LIST_ARCHTYPE ElfW(Addr)
|
|
|
|
|
#define USE_LIST
|
2004-09-02 23:03:25 +00:00
|
|
|
|
#define ARCHDATAM "__ftr_fixup"
|
|
|
|
|
#endif
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* S390 */
|
|
|
|
|
#if defined(__s390__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_S390)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_PLT_ENTRIES
|
|
|
|
|
#define PLT_ENTRY_SIZE 8
|
|
|
|
|
#define USE_GOT_ENTRIES
|
|
|
|
|
#define GOT_ENTRY_SIZE 8
|
|
|
|
|
#define USE_SINGLE
|
2004-09-02 23:03:25 +00:00
|
|
|
|
#endif
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* SuperH */
|
|
|
|
|
#if defined(__sh__)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_SH)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_GOT_ENTRIES
|
|
|
|
|
#define GOT_ENTRY_SIZE 4
|
|
|
|
|
#define USE_SINGLE
|
2003-08-13 19:56:33 +00:00
|
|
|
|
/* the SH changes have only been tested in =little endian= mode */
|
2002-05-24 06:50:15 +00:00
|
|
|
|
/* I'm not sure about big endian, so let's warn: */
|
2006-03-04 22:40:25 +00:00
|
|
|
|
#if defined(__sh__) && BB_BIG_ENDIAN
|
|
|
|
|
# error insmod.c may require changes for use on big endian SH
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* it may or may not work on the SH1/SH2... Error on those also */
|
|
|
|
|
#if ((!(defined(__SH3__) || defined(__SH4__) || defined(__SH5__)))) && (defined(__sh__))
|
2003-08-13 19:56:33 +00:00
|
|
|
|
#error insmod.c may require changes for SH1 or SH2 use
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
2001-02-24 20:01:53 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* Sparc */
|
|
|
|
|
#if defined(__sparc__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_SPARC)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* v850e */
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#if defined(__v850e__)
|
2004-09-02 23:03:25 +00:00
|
|
|
|
#define MATCH_MACHINE(x) ((x) == EM_V850 || (x) == EM_CYGNUS_V850)
|
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
|
#define ELFCLASSM ELFCLASS32
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_PLT_ENTRIES
|
|
|
|
|
#define PLT_ENTRY_SIZE 8
|
|
|
|
|
#define USE_SINGLE
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#ifndef EM_CYGNUS_V850 /* grumble */
|
2006-01-25 00:08:53 +00:00
|
|
|
|
#define EM_CYGNUS_V850 0x9080
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
|
|
|
|
#define SYMBOL_PREFIX "_"
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-02 23:03:25 +00:00
|
|
|
|
/* X86_64 */
|
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_X86_64)
|
2005-03-30 06:29:41 +00:00
|
|
|
|
#define SHT_RELM SHT_RELA
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#define USE_GOT_ENTRIES
|
|
|
|
|
#define GOT_ENTRY_SIZE 8
|
|
|
|
|
#define USE_SINGLE
|
2005-03-30 06:29:41 +00:00
|
|
|
|
#define Elf64_RelM Elf64_Rela
|
2004-09-02 23:03:25 +00:00
|
|
|
|
#define ELFCLASSM ELFCLASS64
|
2004-05-26 11:38:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#ifndef SHT_RELM
|
|
|
|
|
#error Sorry, but insmod.c does not yet support this architecture...
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
//--------modutils module.h, lines 45-242
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/* Definitions for the Linux module syscall interface.
|
|
|
|
|
Copyright 1996, 1997 Linux International.
|
|
|
|
|
|
|
|
|
|
Contributed by Richard Henderson <rth@tamu.edu>
|
|
|
|
|
|
|
|
|
|
This file is part of the Linux modutils.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MODUTILS_MODULE_H
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
/* For sizeof() which are related to the module platform and not to the
|
|
|
|
|
environment isnmod is running in, use sizeof_xx instead of sizeof(xx). */
|
|
|
|
|
|
|
|
|
|
#define tgt_sizeof_char sizeof(char)
|
|
|
|
|
#define tgt_sizeof_short sizeof(short)
|
|
|
|
|
#define tgt_sizeof_int sizeof(int)
|
|
|
|
|
#define tgt_sizeof_long sizeof(long)
|
|
|
|
|
#define tgt_sizeof_char_p sizeof(char *)
|
|
|
|
|
#define tgt_sizeof_void_p sizeof(void *)
|
|
|
|
|
#define tgt_long long
|
|
|
|
|
|
|
|
|
|
#if defined(__sparc__) && !defined(__sparc_v9__) && defined(ARCH_sparc64)
|
|
|
|
|
#undef tgt_sizeof_long
|
|
|
|
|
#undef tgt_sizeof_char_p
|
|
|
|
|
#undef tgt_sizeof_void_p
|
|
|
|
|
#undef tgt_long
|
2006-03-10 19:22:06 +00:00
|
|
|
|
enum {
|
|
|
|
|
tgt_sizeof_long = 8,
|
|
|
|
|
tgt_sizeof_char_p = 8,
|
|
|
|
|
tgt_sizeof_void_p = 8
|
|
|
|
|
};
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#define tgt_long long long
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
/* The structures used in Linux 2.1. */
|
|
|
|
|
|
|
|
|
|
/* Note: new_module_symbol does not use tgt_long intentionally */
|
2006-10-12 20:06:18 +00:00
|
|
|
|
struct new_module_symbol {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
unsigned long value;
|
|
|
|
|
unsigned long name;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct new_module_persist;
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
struct new_module_ref {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
unsigned tgt_long dep; /* kernel addresses */
|
|
|
|
|
unsigned tgt_long ref;
|
|
|
|
|
unsigned tgt_long next_ref;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
struct new_module {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
unsigned tgt_long size_of_struct; /* == sizeof(module) */
|
|
|
|
|
unsigned tgt_long next;
|
|
|
|
|
unsigned tgt_long name;
|
|
|
|
|
unsigned tgt_long size;
|
|
|
|
|
|
|
|
|
|
tgt_long usecount;
|
|
|
|
|
unsigned tgt_long flags; /* AUTOCLEAN et al */
|
|
|
|
|
|
|
|
|
|
unsigned nsyms;
|
|
|
|
|
unsigned ndeps;
|
|
|
|
|
|
|
|
|
|
unsigned tgt_long syms;
|
|
|
|
|
unsigned tgt_long deps;
|
|
|
|
|
unsigned tgt_long refs;
|
|
|
|
|
unsigned tgt_long init;
|
|
|
|
|
unsigned tgt_long cleanup;
|
|
|
|
|
unsigned tgt_long ex_table_start;
|
|
|
|
|
unsigned tgt_long ex_table_end;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#ifdef __alpha__
|
2003-12-24 20:30:45 +00:00
|
|
|
|
unsigned tgt_long gp;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* Everything after here is extension. */
|
|
|
|
|
unsigned tgt_long persist_start;
|
|
|
|
|
unsigned tgt_long persist_end;
|
|
|
|
|
unsigned tgt_long can_unload;
|
|
|
|
|
unsigned tgt_long runsize;
|
|
|
|
|
const char *kallsyms_start; /* All symbols for kernel debugging */
|
|
|
|
|
const char *kallsyms_end;
|
|
|
|
|
const char *archdata_start; /* arch specific data for module */
|
|
|
|
|
const char *archdata_end;
|
|
|
|
|
const char *kernel_data; /* Reserved for kernel internal use */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#ifdef ARCHDATAM
|
|
|
|
|
#define ARCHDATA_SEC_NAME ARCHDATAM
|
|
|
|
|
#else
|
2001-05-21 16:09:18 +00:00
|
|
|
|
#define ARCHDATA_SEC_NAME "__archdata"
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
2001-05-21 16:09:18 +00:00
|
|
|
|
#define KALLSYMS_SEC_NAME "__kallsyms"
|
|
|
|
|
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
struct new_module_info {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
unsigned long addr;
|
|
|
|
|
unsigned long size;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
long usecount;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Bits of module.flags. */
|
2006-03-10 19:22:06 +00:00
|
|
|
|
enum {
|
|
|
|
|
NEW_MOD_RUNNING = 1,
|
|
|
|
|
NEW_MOD_DELETED = 2,
|
|
|
|
|
NEW_MOD_AUTOCLEAN = 4,
|
|
|
|
|
NEW_MOD_VISITED = 8,
|
|
|
|
|
NEW_MOD_USED_ONCE = 16
|
|
|
|
|
};
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2004-06-22 11:50:52 +00:00
|
|
|
|
int init_module(const char *name, const struct new_module *);
|
|
|
|
|
int query_module(const char *name, int which, void *buf,
|
|
|
|
|
size_t bufsize, size_t *ret);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Values for query_module's which. */
|
2006-03-10 19:22:06 +00:00
|
|
|
|
enum {
|
|
|
|
|
QM_MODULES = 1,
|
|
|
|
|
QM_DEPS = 2,
|
|
|
|
|
QM_REFS = 3,
|
|
|
|
|
QM_SYMBOLS = 4,
|
|
|
|
|
QM_INFO = 5
|
|
|
|
|
};
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
/* The system calls unchanged between 2.0 and 2.1. */
|
|
|
|
|
|
|
|
|
|
unsigned long create_module(const char *, size_t);
|
|
|
|
|
int delete_module(const char *);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* module.h */
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
//--------end of modutils module.h
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
//--------modutils obj.h, lines 253-462
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/* Elf object file loading and relocation routines.
|
|
|
|
|
Copyright 1996, 1997 Linux International.
|
|
|
|
|
|
|
|
|
|
Contributed by Richard Henderson <rth@tamu.edu>
|
|
|
|
|
|
|
|
|
|
This file is part of the Linux modutils.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MODUTILS_OBJ_H
|
|
|
|
|
|
|
|
|
|
/* The relocatable object is manipulated using elfin types. */
|
|
|
|
|
|
|
|
|
|
#include <elf.h>
|
2002-04-12 00:28:59 +00:00
|
|
|
|
#include <endian.h>
|
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#ifndef ElfW
|
|
|
|
|
# if ELFCLASSM == ELFCLASS32
|
|
|
|
|
# define ElfW(x) Elf32_ ## x
|
|
|
|
|
# define ELFW(x) ELF32_ ## x
|
|
|
|
|
# else
|
|
|
|
|
# define ElfW(x) Elf64_ ## x
|
|
|
|
|
# define ELFW(x) ELF64_ ## x
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-07-22 08:56:55 +00:00
|
|
|
|
/* For some reason this is missing from some ancient C libraries.... */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#ifndef ELF32_ST_INFO
|
|
|
|
|
# define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef ELF64_ST_INFO
|
|
|
|
|
# define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-10-02 07:02:16 +00:00
|
|
|
|
#define ELF_ST_BIND(info) ELFW(ST_BIND)(info)
|
|
|
|
|
#define ELF_ST_TYPE(info) ELFW(ST_TYPE)(info)
|
|
|
|
|
#define ELF_ST_INFO(bind, type) ELFW(ST_INFO)(bind, type)
|
|
|
|
|
#define ELF_R_TYPE(val) ELFW(R_TYPE)(val)
|
|
|
|
|
#define ELF_R_SYM(val) ELFW(R_SYM)(val)
|
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_string_patch;
|
|
|
|
|
struct obj_symbol_patch;
|
|
|
|
|
|
|
|
|
|
struct obj_section
|
|
|
|
|
{
|
2003-12-24 20:30:45 +00:00
|
|
|
|
ElfW(Shdr) header;
|
|
|
|
|
const char *name;
|
|
|
|
|
char *contents;
|
|
|
|
|
struct obj_section *load_next;
|
|
|
|
|
int idx;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct obj_symbol
|
|
|
|
|
{
|
2003-12-24 20:30:45 +00:00
|
|
|
|
struct obj_symbol *next; /* hash table link */
|
|
|
|
|
const char *name;
|
|
|
|
|
unsigned long value;
|
|
|
|
|
unsigned long size;
|
|
|
|
|
int secidx; /* the defining section index/module */
|
|
|
|
|
int info;
|
|
|
|
|
int ksymidx; /* for export to the kernel symtab */
|
|
|
|
|
int referenced; /* actually used in the link */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Hardcode the hash table size. We shouldn't be needing so many
|
|
|
|
|
symbols that we begin to degrade performance, and we get a big win
|
|
|
|
|
by giving the compiler a constant divisor. */
|
|
|
|
|
|
|
|
|
|
#define HASH_BUCKETS 521
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
struct obj_file {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
ElfW(Ehdr) header;
|
|
|
|
|
ElfW(Addr) baseaddr;
|
|
|
|
|
struct obj_section **sections;
|
|
|
|
|
struct obj_section *load_order;
|
|
|
|
|
struct obj_section **load_order_search_start;
|
|
|
|
|
struct obj_string_patch *string_patches;
|
|
|
|
|
struct obj_symbol_patch *symbol_patches;
|
|
|
|
|
int (*symbol_cmp)(const char *, const char *);
|
|
|
|
|
unsigned long (*symbol_hash)(const char *);
|
|
|
|
|
unsigned long local_symtab_size;
|
|
|
|
|
struct obj_symbol **local_symtab;
|
|
|
|
|
struct obj_symbol *symtab[HASH_BUCKETS];
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
enum obj_reloc {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
obj_reloc_ok,
|
|
|
|
|
obj_reloc_overflow,
|
|
|
|
|
obj_reloc_dangerous,
|
|
|
|
|
obj_reloc_unhandled
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
struct obj_string_patch {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
struct obj_string_patch *next;
|
|
|
|
|
int reloc_secidx;
|
|
|
|
|
ElfW(Addr) reloc_offset;
|
|
|
|
|
ElfW(Addr) string_offset;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
struct obj_symbol_patch {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
struct obj_symbol_patch *next;
|
|
|
|
|
int reloc_secidx;
|
|
|
|
|
ElfW(Addr) reloc_offset;
|
|
|
|
|
struct obj_symbol *sym;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Generic object manipulation routines. */
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static unsigned long obj_elf_hash(const char *);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static unsigned long obj_elf_hash_n(const char *, unsigned long len);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static struct obj_symbol *obj_find_symbol(struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
const char *name);
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static ElfW(Addr) obj_symbol_final_value(struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_symbol *sym);
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static void obj_set_symbol_compare(struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
int (*cmp)(const char *, const char *),
|
|
|
|
|
unsigned long (*hash)(const char *));
|
2001-07-31 22:51:49 +00:00
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static struct obj_section *obj_find_section(struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
const char *name);
|
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static void obj_insert_section_load_order(struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_section *sec);
|
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static struct obj_section *obj_create_alloced_section(struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
const char *name,
|
|
|
|
|
unsigned long align,
|
|
|
|
|
unsigned long size);
|
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static struct obj_section *obj_create_alloced_section_first(struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
const char *name,
|
|
|
|
|
unsigned long align,
|
|
|
|
|
unsigned long size);
|
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static void *obj_extend_section(struct obj_section *sec, unsigned long more);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
const char *string);
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_symbol *sym);
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void obj_check_undefineds(struct obj_file *f);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static void obj_allocate_commons(struct obj_file *f);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static unsigned long obj_load_size(struct obj_file *f);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static int obj_relocate(struct obj_file *f, ElfW(Addr) base);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_file *obj_load(FILE *f, int loadprogbits);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static int obj_create_image(struct obj_file *f, char *image);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Architecture specific manipulation routines. */
|
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static struct obj_file *arch_new_file(void);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static struct obj_section *arch_new_section(void);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static struct obj_symbol *arch_new_symbol(void);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static enum obj_reloc arch_apply_relocation(struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_section *targsec,
|
|
|
|
|
struct obj_section *symsec,
|
|
|
|
|
struct obj_symbol *sym,
|
|
|
|
|
ElfW(RelM) *rel, ElfW(Addr) value);
|
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
static void arch_create_got(struct obj_file *f);
|
2006-03-29 18:57:09 +00:00
|
|
|
|
#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
|
2003-08-30 06:00:33 +00:00
|
|
|
|
static int obj_gpl_license(struct obj_file *f, const char **license);
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_CHECK_TAINTED_MODULE */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#endif /* obj.h */
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
//--------end of modutils obj.h
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
2002-04-01 09:34:25 +00:00
|
|
|
|
/* SPFX is always a string, so it can be concatenated to string constants. */
|
|
|
|
|
#ifdef SYMBOL_PREFIX
|
|
|
|
|
#define SPFX SYMBOL_PREFIX
|
|
|
|
|
#else
|
2006-01-25 00:08:53 +00:00
|
|
|
|
#define SPFX ""
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
1999-12-17 18:57:34 +00:00
|
|
|
|
|
1999-12-21 02:55:11 +00:00
|
|
|
|
#define _PATH_MODULES "/lib/modules"
|
2006-11-21 14:12:53 +00:00
|
|
|
|
enum { STRVERSIONLEN = 64 };
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
|
2006-09-23 12:32:58 +00:00
|
|
|
|
#define OPTION_STR "sLo:fkvqx" USE_FEATURE_INSMOD_LOAD_MAP("m")
|
|
|
|
|
enum {
|
|
|
|
|
OPT_s = 0x1, // -s /* log to syslog */
|
|
|
|
|
/* Not supported but kernel needs this for request_module(),
|
|
|
|
|
as this calls: modprobe -k -s -- <module>
|
|
|
|
|
so silently ignore this flag */
|
|
|
|
|
OPT_L = 0x2, // -L /* Stub warning */
|
|
|
|
|
/* Compatibility with modprobe.
|
|
|
|
|
In theory, this does locking, but we don't do
|
|
|
|
|
that. So be careful and plan your life around not
|
|
|
|
|
loading the same module 50 times concurrently. */
|
|
|
|
|
OPT_o = 0x4, // -o /* name the output module */
|
|
|
|
|
OPT_f = 0x8, // -f /* force loading */
|
|
|
|
|
OPT_k = 0x10, // -k /* module loaded by kerneld, auto-cleanable */
|
|
|
|
|
OPT_v = 0x20, // -v /* verbose output */
|
|
|
|
|
OPT_q = 0x40, // -q /* silent */
|
|
|
|
|
OPT_x = 0x80, // -x /* do not export externs */
|
|
|
|
|
OPT_m = 0x100, // -m /* print module load map */
|
|
|
|
|
};
|
2006-10-06 09:49:47 +00:00
|
|
|
|
#define flag_force_load (option_mask32 & OPT_f)
|
|
|
|
|
#define flag_autoclean (option_mask32 & OPT_k)
|
|
|
|
|
#define flag_verbose (option_mask32 & OPT_v)
|
|
|
|
|
#define flag_quiet (option_mask32 & OPT_q)
|
|
|
|
|
#define flag_noexport (option_mask32 & OPT_x)
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_LOAD_MAP
|
2006-10-06 09:49:47 +00:00
|
|
|
|
#define flag_print_load_map (option_mask32 & OPT_m)
|
2006-09-23 12:32:58 +00:00
|
|
|
|
#else
|
|
|
|
|
#define flag_print_load_map 0
|
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_LIST)
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
struct arch_list_entry
|
2000-12-06 18:18:26 +00:00
|
|
|
|
{
|
2002-05-24 06:50:15 +00:00
|
|
|
|
struct arch_list_entry *next;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
LIST_ARCHTYPE addend;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
int offset;
|
|
|
|
|
int inited : 1;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
};
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_SINGLE)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
|
|
|
|
struct arch_single_entry
|
|
|
|
|
{
|
2000-06-12 23:11:16 +00:00
|
|
|
|
int offset;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
int inited : 1;
|
|
|
|
|
int allocated : 1;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2001-02-24 20:01:53 +00:00
|
|
|
|
#if defined(__mips__)
|
|
|
|
|
struct mips_hi16
|
|
|
|
|
{
|
2003-12-24 20:30:45 +00:00
|
|
|
|
struct mips_hi16 *next;
|
2005-10-02 07:02:16 +00:00
|
|
|
|
ElfW(Addr) *addr;
|
|
|
|
|
ElfW(Addr) value;
|
2001-02-24 20:01:53 +00:00
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-09-24 03:44:29 +00:00
|
|
|
|
struct arch_file {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_file root;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
2001-02-20 20:47:08 +00:00
|
|
|
|
struct obj_section *plt;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#endif
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_section *got;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2001-02-24 20:01:53 +00:00
|
|
|
|
#if defined(__mips__)
|
|
|
|
|
struct mips_hi16 *mips_hi16_list;
|
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2000-09-24 03:44:29 +00:00
|
|
|
|
struct arch_symbol {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_symbol root;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
|
|
|
|
#if defined(USE_PLT_LIST)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
struct arch_list_entry *pltent;
|
|
|
|
|
#else
|
|
|
|
|
struct arch_single_entry pltent;
|
|
|
|
|
#endif
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#endif
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
struct arch_single_entry gotent;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct external_module {
|
|
|
|
|
const char *name;
|
|
|
|
|
ElfW(Addr) addr;
|
|
|
|
|
int used;
|
|
|
|
|
size_t nsyms;
|
|
|
|
|
struct new_module_symbol *syms;
|
|
|
|
|
};
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct new_module_symbol *ksyms;
|
|
|
|
|
static size_t nksyms;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct external_module *ext_modules;
|
|
|
|
|
static int n_ext_modules;
|
|
|
|
|
static int n_ext_modules_used;
|
2001-04-05 06:08:14 +00:00
|
|
|
|
|
2002-06-22 17:15:42 +00:00
|
|
|
|
static char *m_filename;
|
2002-07-19 00:05:54 +00:00
|
|
|
|
static char *m_fullName;
|
1999-12-17 18:57:34 +00:00
|
|
|
|
|
2000-09-24 03:44:29 +00:00
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
/*======================================================================*/
|
|
|
|
|
|
1999-12-17 18:57:34 +00:00
|
|
|
|
|
2001-05-14 17:07:32 +00:00
|
|
|
|
static int check_module_name_match(const char *filename, struct stat *statbuf,
|
2006-10-27 23:42:25 +00:00
|
|
|
|
void *userdata, int depth)
|
1999-12-21 02:55:11 +00:00
|
|
|
|
{
|
2001-05-14 17:07:32 +00:00
|
|
|
|
char *fullname = (char *) userdata;
|
2007-11-02 23:31:10 +00:00
|
|
|
|
char *tmp;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2001-05-14 17:07:32 +00:00
|
|
|
|
if (fullname[0] == '\0')
|
2006-11-27 16:49:55 +00:00
|
|
|
|
return FALSE;
|
2007-11-02 23:31:10 +00:00
|
|
|
|
|
|
|
|
|
tmp = bb_get_last_path_component_nostrip(filename);
|
|
|
|
|
if (strcmp(tmp, fullname) == 0) {
|
|
|
|
|
/* Stop searching if we find a match */
|
|
|
|
|
m_filename = xstrdup(filename);
|
|
|
|
|
return FALSE;
|
1999-12-21 02:55:11 +00:00
|
|
|
|
}
|
2006-11-27 16:49:55 +00:00
|
|
|
|
return TRUE;
|
1999-12-21 02:55:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-17 18:57:34 +00:00
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
/*======================================================================*/
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_file *arch_new_file(void)
|
1999-12-17 18:57:34 +00:00
|
|
|
|
{
|
2000-09-24 03:44:29 +00:00
|
|
|
|
struct arch_file *f;
|
2007-11-02 23:31:10 +00:00
|
|
|
|
f = xzalloc(sizeof(*f));
|
|
|
|
|
return &f->root; /* it's a first member */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_section *arch_new_section(void)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
2007-11-02 23:31:10 +00:00
|
|
|
|
return xzalloc(sizeof(struct obj_section));
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_symbol *arch_new_symbol(void)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
2000-09-24 03:44:29 +00:00
|
|
|
|
struct arch_symbol *sym;
|
2007-11-02 23:31:10 +00:00
|
|
|
|
sym = xzalloc(sizeof(*sym));
|
2000-06-12 23:11:16 +00:00
|
|
|
|
return &sym->root;
|
|
|
|
|
}
|
2000-09-24 03:44:29 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static enum obj_reloc
|
2000-06-12 23:11:16 +00:00
|
|
|
|
arch_apply_relocation(struct obj_file *f,
|
2006-10-12 20:06:18 +00:00
|
|
|
|
struct obj_section *targsec,
|
|
|
|
|
struct obj_section *symsec,
|
|
|
|
|
struct obj_symbol *sym,
|
|
|
|
|
ElfW(RelM) *rel, ElfW(Addr) v)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
2000-09-24 03:44:29 +00:00
|
|
|
|
struct arch_file *ifile = (struct arch_file *) f;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
enum obj_reloc ret = obj_reloc_ok;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
ElfW(Addr) *loc = (ElfW(Addr) *) (targsec->contents + rel->r_offset);
|
|
|
|
|
ElfW(Addr) dot = targsec->header.sh_addr + rel->r_offset;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
struct arch_symbol *isym = (struct arch_symbol *) sym;
|
|
|
|
|
#endif
|
2006-01-30 23:09:20 +00:00
|
|
|
|
#if defined(__arm__) || defined(__i386__) || defined(__mc68000__) || defined(__sh__) || defined(__s390__)
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
2000-12-06 18:18:26 +00:00
|
|
|
|
ElfW(Addr) got = ifile->got ? ifile->got->header.sh_addr : 0;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2006-01-30 23:09:20 +00:00
|
|
|
|
#endif
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
2000-12-06 18:18:26 +00:00
|
|
|
|
ElfW(Addr) plt = ifile->plt ? ifile->plt->header.sh_addr : 0;
|
|
|
|
|
unsigned long *ip;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
# if defined(USE_PLT_LIST)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
struct arch_list_entry *pe;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
# else
|
2002-05-24 06:50:15 +00:00
|
|
|
|
struct arch_single_entry *pe;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
# endif
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2005-10-02 07:02:16 +00:00
|
|
|
|
switch (ELF_R_TYPE(rel->r_info)) {
|
2000-09-24 03:44:29 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#if defined(__arm__)
|
2005-10-02 07:50:49 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_ARM_NONE:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_ARM_ABS32:
|
|
|
|
|
*loc += v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_ARM_GOT32:
|
|
|
|
|
goto bb_use_got;
|
|
|
|
|
|
|
|
|
|
case R_ARM_GOTPC:
|
2004-03-15 08:29:22 +00:00
|
|
|
|
/* relative reloc, always to _GLOBAL_OFFSET_TABLE_
|
|
|
|
|
* (which is .got) similar to branch,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
* but is full 32 bits relative */
|
|
|
|
|
|
|
|
|
|
*loc += got - dot;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_ARM_PC24:
|
|
|
|
|
case R_ARM_PLT32:
|
|
|
|
|
goto bb_use_plt;
|
|
|
|
|
|
|
|
|
|
case R_ARM_GOTOFF: /* address relative to the got */
|
|
|
|
|
*loc += v - got;
|
|
|
|
|
break;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
#elif defined(__cris__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
case R_CRIS_NONE:
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
case R_CRIS_32:
|
|
|
|
|
/* CRIS keeps the relocation value in the r_addend field and
|
|
|
|
|
* should not use whats in *loc at all
|
|
|
|
|
*/
|
2003-12-24 20:30:45 +00:00
|
|
|
|
*loc = v;
|
|
|
|
|
break;
|
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
#elif defined(__H8300H__) || defined(__H8300S__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
case R_H8_DIR24R8:
|
|
|
|
|
loc = (ElfW(Addr) *)((ElfW(Addr))loc - 1);
|
|
|
|
|
*loc = (*loc & 0xff000000) | ((*loc & 0xffffff) + v);
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
case R_H8_DIR24A8:
|
|
|
|
|
*loc += v;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
case R_H8_DIR32:
|
|
|
|
|
case R_H8_DIR32A16:
|
|
|
|
|
*loc += v;
|
|
|
|
|
break;
|
|
|
|
|
case R_H8_PCREL16:
|
|
|
|
|
v -= dot + 2;
|
|
|
|
|
if ((ElfW(Sword))v > 0x7fff ||
|
|
|
|
|
(ElfW(Sword))v < -(ElfW(Sword))0x8000)
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
else
|
|
|
|
|
*(unsigned short *)loc = v;
|
|
|
|
|
break;
|
|
|
|
|
case R_H8_PCREL8:
|
|
|
|
|
v -= dot + 1;
|
|
|
|
|
if ((ElfW(Sword))v > 0x7f ||
|
|
|
|
|
(ElfW(Sword))v < -(ElfW(Sword))0x80)
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
else
|
|
|
|
|
*(unsigned char *)loc = v;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
2003-01-23 06:02:39 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#elif defined(__i386__)
|
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_386_NONE:
|
|
|
|
|
break;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_386_32:
|
|
|
|
|
*loc += v;
|
|
|
|
|
break;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_386_PLT32:
|
|
|
|
|
case R_386_PC32:
|
|
|
|
|
*loc += v - dot;
|
|
|
|
|
break;
|
2001-02-24 20:01:53 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_386_GLOB_DAT:
|
|
|
|
|
case R_386_JMP_SLOT:
|
|
|
|
|
*loc = v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_386_RELATIVE:
|
|
|
|
|
*loc += f->baseaddr;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_386_GOTPC:
|
|
|
|
|
*loc += got - dot;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_386_GOT32:
|
|
|
|
|
goto bb_use_got;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_386_GOTOFF:
|
|
|
|
|
*loc += v - got;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#elif defined(__microblaze__)
|
2006-06-06 06:30:32 +00:00
|
|
|
|
case R_MICROBLAZE_NONE:
|
|
|
|
|
case R_MICROBLAZE_64_NONE:
|
|
|
|
|
case R_MICROBLAZE_32_SYM_OP_SYM:
|
|
|
|
|
case R_MICROBLAZE_32_PCREL:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_MICROBLAZE_64_PCREL: {
|
|
|
|
|
/* dot is the address of the current instruction.
|
|
|
|
|
* v is the target symbol address.
|
|
|
|
|
* So we need to extract the offset in the code,
|
2006-09-17 16:28:10 +00:00
|
|
|
|
* adding v, then subtrating the current address
|
2006-06-06 06:30:32 +00:00
|
|
|
|
* of this instruction.
|
|
|
|
|
* Ex: "IMM 0xFFFE bralid 0x0000" = "bralid 0xFFFE0000"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Get split offset stored in code */
|
|
|
|
|
unsigned int temp = (loc[0] & 0xFFFF) << 16 |
|
|
|
|
|
(loc[1] & 0xFFFF);
|
|
|
|
|
|
2006-09-17 16:28:10 +00:00
|
|
|
|
/* Adjust relative offset. -4 adjustment required
|
2006-06-06 06:30:32 +00:00
|
|
|
|
* because dot points to the IMM insn, but branch
|
|
|
|
|
* is computed relative to the branch instruction itself.
|
|
|
|
|
*/
|
|
|
|
|
temp += v - dot - 4;
|
|
|
|
|
|
|
|
|
|
/* Store back into code */
|
|
|
|
|
loc[0] = (loc[0] & 0xFFFF0000) | temp >> 16;
|
|
|
|
|
loc[1] = (loc[1] & 0xFFFF0000) | (temp & 0xFFFF);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case R_MICROBLAZE_32:
|
|
|
|
|
*loc += v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_MICROBLAZE_64: {
|
|
|
|
|
/* Get split pointer stored in code */
|
|
|
|
|
unsigned int temp1 = (loc[0] & 0xFFFF) << 16 |
|
|
|
|
|
(loc[1] & 0xFFFF);
|
|
|
|
|
|
|
|
|
|
/* Add reloc offset */
|
|
|
|
|
temp1+=v;
|
|
|
|
|
|
|
|
|
|
/* Store back into code */
|
|
|
|
|
loc[0] = (loc[0] & 0xFFFF0000) | temp1 >> 16;
|
|
|
|
|
loc[1] = (loc[1] & 0xFFFF0000) | (temp1 & 0xFFFF);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case R_MICROBLAZE_32_PCREL_LO:
|
|
|
|
|
case R_MICROBLAZE_32_LO:
|
|
|
|
|
case R_MICROBLAZE_SRO32:
|
|
|
|
|
case R_MICROBLAZE_SRW32:
|
|
|
|
|
ret = obj_reloc_unhandled;
|
|
|
|
|
break;
|
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#elif defined(__mc68000__)
|
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_NONE:
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_32:
|
|
|
|
|
*loc += v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_8:
|
|
|
|
|
if (v > 0xff) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
*(char *)loc = v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_16:
|
|
|
|
|
if (v > 0xffff) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
*(short *)loc = v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_68K_PC8:
|
|
|
|
|
v -= dot;
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if ((ElfW(Sword))v > 0x7f ||
|
|
|
|
|
(ElfW(Sword))v < -(ElfW(Sword))0x80) {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
*(char *)loc = v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_68K_PC16:
|
|
|
|
|
v -= dot;
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if ((ElfW(Sword))v > 0x7fff ||
|
|
|
|
|
(ElfW(Sword))v < -(ElfW(Sword))0x8000) {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
*(short *)loc = v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_PC32:
|
|
|
|
|
*(int *)loc = v - dot;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_GLOB_DAT:
|
|
|
|
|
case R_68K_JMP_SLOT:
|
|
|
|
|
*loc = v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_RELATIVE:
|
|
|
|
|
*(int *)loc += f->baseaddr;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_GOT32:
|
|
|
|
|
goto bb_use_got;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
# ifdef R_68K_GOTOFF
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_68K_GOTOFF:
|
|
|
|
|
*loc += v - got;
|
|
|
|
|
break;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
# endif
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
|
|
|
|
#elif defined(__mips__)
|
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_MIPS_NONE:
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_MIPS_32:
|
|
|
|
|
*loc += v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_MIPS_26:
|
|
|
|
|
if (v % 4)
|
|
|
|
|
ret = obj_reloc_dangerous;
|
|
|
|
|
if ((v & 0xf0000000) != ((dot + 4) & 0xf0000000))
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
*loc =
|
|
|
|
|
(*loc & ~0x03ffffff) | ((*loc + (v >> 2)) &
|
|
|
|
|
0x03ffffff);
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_MIPS_HI16:
|
|
|
|
|
{
|
|
|
|
|
struct mips_hi16 *n;
|
|
|
|
|
|
|
|
|
|
/* We cannot relocate this one now because we don't know the value
|
|
|
|
|
of the carry we need to add. Save the information, and let LO16
|
|
|
|
|
do the actual relocation. */
|
2006-12-19 23:36:04 +00:00
|
|
|
|
n = xmalloc(sizeof *n);
|
2003-12-24 20:30:45 +00:00
|
|
|
|
n->addr = loc;
|
|
|
|
|
n->value = v;
|
|
|
|
|
n->next = ifile->mips_hi16_list;
|
|
|
|
|
ifile->mips_hi16_list = n;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-02-24 20:01:53 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_MIPS_LO16:
|
|
|
|
|
{
|
|
|
|
|
unsigned long insnlo = *loc;
|
2005-10-02 07:02:16 +00:00
|
|
|
|
ElfW(Addr) val, vallo;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
|
|
|
|
/* Sign extend the addend we extract from the lo insn. */
|
|
|
|
|
vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000;
|
|
|
|
|
|
|
|
|
|
if (ifile->mips_hi16_list != NULL) {
|
|
|
|
|
struct mips_hi16 *l;
|
|
|
|
|
|
|
|
|
|
l = ifile->mips_hi16_list;
|
|
|
|
|
while (l != NULL) {
|
|
|
|
|
struct mips_hi16 *next;
|
|
|
|
|
unsigned long insn;
|
|
|
|
|
|
|
|
|
|
/* Do the HI16 relocation. Note that we actually don't
|
|
|
|
|
need to know anything about the LO16 itself, except where
|
|
|
|
|
to find the low 16 bits of the addend needed by the LO16. */
|
|
|
|
|
insn = *l->addr;
|
|
|
|
|
val =
|
|
|
|
|
((insn & 0xffff) << 16) +
|
|
|
|
|
vallo;
|
|
|
|
|
val += v;
|
|
|
|
|
|
|
|
|
|
/* Account for the sign extension that will happen in the
|
|
|
|
|
low bits. */
|
|
|
|
|
val =
|
|
|
|
|
((val >> 16) +
|
|
|
|
|
((val & 0x8000) !=
|
|
|
|
|
0)) & 0xffff;
|
|
|
|
|
|
|
|
|
|
insn = (insn & ~0xffff) | val;
|
|
|
|
|
*l->addr = insn;
|
|
|
|
|
|
|
|
|
|
next = l->next;
|
|
|
|
|
free(l);
|
|
|
|
|
l = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ifile->mips_hi16_list = NULL;
|
2001-02-24 20:01:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* Ok, we're done with the HI16 relocs. Now deal with the LO16. */
|
|
|
|
|
val = v + vallo;
|
|
|
|
|
insnlo = (insnlo & ~0xffff) | (val & 0xffff);
|
|
|
|
|
*loc = insnlo;
|
|
|
|
|
break;
|
2001-02-24 20:01:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-04 00:11:26 +00:00
|
|
|
|
#elif defined(__nios2__)
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_NONE:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_BFD_RELOC_32:
|
|
|
|
|
*loc += v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_BFD_RELOC_16:
|
|
|
|
|
if (v > 0xffff) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
*(short *)loc = v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_BFD_RELOC_8:
|
|
|
|
|
if (v > 0xff) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
*(char *)loc = v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_S16:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word;
|
|
|
|
|
|
|
|
|
|
if ((Elf32_Sword)v > 0x7fff ||
|
|
|
|
|
(Elf32_Sword)v < -(Elf32_Sword)0x8000) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word = *loc;
|
|
|
|
|
*loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) |
|
|
|
|
|
(word & 0x3f);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_U16:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word;
|
|
|
|
|
|
|
|
|
|
if (v > 0xffff) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word = *loc;
|
|
|
|
|
*loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) |
|
|
|
|
|
(word & 0x3f);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_PCREL16:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word;
|
|
|
|
|
|
|
|
|
|
v -= dot + 4;
|
|
|
|
|
if ((Elf32_Sword)v > 0x7fff ||
|
|
|
|
|
(Elf32_Sword)v < -(Elf32_Sword)0x8000) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word = *loc;
|
|
|
|
|
*loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) | (word & 0x3f);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_GPREL:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word, gp;
|
|
|
|
|
/* get _gp */
|
|
|
|
|
gp = obj_symbol_final_value(f, obj_find_symbol(f, SPFX "_gp"));
|
|
|
|
|
v-=gp;
|
|
|
|
|
if ((Elf32_Sword)v > 0x7fff ||
|
|
|
|
|
(Elf32_Sword)v < -(Elf32_Sword)0x8000) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word = *loc;
|
|
|
|
|
*loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) | (word & 0x3f);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_CALL26:
|
|
|
|
|
if (v & 3)
|
|
|
|
|
ret = obj_reloc_dangerous;
|
|
|
|
|
if ((v >> 28) != (dot >> 28))
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
*loc = (*loc & 0x3f) | ((v >> 2) << 6);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_IMM5:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word;
|
|
|
|
|
|
|
|
|
|
if (v > 0x1f) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word = *loc & ~0x7c0;
|
|
|
|
|
*loc = word | ((v & 0x1f) << 6);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_IMM6:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word;
|
|
|
|
|
|
|
|
|
|
if (v > 0x3f) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word = *loc & ~0xfc0;
|
|
|
|
|
*loc = word | ((v & 0x3f) << 6);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_IMM8:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word;
|
|
|
|
|
|
|
|
|
|
if (v > 0xff) {
|
|
|
|
|
ret = obj_reloc_overflow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
word = *loc & ~0x3fc0;
|
|
|
|
|
*loc = word | ((v & 0xff) << 6);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_HI16:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word;
|
|
|
|
|
|
|
|
|
|
word = *loc;
|
|
|
|
|
*loc = ((((word >> 22) << 16) | ((v >>16) & 0xffff)) << 6) |
|
|
|
|
|
(word & 0x3f);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_LO16:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word;
|
|
|
|
|
|
|
|
|
|
word = *loc;
|
|
|
|
|
*loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) |
|
|
|
|
|
(word & 0x3f);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_NIOS2_HIADJ16:
|
|
|
|
|
{
|
|
|
|
|
Elf32_Addr word1, word2;
|
|
|
|
|
|
|
|
|
|
word1 = *loc;
|
|
|
|
|
word2 = ((v >> 16) + ((v >> 15) & 1)) & 0xffff;
|
|
|
|
|
*loc = ((((word1 >> 22) << 16) | word2) << 6) |
|
|
|
|
|
(word1 & 0x3f);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2006-02-18 06:14:31 +00:00
|
|
|
|
#elif defined(__powerpc64__)
|
2006-02-20 14:39:55 +00:00
|
|
|
|
/* PPC64 needs a 2.6 kernel, 2.4 module relocation irrelevant */
|
2006-02-18 06:14:31 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#elif defined(__powerpc__)
|
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_PPC_ADDR16_HA:
|
|
|
|
|
*(unsigned short *)loc = (v + 0x8000) >> 16;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_PPC_ADDR16_HI:
|
|
|
|
|
*(unsigned short *)loc = v >> 16;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_PPC_ADDR16_LO:
|
|
|
|
|
*(unsigned short *)loc = v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_PPC_REL24:
|
|
|
|
|
goto bb_use_plt;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_PPC_REL32:
|
|
|
|
|
*loc = v - dot;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_PPC_ADDR32:
|
|
|
|
|
*loc = v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
#elif defined(__s390__)
|
|
|
|
|
|
|
|
|
|
case R_390_32:
|
|
|
|
|
*(unsigned int *) loc += v;
|
|
|
|
|
break;
|
|
|
|
|
case R_390_16:
|
|
|
|
|
*(unsigned short *) loc += v;
|
|
|
|
|
break;
|
|
|
|
|
case R_390_8:
|
|
|
|
|
*(unsigned char *) loc += v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_390_PC32:
|
|
|
|
|
*(unsigned int *) loc += v - dot;
|
|
|
|
|
break;
|
|
|
|
|
case R_390_PC16DBL:
|
|
|
|
|
*(unsigned short *) loc += (v - dot) >> 1;
|
|
|
|
|
break;
|
|
|
|
|
case R_390_PC16:
|
|
|
|
|
*(unsigned short *) loc += v - dot;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_390_PLT32:
|
|
|
|
|
case R_390_PLT16DBL:
|
|
|
|
|
/* find the plt entry and initialize it. */
|
|
|
|
|
pe = (struct arch_single_entry *) &isym->pltent;
|
|
|
|
|
if (pe->inited == 0) {
|
|
|
|
|
ip = (unsigned long *)(ifile->plt->contents + pe->offset);
|
|
|
|
|
ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */
|
|
|
|
|
ip[1] = 0x100607f1;
|
|
|
|
|
if (ELF_R_TYPE(rel->r_info) == R_390_PLT16DBL)
|
|
|
|
|
ip[2] = v - 2;
|
|
|
|
|
else
|
|
|
|
|
ip[2] = v;
|
|
|
|
|
pe->inited = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Insert relative distance to target. */
|
|
|
|
|
v = plt + pe->offset - dot;
|
|
|
|
|
if (ELF_R_TYPE(rel->r_info) == R_390_PLT32)
|
|
|
|
|
*(unsigned int *) loc = (unsigned int) v;
|
|
|
|
|
else if (ELF_R_TYPE(rel->r_info) == R_390_PLT16DBL)
|
|
|
|
|
*(unsigned short *) loc = (unsigned short) ((v + 2) >> 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_390_GLOB_DAT:
|
|
|
|
|
case R_390_JMP_SLOT:
|
|
|
|
|
*loc = v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_390_RELATIVE:
|
|
|
|
|
*loc += f->baseaddr;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_390_GOTPC:
|
|
|
|
|
*(unsigned long *) loc += got - dot;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_390_GOT12:
|
|
|
|
|
case R_390_GOT16:
|
|
|
|
|
case R_390_GOT32:
|
|
|
|
|
if (!isym->gotent.inited)
|
|
|
|
|
{
|
|
|
|
|
isym->gotent.inited = 1;
|
|
|
|
|
*(ElfW(Addr) *)(ifile->got->contents + isym->gotent.offset) = v;
|
|
|
|
|
}
|
|
|
|
|
if (ELF_R_TYPE(rel->r_info) == R_390_GOT12)
|
|
|
|
|
*(unsigned short *) loc |= (*(unsigned short *) loc + isym->gotent.offset) & 0xfff;
|
|
|
|
|
else if (ELF_R_TYPE(rel->r_info) == R_390_GOT16)
|
|
|
|
|
*(unsigned short *) loc += isym->gotent.offset;
|
|
|
|
|
else if (ELF_R_TYPE(rel->r_info) == R_390_GOT32)
|
|
|
|
|
*(unsigned int *) loc += isym->gotent.offset;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
# ifndef R_390_GOTOFF32
|
|
|
|
|
# define R_390_GOTOFF32 R_390_GOTOFF
|
|
|
|
|
# endif
|
|
|
|
|
case R_390_GOTOFF32:
|
|
|
|
|
*loc += v - got;
|
|
|
|
|
break;
|
|
|
|
|
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#elif defined(__sh__)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_NONE:
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_DIR32:
|
|
|
|
|
*loc += v;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_REL32:
|
|
|
|
|
*loc += v - dot;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_PLT32:
|
|
|
|
|
*loc = v - dot;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_GLOB_DAT:
|
|
|
|
|
case R_SH_JMP_SLOT:
|
|
|
|
|
*loc = v;
|
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_RELATIVE:
|
|
|
|
|
*loc = f->baseaddr + rel->r_addend;
|
|
|
|
|
break;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_GOTPC:
|
|
|
|
|
*loc = got - dot + rel->r_addend;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_GOT32:
|
|
|
|
|
goto bb_use_got;
|
|
|
|
|
|
|
|
|
|
case R_SH_GOTOFF:
|
|
|
|
|
*loc = v - got;
|
|
|
|
|
break;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
# if defined(__SH5__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_IMM_MEDLOW16:
|
|
|
|
|
case R_SH_IMM_LOW16:
|
|
|
|
|
{
|
2005-10-02 07:02:16 +00:00
|
|
|
|
ElfW(Addr) word;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if (ELF_R_TYPE(rel->r_info) == R_SH_IMM_MEDLOW16)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
v >>= 16;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/*
|
|
|
|
|
* movi and shori have the format:
|
|
|
|
|
*
|
|
|
|
|
* | op | imm | reg | reserved |
|
|
|
|
|
* 31..26 25..10 9.. 4 3 .. 0
|
|
|
|
|
*
|
|
|
|
|
* so we simply mask and or in imm.
|
|
|
|
|
*/
|
|
|
|
|
word = *loc & ~0x3fffc00;
|
|
|
|
|
word |= (v & 0xffff) << 10;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
*loc = word;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_SH_IMM_MEDLOW16_PCREL:
|
|
|
|
|
case R_SH_IMM_LOW16_PCREL:
|
|
|
|
|
{
|
2005-10-02 07:02:16 +00:00
|
|
|
|
ElfW(Addr) word;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
word = *loc & ~0x3fffc00;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
v -= dot;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if (ELF_R_TYPE(rel->r_info) == R_SH_IMM_MEDLOW16_PCREL)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
v >>= 16;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
word |= (v & 0xffff) << 10;
|
|
|
|
|
|
|
|
|
|
*loc = word;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-10-02 07:50:49 +00:00
|
|
|
|
# endif /* __SH5__ */
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#elif defined(__v850e__)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case R_V850_NONE:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_V850_32:
|
|
|
|
|
/* We write two shorts instead of a long because even
|
|
|
|
|
32-bit insns only need half-word alignment, but
|
|
|
|
|
32-bit data needs to be long-word aligned. */
|
|
|
|
|
v += ((unsigned short *)loc)[0];
|
|
|
|
|
v += ((unsigned short *)loc)[1] << 16;
|
|
|
|
|
((unsigned short *)loc)[0] = v & 0xffff;
|
|
|
|
|
((unsigned short *)loc)[1] = (v >> 16) & 0xffff;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_V850_22_PCREL:
|
|
|
|
|
goto bb_use_plt;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
#elif defined(__x86_64__)
|
2005-10-02 07:54:07 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
case R_X86_64_NONE:
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
2003-12-04 15:02:57 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
case R_X86_64_64:
|
|
|
|
|
*loc += v;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
2003-12-04 15:02:57 +00:00
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
case R_X86_64_32:
|
|
|
|
|
*(unsigned int *) loc += v;
|
|
|
|
|
if (v > 0xffffffff)
|
|
|
|
|
{
|
|
|
|
|
ret = obj_reloc_overflow; /* Kernel module compiled without -mcmodel=kernel. */
|
|
|
|
|
/* error("Possibly is module compiled without -mcmodel=kernel!"); */
|
|
|
|
|
}
|
2004-05-26 11:38:46 +00:00
|
|
|
|
break;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
|
|
|
|
|
case R_X86_64_32S:
|
|
|
|
|
*(signed int *) loc += v;
|
2004-05-26 11:38:46 +00:00
|
|
|
|
break;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
|
|
|
|
|
case R_X86_64_16:
|
|
|
|
|
*(unsigned short *) loc += v;
|
2004-05-26 11:38:46 +00:00
|
|
|
|
break;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
|
|
|
|
|
case R_X86_64_8:
|
|
|
|
|
*(unsigned char *) loc += v;
|
2004-05-26 11:38:46 +00:00
|
|
|
|
break;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
|
|
|
|
|
case R_X86_64_PC32:
|
|
|
|
|
*(unsigned int *) loc += v - dot;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_X86_64_PC16:
|
|
|
|
|
*(unsigned short *) loc += v - dot;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_X86_64_PC8:
|
|
|
|
|
*(unsigned char *) loc += v - dot;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_X86_64_GLOB_DAT:
|
|
|
|
|
case R_X86_64_JUMP_SLOT:
|
|
|
|
|
*loc = v;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_X86_64_RELATIVE:
|
|
|
|
|
*loc += f->baseaddr;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_X86_64_GOT32:
|
|
|
|
|
case R_X86_64_GOTPCREL:
|
|
|
|
|
goto bb_use_got;
|
|
|
|
|
# if 0
|
|
|
|
|
if (!isym->gotent.reloc_done)
|
|
|
|
|
{
|
|
|
|
|
isym->gotent.reloc_done = 1;
|
|
|
|
|
*(Elf64_Addr *)(ifile->got->contents + isym->gotent.offset) = v;
|
|
|
|
|
}
|
|
|
|
|
/* XXX are these really correct? */
|
|
|
|
|
if (ELF64_R_TYPE(rel->r_info) == R_X86_64_GOTPCREL)
|
|
|
|
|
*(unsigned int *) loc += v + isym->gotent.offset;
|
2005-10-02 07:14:06 +00:00
|
|
|
|
else
|
2005-10-02 07:50:49 +00:00
|
|
|
|
*loc += isym->gotent.offset;
|
2004-05-26 11:38:46 +00:00
|
|
|
|
break;
|
2005-10-02 07:50:49 +00:00
|
|
|
|
# endif
|
|
|
|
|
|
2006-01-04 00:11:26 +00:00
|
|
|
|
#else
|
|
|
|
|
# warning "no idea how to handle relocations on your arch"
|
2004-05-26 11:38:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2005-10-02 07:50:49 +00:00
|
|
|
|
default:
|
|
|
|
|
printf("Warning: unhandled reloc %d\n",(int)ELF_R_TYPE(rel->r_info));
|
|
|
|
|
ret = obj_reloc_unhandled;
|
|
|
|
|
break;
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
bb_use_plt:
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* find the plt entry and initialize it if necessary */
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_LIST)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;)
|
|
|
|
|
pe = pe->next;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#else
|
2003-12-24 20:30:45 +00:00
|
|
|
|
pe = &isym->pltent;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
if (! pe->inited) {
|
|
|
|
|
ip = (unsigned long *) (ifile->plt->contents + pe->offset);
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* generate some machine code */
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
|
|
|
|
#if defined(__arm__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
ip[0] = 0xe51ff004; /* ldr pc,[pc,#-4] */
|
|
|
|
|
ip[1] = v; /* sym@ */
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
|
|
|
|
#if defined(__powerpc__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
ip[0] = 0x3d600000 + ((v + 0x8000) >> 16); /* lis r11,sym@ha */
|
2005-10-02 07:14:06 +00:00
|
|
|
|
ip[1] = 0x396b0000 + (v & 0xffff); /* addi r11,r11,sym@l */
|
2003-12-24 20:30:45 +00:00
|
|
|
|
ip[2] = 0x7d6903a6; /* mtctr r11 */
|
|
|
|
|
ip[3] = 0x4e800420; /* bctr */
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#endif
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#if defined(__v850e__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* We have to trash a register, so we assume that any control
|
|
|
|
|
transfer more than 21-bits away must be a function call
|
|
|
|
|
(so we can use a call-clobbered register). */
|
|
|
|
|
ip[0] = 0x0621 + ((v & 0xffff) << 16); /* mov sym, r1 ... */
|
|
|
|
|
ip[1] = ((v >> 16) & 0xffff) + 0x610000; /* ...; jmp r1 */
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
pe->inited = 1;
|
|
|
|
|
}
|
2000-12-06 18:18:26 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* relative distance to target */
|
|
|
|
|
v -= dot;
|
|
|
|
|
/* if the target is too far away.... */
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#if defined(__arm__) || defined(__powerpc__)
|
2004-03-15 08:29:22 +00:00
|
|
|
|
if ((int)v < -0x02000000 || (int)v >= 0x02000000)
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#elif defined(__v850e__)
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if ((ElfW(Sword))v > 0x1fffff || (ElfW(Sword))v < (ElfW(Sword))-0x200000)
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* go via the plt */
|
|
|
|
|
v = plt + pe->offset - dot;
|
2002-04-01 09:34:25 +00:00
|
|
|
|
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#if defined(__v850e__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
if (v & 1)
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#else
|
2003-12-24 20:30:45 +00:00
|
|
|
|
if (v & 3)
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
ret = obj_reloc_dangerous;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* merge the offset into the instruction. */
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#if defined(__arm__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* Convert to words. */
|
|
|
|
|
v >>= 2;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
*loc = (*loc & ~0x00ffffff) | ((v + *loc) & 0x00ffffff);
|
2000-09-24 03:44:29 +00:00
|
|
|
|
#endif
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#if defined(__powerpc__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
*loc = (*loc & ~0x03fffffc) | (v & 0x03fffffc);
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#if defined(__v850e__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* We write two shorts instead of a long because even 32-bit insns
|
|
|
|
|
only need half-word alignment, but the 32-bit data write needs
|
|
|
|
|
to be long-word aligned. */
|
|
|
|
|
((unsigned short *)loc)[0] =
|
|
|
|
|
(*(unsigned short *)loc & 0xffc0) /* opcode + reg */
|
|
|
|
|
| ((v >> 16) & 0x3f); /* offs high part */
|
|
|
|
|
((unsigned short *)loc)[1] =
|
|
|
|
|
(v & 0xffff); /* offs low part */
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* USE_PLT_ENTRIES */
|
2000-09-24 03:44:29 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
bb_use_got:
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
/* needs an entry in the .got: set it, once */
|
|
|
|
|
if (!isym->gotent.inited) {
|
|
|
|
|
isym->gotent.inited = 1;
|
|
|
|
|
*(ElfW(Addr) *) (ifile->got->contents + isym->gotent.offset) = v;
|
|
|
|
|
}
|
|
|
|
|
/* make the reloc with_respect_to_.got */
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#if defined(__sh__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
*loc += isym->gotent.offset + rel->r_addend;
|
2001-06-19 15:00:52 +00:00
|
|
|
|
#elif defined(__i386__) || defined(__arm__) || defined(__mc68000__)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
*loc += isym->gotent.offset;
|
2000-09-24 03:44:29 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* USE_GOT_ENTRIES */
|
2002-05-24 06:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_LIST)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
|
|
|
|
static int arch_list_add(ElfW(RelM) *rel, struct arch_list_entry **list,
|
|
|
|
|
int offset, int size)
|
|
|
|
|
{
|
|
|
|
|
struct arch_list_entry *pe;
|
|
|
|
|
|
|
|
|
|
for (pe = *list; pe != NULL; pe = pe->next) {
|
|
|
|
|
if (pe->addend == rel->r_addend) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pe == NULL) {
|
|
|
|
|
pe = xmalloc(sizeof(struct arch_list_entry));
|
|
|
|
|
pe->next = *list;
|
|
|
|
|
pe->addend = rel->r_addend;
|
|
|
|
|
pe->offset = offset;
|
|
|
|
|
pe->inited = 0;
|
|
|
|
|
*list = pe;
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 03:44:29 +00:00
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_SINGLE)
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
static int arch_single_init(ElfW(RelM) *rel, struct arch_single_entry *single,
|
|
|
|
|
int offset, int size)
|
|
|
|
|
{
|
|
|
|
|
if (single->allocated == 0) {
|
|
|
|
|
single->allocated = 1;
|
|
|
|
|
single->offset = offset;
|
|
|
|
|
single->inited = 0;
|
|
|
|
|
return size;
|
1999-12-21 02:55:11 +00:00
|
|
|
|
}
|
2002-05-24 06:50:15 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
1999-12-17 18:57:34 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2007-01-29 22:51:25 +00:00
|
|
|
|
static struct obj_section *arch_xsect_init(struct obj_file *f, const char *name,
|
2002-05-24 06:50:15 +00:00
|
|
|
|
int offset, int size)
|
|
|
|
|
{
|
|
|
|
|
struct obj_section *myrelsec = obj_find_section(f, name);
|
|
|
|
|
|
|
|
|
|
if (offset == 0) {
|
|
|
|
|
offset += size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (myrelsec) {
|
|
|
|
|
obj_extend_section(myrelsec, offset);
|
|
|
|
|
} else {
|
2004-03-15 08:29:22 +00:00
|
|
|
|
myrelsec = obj_create_alloced_section(f, name,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
size, offset);
|
2002-05-24 06:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return myrelsec;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
1999-12-21 02:55:11 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static void arch_create_got(struct obj_file *f)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES)
|
2000-09-24 03:44:29 +00:00
|
|
|
|
struct arch_file *ifile = (struct arch_file *) f;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
int i;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
int got_offset = 0, got_needed = 0, got_allocate;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
int plt_offset = 0, plt_needed = 0, plt_allocate;
|
2000-09-24 03:44:29 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
struct obj_section *relsec, *symsec, *strsec;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
ElfW(RelM) *rel, *relend;
|
|
|
|
|
ElfW(Sym) *symtab, *extsym;
|
|
|
|
|
const char *strtab, *name;
|
|
|
|
|
struct arch_symbol *intsym;
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
2000-12-06 18:18:26 +00:00
|
|
|
|
for (i = 0; i < f->header.e_shnum; ++i) {
|
|
|
|
|
relsec = f->sections[i];
|
|
|
|
|
if (relsec->header.sh_type != SHT_RELM)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
continue;
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
2000-12-06 18:18:26 +00:00
|
|
|
|
symsec = f->sections[relsec->header.sh_link];
|
|
|
|
|
strsec = f->sections[symsec->header.sh_link];
|
2000-09-24 03:44:29 +00:00
|
|
|
|
|
2000-12-06 18:18:26 +00:00
|
|
|
|
rel = (ElfW(RelM) *) relsec->contents;
|
|
|
|
|
relend = rel + (relsec->header.sh_size / sizeof(ElfW(RelM)));
|
|
|
|
|
symtab = (ElfW(Sym) *) symsec->contents;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
strtab = (const char *) strsec->contents;
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
for (; rel < relend; ++rel) {
|
2005-10-02 07:02:16 +00:00
|
|
|
|
extsym = &symtab[ELF_R_SYM(rel->r_info)];
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
got_allocate = 0;
|
|
|
|
|
#endif
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
plt_allocate = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-10-02 07:02:16 +00:00
|
|
|
|
switch (ELF_R_TYPE(rel->r_info)) {
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#if defined(__arm__)
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_ARM_PC24:
|
|
|
|
|
case R_ARM_PLT32:
|
|
|
|
|
plt_allocate = 1;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_ARM_GOTOFF:
|
|
|
|
|
case R_ARM_GOTPC:
|
|
|
|
|
got_needed = 1;
|
|
|
|
|
continue;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_ARM_GOT32:
|
|
|
|
|
got_allocate = 1;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#elif defined(__i386__)
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_386_GOTPC:
|
|
|
|
|
case R_386_GOTOFF:
|
|
|
|
|
got_needed = 1;
|
|
|
|
|
continue;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_386_GOT32:
|
|
|
|
|
got_allocate = 1;
|
|
|
|
|
break;
|
2001-02-20 20:47:08 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#elif defined(__powerpc__)
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_PPC_REL24:
|
|
|
|
|
plt_allocate = 1;
|
|
|
|
|
break;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#elif defined(__mc68000__)
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_68K_GOT32:
|
|
|
|
|
got_allocate = 1;
|
|
|
|
|
break;
|
2002-04-01 09:34:25 +00:00
|
|
|
|
|
2004-03-19 12:16:18 +00:00
|
|
|
|
#ifdef R_68K_GOTOFF
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_68K_GOTOFF:
|
|
|
|
|
got_needed = 1;
|
|
|
|
|
continue;
|
2004-03-19 12:16:18 +00:00
|
|
|
|
#endif
|
2000-12-06 18:18:26 +00:00
|
|
|
|
|
|
|
|
|
#elif defined(__sh__)
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_SH_GOT32:
|
|
|
|
|
got_allocate = 1;
|
|
|
|
|
break;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_SH_GOTPC:
|
|
|
|
|
case R_SH_GOTOFF:
|
|
|
|
|
got_needed = 1;
|
|
|
|
|
continue;
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2007-04-10 15:42:06 +00:00
|
|
|
|
#elif defined(__v850e__)
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case R_V850_22_PCREL:
|
|
|
|
|
plt_needed = 1;
|
|
|
|
|
break;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
2006-10-12 20:06:18 +00:00
|
|
|
|
default:
|
|
|
|
|
continue;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
1999-12-21 02:55:11 +00:00
|
|
|
|
|
2000-12-06 18:18:26 +00:00
|
|
|
|
if (extsym->st_name != 0) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
name = strtab + extsym->st_name;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
} else {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
name = f->sections[extsym->st_shndx]->name;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
}
|
|
|
|
|
intsym = (struct arch_symbol *) obj_find_symbol(f, name);
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
if (got_allocate) {
|
|
|
|
|
got_offset += arch_single_init(
|
2004-03-15 08:29:22 +00:00
|
|
|
|
rel, &intsym->gotent,
|
2006-11-21 14:12:53 +00:00
|
|
|
|
got_offset, GOT_ENTRY_SIZE);
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
|
|
|
|
got_needed = 1;
|
2000-12-06 18:18:26 +00:00
|
|
|
|
}
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
if (plt_allocate) {
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_LIST)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
plt_offset += arch_list_add(
|
2004-03-15 08:29:22 +00:00
|
|
|
|
rel, &intsym->pltent,
|
2006-11-21 14:12:53 +00:00
|
|
|
|
plt_offset, PLT_ENTRY_SIZE);
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#else
|
|
|
|
|
plt_offset += arch_single_init(
|
2004-03-15 08:29:22 +00:00
|
|
|
|
rel, &intsym->pltent,
|
2006-11-21 14:12:53 +00:00
|
|
|
|
plt_offset, PLT_ENTRY_SIZE);
|
2002-05-24 06:50:15 +00:00
|
|
|
|
#endif
|
|
|
|
|
plt_needed = 1;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2002-04-01 09:34:25 +00:00
|
|
|
|
}
|
2000-12-06 18:18:26 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
if (got_needed) {
|
|
|
|
|
ifile->got = arch_xsect_init(f, ".got", got_offset,
|
2006-11-21 14:12:53 +00:00
|
|
|
|
GOT_ENTRY_SIZE);
|
1999-12-21 02:55:11 +00:00
|
|
|
|
}
|
2001-02-20 20:47:08 +00:00
|
|
|
|
#endif
|
1999-12-21 02:55:11 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
2002-05-24 06:50:15 +00:00
|
|
|
|
if (plt_needed) {
|
|
|
|
|
ifile->plt = arch_xsect_init(f, ".plt", plt_offset,
|
2006-11-21 14:12:53 +00:00
|
|
|
|
PLT_ENTRY_SIZE);
|
2002-05-24 06:50:15 +00:00
|
|
|
|
}
|
2000-12-06 18:18:26 +00:00
|
|
|
|
#endif
|
2002-05-24 06:50:15 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES) */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
|
|
|
|
|
/* Standard ELF hash function. */
|
2006-08-29 19:41:06 +00:00
|
|
|
|
static unsigned long obj_elf_hash_n(const char *name, unsigned long n)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned long h = 0;
|
|
|
|
|
unsigned long g;
|
|
|
|
|
unsigned char ch;
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
while (n > 0) {
|
|
|
|
|
ch = *name++;
|
|
|
|
|
h = (h << 4) + ch;
|
2007-11-06 02:23:39 +00:00
|
|
|
|
g = (h & 0xf0000000);
|
|
|
|
|
if (g != 0) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
h ^= g >> 24;
|
|
|
|
|
h &= ~g;
|
2000-02-08 19:58:47 +00:00
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
n--;
|
2000-02-08 19:58:47 +00:00
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
return h;
|
|
|
|
|
}
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static unsigned long obj_elf_hash(const char *name)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
return obj_elf_hash_n(name, strlen(name));
|
|
|
|
|
}
|
1999-12-21 02:55:11 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
2000-06-12 23:11:16 +00:00
|
|
|
|
/* String comparison for non-co-versioned kernel and module. */
|
|
|
|
|
|
|
|
|
|
static int ncv_strcmp(const char *a, const char *b)
|
|
|
|
|
{
|
|
|
|
|
size_t alen = strlen(a), blen = strlen(b);
|
|
|
|
|
|
|
|
|
|
if (blen == alen + 10 && b[alen] == '_' && b[alen + 1] == 'R')
|
|
|
|
|
return strncmp(a, b, alen);
|
|
|
|
|
else if (alen == blen + 10 && a[blen] == '_' && a[blen + 1] == 'R')
|
|
|
|
|
return strncmp(a, b, blen);
|
|
|
|
|
else
|
|
|
|
|
return strcmp(a, b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* String hashing for non-co-versioned kernel and module. Here
|
|
|
|
|
we are simply forced to drop the crc from the hash. */
|
|
|
|
|
|
|
|
|
|
static unsigned long ncv_symbol_hash(const char *str)
|
|
|
|
|
{
|
|
|
|
|
size_t len = strlen(str);
|
|
|
|
|
if (len > 10 && str[len - 10] == '_' && str[len - 9] == 'R')
|
|
|
|
|
len -= 10;
|
|
|
|
|
return obj_elf_hash_n(str, len);
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static void
|
2000-06-12 23:11:16 +00:00
|
|
|
|
obj_set_symbol_compare(struct obj_file *f,
|
|
|
|
|
int (*cmp) (const char *, const char *),
|
|
|
|
|
unsigned long (*hash) (const char *))
|
|
|
|
|
{
|
|
|
|
|
if (cmp)
|
|
|
|
|
f->symbol_cmp = cmp;
|
|
|
|
|
if (hash) {
|
|
|
|
|
struct obj_symbol *tmptab[HASH_BUCKETS], *sym, *next;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
f->symbol_hash = hash;
|
|
|
|
|
|
|
|
|
|
memcpy(tmptab, f->symtab, sizeof(tmptab));
|
|
|
|
|
memset(f->symtab, 0, sizeof(f->symtab));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < HASH_BUCKETS; ++i)
|
|
|
|
|
for (sym = tmptab[i]; sym; sym = next) {
|
|
|
|
|
unsigned long h = hash(sym->name) % HASH_BUCKETS;
|
|
|
|
|
next = sym->next;
|
|
|
|
|
sym->next = f->symtab[h];
|
|
|
|
|
f->symtab[h] = sym;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_INSMOD_VERSION_CHECKING */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_symbol *
|
|
|
|
|
obj_add_symbol(struct obj_file *f, const char *name,
|
2006-10-12 20:06:18 +00:00
|
|
|
|
unsigned long symidx, int info,
|
|
|
|
|
int secidx, ElfW(Addr) value,
|
|
|
|
|
unsigned long size)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS;
|
2005-10-02 07:02:16 +00:00
|
|
|
|
int n_type = ELF_ST_TYPE(info);
|
|
|
|
|
int n_binding = ELF_ST_BIND(info);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
for (sym = f->symtab[hash]; sym; sym = sym->next)
|
|
|
|
|
if (f->symbol_cmp(sym->name, name) == 0) {
|
|
|
|
|
int o_secidx = sym->secidx;
|
|
|
|
|
int o_info = sym->info;
|
2005-10-02 07:02:16 +00:00
|
|
|
|
int o_type = ELF_ST_TYPE(o_info);
|
|
|
|
|
int o_binding = ELF_ST_BIND(o_info);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* A redefinition! Is it legal? */
|
|
|
|
|
|
|
|
|
|
if (secidx == SHN_UNDEF)
|
|
|
|
|
return sym;
|
|
|
|
|
else if (o_secidx == SHN_UNDEF)
|
|
|
|
|
goto found;
|
|
|
|
|
else if (n_binding == STB_GLOBAL && o_binding == STB_LOCAL) {
|
|
|
|
|
/* Cope with local and global symbols of the same name
|
|
|
|
|
in the same object file, as might have been created
|
|
|
|
|
by ld -r. The only reason locals are now seen at this
|
|
|
|
|
level at all is so that we can do semi-sensible things
|
|
|
|
|
with parameters. */
|
|
|
|
|
|
|
|
|
|
struct obj_symbol *nsym, **p;
|
|
|
|
|
|
|
|
|
|
nsym = arch_new_symbol();
|
|
|
|
|
nsym->next = sym->next;
|
|
|
|
|
nsym->ksymidx = -1;
|
|
|
|
|
|
|
|
|
|
/* Excise the old (local) symbol from the hash chain. */
|
|
|
|
|
for (p = &f->symtab[hash]; *p != sym; p = &(*p)->next)
|
|
|
|
|
continue;
|
|
|
|
|
*p = sym = nsym;
|
|
|
|
|
goto found;
|
|
|
|
|
} else if (n_binding == STB_LOCAL) {
|
|
|
|
|
/* Another symbol of the same name has already been defined.
|
|
|
|
|
Just add this to the local table. */
|
|
|
|
|
sym = arch_new_symbol();
|
|
|
|
|
sym->next = NULL;
|
|
|
|
|
sym->ksymidx = -1;
|
|
|
|
|
f->local_symtab[symidx] = sym;
|
|
|
|
|
goto found;
|
|
|
|
|
} else if (n_binding == STB_WEAK)
|
|
|
|
|
return sym;
|
|
|
|
|
else if (o_binding == STB_WEAK)
|
|
|
|
|
goto found;
|
|
|
|
|
/* Don't unify COMMON symbols with object types the programmer
|
|
|
|
|
doesn't expect. */
|
|
|
|
|
else if (secidx == SHN_COMMON
|
2003-12-24 20:30:45 +00:00
|
|
|
|
&& (o_type == STT_NOTYPE || o_type == STT_OBJECT))
|
2000-06-12 23:11:16 +00:00
|
|
|
|
return sym;
|
|
|
|
|
else if (o_secidx == SHN_COMMON
|
2003-12-24 20:30:45 +00:00
|
|
|
|
&& (n_type == STT_NOTYPE || n_type == STT_OBJECT))
|
2000-06-12 23:11:16 +00:00
|
|
|
|
goto found;
|
|
|
|
|
else {
|
|
|
|
|
/* Don't report an error if the symbol is coming from
|
|
|
|
|
the kernel or some external module. */
|
|
|
|
|
if (secidx <= SHN_HIRESERVE)
|
2003-03-19 09:13:01 +00:00
|
|
|
|
bb_error_msg("%s multiply defined", name);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
return sym;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Completely new symbol. */
|
|
|
|
|
sym = arch_new_symbol();
|
|
|
|
|
sym->next = f->symtab[hash];
|
|
|
|
|
f->symtab[hash] = sym;
|
|
|
|
|
sym->ksymidx = -1;
|
|
|
|
|
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if (ELF_ST_BIND(info) == STB_LOCAL && symidx != -1) {
|
2001-06-28 21:36:06 +00:00
|
|
|
|
if (symidx >= f->local_symtab_size)
|
2003-03-19 09:13:01 +00:00
|
|
|
|
bb_error_msg("local symbol %s with index %ld exceeds local_symtab_size %ld",
|
2001-06-28 21:36:06 +00:00
|
|
|
|
name, (long) symidx, (long) f->local_symtab_size);
|
|
|
|
|
else
|
|
|
|
|
f->local_symtab[symidx] = sym;
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
found:
|
2000-06-12 23:11:16 +00:00
|
|
|
|
sym->name = name;
|
|
|
|
|
sym->value = value;
|
|
|
|
|
sym->size = size;
|
|
|
|
|
sym->secidx = secidx;
|
|
|
|
|
sym->info = info;
|
|
|
|
|
|
|
|
|
|
return sym;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_symbol *
|
|
|
|
|
obj_find_symbol(struct obj_file *f, const char *name)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS;
|
|
|
|
|
|
|
|
|
|
for (sym = f->symtab[hash]; sym; sym = sym->next)
|
|
|
|
|
if (f->symbol_cmp(sym->name, name) == 0)
|
|
|
|
|
return sym;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
static ElfW(Addr) obj_symbol_final_value(struct obj_file * f, struct obj_symbol * sym)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
if (sym) {
|
|
|
|
|
if (sym->secidx >= SHN_LORESERVE)
|
|
|
|
|
return sym->value;
|
|
|
|
|
|
|
|
|
|
return sym->value + f->sections[sym->secidx]->header.sh_addr;
|
|
|
|
|
} else {
|
|
|
|
|
/* As a special case, a NULL sym has value zero. */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_section *obj_find_section(struct obj_file *f, const char *name)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
int i, n = f->header.e_shnum;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
|
if (strcmp(f->sections[i]->name, name) == 0)
|
|
|
|
|
return f->sections[i];
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int obj_load_order_prio(struct obj_section *a)
|
|
|
|
|
{
|
|
|
|
|
unsigned long af, ac;
|
|
|
|
|
|
|
|
|
|
af = a->header.sh_flags;
|
|
|
|
|
|
|
|
|
|
ac = 0;
|
|
|
|
|
if (a->name[0] != '.' || strlen(a->name) != 10 ||
|
2003-12-24 20:30:45 +00:00
|
|
|
|
strcmp(a->name + 5, ".init"))
|
2000-06-12 23:11:16 +00:00
|
|
|
|
ac |= 32;
|
|
|
|
|
if (af & SHF_ALLOC)
|
|
|
|
|
ac |= 16;
|
|
|
|
|
if (!(af & SHF_WRITE))
|
|
|
|
|
ac |= 8;
|
|
|
|
|
if (af & SHF_EXECINSTR)
|
|
|
|
|
ac |= 4;
|
|
|
|
|
if (a->header.sh_type != SHT_NOBITS)
|
|
|
|
|
ac |= 2;
|
|
|
|
|
|
|
|
|
|
return ac;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static void
|
2000-06-12 23:11:16 +00:00
|
|
|
|
obj_insert_section_load_order(struct obj_file *f, struct obj_section *sec)
|
|
|
|
|
{
|
|
|
|
|
struct obj_section **p;
|
|
|
|
|
int prio = obj_load_order_prio(sec);
|
|
|
|
|
for (p = f->load_order_search_start; *p; p = &(*p)->load_next)
|
|
|
|
|
if (obj_load_order_prio(*p) < prio)
|
|
|
|
|
break;
|
|
|
|
|
sec->load_next = *p;
|
|
|
|
|
*p = sec;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_section *obj_create_alloced_section(struct obj_file *f,
|
2006-10-12 20:06:18 +00:00
|
|
|
|
const char *name,
|
|
|
|
|
unsigned long align,
|
|
|
|
|
unsigned long size)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
int newidx = f->header.e_shnum++;
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
|
|
|
|
|
f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec));
|
|
|
|
|
f->sections[newidx] = sec = arch_new_section();
|
|
|
|
|
|
|
|
|
|
sec->header.sh_type = SHT_PROGBITS;
|
|
|
|
|
sec->header.sh_flags = SHF_WRITE | SHF_ALLOC;
|
|
|
|
|
sec->header.sh_size = size;
|
|
|
|
|
sec->header.sh_addralign = align;
|
|
|
|
|
sec->name = name;
|
|
|
|
|
sec->idx = newidx;
|
|
|
|
|
if (size)
|
|
|
|
|
sec->contents = xmalloc(size);
|
|
|
|
|
|
|
|
|
|
obj_insert_section_load_order(f, sec);
|
|
|
|
|
|
|
|
|
|
return sec;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_section *obj_create_alloced_section_first(struct obj_file *f,
|
2006-10-12 20:06:18 +00:00
|
|
|
|
const char *name,
|
|
|
|
|
unsigned long align,
|
|
|
|
|
unsigned long size)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
int newidx = f->header.e_shnum++;
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
|
|
|
|
|
f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec));
|
|
|
|
|
f->sections[newidx] = sec = arch_new_section();
|
|
|
|
|
|
|
|
|
|
sec->header.sh_type = SHT_PROGBITS;
|
|
|
|
|
sec->header.sh_flags = SHF_WRITE | SHF_ALLOC;
|
|
|
|
|
sec->header.sh_size = size;
|
|
|
|
|
sec->header.sh_addralign = align;
|
|
|
|
|
sec->name = name;
|
|
|
|
|
sec->idx = newidx;
|
|
|
|
|
if (size)
|
|
|
|
|
sec->contents = xmalloc(size);
|
|
|
|
|
|
|
|
|
|
sec->load_next = f->load_order;
|
|
|
|
|
f->load_order = sec;
|
|
|
|
|
if (f->load_order_search_start == &f->load_order)
|
|
|
|
|
f->load_order_search_start = &sec->load_next;
|
|
|
|
|
|
|
|
|
|
return sec;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static void *obj_extend_section(struct obj_section *sec, unsigned long more)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned long oldsize = sec->header.sh_size;
|
2004-03-15 08:29:22 +00:00
|
|
|
|
if (more) {
|
2001-04-26 19:29:58 +00:00
|
|
|
|
sec->contents = xrealloc(sec->contents, sec->header.sh_size += more);
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
return sec->contents + oldsize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Conditionally add the symbols from the given symbol set to the
|
|
|
|
|
new module. */
|
|
|
|
|
|
|
|
|
|
static int
|
2004-06-22 11:50:52 +00:00
|
|
|
|
add_symbols_from( struct obj_file *f,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
int idx, struct new_module_symbol *syms, size_t nsyms)
|
|
|
|
|
{
|
|
|
|
|
struct new_module_symbol *s;
|
|
|
|
|
size_t i;
|
|
|
|
|
int used = 0;
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#ifdef SYMBOL_PREFIX
|
|
|
|
|
char *name_buf = 0;
|
|
|
|
|
size_t name_alloced_size = 0;
|
|
|
|
|
#endif
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
|
2003-09-03 00:42:58 +00:00
|
|
|
|
int gpl;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2003-08-30 06:00:33 +00:00
|
|
|
|
gpl = obj_gpl_license(f, NULL) == 0;
|
2003-09-03 00:42:58 +00:00
|
|
|
|
#endif
|
2000-06-12 23:11:16 +00:00
|
|
|
|
for (i = 0, s = syms; i < nsyms; ++i, ++s) {
|
2002-04-01 09:34:25 +00:00
|
|
|
|
/* Only add symbols that are already marked external.
|
|
|
|
|
If we override locals we may cause problems for
|
|
|
|
|
argument initialization. We will also create a false
|
|
|
|
|
dependency on the module. */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_symbol *sym;
|
2003-08-31 01:58:18 +00:00
|
|
|
|
char *name;
|
2002-04-01 09:34:25 +00:00
|
|
|
|
|
2003-08-30 06:00:33 +00:00
|
|
|
|
/* GPL licensed modules can use symbols exported with
|
|
|
|
|
* EXPORT_SYMBOL_GPL, so ignore any GPLONLY_ prefix on the
|
|
|
|
|
* exported names. Non-GPL modules never see any GPLONLY_
|
|
|
|
|
* symbols so they cannot fudge it by adding the prefix on
|
|
|
|
|
* their references.
|
|
|
|
|
*/
|
|
|
|
|
if (strncmp((char *)s->name, "GPLONLY_", 8) == 0) {
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
|
2003-08-30 06:00:33 +00:00
|
|
|
|
if (gpl)
|
2004-08-28 00:43:07 +00:00
|
|
|
|
s->name += 8;
|
2003-08-30 06:00:33 +00:00
|
|
|
|
else
|
2003-09-03 00:42:58 +00:00
|
|
|
|
#endif
|
2003-08-30 06:00:33 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2003-08-31 01:58:18 +00:00
|
|
|
|
name = (char *)s->name;
|
2003-08-30 06:00:33 +00:00
|
|
|
|
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#ifdef SYMBOL_PREFIX
|
|
|
|
|
/* Prepend SYMBOL_PREFIX to the symbol's name (the
|
|
|
|
|
kernel exports `C names', but module object files
|
|
|
|
|
reference `linker names'). */
|
|
|
|
|
size_t extra = sizeof SYMBOL_PREFIX;
|
2007-04-11 17:04:29 +00:00
|
|
|
|
size_t name_size = strlen(name) + extra;
|
2002-04-01 09:34:25 +00:00
|
|
|
|
if (name_size > name_alloced_size) {
|
|
|
|
|
name_alloced_size = name_size * 2;
|
2007-04-11 17:04:29 +00:00
|
|
|
|
name_buf = alloca(name_alloced_size);
|
2002-04-01 09:34:25 +00:00
|
|
|
|
}
|
2007-04-11 17:04:29 +00:00
|
|
|
|
strcpy(name_buf, SYMBOL_PREFIX);
|
|
|
|
|
strcpy(name_buf + extra - 1, name);
|
2002-04-01 09:34:25 +00:00
|
|
|
|
name = name_buf;
|
|
|
|
|
#endif /* SYMBOL_PREFIX */
|
|
|
|
|
|
|
|
|
|
sym = obj_find_symbol(f, name);
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if (sym && !(ELF_ST_BIND(sym->info) == STB_LOCAL)) {
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#ifdef SYMBOL_PREFIX
|
|
|
|
|
/* Put NAME_BUF into more permanent storage. */
|
2007-04-11 17:04:29 +00:00
|
|
|
|
name = xmalloc(name_size);
|
|
|
|
|
strcpy(name, name_buf);
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#endif
|
|
|
|
|
sym = obj_add_symbol(f, name, -1,
|
2005-10-02 07:02:16 +00:00
|
|
|
|
ELF_ST_INFO(STB_GLOBAL,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
STT_NOTYPE),
|
|
|
|
|
idx, s->value, 0);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
/* Did our symbol just get installed? If so, mark the
|
|
|
|
|
module as "used". */
|
|
|
|
|
if (sym->secidx == idx)
|
|
|
|
|
used = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return used;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void add_kernel_symbols(struct obj_file *f)
|
|
|
|
|
{
|
|
|
|
|
struct external_module *m;
|
2000-07-14 16:23:32 +00:00
|
|
|
|
int i, nused = 0;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Add module symbols first. */
|
|
|
|
|
|
2007-04-11 17:04:29 +00:00
|
|
|
|
for (i = 0, m = ext_modules; i < n_ext_modules; ++i, ++m) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (m->nsyms
|
2007-04-11 17:04:29 +00:00
|
|
|
|
&& add_symbols_from(f, SHN_HIRESERVE + 2 + i, m->syms, m->nsyms)
|
|
|
|
|
) {
|
|
|
|
|
m->used = 1;
|
|
|
|
|
++nused;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
n_ext_modules_used = nused;
|
|
|
|
|
|
|
|
|
|
/* And finally the symbols from the kernel proper. */
|
|
|
|
|
|
|
|
|
|
if (nksyms)
|
|
|
|
|
add_symbols_from(f, SHN_HIRESERVE + 1, ksyms, nksyms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *get_modinfo_value(struct obj_file *f, const char *key)
|
|
|
|
|
{
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
char *p, *v, *n, *ep;
|
|
|
|
|
size_t klen = strlen(key);
|
|
|
|
|
|
|
|
|
|
sec = obj_find_section(f, ".modinfo");
|
|
|
|
|
if (sec == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
p = sec->contents;
|
|
|
|
|
ep = p + sec->header.sh_size;
|
|
|
|
|
while (p < ep) {
|
|
|
|
|
v = strchr(p, '=');
|
|
|
|
|
n = strchr(p, '\0');
|
|
|
|
|
if (v) {
|
2000-07-14 16:23:32 +00:00
|
|
|
|
if (p + klen == v && strncmp(p, key, klen) == 0)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
return v + 1;
|
|
|
|
|
} else {
|
2000-07-14 16:23:32 +00:00
|
|
|
|
if (p + klen == n && strcmp(p, key) == 0)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
p = n + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
/* Functions relating to module loading after 2.1.18. */
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void
|
2000-06-12 23:11:16 +00:00
|
|
|
|
new_process_module_arguments(struct obj_file *f, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
while (argc > 0) {
|
2002-04-01 09:34:25 +00:00
|
|
|
|
char *p, *q, *key, *sym_name;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
char *contents, *loc;
|
|
|
|
|
int min, max, n;
|
|
|
|
|
|
|
|
|
|
p = *argv;
|
2007-11-02 23:31:10 +00:00
|
|
|
|
q = strchr(p, '=');
|
|
|
|
|
if (q == NULL) {
|
2000-06-26 11:16:22 +00:00
|
|
|
|
argc--;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
continue;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
key = alloca(q - p + 6);
|
|
|
|
|
memcpy(key, "parm_", 5);
|
|
|
|
|
memcpy(key + 5, p, q - p);
|
|
|
|
|
key[q - p + 5] = 0;
|
|
|
|
|
|
|
|
|
|
p = get_modinfo_value(f, key);
|
|
|
|
|
key += 5;
|
|
|
|
|
if (p == NULL) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("invalid parameter %s", key);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#ifdef SYMBOL_PREFIX
|
2007-04-11 17:04:29 +00:00
|
|
|
|
sym_name = alloca(strlen(key) + sizeof SYMBOL_PREFIX);
|
|
|
|
|
strcpy(sym_name, SYMBOL_PREFIX);
|
|
|
|
|
strcat(sym_name, key);
|
2002-04-01 09:34:25 +00:00
|
|
|
|
#else
|
|
|
|
|
sym_name = key;
|
|
|
|
|
#endif
|
|
|
|
|
sym = obj_find_symbol(f, sym_name);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Also check that the parameter was not resolved from the kernel. */
|
|
|
|
|
if (sym == NULL || sym->secidx > SHN_HIRESERVE) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("symbol for parameter %s not found", key);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isdigit(*p)) {
|
|
|
|
|
min = strtoul(p, &p, 10);
|
|
|
|
|
if (*p == '-')
|
|
|
|
|
max = strtoul(p + 1, &p, 10);
|
|
|
|
|
else
|
|
|
|
|
max = min;
|
|
|
|
|
} else
|
|
|
|
|
min = max = 1;
|
|
|
|
|
|
|
|
|
|
contents = f->sections[sym->secidx]->contents;
|
|
|
|
|
loc = contents + sym->value;
|
|
|
|
|
n = (*++q != '\0');
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
if ((*p == 's') || (*p == 'c')) {
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
/* Do C quoting if we begin with a ", else slurp the lot. */
|
|
|
|
|
if (*q == '"') {
|
|
|
|
|
char *r;
|
|
|
|
|
|
|
|
|
|
str = alloca(strlen(q));
|
|
|
|
|
for (r = str, q++; *q != '"'; ++q, ++r) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
if (*q == '\0')
|
|
|
|
|
bb_error_msg_and_die("improperly terminated string argument for %s",
|
2000-06-12 23:11:16 +00:00
|
|
|
|
key);
|
2007-11-02 23:31:10 +00:00
|
|
|
|
if (*q == '\\')
|
2000-06-12 23:11:16 +00:00
|
|
|
|
switch (*++q) {
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case 'a':
|
|
|
|
|
*r = '\a';
|
|
|
|
|
break;
|
|
|
|
|
case 'b':
|
|
|
|
|
*r = '\b';
|
|
|
|
|
break;
|
|
|
|
|
case 'e':
|
|
|
|
|
*r = '\033';
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
*r = '\f';
|
|
|
|
|
break;
|
|
|
|
|
case 'n':
|
|
|
|
|
*r = '\n';
|
|
|
|
|
break;
|
|
|
|
|
case 'r':
|
|
|
|
|
*r = '\r';
|
|
|
|
|
break;
|
|
|
|
|
case 't':
|
|
|
|
|
*r = '\t';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '0':
|
|
|
|
|
case '1':
|
|
|
|
|
case '2':
|
|
|
|
|
case '3':
|
|
|
|
|
case '4':
|
|
|
|
|
case '5':
|
|
|
|
|
case '6':
|
|
|
|
|
case '7':
|
|
|
|
|
{
|
|
|
|
|
int c = *q - '0';
|
|
|
|
|
if (q[1] >= '0' && q[1] <= '7') {
|
|
|
|
|
c = (c * 8) + *++q - '0';
|
|
|
|
|
if (q[1] >= '0' && q[1] <= '7')
|
2000-06-12 23:11:16 +00:00
|
|
|
|
c = (c * 8) + *++q - '0';
|
|
|
|
|
}
|
2006-10-12 20:06:18 +00:00
|
|
|
|
*r = c;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
default:
|
|
|
|
|
*r = *q;
|
|
|
|
|
break;
|
2007-11-02 23:31:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*r = *q;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
*r = '\0';
|
|
|
|
|
++q;
|
|
|
|
|
} else {
|
|
|
|
|
char *r;
|
|
|
|
|
|
|
|
|
|
/* In this case, the string is not quoted. We will break
|
|
|
|
|
it using the coma (like for ints). If the user wants to
|
|
|
|
|
include comas in a string, he just has to quote it */
|
|
|
|
|
|
|
|
|
|
/* Search the next coma */
|
|
|
|
|
r = strchr(q, ',');
|
|
|
|
|
|
|
|
|
|
/* Found ? */
|
|
|
|
|
if (r != (char *) NULL) {
|
|
|
|
|
/* Recopy the current field */
|
|
|
|
|
str = alloca(r - q + 1);
|
|
|
|
|
memcpy(str, q, r - q);
|
|
|
|
|
|
2004-04-14 17:51:38 +00:00
|
|
|
|
/* I don't know if it is useful, as the previous case
|
|
|
|
|
doesn't nul terminate the string ??? */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
str[r - q] = '\0';
|
|
|
|
|
|
|
|
|
|
/* Keep next fields */
|
|
|
|
|
q = r;
|
|
|
|
|
} else {
|
|
|
|
|
/* last string */
|
|
|
|
|
str = q;
|
2007-01-29 22:51:58 +00:00
|
|
|
|
q = (char*)"";
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*p == 's') {
|
|
|
|
|
/* Normal string */
|
|
|
|
|
obj_string_patch(f, sym->secidx, loc - contents, str);
|
|
|
|
|
loc += tgt_sizeof_char_p;
|
|
|
|
|
} else {
|
2007-04-11 17:04:29 +00:00
|
|
|
|
/* Array of chars (in fact, matrix!) */
|
2000-07-14 16:23:32 +00:00
|
|
|
|
unsigned long charssize; /* size of each member */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Get the size of each member */
|
|
|
|
|
/* Probably we should do that outside the loop ? */
|
|
|
|
|
if (!isdigit(*(p + 1))) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("parameter type 'c' for %s must be followed by"
|
2001-01-31 19:00:21 +00:00
|
|
|
|
" the maximum size", key);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
charssize = strtoul(p + 1, (char **) NULL, 10);
|
|
|
|
|
|
|
|
|
|
/* Check length */
|
|
|
|
|
if (strlen(str) >= charssize) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("string too long for %s (max %ld)", key,
|
2000-06-12 23:11:16 +00:00
|
|
|
|
charssize - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy to location */
|
|
|
|
|
strcpy((char *) loc, str);
|
|
|
|
|
loc += charssize;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
long v = strtoul(q, &q, 0);
|
|
|
|
|
switch (*p) {
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case 'b':
|
|
|
|
|
*loc++ = v;
|
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
|
|
|
|
*(short *) loc = v;
|
|
|
|
|
loc += tgt_sizeof_short;
|
|
|
|
|
break;
|
|
|
|
|
case 'i':
|
|
|
|
|
*(int *) loc = v;
|
|
|
|
|
loc += tgt_sizeof_int;
|
|
|
|
|
break;
|
|
|
|
|
case 'l':
|
|
|
|
|
*(long *) loc = v;
|
|
|
|
|
loc += tgt_sizeof_long;
|
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
default:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("unknown parameter type '%c' for %s", *p, key);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-02 23:31:10 +00:00
|
|
|
|
retry_end_of_value:
|
2000-06-12 23:11:16 +00:00
|
|
|
|
switch (*q) {
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case '\0':
|
|
|
|
|
goto end_of_arg;
|
|
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
|
case '\t':
|
|
|
|
|
case '\n':
|
|
|
|
|
case '\r':
|
|
|
|
|
++q;
|
|
|
|
|
goto retry_end_of_value;
|
|
|
|
|
|
|
|
|
|
case ',':
|
|
|
|
|
if (++n > max) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("too many values for %s (max %d)", key, max);
|
2006-10-12 20:06:18 +00:00
|
|
|
|
}
|
|
|
|
|
++q;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("invalid argument syntax for %s", key);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-02 23:31:10 +00:00
|
|
|
|
end_of_arg:
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (n < min) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("too few values for %s (min %d)", key, min);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
argc--;
|
|
|
|
|
argv++;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
2000-06-12 23:11:16 +00:00
|
|
|
|
static int new_is_module_checksummed(struct obj_file *f)
|
|
|
|
|
{
|
|
|
|
|
const char *p = get_modinfo_value(f, "using_checksums");
|
|
|
|
|
if (p)
|
2006-10-08 12:49:22 +00:00
|
|
|
|
return xatoi(p);
|
2007-11-02 23:31:10 +00:00
|
|
|
|
return 0;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the module's kernel version in the canonical integer form. */
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
new_get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
|
|
|
|
|
{
|
|
|
|
|
char *p, *q;
|
|
|
|
|
int a, b, c;
|
|
|
|
|
|
|
|
|
|
p = get_modinfo_value(f, "kernel_version");
|
|
|
|
|
if (p == NULL)
|
|
|
|
|
return -1;
|
2002-06-18 05:16:25 +00:00
|
|
|
|
safe_strncpy(str, p, STRVERSIONLEN);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
a = strtoul(p, &p, 10);
|
|
|
|
|
if (*p != '.')
|
|
|
|
|
return -1;
|
|
|
|
|
b = strtoul(p + 1, &p, 10);
|
|
|
|
|
if (*p != '.')
|
|
|
|
|
return -1;
|
|
|
|
|
c = strtoul(p + 1, &q, 10);
|
|
|
|
|
if (p + 1 == q)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return a << 16 | b << 8 | c;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_INSMOD_VERSION_CHECKING */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Fetch the loaded modules, and all currently exported symbols. */
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void new_get_kernel_symbols(void)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
char *module_names, *mn;
|
|
|
|
|
struct external_module *modules, *m;
|
|
|
|
|
struct new_module_symbol *syms, *s;
|
|
|
|
|
size_t ret, bufsize, nmod, nsyms, i, j;
|
|
|
|
|
|
|
|
|
|
/* Collect the loaded modules. */
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bufsize = 256;
|
|
|
|
|
module_names = xmalloc(bufsize);
|
|
|
|
|
|
|
|
|
|
retry_modules_load:
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (query_module(NULL, QM_MODULES, module_names, bufsize, &ret)) {
|
2001-04-25 17:22:32 +00:00
|
|
|
|
if (errno == ENOSPC && bufsize < ret) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bufsize = ret;
|
|
|
|
|
module_names = xrealloc(module_names, bufsize);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
goto retry_modules_load;
|
|
|
|
|
}
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_perror_msg_and_die("QM_MODULES");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n_ext_modules = nmod = ret;
|
|
|
|
|
|
|
|
|
|
/* Collect the modules' symbols. */
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
if (nmod) {
|
2001-03-12 23:08:34 +00:00
|
|
|
|
ext_modules = modules = xmalloc(nmod * sizeof(*modules));
|
|
|
|
|
memset(modules, 0, nmod * sizeof(*modules));
|
|
|
|
|
for (i = 0, mn = module_names, m = modules;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
i < nmod; ++i, ++m, mn += strlen(mn) + 1) {
|
2001-03-12 23:08:34 +00:00
|
|
|
|
struct new_module_info info;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2001-03-12 23:08:34 +00:00
|
|
|
|
if (query_module(mn, QM_INFO, &info, sizeof(info), &ret)) {
|
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
|
/* The module was removed out from underneath us. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_perror_msg_and_die("query_module: QM_INFO: %s", mn);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bufsize = 1024;
|
|
|
|
|
syms = xmalloc(bufsize);
|
|
|
|
|
retry_mod_sym_load:
|
2001-03-12 23:08:34 +00:00
|
|
|
|
if (query_module(mn, QM_SYMBOLS, syms, bufsize, &ret)) {
|
|
|
|
|
switch (errno) {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case ENOSPC:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bufsize = ret;
|
|
|
|
|
syms = xrealloc(syms, bufsize);
|
2003-12-24 20:30:45 +00:00
|
|
|
|
goto retry_mod_sym_load;
|
|
|
|
|
case ENOENT:
|
|
|
|
|
/* The module was removed out from underneath us. */
|
|
|
|
|
continue;
|
|
|
|
|
default:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_perror_msg_and_die("query_module: QM_SYMBOLS: %s", mn);
|
2001-03-12 23:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nsyms = ret;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2001-03-12 23:08:34 +00:00
|
|
|
|
m->name = mn;
|
|
|
|
|
m->addr = info.addr;
|
|
|
|
|
m->nsyms = nsyms;
|
|
|
|
|
m->syms = syms;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2001-03-12 23:08:34 +00:00
|
|
|
|
for (j = 0, s = syms; j < nsyms; ++j, ++s) {
|
|
|
|
|
s->name += (unsigned long) syms;
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Collect the kernel's symbols. */
|
|
|
|
|
|
|
|
|
|
syms = xmalloc(bufsize = 16 * 1024);
|
2007-11-02 23:31:10 +00:00
|
|
|
|
retry_kern_sym_load:
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) {
|
2001-04-25 17:22:32 +00:00
|
|
|
|
if (errno == ENOSPC && bufsize < ret) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
syms = xrealloc(syms, bufsize = ret);
|
|
|
|
|
goto retry_kern_sym_load;
|
|
|
|
|
}
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_perror_msg_and_die("kernel: QM_SYMBOLS");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
nksyms = nsyms = ret;
|
|
|
|
|
ksyms = syms;
|
|
|
|
|
|
|
|
|
|
for (j = 0, s = syms; j < nsyms; ++j, ++s) {
|
|
|
|
|
s->name += (unsigned long) syms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the kernel symbol checksum version, or zero if not used. */
|
|
|
|
|
|
|
|
|
|
static int new_is_kernel_checksummed(void)
|
|
|
|
|
{
|
|
|
|
|
struct new_module_symbol *s;
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
/* Using_Versions is not the first symbol, but it should be in there. */
|
|
|
|
|
|
|
|
|
|
for (i = 0, s = ksyms; i < nksyms; ++i, ++s)
|
|
|
|
|
if (strcmp((char *) s->name, "Using_Versions") == 0)
|
|
|
|
|
return s->value;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void new_create_this_module(struct obj_file *f, const char *m_name)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
|
|
|
|
|
sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
sizeof(struct new_module));
|
2000-06-12 23:11:16 +00:00
|
|
|
|
memset(sec->contents, 0, sizeof(struct new_module));
|
|
|
|
|
|
2002-04-01 09:34:25 +00:00
|
|
|
|
obj_add_symbol(f, SPFX "__this_module", -1,
|
2005-10-02 07:02:16 +00:00
|
|
|
|
ELF_ST_INFO(STB_LOCAL, STT_OBJECT), sec->idx, 0,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
sizeof(struct new_module));
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
obj_string_patch(f, sec->idx, offsetof(struct new_module, name),
|
2003-12-24 20:30:45 +00:00
|
|
|
|
m_name);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
|
2003-01-23 04:48:34 +00:00
|
|
|
|
/* add an entry to the __ksymtab section, creating it if necessary */
|
|
|
|
|
static void new_add_ksymtab(struct obj_file *f, struct obj_symbol *sym)
|
|
|
|
|
{
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
ElfW(Addr) ofs;
|
|
|
|
|
|
|
|
|
|
/* ensure __ksymtab is allocated, EXPORT_NOSYMBOLS creates a non-alloc section.
|
|
|
|
|
* If __ksymtab is defined but not marked alloc, x out the first character
|
|
|
|
|
* (no obj_delete routine) and create a new __ksymtab with the correct
|
|
|
|
|
* characteristics.
|
|
|
|
|
*/
|
|
|
|
|
sec = obj_find_section(f, "__ksymtab");
|
|
|
|
|
if (sec && !(sec->header.sh_flags & SHF_ALLOC)) {
|
|
|
|
|
*((char *)(sec->name)) = 'x'; /* override const */
|
|
|
|
|
sec = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (!sec)
|
|
|
|
|
sec = obj_create_alloced_section(f, "__ksymtab",
|
2003-12-24 20:30:45 +00:00
|
|
|
|
tgt_sizeof_void_p, 0);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
if (!sec)
|
|
|
|
|
return;
|
|
|
|
|
sec->header.sh_flags |= SHF_ALLOC;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
/* Empty section might be byte-aligned */
|
|
|
|
|
sec->header.sh_addralign = tgt_sizeof_void_p;
|
2003-01-23 04:48:34 +00:00
|
|
|
|
ofs = sec->header.sh_size;
|
|
|
|
|
obj_symbol_patch(f, sec->idx, ofs, sym);
|
|
|
|
|
obj_string_patch(f, sec->idx, ofs + tgt_sizeof_void_p, sym->name);
|
|
|
|
|
obj_extend_section(sec, 2 * tgt_sizeof_char_p);
|
|
|
|
|
}
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
static int new_create_module_ksymtab(struct obj_file *f)
|
|
|
|
|
{
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* We must always add the module references. */
|
|
|
|
|
|
|
|
|
|
if (n_ext_modules_used) {
|
|
|
|
|
struct new_module_ref *dep;
|
|
|
|
|
struct obj_symbol *tm;
|
|
|
|
|
|
|
|
|
|
sec = obj_create_alloced_section(f, ".kmodtab", tgt_sizeof_void_p,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
(sizeof(struct new_module_ref)
|
|
|
|
|
* n_ext_modules_used));
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (!sec)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2002-04-01 09:34:25 +00:00
|
|
|
|
tm = obj_find_symbol(f, SPFX "__this_module");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
dep = (struct new_module_ref *) sec->contents;
|
|
|
|
|
for (i = 0; i < n_ext_modules; ++i)
|
|
|
|
|
if (ext_modules[i].used) {
|
|
|
|
|
dep->dep = ext_modules[i].addr;
|
|
|
|
|
obj_symbol_patch(f, sec->idx,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
(char *) &dep->ref - sec->contents, tm);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
dep->next_ref = 0;
|
|
|
|
|
++dep;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-23 12:32:58 +00:00
|
|
|
|
if (!flag_noexport && !obj_find_section(f, "__ksymtab")) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
size_t nsyms;
|
|
|
|
|
int *loaded;
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
sec = obj_create_alloced_section(f, "__ksymtab", tgt_sizeof_void_p, 0);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* We don't want to export symbols residing in sections that
|
|
|
|
|
aren't loaded. There are a number of these created so that
|
|
|
|
|
we make sure certain module options don't appear twice. */
|
|
|
|
|
|
|
|
|
|
loaded = alloca(sizeof(int) * (i = f->header.e_shnum));
|
|
|
|
|
while (--i >= 0)
|
|
|
|
|
loaded[i] = (f->sections[i]->header.sh_flags & SHF_ALLOC) != 0;
|
|
|
|
|
|
|
|
|
|
for (nsyms = i = 0; i < HASH_BUCKETS; ++i) {
|
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
for (sym = f->symtab[i]; sym; sym = sym->next)
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if (ELF_ST_BIND(sym->info) != STB_LOCAL
|
2003-12-24 20:30:45 +00:00
|
|
|
|
&& sym->secidx <= SHN_HIRESERVE
|
|
|
|
|
&& (sym->secidx >= SHN_LORESERVE
|
|
|
|
|
|| loaded[sym->secidx])) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
ElfW(Addr) ofs = nsyms * 2 * tgt_sizeof_void_p;
|
|
|
|
|
|
|
|
|
|
obj_symbol_patch(f, sec->idx, ofs, sym);
|
|
|
|
|
obj_string_patch(f, sec->idx, ofs + tgt_sizeof_void_p,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
sym->name);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
nsyms++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
obj_extend_section(sec, nsyms * 2 * tgt_sizeof_char_p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2004-06-22 11:50:52 +00:00
|
|
|
|
new_init_module(const char *m_name, struct obj_file *f, unsigned long m_size)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
struct new_module *module;
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
void *image;
|
|
|
|
|
int ret;
|
|
|
|
|
tgt_long m_addr;
|
|
|
|
|
|
|
|
|
|
sec = obj_find_section(f, ".this");
|
2004-03-15 08:29:22 +00:00
|
|
|
|
if (!sec || !sec->contents) {
|
2003-03-19 09:13:01 +00:00
|
|
|
|
bb_perror_msg_and_die("corrupt module %s?",m_name);
|
2001-04-26 19:29:58 +00:00
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
module = (struct new_module *) sec->contents;
|
|
|
|
|
m_addr = sec->header.sh_addr;
|
|
|
|
|
|
|
|
|
|
module->size_of_struct = sizeof(*module);
|
|
|
|
|
module->size = m_size;
|
|
|
|
|
module->flags = flag_autoclean ? NEW_MOD_AUTOCLEAN : 0;
|
|
|
|
|
|
|
|
|
|
sec = obj_find_section(f, "__ksymtab");
|
|
|
|
|
if (sec && sec->header.sh_size) {
|
|
|
|
|
module->syms = sec->header.sh_addr;
|
|
|
|
|
module->nsyms = sec->header.sh_size / (2 * tgt_sizeof_char_p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (n_ext_modules_used) {
|
|
|
|
|
sec = obj_find_section(f, ".kmodtab");
|
|
|
|
|
module->deps = sec->header.sh_addr;
|
|
|
|
|
module->ndeps = n_ext_modules_used;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module->init =
|
2002-04-01 09:34:25 +00:00
|
|
|
|
obj_symbol_final_value(f, obj_find_symbol(f, SPFX "init_module"));
|
2000-06-12 23:11:16 +00:00
|
|
|
|
module->cleanup =
|
2002-04-01 09:34:25 +00:00
|
|
|
|
obj_symbol_final_value(f, obj_find_symbol(f, SPFX "cleanup_module"));
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
sec = obj_find_section(f, "__ex_table");
|
|
|
|
|
if (sec) {
|
|
|
|
|
module->ex_table_start = sec->header.sh_addr;
|
|
|
|
|
module->ex_table_end = sec->header.sh_addr + sec->header.sh_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sec = obj_find_section(f, ".text.init");
|
|
|
|
|
if (sec) {
|
|
|
|
|
module->runsize = sec->header.sh_addr - m_addr;
|
|
|
|
|
}
|
|
|
|
|
sec = obj_find_section(f, ".data.init");
|
|
|
|
|
if (sec) {
|
|
|
|
|
if (!module->runsize ||
|
2003-12-24 20:30:45 +00:00
|
|
|
|
module->runsize > sec->header.sh_addr - m_addr)
|
|
|
|
|
module->runsize = sec->header.sh_addr - m_addr;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
2001-05-21 16:09:18 +00:00
|
|
|
|
sec = obj_find_section(f, ARCHDATA_SEC_NAME);
|
|
|
|
|
if (sec && sec->header.sh_size) {
|
|
|
|
|
module->archdata_start = (void*)sec->header.sh_addr;
|
|
|
|
|
module->archdata_end = module->archdata_start + sec->header.sh_size;
|
|
|
|
|
}
|
|
|
|
|
sec = obj_find_section(f, KALLSYMS_SEC_NAME);
|
|
|
|
|
if (sec && sec->header.sh_size) {
|
|
|
|
|
module->kallsyms_start = (void*)sec->header.sh_addr;
|
|
|
|
|
module->kallsyms_end = module->kallsyms_start + sec->header.sh_size;
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Whew! All of the initialization is complete. Collect the final
|
|
|
|
|
module image and give it to the kernel. */
|
|
|
|
|
|
|
|
|
|
image = xmalloc(m_size);
|
|
|
|
|
obj_create_image(f, image);
|
|
|
|
|
|
2004-06-22 11:50:52 +00:00
|
|
|
|
ret = init_module(m_name, (struct new_module *) image);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (ret)
|
2003-03-19 09:13:01 +00:00
|
|
|
|
bb_perror_msg("init_module: %s", m_name);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
free(image);
|
|
|
|
|
|
|
|
|
|
return ret == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void
|
2000-06-12 23:11:16 +00:00
|
|
|
|
obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
|
|
|
|
|
const char *string)
|
|
|
|
|
{
|
|
|
|
|
struct obj_string_patch *p;
|
|
|
|
|
struct obj_section *strsec;
|
|
|
|
|
size_t len = strlen(string) + 1;
|
|
|
|
|
char *loc;
|
|
|
|
|
|
|
|
|
|
p = xmalloc(sizeof(*p));
|
|
|
|
|
p->next = f->string_patches;
|
|
|
|
|
p->reloc_secidx = secidx;
|
|
|
|
|
p->reloc_offset = offset;
|
|
|
|
|
f->string_patches = p;
|
|
|
|
|
|
|
|
|
|
strsec = obj_find_section(f, ".kstrtab");
|
|
|
|
|
if (strsec == NULL) {
|
|
|
|
|
strsec = obj_create_alloced_section(f, ".kstrtab", 1, len);
|
|
|
|
|
p->string_offset = 0;
|
|
|
|
|
loc = strsec->contents;
|
|
|
|
|
} else {
|
|
|
|
|
p->string_offset = strsec->header.sh_size;
|
|
|
|
|
loc = obj_extend_section(strsec, len);
|
|
|
|
|
}
|
|
|
|
|
memcpy(loc, string, len);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-04 15:43:26 +00:00
|
|
|
|
static void
|
2000-06-12 23:11:16 +00:00
|
|
|
|
obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
|
|
|
|
|
struct obj_symbol *sym)
|
|
|
|
|
{
|
|
|
|
|
struct obj_symbol_patch *p;
|
|
|
|
|
|
|
|
|
|
p = xmalloc(sizeof(*p));
|
|
|
|
|
p->next = f->symbol_patches;
|
|
|
|
|
p->reloc_secidx = secidx;
|
|
|
|
|
p->reloc_offset = offset;
|
|
|
|
|
p->sym = sym;
|
|
|
|
|
f->symbol_patches = p;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void obj_check_undefineds(struct obj_file *f)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
2007-11-02 23:31:10 +00:00
|
|
|
|
unsigned i;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < HASH_BUCKETS; ++i) {
|
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
for (sym = f->symtab[i]; sym; sym = sym->next)
|
|
|
|
|
if (sym->secidx == SHN_UNDEF) {
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if (ELF_ST_BIND(sym->info) == STB_WEAK) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
sym->secidx = SHN_ABS;
|
|
|
|
|
sym->value = 0;
|
|
|
|
|
} else {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
if (!flag_quiet)
|
|
|
|
|
bb_error_msg_and_die("unresolved symbol %s", sym->name);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static void obj_allocate_commons(struct obj_file *f)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
struct common_entry {
|
|
|
|
|
struct common_entry *next;
|
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
} *common_head = NULL;
|
|
|
|
|
|
|
|
|
|
unsigned long i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < HASH_BUCKETS; ++i) {
|
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
for (sym = f->symtab[i]; sym; sym = sym->next)
|
|
|
|
|
if (sym->secidx == SHN_COMMON) {
|
|
|
|
|
/* Collect all COMMON symbols and sort them by size so as to
|
|
|
|
|
minimize space wasted by alignment requirements. */
|
|
|
|
|
{
|
|
|
|
|
struct common_entry **p, *n;
|
|
|
|
|
for (p = &common_head; *p; p = &(*p)->next)
|
|
|
|
|
if (sym->size <= (*p)->sym->size)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
n = alloca(sizeof(*n));
|
|
|
|
|
n->next = *p;
|
|
|
|
|
n->sym = sym;
|
|
|
|
|
*p = n;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < f->local_symtab_size; ++i) {
|
|
|
|
|
struct obj_symbol *sym = f->local_symtab[i];
|
|
|
|
|
if (sym && sym->secidx == SHN_COMMON) {
|
|
|
|
|
struct common_entry **p, *n;
|
|
|
|
|
for (p = &common_head; *p; p = &(*p)->next)
|
|
|
|
|
if (sym == (*p)->sym)
|
|
|
|
|
break;
|
|
|
|
|
else if (sym->size < (*p)->sym->size) {
|
|
|
|
|
n = alloca(sizeof(*n));
|
|
|
|
|
n->next = *p;
|
|
|
|
|
n->sym = sym;
|
|
|
|
|
*p = n;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (common_head) {
|
|
|
|
|
/* Find the bss section. */
|
|
|
|
|
for (i = 0; i < f->header.e_shnum; ++i)
|
|
|
|
|
if (f->sections[i]->header.sh_type == SHT_NOBITS)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* If for some reason there hadn't been one, create one. */
|
|
|
|
|
if (i == f->header.e_shnum) {
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
|
|
|
|
|
f->sections = xrealloc(f->sections, (i + 1) * sizeof(sec));
|
|
|
|
|
f->sections[i] = sec = arch_new_section();
|
|
|
|
|
f->header.e_shnum = i + 1;
|
|
|
|
|
|
|
|
|
|
sec->header.sh_type = SHT_PROGBITS;
|
|
|
|
|
sec->header.sh_flags = SHF_WRITE | SHF_ALLOC;
|
|
|
|
|
sec->name = ".bss";
|
|
|
|
|
sec->idx = i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allocate the COMMONS. */
|
|
|
|
|
{
|
|
|
|
|
ElfW(Addr) bss_size = f->sections[i]->header.sh_size;
|
|
|
|
|
ElfW(Addr) max_align = f->sections[i]->header.sh_addralign;
|
|
|
|
|
struct common_entry *c;
|
|
|
|
|
|
|
|
|
|
for (c = common_head; c; c = c->next) {
|
|
|
|
|
ElfW(Addr) align = c->sym->value;
|
|
|
|
|
|
|
|
|
|
if (align > max_align)
|
|
|
|
|
max_align = align;
|
|
|
|
|
if (bss_size & (align - 1))
|
|
|
|
|
bss_size = (bss_size | (align - 1)) + 1;
|
|
|
|
|
|
|
|
|
|
c->sym->secidx = i;
|
|
|
|
|
c->sym->value = bss_size;
|
|
|
|
|
|
|
|
|
|
bss_size += c->sym->size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f->sections[i]->header.sh_size = bss_size;
|
|
|
|
|
f->sections[i]->header.sh_addralign = max_align;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For the sake of patch relocation and parameter initialization,
|
|
|
|
|
allocate zeroed data for NOBITS sections now. Note that after
|
|
|
|
|
this we cannot assume NOBITS are really empty. */
|
|
|
|
|
for (i = 0; i < f->header.e_shnum; ++i) {
|
|
|
|
|
struct obj_section *s = f->sections[i];
|
|
|
|
|
if (s->header.sh_type == SHT_NOBITS) {
|
2000-12-06 18:18:26 +00:00
|
|
|
|
if (s->header.sh_size != 0)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
s->contents = memset(xmalloc(s->header.sh_size),
|
|
|
|
|
0, s->header.sh_size);
|
2000-12-06 18:18:26 +00:00
|
|
|
|
else
|
|
|
|
|
s->contents = NULL;
|
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
s->header.sh_type = SHT_PROGBITS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static unsigned long obj_load_size(struct obj_file *f)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned long dot = 0;
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
|
|
|
|
|
/* Finalize the positions of the sections relative to one another. */
|
|
|
|
|
|
|
|
|
|
for (sec = f->load_order; sec; sec = sec->load_next) {
|
|
|
|
|
ElfW(Addr) align;
|
|
|
|
|
|
|
|
|
|
align = sec->header.sh_addralign;
|
|
|
|
|
if (align && (dot & (align - 1)))
|
|
|
|
|
dot = (dot | (align - 1)) + 1;
|
|
|
|
|
|
|
|
|
|
sec->header.sh_addr = dot;
|
|
|
|
|
dot += sec->header.sh_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dot;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static int obj_relocate(struct obj_file *f, ElfW(Addr) base)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
int i, n = f->header.e_shnum;
|
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
|
|
/* Finalize the addresses of the sections. */
|
|
|
|
|
|
|
|
|
|
f->baseaddr = base;
|
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
|
f->sections[i]->header.sh_addr += base;
|
|
|
|
|
|
|
|
|
|
/* And iterate over all of the relocations. */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
|
struct obj_section *relsec, *symsec, *targsec, *strsec;
|
|
|
|
|
ElfW(RelM) * rel, *relend;
|
|
|
|
|
ElfW(Sym) * symtab;
|
|
|
|
|
const char *strtab;
|
|
|
|
|
|
|
|
|
|
relsec = f->sections[i];
|
|
|
|
|
if (relsec->header.sh_type != SHT_RELM)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
symsec = f->sections[relsec->header.sh_link];
|
|
|
|
|
targsec = f->sections[relsec->header.sh_info];
|
|
|
|
|
strsec = f->sections[symsec->header.sh_link];
|
|
|
|
|
|
|
|
|
|
rel = (ElfW(RelM) *) relsec->contents;
|
|
|
|
|
relend = rel + (relsec->header.sh_size / sizeof(ElfW(RelM)));
|
|
|
|
|
symtab = (ElfW(Sym) *) symsec->contents;
|
|
|
|
|
strtab = (const char *) strsec->contents;
|
|
|
|
|
|
|
|
|
|
for (; rel < relend; ++rel) {
|
|
|
|
|
ElfW(Addr) value = 0;
|
|
|
|
|
struct obj_symbol *intsym = NULL;
|
|
|
|
|
unsigned long symndx;
|
|
|
|
|
ElfW(Sym) * extsym = 0;
|
|
|
|
|
const char *errmsg;
|
|
|
|
|
|
|
|
|
|
/* Attempt to find a value to use for this relocation. */
|
|
|
|
|
|
2005-10-02 07:02:16 +00:00
|
|
|
|
symndx = ELF_R_SYM(rel->r_info);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (symndx) {
|
|
|
|
|
/* Note we've already checked for undefined symbols. */
|
|
|
|
|
|
|
|
|
|
extsym = &symtab[symndx];
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if (ELF_ST_BIND(extsym->st_info) == STB_LOCAL) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
/* Local symbols we look up in the local table to be sure
|
|
|
|
|
we get the one that is really intended. */
|
|
|
|
|
intsym = f->local_symtab[symndx];
|
|
|
|
|
} else {
|
|
|
|
|
/* Others we look up in the hash table. */
|
|
|
|
|
const char *name;
|
|
|
|
|
if (extsym->st_name)
|
|
|
|
|
name = strtab + extsym->st_name;
|
|
|
|
|
else
|
|
|
|
|
name = f->sections[extsym->st_shndx]->name;
|
|
|
|
|
intsym = obj_find_symbol(f, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value = obj_symbol_final_value(f, intsym);
|
|
|
|
|
intsym->referenced = 1;
|
|
|
|
|
}
|
|
|
|
|
#if SHT_RELM == SHT_RELA
|
|
|
|
|
#if defined(__alpha__) && defined(AXP_BROKEN_GAS)
|
|
|
|
|
/* Work around a nasty GAS bug, that is fixed as of 2.7.0.9. */
|
|
|
|
|
if (!extsym || !extsym->st_name ||
|
2005-10-02 07:02:16 +00:00
|
|
|
|
ELF_ST_BIND(extsym->st_info) != STB_LOCAL)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#endif
|
|
|
|
|
value += rel->r_addend;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Do it! */
|
|
|
|
|
switch (arch_apply_relocation
|
2006-10-12 20:06:18 +00:00
|
|
|
|
(f, targsec, symsec, intsym, rel, value)
|
|
|
|
|
) {
|
|
|
|
|
case obj_reloc_ok:
|
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case obj_reloc_overflow:
|
|
|
|
|
errmsg = "Relocation overflow";
|
|
|
|
|
goto bad_reloc;
|
|
|
|
|
case obj_reloc_dangerous:
|
|
|
|
|
errmsg = "Dangerous relocation";
|
|
|
|
|
goto bad_reloc;
|
|
|
|
|
case obj_reloc_unhandled:
|
|
|
|
|
errmsg = "Unhandled relocation";
|
2003-12-24 20:30:45 +00:00
|
|
|
|
bad_reloc:
|
2006-10-12 20:06:18 +00:00
|
|
|
|
if (extsym) {
|
|
|
|
|
bb_error_msg("%s of type %ld for %s", errmsg,
|
|
|
|
|
(long) ELF_R_TYPE(rel->r_info),
|
|
|
|
|
strtab + extsym->st_name);
|
|
|
|
|
} else {
|
|
|
|
|
bb_error_msg("%s of type %ld", errmsg,
|
|
|
|
|
(long) ELF_R_TYPE(rel->r_info));
|
|
|
|
|
}
|
|
|
|
|
ret = 0;
|
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Finally, take care of the patches. */
|
|
|
|
|
|
|
|
|
|
if (f->string_patches) {
|
|
|
|
|
struct obj_string_patch *p;
|
|
|
|
|
struct obj_section *strsec;
|
|
|
|
|
ElfW(Addr) strsec_base;
|
|
|
|
|
strsec = obj_find_section(f, ".kstrtab");
|
|
|
|
|
strsec_base = strsec->header.sh_addr;
|
|
|
|
|
|
|
|
|
|
for (p = f->string_patches; p; p = p->next) {
|
|
|
|
|
struct obj_section *targsec = f->sections[p->reloc_secidx];
|
|
|
|
|
*(ElfW(Addr) *) (targsec->contents + p->reloc_offset)
|
|
|
|
|
= strsec_base + p->string_offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f->symbol_patches) {
|
|
|
|
|
struct obj_symbol_patch *p;
|
|
|
|
|
|
|
|
|
|
for (p = f->symbol_patches; p; p = p->next) {
|
|
|
|
|
struct obj_section *targsec = f->sections[p->reloc_secidx];
|
|
|
|
|
*(ElfW(Addr) *) (targsec->contents + p->reloc_offset)
|
|
|
|
|
= obj_symbol_final_value(f, p->sym);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static int obj_create_image(struct obj_file *f, char *image)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
ElfW(Addr) base = f->baseaddr;
|
|
|
|
|
|
|
|
|
|
for (sec = f->load_order; sec; sec = sec->load_next) {
|
|
|
|
|
char *secimg;
|
|
|
|
|
|
2001-02-24 20:01:53 +00:00
|
|
|
|
if (sec->contents == 0 || sec->header.sh_size == 0)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
secimg = image + (sec->header.sh_addr - base);
|
|
|
|
|
|
|
|
|
|
/* Note that we allocated data for NOBITS sections earlier. */
|
|
|
|
|
memcpy(secimg, sec->contents, sec->header.sh_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
|
2001-07-17 01:12:36 +00:00
|
|
|
|
static struct obj_file *obj_load(FILE * fp, int loadprogbits)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
|
|
|
|
struct obj_file *f;
|
|
|
|
|
ElfW(Shdr) * section_headers;
|
|
|
|
|
int shnum, i;
|
|
|
|
|
char *shstrtab;
|
|
|
|
|
|
|
|
|
|
/* Read the file header. */
|
|
|
|
|
|
|
|
|
|
f = arch_new_file();
|
|
|
|
|
f->symbol_cmp = strcmp;
|
|
|
|
|
f->symbol_hash = obj_elf_hash;
|
|
|
|
|
f->load_order_search_start = &f->load_order;
|
|
|
|
|
|
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
|
if (fread(&f->header, sizeof(f->header), 1, fp) != 1) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_perror_msg_and_die("error reading ELF header");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f->header.e_ident[EI_MAG0] != ELFMAG0
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|| f->header.e_ident[EI_MAG1] != ELFMAG1
|
|
|
|
|
|| f->header.e_ident[EI_MAG2] != ELFMAG2
|
|
|
|
|
|| f->header.e_ident[EI_MAG3] != ELFMAG3) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("not an ELF file");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
if (f->header.e_ident[EI_CLASS] != ELFCLASSM
|
2006-03-25 02:49:28 +00:00
|
|
|
|
|| f->header.e_ident[EI_DATA] != (BB_BIG_ENDIAN
|
2006-06-03 19:35:15 +00:00
|
|
|
|
? ELFDATA2MSB : ELFDATA2LSB)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|| f->header.e_ident[EI_VERSION] != EV_CURRENT
|
|
|
|
|
|| !MATCH_MACHINE(f->header.e_machine)) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("ELF file not for this architecture");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
if (f->header.e_type != ET_REL) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("ELF file not a relocatable object");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read the section headers. */
|
|
|
|
|
|
|
|
|
|
if (f->header.e_shentsize != sizeof(ElfW(Shdr))) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("section header size mismatch: %lu != %lu",
|
2000-06-12 23:11:16 +00:00
|
|
|
|
(unsigned long) f->header.e_shentsize,
|
|
|
|
|
(unsigned long) sizeof(ElfW(Shdr)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shnum = f->header.e_shnum;
|
|
|
|
|
f->sections = xmalloc(sizeof(struct obj_section *) * shnum);
|
|
|
|
|
memset(f->sections, 0, sizeof(struct obj_section *) * shnum);
|
|
|
|
|
|
|
|
|
|
section_headers = alloca(sizeof(ElfW(Shdr)) * shnum);
|
|
|
|
|
fseek(fp, f->header.e_shoff, SEEK_SET);
|
|
|
|
|
if (fread(section_headers, sizeof(ElfW(Shdr)), shnum, fp) != shnum) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_perror_msg_and_die("error reading ELF section headers");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read the section data. */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < shnum; ++i) {
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
|
|
|
|
|
f->sections[i] = sec = arch_new_section();
|
|
|
|
|
|
|
|
|
|
sec->header = section_headers[i];
|
|
|
|
|
sec->idx = i;
|
|
|
|
|
|
2007-04-12 00:32:05 +00:00
|
|
|
|
if (sec->header.sh_size) {
|
2006-10-12 20:06:18 +00:00
|
|
|
|
switch (sec->header.sh_type) {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case SHT_NULL:
|
|
|
|
|
case SHT_NOTE:
|
|
|
|
|
case SHT_NOBITS:
|
|
|
|
|
/* ignore */
|
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case SHT_PROGBITS:
|
2001-05-21 16:09:18 +00:00
|
|
|
|
#if LOADBITS
|
2003-12-24 20:30:45 +00:00
|
|
|
|
if (!loadprogbits) {
|
|
|
|
|
sec->contents = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-03-15 08:29:22 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case SHT_SYMTAB:
|
|
|
|
|
case SHT_STRTAB:
|
|
|
|
|
case SHT_RELM:
|
|
|
|
|
if (sec->header.sh_size > 0) {
|
|
|
|
|
sec->contents = xmalloc(sec->header.sh_size);
|
|
|
|
|
fseek(fp, sec->header.sh_offset, SEEK_SET);
|
|
|
|
|
if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_perror_msg_and_die("error reading ELF section data");
|
2003-12-24 20:30:45 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
sec->contents = NULL;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
2003-12-24 20:30:45 +00:00
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
#if SHT_RELM == SHT_REL
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case SHT_RELA:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("RELA relocations not supported on this architecture");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#else
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case SHT_REL:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("REL relocations not supported on this architecture");
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
default:
|
|
|
|
|
if (sec->header.sh_type >= SHT_LOPROC) {
|
|
|
|
|
/* Assume processor specific section types are debug
|
|
|
|
|
info and can safely be ignored. If this is ever not
|
|
|
|
|
the case (Hello MIPS?), don't put ifdefs here but
|
|
|
|
|
create an arch_load_proc_section(). */
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("can't handle sections of type %ld",
|
2003-12-24 20:30:45 +00:00
|
|
|
|
(long) sec->header.sh_type);
|
2006-10-12 20:06:18 +00:00
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Do what sort of interpretation as needed by each section. */
|
|
|
|
|
|
|
|
|
|
shstrtab = f->sections[f->header.e_shstrndx]->contents;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < shnum; ++i) {
|
|
|
|
|
struct obj_section *sec = f->sections[i];
|
|
|
|
|
sec->name = shstrtab + sec->header.sh_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < shnum; ++i) {
|
|
|
|
|
struct obj_section *sec = f->sections[i];
|
|
|
|
|
|
2001-04-25 17:22:32 +00:00
|
|
|
|
/* .modinfo should be contents only but gcc has no attribute for that.
|
|
|
|
|
* The kernel may have marked .modinfo as ALLOC, ignore this bit.
|
|
|
|
|
*/
|
|
|
|
|
if (strcmp(sec->name, ".modinfo") == 0)
|
|
|
|
|
sec->header.sh_flags &= ~SHF_ALLOC;
|
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (sec->header.sh_flags & SHF_ALLOC)
|
|
|
|
|
obj_insert_section_load_order(f, sec);
|
|
|
|
|
|
|
|
|
|
switch (sec->header.sh_type) {
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case SHT_SYMTAB:
|
|
|
|
|
{
|
|
|
|
|
unsigned long nsym, j;
|
|
|
|
|
char *strtab;
|
|
|
|
|
ElfW(Sym) * sym;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
if (sec->header.sh_entsize != sizeof(ElfW(Sym))) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("symbol size mismatch: %lu != %lu",
|
2006-10-12 20:06:18 +00:00
|
|
|
|
(unsigned long) sec->header.sh_entsize,
|
|
|
|
|
(unsigned long) sizeof(ElfW(Sym)));
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
nsym = sec->header.sh_size / sizeof(ElfW(Sym));
|
|
|
|
|
strtab = f->sections[sec->header.sh_link]->contents;
|
|
|
|
|
sym = (ElfW(Sym) *) sec->contents;
|
|
|
|
|
|
|
|
|
|
/* Allocate space for a table of local symbols. */
|
|
|
|
|
j = f->local_symtab_size = sec->header.sh_info;
|
|
|
|
|
f->local_symtab = xzalloc(j * sizeof(struct obj_symbol *));
|
|
|
|
|
|
|
|
|
|
/* Insert all symbols into the hash table. */
|
|
|
|
|
for (j = 1, ++sym; j < nsym; ++j, ++sym) {
|
|
|
|
|
ElfW(Addr) val = sym->st_value;
|
|
|
|
|
const char *name;
|
|
|
|
|
if (sym->st_name)
|
|
|
|
|
name = strtab + sym->st_name;
|
|
|
|
|
else if (sym->st_shndx < shnum)
|
|
|
|
|
name = f->sections[sym->st_shndx]->name;
|
|
|
|
|
else
|
|
|
|
|
continue;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
#if defined(__SH5__)
|
2006-10-12 20:06:18 +00:00
|
|
|
|
/*
|
|
|
|
|
* For sh64 it is possible that the target of a branch
|
|
|
|
|
* requires a mode switch (32 to 16 and back again).
|
|
|
|
|
*
|
|
|
|
|
* This is implied by the lsb being set in the target
|
|
|
|
|
* address for SHmedia mode and clear for SHcompact.
|
|
|
|
|
*/
|
|
|
|
|
val |= sym->st_other & 4;
|
2003-08-13 19:56:33 +00:00
|
|
|
|
#endif
|
2006-10-12 20:06:18 +00:00
|
|
|
|
obj_add_symbol(f, name, j, sym->st_info, sym->st_shndx,
|
|
|
|
|
val, sym->st_size);
|
2001-04-25 17:22:32 +00:00
|
|
|
|
}
|
2006-10-12 20:06:18 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case SHT_RELM:
|
|
|
|
|
if (sec->header.sh_entsize != sizeof(ElfW(RelM))) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("relocation entry size mismatch: %lu != %lu",
|
2006-10-12 20:06:18 +00:00
|
|
|
|
(unsigned long) sec->header.sh_entsize,
|
|
|
|
|
(unsigned long) sizeof(ElfW(RelM)));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* XXX Relocation code from modutils-2.3.19 is not here.
|
|
|
|
|
* Why? That's about 20 lines of code from obj/obj_load.c,
|
|
|
|
|
* which gets done in a second pass through the sections.
|
|
|
|
|
* This BusyBox insmod does similar work in obj_relocate(). */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_LOADINKMEM
|
2001-05-21 16:09:18 +00:00
|
|
|
|
/*
|
|
|
|
|
* load the unloaded sections directly into the memory allocated by
|
|
|
|
|
* kernel for the module
|
|
|
|
|
*/
|
|
|
|
|
|
2001-08-22 05:26:08 +00:00
|
|
|
|
static int obj_load_progbits(FILE * fp, struct obj_file* f, char* imagebase)
|
2001-05-21 16:09:18 +00:00
|
|
|
|
{
|
|
|
|
|
ElfW(Addr) base = f->baseaddr;
|
|
|
|
|
struct obj_section* sec;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2001-05-21 16:09:18 +00:00
|
|
|
|
for (sec = f->load_order; sec; sec = sec->load_next) {
|
|
|
|
|
|
|
|
|
|
/* section already loaded? */
|
|
|
|
|
if (sec->contents != NULL)
|
|
|
|
|
continue;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2001-05-21 16:09:18 +00:00
|
|
|
|
if (sec->header.sh_size == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
sec->contents = imagebase + (sec->header.sh_addr - base);
|
|
|
|
|
fseek(fp, sec->header.sh_offset, SEEK_SET);
|
|
|
|
|
if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) {
|
2006-09-06 19:02:46 +00:00
|
|
|
|
bb_perror_msg("error reading ELF section data");
|
2001-05-21 16:09:18 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
static void hide_special_symbols(struct obj_file *f)
|
|
|
|
|
{
|
|
|
|
|
static const char *const specials[] = {
|
2002-04-01 09:34:25 +00:00
|
|
|
|
SPFX "cleanup_module",
|
|
|
|
|
SPFX "init_module",
|
|
|
|
|
SPFX "kernel_version",
|
2000-06-12 23:11:16 +00:00
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
const char *const *p;
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
for (p = specials; *p; ++p) {
|
|
|
|
|
sym = obj_find_symbol(f, *p);
|
|
|
|
|
if (sym != NULL)
|
|
|
|
|
sym->info = ELF_ST_INFO(STB_LOCAL, ELF_ST_TYPE(sym->info));
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-30 06:00:33 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
|
2002-09-16 05:30:24 +00:00
|
|
|
|
static int obj_gpl_license(struct obj_file *f, const char **license)
|
|
|
|
|
{
|
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
/* This list must match *exactly* the list of allowable licenses in
|
|
|
|
|
* linux/include/linux/module.h. Checking for leading "GPL" will not
|
|
|
|
|
* work, somebody will use "GPL sucks, this is proprietary".
|
|
|
|
|
*/
|
2007-08-12 20:58:27 +00:00
|
|
|
|
static const char *const gpl_licenses[] = {
|
2002-09-16 05:30:24 +00:00
|
|
|
|
"GPL",
|
|
|
|
|
"GPL v2",
|
|
|
|
|
"GPL and additional rights",
|
|
|
|
|
"Dual BSD/GPL",
|
2007-08-12 20:58:27 +00:00
|
|
|
|
"Dual MPL/GPL"
|
2002-09-16 05:30:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
sec = obj_find_section(f, ".modinfo");
|
|
|
|
|
if (sec) {
|
2002-09-16 05:30:24 +00:00
|
|
|
|
const char *value, *ptr, *endptr;
|
|
|
|
|
ptr = sec->contents;
|
|
|
|
|
endptr = ptr + sec->header.sh_size;
|
|
|
|
|
while (ptr < endptr) {
|
2006-10-12 20:06:18 +00:00
|
|
|
|
value = strchr(ptr, '=');
|
|
|
|
|
if (value && strncmp(ptr, "license", value-ptr) == 0) {
|
2002-09-16 05:30:24 +00:00
|
|
|
|
int i;
|
|
|
|
|
if (license)
|
|
|
|
|
*license = value+1;
|
2007-06-25 10:55:35 +00:00
|
|
|
|
for (i = 0; i < ARRAY_SIZE(gpl_licenses); ++i) {
|
2002-09-16 05:30:24 +00:00
|
|
|
|
if (strcmp(value+1, gpl_licenses[i]) == 0)
|
2006-11-27 16:49:31 +00:00
|
|
|
|
return 0;
|
2002-09-16 05:30:24 +00:00
|
|
|
|
}
|
2006-11-27 16:49:31 +00:00
|
|
|
|
return 2;
|
2002-09-16 05:30:24 +00:00
|
|
|
|
}
|
2007-11-02 23:31:10 +00:00
|
|
|
|
ptr = strchr(ptr, '\0');
|
|
|
|
|
if (ptr)
|
|
|
|
|
ptr++;
|
2002-09-16 05:30:24 +00:00
|
|
|
|
else
|
|
|
|
|
ptr = endptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-11-27 16:49:31 +00:00
|
|
|
|
return 1;
|
2002-09-16 05:30:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define TAINT_FILENAME "/proc/sys/kernel/tainted"
|
2007-11-02 23:31:10 +00:00
|
|
|
|
#define TAINT_PROPRIETORY_MODULE (1 << 0)
|
|
|
|
|
#define TAINT_FORCED_MODULE (1 << 1)
|
|
|
|
|
#define TAINT_UNSAFE_SMP (1 << 2)
|
2005-10-02 07:14:06 +00:00
|
|
|
|
#define TAINT_URL "http://www.tux.org/lkml/#export-tainted"
|
2002-09-16 05:30:24 +00:00
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static void set_tainted(int fd, char *m_name,
|
2002-09-16 05:30:24 +00:00
|
|
|
|
int kernel_has_tainted, int taint, const char *text1, const char *text2)
|
|
|
|
|
{
|
2007-06-21 12:43:45 +00:00
|
|
|
|
static smallint printed_info;
|
|
|
|
|
|
2002-09-16 05:30:24 +00:00
|
|
|
|
char buf[80];
|
|
|
|
|
int oldval;
|
2007-06-21 12:43:45 +00:00
|
|
|
|
|
2002-09-16 05:30:24 +00:00
|
|
|
|
if (fd < 0 && !kernel_has_tainted)
|
|
|
|
|
return; /* New modutils on old kernel */
|
|
|
|
|
printf("Warning: loading %s will taint the kernel: %s%s\n",
|
|
|
|
|
m_name, text1, text2);
|
2007-06-21 12:43:45 +00:00
|
|
|
|
if (!printed_info) {
|
2002-09-16 05:30:24 +00:00
|
|
|
|
printf(" See %s for information about tainted modules\n", TAINT_URL);
|
2007-06-21 12:43:45 +00:00
|
|
|
|
printed_info = 1;
|
2002-09-16 05:30:24 +00:00
|
|
|
|
}
|
|
|
|
|
if (fd >= 0) {
|
|
|
|
|
read(fd, buf, sizeof(buf)-1);
|
|
|
|
|
buf[sizeof(buf)-1] = '\0';
|
|
|
|
|
oldval = strtoul(buf, NULL, 10);
|
|
|
|
|
sprintf(buf, "%d\n", oldval | taint);
|
|
|
|
|
write(fd, buf, strlen(buf));
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2002-09-16 05:30:24 +00:00
|
|
|
|
/* Check if loading this module will taint the kernel. */
|
|
|
|
|
static void check_tainted_module(struct obj_file *f, char *m_name)
|
|
|
|
|
{
|
2007-08-12 20:58:27 +00:00
|
|
|
|
static const char tainted_file[] ALIGN1 = TAINT_FILENAME;
|
|
|
|
|
|
2002-09-16 05:30:24 +00:00
|
|
|
|
int fd, kernel_has_tainted;
|
|
|
|
|
const char *ptr;
|
|
|
|
|
|
|
|
|
|
kernel_has_tainted = 1;
|
2006-10-12 20:06:18 +00:00
|
|
|
|
fd = open(tainted_file, O_RDWR);
|
|
|
|
|
if (fd < 0) {
|
2002-09-16 05:30:24 +00:00
|
|
|
|
if (errno == ENOENT)
|
|
|
|
|
kernel_has_tainted = 0;
|
|
|
|
|
else if (errno == EACCES)
|
|
|
|
|
kernel_has_tainted = 1;
|
|
|
|
|
else {
|
|
|
|
|
perror(tainted_file);
|
|
|
|
|
kernel_has_tainted = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (obj_gpl_license(f, &ptr)) {
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
set_tainted(fd, m_name, kernel_has_tainted, TAINT_PROPRIETORY_MODULE, "no license", "");
|
2002-09-16 05:30:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
/* The module has a non-GPL license so we pretend that the
|
|
|
|
|
* kernel always has a taint flag to get a warning even on
|
|
|
|
|
* kernels without the proc flag.
|
|
|
|
|
*/
|
2007-11-02 23:31:10 +00:00
|
|
|
|
set_tainted(fd, m_name, 1, TAINT_PROPRIETORY_MODULE, "non-GPL license - ", ptr);
|
2002-09-16 05:30:24 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
set_tainted(fd, m_name, 1, TAINT_PROPRIETORY_MODULE, "Unexpected return from obj_gpl_license", "");
|
2002-09-16 05:30:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flag_force_load)
|
2007-11-02 23:31:10 +00:00
|
|
|
|
set_tainted(fd, m_name, 1, TAINT_FORCED_MODULE, "forced load", "");
|
2002-09-16 05:30:24 +00:00
|
|
|
|
|
|
|
|
|
if (fd >= 0)
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#else /* FEATURE_CHECK_TAINTED_MODULE */
|
2006-12-26 10:42:51 +00:00
|
|
|
|
#define check_tainted_module(x, y) do { } while (0);
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_CHECK_TAINTED_MODULE */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
|
2003-01-23 04:48:34 +00:00
|
|
|
|
/* add module source, timestamp, kernel version and a symbol for the
|
|
|
|
|
* start of some sections. this info is used by ksymoops to do better
|
|
|
|
|
* debugging.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
|
|
|
|
|
{
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
2004-06-22 11:50:52 +00:00
|
|
|
|
return new_get_module_version(f, str);
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#else /* FEATURE_INSMOD_VERSION_CHECKING */
|
2003-12-24 20:30:45 +00:00
|
|
|
|
strncpy(str, "???", sizeof(str));
|
|
|
|
|
return -1;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_INSMOD_VERSION_CHECKING */
|
2003-01-23 04:48:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add module source, timestamp, kernel version and a symbol for the
|
|
|
|
|
* start of some sections. this info is used by ksymoops to do better
|
|
|
|
|
* debugging.
|
|
|
|
|
*/
|
2004-03-15 08:29:22 +00:00
|
|
|
|
static void
|
2003-01-23 04:48:34 +00:00
|
|
|
|
add_ksymoops_symbols(struct obj_file *f, const char *filename,
|
|
|
|
|
const char *m_name)
|
|
|
|
|
{
|
2007-08-12 20:58:27 +00:00
|
|
|
|
static const char symprefix[] ALIGN1 = "__insmod_";
|
2007-11-02 23:31:10 +00:00
|
|
|
|
static const char section_names[][8] = {
|
2003-01-23 04:48:34 +00:00
|
|
|
|
".text",
|
|
|
|
|
".rodata",
|
|
|
|
|
".data",
|
2005-03-30 16:36:40 +00:00
|
|
|
|
".bss",
|
|
|
|
|
".sbss"
|
2003-01-23 04:48:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
struct obj_section *sec;
|
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
char *name, *absolute_filename;
|
|
|
|
|
char str[STRVERSIONLEN];
|
|
|
|
|
int i, l, lm_name, lfilename, use_ksymtab, version;
|
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
|
|
/* WARNING: was using realpath, but replaced by readlink to stop using
|
|
|
|
|
* lots of stack. But here it seems to be able to cause problems? */
|
|
|
|
|
absolute_filename = xmalloc_readlink(filename);
|
|
|
|
|
if (!absolute_filename)
|
2006-08-03 15:41:12 +00:00
|
|
|
|
absolute_filename = xstrdup(filename);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
|
|
|
|
|
lm_name = strlen(m_name);
|
|
|
|
|
lfilename = strlen(absolute_filename);
|
|
|
|
|
|
|
|
|
|
/* add to ksymtab if it already exists or there is no ksymtab and other symbols
|
|
|
|
|
* are not to be exported. otherwise leave ksymtab alone for now, the
|
|
|
|
|
* "export all symbols" compatibility code will export these symbols later.
|
|
|
|
|
*/
|
2006-09-23 12:32:58 +00:00
|
|
|
|
use_ksymtab = obj_find_section(f, "__ksymtab") || flag_noexport;
|
2003-01-23 04:48:34 +00:00
|
|
|
|
|
2006-12-31 18:57:37 +00:00
|
|
|
|
sec = obj_find_section(f, ".this");
|
|
|
|
|
if (sec) {
|
2003-01-23 04:48:34 +00:00
|
|
|
|
/* tag the module header with the object name, last modified
|
|
|
|
|
* timestamp and module version. worst case for module version
|
|
|
|
|
* is 0xffffff, decimal 16777215. putting all three fields in
|
|
|
|
|
* one symbol is less readable but saves kernel space.
|
|
|
|
|
*/
|
2007-11-02 23:31:10 +00:00
|
|
|
|
l = sizeof(symprefix) + /* "__insmod_" */
|
|
|
|
|
lm_name + /* module name */
|
|
|
|
|
2 + /* "_O" */
|
|
|
|
|
lfilename + /* object filename */
|
|
|
|
|
2 + /* "_M" */
|
|
|
|
|
2 * sizeof(statbuf.st_mtime) + /* mtime in hex */
|
|
|
|
|
2 + /* "_V" */
|
|
|
|
|
8 + /* version in dec */
|
|
|
|
|
1; /* nul */
|
2003-01-23 04:48:34 +00:00
|
|
|
|
name = xmalloc(l);
|
|
|
|
|
if (stat(absolute_filename, &statbuf) != 0)
|
|
|
|
|
statbuf.st_mtime = 0;
|
|
|
|
|
version = get_module_version(f, str); /* -1 if not found */
|
|
|
|
|
snprintf(name, l, "%s%s_O%s_M%0*lX_V%d",
|
2003-12-24 20:30:45 +00:00
|
|
|
|
symprefix, m_name, absolute_filename,
|
2007-11-02 23:31:10 +00:00
|
|
|
|
(int)(2 * sizeof(statbuf.st_mtime)), statbuf.st_mtime,
|
2003-12-24 20:30:45 +00:00
|
|
|
|
version);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
sym = obj_add_symbol(f, name, -1,
|
2005-10-02 07:02:16 +00:00
|
|
|
|
ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
|
2003-12-24 20:30:45 +00:00
|
|
|
|
sec->idx, sec->header.sh_addr, 0);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
if (use_ksymtab)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
new_add_ksymtab(f, sym);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
}
|
|
|
|
|
free(absolute_filename);
|
|
|
|
|
#ifdef _NOT_SUPPORTED_
|
|
|
|
|
/* record where the persistent data is going, same address as previous symbol */
|
|
|
|
|
|
|
|
|
|
if (f->persist) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
l = sizeof(symprefix) + /* "__insmod_" */
|
|
|
|
|
lm_name + /* module name */
|
|
|
|
|
2 + /* "_P" */
|
|
|
|
|
strlen(f->persist) + /* data store */
|
|
|
|
|
1; /* nul */
|
2003-01-23 04:48:34 +00:00
|
|
|
|
name = xmalloc(l);
|
|
|
|
|
snprintf(name, l, "%s%s_P%s",
|
2003-12-24 20:30:45 +00:00
|
|
|
|
symprefix, m_name, f->persist);
|
2005-10-02 07:02:16 +00:00
|
|
|
|
sym = obj_add_symbol(f, name, -1, ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
|
2003-12-24 20:30:45 +00:00
|
|
|
|
sec->idx, sec->header.sh_addr, 0);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
if (use_ksymtab)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
new_add_ksymtab(f, sym);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
}
|
|
|
|
|
#endif /* _NOT_SUPPORTED_ */
|
|
|
|
|
/* tag the desired sections if size is non-zero */
|
|
|
|
|
|
2007-06-25 10:55:35 +00:00
|
|
|
|
for (i = 0; i < ARRAY_SIZE(section_names); ++i) {
|
2006-12-31 18:57:37 +00:00
|
|
|
|
sec = obj_find_section(f, section_names[i]);
|
|
|
|
|
if (sec && sec->header.sh_size) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
l = sizeof(symprefix) + /* "__insmod_" */
|
|
|
|
|
lm_name + /* module name */
|
|
|
|
|
2 + /* "_S" */
|
|
|
|
|
strlen(sec->name) + /* section name */
|
|
|
|
|
2 + /* "_L" */
|
|
|
|
|
8 + /* length in dec */
|
|
|
|
|
1; /* nul */
|
2003-01-23 04:48:34 +00:00
|
|
|
|
name = xmalloc(l);
|
|
|
|
|
snprintf(name, l, "%s%s_S%s_L%ld",
|
2003-12-24 20:30:45 +00:00
|
|
|
|
symprefix, m_name, sec->name,
|
|
|
|
|
(long)sec->header.sh_size);
|
2005-10-02 07:02:16 +00:00
|
|
|
|
sym = obj_add_symbol(f, name, -1, ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
|
2003-12-24 20:30:45 +00:00
|
|
|
|
sec->idx, sec->header.sh_addr, 0);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
if (use_ksymtab)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
new_add_ksymtab(f, sym);
|
2003-01-23 04:48:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
|
2003-01-23 04:48:34 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_LOAD_MAP
|
2003-01-23 04:57:35 +00:00
|
|
|
|
static void print_load_map(struct obj_file *f)
|
|
|
|
|
{
|
|
|
|
|
struct obj_section *sec;
|
2006-12-30 18:42:29 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_LOAD_MAP_FULL
|
|
|
|
|
struct obj_symbol **all, **p;
|
2003-01-23 04:57:35 +00:00
|
|
|
|
int i, nsyms, *loaded;
|
2006-12-30 18:42:29 +00:00
|
|
|
|
struct obj_symbol *sym;
|
|
|
|
|
#endif
|
2003-01-23 04:57:35 +00:00
|
|
|
|
/* Report on the section layout. */
|
|
|
|
|
|
|
|
|
|
printf("Sections: Size %-*s Align\n",
|
|
|
|
|
(int) (2 * sizeof(void *)), "Address");
|
|
|
|
|
|
|
|
|
|
for (sec = f->load_order; sec; sec = sec->load_next) {
|
|
|
|
|
int a;
|
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
|
|
for (a = -1, tmp = sec->header.sh_addralign; tmp; ++a)
|
|
|
|
|
tmp >>= 1;
|
|
|
|
|
if (a == -1)
|
|
|
|
|
a = 0;
|
|
|
|
|
|
|
|
|
|
printf("%-15s %08lx %0*lx 2**%d\n",
|
|
|
|
|
sec->name,
|
|
|
|
|
(long)sec->header.sh_size,
|
|
|
|
|
(int) (2 * sizeof(void *)),
|
|
|
|
|
(long)sec->header.sh_addr,
|
|
|
|
|
a);
|
|
|
|
|
}
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_LOAD_MAP_FULL
|
2003-01-23 04:57:35 +00:00
|
|
|
|
/* Quick reference which section indicies are loaded. */
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
i = f->header.e_shnum;
|
|
|
|
|
loaded = alloca(sizeof(int) * i);
|
2003-01-23 04:57:35 +00:00
|
|
|
|
while (--i >= 0)
|
2007-11-02 23:31:10 +00:00
|
|
|
|
loaded[i] = ((f->sections[i]->header.sh_flags & SHF_ALLOC) != 0);
|
2003-01-23 04:57:35 +00:00
|
|
|
|
|
|
|
|
|
/* Collect the symbols we'll be listing. */
|
|
|
|
|
|
|
|
|
|
for (nsyms = i = 0; i < HASH_BUCKETS; ++i)
|
|
|
|
|
for (sym = f->symtab[i]; sym; sym = sym->next)
|
|
|
|
|
if (sym->secidx <= SHN_HIRESERVE
|
|
|
|
|
&& (sym->secidx >= SHN_LORESERVE || loaded[sym->secidx]))
|
|
|
|
|
++nsyms;
|
|
|
|
|
|
|
|
|
|
all = alloca(nsyms * sizeof(struct obj_symbol *));
|
|
|
|
|
|
|
|
|
|
for (i = 0, p = all; i < HASH_BUCKETS; ++i)
|
|
|
|
|
for (sym = f->symtab[i]; sym; sym = sym->next)
|
|
|
|
|
if (sym->secidx <= SHN_HIRESERVE
|
|
|
|
|
&& (sym->secidx >= SHN_LORESERVE || loaded[sym->secidx]))
|
|
|
|
|
*p++ = sym;
|
|
|
|
|
|
|
|
|
|
/* And list them. */
|
|
|
|
|
printf("\nSymbols:\n");
|
|
|
|
|
for (p = all; p < all + nsyms; ++p) {
|
|
|
|
|
char type = '?';
|
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
|
|
sym = *p;
|
|
|
|
|
if (sym->secidx == SHN_ABS) {
|
|
|
|
|
type = 'A';
|
|
|
|
|
value = sym->value;
|
|
|
|
|
} else if (sym->secidx == SHN_UNDEF) {
|
|
|
|
|
type = 'U';
|
|
|
|
|
value = 0;
|
|
|
|
|
} else {
|
|
|
|
|
sec = f->sections[sym->secidx];
|
|
|
|
|
|
|
|
|
|
if (sec->header.sh_type == SHT_NOBITS)
|
|
|
|
|
type = 'B';
|
|
|
|
|
else if (sec->header.sh_flags & SHF_ALLOC) {
|
|
|
|
|
if (sec->header.sh_flags & SHF_EXECINSTR)
|
|
|
|
|
type = 'T';
|
|
|
|
|
else if (sec->header.sh_flags & SHF_WRITE)
|
|
|
|
|
type = 'D';
|
|
|
|
|
else
|
|
|
|
|
type = 'R';
|
|
|
|
|
}
|
|
|
|
|
value = sym->value + sec->header.sh_addr;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-02 07:02:16 +00:00
|
|
|
|
if (ELF_ST_BIND(sym->info) == STB_LOCAL)
|
2003-01-23 04:57:35 +00:00
|
|
|
|
type = tolower(type);
|
|
|
|
|
|
|
|
|
|
printf("%0*lx %c %s\n", (int) (2 * sizeof(void *)), value,
|
|
|
|
|
type, sym->name);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#else /* !FEATURE_INSMOD_LOAD_MAP */
|
2006-09-23 12:32:58 +00:00
|
|
|
|
void print_load_map(struct obj_file *f);
|
2003-01-23 04:57:35 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
|
int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
|
int insmod_main(int argc, char **argv)
|
2000-06-12 23:11:16 +00:00
|
|
|
|
{
|
2006-10-12 20:06:18 +00:00
|
|
|
|
char *opt_o, *arg1;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
int len;
|
2004-06-22 20:10:53 +00:00
|
|
|
|
int k_crcs;
|
2002-06-06 14:24:57 +00:00
|
|
|
|
char *tmp, *tmp1;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
unsigned long m_size;
|
|
|
|
|
ElfW(Addr) m_addr;
|
|
|
|
|
struct obj_file *f;
|
2001-02-15 19:07:43 +00:00
|
|
|
|
struct stat st;
|
2007-11-02 23:31:10 +00:00
|
|
|
|
char *m_name = NULL;
|
2000-12-01 02:55:13 +00:00
|
|
|
|
int exit_status = EXIT_FAILURE;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
int m_has_modinfo;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
2001-08-06 14:18:08 +00:00
|
|
|
|
struct utsname uts_info;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
char m_strversion[STRVERSIONLEN];
|
2004-06-22 20:10:53 +00:00
|
|
|
|
int m_version, m_crcs;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
#endif
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_CLEAN_UP
|
2007-09-24 19:54:36 +00:00
|
|
|
|
FILE *fp = NULL;
|
2002-06-22 17:15:42 +00:00
|
|
|
|
#else
|
|
|
|
|
FILE *fp;
|
2003-01-23 04:57:35 +00:00
|
|
|
|
#endif
|
2003-12-19 21:04:19 +00:00
|
|
|
|
int k_version = 0;
|
|
|
|
|
struct utsname myuname;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Parse any options */
|
2007-08-18 15:32:12 +00:00
|
|
|
|
getopt32(argv, OPTION_STR, &opt_o);
|
2006-10-12 20:06:18 +00:00
|
|
|
|
arg1 = argv[optind];
|
2006-10-06 09:49:47 +00:00
|
|
|
|
if (option_mask32 & OPT_o) { // -o /* name the output module */
|
2006-09-23 12:32:58 +00:00
|
|
|
|
free(m_name);
|
|
|
|
|
m_name = xstrdup(opt_o);
|
|
|
|
|
}
|
2003-12-19 21:04:19 +00:00
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
if (arg1 == NULL) {
|
2003-03-19 09:13:01 +00:00
|
|
|
|
bb_show_usage();
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
2001-01-24 19:07:09 +00:00
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
/* Grab the module name */
|
2006-10-12 20:06:18 +00:00
|
|
|
|
tmp1 = xstrdup(arg1);
|
2002-06-06 14:24:57 +00:00
|
|
|
|
tmp = basename(tmp1);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
len = strlen(tmp);
|
|
|
|
|
|
2003-12-19 21:04:19 +00:00
|
|
|
|
if (uname(&myuname) == 0) {
|
|
|
|
|
if (myuname.release[0] == '2') {
|
|
|
|
|
k_version = myuname.release[2] - '0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_2_6_MODULES
|
2006-10-12 20:06:18 +00:00
|
|
|
|
if (k_version > 4 && len > 3 && tmp[len - 3] == '.'
|
|
|
|
|
&& tmp[len - 2] == 'k' && tmp[len - 1] == 'o'
|
|
|
|
|
) {
|
|
|
|
|
len -= 3;
|
2003-12-19 21:04:19 +00:00
|
|
|
|
tmp[len] = '\0';
|
2006-10-12 20:06:18 +00:00
|
|
|
|
} else
|
2003-12-19 21:04:19 +00:00
|
|
|
|
#endif
|
2003-12-24 20:30:45 +00:00
|
|
|
|
if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') {
|
2006-10-12 20:06:18 +00:00
|
|
|
|
len -= 2;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
tmp[len] = '\0';
|
|
|
|
|
}
|
2002-06-18 05:16:25 +00:00
|
|
|
|
|
2003-12-19 21:04:19 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_2_6_MODULES
|
2003-12-19 21:04:19 +00:00
|
|
|
|
if (k_version > 4)
|
2006-08-03 15:41:12 +00:00
|
|
|
|
m_fullName = xasprintf("%s.ko", tmp);
|
2003-12-19 21:04:19 +00:00
|
|
|
|
else
|
|
|
|
|
#endif
|
2006-08-03 15:41:12 +00:00
|
|
|
|
m_fullName = xasprintf("%s.o", tmp);
|
2002-06-22 17:15:42 +00:00
|
|
|
|
|
|
|
|
|
if (!m_name) {
|
|
|
|
|
m_name = tmp;
|
|
|
|
|
} else {
|
2002-06-06 14:24:57 +00:00
|
|
|
|
free(tmp1);
|
2007-11-02 23:31:10 +00:00
|
|
|
|
tmp1 = NULL; /* flag for free(m_name) before exit() */
|
2001-01-25 04:11:06 +00:00
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-09-24 19:54:36 +00:00
|
|
|
|
/* Get a filedesc for the module. Check that we have a complete path */
|
2006-10-12 20:06:18 +00:00
|
|
|
|
if (stat(arg1, &st) < 0 || !S_ISREG(st.st_mode)
|
|
|
|
|
|| (fp = fopen(arg1, "r")) == NULL
|
|
|
|
|
) {
|
2001-05-14 17:07:32 +00:00
|
|
|
|
/* Hmm. Could not open it. First search under /lib/modules/`uname -r`,
|
|
|
|
|
* but do not error out yet if we fail to find it... */
|
2003-12-19 21:04:19 +00:00
|
|
|
|
if (k_version) { /* uname succeedd */
|
|
|
|
|
char *module_dir;
|
|
|
|
|
char *tmdn;
|
2002-07-19 00:05:54 +00:00
|
|
|
|
|
2003-12-19 21:04:19 +00:00
|
|
|
|
tmdn = concat_path_file(_PATH_MODULES, myuname.release);
|
2001-05-14 20:03:04 +00:00
|
|
|
|
/* Jump through hoops in case /lib/modules/`uname -r`
|
|
|
|
|
* is a symlink. We do not want recursive_action to
|
|
|
|
|
* follow symlinks, but we do want to follow the
|
|
|
|
|
* /lib/modules/`uname -r` dir, So resolve it ourselves
|
|
|
|
|
* if it is a link... */
|
2007-11-02 23:31:10 +00:00
|
|
|
|
module_dir = xmalloc_readlink(tmdn);
|
|
|
|
|
if (!module_dir)
|
|
|
|
|
module_dir = xstrdup(tmdn);
|
2007-04-08 10:52:28 +00:00
|
|
|
|
recursive_action(module_dir, ACTION_RECURSE,
|
2007-11-02 23:31:10 +00:00
|
|
|
|
check_module_name_match, NULL, m_fullName, 0);
|
|
|
|
|
free(module_dir);
|
2003-12-19 21:04:19 +00:00
|
|
|
|
free(tmdn);
|
2001-05-14 17:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if we have found anything yet */
|
2007-09-24 19:54:36 +00:00
|
|
|
|
if (!m_filename || ((fp = fopen(m_filename, "r")) == NULL)) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
int r;
|
|
|
|
|
char *module_dir;
|
2002-07-19 00:05:54 +00:00
|
|
|
|
|
2003-12-19 21:04:19 +00:00
|
|
|
|
free(m_filename);
|
2007-09-24 19:54:36 +00:00
|
|
|
|
m_filename = NULL;
|
2007-11-02 23:31:10 +00:00
|
|
|
|
module_dir = xmalloc_readlink(_PATH_MODULES);
|
|
|
|
|
if (!module_dir)
|
|
|
|
|
module_dir = xstrdup(_PATH_MODULES);
|
2001-05-14 17:07:32 +00:00
|
|
|
|
/* No module found under /lib/modules/`uname -r`, this
|
|
|
|
|
* time cast the net a bit wider. Search /lib/modules/ */
|
2007-11-02 23:31:10 +00:00
|
|
|
|
r = recursive_action(module_dir, ACTION_RECURSE,
|
|
|
|
|
check_module_name_match, NULL, m_fullName, 0);
|
|
|
|
|
if (r)
|
|
|
|
|
bb_error_msg_and_die("%s: module not found", m_fullName);
|
|
|
|
|
free(module_dir);
|
|
|
|
|
if (m_filename == NULL
|
|
|
|
|
|| ((fp = fopen(m_filename, "r")) == NULL)
|
2006-10-12 20:06:18 +00:00
|
|
|
|
) {
|
2007-09-24 19:54:36 +00:00
|
|
|
|
bb_error_msg_and_die("%s: module not found", m_fullName);
|
2007-11-02 23:31:10 +00:00
|
|
|
|
}
|
2001-05-14 17:07:32 +00:00
|
|
|
|
}
|
2003-12-19 21:04:19 +00:00
|
|
|
|
} else
|
2006-10-12 20:06:18 +00:00
|
|
|
|
m_filename = xstrdup(arg1);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2005-12-11 20:14:12 +00:00
|
|
|
|
if (flag_verbose)
|
2003-12-31 23:20:10 +00:00
|
|
|
|
printf("Using %s\n", m_filename);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_2_6_MODULES
|
2006-10-12 20:06:18 +00:00
|
|
|
|
if (k_version > 4) {
|
|
|
|
|
argv[optind] = m_filename;
|
2003-08-31 01:58:18 +00:00
|
|
|
|
optind--;
|
|
|
|
|
return insmod_ng_main(argc - optind, argv + optind);
|
2003-12-19 21:04:19 +00:00
|
|
|
|
}
|
2003-08-31 01:58:18 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
f = obj_load(fp, LOADBITS);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
if (get_modinfo_value(f, "kernel_version") == NULL)
|
|
|
|
|
m_has_modinfo = 0;
|
|
|
|
|
else
|
|
|
|
|
m_has_modinfo = 1;
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
2000-06-12 23:11:16 +00:00
|
|
|
|
/* Version correspondence? */
|
2002-07-02 19:14:23 +00:00
|
|
|
|
if (!flag_quiet) {
|
|
|
|
|
if (uname(&uts_info) < 0)
|
|
|
|
|
uts_info.release[0] = '\0';
|
|
|
|
|
if (m_has_modinfo) {
|
|
|
|
|
m_version = new_get_module_version(f, m_strversion);
|
|
|
|
|
if (m_version == -1) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("cannot find the kernel version the module was "
|
2002-07-02 19:14:23 +00:00
|
|
|
|
"compiled for");
|
|
|
|
|
}
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-02 19:14:23 +00:00
|
|
|
|
if (strncmp(uts_info.release, m_strversion, STRVERSIONLEN) != 0) {
|
2007-06-12 08:52:02 +00:00
|
|
|
|
bb_error_msg("%skernel-module version mismatch\n"
|
|
|
|
|
"\t%s was compiled for kernel version %s\n"
|
|
|
|
|
"\twhile this kernel is version %s",
|
|
|
|
|
flag_force_load ? "warning: " : "",
|
|
|
|
|
m_filename, m_strversion, uts_info.release);
|
|
|
|
|
if (!flag_force_load)
|
2002-07-02 19:14:23 +00:00
|
|
|
|
goto out;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
k_crcs = 0;
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_INSMOD_VERSION_CHECKING */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
if (query_module(NULL, 0, NULL, 0, NULL))
|
|
|
|
|
bb_error_msg_and_die("not configured to support old kernels");
|
|
|
|
|
new_get_kernel_symbols();
|
|
|
|
|
k_crcs = new_is_kernel_checksummed();
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
2004-06-22 11:50:52 +00:00
|
|
|
|
m_crcs = 0;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (m_has_modinfo)
|
|
|
|
|
m_crcs = new_is_module_checksummed(f);
|
|
|
|
|
|
|
|
|
|
if (m_crcs != k_crcs)
|
|
|
|
|
obj_set_symbol_compare(f, ncv_strcmp, ncv_symbol_hash);
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_INSMOD_VERSION_CHECKING */
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Let the module know about the kernel symbols. */
|
|
|
|
|
add_kernel_symbols(f);
|
|
|
|
|
|
|
|
|
|
/* Allocate common symbols, symbol tables, and string tables. */
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
new_create_this_module(f, m_name);
|
|
|
|
|
obj_check_undefineds(f);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
obj_allocate_commons(f);
|
2002-09-16 05:30:24 +00:00
|
|
|
|
check_tainted_module(f, m_name);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
2001-01-24 23:59:50 +00:00
|
|
|
|
/* done with the module name, on to the optional var=value arguments */
|
|
|
|
|
++optind;
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (optind < argc) {
|
2007-11-02 23:31:10 +00:00
|
|
|
|
new_process_module_arguments(f, argc - optind, argv + optind);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
arch_create_got(f);
|
|
|
|
|
hide_special_symbols(f);
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
|
2003-01-23 04:48:34 +00:00
|
|
|
|
add_ksymoops_symbols(f, m_filename, m_name);
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
|
2003-01-23 04:48:34 +00:00
|
|
|
|
|
2004-06-22 11:50:52 +00:00
|
|
|
|
new_create_module_ksymtab(f);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
|
|
|
|
|
/* Find current size of the module */
|
|
|
|
|
m_size = obj_load_size(f);
|
|
|
|
|
|
|
|
|
|
m_addr = create_module(m_name, m_size);
|
2002-06-22 17:15:42 +00:00
|
|
|
|
if (m_addr == -1) switch (errno) {
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case EEXIST:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("a module named %s already exists", m_name);
|
2003-12-24 20:30:45 +00:00
|
|
|
|
case ENOMEM:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_error_msg_and_die("can't allocate kernel memory for module; needed %lu bytes",
|
2003-12-24 20:30:45 +00:00
|
|
|
|
m_size);
|
|
|
|
|
default:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
bb_perror_msg_and_die("create_module: %s", m_name);
|
2000-06-12 23:11:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
#if !LOADBITS
|
2001-05-21 16:09:18 +00:00
|
|
|
|
/*
|
|
|
|
|
* the PROGBITS section was not loaded by the obj_load
|
|
|
|
|
* now we can load them directly into the kernel memory
|
|
|
|
|
*/
|
2001-08-22 05:26:08 +00:00
|
|
|
|
if (!obj_load_progbits(fp, f, (char*)m_addr)) {
|
2001-05-21 16:09:18 +00:00
|
|
|
|
delete_module(m_name);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2003-12-19 21:04:19 +00:00
|
|
|
|
#endif
|
2001-05-21 16:09:18 +00:00
|
|
|
|
|
2000-06-12 23:11:16 +00:00
|
|
|
|
if (!obj_relocate(f, m_addr)) {
|
|
|
|
|
delete_module(m_name);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-12 20:06:18 +00:00
|
|
|
|
if (!new_init_module(m_name, f, m_size)) {
|
2000-06-12 23:11:16 +00:00
|
|
|
|
delete_module(m_name);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-12 00:32:05 +00:00
|
|
|
|
if (flag_print_load_map)
|
2003-01-23 04:57:35 +00:00
|
|
|
|
print_load_map(f);
|
|
|
|
|
|
2000-12-01 02:55:13 +00:00
|
|
|
|
exit_status = EXIT_SUCCESS;
|
1999-12-21 02:55:11 +00:00
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
out:
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_CLEAN_UP
|
2007-04-12 00:32:05 +00:00
|
|
|
|
if (fp)
|
2003-12-24 20:30:45 +00:00
|
|
|
|
fclose(fp);
|
2006-03-01 16:39:45 +00:00
|
|
|
|
free(tmp1);
|
2007-04-12 00:32:05 +00:00
|
|
|
|
if (!tmp1)
|
2002-06-22 17:15:42 +00:00
|
|
|
|
free(m_name);
|
|
|
|
|
free(m_filename);
|
|
|
|
|
#endif
|
2006-11-27 16:49:31 +00:00
|
|
|
|
return exit_status;
|
1999-12-17 18:57:34 +00:00
|
|
|
|
}
|
2003-12-11 01:42:13 +00:00
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
#endif /* ENABLE_FEATURE_2_4_MODULES */
|
|
|
|
|
/*
|
|
|
|
|
* End of big piece of 2.4-specific code
|
|
|
|
|
*/
|
2003-12-11 01:42:13 +00:00
|
|
|
|
|
|
|
|
|
|
2006-11-21 14:12:53 +00:00
|
|
|
|
#if ENABLE_FEATURE_2_6_MODULES
|
2003-12-11 01:42:13 +00:00
|
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <asm/unistd.h>
|
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
|
|
|
|
|
/* We use error numbers in a loose translation... */
|
|
|
|
|
static const char *moderror(int err)
|
|
|
|
|
{
|
|
|
|
|
switch (err) {
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case ENOEXEC:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
return "invalid module format";
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case ENOENT:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
return "unknown symbol in module";
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case ESRCH:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
return "module has wrong symbol version";
|
2006-10-12 20:06:18 +00:00
|
|
|
|
case EINVAL:
|
2007-11-02 23:31:10 +00:00
|
|
|
|
return "invalid parameters";
|
2006-10-12 20:06:18 +00:00
|
|
|
|
default:
|
|
|
|
|
return strerror(err);
|
2003-12-11 01:42:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 23:31:10 +00:00
|
|
|
|
#if !ENABLE_FEATURE_2_4_MODULES
|
|
|
|
|
int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
|
int insmod_main(int argc, char **argv)
|
|
|
|
|
#else
|
|
|
|
|
static int insmod_ng_main(int argc, char **argv)
|
|
|
|
|
#endif
|
2003-12-11 01:42:13 +00:00
|
|
|
|
{
|
2006-11-21 11:58:14 +00:00
|
|
|
|
long ret;
|
|
|
|
|
size_t len;
|
2007-06-13 06:47:47 +00:00
|
|
|
|
int optlen;
|
2003-12-11 01:42:13 +00:00
|
|
|
|
void *map;
|
2006-11-21 11:58:14 +00:00
|
|
|
|
char *filename, *options;
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2006-11-21 11:58:14 +00:00
|
|
|
|
filename = *++argv;
|
|
|
|
|
if (!filename)
|
2003-12-11 01:42:13 +00:00
|
|
|
|
bb_show_usage();
|
|
|
|
|
|
|
|
|
|
/* Rest is options */
|
2007-06-13 06:47:47 +00:00
|
|
|
|
options = xzalloc(1);
|
|
|
|
|
optlen = 0;
|
2006-11-21 11:58:14 +00:00
|
|
|
|
while (*++argv) {
|
|
|
|
|
options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
|
2003-12-11 01:42:13 +00:00
|
|
|
|
/* Spaces handled by "" pairs, but no way of escaping quotes */
|
2007-06-13 06:47:47 +00:00
|
|
|
|
optlen += sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv);
|
2003-12-11 01:42:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-21 11:58:14 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* Any special reason why mmap? It isn't performace critical... */
|
|
|
|
|
int fd;
|
|
|
|
|
struct stat st;
|
|
|
|
|
unsigned long len;
|
2006-09-09 12:25:20 +00:00
|
|
|
|
fd = xopen(filename, O_RDONLY);
|
2003-12-11 01:42:13 +00:00
|
|
|
|
fstat(fd, &st);
|
|
|
|
|
len = st.st_size;
|
2005-12-07 22:45:28 +00:00
|
|
|
|
map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
2003-12-11 01:42:13 +00:00
|
|
|
|
if (map == MAP_FAILED) {
|
2006-11-18 22:04:09 +00:00
|
|
|
|
bb_perror_msg_and_die("cannot mmap '%s'", filename);
|
2003-12-11 01:42:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-21 11:58:14 +00:00
|
|
|
|
/* map == NULL on Blackfin, probably on other MMU-less systems too. Workaround. */
|
|
|
|
|
if (map == NULL) {
|
|
|
|
|
map = xmalloc(len);
|
|
|
|
|
xread(fd, map, len);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
len = MAXINT(ssize_t);
|
|
|
|
|
map = xmalloc_open_read_close(filename, &len);
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-12-11 01:42:13 +00:00
|
|
|
|
ret = syscall(__NR_init_module, map, len, options);
|
|
|
|
|
if (ret != 0) {
|
2007-11-06 02:02:45 +00:00
|
|
|
|
bb_error_msg_and_die("cannot insert '%s': %s",
|
|
|
|
|
filename, moderror(errno));
|
2003-12-11 01:42:13 +00:00
|
|
|
|
}
|
2003-12-24 20:30:45 +00:00
|
|
|
|
|
2003-12-11 01:42:13 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|