2004-10-30 22:33:43 +02:00
|
|
|
/* $XdotOrg: xc/programs/Xserver/hw/xfree86/loader/elfloader.c,v 1.2 2004/04/23 19:54:06 eich Exp $ */
|
2004-04-23 21:54:30 +02:00
|
|
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/elfloader.c,v 1.61tsi Exp $ */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright 1995-1998 by Metro Link, Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of Metro Link, Inc. not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
|
|
|
* specific, written prior permission. Metro Link, Inc. makes no
|
|
|
|
* representations about the suitability of this software for any purpose.
|
|
|
|
* It is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* METRO LINK, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL METRO LINK, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
2003-11-25 20:29:01 +01:00
|
|
|
#ifndef __UNIXOS2__
|
2003-11-14 17:48:57 +01:00
|
|
|
#include <sys/mman.h>
|
2003-11-25 20:29:01 +01:00
|
|
|
#endif
|
2003-11-14 17:48:57 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef __QNX__
|
|
|
|
# include <fcntl.h>
|
|
|
|
#else
|
|
|
|
# include <sys/fcntl.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#if defined(linux) && defined (__ia64__)
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DBMALLOC
|
|
|
|
# include <debug/malloc.h>
|
|
|
|
# define Xalloc(size) malloc(size)
|
|
|
|
# define Xcalloc(size) calloc(1,(size))
|
|
|
|
# define Xfree(size) free(size)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Xos.h"
|
|
|
|
#include "os.h"
|
|
|
|
#include "elf.h"
|
|
|
|
|
|
|
|
#include "sym.h"
|
|
|
|
#include "loader.h"
|
|
|
|
|
|
|
|
#include "compiler.h"
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
#ifndef LOADERDEBUG
|
|
|
|
#define LOADERDEBUG 0
|
|
|
|
#endif
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
#if LOADERDEBUG
|
2003-11-14 17:48:57 +01:00
|
|
|
# define ELFDEBUG ErrorF
|
|
|
|
#endif
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
#if defined(__ia64__)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* R_IA64_LTOFF22X and R_IA64_LDXMOV are relocation optimizations for
|
|
|
|
* IA64. Conforming implementations must recognize them and may either
|
|
|
|
* implement the optimization or may fallback to previous
|
|
|
|
* non-optimized behavior by treating R_IA64_LTOFF22X as a
|
|
|
|
* R_IA64_LTOFF22 and ignoring R_IA64_LDXMOV. The
|
|
|
|
* IA64_LDX_OPTIMIZATION conditional controls the fallback behavior,
|
|
|
|
* if defined the optimizations are performed.
|
|
|
|
*
|
|
|
|
* To implement the optimization we want to change is the sequence on
|
|
|
|
* the left to that on the right, without regard to any intervening
|
|
|
|
* instructions:
|
|
|
|
*
|
|
|
|
* 1) addl t1=@ltoff(var),gp ==> addl t1=@gprel(var),gp
|
|
|
|
* 2) ld8 t2=[t1] ==> mov t2=t1
|
|
|
|
* 3) ld8 loc0=[t2] ==> ld8 loc0=[t2]
|
|
|
|
*
|
|
|
|
* The relocations that match the above instructions are:
|
|
|
|
*
|
|
|
|
* 1) R_IA64_LTOFF22 ==> R_IA64_LTOFF22X
|
|
|
|
* 2) -- ==> R_IA64_LDXMOV
|
|
|
|
* 3) -- ==> --
|
|
|
|
*
|
|
|
|
* First lets look at left hand column to understand the original
|
|
|
|
* mechanism. The virtual address of a symbol is stored in the GOT,
|
|
|
|
* when that symbol is referenced the following sequence occurs,
|
|
|
|
* instruction 1 loads the address of the GOT entry containing the
|
|
|
|
* virtural address of the symbol into t1. Instruction 2 loads the
|
|
|
|
* virtual address of the symbol into t2 by dereferencing t1. Finally
|
|
|
|
* the symbol is loaded in instruction 3 by dereferencing its virtual
|
|
|
|
* address in t2.
|
|
|
|
*
|
|
|
|
* The optimization that LTOFF22X/LDXMOV introduces is based on the
|
|
|
|
* observation we are doing an extra load (instruction 2) if we can
|
|
|
|
* generate the virtual address for the symbol without doing a lookup in
|
|
|
|
* the GOT. This is possible if the virtual address of the symbol can be
|
|
|
|
* computed via GP relative addressing. In other words the virtual
|
|
|
|
* address of the symbol is a fixed offset from the GP. This fixed offset
|
|
|
|
* must be within the limits of the signed 22 bit immediate offset in the
|
|
|
|
* ld8 instruction, otherwise the original indirect GOT lookup must be
|
|
|
|
* performed (LTOFF22).
|
|
|
|
*
|
|
|
|
* If we can use GP relative addressing for the symbol then the
|
|
|
|
* instruction that loaded the virtual address of the symbol into t2 must
|
|
|
|
* also be patched, hence the introduction of the LDXMOV relocation. The
|
|
|
|
* LDXMOV essentially turns the GOT lookup into a no-op by changing the
|
|
|
|
* ld8 into a register move that preserves the register location of the
|
|
|
|
* symbol's virtual address (e.g. t2).
|
|
|
|
*
|
|
|
|
* The important point to recognize when implementing the LTOFF22X/LDXMOV
|
|
|
|
* optimization is that relocations are interdependent, the LDXMOV is
|
|
|
|
* only applied if the LTOFF22X is applied. It is also worth noting that
|
|
|
|
* there is no relationship between LDXMOV relocations and LTOFF22X in
|
|
|
|
* the ELF relocation section other than they share the same
|
|
|
|
* symbol+addend value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IA64_LDX_OPTIMIZATION 1
|
|
|
|
#endif
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
#ifndef UseMMAP
|
|
|
|
# if defined (__ia64__) || defined (__sparc__)
|
|
|
|
# define MergeSectionAlloc
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (DoMMAPedMerge)
|
|
|
|
# include <sys/mman.h>
|
|
|
|
# define MergeSectionAlloc
|
|
|
|
# define MMAP_PROT (PROT_READ | PROT_WRITE | PROT_EXEC)
|
|
|
|
# if !defined(linux)
|
|
|
|
# error No MAP_ANON?
|
|
|
|
# endif
|
2004-04-23 21:54:30 +02:00
|
|
|
# if !defined (__amd64__) || !defined(__linux__)
|
2003-11-14 17:48:57 +01:00
|
|
|
# define MMAP_FLAGS (MAP_PRIVATE | MAP_ANON)
|
|
|
|
# else
|
|
|
|
# define MMAP_FLAGS (MAP_PRIVATE | MAP_ANON | MAP_32BIT)
|
|
|
|
# endif
|
|
|
|
# if defined (MmapPageAlign)
|
|
|
|
# define MMAP_ALIGN(size) do { \
|
|
|
|
int pagesize = getpagesize(); \
|
|
|
|
size = ( size + pagesize - 1) / pagesize; \
|
|
|
|
size *= pagesize; \
|
|
|
|
} while (0);
|
|
|
|
# else
|
|
|
|
# define MMAP_ALIGN(size)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (__alpha__) || \
|
|
|
|
defined (__ia64__) || \
|
2004-04-23 21:54:30 +02:00
|
|
|
defined (__amd64__) || \
|
2003-11-14 17:48:57 +01:00
|
|
|
(defined (__sparc__) && \
|
|
|
|
(defined (__arch64__) || \
|
|
|
|
defined (__sparcv9)))
|
|
|
|
typedef Elf64_Ehdr Elf_Ehdr;
|
|
|
|
typedef Elf64_Shdr Elf_Shdr;
|
|
|
|
typedef Elf64_Sym Elf_Sym;
|
|
|
|
typedef Elf64_Rel Elf_Rel;
|
|
|
|
typedef Elf64_Rela Elf_Rela;
|
|
|
|
typedef Elf64_Addr Elf_Addr;
|
|
|
|
typedef Elf64_Half Elf_Half;
|
|
|
|
typedef Elf64_Off Elf_Off;
|
|
|
|
typedef Elf64_Sword Elf_Sword;
|
|
|
|
typedef Elf64_Word Elf_Word;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
#define ELF_ST_BIND ELF64_ST_BIND
|
|
|
|
#define ELF_ST_TYPE ELF64_ST_TYPE
|
|
|
|
#define ELF_R_SYM ELF64_R_SYM
|
|
|
|
#define ELF_R_TYPE ELF64_R_TYPE
|
|
|
|
|
|
|
|
# if defined (__alpha__) || defined (__ia64__)
|
|
|
|
/*
|
|
|
|
* The GOT is allocated dynamically. We need to keep a list of entries that
|
|
|
|
* have already been added to the GOT.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
typedef struct _elf_GOT_Entry {
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Rela *rel;
|
|
|
|
int offset;
|
|
|
|
struct _elf_GOT_Entry *next;
|
2003-11-14 17:48:57 +01:00
|
|
|
} ELFGotEntryRec, *ELFGotEntryPtr;
|
|
|
|
|
|
|
|
typedef struct _elf_GOT {
|
2003-11-25 20:29:01 +01:00
|
|
|
unsigned int size;
|
|
|
|
unsigned int nuses;
|
|
|
|
unsigned char *freeptr;
|
|
|
|
struct _elf_GOT *next;
|
|
|
|
unsigned char section[1];
|
2003-11-14 17:48:57 +01:00
|
|
|
} ELFGotRec, *ELFGotPtr;
|
|
|
|
|
|
|
|
# ifdef MergeSectionAlloc
|
|
|
|
static ELFGotPtr ELFSharedGOTs;
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined (__ia64__)
|
|
|
|
/*
|
|
|
|
* The PLT is allocated dynamically. We need to keep a list of entries that
|
|
|
|
* have already been added to the PLT.
|
|
|
|
*/
|
|
|
|
typedef struct _elf_PLT_Entry {
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Rela *rel;
|
|
|
|
int offset;
|
|
|
|
int gotoffset;
|
|
|
|
struct _elf_PLT_Entry *next;
|
2003-11-14 17:48:57 +01:00
|
|
|
} ELFPltEntryRec, *ELFPltEntryPtr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The OPD is allocated dynamically within the GOT. We need to keep a list
|
|
|
|
* of entries that have already been added to the OPD.
|
|
|
|
*/
|
|
|
|
typedef struct _elf_OPD {
|
2003-11-25 20:29:01 +01:00
|
|
|
LOOKUP *l;
|
|
|
|
int index;
|
|
|
|
int offset;
|
|
|
|
struct _elf_OPD *next;
|
2003-11-14 17:48:57 +01:00
|
|
|
} ELFOpdRec, *ELFOpdPtr;
|
|
|
|
# endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
typedef Elf32_Ehdr Elf_Ehdr;
|
|
|
|
typedef Elf32_Shdr Elf_Shdr;
|
|
|
|
typedef Elf32_Sym Elf_Sym;
|
|
|
|
typedef Elf32_Rel Elf_Rel;
|
|
|
|
typedef Elf32_Rela Elf_Rela;
|
|
|
|
typedef Elf32_Addr Elf_Addr;
|
|
|
|
typedef Elf32_Half Elf_Half;
|
|
|
|
typedef Elf32_Off Elf_Off;
|
|
|
|
typedef Elf32_Sword Elf_Sword;
|
|
|
|
typedef Elf32_Word Elf_Word;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
#define ELF_ST_BIND ELF32_ST_BIND
|
|
|
|
#define ELF_ST_TYPE ELF32_ST_TYPE
|
|
|
|
#define ELF_R_SYM ELF32_R_SYM
|
|
|
|
#define ELF_R_TYPE ELF32_R_TYPE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__powerpc__) || \
|
|
|
|
defined(__mc68000__) || \
|
|
|
|
defined(__alpha__) || \
|
|
|
|
defined(__sparc__) || \
|
|
|
|
defined(__ia64__) || \
|
2004-04-23 21:54:30 +02:00
|
|
|
defined(__amd64__)
|
2003-11-14 17:48:57 +01:00
|
|
|
typedef Elf_Rela Elf_Rel_t;
|
|
|
|
#else
|
2003-11-25 20:29:01 +01:00
|
|
|
typedef Elf_Rel Elf_Rel_t;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
void *saddr;
|
|
|
|
char *name;
|
|
|
|
int ndx;
|
|
|
|
int size;
|
|
|
|
int flags;
|
|
|
|
} LoadSection;
|
|
|
|
|
|
|
|
#define RELOC_SECTION 0x1
|
|
|
|
#define LOADED_SECTION 0x2
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure contains all of the information about a module
|
|
|
|
* that has been loaded.
|
|
|
|
*/
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
typedef struct {
|
|
|
|
int handle;
|
|
|
|
int module;
|
|
|
|
int fd;
|
|
|
|
loader_funcs *funcs;
|
|
|
|
Elf_Ehdr *header; /* file header */
|
|
|
|
int numsh;
|
|
|
|
Elf_Shdr *sections; /* Address of the section header table */
|
|
|
|
int secsize; /* size of the section table */
|
|
|
|
unsigned char **saddr; /* Start addresss of the section pointer table */
|
|
|
|
unsigned char *shstraddr; /* Start address of the section header string table */
|
|
|
|
int shstrndx; /* index of the section header string table */
|
|
|
|
int shstrsize; /* size of the section header string table */
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
unsigned char *got; /* Start address of the .got section */
|
|
|
|
ELFGotEntryPtr got_entries; /* List of entries in the .got section */
|
|
|
|
int gotndx; /* index of the .got section */
|
|
|
|
int gotsize; /* actual size of the .got section */
|
|
|
|
ELFGotPtr shared_got; /* Pointer to ELFGotRec if shared */
|
|
|
|
#endif /*(__alpha__) || (__ia64__) */
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__ia64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFOpdPtr opd_entries; /* List of entries in the .opd section */
|
|
|
|
unsigned char *plt; /* Start address of the .plt section */
|
|
|
|
ELFPltEntryPtr plt_entries; /* List of entries in the .plt section */
|
|
|
|
int pltndx; /* index of the .plt section */
|
|
|
|
int pltsize; /* size of the .plt section */
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif /*__ia64__*/
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *symtab; /* Start address of the .symtab section */
|
|
|
|
int symndx; /* index of the .symtab section */
|
|
|
|
unsigned char *common; /* Start address of the SHN_COMMON space */
|
|
|
|
int comsize; /* size of the SHN_COMMON space */
|
|
|
|
|
|
|
|
unsigned char *base; /* Alloced address of section block */
|
|
|
|
unsigned long baseptr; /* Pointer to next free space in base */
|
|
|
|
int basesize; /* Size of that allocation */
|
|
|
|
unsigned char *straddr; /* Start address of the string table */
|
|
|
|
int strndx; /* index of the string table */
|
|
|
|
int strsize; /* size of the string table */
|
|
|
|
LoadSection *lsection;
|
|
|
|
int lsectidx;
|
|
|
|
} ELFModuleRec, *ELFModulePtr;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a relocation is unable to be satisfied, then put it on a list
|
|
|
|
* to try later after more modules have been loaded.
|
|
|
|
*/
|
|
|
|
typedef struct _elf_reloc {
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Rel_t *rel;
|
|
|
|
ELFModulePtr file;
|
|
|
|
Elf_Word secn;
|
|
|
|
struct _elf_reloc *next;
|
2003-11-14 17:48:57 +01:00
|
|
|
} ELFRelocRec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* symbols with a st_shndx of COMMON need to have space allocated for them.
|
|
|
|
*
|
|
|
|
* Gather all of these symbols together, and allocate one chunk when we
|
|
|
|
* are done.
|
|
|
|
*/
|
|
|
|
typedef struct _elf_COMMON {
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *sym;
|
|
|
|
struct _elf_COMMON *next;
|
2003-11-14 17:48:57 +01:00
|
|
|
} ELFCommonRec;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
static ELFCommonPtr listCOMMON = NULL;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/* Prototypes for static functions */
|
|
|
|
static int ELFhashCleanOut(void *, itemPtr);
|
|
|
|
static char *ElfGetStringIndex(ELFModulePtr, int, int);
|
|
|
|
static char *ElfGetString(ELFModulePtr, int);
|
|
|
|
static char *ElfGetSectionName(ELFModulePtr, int);
|
|
|
|
static ELFRelocPtr ElfDelayRelocation(ELFModulePtr, Elf_Word, Elf_Rel_t *);
|
|
|
|
static ELFCommonPtr ElfAddCOMMON(Elf_Sym *);
|
|
|
|
static int ElfCOMMONSize(void);
|
2003-11-25 20:29:01 +01:00
|
|
|
static int ElfCreateCOMMON(ELFModulePtr, LOOKUP *);
|
2003-11-14 17:48:57 +01:00
|
|
|
static char *ElfGetSymbolNameIndex(ELFModulePtr, int, int);
|
|
|
|
static char *ElfGetSymbolName(ELFModulePtr, int);
|
|
|
|
static Elf_Addr ElfGetSymbolValue(ELFModulePtr, int);
|
2003-11-25 20:29:01 +01:00
|
|
|
static ELFRelocPtr Elf_RelocateEntry(ELFModulePtr, Elf_Word, Elf_Rel_t *,
|
|
|
|
int);
|
2003-11-14 17:48:57 +01:00
|
|
|
static ELFRelocPtr ELFCollectRelocations(ELFModulePtr, int);
|
|
|
|
static LOOKUP *ELF_GetSymbols(ELFModulePtr, unsigned short **);
|
|
|
|
static void ELFCollectSections(ELFModulePtr, int, int *, int *);
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
|
|
|
static void ElfAddGOT(ELFModulePtr, Elf_Rel_t *);
|
|
|
|
static int ELFCreateGOT(ELFModulePtr, int);
|
|
|
|
#endif
|
|
|
|
#if defined(__ia64__)
|
|
|
|
static void ElfAddOPD(ELFModulePtr, int, LOOKUP *);
|
|
|
|
static void ELFCreateOPD(ELFModulePtr);
|
|
|
|
static void ElfAddPLT(ELFModulePtr, Elf_Rel_t *);
|
|
|
|
static void ELFCreatePLT(ELFModulePtr);
|
|
|
|
enum ia64_operand {
|
|
|
|
IA64_OPND_IMM22,
|
2003-11-25 20:29:01 +01:00
|
|
|
IA64_OPND_TGT25C,
|
|
|
|
IA64_OPND_LDXMOV
|
2003-11-14 17:48:57 +01:00
|
|
|
};
|
|
|
|
static void IA64InstallReloc(unsigned long *, int, enum ia64_operand, long);
|
|
|
|
#endif /*__ia64__*/
|
|
|
|
|
|
|
|
#ifdef MergeSectionAlloc
|
|
|
|
static void *
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFLoaderSectToMem(ELFModulePtr elffile, int align, unsigned long offset,
|
|
|
|
int size, char *label)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
void *ret;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->baseptr = (elffile->baseptr + align - 1) & ~(align - 1);
|
|
|
|
ret = (void *)elffile->baseptr;
|
|
|
|
_LoaderFileRead(elffile->fd, offset, ret, size);
|
|
|
|
elffile->baseptr += size;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFLoaderSectCalloc(ELFModulePtr elffile, int align, int size)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
void *ret;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->baseptr = (elffile->baseptr + align - 1) & ~(align - 1);
|
|
|
|
ret = (void *)elffile->baseptr;
|
|
|
|
elffile->baseptr += size;
|
|
|
|
#ifndef DoMMAPedMerge
|
2003-11-25 20:29:01 +01:00
|
|
|
memset(ret, 0, size); /* mmap() does this for us */
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else /* MergeSectionAlloc */
|
|
|
|
# define ELFLoaderSectToMem(elffile,align,offset,size,label) \
|
|
|
|
_LoaderFileToMem((elffile)->fd,offset,size,label)
|
|
|
|
# define ELFLoaderSectCalloc(elffile,align,size) xf86loadercalloc(1,size)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility Functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFhashCleanOut(void *voidptr, itemPtr item)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
ELFModulePtr module = (ELFModulePtr) voidptr;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
return (module->handle == item->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manage listResolv
|
|
|
|
*/
|
|
|
|
static ELFRelocPtr
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfDelayRelocation(ELFModulePtr elffile, Elf_Word secn, Elf_Rel_t *rel)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFRelocPtr reloc;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
if ((reloc = xf86loadermalloc(sizeof(ELFRelocRec))) == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ElfDelayRelocation() Unable to allocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
reloc->file = elffile;
|
|
|
|
reloc->secn = secn;
|
|
|
|
reloc->rel = rel;
|
|
|
|
reloc->next = 0;
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ElfDelayRelocation %p: file %p, sec %d,"
|
2003-11-14 17:48:57 +01:00
|
|
|
" r_offset 0x%lx, r_info 0x%x",
|
2003-11-25 20:29:01 +01:00
|
|
|
(void *)reloc, (void *)elffile, secn,
|
|
|
|
(unsigned long)rel->r_offset, rel->r_info);
|
2003-11-14 17:48:57 +01:00
|
|
|
# if defined(__powerpc__) || \
|
|
|
|
defined(__mc68000__) || \
|
|
|
|
defined(__alpha__) || \
|
|
|
|
defined(__sparc__) || \
|
|
|
|
defined(__ia64__) || \
|
2004-04-23 21:54:30 +02:00
|
|
|
defined(__amd64__)
|
2003-11-14 17:48:57 +01:00
|
|
|
ELFDEBUG(", r_addend 0x%lx", rel->r_addend);
|
|
|
|
# endif
|
|
|
|
ELFDEBUG("\n");
|
|
|
|
#endif
|
|
|
|
return reloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manage listCOMMON
|
|
|
|
*/
|
|
|
|
static ELFCommonPtr
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfAddCOMMON(Elf_Sym *sym)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
ELFCommonPtr common;
|
|
|
|
|
|
|
|
if ((common = xf86loadermalloc(sizeof(ELFCommonRec))) == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ElfAddCOMMON() Unable to allocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
common->sym = sym;
|
|
|
|
common->next = 0;
|
2003-11-14 17:48:57 +01:00
|
|
|
return common;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ElfCOMMONSize(void)
|
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
int size = 0;
|
2003-11-14 17:48:57 +01:00
|
|
|
ELFCommonPtr common;
|
|
|
|
|
|
|
|
for (common = listCOMMON; common; common = common->next) {
|
2003-11-25 20:29:01 +01:00
|
|
|
size += common->sym->st_size;
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__alpha__) || \
|
|
|
|
defined(__ia64__) || \
|
2004-04-23 21:54:30 +02:00
|
|
|
defined(__amd64__) || \
|
2003-11-14 17:48:57 +01:00
|
|
|
(defined(__sparc__) && \
|
|
|
|
(defined(__arch64__) || \
|
|
|
|
defined(__sparcv9)))
|
2003-11-25 20:29:01 +01:00
|
|
|
size = (size + 7) & ~0x7;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfCreateCOMMON(ELFModulePtr elffile, LOOKUP *pLookup)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
int numsyms = 0, size = 0, l = 0;
|
|
|
|
int offset = 0, firstcommon = 0;
|
2003-11-14 17:48:57 +01:00
|
|
|
ELFCommonPtr common;
|
|
|
|
|
|
|
|
if (listCOMMON == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (common = listCOMMON; common; common = common->next) {
|
2003-11-25 20:29:01 +01:00
|
|
|
size += common->sym->st_size;
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__alpha__) || \
|
|
|
|
defined(__ia64__) || \
|
2004-04-23 21:54:30 +02:00
|
|
|
defined(__amd64__) || \
|
2003-11-14 17:48:57 +01:00
|
|
|
(defined(__sparc__) && \
|
|
|
|
(defined(__arch64__) || \
|
|
|
|
defined(__sparcv9)))
|
2003-11-25 20:29:01 +01:00
|
|
|
size = (size + 7) & ~0x7;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
numsyms++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("ElfCreateCOMMON() %d entries (%d bytes) of COMMON data\n",
|
2003-11-25 20:29:01 +01:00
|
|
|
numsyms, size);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->comsize = size;
|
|
|
|
if ((elffile->common = ELFLoaderSectCalloc(elffile, 8, size)) == NULL) {
|
|
|
|
ErrorF("ElfCreateCOMMON() Unable to allocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if (DebuggerPresent) {
|
|
|
|
ldrCommons = xf86loadermalloc(numsyms * sizeof(LDRCommon));
|
2003-11-14 17:48:57 +01:00
|
|
|
nCommons = numsyms;
|
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
for (l = 0; pLookup[l].symName; l++) ;
|
|
|
|
firstcommon = l;
|
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
/* Traverse the common list and create a lookup table with all the
|
|
|
|
* common symbols. Destroy the common list in the process.
|
|
|
|
* See also ResolveSymbols.
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
while (listCOMMON) {
|
|
|
|
common = listCOMMON;
|
2003-11-14 17:48:57 +01:00
|
|
|
/* this is xstrdup because is should be more efficient. it is freed
|
|
|
|
* with xf86loaderfree
|
|
|
|
*/
|
|
|
|
pLookup[l].symName =
|
2003-11-25 20:29:01 +01:00
|
|
|
xf86loaderstrdup(ElfGetString(elffile, common->sym->st_name));
|
|
|
|
pLookup[l].offset = (funcptr) (elffile->common + offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("Adding common %p %s\n",
|
|
|
|
(void *)pLookup[l].offset, pLookup[l].symName);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
/* Record the symbol address for gdb */
|
2003-11-25 20:29:01 +01:00
|
|
|
if (DebuggerPresent && ldrCommons) {
|
|
|
|
ldrCommons[l - firstcommon].addr = (void *)pLookup[l].offset;
|
|
|
|
ldrCommons[l - firstcommon].name = pLookup[l].symName;
|
|
|
|
ldrCommons[l - firstcommon].namelen = strlen(pLookup[l].symName);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
listCOMMON = common->next;
|
|
|
|
offset += common->sym->st_size;
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__alpha__) || \
|
|
|
|
defined(__ia64__) || \
|
2004-04-23 21:54:30 +02:00
|
|
|
defined(__amd64__) || \
|
2003-11-14 17:48:57 +01:00
|
|
|
(defined(__sparc__) && \
|
|
|
|
(defined(__arch64__) || \
|
|
|
|
defined(__sparcv9)))
|
2003-11-25 20:29:01 +01:00
|
|
|
offset = (offset + 7) & ~0x7;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
xf86loaderfree(common);
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
/* listCOMMON == 0 */
|
2003-11-25 20:29:01 +01:00
|
|
|
pLookup[l].symName = NULL; /* Terminate the list. */
|
2003-11-14 17:48:57 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* String Table
|
|
|
|
*/
|
|
|
|
static char *
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfGetStringIndex(ELFModulePtr file, int offset, int index)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
if (!offset || !index)
|
|
|
|
return "";
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
return (char *)(file->saddr[index] + offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfGetString(ELFModulePtr file, int offset)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
return ElfGetStringIndex(file, offset, file->strndx);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfGetSectionName(ELFModulePtr file, int offset)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
return (char *)(file->shstraddr + offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Symbol Table
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get symbol name
|
|
|
|
*/
|
|
|
|
static char *
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfGetSymbolNameIndex(ELFModulePtr elffile, int index, int secndx)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *syms;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ElfGetSymbolNameIndex(%x,%x) ", index, secndx);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
syms = (Elf_Sym *) elffile->saddr[secndx];
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("%s ", ElfGetString(elffile, syms[index].st_name));
|
|
|
|
ELFDEBUG("%x %x ", ELF_ST_BIND(syms[index].st_info),
|
2003-11-14 17:48:57 +01:00
|
|
|
ELF_ST_TYPE(syms[index].st_info));
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("%lx\n", (unsigned long)syms[index].st_value);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
return ElfGetString(elffile, syms[index].st_name);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfGetSymbolName(ELFModulePtr elffile, int index)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
return ElfGetSymbolNameIndex(elffile, index, elffile->symndx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Elf_Addr
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfGetSymbolValue(ELFModulePtr elffile, int index)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *syms;
|
|
|
|
Elf_Addr symval = 0; /* value of the indicated symbol */
|
|
|
|
char *symname = NULL; /* name of symbol in relocation */
|
|
|
|
itemPtr symbol = NULL; /* name/value of symbol */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
syms = (Elf_Sym *) elffile->saddr[elffile->symndx];
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
switch (ELF_ST_TYPE(syms[index].st_info)) {
|
|
|
|
case STT_NOTYPE:
|
|
|
|
case STT_OBJECT:
|
|
|
|
case STT_FUNC:
|
|
|
|
switch (ELF_ST_BIND(syms[index].st_info)) {
|
|
|
|
case STB_LOCAL:
|
|
|
|
symval = (Elf_Addr) (elffile->saddr[syms[index].st_shndx] +
|
|
|
|
syms[index].st_value);
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef __ia64__
|
2003-11-25 20:29:01 +01:00
|
|
|
if (ELF_ST_TYPE(syms[index].st_info) == STT_FUNC) {
|
|
|
|
ELFOpdPtr opdent;
|
|
|
|
|
|
|
|
for (opdent = elffile->opd_entries; opdent;
|
|
|
|
opdent = opdent->next)
|
|
|
|
if (opdent->index == index)
|
|
|
|
break;
|
|
|
|
if (opdent) {
|
|
|
|
((unsigned long *)(elffile->got + opdent->offset))[0] =
|
|
|
|
symval;
|
|
|
|
((unsigned long *)(elffile->got + opdent->offset))[1] =
|
|
|
|
(long)elffile->got;
|
|
|
|
symval = (Elf_Addr) (elffile->got + opdent->offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
break;
|
2003-11-25 20:29:01 +01:00
|
|
|
case STB_GLOBAL:
|
|
|
|
case STB_WEAK: /* STB_WEAK seems like a hack to cover for
|
|
|
|
* some other problem */
|
|
|
|
symname = ElfGetString(elffile, syms[index].st_name);
|
|
|
|
symbol = LoaderHashFind(symname);
|
|
|
|
if (symbol == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
symval = (Elf_Addr) symbol->address;
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
|
|
|
default:
|
2003-11-25 20:29:01 +01:00
|
|
|
symval = 0;
|
|
|
|
ErrorF("ElfGetSymbolValue(), unhandled symbol scope %x\n",
|
|
|
|
ELF_ST_BIND(syms[index].st_info));
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
#ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("%p\t", (void *)symbol);
|
|
|
|
ELFDEBUG("%lx\t", (unsigned long)symval);
|
|
|
|
ELFDEBUG("%s\n", symname ? symname : "NULL");
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case STT_SECTION:
|
|
|
|
symval = (Elf_Addr) elffile->saddr[syms[index].st_shndx];
|
|
|
|
#ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("ST_SECTION %lx\n", (unsigned long)symval);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case STT_FILE:
|
|
|
|
case STT_LOPROC:
|
|
|
|
case STT_HIPROC:
|
|
|
|
default:
|
|
|
|
symval = 0;
|
|
|
|
ErrorF("ElfGetSymbolValue(), unhandled symbol type %x\n",
|
|
|
|
ELF_ST_TYPE(syms[index].st_info));
|
|
|
|
break;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
return symval;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__powerpc__)
|
|
|
|
/*
|
|
|
|
* This function returns the address of a pseudo PLT routine which can
|
|
|
|
* be used to compute a function offset. This is needed because loaded
|
|
|
|
* modules have an offset from the .text section of greater than 24 bits.
|
|
|
|
* The code generated makes the assumption that all function entry points
|
|
|
|
* will be within a 24 bit offset (non-PIC code).
|
|
|
|
*/
|
|
|
|
static Elf_Addr
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfGetPltAddr(ELFModulePtr elffile, int index)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *syms;
|
|
|
|
Elf_Addr symval = 0; /* value of the indicated symbol */
|
2003-11-14 17:48:57 +01:00
|
|
|
char *symname = NULL; /* name of symbol in relocation */
|
|
|
|
itemPtr symbol; /* name/value of symbol */
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
syms = (Elf_Sym *) elffile->saddr[elffile->symndx];
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
switch (ELF_ST_TYPE(syms[index].st_info)) {
|
|
|
|
case STT_NOTYPE:
|
|
|
|
case STT_OBJECT:
|
|
|
|
case STT_FUNC:
|
|
|
|
switch (ELF_ST_BIND(syms[index].st_info)) {
|
|
|
|
case STB_GLOBAL:
|
|
|
|
symname = ElfGetString(elffile, syms[index].st_name);
|
|
|
|
symbol = LoaderHashFind(symname);
|
|
|
|
if (symbol == 0)
|
|
|
|
return 0;
|
2003-11-14 17:48:57 +01:00
|
|
|
/*
|
|
|
|
* Here we are building up a pseudo Plt function that can make a call to
|
|
|
|
* a function that has an offset greater than 24 bits. The following code
|
|
|
|
* is being used to implement this.
|
|
|
|
|
|
|
|
1 00000000 .extern realfunc
|
|
|
|
2 00000000 .global pltfunc
|
|
|
|
3 00000000 pltfunc:
|
|
|
|
4 00000000 3d 80 00 00 lis r12,hi16(realfunc)
|
|
|
|
5 00000004 61 8c 00 00 ori r12,r12,lo16(realfunc)
|
|
|
|
6 00000008 7d 89 03 a6 mtctr r12
|
|
|
|
7 0000000c 4e 80 04 20 bctr
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
symbol->code.plt[0] = 0x3d80; /* lis r12 */
|
|
|
|
symbol->code.plt[1] =
|
|
|
|
(((Elf_Addr) symbol->address) & 0xffff0000) >> 16;
|
|
|
|
symbol->code.plt[2] = 0x618c; /* ori r12,r12 */
|
|
|
|
symbol->code.plt[3] = (((Elf_Addr) symbol->address) & 0xffff);
|
|
|
|
symbol->code.plt[4] = 0x7d89; /* mtcr r12 */
|
|
|
|
symbol->code.plt[5] = 0x03a6;
|
|
|
|
symbol->code.plt[6] = 0x4e80; /* bctr */
|
|
|
|
symbol->code.plt[7] = 0x0420;
|
|
|
|
symbol->address = (char *)&symbol->code.plt[0];
|
|
|
|
symval = (Elf_Addr) symbol->address;
|
|
|
|
ppc_flush_icache(&symbol->code.plt[0]);
|
|
|
|
ppc_flush_icache(&symbol->code.plt[6]);
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
|
|
|
default:
|
2003-11-25 20:29:01 +01:00
|
|
|
symval = 0;
|
|
|
|
ErrorF("ElfGetPltAddr(), unhandled symbol scope %x\n",
|
|
|
|
ELF_ST_BIND(syms[index].st_info));
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("ElfGetPlt: symbol=%lx\t", symbol);
|
|
|
|
ELFDEBUG("newval=%lx\t", symval);
|
|
|
|
ELFDEBUG("name=\"%s\"\n", symname ? symname : "NULL");
|
|
|
|
# endif
|
|
|
|
break;
|
|
|
|
case STT_SECTION:
|
|
|
|
case STT_FILE:
|
|
|
|
case STT_LOPROC:
|
|
|
|
case STT_HIPROC:
|
|
|
|
default:
|
|
|
|
symval = 0;
|
|
|
|
ErrorF("ElfGetPltAddr(), Unexpected symbol type %x",
|
|
|
|
ELF_ST_TYPE(syms[index].st_info));
|
|
|
|
ErrorF("for a Plt request\n");
|
|
|
|
break;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
return symval;
|
|
|
|
}
|
|
|
|
#endif /* __powerpc__ */
|
|
|
|
|
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
|
|
|
/*
|
|
|
|
* Manage GOT Entries
|
|
|
|
*/
|
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfAddGOT(ELFModulePtr elffile, Elf_Rel_t *rel)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
ELFGotEntryPtr gotent;
|
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *sym;
|
|
|
|
|
|
|
|
sym = (Elf_Sym *) & (elffile->symtab[ELF_R_SYM(rel->r_info)]);
|
|
|
|
if (sym->st_name) {
|
|
|
|
ELFDEBUG("ElfAddGOT: Adding GOT entry for %s\n",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
} else
|
|
|
|
ELFDEBUG("ElfAddGOT: Adding GOT entry for %s\n",
|
|
|
|
ElfGetSectionName(elffile,
|
|
|
|
elffile->sections[sym->st_shndx].
|
|
|
|
sh_name));
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
for (gotent = elffile->got_entries; gotent; gotent = gotent->next) {
|
|
|
|
if (ELF_R_SYM(gotent->rel->r_info) == ELF_R_SYM(rel->r_info) &&
|
|
|
|
gotent->rel->r_addend == rel->r_addend)
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if (gotent) {
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("Entry already present in GOT\n");
|
|
|
|
# endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((gotent = xf86loadermalloc(sizeof(ELFGotEntryRec))) == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ElfAddGOT() Unable to allocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("Entry added with offset %x\n", elffile->gotsize);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
gotent->rel = rel;
|
|
|
|
gotent->offset = elffile->gotsize;
|
|
|
|
gotent->next = elffile->got_entries;
|
|
|
|
elffile->got_entries = gotent;
|
|
|
|
elffile->gotsize += 8;
|
2003-11-14 17:48:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFCreateGOT(ELFModulePtr elffile, int maxalign)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
# ifdef MergeSectionAlloc
|
|
|
|
ELFGotPtr gots;
|
|
|
|
# endif
|
|
|
|
int gotsize;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: Is it REALLY needed to ensure GOT's are non-null?
|
|
|
|
*/
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ELFCreateGOT: %x entries in the GOT\n", elffile->gotsize / 8);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hmmm. Someone is getting here without any got entries, but they
|
|
|
|
* may still have R_ALPHA_GPDISP relocations against the got.
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
if (elffile->gotsize == 0)
|
|
|
|
ELFDEBUG("Module %s doesn't have any GOT entries!\n",
|
|
|
|
_LoaderModuleToName(elffile->module));
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
if (elffile->gotsize == 0)
|
|
|
|
elffile->gotsize = 8;
|
|
|
|
elffile->sections[elffile->gotndx].sh_size = elffile->gotsize;
|
2003-11-14 17:48:57 +01:00
|
|
|
gotsize = elffile->gotsize;
|
|
|
|
|
|
|
|
# ifdef MergeSectionAlloc
|
|
|
|
# ifdef __alpha__
|
|
|
|
# define GOTDistance 0x100000
|
|
|
|
# endif
|
|
|
|
# ifdef __ia64__
|
|
|
|
# define GOTDistance 0x200000
|
|
|
|
# endif
|
|
|
|
for (gots = ELFSharedGOTs; gots; gots = gots->next) {
|
|
|
|
if (gots->freeptr + elffile->gotsize > gots->section + gots->size)
|
|
|
|
continue;
|
|
|
|
if (gots->section > elffile->base) {
|
|
|
|
if (gots->section + gots->size - elffile->base >= GOTDistance)
|
|
|
|
continue;
|
|
|
|
} else {
|
2003-11-25 20:29:01 +01:00
|
|
|
if (elffile->base + elffile->basesize - gots->section >=
|
|
|
|
GOTDistance)
|
2003-11-14 17:48:57 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
elffile->got = gots->freeptr;
|
|
|
|
elffile->shared_got = gots;
|
|
|
|
gots->freeptr = gots->freeptr + elffile->gotsize;
|
|
|
|
gots->nuses++;
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ELFCreateGOT: GOT address %lx in shared GOT, nuses %d\n",
|
|
|
|
elffile->got, gots->nuses);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gotsize += 16383 + sizeof(ELFGotRec);
|
2003-11-25 20:29:01 +01:00
|
|
|
# endif /*MergeSectionAlloc */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
if ((elffile->got = xf86loadermalloc(gotsize)) == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ELFCreateGOT() Unable to allocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
# ifdef MergeSectionAlloc
|
|
|
|
if (elffile->got > elffile->base) {
|
|
|
|
if (elffile->got + elffile->gotsize - elffile->base >= GOTDistance)
|
|
|
|
gotsize = 0;
|
|
|
|
} else {
|
|
|
|
if (elffile->base + elffile->basesize - elffile->got >= GOTDistance)
|
|
|
|
gotsize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gotsize) {
|
|
|
|
xf86loaderfree(elffile->got);
|
|
|
|
# if !defined(DoMMAPedMerge)
|
|
|
|
elffile->basesize += 8 + elffile->gotsize;
|
|
|
|
elffile->base = xf86loaderrealloc(elffile->base, elffile->basesize);
|
|
|
|
if (elffile->base == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ELFCreateGOT() Unable to reallocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-10-30 22:33:43 +02:00
|
|
|
# if defined(linux) || defined(__OpenBSD__) || defined(sun)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
unsigned long page_size = getpagesize();
|
|
|
|
unsigned long round;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
round = (unsigned long)elffile->base & (page_size - 1);
|
|
|
|
mprotect(elffile->base - round,
|
|
|
|
(elffile->basesize + round + page_size -
|
|
|
|
1) & ~(page_size - 1),
|
|
|
|
PROT_READ | PROT_WRITE | PROT_EXEC);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
{
|
|
|
|
int oldbasesize = elffile->basesize;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->basesize += 8 + elffile->gotsize;
|
|
|
|
MMAP_ALIGN(elffile->basesize);
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->base = mremap(elffile->base, oldbasesize,
|
|
|
|
elffile->basesize, MREMAP_MAYMOVE);
|
2003-11-14 17:48:57 +01:00
|
|
|
if (elffile->base == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ELFCreateGOT() Unable to remap memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->baseptr =
|
|
|
|
((long)elffile->base + (maxalign - 1)) & ~(maxalign - 1);
|
|
|
|
elffile->got =
|
|
|
|
(unsigned char
|
|
|
|
*)((long)(elffile->base + elffile->basesize -
|
|
|
|
elffile->gotsize) & ~7);
|
2003-11-14 17:48:57 +01:00
|
|
|
} else {
|
2003-11-25 20:29:01 +01:00
|
|
|
gots = (ELFGotPtr) elffile->got;
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->got = gots->section;
|
|
|
|
gots->size = gotsize - sizeof(ELFGotRec) + 1;
|
|
|
|
gots->nuses = 1;
|
|
|
|
gots->freeptr = gots->section + elffile->gotsize;
|
|
|
|
gots->next = ELFSharedGOTs;
|
|
|
|
ELFSharedGOTs = gots;
|
|
|
|
elffile->shared_got = gots;
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ELFCreateGOT: Created a shareable GOT with size %d\n",
|
|
|
|
gots->size);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
# endif /*MergeSectionAlloc */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ELFCreateGOT: GOT address %lx\n", elffile->got);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
#endif /* defined(__alpha__) || defined(__ia64__) */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
#if defined(__ia64__)
|
|
|
|
/*
|
|
|
|
* Manage OPD Entries
|
|
|
|
*/
|
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfAddOPD(ELFModulePtr elffile, int index, LOOKUP *l)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
ELFOpdPtr opdent;
|
|
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
for (opdent = elffile->opd_entries; opdent; opdent = opdent->next)
|
|
|
|
if (opdent->index == index)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opdent = xf86loadermalloc(sizeof(ELFOpdRec))) == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ElfAddOPD() Unable to allocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("OPD Entry %d added with offset %x\n", index, elffile->gotsize);
|
|
|
|
# endif
|
|
|
|
opdent->l = l;
|
|
|
|
opdent->index = index;
|
|
|
|
opdent->offset = elffile->gotsize;
|
|
|
|
opdent->next = elffile->opd_entries;
|
|
|
|
elffile->opd_entries = opdent;
|
|
|
|
elffile->gotsize += 16;
|
|
|
|
return;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFCreateOPD(ELFModulePtr elffile)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
ELFOpdPtr opdent;
|
|
|
|
|
|
|
|
if (elffile->got == NULL)
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ELFCreateOPD() Unallocated GOT!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
for (opdent = elffile->opd_entries; opdent; opdent = opdent->next) {
|
|
|
|
if (opdent->index != -1)
|
|
|
|
continue;
|
2003-11-25 20:29:01 +01:00
|
|
|
((unsigned long *)(elffile->got + opdent->offset))[0] =
|
|
|
|
(long)opdent->l->offset;
|
|
|
|
((unsigned long *)(elffile->got + opdent->offset))[1] =
|
|
|
|
(long)elffile->got;
|
|
|
|
opdent->l->offset = (funcptr) (elffile->got + opdent->offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manage PLT Entries
|
|
|
|
*/
|
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfAddPLT(ELFModulePtr elffile, Elf_Rel_t *rel)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
ELFPltEntryPtr pltent;
|
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *sym;
|
|
|
|
|
|
|
|
sym = (Elf_Sym *) & (elffile->symtab[ELF_R_SYM(rel->r_info)]);
|
|
|
|
if (sym->st_name) {
|
|
|
|
ELFDEBUG("ElfAddPLT: Adding PLT entry for %s\n",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
} else
|
|
|
|
ErrorF("ElfAddPLT: Add PLT entry for section??\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
if (rel->r_addend)
|
|
|
|
ErrorF("ElfAddPLT: Add PLT entry with non-zero addend??\n");
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
for (pltent = elffile->plt_entries; pltent; pltent = pltent->next) {
|
|
|
|
if (ELF_R_SYM(pltent->rel->r_info) == ELF_R_SYM(rel->r_info))
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if (pltent) {
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("Entry already present in PLT\n");
|
|
|
|
# endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pltent = xf86loadermalloc(sizeof(ELFPltEntryRec))) == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("ElfAddPLT() Unable to allocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("Entry added with offset %x\n", elffile->pltsize);
|
|
|
|
# endif
|
|
|
|
pltent->rel = rel;
|
|
|
|
pltent->offset = elffile->pltsize;
|
|
|
|
pltent->gotoffset = elffile->gotsize;
|
|
|
|
pltent->next = elffile->plt_entries;
|
|
|
|
elffile->plt_entries = pltent;
|
|
|
|
elffile->pltsize += 32;
|
|
|
|
elffile->gotsize += 16;
|
|
|
|
return;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFCreatePLT(ELFModulePtr elffile)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ELFCreatePLT: %x entries in the PLT\n", elffile->pltsize / 8);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if (elffile->pltsize == 0)
|
|
|
|
return;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if ((elffile->plt =
|
|
|
|
ELFLoaderSectCalloc(elffile, 32, elffile->pltsize)) == NULL) {
|
|
|
|
ErrorF("ELFCreatePLT() Unable to allocate memory!!!!\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-10-30 22:33:43 +02:00
|
|
|
# if defined(linux) || defined(__OpenBSD__) || defined(sun)
|
2004-04-23 21:54:30 +02:00
|
|
|
{
|
|
|
|
unsigned long page_size = getpagesize();
|
|
|
|
unsigned long round;
|
|
|
|
|
|
|
|
round = (unsigned long)elffile->plt & (page_size - 1);
|
|
|
|
mprotect(elffile->plt - round,
|
|
|
|
(elffile->pltsize + round + page_size - 1) & ~(page_size - 1),
|
|
|
|
PROT_READ | PROT_WRITE | PROT_EXEC);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->sections[elffile->pltndx].sh_size = elffile->pltsize;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ELFCreatePLT: PLT address %lx\n", elffile->plt);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
IA64InstallReloc(unsigned long *data128, int slot, enum ia64_operand opnd,
|
|
|
|
long value)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
unsigned long data = 0;
|
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("\nIA64InstallReloc %p %d %d %016lx\n", data128, slot, opnd,
|
|
|
|
value);
|
|
|
|
ELFDEBUG("Before [%016lx%016lx]\n", data128[1], data128[0]);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
switch (slot) {
|
2003-11-25 20:29:01 +01:00
|
|
|
case 0:
|
|
|
|
data = *data128;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
memcpy(&data, (char *)data128 + 5, 8);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
memcpy(&data, (char *)data128 + 10, 6);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FatalError("Unexpected slot in IA64InstallReloc()\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
switch (opnd) {
|
|
|
|
case IA64_OPND_IMM22:
|
|
|
|
data &= ~(0x3fff9fc0000UL << slot);
|
2003-11-25 20:29:01 +01:00
|
|
|
data |= (value & 0x7f) << (18 + slot); /* [13:19] + 5 + slot */
|
2003-11-14 17:48:57 +01:00
|
|
|
data |= (value & 0xff80) << (25 + slot); /* [27:35] + 5 + slot */
|
|
|
|
data |= (value & 0x1f0000) << (11 + slot); /* [22:26] + 5 + slot */
|
|
|
|
data |= (value & 0x200000) << (20 + slot); /* [36:36] + 5 + slot */
|
|
|
|
if (value << 42 >> 42 != value)
|
|
|
|
ErrorF("Relocation %016lx truncated to fit into IMM22\n", value);
|
|
|
|
break;
|
|
|
|
case IA64_OPND_TGT25C:
|
|
|
|
data &= ~(0x23ffffc0000UL << slot);
|
|
|
|
data |= (value & 0xfffff0) << (14 + slot); /* [13:32] + 5 + slot */
|
|
|
|
data |= (value & 0x1000000) << (17 + slot); /* [36:36] + 5 + slot */
|
|
|
|
if (value << 39 >> 39 != value || (value & 0xf))
|
|
|
|
ErrorF("Relocation %016lx truncated to fit into TGT25C\n", value);
|
|
|
|
break;
|
2003-11-25 20:29:01 +01:00
|
|
|
#ifdef IA64_LDX_OPTIMIZATION
|
|
|
|
case IA64_OPND_LDXMOV:
|
|
|
|
/*
|
|
|
|
* Convert "ld8 t2=[t1]" to "mov t2=t1" which is really "add t2=0,t1"
|
|
|
|
* Mask all but the r3,r1,qp fields,
|
|
|
|
* then OR in the ALU opcode = 8 into the opcode field [40:37]
|
|
|
|
*
|
|
|
|
* Mask for the r3,r1,qp bit fields [26:20][12:6][5:0] = 0x7f01fff,
|
|
|
|
* This mask negated only within the 41 bit wide instruction and
|
|
|
|
* shifted left by 5 for the bundle template is 0x3FFF01FC0000
|
|
|
|
*
|
|
|
|
* opcode field [40:37] with a value of 8 is 0x10000000000
|
|
|
|
* shifted left by 5 for the bundle template is 0x200000000000
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
data &= ~(0x3FFF01FC0000 << slot);
|
|
|
|
data |= (0x200000000000 << slot);
|
|
|
|
break;
|
|
|
|
#endif
|
2003-11-14 17:48:57 +01:00
|
|
|
default:
|
|
|
|
FatalError("Unhandled operand in IA64InstallReloc()\n");
|
|
|
|
}
|
|
|
|
switch (slot) {
|
2003-11-25 20:29:01 +01:00
|
|
|
case 0:
|
|
|
|
*data128 = data;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
memcpy((char *)data128 + 5, &data, 8);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
memcpy((char *)data128 + 10, &data, 6);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FatalError("Unexpected slot in IA64InstallReloc()\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
ia64_flush_cache(data128);
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("After [%016lx%016lx]\n", data128[1], data128[0]);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /*__ia64__*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fix all of the relocations for the given section.
|
|
|
|
* If the argument 'force' is non-zero, then the relocation will be
|
|
|
|
* made even if the symbol can't be found (by substituting
|
|
|
|
* LoaderDefaultFunc) otherwise, the relocation will be deferred.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static ELFRelocPtr
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_RelocateEntry(ELFModulePtr elffile, Elf_Word secn, Elf_Rel_t *rel,
|
|
|
|
int force)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
unsigned char *secp = elffile->saddr[secn];
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
#if !defined(__ia64__)
|
|
|
|
unsigned int *dest32; /* address of the 32 bit place being modified */
|
|
|
|
#endif
|
|
|
|
#if defined(__powerpc__) || defined(__sparc__)
|
|
|
|
unsigned short *dest16; /* address of the 16 bit place being modified */
|
|
|
|
#endif
|
|
|
|
#if defined(__sparc__)
|
|
|
|
unsigned char *dest8; /* address of the 8 bit place being modified */
|
2003-11-25 20:29:01 +01:00
|
|
|
unsigned long *dest64;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
2003-11-25 20:29:01 +01:00
|
|
|
#if defined(__alpha__)
|
2003-11-14 17:48:57 +01:00
|
|
|
unsigned int *dest32h; /* address of the high 32 bit place being modified */
|
|
|
|
unsigned long *dest64;
|
|
|
|
unsigned short *dest16;
|
|
|
|
#endif
|
2004-04-23 21:54:30 +02:00
|
|
|
#if defined(__amd64__)
|
2003-11-14 17:48:57 +01:00
|
|
|
unsigned long *dest64;
|
|
|
|
int *dest32s;
|
|
|
|
#endif
|
|
|
|
#if defined(__ia64__)
|
|
|
|
unsigned long *dest64;
|
|
|
|
unsigned long *dest128;
|
|
|
|
#endif
|
|
|
|
Elf_Addr symval = 0; /* value of the indicated symbol */
|
|
|
|
|
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("%lx %d %d\n", (unsigned long)rel->r_offset,
|
|
|
|
ELF_R_SYM(rel->r_info), ELF_R_TYPE(rel->r_info));
|
2003-11-14 17:48:57 +01:00
|
|
|
# if defined(__powerpc__) || \
|
|
|
|
defined(__mc68000__) || \
|
|
|
|
defined(__alpha__) || \
|
|
|
|
defined(__sparc__) || \
|
|
|
|
defined(__ia64__) || \
|
2004-04-23 21:54:30 +02:00
|
|
|
defined(__amd64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("%lx", rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
ELFDEBUG("\n");
|
|
|
|
#endif /*ELFDEBUG*/
|
|
|
|
#if defined(__alpha__)
|
2003-11-25 20:29:01 +01:00
|
|
|
if (ELF_R_SYM(rel->r_info)
|
|
|
|
&& ELF_R_TYPE(rel->r_info) != R_ALPHA_GPDISP)
|
2003-11-14 17:48:57 +01:00
|
|
|
#else
|
2003-11-25 20:29:01 +01:00
|
|
|
if (ELF_R_SYM(rel->r_info))
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
symval = ElfGetSymbolValue(elffile, ELF_R_SYM(rel->r_info));
|
|
|
|
if (symval == 0) {
|
|
|
|
if (force) {
|
2003-11-25 20:29:01 +01:00
|
|
|
symval = (Elf_Addr) & LoaderDefaultFunc;
|
2003-11-14 17:48:57 +01:00
|
|
|
} else {
|
|
|
|
#ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("***Unable to resolve symbol %s\n",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
#endif
|
|
|
|
return ElfDelayRelocation(elffile, secn, rel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
switch (ELF_R_TYPE(rel->r_info)) {
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(i386)
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_386_32:
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_386_32\t");
|
|
|
|
ELFDEBUG("dest32=%p\t", (void *)dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", (unsigned int)*dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = symval + (*dest32); /* S + A */
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", (unsigned int)*dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_386_PC32:
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_386_PC32 %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%p\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", (unsigned long)symval);
|
|
|
|
ELFDEBUG("dest32=%p\t", (void *)dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", (unsigned int)*dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = symval + (*dest32) - (Elf_Addr) dest32; /* S + A - P */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", (unsigned int)*dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif /* i386 */
|
2004-04-23 21:54:30 +02:00
|
|
|
#if defined(__amd64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_X86_64_32:
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_X86_32\t");
|
|
|
|
ELFDEBUG("dest32=%x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8lx\t", *dest32);
|
|
|
|
ELFDEBUG("r_addend=%lx\t", rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = symval + rel->r_addend + (*dest32); /* S + A */
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8lx\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_X86_64_32S:
|
|
|
|
dest32s = (int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_X86_64_32\t");
|
|
|
|
ELFDEBUG("dest32s=%x\t", dest32s);
|
|
|
|
ELFDEBUG("*dest32s=%8.8lx\t", *dest32s);
|
|
|
|
ELFDEBUG("r_addend=%lx\t", rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32s = symval + rel->r_addend + (*dest32s); /* S + A */
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32s=%8.8lx\n", *dest32s);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_X86_64_PC32:
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_X86_64_PC32 %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest32=%x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8lx\t", *dest32);
|
|
|
|
ELFDEBUG("r_addend=%lx\t", rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = symval + rel->r_addend + (*dest32) - (Elf_Addr) dest32; /* S + A - P */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8lx\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_X86_64_64:
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_AMD64_64\t");
|
|
|
|
ELFDEBUG("dest64=%x\t", dest64);
|
|
|
|
ELFDEBUG("*dest64=%8.8lx\t", *dest64);
|
|
|
|
ELFDEBUG("r_addend=%lx\t", rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest64 = symval + rel->r_addend + (*dest64); /* S + A */
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest64=%8.8lx\n", *dest64);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
2004-04-23 21:54:30 +02:00
|
|
|
#endif /* __amd64__ */
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__alpha__)
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_ALPHA_NONE:
|
|
|
|
case R_ALPHA_LITUSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_ALPHA_REFQUAD:
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
symval = ElfGetSymbolValue(elffile, ELF_R_SYM(rel->r_info));
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("R_ALPHA_REFQUAD\t");
|
|
|
|
ELFDEBUG("dest64=%lx\t", dest64);
|
|
|
|
ELFDEBUG("*dest64=%8.8lx\t", *dest64);
|
|
|
|
# endif
|
|
|
|
*dest64 = symval + rel->r_addend + (*dest64); /* S + A + P */
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("*dest64=%8.8lx\n", *dest64);
|
|
|
|
# endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_ALPHA_GPREL32:
|
|
|
|
{
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
dest32 = (unsigned int *)dest64;
|
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("R_ALPHA_GPREL32 %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest32=%lx\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
symval += rel->r_addend;
|
2003-11-25 20:29:01 +01:00
|
|
|
symval = ((unsigned char *)symval) -
|
|
|
|
((unsigned char *)elffile->got);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
if ((symval & 0xffffffff00000000) != 0x0000000000000000 &&
|
|
|
|
(symval & 0xffffffff00000000) != 0xffffffff00000000) {
|
2003-11-14 17:48:57 +01:00
|
|
|
FatalError("R_ALPHA_GPREL32 symval-got is too large for %s\n",
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = symval;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
break;
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_ALPHA_GPRELLOW:
|
|
|
|
{
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
dest16 = (unsigned short *)dest64;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
symval += rel->r_addend;
|
2003-11-25 20:29:01 +01:00
|
|
|
symval = ((unsigned char *)symval) -
|
|
|
|
((unsigned char *)elffile->got);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest16 = symval;
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_ALPHA_GPRELHIGH:
|
|
|
|
{
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
dest16 = (unsigned short *)dest64;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
symval += rel->r_addend;
|
2003-11-25 20:29:01 +01:00
|
|
|
symval = ((unsigned char *)symval) -
|
|
|
|
((unsigned char *)elffile->got);
|
2003-11-14 17:48:57 +01:00
|
|
|
symval = ((long)symval >> 16) + ((symval >> 15) & 1);
|
2003-11-25 20:29:01 +01:00
|
|
|
if ((long)symval > 0x7fff || (long)symval < -(long)0x8000) {
|
|
|
|
FatalError
|
|
|
|
("R_ALPHA_GPRELHIGH symval-got is too large for %s:%lx\n",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)),
|
|
|
|
symval);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest16 = symval;
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_ALPHA_LITERAL:
|
|
|
|
{
|
2003-11-14 17:48:57 +01:00
|
|
|
ELFGotEntryPtr gotent;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_ALPHA_LITERAL %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest32=%lx\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
for (gotent = elffile->got_entries; gotent; gotent = gotent->next) {
|
|
|
|
if (ELF_R_SYM(gotent->rel->r_info) == ELF_R_SYM(rel->r_info)
|
|
|
|
&& gotent->rel->r_addend == rel->r_addend)
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the address in the GOT */
|
2003-11-25 20:29:01 +01:00
|
|
|
if (gotent) {
|
|
|
|
*(unsigned long *)(elffile->got + gotent->offset) =
|
|
|
|
symval + rel->r_addend;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("Setting gotent[%x]=%lx\t",
|
2003-11-25 20:29:01 +01:00
|
|
|
gotent->offset, symval + rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
if ((gotent->offset & 0xffff0000) != 0)
|
|
|
|
FatalError("\nR_ALPHA_LITERAL offset %x too large\n",
|
|
|
|
gotent->offset);
|
2003-11-25 20:29:01 +01:00
|
|
|
(*dest32) |= (gotent->offset); /* The address part is always 0 */
|
|
|
|
} else {
|
2003-11-14 17:48:57 +01:00
|
|
|
unsigned long val;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
/* S + A - P >> 2 */
|
2003-11-25 20:29:01 +01:00
|
|
|
val = ((symval + (rel->r_addend) - (Elf_Addr) dest32));
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A-P=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
if ((val & 0xffff0000) != 0xffff0000 &&
|
|
|
|
(val & 0xffff0000) != 0x00000000) {
|
2003-11-14 17:48:57 +01:00
|
|
|
ErrorF("\nR_ALPHA_LITERAL offset %x too large\n", val);
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
val &= 0x0000ffff;
|
2003-11-25 20:29:01 +01:00
|
|
|
(*dest32) |= (val); /* The address part is always 0 */
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
|
|
|
break;
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case R_ALPHA_GPDISP:
|
|
|
|
{
|
2003-11-14 17:48:57 +01:00
|
|
|
long offset;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
dest32h = (unsigned int *)(secp + rel->r_offset);
|
|
|
|
dest32 = (unsigned int *)((secp + rel->r_offset) + rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_ALPHA_GPDISP %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("got=%lx\t", elffile->got);
|
|
|
|
ELFDEBUG("dest32=%lx\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", *dest32);
|
|
|
|
ELFDEBUG("dest32h=%lx\t", dest32h);
|
|
|
|
ELFDEBUG("*dest32h=%8.8x\t", *dest32h);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
if ((*dest32h >> 26) != 9 || (*dest32 >> 26) != 8) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("***Bad instructions in relocating %s\n",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
symval = (*dest32h & 0xffff) << 16 | (*dest32 & 0xffff);
|
|
|
|
symval = (symval ^ 0x80008000) - 0x80008000;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
offset = ((unsigned char *)elffile->got -
|
|
|
|
(unsigned char *)dest32h);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("got-dest32=%lx\t", offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if ((offset >= 0x7fff8000L) || (offset < -0x80000000L)) {
|
|
|
|
FatalError("Offset overflow for R_ALPHA_GPDISP\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
symval += (unsigned long)offset;
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
# endif
|
|
|
|
*dest32 = (*dest32 & 0xffff0000) | (symval & 0xffff);
|
|
|
|
*dest32h = (*dest32h & 0xffff0000) |
|
|
|
|
(((symval >> 16) + ((symval >> 15) & 1)) & 0xffff);
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", *dest32);
|
|
|
|
ELFDEBUG("*dest32h=%8.8x\n", *dest32h);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case R_ALPHA_HINT:
|
|
|
|
dest32 = (unsigned int *)((secp + rel->r_offset) + rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_ALPHA_HINT %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest32=%lx\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
symval -= (Elf_Addr) (((unsigned char *)dest32) + 4);
|
|
|
|
if (symval % 4) {
|
|
|
|
ErrorF("R_ALPHA_HINT bad alignment of offset\n");
|
|
|
|
}
|
|
|
|
symval = symval >> 2;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if (symval & 0xffff8000) {
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_ALPHA_HINT symval too large\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
*dest32 = (*dest32 & ~0x3fff) | (symval & 0x3fff);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case R_ALPHA_GPREL16:
|
|
|
|
{
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
dest16 = (unsigned short *)dest64;
|
|
|
|
|
|
|
|
symval += rel->r_addend;
|
|
|
|
symval = ((unsigned char *)symval) -
|
|
|
|
((unsigned char *)elffile->got);
|
|
|
|
if ((long)symval > 0x7fff || (long)symval < -(long)0x8000) {
|
|
|
|
FatalError
|
|
|
|
("R_ALPHA_GPREL16 symval-got is too large for %s:%lx\n",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)),
|
|
|
|
symval);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest16 = symval;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif /* alpha */
|
|
|
|
#if defined(__mc68000__)
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_68K_32:
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_68K_32\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = symval + (rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = val; /* S + A */
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_68K_PC32:
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_68K_PC32\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
/* S + A - P */
|
|
|
|
val = symval + (rel->r_addend);
|
|
|
|
val -= *dest32;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A=%x\t", val);
|
|
|
|
ELFDEBUG("S+A-P=%x\t", val + (*dest32) - (Elf_Addr) dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = val + (*dest32) - (Elf_Addr) dest32; /* S + A - P */
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif /* __mc68000__ */
|
|
|
|
#if defined(__powerpc__)
|
|
|
|
# if defined(PowerMAX_OS)
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_PPC_DISP24: /* 11 */
|
|
|
|
dest32 = (unsigned long *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_DISP24 %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("dest32=%x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
/* S + A - P >> 2 */
|
|
|
|
val = ((symval + (rel->r_addend) - (Elf_Addr) dest32));
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A-P=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
val = val >> 2;
|
|
|
|
if ((val & 0x3f000000) != 0x3f000000 &&
|
|
|
|
(val & 0x3f000000) != 0x00000000) {
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_DISP24 offset %x too large\n", val << 2);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
symval = ElfGetPltAddr(elffile, ELF_R_SYM(rel->r_info));
|
|
|
|
val = ((symval + (rel->r_addend) - (Elf_Addr) dest32));
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("PLT offset is %x\n", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
val = val >> 2;
|
|
|
|
if ((val & 0x3f000000) != 0x3f000000 &&
|
|
|
|
(val & 0x3f000000) != 0x00000000)
|
|
|
|
FatalError("R_PPC_DISP24 PLT offset %x too large\n",
|
|
|
|
val << 2);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
val &= 0x00ffffff;
|
|
|
|
(*dest32) |= (val << 2); /* The address part is always 0 */
|
|
|
|
ppc_flush_icache(dest32);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_16HU: /* 31 */
|
|
|
|
dest16 = (unsigned short *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
dest32 = (unsigned long *)(dest16 - 1);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# endif
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_16HU\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest16=%x\t", dest16);
|
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned short val;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = ((symval + (rel->r_addend)) & 0xffff0000) >> 16;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("uhi16(S+A)=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest16 = val; /* S + A */
|
|
|
|
ppc_flush_icache(dest16);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_32: /* 32 */
|
|
|
|
dest32 = (unsigned long *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_32\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = symval + (rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = val; /* S + A */
|
|
|
|
ppc_flush_icache(dest32);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_32UA: /* 33 */
|
|
|
|
dest32 = (unsigned long *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_32UA\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
unsigned char *dest8 = (unsigned char *)dest32;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = symval + (rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest8++ = (val & 0xff000000) >> 24;
|
|
|
|
*dest8++ = (val & 0x00ff0000) >> 16;
|
|
|
|
*dest8++ = (val & 0x0000ff00) >> 8;
|
|
|
|
*dest8++ = (val & 0x000000ff);
|
|
|
|
ppc_flush_icache(dest32);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_16H: /* 34 */
|
|
|
|
dest16 = (unsigned short *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
dest32 = (unsigned long *)(dest16 - 1);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_16H\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symbol=%s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest16=%x\t", dest16);
|
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned short val;
|
|
|
|
unsigned short loval;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = ((symval + (rel->r_addend)) & 0xffff0000) >> 16;
|
|
|
|
loval = (symval + (rel->r_addend)) & 0xffff;
|
|
|
|
if (loval & 0x8000) {
|
|
|
|
/*
|
|
|
|
* This is hi16(), instead of uhi16(). Because of this,
|
|
|
|
* if the lo16() will produce a negative offset, then
|
|
|
|
* we have to increment this part of the address to get
|
|
|
|
* the correct final result.
|
|
|
|
*/
|
|
|
|
val++;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("hi16(S+A)=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest16 = val; /* S + A */
|
|
|
|
ppc_flush_icache(dest16);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_16L: /* 35 */
|
|
|
|
dest16 = (unsigned short *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
dest32 = (unsigned long *)(dest16 - 1);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_16L\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest16=%x\t", dest16);
|
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned short val;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = (symval + (rel->r_addend)) & 0xffff;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("lo16(S+A)=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest16 = val; /* S + A */
|
|
|
|
ppc_flush_icache(dest16);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
# else /* PowerMAX_OS */
|
2003-11-25 20:29:01 +01:00
|
|
|
/* Linux PPC */
|
|
|
|
case R_PPC_ADDR32: /* 1 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
|
|
|
symval = ElfGetSymbolValue(elffile, ELF_R_SYM(rel->r_info));
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_ADDR32\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = symval + (rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = val; /* S + A */
|
|
|
|
ppc_flush_icache(dest32);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_ADDR16_LO: /* 4 */
|
|
|
|
dest16 = (unsigned short *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
dest32 = (unsigned long *)(dest16 - 1);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_ADDR16_LO\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest16=%x\t", dest16);
|
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned short val;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = (symval + (rel->r_addend)) & 0xffff;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("lo16(S+A)=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest16 = val; /* S + A */
|
|
|
|
ppc_flush_icache(dest16);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_ADDR16_HA: /* 6 */
|
|
|
|
dest16 = (unsigned short *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
dest32 = (unsigned long *)(dest16 - 1);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_ADDR16_HA\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest16=%x\t", dest16);
|
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned short val;
|
|
|
|
unsigned short loval;
|
|
|
|
|
|
|
|
/* S + A */
|
|
|
|
val = ((symval + (rel->r_addend)) & 0xffff0000) >> 16;
|
|
|
|
loval = (symval + (rel->r_addend)) & 0xffff;
|
|
|
|
if (loval & 0x8000) {
|
|
|
|
/*
|
|
|
|
* This is hi16(), instead of uhi16(). Because of this,
|
|
|
|
* if the lo16() will produce a negative offset, then
|
|
|
|
* we have to increment this part of the address to get
|
|
|
|
* the correct final result.
|
|
|
|
*/
|
|
|
|
val++;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("hi16(S+A)=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest16 = val; /* S + A */
|
|
|
|
ppc_flush_icache(dest16);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest16=%8.8x\t", *dest16);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_REL24: /* 10 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_REL24 %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("dest32=%x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\t", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
/* S + A - P >> 2 */
|
|
|
|
val = ((symval + (rel->r_addend) - (Elf_Addr) dest32));
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A-P=%x\t", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
val = val >> 2;
|
|
|
|
if ((val & 0x3f000000) != 0x3f000000 &&
|
|
|
|
(val & 0x3f000000) != 0x00000000) {
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_REL24 offset %x too large\n", val << 2);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
symval = ElfGetPltAddr(elffile, ELF_R_SYM(rel->r_info));
|
|
|
|
val = ((symval + (rel->r_addend) - (Elf_Addr) dest32));
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("PLT offset is %x\n", val);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
val = val >> 2;
|
|
|
|
if ((val & 0x3f000000) != 0x3f000000 &&
|
|
|
|
(val & 0x3f000000) != 0x00000000)
|
|
|
|
FatalError("R_PPC_REL24 PLT offset %x too large\n",
|
|
|
|
val << 2);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
val &= 0x00ffffff;
|
|
|
|
(*dest32) |= (val << 2); /* The address part is always 0 */
|
|
|
|
ppc_flush_icache(dest32);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
case R_PPC_REL32: /* 26 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_PPC_REL32\t");
|
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%x\t", symval);
|
|
|
|
ELFDEBUG("r_addend=%x\t", rel->r_addend);
|
|
|
|
ELFDEBUG("dest32=%8.8x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
/* S + A - P */
|
|
|
|
val = symval + (rel->r_addend);
|
|
|
|
val -= *dest32;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("S+A=%x\t", val);
|
|
|
|
ELFDEBUG("S+A-P=%x\t", val + (*dest32) - (Elf_Addr) dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = val + (*dest32) - (Elf_Addr) dest32; /* S + A - P */
|
|
|
|
ppc_flush_icache(dest32);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8x\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
# endif /* PowerMAX_OS */
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif /* __powerpc__ */
|
|
|
|
#ifdef __sparc__
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_NONE: /* 0 */
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_8: /* 1 */
|
|
|
|
dest8 = (unsigned char *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest8 = symval;
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_16: /* 2 */
|
|
|
|
dest16 = (unsigned short *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest16 = symval;
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_32: /* 3 */
|
|
|
|
case R_SPARC_UA32: /* 23 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
((unsigned char *)dest32)[0] = (unsigned char)(symval >> 24);
|
|
|
|
((unsigned char *)dest32)[1] = (unsigned char)(symval >> 16);
|
|
|
|
((unsigned char *)dest32)[2] = (unsigned char)(symval >> 8);
|
|
|
|
((unsigned char *)dest32)[3] = (unsigned char)(symval);
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_GLOB_DAT: /* 20 */
|
|
|
|
case R_SPARC_64: /* 32 */
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest64 = symval;
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_DISP8: /* 4 */
|
|
|
|
dest8 = (unsigned char *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest8 = (symval - (Elf_Addr) dest8);
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_DISP16: /* 5 */
|
|
|
|
dest16 = (unsigned short *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest16 = (symval - (Elf_Addr) dest16);
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_DISP32: /* 6 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest32 = (symval - (Elf_Addr) dest32);
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_WDISP30: /* 7 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest32 = ((*dest32 & 0xc0000000) |
|
|
|
|
(((symval - (Elf_Addr) dest32) >> 2) & 0x3fffffff));
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_HI22: /* 9 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest32 = (*dest32 & 0xffc00000) | (symval >> 10);
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_LO10: /* 12 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
|
|
|
symval += rel->r_addend;
|
|
|
|
*dest32 = (*dest32 & ~0x3ff) | (symval & 0x3ff);
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_COPY: /* 19 */
|
|
|
|
/* Fix your code... I'd rather dish out an error here
|
|
|
|
* so people will not link together PIC and non-PIC
|
|
|
|
* code into a final driver object file.
|
|
|
|
*/
|
|
|
|
ErrorF("Elf_RelocateEntry():"
|
|
|
|
" Copy relocs not supported on Sparc.\n");
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_SPARC_JMP_SLOT: /* 21 */
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
|
|
|
/* Before we change it the PLT entry looks like:
|
|
|
|
*
|
|
|
|
* pltent: sethi %hi(rela_plt_offset), %g1
|
|
|
|
* b,a PLT0
|
|
|
|
* nop
|
|
|
|
*
|
|
|
|
* We change it into:
|
|
|
|
*
|
|
|
|
* pltent: sethi %hi(rela_plt_offset), %g1
|
|
|
|
* sethi %hi(symval), %g1
|
|
|
|
* jmp %g1 + %lo(symval), %g0
|
|
|
|
*/
|
|
|
|
symval += rel->r_addend;
|
|
|
|
dest32[2] = 0x81c06000 | (symval & 0x3ff);
|
|
|
|
__asm __volatile("flush %0 + 0x8"::"r"(dest32));
|
|
|
|
|
|
|
|
dest32[1] = 0x03000000 | (symval >> 10);
|
|
|
|
__asm __volatile("flush %0 + 0x4"::"r"(dest32));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_SPARC_RELATIVE: /* 22 */
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
*dest64 = (unsigned long)secp + rel->r_addend;
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif /*__sparc__*/
|
|
|
|
#ifdef __ia64__
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_IA64_NONE:
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_IA64_LTOFF_FPTR22:
|
|
|
|
if (rel->r_addend)
|
|
|
|
FatalError("\nAddend for R_IA64_LTOFF_FPTR22 not supported\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("opd=%016lx.%016lx\n",
|
|
|
|
((long *)symval)[0], ((long *)symval)[1]);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
case R_IA64_LTOFF22:
|
|
|
|
#ifndef IA64_LDX_OPTIMIZATION
|
|
|
|
case R_IA64_LTOFF22X: /* If not implementing LDXMOV optimization treat LTOFF22X as LTOFF22 */
|
|
|
|
#endif
|
|
|
|
{
|
2003-11-14 17:48:57 +01:00
|
|
|
ELFGotEntryPtr gotent;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
dest128 = (unsigned long *)(secp + (rel->r_offset & ~3));
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("%s %s\t", ELF_R_TYPE(rel->r_info) == R_IA64_LTOFF22 ?
|
|
|
|
"R_IA64_LTOFF22" : "R_IA64_LTOFF_FPTR22",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest128=%lx\t", dest128);
|
|
|
|
ELFDEBUG("slot=%d\n", rel->r_offset & 3);
|
|
|
|
ELFDEBUG("*dest128=[%016lx%016lx]\n", dest128[1], dest128[0]);
|
|
|
|
# endif
|
|
|
|
|
|
|
|
for (gotent = elffile->got_entries; gotent; gotent = gotent->next) {
|
|
|
|
if (ELF_R_SYM(gotent->rel->r_info) == ELF_R_SYM(rel->r_info)
|
|
|
|
&& gotent->rel->r_addend == rel->r_addend)
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the address in the GOT */
|
2003-11-25 20:29:01 +01:00
|
|
|
if (gotent) {
|
|
|
|
*(unsigned long *)(elffile->got + gotent->offset) =
|
|
|
|
symval + rel->r_addend;
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("Setting gotent[%x]=%lx\n",
|
2003-11-25 20:29:01 +01:00
|
|
|
gotent->offset, symval + rel->r_addend);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
if ((gotent->offset & 0xffe00000) != 0)
|
|
|
|
FatalError("\nR_IA64_LTOFF22 offset %x too large\n",
|
|
|
|
gotent->offset);
|
2003-11-25 20:29:01 +01:00
|
|
|
IA64InstallReloc(dest128, rel->r_offset & 3, IA64_OPND_IMM22,
|
|
|
|
gotent->offset);
|
|
|
|
} else
|
2003-11-14 17:48:57 +01:00
|
|
|
FatalError("\nCould not find GOT entry\n");
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_IA64_PCREL21B:
|
|
|
|
{
|
2003-11-14 17:48:57 +01:00
|
|
|
ELFPltEntryPtr pltent;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
dest128 = (unsigned long *)(secp + (rel->r_offset & ~3));
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_IA64_PCREL21B %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("opd=%lx.%lx\t", ((long *)symval)[0],
|
|
|
|
((long *)symval)[1]);
|
|
|
|
ELFDEBUG("dest128=%lx\t", dest128);
|
|
|
|
ELFDEBUG("slot=%d\n", rel->r_offset & 3);
|
|
|
|
ELFDEBUG("*dest128=[%016lx%016lx]\n", dest128[1], dest128[0]);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
if (rel->r_addend)
|
|
|
|
FatalError("\nAddend for PCREL21B not supported\n");
|
|
|
|
if (((long *)symval)[1] == (long)elffile->got
|
2003-11-25 20:29:01 +01:00
|
|
|
&& (((unsigned long)dest128 - ((unsigned long *)symval)[0]) +
|
|
|
|
0x2000000 < 0x4000000)) {
|
2003-11-14 17:48:57 +01:00
|
|
|
/* We can save the travel through PLT */
|
|
|
|
IA64InstallReloc(dest128, rel->r_offset & 3, IA64_OPND_TGT25C,
|
2003-11-25 20:29:01 +01:00
|
|
|
((unsigned long *)symval)[0] -
|
|
|
|
(unsigned long)dest128);
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
for (pltent = elffile->plt_entries; pltent; pltent = pltent->next) {
|
|
|
|
if (ELF_R_SYM(pltent->rel->r_info) == ELF_R_SYM(rel->r_info)
|
|
|
|
&& pltent->rel->r_addend == rel->r_addend)
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the address in the PLT */
|
|
|
|
if (pltent == NULL)
|
|
|
|
FatalError("\nCould not find PLT entry\n");
|
|
|
|
else {
|
2003-11-25 20:29:01 +01:00
|
|
|
unsigned long *p =
|
|
|
|
(unsigned long *)(elffile->plt + pltent->offset);
|
|
|
|
unsigned long r =
|
|
|
|
(unsigned long)symval - (unsigned long)elffile->got;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
if (r + 0x200000 >= 0x400000) {
|
2003-11-25 20:29:01 +01:00
|
|
|
/* Too far from gp to use the official function descriptor,
|
|
|
|
* so we have to make a local one.
|
|
|
|
*/
|
|
|
|
r = pltent->gotoffset;
|
|
|
|
memcpy(elffile->got + r, (char *)symval, 16);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [MMI] addl r15=NNN,r1;; ld8 r16=[r15],8; mov r14=r1;; */
|
|
|
|
p[0] = 0x410024000200780bUL;
|
|
|
|
p[1] = 0x84000801c028303cUL;
|
|
|
|
/* [MIB] ld8 r1=[r15]; mov b6=r16; br.few b6;; */
|
|
|
|
p[2] = 0x806010181e000811UL;
|
|
|
|
p[3] = 0x0080006000038004UL;
|
|
|
|
IA64InstallReloc(p, 0, IA64_OPND_IMM22, r);
|
|
|
|
IA64InstallReloc(dest128, rel->r_offset & 3, IA64_OPND_TGT25C,
|
|
|
|
(unsigned long)p - (unsigned long)dest128);
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_IA64_FPTR64LSB:
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("R_IA64_FPTR64LSB %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest64=%lx\t", dest64);
|
|
|
|
ELFDEBUG("opd=%016lx.%016lx\n", ((long *)symval)[0],
|
|
|
|
((long *)symval)[1]);
|
|
|
|
# endif
|
|
|
|
|
|
|
|
if (rel->r_addend)
|
|
|
|
FatalError("\nAddend not supported for R_IA64_FPTR64LSB\n");
|
|
|
|
*dest64 = symval;
|
|
|
|
ia64_flush_cache(dest64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_IA64_DIR64LSB:
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("R_IA64_DIR64LSB %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest64=%lx\n", dest64);
|
|
|
|
# endif
|
|
|
|
*dest64 = symval + rel->r_addend;
|
|
|
|
ia64_flush_cache(dest64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_IA64_PCREL64LSB:
|
|
|
|
dest64 = (unsigned long *)(secp + rel->r_offset);
|
|
|
|
#ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("R_IA64_PCREL64LSB %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest64=%lx\n", dest64);
|
|
|
|
#endif
|
|
|
|
*dest64 = symval + rel->r_addend - (unsigned long)dest64;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R_IA64_GPREL22:
|
|
|
|
dest128 = (unsigned long *)(secp + (rel->r_offset & ~3));
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("R_IA64_GPREL22 %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest128=%lx\t", dest128);
|
|
|
|
ELFDEBUG("slot=%d\n", rel->r_offset & 3);
|
|
|
|
ELFDEBUG("*dest128=[%016lx%016lx]\n", dest128[1], dest128[0]);
|
|
|
|
# endif
|
|
|
|
IA64InstallReloc(dest128, rel->r_offset & 3, IA64_OPND_IMM22,
|
|
|
|
symval + rel->r_addend - (long)elffile->got);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef IA64_LDX_OPTIMIZATION
|
|
|
|
case R_IA64_LTOFF22X:
|
|
|
|
{
|
|
|
|
ELFGotEntryPtr gotent;
|
|
|
|
long gp_offset = symval + rel->r_addend - (long)elffile->got;
|
|
|
|
|
|
|
|
dest128 = (unsigned long *)(secp + (rel->r_offset & ~3));
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_IA64_LTOFF22X %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest128=%lx\t", dest128);
|
|
|
|
ELFDEBUG("slot=%d\n", rel->r_offset & 3);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if (gp_offset << 42 >> 42 != gp_offset) {
|
|
|
|
/* Offset is too large for LTOFF22X,
|
|
|
|
* fallback to using GOT lookup, e.g. LTOFF22.
|
|
|
|
* Note: LDXMOV will fail the same test and will be ignored. */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("gp_offset=%ld too large, using GOT instead (LTOFF22)\n", gp_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
for (gotent = elffile->got_entries; gotent;
|
|
|
|
gotent = gotent->next) {
|
|
|
|
if (ELF_R_SYM(gotent->rel->r_info) ==
|
|
|
|
ELF_R_SYM(rel->r_info)
|
|
|
|
&& gotent->rel->r_addend == rel->r_addend)
|
|
|
|
break;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
/* Set the address in the GOT */
|
|
|
|
if (gotent) {
|
|
|
|
*(unsigned long *)(elffile->got + gotent->offset) =
|
|
|
|
symval + rel->r_addend;
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("Setting gotent[%x]=%lx\n", gotent->offset,
|
|
|
|
symval + rel->r_addend);
|
|
|
|
# endif
|
|
|
|
if ((gotent->offset & 0xffe00000) != 0)
|
|
|
|
FatalError("\nR_IA64_LTOFF22 offset %x too large\n",
|
|
|
|
gotent->offset);
|
|
|
|
} else {
|
|
|
|
FatalError("\nCould not find GOT entry\n");
|
|
|
|
}
|
|
|
|
gp_offset = gotent->offset; /* Use GOT lookup */
|
|
|
|
} else {
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("using gp_offset=%ld (LTOFF22X)", gp_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
IA64InstallReloc(dest128, rel->r_offset & 3, IA64_OPND_IMM22,
|
2003-11-25 20:29:01 +01:00
|
|
|
gp_offset);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case R_IA64_LDXMOV:
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("R_IA64_LDXMOV %s\t",
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
|
|
|
# endif
|
|
|
|
|
|
|
|
#ifdef IA64_LDX_OPTIMIZATION
|
|
|
|
{
|
|
|
|
long gp_offset = symval + rel->r_addend - (long)elffile->got;
|
|
|
|
|
|
|
|
dest128 = (unsigned long *)(secp + (rel->r_offset & ~3));
|
|
|
|
|
|
|
|
if (gp_offset << 42 >> 42 != gp_offset) {
|
|
|
|
/* Offset is too large for LTOFF22X, ignore this relocation */
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("offset = %ld too large, ignoring\n", gp_offset);
|
|
|
|
# endif
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("secp=%lx\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest128=%lx\t", dest128);
|
|
|
|
ELFDEBUG("slot=%d\n", rel->r_offset & 3);
|
|
|
|
ELFDEBUG("offset=%ld\n", gp_offset);
|
|
|
|
ELFDEBUG("*dest128=[%016lx%016lx]\n", dest128[1], dest128[0]);
|
|
|
|
# endif
|
|
|
|
|
|
|
|
IA64InstallReloc(dest128, rel->r_offset & 3, IA64_OPND_LDXMOV,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
#endif /*__ia64__*/
|
|
|
|
|
|
|
|
#if defined(__arm__)
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_ARM_ABS32:
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("R_ARM_ABS32\t");
|
|
|
|
ELFDEBUG("dest32=%x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8lx\t", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = symval + (*dest32); /* S + A */
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8lx\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_ARM_REL32:
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
{
|
2003-11-14 17:48:57 +01:00
|
|
|
char *namestr;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
ELFDEBUG("R_ARM_REL32 %s\t",
|
|
|
|
namestr =
|
|
|
|
ElfGetSymbolName(elffile, ELF_R_SYM(rel->r_info)));
|
2003-11-14 17:48:57 +01:00
|
|
|
xf86loaderfree(namestr);
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("secp=%x\t", secp);
|
|
|
|
ELFDEBUG("symval=%lx\t", symval);
|
|
|
|
ELFDEBUG("dest32=%x\t", dest32);
|
|
|
|
ELFDEBUG("*dest32=%8.8lx\t", *dest32);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
*dest32 = symval + (*dest32) - (Elf_Addr) dest32; /* S + A - P */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
# ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("*dest32=%8.8lx\n", *dest32);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
case R_ARM_PC24:
|
|
|
|
{
|
2003-11-14 17:48:57 +01:00
|
|
|
unsigned long val;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
dest32 = (unsigned int *)(secp + rel->r_offset);
|
2003-11-14 17:48:57 +01:00
|
|
|
val = (*dest32 & 0x00ffffff) << 2;
|
2003-11-25 20:29:01 +01:00
|
|
|
val = symval - (unsigned long)dest32 + val;
|
|
|
|
val >>= 2;
|
|
|
|
*dest32 = (*dest32 & 0xff000000) | (val & 0x00ffffff);
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef NOTYET
|
|
|
|
arm_flush_cache(dest32);
|
|
|
|
#endif
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
#endif /* (__arm__) */
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
default:
|
|
|
|
ErrorF("Elf_RelocateEntry() Unsupported relocation type %d\n",
|
|
|
|
(int)ELF_R_TYPE(rel->r_info));
|
|
|
|
break;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ELFRelocPtr
|
|
|
|
ELFCollectRelocations(elffile, index)
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFModulePtr elffile;
|
|
|
|
int index; /* The section to use as relocation data */
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
int i, numrel;
|
|
|
|
Elf_Shdr *sect = &(elffile->sections[index]);
|
|
|
|
Elf_Rel_t *rel = (Elf_Rel_t *) elffile->saddr[index];
|
2003-11-14 17:48:57 +01:00
|
|
|
ELFRelocPtr reloc_head = NULL;
|
|
|
|
ELFRelocPtr tmp;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
numrel = sect->sh_size / sect->sh_entsize;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
for (i = 0; i < numrel; i++) {
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__alpha__)
|
2003-11-25 20:29:01 +01:00
|
|
|
if (ELF_R_TYPE(rel[i].r_info) == R_ALPHA_LITERAL) {
|
|
|
|
ElfAddGOT(elffile, &rel[i]);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
#if defined(__ia64__)
|
|
|
|
if (ELF_R_TYPE(rel[i].r_info) == R_IA64_LTOFF22
|
2003-11-25 20:29:01 +01:00
|
|
|
|| ELF_R_TYPE(rel[i].r_info) == R_IA64_LTOFF22X
|
2003-11-14 17:48:57 +01:00
|
|
|
|| ELF_R_TYPE(rel[i].r_info) == R_IA64_LTOFF_FPTR22) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfAddGOT(elffile, &rel[i]);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
if (ELF_R_TYPE(rel[i].r_info) == R_IA64_PCREL21B) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ElfAddPLT(elffile, &rel[i]);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
if (ELF_R_TYPE(rel[i].r_info) == R_IA64_LTOFF_FPTR22
|
|
|
|
|| ELF_R_TYPE(rel[i].r_info) == R_IA64_FPTR64LSB) {
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *syms = (Elf_Sym *) elffile->saddr[elffile->symndx];
|
|
|
|
|
|
|
|
if (ELF_ST_BIND(syms[ELF_R_SYM(rel[i].r_info)].st_info) ==
|
|
|
|
STB_LOCAL) {
|
2003-11-14 17:48:57 +01:00
|
|
|
ElfAddOPD(elffile, ELF_R_SYM(rel[i].r_info), NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
tmp = ElfDelayRelocation(elffile, sect->sh_info, &(rel[i]));
|
|
|
|
tmp->next = reloc_head;
|
|
|
|
reloc_head = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return reloc_head;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ELF_GetSymbols()
|
|
|
|
*
|
|
|
|
* add the symbols to the symbol table maintained by the loader.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static LOOKUP *
|
2003-11-25 20:29:01 +01:00
|
|
|
ELF_GetSymbols(ELFModulePtr elffile, unsigned short **psecttable)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Sym *syms;
|
|
|
|
Elf_Shdr *sect;
|
|
|
|
int i, l, numsyms;
|
|
|
|
LOOKUP *lookup, *p;
|
2003-11-14 17:48:57 +01:00
|
|
|
ELFCommonPtr tmp;
|
|
|
|
unsigned short *secttable;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
syms = elffile->symtab;
|
|
|
|
sect = &(elffile->sections[elffile->symndx]);
|
|
|
|
numsyms = sect->sh_size / sect->sh_entsize;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if ((lookup = xf86loadermalloc((numsyms + 1) * sizeof(LOOKUP))) == NULL)
|
2003-11-14 17:48:57 +01:00
|
|
|
return 0;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if ((secttable =
|
|
|
|
xf86loadercalloc(sizeof(unsigned short), (numsyms + 1))) == NULL) {
|
2003-11-14 17:48:57 +01:00
|
|
|
xf86loaderfree(lookup);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*psecttable = secttable;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
for (i = 0, l = 0; i < numsyms; i++) {
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("value=%lx\tsize=%lx\tBIND=%x\tTYPE=%x\tndx=%x\t%s\n",
|
|
|
|
(unsigned long)syms[i].st_value,
|
|
|
|
(unsigned long)syms[i].st_size,
|
|
|
|
ELF_ST_BIND(syms[i].st_info), ELF_ST_TYPE(syms[i].st_info),
|
|
|
|
syms[i].st_shndx, ElfGetString(elffile, syms[i].st_name));
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if (ELF_ST_BIND(syms[i].st_info) == STB_LOCAL)
|
|
|
|
/* Don't add static symbols to the symbol table */
|
|
|
|
continue;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
switch (ELF_ST_TYPE(syms[i].st_info)) {
|
|
|
|
case STT_OBJECT:
|
|
|
|
case STT_FUNC:
|
|
|
|
case STT_SECTION:
|
|
|
|
case STT_NOTYPE:
|
|
|
|
switch (syms[i].st_shndx) {
|
|
|
|
case SHN_ABS:
|
|
|
|
ErrorF("ELF_GetSymbols() Don't know how to handle SHN_ABS\n");
|
|
|
|
break;
|
|
|
|
case SHN_COMMON:
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("Adding COMMON space for %s\n",
|
|
|
|
ElfGetString(elffile, syms[i].st_name));
|
|
|
|
#endif
|
|
|
|
if (!LoaderHashFind(ElfGetString(elffile, syms[i].st_name))) {
|
|
|
|
tmp = ElfAddCOMMON(&(syms[i]));
|
|
|
|
if (tmp) {
|
|
|
|
tmp->next = listCOMMON;
|
|
|
|
listCOMMON = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHN_UNDEF:
|
|
|
|
/*
|
|
|
|
* UNDEF will get resolved later, so the value
|
|
|
|
* doesn't really matter here.
|
|
|
|
*/
|
|
|
|
/* since we don't know the value don't advertise the symbol */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lookup[l].symName =
|
|
|
|
xf86loaderstrdup(ElfGetString
|
|
|
|
(elffile, syms[i].st_name));
|
|
|
|
lookup[l].offset = (funcptr) syms[i].st_value;
|
|
|
|
secttable[l] = syms[i].st_shndx;
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("Adding symbol %lx(%d) %s\n",
|
|
|
|
(unsigned long)lookup[l].offset, secttable[l],
|
|
|
|
lookup[l].symName);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
#ifdef __ia64__
|
2003-11-25 20:29:01 +01:00
|
|
|
if (ELF_ST_TYPE(syms[i].st_info) == STT_FUNC) {
|
|
|
|
ElfAddOPD(elffile, -1, &lookup[l]);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
2003-11-25 20:29:01 +01:00
|
|
|
l++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STT_FILE:
|
|
|
|
case STT_LOPROC:
|
|
|
|
case STT_HIPROC:
|
|
|
|
/* Skip this type */
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("Skipping TYPE %d %s\n",
|
|
|
|
ELF_ST_TYPE(syms[i].st_info),
|
|
|
|
ElfGetString(elffile, syms[i].st_name));
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
2003-11-25 20:29:01 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ErrorF("ELF_GetSymbols(): Unepected symbol type %d\n",
|
|
|
|
ELF_ST_TYPE(syms[i].st_info));
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
lookup[l].symName = NULL; /* Terminate the list */
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the ELF symbols that will show up in every object module.
|
|
|
|
*/
|
|
|
|
for (i = 0, p = lookup; p->symName; i++, p++) {
|
|
|
|
while (!strcmp(lookup[i].symName, ".text")
|
|
|
|
|| !strcmp(lookup[i].symName, ".data")
|
|
|
|
|| !strcmp(lookup[i].symName, ".bss")
|
|
|
|
|| !strcmp(lookup[i].symName, ".comment")
|
|
|
|
|| !strcmp(lookup[i].symName, ".note")
|
2003-11-25 20:29:01 +01:00
|
|
|
) {
|
|
|
|
memmove(&(lookup[i]), &(lookup[i + 1]), (l - i) * sizeof(LOOKUP));
|
|
|
|
memmove(&(secttable[i]), &(secttable[i + 1]),
|
|
|
|
(l-- - i) * sizeof(unsigned short));
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return lookup;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SecOffset(index) elffile->sections[index].sh_offset
|
|
|
|
#define SecSize(index) elffile->sections[index].sh_size
|
|
|
|
#define SecAlign(index) elffile->sections[index].sh_addralign
|
|
|
|
#define SecType(index) elffile->sections[index].sh_type
|
|
|
|
#define SecFlags(index) elffile->sections[index].sh_flags
|
|
|
|
#define SecInfo(index) elffile->sections[index].sh_info
|
|
|
|
|
|
|
|
#define AdjustSize(i) \
|
|
|
|
if (!pass) { \
|
|
|
|
if (SecAlign(i) > *maxalign) \
|
|
|
|
*maxalign = SecAlign(i); \
|
|
|
|
*totalsize += (SecAlign(i) - 1); \
|
|
|
|
*totalsize &= ~(SecAlign(i) - 1); \
|
|
|
|
*totalsize += SecSize(i); \
|
|
|
|
continue; \
|
|
|
|
} do { } while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ELFCollectSections
|
|
|
|
*
|
|
|
|
* Do the work required to load each section into memory.
|
|
|
|
*/
|
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFCollectSections(ELFModulePtr elffile, int pass, int *totalsize,
|
|
|
|
int *maxalign)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
int i;
|
2003-11-14 17:48:57 +01:00
|
|
|
int j;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
/*
|
|
|
|
* Find and identify all of the Sections
|
|
|
|
*/
|
|
|
|
j = elffile->lsectidx;
|
2003-11-25 20:29:01 +01:00
|
|
|
for (i = 1; i < elffile->numsh; i++) {
|
2003-11-14 17:48:57 +01:00
|
|
|
int flags = 0;
|
|
|
|
char *name = ElfGetSectionName(elffile, elffile->sections[i].sh_name);
|
|
|
|
|
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
if (!strcmp(name, ".got") /*Isn't there a more generic way to do this? */
|
2003-11-14 17:48:57 +01:00
|
|
|
# if defined(__ia64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
|| !strcmp(name, ".plt") || !strcmp(name, ".IA_64.unwind_info")
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
)
|
|
|
|
continue;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
switch (SecType(i)) {
|
|
|
|
case SHT_STRTAB:
|
2003-11-25 20:29:01 +01:00
|
|
|
if (!strcmp(name, ".shstrtab")) /* already loaded */
|
2003-11-14 17:48:57 +01:00
|
|
|
continue;
|
2003-11-25 20:29:01 +01:00
|
|
|
if (!strcmp(name, ".stabstr")) /* ignore debug info */
|
2003-11-14 17:48:57 +01:00
|
|
|
continue;
|
2004-04-23 21:54:30 +02:00
|
|
|
if (!strcmp(name, ".stab.indexstr")) /* ignore more debug info */
|
|
|
|
continue;
|
2003-11-14 17:48:57 +01:00
|
|
|
case SHT_SYMTAB:
|
2003-11-25 20:29:01 +01:00
|
|
|
if (pass)
|
|
|
|
continue;
|
2003-11-14 17:48:57 +01:00
|
|
|
flags = LOADED_SECTION;
|
|
|
|
flags |= RELOC_SECTION;
|
|
|
|
break;
|
|
|
|
case SHT_REL:
|
|
|
|
case SHT_RELA:
|
2003-11-25 20:29:01 +01:00
|
|
|
if (pass)
|
|
|
|
continue;
|
|
|
|
if (!(SecFlags(SecInfo(i)) & SHF_ALLOC))
|
|
|
|
continue;
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef __ia64__
|
|
|
|
if (SecType(SecInfo(i)) == SHT_IA_64_UNWIND)
|
2003-11-25 20:29:01 +01:00
|
|
|
continue;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
2003-11-25 20:29:01 +01:00
|
|
|
flags = LOADED_SECTION;
|
|
|
|
flags |= RELOC_SECTION;
|
|
|
|
break;
|
2003-11-14 17:48:57 +01:00
|
|
|
case SHT_PROGBITS:
|
|
|
|
flags |= LOADED_SECTION;
|
|
|
|
case SHT_NOBITS:
|
2003-11-25 20:29:01 +01:00
|
|
|
if (!(elffile->sections[i].sh_flags & SHF_ALLOC))
|
2003-11-14 17:48:57 +01:00
|
|
|
continue;
|
|
|
|
AdjustSize(i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef ELFDEBUG
|
|
|
|
if (pass)
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ELF: Not loading %s\n", name);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->lsection = xf86loaderrealloc(elffile->lsection,
|
2003-11-25 20:29:01 +01:00
|
|
|
(j + 1) * sizeof(LoadSection));
|
2003-11-14 17:48:57 +01:00
|
|
|
if (!(flags & RELOC_SECTION)) {
|
2003-11-25 20:29:01 +01:00
|
|
|
if (flags & LOADED_SECTION) {
|
|
|
|
elffile->lsection[j].saddr /* sect. contains data */
|
|
|
|
= ELFLoaderSectToMem(elffile, SecAlign(i),
|
|
|
|
SecOffset(i), SecSize(i), name);
|
2003-11-14 17:48:57 +01:00
|
|
|
} else {
|
2003-11-25 20:29:01 +01:00
|
|
|
if (SecSize(i))
|
|
|
|
elffile->lsection[j].saddr
|
|
|
|
= ELFLoaderSectCalloc(elffile, SecAlign(i),
|
|
|
|
SecSize(i));
|
|
|
|
else
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->lsection[j].saddr = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
elffile->lsection[j].saddr =
|
2003-11-25 20:29:01 +01:00
|
|
|
(Elf_Sym *) _LoaderFileToMem(elffile->fd, SecOffset(i),
|
|
|
|
SecSize(i), name);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->saddr[i] = elffile->lsection[j].saddr;
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("%s starts at %p size: %lx\n",
|
|
|
|
name, elffile->saddr[i], (unsigned long)SecSize(i));
|
|
|
|
#endif
|
|
|
|
elffile->lsection[j].name = name;
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->lsection[j].ndx = i;
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->lsection[j].size = SecSize(i);
|
|
|
|
elffile->lsection[j].flags = flags;
|
2003-11-14 17:48:57 +01:00
|
|
|
switch (SecType(i)) {
|
2004-10-30 22:33:43 +02:00
|
|
|
#if defined(linux) || defined(__OpenBSD__) || defined(sun)
|
2003-11-14 17:48:57 +01:00
|
|
|
case SHT_PROGBITS:
|
2004-04-23 21:54:30 +02:00
|
|
|
{
|
|
|
|
unsigned long page_size = getpagesize();
|
|
|
|
unsigned long round;
|
|
|
|
|
|
|
|
round = (unsigned long)elffile->lsection[j].saddr & (page_size -1);
|
|
|
|
mprotect( (char *)elffile->lsection[j].saddr - round,
|
|
|
|
SecSize(i) + round, PROT_READ | PROT_WRITE | PROT_EXEC);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case SHT_SYMTAB:
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->symtab = (Elf_Sym *) elffile->saddr[i];
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->symndx = i;
|
|
|
|
break;
|
|
|
|
case SHT_STRTAB:
|
|
|
|
elffile->straddr = elffile->saddr[i];
|
|
|
|
elffile->strsize = elffile->lsection[j].size;
|
|
|
|
elffile->strndx = i;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
elffile->lsectidx = ++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public API for the ELF implementation of the loader.
|
|
|
|
*/
|
|
|
|
void *
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFLoadModule(loaderPtr modrec, int elffd, LOOKUP **ppLookup)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
ELFModulePtr elffile;
|
2003-11-25 20:29:01 +01:00
|
|
|
Elf_Ehdr *header;
|
|
|
|
ELFRelocPtr elf_reloc, tail;
|
|
|
|
void *v;
|
2003-11-14 17:48:57 +01:00
|
|
|
LDRModulePtr elfmod;
|
2003-11-25 20:29:01 +01:00
|
|
|
int totalsize, maxalign, i;
|
2003-11-14 17:48:57 +01:00
|
|
|
unsigned short *secttable;
|
2003-11-25 20:29:01 +01:00
|
|
|
LOOKUP *pLookup;
|
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
ldrCommons = 0;
|
|
|
|
nCommons = 0;
|
|
|
|
|
|
|
|
#ifdef ELFDEBUG
|
|
|
|
ELFDEBUG("Loading %s %s\n", modrec->name, modrec->cname);
|
|
|
|
#endif
|
|
|
|
if ((elffile = xf86loadercalloc(1, sizeof(ELFModuleRec))) == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("Unable to allocate ELFModuleRec\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->handle = modrec->handle;
|
|
|
|
elffile->module = modrec->module;
|
|
|
|
elffile->fd = elffd;
|
|
|
|
v = elffile->funcs = modrec->funcs;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the ELF header
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->header =
|
|
|
|
(Elf_Ehdr *) _LoaderFileToMem(elffd, 0, sizeof(Elf_Ehdr),
|
|
|
|
"header");
|
|
|
|
header = (Elf_Ehdr *) elffile->header;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the section table
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->numsh = header->e_shnum;
|
|
|
|
elffile->secsize = (header->e_shentsize * header->e_shnum);
|
|
|
|
elffile->sections =
|
|
|
|
(Elf_Shdr *) _LoaderFileToMem(elffd, header->e_shoff,
|
|
|
|
elffile->secsize, "sections");
|
2003-11-14 17:48:57 +01:00
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
|
|
|
/*
|
|
|
|
* Need to allocate space for the .got section which will be
|
|
|
|
* fabricated later
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->gotndx = header->e_shnum;
|
2003-11-14 17:48:57 +01:00
|
|
|
header->e_shnum++;
|
|
|
|
# if defined(__ia64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->pltndx = header->e_shnum;
|
2003-11-14 17:48:57 +01:00
|
|
|
header->e_shnum++;
|
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->numsh = header->e_shnum;
|
|
|
|
elffile->secsize = (header->e_shentsize * header->e_shnum);
|
|
|
|
elffile->sections =
|
|
|
|
xf86loaderrealloc(elffile->sections, elffile->secsize);
|
|
|
|
#endif /*defined(__alpha__) || defined(__ia64__) */
|
|
|
|
elffile->saddr =
|
|
|
|
xf86loadercalloc(elffile->numsh, sizeof(unsigned char *));
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
|
|
|
/*
|
|
|
|
* Manually fill in the entry for the .got section so ELFCollectSections()
|
|
|
|
* will be able to find it.
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->sections[elffile->gotndx].sh_name =
|
|
|
|
SecSize(header->e_shstrndx) + 1;
|
|
|
|
elffile->sections[elffile->gotndx].sh_type = SHT_PROGBITS;
|
|
|
|
elffile->sections[elffile->gotndx].sh_flags = SHF_WRITE | SHF_ALLOC;
|
|
|
|
elffile->sections[elffile->gotndx].sh_size = 0;
|
|
|
|
elffile->sections[elffile->gotndx].sh_addralign = 8;
|
2003-11-14 17:48:57 +01:00
|
|
|
/* Add room to copy ".got", and maintain alignment */
|
2003-11-25 20:29:01 +01:00
|
|
|
SecSize(header->e_shstrndx) += 8;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
#if defined(__ia64__)
|
|
|
|
/*
|
|
|
|
* Manually fill in the entry for the .plt section so ELFCollectSections()
|
|
|
|
* will be able to find it.
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->sections[elffile->pltndx].sh_name =
|
|
|
|
SecSize(header->e_shstrndx) + 1;
|
|
|
|
elffile->sections[elffile->pltndx].sh_type = SHT_PROGBITS;
|
|
|
|
elffile->sections[elffile->pltndx].sh_flags = SHF_EXECINSTR | SHF_ALLOC;
|
|
|
|
elffile->sections[elffile->pltndx].sh_size = 0;
|
|
|
|
elffile->sections[elffile->pltndx].sh_addralign = 32;
|
2003-11-14 17:48:57 +01:00
|
|
|
/* Add room to copy ".plt", and maintain alignment */
|
2003-11-25 20:29:01 +01:00
|
|
|
SecSize(header->e_shstrndx) += 32;
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the section header string table
|
|
|
|
*/
|
|
|
|
elffile->shstrsize = SecSize(header->e_shstrndx);
|
|
|
|
elffile->shstraddr =
|
2003-11-25 20:29:01 +01:00
|
|
|
_LoaderFileToMem(elffd, SecOffset(header->e_shstrndx),
|
|
|
|
SecSize(header->e_shstrndx), ".shstrtab");
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->shstrndx = header->e_shstrndx;
|
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
|
|
|
/*
|
|
|
|
* Add the string for the .got section
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
strcpy((char *)(elffile->shstraddr +
|
|
|
|
elffile->sections[elffile->gotndx].sh_name), ".got");
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
#if defined(__ia64__)
|
|
|
|
/*
|
|
|
|
* Add the string for the .plt section
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
strcpy((char *)(elffile->shstraddr +
|
|
|
|
elffile->sections[elffile->pltndx].sh_name), ".plt");
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load some desired sections, compute size of the remaining ones
|
|
|
|
*/
|
|
|
|
totalsize = 0;
|
|
|
|
maxalign = 0;
|
|
|
|
ELFCollectSections(elffile, 0, &totalsize, &maxalign);
|
2003-11-25 20:29:01 +01:00
|
|
|
if (elffile->straddr == NULL || elffile->strsize == 0) {
|
2003-11-14 17:48:57 +01:00
|
|
|
#if 0
|
|
|
|
ErrorF("No symbols found in this module\n");
|
|
|
|
#endif
|
|
|
|
ELFUnloadModule(elffile);
|
2003-11-25 20:29:01 +01:00
|
|
|
return (void *)-1L;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* add symbols
|
|
|
|
*/
|
|
|
|
*ppLookup = pLookup = ELF_GetSymbols(elffile, §table);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do relocations
|
|
|
|
*/
|
|
|
|
for (i = 0; i < elffile->lsectidx; i++) {
|
|
|
|
switch (SecType(elffile->lsection[i].ndx)) {
|
|
|
|
case SHT_REL:
|
|
|
|
case SHT_RELA:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
elf_reloc = ELFCollectRelocations(elffile, elffile->lsection[i].ndx);
|
2003-11-14 17:48:57 +01:00
|
|
|
if (elf_reloc) {
|
2003-11-25 20:29:01 +01:00
|
|
|
for (tail = elf_reloc; tail->next; tail = tail->next) ;
|
2003-11-14 17:48:57 +01:00
|
|
|
tail->next = _LoaderGetRelocations(v)->elf_reloc;
|
|
|
|
_LoaderGetRelocations(v)->elf_reloc = elf_reloc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__ia64__)
|
|
|
|
totalsize += (elffile->sections[elffile->pltndx].sh_addralign - 1);
|
|
|
|
totalsize &= ~(elffile->sections[elffile->pltndx].sh_addralign - 1);
|
|
|
|
totalsize += elffile->pltsize;
|
|
|
|
if (maxalign < elffile->sections[elffile->pltndx].sh_addralign)
|
|
|
|
maxalign = elffile->sections[elffile->pltndx].sh_addralign;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Space for COMMON */
|
|
|
|
totalsize = (totalsize + 7) & ~7;
|
|
|
|
totalsize += ElfCOMMONSize();
|
|
|
|
|
|
|
|
#ifdef MergeSectionAlloc
|
|
|
|
elffile->basesize = totalsize + maxalign;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
# if !defined(DoMMAPedMerge)
|
|
|
|
elffile->base = xf86loadermalloc(elffile->basesize);
|
|
|
|
if (elffile->base == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("Unable to allocate ELF sections\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-10-30 22:33:43 +02:00
|
|
|
# if defined(linux) || defined(__OpenBSD__) || defined(sun)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
unsigned long page_size = getpagesize();
|
|
|
|
unsigned long round;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
round = (unsigned long)elffile->base & (page_size - 1);
|
|
|
|
mprotect(elffile->base - round,
|
|
|
|
(elffile->basesize + round + page_size - 1) & ~(page_size -
|
|
|
|
1),
|
|
|
|
PROT_READ | PROT_WRITE | PROT_EXEC);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
# else
|
2003-11-14 17:48:57 +01:00
|
|
|
MMAP_ALIGN(elffile->basesize);
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->base = mmap(0, elffile->basesize, MMAP_PROT, MMAP_FLAGS, -1,
|
|
|
|
(off_t) 0);
|
2003-11-14 17:48:57 +01:00
|
|
|
if (elffile->base == NULL) {
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorF("Unable to mmap ELF sections\n");
|
2003-11-14 17:48:57 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
elffile->baseptr =
|
|
|
|
((long)elffile->base + (maxalign - 1)) & ~(maxalign - 1);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
if (!ELFCreateGOT(elffile, maxalign))
|
2003-11-14 17:48:57 +01:00
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
#if defined(__ia64__)
|
|
|
|
ELFCreatePLT(elffile);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ELFCollectSections(elffile, 1, NULL, NULL);
|
|
|
|
|
|
|
|
for (i = 0; pLookup[i].symName; i++)
|
|
|
|
if (secttable[i]) {
|
2003-11-25 20:29:01 +01:00
|
|
|
pLookup[i].offset =
|
|
|
|
(funcptr) ((long)pLookup[i].offset +
|
|
|
|
(long)elffile->saddr[secttable[i]]);
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("Finalizing symbol %p %s\n",
|
|
|
|
(void *)pLookup[i].offset, pLookup[i].symName);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
xf86loaderfree(secttable);
|
|
|
|
|
|
|
|
#if defined(__ia64__)
|
|
|
|
ELFCreateOPD(elffile);
|
|
|
|
#endif
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
if (!ElfCreateCOMMON(elffile, *ppLookup))
|
2003-11-14 17:48:57 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Record info for gdb - if we can't allocate the loader record fail
|
2003-11-25 20:29:01 +01:00
|
|
|
* silently (the user will find out soon enough that there's no VM left */
|
2003-11-14 17:48:57 +01:00
|
|
|
if ((elfmod = xf86loadercalloc(1, sizeof(LDRModuleRec))) != NULL) {
|
|
|
|
elfmod->name = strdup(modrec->name);
|
|
|
|
elfmod->namelen = strlen(modrec->name);
|
|
|
|
elfmod->version = 1;
|
2003-11-25 20:29:01 +01:00
|
|
|
for (i = 0; i < elffile->lsectidx; i++) {
|
2003-11-14 17:48:57 +01:00
|
|
|
char *name = elffile->lsection[i].name;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
if (!strcmp(name, ".text"))
|
2003-11-14 17:48:57 +01:00
|
|
|
elfmod->text = elffile->lsection[i].saddr;
|
2003-11-25 20:29:01 +01:00
|
|
|
else if (!strcmp(name, ".data"))
|
2003-11-14 17:48:57 +01:00
|
|
|
elfmod->data = elffile->lsection[i].saddr;
|
2003-11-25 20:29:01 +01:00
|
|
|
else if (!strcmp(name, ".rodata"))
|
2003-11-14 17:48:57 +01:00
|
|
|
elfmod->rodata = elffile->lsection[i].saddr;
|
2003-11-25 20:29:01 +01:00
|
|
|
else if (!strcmp(name, ".bss"))
|
2003-11-14 17:48:57 +01:00
|
|
|
elfmod->bss = elffile->lsection[i].saddr;
|
|
|
|
}
|
|
|
|
elfmod->next = ModList;
|
|
|
|
elfmod->commons = ldrCommons;
|
|
|
|
elfmod->commonslen = nCommons;
|
|
|
|
|
|
|
|
ModList = elfmod;
|
|
|
|
|
|
|
|
/* Tell GDB something interesting happened */
|
|
|
|
_loader_debug_state();
|
|
|
|
}
|
|
|
|
return (void *)elffile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFResolveSymbols(void *mod)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
|
|
|
ELFRelocPtr newlist, p, tmp;
|
|
|
|
|
|
|
|
/* Try to relocate everything. Build a new list containing entries
|
|
|
|
* which we failed to relocate. Destroy the old list in the process.
|
|
|
|
*/
|
|
|
|
newlist = 0;
|
2003-11-25 20:29:01 +01:00
|
|
|
for (p = _LoaderGetRelocations(mod)->elf_reloc; p;) {
|
2003-11-14 17:48:57 +01:00
|
|
|
#ifdef ELFDEBUG
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFDEBUG("ResolveSymbols: "
|
|
|
|
"file %p, sec %d, r_offset 0x%x, r_info 0x%p\n",
|
|
|
|
(void *)p->file, p->secn, p->rel->r_offset,
|
|
|
|
(void *)p->rel->r_info);
|
2003-11-14 17:48:57 +01:00
|
|
|
#endif
|
|
|
|
tmp = Elf_RelocateEntry(p->file, p->secn, p->rel, FALSE);
|
|
|
|
if (tmp) {
|
|
|
|
/* Failed to relocate. Keep it in the list. */
|
|
|
|
tmp->next = newlist;
|
|
|
|
newlist = tmp;
|
|
|
|
}
|
|
|
|
tmp = p;
|
|
|
|
p = p->next;
|
|
|
|
xf86loaderfree(tmp);
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
_LoaderGetRelocations(mod)->elf_reloc = newlist;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFCheckForUnresolved(void *mod)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFRelocPtr erel;
|
|
|
|
char *name;
|
|
|
|
int flag, fatalsym = 0;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
|
|
|
if ((erel = _LoaderGetRelocations(mod)->elf_reloc) == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
while (erel) {
|
2003-11-14 17:48:57 +01:00
|
|
|
Elf_RelocateEntry(erel->file, erel->secn, erel->rel, TRUE);
|
|
|
|
name = ElfGetSymbolName(erel->file, ELF_R_SYM(erel->rel->r_info));
|
2003-11-25 20:29:01 +01:00
|
|
|
flag = _LoaderHandleUnresolved(name,
|
|
|
|
_LoaderHandleToName(erel->file->
|
|
|
|
handle));
|
|
|
|
if (flag)
|
|
|
|
fatalsym = 1;
|
|
|
|
erel = erel->next;
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
return fatalsym;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFUnloadModule(void *modptr)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFModulePtr elffile = (ELFModulePtr) modptr;
|
|
|
|
ELFRelocPtr relptr, reltptr, *brelptr;
|
2003-11-14 17:48:57 +01:00
|
|
|
int i;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
/*
|
|
|
|
* Delete any unresolved relocations
|
|
|
|
*/
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
relptr = _LoaderGetRelocations(elffile->funcs)->elf_reloc;
|
|
|
|
brelptr = &(_LoaderGetRelocations(elffile->funcs)->elf_reloc);
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
while (relptr) {
|
|
|
|
if (relptr->file == elffile) {
|
|
|
|
*brelptr = relptr->next; /* take it out of the list */
|
|
|
|
reltptr = relptr; /* save pointer to this node */
|
|
|
|
relptr = relptr->next; /* advance the pointer */
|
|
|
|
xf86loaderfree(reltptr); /* free the node */
|
|
|
|
} else {
|
|
|
|
brelptr = &(relptr->next);
|
|
|
|
relptr = relptr->next; /* advance the pointer */
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete any symbols in the symbols table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
LoaderHashTraverse((void *)elffile, ELFhashCleanOut);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the sections that were allocated.
|
|
|
|
*/
|
|
|
|
#if !defined (DoMMAPedMerge)
|
|
|
|
# define CheckandFree(ptr,size) if(ptr) xf86loaderfree(ptr)
|
2003-11-25 20:29:01 +01:00
|
|
|
#else
|
2003-11-14 17:48:57 +01:00
|
|
|
# define CheckandFree(ptr,size) if (ptr) munmap(ptr,size)
|
|
|
|
#endif
|
|
|
|
#define CheckandFreeFile(ptr,size) if(ptr) _LoaderFreeFileMem((ptr),(size))
|
|
|
|
|
|
|
|
#ifdef MergeSectionAlloc
|
2003-11-25 20:29:01 +01:00
|
|
|
CheckandFree(elffile->base, elffile->basesize);
|
2003-11-14 17:48:57 +01:00
|
|
|
# if defined(__alpha__) || defined(__ia64__)
|
|
|
|
if (elffile->shared_got) {
|
|
|
|
elffile->shared_got->nuses--;
|
|
|
|
if (!elffile->shared_got->nuses) {
|
|
|
|
ELFGotPtr *pgot = &ELFSharedGOTs;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
while (*pgot && *pgot != elffile->shared_got)
|
|
|
|
pgot = &(*pgot)->next;
|
|
|
|
if (*pgot)
|
|
|
|
*pgot = elffile->shared_got->next;
|
|
|
|
xf86loaderfree(elffile->shared_got);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
2003-11-25 20:29:01 +01:00
|
|
|
#else /*MergeSectionAlloc */
|
|
|
|
CheckandFree(elffile->common, elffile->comsize);
|
2003-11-14 17:48:57 +01:00
|
|
|
# if defined(__alpha__) || defined(__ia64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
CheckandFree(elffile->got, elffile->gotsize);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
# if defined(__ia64__)
|
2003-11-25 20:29:01 +01:00
|
|
|
CheckandFree(elffile->plt, elffile->pltsize);
|
2003-11-14 17:48:57 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
|
|
|
{
|
|
|
|
ELFGotEntryPtr gotent;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
|
|
|
while ((gotent = elffile->got_entries)) {
|
2003-11-14 17:48:57 +01:00
|
|
|
elffile->got_entries = gotent->next;
|
|
|
|
xf86loaderfree(gotent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(__ia64__)
|
|
|
|
{
|
|
|
|
ELFPltEntryPtr pltent;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
while ((pltent = elffile->plt_entries)) {
|
|
|
|
elffile->plt_entries = pltent->next;
|
|
|
|
xf86loaderfree(pltent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
ELFOpdPtr opdent;
|
2003-11-25 20:29:01 +01:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
while ((opdent = elffile->opd_entries)) {
|
|
|
|
elffile->opd_entries = opdent->next;
|
|
|
|
xf86loaderfree(opdent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < elffile->lsectidx; i++) {
|
|
|
|
#ifdef MergeSectionAlloc
|
|
|
|
if (!(elffile->lsection[i].flags & RELOC_SECTION))
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
if (elffile->lsection[i].flags & LOADED_SECTION) {
|
|
|
|
CheckandFreeFile(elffile->lsection[i].saddr,
|
|
|
|
elffile->lsection[i].size);
|
|
|
|
} else {
|
|
|
|
CheckandFree(elffile->lsection[i].saddr,
|
|
|
|
elffile->lsection[i].size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xf86loaderfree(elffile->lsection);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the section table, section pointer array, and section names
|
|
|
|
*/
|
2003-11-25 20:29:01 +01:00
|
|
|
_LoaderFreeFileMem(elffile->sections, elffile->secsize);
|
2003-11-14 17:48:57 +01:00
|
|
|
xf86loaderfree(elffile->saddr);
|
2003-11-25 20:29:01 +01:00
|
|
|
_LoaderFreeFileMem(elffile->header, sizeof(Elf_Ehdr));
|
|
|
|
_LoaderFreeFileMem(elffile->shstraddr, elffile->shstrsize);
|
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
/*
|
|
|
|
* Free the ELFModuleRec
|
|
|
|
*/
|
|
|
|
xf86loaderfree(elffile);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
ELFAddressToSection(void *modptr, unsigned long address)
|
|
|
|
{
|
2003-11-25 20:29:01 +01:00
|
|
|
ELFModulePtr elffile = (ELFModulePtr) modptr;
|
2003-11-14 17:48:57 +01:00
|
|
|
int i;
|
|
|
|
|
2003-11-25 20:29:01 +01:00
|
|
|
for (i = 1; i < elffile->numsh; i++) {
|
|
|
|
if (address >= (unsigned long)elffile->saddr[i] &&
|
|
|
|
address <= (unsigned long)elffile->saddr[i] + SecSize(i)) {
|
|
|
|
return ElfGetSectionName(elffile, elffile->sections[i].sh_name);
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
return NULL;
|
|
|
|
}
|