Kill a.out, COFF and ELF loaders with FIRE.
This commit is contained in:
		
							parent
							
								
									a3a4221495
								
							
						
					
					
						commit
						c946817748
					
				
							
								
								
									
										16
									
								
								ChangeLog
								
								
								
								
							
							
						
						
									
										16
									
								
								ChangeLog
								
								
								
								
							| 
						 | 
					@ -41,6 +41,22 @@
 | 
				
			||||||
	Ignore requests to load deprecated GLcore and speedo modules
 | 
						Ignore requests to load deprecated GLcore and speedo modules
 | 
				
			||||||
	(properly, this time).
 | 
						(properly, this time).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* hw/xfree86/loader/Makefile.am:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/loader.c:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/loader.h:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/ar.h:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/aout.h:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/aoutloader.h:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/aoutloader.c:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/coff.h:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/coffloader.h:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/coffloader.c:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/elf.h:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/elfloader.h:
 | 
				
			||||||
 | 
						* hw/xfree86/loader/elfloader.c:
 | 
				
			||||||
 | 
						Kill the a.out, ELF and COFF loaders with extreme prejudice.  Good
 | 
				
			||||||
 | 
						riddance.  There's more where this came from, too.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2006-05-30  Matthieu Herrb <matthieu.herrb@laas.fr>
 | 
					2006-05-30  Matthieu Herrb <matthieu.herrb@laas.fr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	* hw/xfree86/os-support/bsd/Makefile.am:
 | 
						* hw/xfree86/os-support/bsd/Makefile.am:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,18 +13,8 @@ if XORG_LOADER_SPARC
 | 
				
			||||||
SPARC_SOURCES = SparcMulDiv.S
 | 
					SPARC_SOURCES = SparcMulDiv.S
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sdk_HEADERS = \
 | 
					 | 
				
			||||||
	elf.h
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
EXTRA_DIST = \
 | 
					EXTRA_DIST = \
 | 
				
			||||||
	aout.h \
 | 
					 | 
				
			||||||
	aoutloader.h \
 | 
					 | 
				
			||||||
	ar.h \
 | 
					 | 
				
			||||||
	coff.h \
 | 
					 | 
				
			||||||
	coffloader.h \
 | 
					 | 
				
			||||||
	dlloader.h \
 | 
						dlloader.h \
 | 
				
			||||||
	elf.h \
 | 
					 | 
				
			||||||
	elfloader.h \
 | 
					 | 
				
			||||||
	hash.h \
 | 
						hash.h \
 | 
				
			||||||
	loader.h \
 | 
						loader.h \
 | 
				
			||||||
	loaderProcs.h \
 | 
						loaderProcs.h \
 | 
				
			||||||
| 
						 | 
					@ -37,10 +27,7 @@ libloader_a_SOURCES = \
 | 
				
			||||||
	loadext.c \
 | 
						loadext.c \
 | 
				
			||||||
        loadmod.c \
 | 
					        loadmod.c \
 | 
				
			||||||
	loadfont.c \
 | 
						loadfont.c \
 | 
				
			||||||
        aoutloader.c \
 | 
					 | 
				
			||||||
        dlloader.c \
 | 
					        dlloader.c \
 | 
				
			||||||
        elfloader.c \
 | 
					 | 
				
			||||||
        coffloader.c \
 | 
					 | 
				
			||||||
	os.c \
 | 
						os.c \
 | 
				
			||||||
	dixsym.c \
 | 
						dixsym.c \
 | 
				
			||||||
	extsym.c \
 | 
						extsym.c \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,235 +0,0 @@
 | 
				
			||||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/aout.h,v 1.7 2002/05/31 18:46:00 dawes Exp $ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Borrowed from NetBSD's exec_aout.h
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Copyright (c) 1993, 1994 Christopher G. Demetriou
 | 
					 | 
				
			||||||
 * All rights reserved.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Redistribution and use in source and binary forms, with or without
 | 
					 | 
				
			||||||
 * modification, are permitted provided that the following conditions
 | 
					 | 
				
			||||||
 * are met:
 | 
					 | 
				
			||||||
 * 1. Redistributions of source code must retain the above copyright
 | 
					 | 
				
			||||||
 *    notice, this list of conditions and the following disclaimer.
 | 
					 | 
				
			||||||
 * 2. Redistributions in binary form must reproduce the above copyright
 | 
					 | 
				
			||||||
 *    notice, this list of conditions and the following disclaimer in the
 | 
					 | 
				
			||||||
 *    documentation and/or other materials provided with the distribution.
 | 
					 | 
				
			||||||
 * 3. All advertising materials mentioning features or use of this software
 | 
					 | 
				
			||||||
 *    must display the following acknowledgement:
 | 
					 | 
				
			||||||
 *      This product includes software developed by Christopher G. Demetriou.
 | 
					 | 
				
			||||||
 * 4. The name of the author may not be used to endorse or promote products
 | 
					 | 
				
			||||||
 *    derived from this software without specific prior written permission
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 | 
					 | 
				
			||||||
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
					 | 
				
			||||||
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 | 
					 | 
				
			||||||
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 | 
					 | 
				
			||||||
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 | 
					 | 
				
			||||||
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
					 | 
				
			||||||
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
					 | 
				
			||||||
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
					 | 
				
			||||||
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 | 
					 | 
				
			||||||
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_XORG_CONFIG_H
 | 
					 | 
				
			||||||
#include <xorg-config.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef _AOUT_H
 | 
					 | 
				
			||||||
#define _AOUT_H
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <X11/Xos.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Get prototype for ntohl, per SuSv3. */
 | 
					 | 
				
			||||||
#include <arpa/inet.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* OS/2 EMX has ntohl in this file */
 | 
					 | 
				
			||||||
#ifdef __UNIXOS2__
 | 
					 | 
				
			||||||
#include <sys/param.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define __LDPGSZ        4096U
 | 
					 | 
				
			||||||
#ifndef AOUT_PAGSIZ
 | 
					 | 
				
			||||||
#define AOUT_PAGSIZ(ex)    (__LDPGSZ)
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* 
 | 
					 | 
				
			||||||
 * a.out  header 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
typedef struct AOUT_exec {
 | 
					 | 
				
			||||||
    unsigned long a_midmag;	/* htonl(flags<<26 | mid<<16 | magic) */
 | 
					 | 
				
			||||||
    unsigned long a_text;	/* text segment size */
 | 
					 | 
				
			||||||
    unsigned long a_data;	/* initialized data size */
 | 
					 | 
				
			||||||
    unsigned long a_bss;	/* uninitialized data size */
 | 
					 | 
				
			||||||
    unsigned long a_syms;	/* symbol table size */
 | 
					 | 
				
			||||||
    unsigned long a_entry;	/* entry point */
 | 
					 | 
				
			||||||
    unsigned long a_trsize;	/* text relocation size */
 | 
					 | 
				
			||||||
    unsigned long a_drsize;	/* data relocation size */
 | 
					 | 
				
			||||||
} AOUTHDR;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* a_magic */
 | 
					 | 
				
			||||||
#define OMAGIC          0407	/* old impure format */
 | 
					 | 
				
			||||||
#define NMAGIC          0410	/* read-only text */
 | 
					 | 
				
			||||||
#define ZMAGIC          0413	/* demand load format */
 | 
					 | 
				
			||||||
#define QMAGIC          0314	/* "compact" demand load format; deprecated */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * a_mid - keep sorted in numerical order for sanity's sake
 | 
					 | 
				
			||||||
 * ensure that: 0 < mid < 0x3ff
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define MID_ZERO        0	/* unknown - implementation dependent */
 | 
					 | 
				
			||||||
#define MID_SUN010      1	/* sun 68010/68020 binary */
 | 
					 | 
				
			||||||
#define MID_SUN020      2	/* sun 68020-only binary */
 | 
					 | 
				
			||||||
#define MID_PC386       100	/* 386 PC binary. (so quoth BFD) */
 | 
					 | 
				
			||||||
#define MID_HP200       200	/* hp200 (68010) BSD binary */
 | 
					 | 
				
			||||||
#define MID_I386        134	/* i386 BSD binary */
 | 
					 | 
				
			||||||
#define MID_M68K        135	/* m68k BSD binary with 8K page sizes */
 | 
					 | 
				
			||||||
#define MID_M68K4K      136	/* m68k BSD binary with 4K page sizes */
 | 
					 | 
				
			||||||
#define MID_NS32532     137	/* ns32532 */
 | 
					 | 
				
			||||||
#define MID_SPARC       138	/* sparc */
 | 
					 | 
				
			||||||
#define MID_PMAX        139	/* pmax */
 | 
					 | 
				
			||||||
#define MID_VAX         140	/* vax */
 | 
					 | 
				
			||||||
#define MID_ALPHA       141	/* Alpha BSD binary */
 | 
					 | 
				
			||||||
#define MID_MIPS        142	/* big-endian MIPS */
 | 
					 | 
				
			||||||
#define MID_ARM6        143	/* ARM6 */
 | 
					 | 
				
			||||||
#define MID_HP300       300	/* hp300 (68020+68881) BSD binary */
 | 
					 | 
				
			||||||
#define MID_HPUX        0x20C	/* hp200/300 HP-UX binary */
 | 
					 | 
				
			||||||
#define MID_HPUX800     0x20B	/* hp800 HP-UX binary */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * a_flags
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define EX_DYNAMIC      0x20
 | 
					 | 
				
			||||||
#define EX_PIC          0x10
 | 
					 | 
				
			||||||
#define EX_DPMASK       0x30
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Interpretation of the (a_flags & EX_DPMASK) bits:
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *      00              traditional executable or object file
 | 
					 | 
				
			||||||
 *      01              object file contains PIC code (set by `as -k')
 | 
					 | 
				
			||||||
 *      10              dynamic executable
 | 
					 | 
				
			||||||
 *      11              position independent executable image
 | 
					 | 
				
			||||||
 *                      (eg. a shared library)
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * The a.out structure's a_midmag field is a network-byteorder encoding
 | 
					 | 
				
			||||||
 * of this int
 | 
					 | 
				
			||||||
 *      FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
 | 
					 | 
				
			||||||
 * Where `F' is 6 bits of flag like EX_DYNAMIC,
 | 
					 | 
				
			||||||
 *       `m' is 10 bits of machine-id like MID_I386, and
 | 
					 | 
				
			||||||
 *       `M' is 16 bits worth of magic number, ie. ZMAGIC.
 | 
					 | 
				
			||||||
 * The macros below will set/get the needed fields.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define AOUT_GETMAGIC(ex) \
 | 
					 | 
				
			||||||
    ( (((ex)->a_midmag)&0xffff0000U) ? (ntohl(((ex)->a_midmag))&0xffffU) : ((ex)->a_midmag))
 | 
					 | 
				
			||||||
#define AOUT_GETMAGIC2(ex) \
 | 
					 | 
				
			||||||
    ( (((ex)->a_midmag)&0xffff0000U) ? (ntohl(((ex)->a_midmag))&0xffffU) : \
 | 
					 | 
				
			||||||
    (((ex)->a_midmag) | 0x10000) )
 | 
					 | 
				
			||||||
#define AOUT_GETMID(ex) \
 | 
					 | 
				
			||||||
    ( (((ex)->a_midmag)&0xffff0000U) ? ((ntohl(((ex)->a_midmag))>>16)&0x03ffU) : MID_ZERO )
 | 
					 | 
				
			||||||
#define AOUT_GETFLAG(ex) \
 | 
					 | 
				
			||||||
    ( (((ex)->a_midmag)&0xffff0000U) ? ((ntohl(((ex)->a_midmag))>>26)&0x3fU) : 0 )
 | 
					 | 
				
			||||||
#define AOUT_SETMAGIC(ex,mag,mid,flag) \
 | 
					 | 
				
			||||||
    ( (ex)->a_midmag = htonl( (((flag)&0x3fU)<<26) | (((mid)&0x03ffU)<<16) | \
 | 
					 | 
				
			||||||
    (((mag)&0xffffU)) ) )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define AOUT_ALIGN(ex,x) \
 | 
					 | 
				
			||||||
        (AOUT_GETMAGIC(ex) == ZMAGIC || AOUT_GETMAGIC(ex) == QMAGIC ? \
 | 
					 | 
				
			||||||
        ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Valid magic number check. */
 | 
					 | 
				
			||||||
#define AOUT_BADMAG(ex) \
 | 
					 | 
				
			||||||
        (AOUT_GETMAGIC(ex) != NMAGIC && AOUT_GETMAGIC(ex) != OMAGIC && \
 | 
					 | 
				
			||||||
        AOUT_GETMAGIC(ex) != ZMAGIC && AOUT_GETMAGIC(ex) != QMAGIC)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Address of the bottom of the text segment. */
 | 
					 | 
				
			||||||
#define AOUT_TXTADDR(ex)   (AOUT_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Address of the bottom of the data segment. */
 | 
					 | 
				
			||||||
#define AOUT_DATADDR(ex) \
 | 
					 | 
				
			||||||
        (AOUT_GETMAGIC(ex) == OMAGIC ? AOUT_TXTADDR(ex) + (ex)->a_text : \
 | 
					 | 
				
			||||||
        (AOUT_TXTADDR(ex) + (ex)->a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Address of the bottom of the bss segment. */
 | 
					 | 
				
			||||||
#define AOUT_BSSADDR(ex) \
 | 
					 | 
				
			||||||
        (AOUT_DATADDR(ex) + (ex)->a_data)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Text segment offset. */
 | 
					 | 
				
			||||||
#define AOUT_TXTOFF(ex) \
 | 
					 | 
				
			||||||
        ( AOUT_GETMAGIC2(ex)==ZMAGIC || AOUT_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
 | 
					 | 
				
			||||||
        0 : (AOUT_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \
 | 
					 | 
				
			||||||
        sizeof(struct AOUT_exec)) )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Data segment offset. */
 | 
					 | 
				
			||||||
#define AOUT_DATOFF(ex) \
 | 
					 | 
				
			||||||
        AOUT_ALIGN(ex, AOUT_TXTOFF(ex) + (ex)->a_text)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Text relocation table offset. */
 | 
					 | 
				
			||||||
#define AOUT_TRELOFF(ex) \
 | 
					 | 
				
			||||||
        (AOUT_DATOFF(ex) + (ex)->a_data)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Data relocation table offset. */
 | 
					 | 
				
			||||||
#define AOUT_DRELOFF(ex) \
 | 
					 | 
				
			||||||
        (AOUT_TRELOFF(ex) + (ex)->a_trsize)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Symbol table offset. */
 | 
					 | 
				
			||||||
#define AOUT_SYMOFF(ex) \
 | 
					 | 
				
			||||||
        (AOUT_DRELOFF(ex) + (ex)->a_drsize)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* String table offset. */
 | 
					 | 
				
			||||||
#define AOUT_STROFF(ex) \
 | 
					 | 
				
			||||||
        (AOUT_SYMOFF(ex) + (ex)->a_syms)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Relocation format. */
 | 
					 | 
				
			||||||
struct relocation_info_i386 {
 | 
					 | 
				
			||||||
    int r_address;		/* offset in text or data segment */
 | 
					 | 
				
			||||||
    unsigned int r_symbolnum:24,	/* ordinal number of add symbol */
 | 
					 | 
				
			||||||
        r_pcrel:1,		/* 1 if value should be pc-relative */
 | 
					 | 
				
			||||||
        r_length:2,		/* log base 2 of value's width */
 | 
					 | 
				
			||||||
        r_extern:1,		/* 1 if need to add symbol to value */
 | 
					 | 
				
			||||||
        r_baserel:1,		/* linkage table relative */
 | 
					 | 
				
			||||||
        r_jmptable:1,		/* relocate to jump table */
 | 
					 | 
				
			||||||
        r_relative:1,		/* load address relative */
 | 
					 | 
				
			||||||
        r_copy:1;		/* run time copy */
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define relocation_info relocation_info_i386
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Symbol table entry format.  The #ifdef's are so that programs including
 | 
					 | 
				
			||||||
 * nlist.h can initialize nlist structures statically.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
typedef struct AOUT_nlist {
 | 
					 | 
				
			||||||
    union {
 | 
					 | 
				
			||||||
	char *n_name;		/* symbol name (in memory) */
 | 
					 | 
				
			||||||
	long n_strx;		/* file string table offset (on disk) */
 | 
					 | 
				
			||||||
    } n_un;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define AOUT_UNDF  0x00		/* undefined */
 | 
					 | 
				
			||||||
#define AOUT_ABS   0x02		/* absolute address */
 | 
					 | 
				
			||||||
#define AOUT_TEXT  0x04		/* text segment */
 | 
					 | 
				
			||||||
#define AOUT_DATA  0x06		/* data segment */
 | 
					 | 
				
			||||||
#define AOUT_BSS   0x08		/* bss segment */
 | 
					 | 
				
			||||||
#define AOUT_INDR  0x0a		/* alias definition */
 | 
					 | 
				
			||||||
#define AOUT_SIZE  0x0c		/* pseudo type, defines a symbol's size */
 | 
					 | 
				
			||||||
#define AOUT_COMM  0x12		/* common reference */
 | 
					 | 
				
			||||||
#define AOUT_FN    0x1e		/* file name (AOUT_EXT on) */
 | 
					 | 
				
			||||||
#define AOUT_WARN  0x1e		/* warning message (AOUT_EXT off) */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define AOUT_EXT   0x01		/* external (global) bit, OR'ed in */
 | 
					 | 
				
			||||||
#define AOUT_TYPE  0x1e		/* mask for all the type bits */
 | 
					 | 
				
			||||||
    unsigned char n_type;	/* type defines */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    char n_other;		/* spare */
 | 
					 | 
				
			||||||
#define n_hash  n_desc		/* used internally by ld(1); XXX */
 | 
					 | 
				
			||||||
    short n_desc;		/* used by stab entries */
 | 
					 | 
				
			||||||
    unsigned long n_value;	/* address/value of the symbol */
 | 
					 | 
				
			||||||
} AOUT_nlist;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define AOUT_FORMAT        "%08x"	/* namelist value format; XXX */
 | 
					 | 
				
			||||||
#define AOUT_STAB          0x0e0	/* mask for debugger symbols -- stab(5) */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,866 +0,0 @@
 | 
				
			||||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/aoutloader.c,v 1.19 2003/10/15 16:58:34 dawes Exp $ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Copyright (c) 1997 Matthieu Herrb
 | 
					 | 
				
			||||||
 * Copyright 1995-1998 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.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Modified 21/02/97 by Sebastien Marineau to support OS/2 a.out objects
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#ifdef HAVE_XORG_CONFIG_H
 | 
					 | 
				
			||||||
#include <xorg-config.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <sys/types.h>
 | 
					 | 
				
			||||||
#include <sys/stat.h>
 | 
					 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
#include <stdlib.h>
 | 
					 | 
				
			||||||
#ifdef __QNX__
 | 
					 | 
				
			||||||
#include <fcntl.h>
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
#include <sys/fcntl.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#include <sys/stat.h>
 | 
					 | 
				
			||||||
#include <netinet/in.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef DBMALLOC
 | 
					 | 
				
			||||||
#include <debug/malloc.h>
 | 
					 | 
				
			||||||
#define Xalloc(size) malloc(size)
 | 
					 | 
				
			||||||
#define Xcalloc(size) calloc(1,(size))
 | 
					 | 
				
			||||||
#define Xfree(size) free(size)
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <X11/Xos.h>
 | 
					 | 
				
			||||||
#include "os.h"
 | 
					 | 
				
			||||||
#include "aout.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "sym.h"
 | 
					 | 
				
			||||||
#include "loader.h"
 | 
					 | 
				
			||||||
#include "aoutloader.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef LOADERDEBUG
 | 
					 | 
				
			||||||
#define LOADERDEBUG 0
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if LOADERDEBUG
 | 
					 | 
				
			||||||
#define AOUTDEBUG ErrorF
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef MIN
 | 
					 | 
				
			||||||
#define MIN(a,b) ((a)<(b)?(a):(b))
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * This structure contains all of the information about a module
 | 
					 | 
				
			||||||
 * that has been loaded.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
    int handle;
 | 
					 | 
				
			||||||
    int module;
 | 
					 | 
				
			||||||
    int fd;
 | 
					 | 
				
			||||||
    loader_funcs *funcs;
 | 
					 | 
				
			||||||
    AOUTHDR *header;		/* file header */
 | 
					 | 
				
			||||||
    unsigned char *text;	/* Start address of the text section */
 | 
					 | 
				
			||||||
    unsigned int textsize;	/* Size of the text section */
 | 
					 | 
				
			||||||
    unsigned char *data;	/* Start address of the data section */
 | 
					 | 
				
			||||||
    unsigned int datasize;	/* Size of the data section */
 | 
					 | 
				
			||||||
    unsigned char *bss;		/* Start address of the bss data */
 | 
					 | 
				
			||||||
    unsigned int bsssize;	/* Size of the bss section */
 | 
					 | 
				
			||||||
    struct relocation_info *txtrel;	/* Start address of the text relocation table */
 | 
					 | 
				
			||||||
    struct relocation_info *datarel;	/* Start address of the data relocation table */
 | 
					 | 
				
			||||||
    AOUT_nlist *symtab;		/* Start address of the symbol table */
 | 
					 | 
				
			||||||
    unsigned char *strings;	/* Start address of the string table */
 | 
					 | 
				
			||||||
    unsigned long strsize;	/* size of string table */
 | 
					 | 
				
			||||||
    unsigned char *common;	/* Start address of the common data */
 | 
					 | 
				
			||||||
    unsigned long comsize;	/* size of common data */
 | 
					 | 
				
			||||||
} AOUTModuleRec, *AOUTModulePtr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * If an relocation is unable to be satisfied, then put it on a list
 | 
					 | 
				
			||||||
 * to try later after more modules have been loaded.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
typedef struct AOUT_RELOC {
 | 
					 | 
				
			||||||
    AOUTModulePtr file;
 | 
					 | 
				
			||||||
    struct relocation_info *rel;
 | 
					 | 
				
			||||||
    int type;			/* AOUT_TEXT or AOUT_DATA */
 | 
					 | 
				
			||||||
    struct AOUT_RELOC *next;
 | 
					 | 
				
			||||||
} AOUTRelocRec;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Symbols with a section number of 0 (N_UNDF) but a value of non-zero
 | 
					 | 
				
			||||||
 * need to have space allocated for them.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Gather all of these symbols together, and allocate one chunk when we
 | 
					 | 
				
			||||||
 * are done.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct AOUT_COMMON {
 | 
					 | 
				
			||||||
    struct AOUT_nlist *sym;
 | 
					 | 
				
			||||||
    int index;
 | 
					 | 
				
			||||||
    struct AOUT_COMMON *next;
 | 
					 | 
				
			||||||
} AOUTCommonRec;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static AOUTCommonPtr listCOMMON = NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* prototypes for static functions */
 | 
					 | 
				
			||||||
static int AOUTHashCleanOut(void *, itemPtr);
 | 
					 | 
				
			||||||
static char *AOUTGetSymbolName(AOUTModulePtr, struct AOUT_nlist *);
 | 
					 | 
				
			||||||
static void *AOUTGetSymbolValue(AOUTModulePtr, int);
 | 
					 | 
				
			||||||
static AOUTCommonPtr AOUTAddCommon(struct AOUT_nlist *, int);
 | 
					 | 
				
			||||||
static LOOKUP *AOUTCreateCommon(AOUTModulePtr);
 | 
					 | 
				
			||||||
static LOOKUP *AOUT_GetSymbols(AOUTModulePtr);
 | 
					 | 
				
			||||||
static AOUTRelocPtr AOUTDelayRelocation(AOUTModulePtr, int,
 | 
					 | 
				
			||||||
					struct relocation_info_i386 *);
 | 
					 | 
				
			||||||
static AOUTRelocPtr AOUTCollectRelocations(AOUTModulePtr);
 | 
					 | 
				
			||||||
static void AOUT_Relocate(unsigned long *, unsigned long, int);
 | 
					 | 
				
			||||||
static AOUTRelocPtr AOUT_RelocateEntry(AOUTModulePtr, int,
 | 
					 | 
				
			||||||
				       struct relocation_info_i386 *);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Return 1 if the symbol in item belongs to aoutfile
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static int
 | 
					 | 
				
			||||||
AOUTHashCleanOut(void *voidptr, itemPtr item)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTModulePtr aoutfile = (AOUTModulePtr) voidptr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return (aoutfile->handle == item->handle);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Manage listResolv 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static AOUTRelocPtr
 | 
					 | 
				
			||||||
AOUTDelayRelocation(AOUTModulePtr aoutfile, int type,
 | 
					 | 
				
			||||||
		    struct relocation_info *rel)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTRelocPtr reloc;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if ((reloc = xf86loadermalloc(sizeof(AOUTRelocRec))) == NULL) {
 | 
					 | 
				
			||||||
	ErrorF("AOUTDelayRelocation() Unable to allocate memory\n");
 | 
					 | 
				
			||||||
	return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if ((unsigned long)rel < 0x200) {
 | 
					 | 
				
			||||||
	ErrorF("bug");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    reloc->file = aoutfile;
 | 
					 | 
				
			||||||
    reloc->type = type;
 | 
					 | 
				
			||||||
    reloc->rel = rel;
 | 
					 | 
				
			||||||
    reloc->next = 0;
 | 
					 | 
				
			||||||
    return reloc;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Manage listCOMMON
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static AOUTCommonPtr
 | 
					 | 
				
			||||||
AOUTAddCommon(struct AOUT_nlist *sym, int index)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTCommonPtr common;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if ((common = xf86loadermalloc(sizeof(AOUTCommonRec))) == NULL) {
 | 
					 | 
				
			||||||
	ErrorF("AOUTAddCommon() Unable to allocate memory\n");
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    common->sym = sym;
 | 
					 | 
				
			||||||
    common->index = index;
 | 
					 | 
				
			||||||
    common->next = 0;
 | 
					 | 
				
			||||||
    return common;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static LOOKUP *
 | 
					 | 
				
			||||||
AOUTCreateCommon(AOUTModulePtr aoutfile)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int numsyms = 0, size = 0, l = 0;
 | 
					 | 
				
			||||||
    int offset = 0;
 | 
					 | 
				
			||||||
    AOUTCommonPtr common;
 | 
					 | 
				
			||||||
    LOOKUP *lookup;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (listCOMMON == NULL)
 | 
					 | 
				
			||||||
	return NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    common = listCOMMON;
 | 
					 | 
				
			||||||
    for (common = listCOMMON; common; common = common->next) {
 | 
					 | 
				
			||||||
	/* Ensure long word alignment */
 | 
					 | 
				
			||||||
	if ((common->sym->n_value & (sizeof(long) - 1)) != 0)
 | 
					 | 
				
			||||||
	    common->sym->n_value = (common->sym->n_value + (sizeof(long) - 1))
 | 
					 | 
				
			||||||
		    & ~(sizeof(long) - 1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* accumulate the sizes */
 | 
					 | 
				
			||||||
	size += common->sym->n_value;
 | 
					 | 
				
			||||||
	numsyms++;
 | 
					 | 
				
			||||||
    }				/* while */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
    AOUTDEBUG("AOUTCreateCommon() %d entries (%d bytes) of COMMON data\n",
 | 
					 | 
				
			||||||
	      numsyms, size);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if ((lookup = xf86loadermalloc((numsyms + 1) * sizeof(LOOKUP))) == NULL) {
 | 
					 | 
				
			||||||
	ErrorF("AOUTCreateCommon() Unable to allocate memory\n");
 | 
					 | 
				
			||||||
	return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    aoutfile->comsize = size;
 | 
					 | 
				
			||||||
    if ((aoutfile->common = xf86loadercalloc(1, size)) == NULL) {
 | 
					 | 
				
			||||||
	ErrorF("AOUTCreateCommon() Unable to allocate memory\n");
 | 
					 | 
				
			||||||
	return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    while (listCOMMON) {
 | 
					 | 
				
			||||||
	common = listCOMMON;
 | 
					 | 
				
			||||||
	lookup[l].symName = AOUTGetSymbolName(aoutfile, common->sym);
 | 
					 | 
				
			||||||
	lookup[l].offset = (funcptr) (aoutfile->common + offset);
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
	AOUTDEBUG("Adding %p %s\n", (void *)lookup[l].offset,
 | 
					 | 
				
			||||||
		  lookup[l].symName);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	listCOMMON = common->next;
 | 
					 | 
				
			||||||
	offset += common->sym->n_value;
 | 
					 | 
				
			||||||
	xf86loaderfree(common);
 | 
					 | 
				
			||||||
	l++;
 | 
					 | 
				
			||||||
    }				/* while */
 | 
					 | 
				
			||||||
    /* listCOMMON == NULL */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    lookup[l].symName = NULL;	/* Terminate the list */
 | 
					 | 
				
			||||||
    return lookup;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Symbol Table
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static char *
 | 
					 | 
				
			||||||
AOUTGetString(AOUTModulePtr aoutfile, int index)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    char *symname = (char *)&(aoutfile->strings[index]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (symname[0] == '_') {
 | 
					 | 
				
			||||||
	symname++;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return symname;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Return the name of a symbol 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static char *
 | 
					 | 
				
			||||||
AOUTGetSymbolName(AOUTModulePtr aoutfile, struct AOUT_nlist *sym)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    char *symname = AOUTGetString(aoutfile, sym->n_un.n_strx);
 | 
					 | 
				
			||||||
    char *name;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    name = xf86loadermalloc(strlen(symname) + 1);
 | 
					 | 
				
			||||||
    if (!name)
 | 
					 | 
				
			||||||
	FatalError("AOUTGetSymbolName: Out of memory\n");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    strcpy(name, symname);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return name;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Return the value of a symbol in the loader's symbol table
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static void *
 | 
					 | 
				
			||||||
AOUTGetSymbolValue(AOUTModulePtr aoutfile, int index)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    void *symval = NULL;	/* value of the indicated symbol */
 | 
					 | 
				
			||||||
    itemPtr symbol = NULL;	/* name/value of symbol */
 | 
					 | 
				
			||||||
    char *name = NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    name = AOUTGetSymbolName(aoutfile, aoutfile->symtab + index);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (name)
 | 
					 | 
				
			||||||
	symbol = LoaderHashFind(name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (symbol)
 | 
					 | 
				
			||||||
	symval = (unsigned char *)symbol->address;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    xf86loaderfree(name);
 | 
					 | 
				
			||||||
    return symval;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Perform the actual relocation 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static void
 | 
					 | 
				
			||||||
AOUT_Relocate(unsigned long *destl, unsigned long val, int pcrel)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
    AOUTDEBUG("AOUT_Relocate %p : %08lx %s",
 | 
					 | 
				
			||||||
	      (void *)destl, *destl, pcrel == 1 ? "rel" : "abs");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    if (pcrel) {
 | 
					 | 
				
			||||||
	/* relative to PC */
 | 
					 | 
				
			||||||
	*destl = val - ((unsigned long)destl + sizeof(long));
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
	*destl += val;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
    AOUTDEBUG(" -> %08lx\n", *destl);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Fix the relocation for text or data section
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static AOUTRelocPtr
 | 
					 | 
				
			||||||
AOUT_RelocateEntry(AOUTModulePtr aoutfile, int type,
 | 
					 | 
				
			||||||
		   struct relocation_info *rel)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTHDR *header = aoutfile->header;
 | 
					 | 
				
			||||||
    AOUT_nlist *symtab = aoutfile->symtab;
 | 
					 | 
				
			||||||
    int symnum;
 | 
					 | 
				
			||||||
    void *symval;
 | 
					 | 
				
			||||||
    unsigned long *destl;	/* address of the location to be modified */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    symnum = rel->r_symbolnum;
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
	char *name;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (rel->r_extern) {
 | 
					 | 
				
			||||||
	    AOUTDEBUG("AOUT_RelocateEntry: extern %s\n",
 | 
					 | 
				
			||||||
		      name = AOUTGetSymbolName(aoutfile, symtab + symnum));
 | 
					 | 
				
			||||||
	    xf86loaderfree(name);
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
	    AOUTDEBUG("AOUT_RelocateEntry: intern\n");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	AOUTDEBUG("  pcrel: %d", rel->r_pcrel);
 | 
					 | 
				
			||||||
	AOUTDEBUG("  length: %d", rel->r_length);
 | 
					 | 
				
			||||||
	AOUTDEBUG("  baserel: %d", rel->r_baserel);
 | 
					 | 
				
			||||||
	AOUTDEBUG("  jmptable: %d", rel->r_jmptable);
 | 
					 | 
				
			||||||
	AOUTDEBUG("  relative: %d", rel->r_relative);
 | 
					 | 
				
			||||||
	AOUTDEBUG("  copy: %d\n", rel->r_copy);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#endif /* AOUTDEBUG */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (rel->r_length != 2) {
 | 
					 | 
				
			||||||
	ErrorF("AOUT_ReloateEntry: length != 2\n");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* 
 | 
					 | 
				
			||||||
     * First find the address to modify
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    switch (type) {
 | 
					 | 
				
			||||||
    case AOUT_TEXT:
 | 
					 | 
				
			||||||
	/* Check that the relocation offset is in the text segment */
 | 
					 | 
				
			||||||
	if (rel->r_address > header->a_text) {
 | 
					 | 
				
			||||||
	    ErrorF("AOUT_RelocateEntry(): "
 | 
					 | 
				
			||||||
		   "text relocation out of text section\n");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	destl = (unsigned long *)(aoutfile->text + rel->r_address);
 | 
					 | 
				
			||||||
	break;
 | 
					 | 
				
			||||||
    case AOUT_DATA:
 | 
					 | 
				
			||||||
	/* Check that the relocation offset is in the data segment */
 | 
					 | 
				
			||||||
	if (rel->r_address > header->a_data) {
 | 
					 | 
				
			||||||
	    ErrorF("AOUT_RelocateEntry():"
 | 
					 | 
				
			||||||
		   "data relocation out of data section\n");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	destl = (unsigned long *)(aoutfile->data + rel->r_address);
 | 
					 | 
				
			||||||
	break;
 | 
					 | 
				
			||||||
    default:
 | 
					 | 
				
			||||||
	ErrorF("AOUT_RelocateEntry(): unknown section type %d\n", type);
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
    }				/* switch */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
     * Now handle the relocation 
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    if (rel->r_extern) {
 | 
					 | 
				
			||||||
	/* Lookup the symbol in the loader's symbol table */
 | 
					 | 
				
			||||||
	symval = AOUTGetSymbolValue(aoutfile, symnum);
 | 
					 | 
				
			||||||
	if (symval != 0) {
 | 
					 | 
				
			||||||
	    /* we've got the value */
 | 
					 | 
				
			||||||
	    AOUT_Relocate(destl, (unsigned long)symval, rel->r_pcrel);
 | 
					 | 
				
			||||||
	    return 0;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
	    /* The symbol should be undefined */
 | 
					 | 
				
			||||||
	    switch (symtab[symnum].n_type & AOUT_TYPE) {
 | 
					 | 
				
			||||||
	    case AOUT_UNDF:
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
		AOUTDEBUG("  extern AOUT_UNDEF\n");
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		/* Add this relocation back to the global list */
 | 
					 | 
				
			||||||
		return AOUTDelayRelocation(aoutfile, type, rel);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    default:
 | 
					 | 
				
			||||||
		ErrorF("AOUT_RelocateEntry():"
 | 
					 | 
				
			||||||
		       " impossible intern relocation type: %d\n",
 | 
					 | 
				
			||||||
		       symtab[symnum].n_type);
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
	    }			/* switch */
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
	/* intern */
 | 
					 | 
				
			||||||
	switch (rel->r_symbolnum) {
 | 
					 | 
				
			||||||
	case AOUT_TEXT:
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
	    AOUTDEBUG("  AOUT_TEXT\n");
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	    /* Only absolute intern text relocations need to be handled */
 | 
					 | 
				
			||||||
	    if (rel->r_pcrel == 0)
 | 
					 | 
				
			||||||
		AOUT_Relocate(destl, (unsigned long)aoutfile->text,
 | 
					 | 
				
			||||||
			      rel->r_pcrel);
 | 
					 | 
				
			||||||
	    return 0;
 | 
					 | 
				
			||||||
	case AOUT_DATA:
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
	    AOUTDEBUG("  AOUT_DATA\n");
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	    if (rel->r_pcrel == 0)
 | 
					 | 
				
			||||||
		AOUT_Relocate(destl, (unsigned long)aoutfile->data
 | 
					 | 
				
			||||||
			      - header->a_text, rel->r_pcrel);
 | 
					 | 
				
			||||||
	    else
 | 
					 | 
				
			||||||
		ErrorF("AOUT_RelocateEntry(): "
 | 
					 | 
				
			||||||
		       "don't know how to handle data pc-relative reloc\n");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    return 0;
 | 
					 | 
				
			||||||
	case AOUT_BSS:
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
	    AOUTDEBUG("  AOUT_BSS\n");
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	    if (rel->r_pcrel == 0)
 | 
					 | 
				
			||||||
		AOUT_Relocate(destl, (unsigned long)aoutfile->bss
 | 
					 | 
				
			||||||
			      - header->a_text - header->a_data,
 | 
					 | 
				
			||||||
			      rel->r_pcrel);
 | 
					 | 
				
			||||||
	    else
 | 
					 | 
				
			||||||
		ErrorF("AOUT_RelocateEntry(): "
 | 
					 | 
				
			||||||
		       "don't know how to handle bss pc-relative reloc\n");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    return 0;
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
	    ErrorF("AOUT_RelocateEntry():"
 | 
					 | 
				
			||||||
		   " unknown intern relocation type: %d\n", rel->r_symbolnum);
 | 
					 | 
				
			||||||
	    return 0;
 | 
					 | 
				
			||||||
	}			/* switch */
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}				/* AOUT_RelocateEntry */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static AOUTRelocPtr
 | 
					 | 
				
			||||||
AOUTCollectRelocations(AOUTModulePtr aoutfile)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTHDR *header = aoutfile->header;
 | 
					 | 
				
			||||||
    int i, nreloc;
 | 
					 | 
				
			||||||
    struct relocation_info *rel;
 | 
					 | 
				
			||||||
    AOUTRelocPtr reloc_head = NULL;
 | 
					 | 
				
			||||||
    AOUTRelocPtr tmp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Text relocations */
 | 
					 | 
				
			||||||
    if (aoutfile->text != NULL && aoutfile->txtrel != NULL) {
 | 
					 | 
				
			||||||
	nreloc = header->a_trsize / sizeof(struct relocation_info);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for (i = 0; i < nreloc; i++) {
 | 
					 | 
				
			||||||
	    rel = aoutfile->txtrel + i;
 | 
					 | 
				
			||||||
	    tmp = AOUTDelayRelocation(aoutfile, AOUT_TEXT, rel);
 | 
					 | 
				
			||||||
	    if (tmp) {
 | 
					 | 
				
			||||||
		tmp->next = reloc_head;
 | 
					 | 
				
			||||||
		reloc_head = tmp;
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	}			/* for */
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* Data relocations */
 | 
					 | 
				
			||||||
    if (aoutfile->data != NULL && aoutfile->datarel != NULL) {
 | 
					 | 
				
			||||||
	nreloc = header->a_drsize / sizeof(struct relocation_info);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for (i = 0; i < nreloc; i++) {
 | 
					 | 
				
			||||||
	    rel = aoutfile->datarel + i;
 | 
					 | 
				
			||||||
	    tmp = AOUTDelayRelocation(aoutfile, AOUT_DATA, rel);
 | 
					 | 
				
			||||||
	    tmp->next = reloc_head;
 | 
					 | 
				
			||||||
	    reloc_head = tmp;
 | 
					 | 
				
			||||||
	}			/* for */
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return reloc_head;
 | 
					 | 
				
			||||||
}				/* AOUTCollectRelocations */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * AOUT_GetSymbols()
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * add the symbols to the loader's symbol table
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static LOOKUP *
 | 
					 | 
				
			||||||
AOUT_GetSymbols(AOUTModulePtr aoutfile)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int fd = aoutfile->fd;
 | 
					 | 
				
			||||||
    AOUTHDR *header = aoutfile->header;
 | 
					 | 
				
			||||||
    int nsyms, soff, i, l;
 | 
					 | 
				
			||||||
    char *symname;
 | 
					 | 
				
			||||||
    AOUT_nlist *s;
 | 
					 | 
				
			||||||
    LOOKUP *lookup, *lookup_common;
 | 
					 | 
				
			||||||
    AOUTCommonPtr tmp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    aoutfile->symtab = (AOUT_nlist *) _LoaderFileToMem(fd,
 | 
					 | 
				
			||||||
						       AOUT_SYMOFF(header),
 | 
					 | 
				
			||||||
						       header->a_syms,
 | 
					 | 
				
			||||||
						       "symbols");
 | 
					 | 
				
			||||||
    nsyms = header->a_syms / sizeof(AOUT_nlist);
 | 
					 | 
				
			||||||
    lookup = xf86loadermalloc(nsyms * sizeof(LOOKUP));
 | 
					 | 
				
			||||||
    if (lookup == NULL) {
 | 
					 | 
				
			||||||
	ErrorF("AOUT_GetSymbols(): can't allocate memory\n");
 | 
					 | 
				
			||||||
	return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    for (i = 0, l = 0; i < nsyms; i++) {
 | 
					 | 
				
			||||||
	s = aoutfile->symtab + i;
 | 
					 | 
				
			||||||
	soff = s->n_un.n_strx;
 | 
					 | 
				
			||||||
	if (soff == 0 || (s->n_type & AOUT_STAB) != 0)
 | 
					 | 
				
			||||||
	    continue;
 | 
					 | 
				
			||||||
	symname = AOUTGetSymbolName(aoutfile, s);
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
	AOUTDEBUG("AOUT_GetSymbols(): %s %02x %02x %08lx\n",
 | 
					 | 
				
			||||||
		  symname, s->n_type, s->n_other, s->n_value);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	switch (s->n_type & AOUT_TYPE) {
 | 
					 | 
				
			||||||
	case AOUT_UNDF:
 | 
					 | 
				
			||||||
	    if (s->n_value != 0) {
 | 
					 | 
				
			||||||
		if (!LoaderHashFind(symname)) {
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
		    AOUTDEBUG("Adding common %s\n", symname);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		    tmp = AOUTAddCommon(s, i);
 | 
					 | 
				
			||||||
		    if (tmp) {
 | 
					 | 
				
			||||||
			tmp->next = listCOMMON;
 | 
					 | 
				
			||||||
			listCOMMON = tmp;
 | 
					 | 
				
			||||||
		    }
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	    } else {
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
		AOUTDEBUG("Adding undef %s\n", symname);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    xf86loaderfree(symname);
 | 
					 | 
				
			||||||
	    break;
 | 
					 | 
				
			||||||
	case AOUT_TEXT:
 | 
					 | 
				
			||||||
	    if (s->n_type & AOUT_EXT) {
 | 
					 | 
				
			||||||
		lookup[l].symName = symname;
 | 
					 | 
				
			||||||
		/* text symbols start at 0 */
 | 
					 | 
				
			||||||
		lookup[l].offset = (funcptr) (aoutfile->text + s->n_value);
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
		AOUTDEBUG("Adding text %s %p\n", symname,
 | 
					 | 
				
			||||||
			  (void *)lookup[l].offset);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		l++;
 | 
					 | 
				
			||||||
	    } else {
 | 
					 | 
				
			||||||
		xf86loaderfree(symname);
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    break;
 | 
					 | 
				
			||||||
	case AOUT_DATA:
 | 
					 | 
				
			||||||
	    if (s->n_type & AOUT_EXT) {
 | 
					 | 
				
			||||||
		lookup[l].symName = symname;
 | 
					 | 
				
			||||||
		/* data symbols are following text */
 | 
					 | 
				
			||||||
		lookup[l].offset = (funcptr) (aoutfile->data +
 | 
					 | 
				
			||||||
					      s->n_value - header->a_text);
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
		AOUTDEBUG("Adding data %s %p\n", symname,
 | 
					 | 
				
			||||||
			  (void *)lookup[l].offset);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		l++;
 | 
					 | 
				
			||||||
	    } else {
 | 
					 | 
				
			||||||
		xf86loaderfree(symname);
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    break;
 | 
					 | 
				
			||||||
	case AOUT_BSS:
 | 
					 | 
				
			||||||
	    if (s->n_type & AOUT_EXT) {
 | 
					 | 
				
			||||||
		lookup[l].symName = symname;
 | 
					 | 
				
			||||||
		/* bss symbols follow both text and data */
 | 
					 | 
				
			||||||
		lookup[l].offset = (funcptr) (aoutfile->bss + s->n_value
 | 
					 | 
				
			||||||
					      - (header->a_data
 | 
					 | 
				
			||||||
						 + header->a_text));
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
		AOUTDEBUG("Adding bss %s %p\n", symname,
 | 
					 | 
				
			||||||
			  (void *)lookup[l].offset);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		l++;
 | 
					 | 
				
			||||||
	    } else {
 | 
					 | 
				
			||||||
		xf86loaderfree(symname);
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    break;
 | 
					 | 
				
			||||||
	case AOUT_FN:
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
	    if (s->n_type & AOUT_EXT) {
 | 
					 | 
				
			||||||
		AOUTDEBUG("Ignoring AOUT_FN %s\n", symname);
 | 
					 | 
				
			||||||
	    } else {
 | 
					 | 
				
			||||||
		AOUTDEBUG("Ignoring AOUT_WARN %s\n", symname);
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	    xf86loaderfree(symname);
 | 
					 | 
				
			||||||
	    break;
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
	    ErrorF("Unknown symbol type %x\n", s->n_type & AOUT_TYPE);
 | 
					 | 
				
			||||||
	    xf86loaderfree(symname);
 | 
					 | 
				
			||||||
	}			/* switch */
 | 
					 | 
				
			||||||
    }				/* for */
 | 
					 | 
				
			||||||
    lookup[l].symName = NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    lookup_common = AOUTCreateCommon(aoutfile);
 | 
					 | 
				
			||||||
    if (lookup_common) {
 | 
					 | 
				
			||||||
	LOOKUP *p;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for (i = 0, p = lookup_common; p->symName; i++, p++) ;
 | 
					 | 
				
			||||||
	memcpy(&(lookup[l]), lookup_common, i * sizeof(LOOKUP));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	xf86loaderfree(lookup_common);
 | 
					 | 
				
			||||||
	l += i;
 | 
					 | 
				
			||||||
	lookup[l].symName = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return lookup;
 | 
					 | 
				
			||||||
}				/* AOUT_GetSymbols */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Public API for the a.out implementation of the loader
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
void *
 | 
					 | 
				
			||||||
AOUTLoadModule(loaderPtr modrec, int aoutfd, LOOKUP ** ppLookup, int flags)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTModulePtr aoutfile = NULL;
 | 
					 | 
				
			||||||
    AOUTHDR *header;
 | 
					 | 
				
			||||||
    AOUTRelocPtr reloc, tail;
 | 
					 | 
				
			||||||
    void *v;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
    AOUTDEBUG("AOUTLoadModule(%s, %d, %d)\n",
 | 
					 | 
				
			||||||
	      modrec->name, modrec->handle, aoutfd);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    if ((aoutfile = xf86loadercalloc(1, sizeof(AOUTModuleRec))) == NULL) {
 | 
					 | 
				
			||||||
	ErrorF("Unable to allocate AOUTModuleRec\n");
 | 
					 | 
				
			||||||
	return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    aoutfile->handle = modrec->handle;
 | 
					 | 
				
			||||||
    aoutfile->module = modrec->module;
 | 
					 | 
				
			||||||
    aoutfile->fd = aoutfd;
 | 
					 | 
				
			||||||
    v = aoutfile->funcs = modrec->funcs;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
     *  Get the a.out header
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    aoutfile->header =
 | 
					 | 
				
			||||||
	    (AOUTHDR *) _LoaderFileToMem(aoutfd, 0, sizeof(AOUTHDR),
 | 
					 | 
				
			||||||
					 "header");
 | 
					 | 
				
			||||||
    header = (AOUTHDR *) aoutfile->header;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* 
 | 
					 | 
				
			||||||
     * Load the 6 other sections 
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    /* text */
 | 
					 | 
				
			||||||
    if (header->a_text != 0) {
 | 
					 | 
				
			||||||
	aoutfile->text = _LoaderFileToMem(aoutfile->fd,
 | 
					 | 
				
			||||||
					  AOUT_TXTOFF(header),
 | 
					 | 
				
			||||||
					  header->a_text, "text");
 | 
					 | 
				
			||||||
	aoutfile->textsize = header->a_text;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
	aoutfile->text = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* data */
 | 
					 | 
				
			||||||
    if (header->a_data != 0) {
 | 
					 | 
				
			||||||
	aoutfile->data = _LoaderFileToMem(aoutfile->fd,
 | 
					 | 
				
			||||||
					  AOUT_DATOFF(header),
 | 
					 | 
				
			||||||
					  header->a_data, "data");
 | 
					 | 
				
			||||||
	aoutfile->datasize = header->a_data;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
	aoutfile->data = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* bss */
 | 
					 | 
				
			||||||
    if (header->a_bss != 0) {
 | 
					 | 
				
			||||||
	aoutfile->bss = xf86loadercalloc(1, header->a_bss);
 | 
					 | 
				
			||||||
	aoutfile->bsssize = header->a_bss;
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
	aoutfile->bss = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* Text Relocations */
 | 
					 | 
				
			||||||
    if (header->a_trsize != 0) {
 | 
					 | 
				
			||||||
	aoutfile->txtrel = _LoaderFileToMem(aoutfile->fd,
 | 
					 | 
				
			||||||
					    AOUT_TRELOFF(header),
 | 
					 | 
				
			||||||
					    header->a_trsize, "txtrel");
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
	aoutfile->txtrel = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* Data Relocations */
 | 
					 | 
				
			||||||
    if (header->a_drsize != 0) {
 | 
					 | 
				
			||||||
	aoutfile->datarel = _LoaderFileToMem(aoutfile->fd,
 | 
					 | 
				
			||||||
					     AOUT_DRELOFF(header),
 | 
					 | 
				
			||||||
					     header->a_drsize, "datarel");
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
	aoutfile->datarel = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* String table */
 | 
					 | 
				
			||||||
    _LoaderFileRead(aoutfile->fd, AOUT_STROFF(header),
 | 
					 | 
				
			||||||
		    &(aoutfile->strsize), sizeof(int));
 | 
					 | 
				
			||||||
    if (aoutfile->strsize != 0) {
 | 
					 | 
				
			||||||
	aoutfile->strings = _LoaderFileToMem(aoutfile->fd,
 | 
					 | 
				
			||||||
					     AOUT_STROFF(header),
 | 
					 | 
				
			||||||
					     aoutfile->strsize, "strings");
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
	aoutfile->strings = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* load symbol table */
 | 
					 | 
				
			||||||
    *ppLookup = AOUT_GetSymbols(aoutfile);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Do relocations */
 | 
					 | 
				
			||||||
    reloc = AOUTCollectRelocations(aoutfile);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (reloc) {
 | 
					 | 
				
			||||||
	for (tail = reloc; tail->next; tail = tail->next) ;
 | 
					 | 
				
			||||||
	tail->next = _LoaderGetRelocations(v)->aout_reloc;
 | 
					 | 
				
			||||||
	_LoaderGetRelocations(v)->aout_reloc = reloc;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return (void *)aoutfile;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
AOUTResolveSymbols(void *mod)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTRelocPtr newlist, p, tmp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
    AOUTDEBUG("AOUTResolveSymbols()\n");
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    newlist = 0;
 | 
					 | 
				
			||||||
    for (p = _LoaderGetRelocations(mod)->aout_reloc; p;) {
 | 
					 | 
				
			||||||
	tmp = AOUT_RelocateEntry(p->file, p->type, p->rel);
 | 
					 | 
				
			||||||
	if (tmp) {
 | 
					 | 
				
			||||||
	    /* Failed to relocate.  Keep it in the list. */
 | 
					 | 
				
			||||||
	    tmp->next = newlist;
 | 
					 | 
				
			||||||
	    newlist = tmp;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	tmp = p;
 | 
					 | 
				
			||||||
	p = p->next;
 | 
					 | 
				
			||||||
	xf86loaderfree(tmp);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    _LoaderGetRelocations(mod)->aout_reloc = newlist;
 | 
					 | 
				
			||||||
}				/* AOUTResolveSymbols */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int
 | 
					 | 
				
			||||||
AOUTCheckForUnresolved(void *mod)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int symnum;
 | 
					 | 
				
			||||||
    AOUTRelocPtr crel;
 | 
					 | 
				
			||||||
    char *name;
 | 
					 | 
				
			||||||
    int fatalsym = 0, flag;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
    AOUTDEBUG("AOUTCheckForUnResolved()\n");
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    if ((crel = _LoaderGetRelocations(mod)->aout_reloc) == NULL)
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    while (crel) {
 | 
					 | 
				
			||||||
	if (crel->type == AOUT_TEXT) {
 | 
					 | 
				
			||||||
	    /* Attempt to make unresolved  text references 
 | 
					 | 
				
			||||||
	     * point to a default function */
 | 
					 | 
				
			||||||
	    AOUT_Relocate((unsigned long *)(crel->file->text
 | 
					 | 
				
			||||||
					    + crel->rel->r_address),
 | 
					 | 
				
			||||||
			  (unsigned long)LoaderDefaultFunc,
 | 
					 | 
				
			||||||
			  crel->rel->r_pcrel);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	symnum = crel->rel->r_symbolnum;
 | 
					 | 
				
			||||||
	name = AOUTGetSymbolName(crel->file, crel->file->symtab + symnum);
 | 
					 | 
				
			||||||
	flag = _LoaderHandleUnresolved(name,
 | 
					 | 
				
			||||||
				       _LoaderHandleToName(crel->file->
 | 
					 | 
				
			||||||
							   handle));
 | 
					 | 
				
			||||||
	xf86loaderfree(name);
 | 
					 | 
				
			||||||
	if (flag)
 | 
					 | 
				
			||||||
	    fatalsym = 1;
 | 
					 | 
				
			||||||
	crel = crel->next;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return fatalsym;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
AOUTUnloadModule(void *modptr)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTModulePtr aoutfile = (AOUTModulePtr) modptr;
 | 
					 | 
				
			||||||
    AOUTRelocPtr relptr, *prevptr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef AOUTDEBUG
 | 
					 | 
				
			||||||
    AOUTDEBUG("AOUTUnLoadModule(0x%p)\n", modptr);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Delete any unresolved relocations
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    relptr = _LoaderGetRelocations(aoutfile->funcs)->aout_reloc;
 | 
					 | 
				
			||||||
    prevptr = &(_LoaderGetRelocations(aoutfile->funcs)->aout_reloc);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    while (relptr) {
 | 
					 | 
				
			||||||
	if (relptr->file == aoutfile) {
 | 
					 | 
				
			||||||
	    *prevptr = relptr->next;
 | 
					 | 
				
			||||||
	    xf86loaderfree(relptr);
 | 
					 | 
				
			||||||
	    relptr = *prevptr;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
	    prevptr = &(relptr->next);
 | 
					 | 
				
			||||||
	    relptr = relptr->next;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
    }				/* while */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* clean the symbols table */
 | 
					 | 
				
			||||||
    LoaderHashTraverse((void *)aoutfile, AOUTHashCleanOut);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define CheckandFree(ptr,size)  if(ptr) _LoaderFreeFileMem((ptr),(size))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    CheckandFree(aoutfile->strings, aoutfile->strsize);
 | 
					 | 
				
			||||||
    CheckandFree(aoutfile->symtab, aoutfile->header->a_syms);
 | 
					 | 
				
			||||||
    CheckandFree(aoutfile->datarel, aoutfile->header->a_drsize);
 | 
					 | 
				
			||||||
    CheckandFree(aoutfile->txtrel, aoutfile->header->a_trsize);
 | 
					 | 
				
			||||||
    CheckandFree(aoutfile->data, aoutfile->header->a_data);
 | 
					 | 
				
			||||||
    CheckandFree(aoutfile->text, aoutfile->header->a_text);
 | 
					 | 
				
			||||||
    /* Free allocated sections */
 | 
					 | 
				
			||||||
    if (aoutfile->bss != NULL) {
 | 
					 | 
				
			||||||
	xf86loaderfree(aoutfile->bss);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (aoutfile->common != NULL) {
 | 
					 | 
				
			||||||
	xf86loaderfree(aoutfile->common);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Free header */
 | 
					 | 
				
			||||||
    _LoaderFreeFileMem(aoutfile->header, sizeof(AOUTHDR));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* Free the module structure itself */
 | 
					 | 
				
			||||||
    xf86loaderfree(aoutfile);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
char *
 | 
					 | 
				
			||||||
AOUTAddressToSection(void *modptr, unsigned long address)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    AOUTModulePtr aoutfile = (AOUTModulePtr) modptr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (address >= (unsigned long)aoutfile->text &&
 | 
					 | 
				
			||||||
	address <= (unsigned long)aoutfile->text + aoutfile->textsize) {
 | 
					 | 
				
			||||||
	return "text";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (address >= (unsigned long)aoutfile->data &&
 | 
					 | 
				
			||||||
	address <= (unsigned long)aoutfile->data + aoutfile->datasize) {
 | 
					 | 
				
			||||||
	return "data";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (address >= (unsigned long)aoutfile->bss &&
 | 
					 | 
				
			||||||
	address <= (unsigned long)aoutfile->bss + aoutfile->bsssize) {
 | 
					 | 
				
			||||||
	return "bss";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return NULL;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,35 +0,0 @@
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Copyright 1997,1998 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.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/aoutloader.h,v 1.3 1998/09/20 14:41:03 dawes Exp $ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_XORG_CONFIG_H
 | 
					 | 
				
			||||||
#include <xorg-config.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef _AOUTLOADER_H
 | 
					 | 
				
			||||||
#define _AOUTLOADER_H
 | 
					 | 
				
			||||||
extern void *AOUTLoadModule(loaderPtr, int, LOOKUP **, int flags);
 | 
					 | 
				
			||||||
extern void AOUTResolveSymbols(void *);
 | 
					 | 
				
			||||||
extern int AOUTCheckForUnresolved(void *);
 | 
					 | 
				
			||||||
extern char *AOUTAddressToSection(void *, unsigned long);
 | 
					 | 
				
			||||||
extern void AOUTUnloadModule(void *);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,75 +0,0 @@
 | 
				
			||||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/ar.h,v 1.3 1998/07/25 16:56:12 dawes Exp $ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_XORG_CONFIG_H
 | 
					 | 
				
			||||||
#include <xorg-config.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef _AR_H
 | 
					 | 
				
			||||||
#define _AR_H
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ARMAG "!<arch>\n"
 | 
					 | 
				
			||||||
#define SARMAG 8
 | 
					 | 
				
			||||||
#define ARFMAG "`\n"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if !(defined(__powerpc__) && defined(Lynx))
 | 
					 | 
				
			||||||
struct ar_hdr {
 | 
					 | 
				
			||||||
    char ar_name[16];
 | 
					 | 
				
			||||||
    char ar_date[12];
 | 
					 | 
				
			||||||
    char ar_uid[6];
 | 
					 | 
				
			||||||
    char ar_gid[6];
 | 
					 | 
				
			||||||
    char ar_mode[8];
 | 
					 | 
				
			||||||
    char ar_size[10];
 | 
					 | 
				
			||||||
    char ar_fmag[2];
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define AIAMAG "<aiaff>\n"
 | 
					 | 
				
			||||||
#define SAIAMAG 8
 | 
					 | 
				
			||||||
#define AIAFMAG "`\n"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct fl_hdr {			/* archive fixed length header - printable ascii */
 | 
					 | 
				
			||||||
    char fl_magic[SAIAMAG];	/* Archive file magic string */
 | 
					 | 
				
			||||||
    char fl_memoff[12];		/* Offset to member table */
 | 
					 | 
				
			||||||
    char fl_gstoff[12];		/* Offset to global symbol table */
 | 
					 | 
				
			||||||
    char fl_fstmoff[12];	/* Offset to first archive member */
 | 
					 | 
				
			||||||
    char fl_lstmoff[12];	/* Offset to last archive member */
 | 
					 | 
				
			||||||
    char fl_freeoff[12];	/* Offset to first mem on free list */
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define FL_HDR struct fl_hdr
 | 
					 | 
				
			||||||
#define FL_HSZ sizeof(FL_HDR)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct ar_hdr {			/* archive file member header - printable ascii */
 | 
					 | 
				
			||||||
    char ar_size[12];		/* file member size - decimal */
 | 
					 | 
				
			||||||
    char ar_nxtmem[12];		/* pointer to next member -  decimal */
 | 
					 | 
				
			||||||
    char ar_prvmem[12];		/* pointer to previous member -  decimal */
 | 
					 | 
				
			||||||
    char ar_date[12];		/* file member date - decimal */
 | 
					 | 
				
			||||||
    char ar_uid[12];		/* file member user id - decimal */
 | 
					 | 
				
			||||||
    char ar_gid[12];		/* file member group id - decimal */
 | 
					 | 
				
			||||||
    char ar_mode[12];		/* file member mode - octal */
 | 
					 | 
				
			||||||
    char ar_namlen[4];		/* file member name length - decimal */
 | 
					 | 
				
			||||||
    union {
 | 
					 | 
				
			||||||
	char an_name[2];	/* variable length member name */
 | 
					 | 
				
			||||||
	char an_fmag[2];	/* AIAFMAG - string to end header */
 | 
					 | 
				
			||||||
    } _ar_name;			/*      and variable length name */
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ar_name _ar_name.an_name
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 *	Note: 	'ar_namlen' contains the length of the member name which
 | 
					 | 
				
			||||||
 *		may be up to 255 chars.  The character string containing
 | 
					 | 
				
			||||||
 *		the name begins at '_ar_name.ar_name'.  The terminating
 | 
					 | 
				
			||||||
 *		string AIAFMAG, is only cosmetic. File member contents begin
 | 
					 | 
				
			||||||
 *		at the first even byte boundary past 'header position + 
 | 
					 | 
				
			||||||
 *		sizeof(struct ar_hdr) + ar_namlen',  and continue for
 | 
					 | 
				
			||||||
 *		'ar_size' bytes.
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define AR_HDR struct ar_hdr
 | 
					 | 
				
			||||||
#define AR_HSZ sizeof(AR_HDR)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* !__powerpc__ && Lynx */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* _AR_H */
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,237 +0,0 @@
 | 
				
			||||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/coff.h,v 1.5 1998/07/25 16:56:12 dawes Exp $ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* This file was implemented from the information in the book
 | 
					 | 
				
			||||||
   Understanding and Using COFF
 | 
					 | 
				
			||||||
   Gintaras R. Gircys
 | 
					 | 
				
			||||||
   O'Reilly, 1988
 | 
					 | 
				
			||||||
   and by looking at the Linux kernel code.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   It is therefore most likely free to use...
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   If the file format changes in the COFF object, this file should be
 | 
					 | 
				
			||||||
   subsequently updated to reflect the changes.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   The actual loader module only uses a few of the COFF structures. 
 | 
					 | 
				
			||||||
   Only those are included here.  If you wish more information about 
 | 
					 | 
				
			||||||
   COFF, thein check out the book mentioned above.
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_XORG_CONFIG_H
 | 
					 | 
				
			||||||
#include <xorg-config.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef _COFF_H
 | 
					 | 
				
			||||||
#define _COFF_H
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define  E_SYMNMLEN  8		/* Number of characters in a symbol name         */
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Intel 386/486  
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * FILE HEADER 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct COFF_filehdr {
 | 
					 | 
				
			||||||
    unsigned short f_magic;	/* magic number                 */
 | 
					 | 
				
			||||||
    unsigned short f_nscns;	/* number of sections           */
 | 
					 | 
				
			||||||
    long f_timdat;		/* time & date stamp            */
 | 
					 | 
				
			||||||
    long f_symptr;		/* file pointer to symtab       */
 | 
					 | 
				
			||||||
    long f_nsyms;		/* number of symtab entries     */
 | 
					 | 
				
			||||||
    unsigned short f_opthdr;	/* sizeof(optional hdr)         */
 | 
					 | 
				
			||||||
    unsigned short f_flags;	/* flags                        */
 | 
					 | 
				
			||||||
} FILHDR;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define	FILHSZ	sizeof(FILHDR)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * SECTION HEADER 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct COFF_scnhdr {
 | 
					 | 
				
			||||||
    char s_name[8];		/* section name                 */
 | 
					 | 
				
			||||||
    long s_paddr;		/* physical address             */
 | 
					 | 
				
			||||||
    long s_vaddr;		/* virtual address              */
 | 
					 | 
				
			||||||
    long s_size;		/* section size                 */
 | 
					 | 
				
			||||||
    long s_scnptr;		/* raw data for section         */
 | 
					 | 
				
			||||||
    long s_relptr;		/* relocation                   */
 | 
					 | 
				
			||||||
    long s_lnnoptr;		/* line numbers                 */
 | 
					 | 
				
			||||||
    unsigned short s_nreloc;	/* number of relocation entries */
 | 
					 | 
				
			||||||
    unsigned short s_nlnno;	/* number of line number entries */
 | 
					 | 
				
			||||||
    long s_flags;		/* flags                        */
 | 
					 | 
				
			||||||
} SCNHDR;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define	COFF_SCNHDR	struct COFF_scnhdr
 | 
					 | 
				
			||||||
#define	COFF_SCNHSZ	sizeof(COFF_SCNHDR)
 | 
					 | 
				
			||||||
#define SCNHSZ		COFF_SCNHSZ
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * the optional COFF header as used by Linux COFF
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
    char magic[2];		/* type of file                  */
 | 
					 | 
				
			||||||
    char vstamp[2];		/* version stamp                 */
 | 
					 | 
				
			||||||
    char tsize[4];		/* text size in bytes            */
 | 
					 | 
				
			||||||
    char dsize[4];		/* initialized data              */
 | 
					 | 
				
			||||||
    char bsize[4];		/* uninitialized data            */
 | 
					 | 
				
			||||||
    char entry[4];		/* entry point                   */
 | 
					 | 
				
			||||||
    char text_start[4];		/* base of text                  */
 | 
					 | 
				
			||||||
    char data_start[4];		/* base of data                  */
 | 
					 | 
				
			||||||
} AOUTHDR;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * SYMBOLS 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct COFF_syment {
 | 
					 | 
				
			||||||
    union {
 | 
					 | 
				
			||||||
	char _n_name[E_SYMNMLEN];	/* Symbol name (first 8 chars)  */
 | 
					 | 
				
			||||||
	struct {
 | 
					 | 
				
			||||||
	    long _n_zeroes;	/* Leading zeros               */
 | 
					 | 
				
			||||||
	    long _n_offset;	/* Offset for a header section */
 | 
					 | 
				
			||||||
	} _n_n;
 | 
					 | 
				
			||||||
	char *_n_nptr[2];	/* allows for overlaying       */
 | 
					 | 
				
			||||||
    } _n;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    long n_value;		/* address of the segment       */
 | 
					 | 
				
			||||||
    short n_scnum;		/* Section number               */
 | 
					 | 
				
			||||||
    unsigned short n_type;	/* Type of section              */
 | 
					 | 
				
			||||||
    char n_sclass;		/* Loader class                 */
 | 
					 | 
				
			||||||
    char n_numaux;		/* Number of aux entries following */
 | 
					 | 
				
			||||||
} SYMENT;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define n_name		_n._n_name
 | 
					 | 
				
			||||||
#define n_nptr		_n._n_nptr[1]
 | 
					 | 
				
			||||||
#define n_zeroes	_n._n_n._n_zeroes
 | 
					 | 
				
			||||||
#define n_offset	_n._n_n._n_offset
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define COFF_E_SYMNMLEN	 8	/* characters in a short symbol name    */
 | 
					 | 
				
			||||||
#define COFF_E_FILNMLEN	14	/* characters in a file name            */
 | 
					 | 
				
			||||||
#define COFF_E_DIMNUM	 4	/* array dimensions in aux entry        */
 | 
					 | 
				
			||||||
#define SYMNMLEN	COFF_E_SYMNMLEN
 | 
					 | 
				
			||||||
#define SYMESZ		18	/* not really sizeof(SYMENT) due to padding */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Special section number found in the symbol section */
 | 
					 | 
				
			||||||
#define	N_UNDEF	0
 | 
					 | 
				
			||||||
#define	N_ABS	-1
 | 
					 | 
				
			||||||
#define	N_DEBUG	-2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Symbol storage class values */
 | 
					 | 
				
			||||||
#define C_NULL		0
 | 
					 | 
				
			||||||
#define C_EXT		2
 | 
					 | 
				
			||||||
#define C_FILE		103
 | 
					 | 
				
			||||||
#define C_HIDEXT	107
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * AUX Entries
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
typedef struct COFF_auxent {
 | 
					 | 
				
			||||||
    long x_scnlen;
 | 
					 | 
				
			||||||
    long x_parmhash;
 | 
					 | 
				
			||||||
    unsigned short x_snhash;
 | 
					 | 
				
			||||||
    unsigned char x_smtyp;
 | 
					 | 
				
			||||||
    unsigned char x_smclas;
 | 
					 | 
				
			||||||
    long x_stab;
 | 
					 | 
				
			||||||
    unsigned short x_snstab;
 | 
					 | 
				
			||||||
} AUXENT;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Auxillary Symbol type values */
 | 
					 | 
				
			||||||
#define XTY_ER	0		/* Enternal Reference */
 | 
					 | 
				
			||||||
#define XTY_SD	1		/* csect section definition */
 | 
					 | 
				
			||||||
#define XTY_LD	2		/* Label definition */
 | 
					 | 
				
			||||||
#define XTY_CM	3		/* common csect definition */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Auxillary Symbol storage mapping class values */
 | 
					 | 
				
			||||||
#define XMC_PR	0		/* Program code */
 | 
					 | 
				
			||||||
#define XMC_RO	1		/* Read-only constant */
 | 
					 | 
				
			||||||
#define XMC_DB	2		/* Debug dictionary */
 | 
					 | 
				
			||||||
#define XMC_TC	3		/* TOC entry */
 | 
					 | 
				
			||||||
#define XMC_UA	4		/* Unclassified */
 | 
					 | 
				
			||||||
#define XMC_RW	5		/* Read/write data */
 | 
					 | 
				
			||||||
#define XMC_GL	6		/* Global linkage */
 | 
					 | 
				
			||||||
#define XMC_XO	7		/* Extended operation */
 | 
					 | 
				
			||||||
#define XMC_SV	8		/* Supervisor call descriptor */
 | 
					 | 
				
			||||||
#define XMC_BS	9		/* BSS class */
 | 
					 | 
				
			||||||
#define XMC_DS	10		/* Function descriptor csect */
 | 
					 | 
				
			||||||
#define XMC_UC	11		/* Unnamed FORTRAN comon */
 | 
					 | 
				
			||||||
#define XMC_TI	12		/* Reserved */
 | 
					 | 
				
			||||||
#define XMC_TB	13		/* Reserved */
 | 
					 | 
				
			||||||
#define XMC_TC0	15		/* TOC anchor */
 | 
					 | 
				
			||||||
#define XMC_TD	16		/* Scalar data entry in TOC */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * RELOCATION DIRECTIVES
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct COFF_reloc {
 | 
					 | 
				
			||||||
    long r_vaddr;		/* Virtual address of item    */
 | 
					 | 
				
			||||||
    long r_symndx;		/* Symbol index in the symtab */
 | 
					 | 
				
			||||||
#if defined(__powerpc__)
 | 
					 | 
				
			||||||
    union {
 | 
					 | 
				
			||||||
	unsigned short _r_type;	/* old style coff relocation type */
 | 
					 | 
				
			||||||
	struct {
 | 
					 | 
				
			||||||
	    char _r_rsize;	/* sign and reloc bit len */
 | 
					 | 
				
			||||||
	    char _r_rtype;	/* toc relocation type */
 | 
					 | 
				
			||||||
	} _r_r;
 | 
					 | 
				
			||||||
    } _r;
 | 
					 | 
				
			||||||
#define r_otype  _r._r_type	/* old style reloc - original name */
 | 
					 | 
				
			||||||
#define r_rsize _r._r_r._r_rsize	/* extract sign and bit len    */
 | 
					 | 
				
			||||||
#define r_type _r._r_r._r_rtype	/* extract toc relocation type */
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    unsigned short r_type;	/* Relocation type             */
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
} RELOC;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define COFF_RELOC	struct COFF_reloc
 | 
					 | 
				
			||||||
#define COFF_RELSZ	10
 | 
					 | 
				
			||||||
#define RELSZ		COFF_RELSZ
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * x86 Relocation types 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define	R_ABS		000
 | 
					 | 
				
			||||||
#define	R_DIR32		006
 | 
					 | 
				
			||||||
#define	R_PCRLONG	024
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if defined(__powerpc__)
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Power PC
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define R_LEN	0x1F		/* extract bit-length field */
 | 
					 | 
				
			||||||
#define R_SIGN	0x80		/* extract sign of relocation */
 | 
					 | 
				
			||||||
#define R_FIXUP	0x40		/* extract code-fixup bit */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define RELOC_RLEN(x)	((x)._r._r_r._r_rsize & R_LEN)
 | 
					 | 
				
			||||||
#define RELOC_RSIGN(x)	((x)._r._r_r._r_rsize & R_SIGN)
 | 
					 | 
				
			||||||
#define RELOC_RFIXUP(x)	((x)._r._r_r._r_rsize & R_FIXUP)
 | 
					 | 
				
			||||||
#define RELOC_RTYPE(x)	((x)._r._r_r._r_rtype)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * POWER and PowerPC - relocation types
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define R_POS	0x00	/* A(sym) Positive Relocation */
 | 
					 | 
				
			||||||
#define R_NEG	0x01	/* -A(sym) Negative Relocation */
 | 
					 | 
				
			||||||
#define R_REL	0x02	/* A(sym-*) Relative to self */
 | 
					 | 
				
			||||||
#define R_TOC	0x03	/* A(sym-TOC) Relative to TOC */
 | 
					 | 
				
			||||||
#define R_TRL	0x12	/* A(sym-TOC) TOC Relative indirect load. */
 | 
					 | 
				
			||||||
					/* modifiable instruction */
 | 
					 | 
				
			||||||
#define R_TRLA	0x13	/* A(sym-TOC) TOC Rel load address. modifiable inst */
 | 
					 | 
				
			||||||
#define R_GL	0x05	/* A(external TOC of sym) Global Linkage */
 | 
					 | 
				
			||||||
#define R_TCL	0x06	/* A(local TOC of sym) Local object TOC address */
 | 
					 | 
				
			||||||
#define R_RL	0x0C	/* A(sym) Pos indirect load. modifiable instruction */
 | 
					 | 
				
			||||||
#define R_RLA	0x0D	/* A(sym) Pos Load Address. modifiable instruction */
 | 
					 | 
				
			||||||
#define R_REF	0x0F	/* AL0(sym) Non relocating ref. No garbage collect */
 | 
					 | 
				
			||||||
#define R_BA	0x08	/* A(sym) Branch absolute. Cannot modify instruction */
 | 
					 | 
				
			||||||
#define R_RBA	0x18	/* A(sym) Branch absolute. modifiable instruction */
 | 
					 | 
				
			||||||
#define R_RBAC	0x19	/* A(sym) Branch absolute constant. modifiable instr */
 | 
					 | 
				
			||||||
#define R_BR	0x0A	/* A(sym-*) Branch rel to self. non modifiable */
 | 
					 | 
				
			||||||
#define R_RBR	0x1A	/* A(sym-*) Branch rel to self. modifiable instr */
 | 
					 | 
				
			||||||
#define R_RBRC	0x1B	/* A(sym-*) Branch absolute const. */
 | 
					 | 
				
			||||||
						/* modifiable to R_RBR */
 | 
					 | 
				
			||||||
#define R_RTB	0x04	/* A((sym-*)/2) RT IAR Rel Branch. non modifiable */
 | 
					 | 
				
			||||||
#define R_RRTBI	0x14	/* A((sym-*)/2) RT IAR Rel Br. modifiable to R_RRTBA */
 | 
					 | 
				
			||||||
#define R_RRTBA	0x15	/* A((sym-*)/2) RT absolute br. modifiable to R_RRTBI */
 | 
					 | 
				
			||||||
#endif /* __powerpc */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* _COFF_H */
 | 
					 | 
				
			||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
					@ -1,38 +0,0 @@
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Copyright 1997,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.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/coffloader.h,v 1.3 1998/09/20 14:41:04 dawes Exp $ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_XORG_CONFIG_H
 | 
					 | 
				
			||||||
#include <xorg-config.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef _COFFLOADER_H
 | 
					 | 
				
			||||||
#define _COFFLOADER_H
 | 
					 | 
				
			||||||
/* coffloader.c */
 | 
					 | 
				
			||||||
extern void *COFFLoadModule(loaderPtr, int, LOOKUP **, int flags);
 | 
					 | 
				
			||||||
extern void COFFResolveSymbols(void *);
 | 
					 | 
				
			||||||
extern int COFFCheckForUnresolved(void *);
 | 
					 | 
				
			||||||
extern char *COFFAddressToSection(void *, unsigned long);
 | 
					 | 
				
			||||||
extern void COFFUnloadModule(void *);
 | 
					 | 
				
			||||||
#endif /* _COFFLOADER_H */
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,712 +0,0 @@
 | 
				
			||||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/elf.h,v 1.16 2003/06/12 14:12:34 eich Exp $ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef unsigned int Elf32_Addr;
 | 
					 | 
				
			||||||
typedef unsigned short Elf32_Half;
 | 
					 | 
				
			||||||
typedef unsigned int Elf32_Off;
 | 
					 | 
				
			||||||
typedef long Elf32_Sword;
 | 
					 | 
				
			||||||
typedef unsigned int Elf32_Word;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef unsigned long Elf64_Addr;
 | 
					 | 
				
			||||||
typedef unsigned short Elf64_Half;
 | 
					 | 
				
			||||||
typedef unsigned long Elf64_Off;
 | 
					 | 
				
			||||||
typedef int Elf64_Sword;
 | 
					 | 
				
			||||||
typedef unsigned int Elf64_Word;
 | 
					 | 
				
			||||||
typedef unsigned long Elf64_Xword;
 | 
					 | 
				
			||||||
typedef long Elf64_Sxword;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* These constants are for the segment types stored in the image headers */
 | 
					 | 
				
			||||||
#define PT_NULL    0
 | 
					 | 
				
			||||||
#define PT_LOAD    1
 | 
					 | 
				
			||||||
#define PT_DYNAMIC 2
 | 
					 | 
				
			||||||
#define PT_INTERP  3
 | 
					 | 
				
			||||||
#define PT_NOTE    4
 | 
					 | 
				
			||||||
#define PT_SHLIB   5
 | 
					 | 
				
			||||||
#define PT_PHDR    6
 | 
					 | 
				
			||||||
#define PT_LOPROC  0x70000000
 | 
					 | 
				
			||||||
#define PT_HIPROC  0x7fffffff
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* These constants define the different elf file types */
 | 
					 | 
				
			||||||
#define ET_NONE   0
 | 
					 | 
				
			||||||
#define ET_REL    1
 | 
					 | 
				
			||||||
#define ET_EXEC   2
 | 
					 | 
				
			||||||
#define ET_DYN    3
 | 
					 | 
				
			||||||
#define ET_CORE   4
 | 
					 | 
				
			||||||
#define ET_LOPROC 5
 | 
					 | 
				
			||||||
#define ET_HIPROC 6
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* These constants define the various ELF target machines */
 | 
					 | 
				
			||||||
#define EM_NONE  	0
 | 
					 | 
				
			||||||
#define EM_M32   	1
 | 
					 | 
				
			||||||
#define EM_SPARC 	2
 | 
					 | 
				
			||||||
#define EM_386   	3
 | 
					 | 
				
			||||||
#define EM_68K   	4
 | 
					 | 
				
			||||||
#define EM_88K   	5
 | 
					 | 
				
			||||||
#define EM_486   	6	/* Perhaps disused */
 | 
					 | 
				
			||||||
#define EM_860   	7
 | 
					 | 
				
			||||||
#define EM_MIPS		8
 | 
					 | 
				
			||||||
#define EM_MIPS_RS4_BE 10
 | 
					 | 
				
			||||||
#define EM_PARISC      15
 | 
					 | 
				
			||||||
#define EM_SPARC32PLUS 18
 | 
					 | 
				
			||||||
#define EM_PPC	       20
 | 
					 | 
				
			||||||
#define EM_SPARCV9     43
 | 
					 | 
				
			||||||
#define EM_IA_64       50
 | 
					 | 
				
			||||||
#define EM_ALPHA       0x9026
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* This is the info that is needed to parse the dynamic section of the file */
 | 
					 | 
				
			||||||
#define DT_NULL		0
 | 
					 | 
				
			||||||
#define DT_NEEDED	1
 | 
					 | 
				
			||||||
#define DT_PLTRELSZ	2
 | 
					 | 
				
			||||||
#define DT_PLTGOT	3
 | 
					 | 
				
			||||||
#define DT_HASH		4
 | 
					 | 
				
			||||||
#define DT_STRTAB	5
 | 
					 | 
				
			||||||
#define DT_SYMTAB	6
 | 
					 | 
				
			||||||
#define DT_RELA		7
 | 
					 | 
				
			||||||
#define DT_RELASZ	8
 | 
					 | 
				
			||||||
#define DT_RELAENT	9
 | 
					 | 
				
			||||||
#define DT_STRSZ	10
 | 
					 | 
				
			||||||
#define DT_SYMENT	11
 | 
					 | 
				
			||||||
#define DT_INIT		12
 | 
					 | 
				
			||||||
#define DT_FINI		13
 | 
					 | 
				
			||||||
#define DT_SONAME	14
 | 
					 | 
				
			||||||
#define DT_RPATH 	15
 | 
					 | 
				
			||||||
#define DT_SYMBOLIC	16
 | 
					 | 
				
			||||||
#define DT_REL	        17
 | 
					 | 
				
			||||||
#define DT_RELSZ	18
 | 
					 | 
				
			||||||
#define DT_RELENT	19
 | 
					 | 
				
			||||||
#define DT_PLTREL	20
 | 
					 | 
				
			||||||
#define DT_DEBUG	21
 | 
					 | 
				
			||||||
#define DT_TEXTREL	22
 | 
					 | 
				
			||||||
#define DT_JMPREL	23
 | 
					 | 
				
			||||||
#define DT_LOPROC	0x70000000
 | 
					 | 
				
			||||||
#define DT_HIPROC	0x7fffffff
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* This info is needed when parsing the symbol table */
 | 
					 | 
				
			||||||
#define STB_LOCAL  0
 | 
					 | 
				
			||||||
#define STB_GLOBAL 1
 | 
					 | 
				
			||||||
#define STB_WEAK   2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define STT_NOTYPE  0
 | 
					 | 
				
			||||||
#define STT_OBJECT  1
 | 
					 | 
				
			||||||
#define STT_FUNC    2
 | 
					 | 
				
			||||||
#define STT_SECTION 3
 | 
					 | 
				
			||||||
#define STT_FILE    4
 | 
					 | 
				
			||||||
#define STT_LOPROC  13
 | 
					 | 
				
			||||||
#define STT_HIPROC  15
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ELF32_ST_BIND(x) ((x) >> 4)
 | 
					 | 
				
			||||||
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ELF64_ST_BIND(x) ELF32_ST_BIND (x)
 | 
					 | 
				
			||||||
#define ELF64_ST_TYPE(x) ELF32_ST_TYPE (x)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct dynamic32 {
 | 
					 | 
				
			||||||
    Elf32_Sword d_tag;
 | 
					 | 
				
			||||||
    union {
 | 
					 | 
				
			||||||
	Elf32_Sword d_val;
 | 
					 | 
				
			||||||
	Elf32_Addr d_ptr;
 | 
					 | 
				
			||||||
    } d_un;
 | 
					 | 
				
			||||||
} Elf32_Dyn;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct dynamic64 {
 | 
					 | 
				
			||||||
    Elf64_Sxword d_tag;
 | 
					 | 
				
			||||||
    union {
 | 
					 | 
				
			||||||
	Elf64_Xword d_val;
 | 
					 | 
				
			||||||
	Elf64_Addr d_ptr;
 | 
					 | 
				
			||||||
    } d_un;
 | 
					 | 
				
			||||||
} Elf64_Dyn;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_XORG_CONFIG_H
 | 
					 | 
				
			||||||
#include <xorg-config.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef QNX4
 | 
					 | 
				
			||||||
extern Elf32_Dyn _DYNAMIC[];
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* The following are used with relocations */
 | 
					 | 
				
			||||||
#define ELF32_R_SYM(x) ((x) >> 8)
 | 
					 | 
				
			||||||
#define ELF32_R_TYPE(x) ((x) & 0xff)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ELF64_R_SYM(x)  ((x) >> 32)
 | 
					 | 
				
			||||||
#define ELF64_R_TYPE(x)  ((x) & 0xffffffff)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* x86 Relocation Types */
 | 
					 | 
				
			||||||
#define R_386_NONE	0
 | 
					 | 
				
			||||||
#define R_386_32	1
 | 
					 | 
				
			||||||
#define R_386_PC32	2
 | 
					 | 
				
			||||||
#define R_386_GOT32	3
 | 
					 | 
				
			||||||
#define R_386_PLT32	4
 | 
					 | 
				
			||||||
#define R_386_COPY	5
 | 
					 | 
				
			||||||
#define R_386_GLOB_DAT	6
 | 
					 | 
				
			||||||
#define R_386_JMP_SLOT	7
 | 
					 | 
				
			||||||
#define R_386_RELATIVE	8
 | 
					 | 
				
			||||||
#define R_386_GOTOFF	9
 | 
					 | 
				
			||||||
#define R_386_GOTPC	10
 | 
					 | 
				
			||||||
#define R_386_NUM	11
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* AMD64 Relocation Types */
 | 
					 | 
				
			||||||
#define R_X86_64_NONE                   0
 | 
					 | 
				
			||||||
#define R_X86_64_64                     1
 | 
					 | 
				
			||||||
#define R_X86_64_PC32                   2
 | 
					 | 
				
			||||||
#define R_X86_64_GOT32                  3
 | 
					 | 
				
			||||||
#define R_X86_64_PLT32                  4
 | 
					 | 
				
			||||||
#define R_X86_64_COPY                   5
 | 
					 | 
				
			||||||
#define R_X86_64_GLOB_DAT               6
 | 
					 | 
				
			||||||
#define R_X86_64_JUMP_SLOT              7
 | 
					 | 
				
			||||||
#define R_X86_64_RELATIVE               8
 | 
					 | 
				
			||||||
#define R_X86_64_GOTPCREL               9
 | 
					 | 
				
			||||||
#define R_X86_64_32                    10
 | 
					 | 
				
			||||||
#define R_X86_64_32S                   11
 | 
					 | 
				
			||||||
#define R_X86_64_16                    12
 | 
					 | 
				
			||||||
#define R_X86_64_PC16                  13
 | 
					 | 
				
			||||||
#define R_X86_64_8                     14
 | 
					 | 
				
			||||||
#define R_X86_64_PC8                   15
 | 
					 | 
				
			||||||
#define R_X86_64_GNU_VTINHERIT         250
 | 
					 | 
				
			||||||
#define R_X86_64_GNU_VTENTRY           251
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* sparc Relocation Types */
 | 
					 | 
				
			||||||
#define	R_SPARC_NONE		0
 | 
					 | 
				
			||||||
#define	R_SPARC_8		1
 | 
					 | 
				
			||||||
#define	R_SPARC_16		2
 | 
					 | 
				
			||||||
#define	R_SPARC_32		3
 | 
					 | 
				
			||||||
#define	R_SPARC_DISP8		4
 | 
					 | 
				
			||||||
#define	R_SPARC_DISP16		5
 | 
					 | 
				
			||||||
#define	R_SPARC_DISP32		6
 | 
					 | 
				
			||||||
#define	R_SPARC_WDISP30		7
 | 
					 | 
				
			||||||
#define	R_SPARC_WDISP22		8
 | 
					 | 
				
			||||||
#define	R_SPARC_HI22		9
 | 
					 | 
				
			||||||
#define	R_SPARC_22		10
 | 
					 | 
				
			||||||
#define	R_SPARC_13		11
 | 
					 | 
				
			||||||
#define	R_SPARC_LO10		12
 | 
					 | 
				
			||||||
#define	R_SPARC_GOT10		13
 | 
					 | 
				
			||||||
#define	R_SPARC_GOT13		14
 | 
					 | 
				
			||||||
#define	R_SPARC_GOT22		15
 | 
					 | 
				
			||||||
#define	R_SPARC_PC10		16
 | 
					 | 
				
			||||||
#define	R_SPARC_PC22		17
 | 
					 | 
				
			||||||
#define	R_SPARC_WPLT30		18
 | 
					 | 
				
			||||||
#define	R_SPARC_COPY		19
 | 
					 | 
				
			||||||
#define	R_SPARC_GLOB_DAT	20
 | 
					 | 
				
			||||||
#define	R_SPARC_JMP_SLOT	21
 | 
					 | 
				
			||||||
#define	R_SPARC_RELATIVE	22
 | 
					 | 
				
			||||||
#define	R_SPARC_UA32		23
 | 
					 | 
				
			||||||
#define	R_SPARC_PLT32		24
 | 
					 | 
				
			||||||
#define	R_SPARC_HIPLT22		25
 | 
					 | 
				
			||||||
#define	R_SPARC_LOPLT10		26
 | 
					 | 
				
			||||||
#define	R_SPARC_PCPLT32		27
 | 
					 | 
				
			||||||
#define	R_SPARC_PCPLT22		28
 | 
					 | 
				
			||||||
#define	R_SPARC_PCPLT10		29
 | 
					 | 
				
			||||||
#define	R_SPARC_10		30
 | 
					 | 
				
			||||||
#define	R_SPARC_11		31
 | 
					 | 
				
			||||||
#define	R_SPARC_64		32
 | 
					 | 
				
			||||||
#define	R_SPARC_OLO10		33
 | 
					 | 
				
			||||||
#define	R_SPARC_HH22		34
 | 
					 | 
				
			||||||
#define	R_SPARC_HM10		35
 | 
					 | 
				
			||||||
#define	R_SPARC_LM22		36
 | 
					 | 
				
			||||||
#define	R_SPARC_PC_HH22		37
 | 
					 | 
				
			||||||
#define	R_SPARC_PC_HM10		38
 | 
					 | 
				
			||||||
#define	R_SPARC_PC_LM22		39
 | 
					 | 
				
			||||||
#define	R_SPARC_WDISP16		40
 | 
					 | 
				
			||||||
#define	R_SPARC_WDISP19		41
 | 
					 | 
				
			||||||
#define	R_SPARC_GLOB_JMP	42
 | 
					 | 
				
			||||||
#define	R_SPARC_7		43
 | 
					 | 
				
			||||||
#define	R_SPARC_5		44
 | 
					 | 
				
			||||||
#define	R_SPARC_6		45
 | 
					 | 
				
			||||||
#define	R_SPARC_DISP64		46
 | 
					 | 
				
			||||||
#define	R_SPARC_PLT64		47
 | 
					 | 
				
			||||||
#define	R_SPARC_HIX22		48
 | 
					 | 
				
			||||||
#define	R_SPARC_LOX10		49
 | 
					 | 
				
			||||||
#define	R_SPARC_H44		50
 | 
					 | 
				
			||||||
#define	R_SPARC_M44		51
 | 
					 | 
				
			||||||
#define	R_SPARC_L44		52
 | 
					 | 
				
			||||||
#define	R_SPARC_REGISTER	53
 | 
					 | 
				
			||||||
#define	R_SPARC_UA64		54
 | 
					 | 
				
			||||||
#define	R_SPARC_UA16		55
 | 
					 | 
				
			||||||
#define	R_SPARC_NUM		56
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* m68k Relocation Types */
 | 
					 | 
				
			||||||
#define R_68K_NONE	0	/* No reloc */
 | 
					 | 
				
			||||||
#define R_68K_32	1	/* Direct 32 bit  */
 | 
					 | 
				
			||||||
#define R_68K_16	2	/* Direct 16 bit  */
 | 
					 | 
				
			||||||
#define R_68K_8		3	/* Direct 8 bit  */
 | 
					 | 
				
			||||||
#define R_68K_PC32	4	/* PC relative 32 bit */
 | 
					 | 
				
			||||||
#define R_68K_PC16	5	/* PC relative 16 bit */
 | 
					 | 
				
			||||||
#define R_68K_PC8	6	/* PC relative 8 bit */
 | 
					 | 
				
			||||||
#define R_68K_GOT32	7	/* 32 bit PC relative GOT entry */
 | 
					 | 
				
			||||||
#define R_68K_GOT16	8	/* 16 bit PC relative GOT entry */
 | 
					 | 
				
			||||||
#define R_68K_GOT8	9	/* 8 bit PC relative GOT entry */
 | 
					 | 
				
			||||||
#define R_68K_GOT32O	10	/* 32 bit GOT offset */
 | 
					 | 
				
			||||||
#define R_68K_GOT16O	11	/* 16 bit GOT offset */
 | 
					 | 
				
			||||||
#define R_68K_GOT8O	12	/* 8 bit GOT offset */
 | 
					 | 
				
			||||||
#define R_68K_PLT32	13	/* 32 bit PC relative PLT address */
 | 
					 | 
				
			||||||
#define R_68K_PLT16	14	/* 16 bit PC relative PLT address */
 | 
					 | 
				
			||||||
#define R_68K_PLT8	15	/* 8 bit PC relative PLT address */
 | 
					 | 
				
			||||||
#define R_68K_PLT32O	16	/* 32 bit PLT offset */
 | 
					 | 
				
			||||||
#define R_68K_PLT16O	17	/* 16 bit PLT offset */
 | 
					 | 
				
			||||||
#define R_68K_PLT8O	18	/* 8 bit PLT offset */
 | 
					 | 
				
			||||||
#define R_68K_COPY	19	/* Copy symbol at runtime */
 | 
					 | 
				
			||||||
#define R_68K_GLOB_DAT	20	/* Create GOT entry */
 | 
					 | 
				
			||||||
#define R_68K_JMP_SLOT	21	/* Create PLT entry */
 | 
					 | 
				
			||||||
#define R_68K_RELATIVE	22	/* Adjust by program base */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Alpha Relocation Types */
 | 
					 | 
				
			||||||
#define R_ALPHA_NONE		0	/* No reloc */
 | 
					 | 
				
			||||||
#define R_ALPHA_REFLONG		1	/* Direct 32 bit */
 | 
					 | 
				
			||||||
#define R_ALPHA_REFQUAD		2	/* Direct 64 bit */
 | 
					 | 
				
			||||||
#define R_ALPHA_GPREL32		3	/* GP relative 32 bit */
 | 
					 | 
				
			||||||
#define R_ALPHA_LITERAL		4	/* GP relative 16 bit w/optimization */
 | 
					 | 
				
			||||||
#define R_ALPHA_LITUSE		5	/* Optimization hint for LITERAL */
 | 
					 | 
				
			||||||
#define R_ALPHA_GPDISP		6	/* Add displacement to GP */
 | 
					 | 
				
			||||||
#define R_ALPHA_BRADDR		7	/* PC+4 relative 23 bit shifted */
 | 
					 | 
				
			||||||
#define R_ALPHA_HINT		8	/* PC+4 relative 16 bit shifted */
 | 
					 | 
				
			||||||
#define R_ALPHA_SREL16		9	/* PC relative 16 bit */
 | 
					 | 
				
			||||||
#define R_ALPHA_SREL32		10	/* PC relative 32 bit */
 | 
					 | 
				
			||||||
#define R_ALPHA_SREL64		11	/* PC relative 64 bit */
 | 
					 | 
				
			||||||
#define R_ALPHA_OP_PUSH		12	/* OP stack push */
 | 
					 | 
				
			||||||
#define R_ALPHA_OP_STORE	13	/* OP stack pop and store */
 | 
					 | 
				
			||||||
#define R_ALPHA_OP_PSUB		14	/* OP stack subtract */
 | 
					 | 
				
			||||||
#define R_ALPHA_OP_PRSHIFT	15	/* OP stack right shift */
 | 
					 | 
				
			||||||
#define R_ALPHA_GPVALUE		16
 | 
					 | 
				
			||||||
#define R_ALPHA_GPRELHIGH	17
 | 
					 | 
				
			||||||
#define R_ALPHA_GPRELLOW	18
 | 
					 | 
				
			||||||
#define R_ALPHA_GPREL16		19
 | 
					 | 
				
			||||||
#define R_ALPHA_IMMED_GP_HI32	20
 | 
					 | 
				
			||||||
#define R_ALPHA_IMMED_SCN_HI32	21
 | 
					 | 
				
			||||||
#define R_ALPHA_IMMED_BR_HI32	22
 | 
					 | 
				
			||||||
#define R_ALPHA_IMMED_LO32	23
 | 
					 | 
				
			||||||
#define R_ALPHA_COPY		24	/* Copy symbol at runtime */
 | 
					 | 
				
			||||||
#define R_ALPHA_GLOB_DAT	25	/* Create GOT entry */
 | 
					 | 
				
			||||||
#define R_ALPHA_JMP_SLOT	26	/* Create PLT entry */
 | 
					 | 
				
			||||||
#define R_ALPHA_RELATIVE	27	/* Adjust by program base */
 | 
					 | 
				
			||||||
#define R_ALPHA_BRSGP		28	/* Calc displacement for BRS */   
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* IA-64 relocations.  */
 | 
					 | 
				
			||||||
#define R_IA64_NONE		0x00	/* none */
 | 
					 | 
				
			||||||
#define R_IA64_IMM14		0x21	/* symbol + addend, add imm14 */
 | 
					 | 
				
			||||||
#define R_IA64_IMM22		0x22	/* symbol + addend, add imm22 */
 | 
					 | 
				
			||||||
#define R_IA64_IMM64		0x23	/* symbol + addend, mov imm64 */
 | 
					 | 
				
			||||||
#define R_IA64_DIR32MSB		0x24	/* symbol + addend, data4 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_DIR32LSB		0x25	/* symbol + addend, data4 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_DIR64MSB		0x26	/* symbol + addend, data8 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_DIR64LSB		0x27	/* symbol + addend, data8 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_GPREL22		0x2a	/* @gprel(sym + add), add imm22 */
 | 
					 | 
				
			||||||
#define R_IA64_GPREL64I		0x2b	/* @gprel(sym + add), mov imm64 */
 | 
					 | 
				
			||||||
#define R_IA64_GPREL64MSB	0x2e	/* @gprel(sym + add), data8 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_GPREL64LSB	0x2f	/* @gprel(sym + add), data8 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_LTOFF22		0x32	/* @ltoff(sym + add), add imm22 */
 | 
					 | 
				
			||||||
#define R_IA64_LTOFF64I		0x33	/* @ltoff(sym + add), mov imm64 */
 | 
					 | 
				
			||||||
#define R_IA64_PLTOFF22		0x3a	/* @pltoff(sym + add), add imm22 */
 | 
					 | 
				
			||||||
#define R_IA64_PLTOFF64I	0x3b	/* @pltoff(sym + add), mov imm64 */
 | 
					 | 
				
			||||||
#define R_IA64_PLTOFF64MSB	0x3e	/* @pltoff(sym + add), data8 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_PLTOFF64LSB	0x3f	/* @pltoff(sym + add), data8 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_FPTR64I		0x43	/* @fptr(sym + add), mov imm64 */
 | 
					 | 
				
			||||||
#define R_IA64_FPTR32MSB	0x44	/* @fptr(sym + add), data4 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_FPTR32LSB	0x45	/* @fptr(sym + add), data4 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_FPTR64MSB	0x46	/* @fptr(sym + add), data8 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_FPTR64LSB	0x47	/* @fptr(sym + add), data8 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_PCREL21B		0x49	/* @pcrel(sym + add), ptb, call */
 | 
					 | 
				
			||||||
#define R_IA64_PCREL21M		0x4a	/* @pcrel(sym + add), chk.s */
 | 
					 | 
				
			||||||
#define R_IA64_PCREL21F		0x4b	/* @pcrel(sym + add), fchkf */
 | 
					 | 
				
			||||||
#define R_IA64_PCREL32MSB	0x4c	/* @pcrel(sym + add), data4 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_PCREL32LSB	0x4d	/* @pcrel(sym + add), data4 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_PCREL64MSB	0x4e	/* @pcrel(sym + add), data8 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_PCREL64LSB	0x4f	/* @pcrel(sym + add), data8 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_LTOFF_FPTR22	0x52	/* @ltoff(@fptr(s+a)), imm22 */
 | 
					 | 
				
			||||||
#define R_IA64_LTOFF_FPTR64I	0x53	/* @ltoff(@fptr(s+a)), imm64 */
 | 
					 | 
				
			||||||
#define R_IA64_SEGREL32MSB	0x5c	/* @segrel(sym + add), data4 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_SEGREL32LSB	0x5d	/* @segrel(sym + add), data4 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_SEGREL64MSB	0x5e	/* @segrel(sym + add), data8 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_SEGREL64LSB	0x5f	/* @segrel(sym + add), data8 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_SECREL32MSB	0x64	/* @secrel(sym + add), data4 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_SECREL32LSB	0x65	/* @secrel(sym + add), data4 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_SECREL64MSB	0x66	/* @secrel(sym + add), data8 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_SECREL64LSB	0x67	/* @secrel(sym + add), data8 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_REL32MSB		0x6c	/* data 4 + REL */
 | 
					 | 
				
			||||||
#define R_IA64_REL32LSB		0x6d	/* data 4 + REL */
 | 
					 | 
				
			||||||
#define R_IA64_REL64MSB		0x6e	/* data 8 + REL */
 | 
					 | 
				
			||||||
#define R_IA64_REL64LSB		0x6f	/* data 8 + REL */
 | 
					 | 
				
			||||||
#define R_IA64_LTV32MSB		0x70	/* symbol + addend, data4 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_LTV32LSB		0x71	/* symbol + addend, data4 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_LTV64MSB		0x72	/* symbol + addend, data8 MSB */
 | 
					 | 
				
			||||||
#define R_IA64_LTV64LSB		0x73	/* symbol + addend, data8 LSB */
 | 
					 | 
				
			||||||
#define R_IA64_IPLTMSB		0x80	/* dynamic reloc, imported PLT, MSB */
 | 
					 | 
				
			||||||
#define R_IA64_IPLTLSB		0x81	/* dynamic reloc, imported PLT, LSB */
 | 
					 | 
				
			||||||
#define R_IA64_LTOFF22X		0x86	/* LTOFF22, relaxable.  */
 | 
					 | 
				
			||||||
#define R_IA64_LDXMOV		0x87	/* Use of LTOFF22X.  */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define R_IA64_TYPE(R)		((R) & -8)
 | 
					 | 
				
			||||||
#define R_IA64_FORMAT(R)	((R) & 7)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Apparantly, Linux and PowerMAXOS use different version of ELF as the
 | 
					 | 
				
			||||||
 * Relocation types are very different.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#if defined(PowerMAX_OS)
 | 
					 | 
				
			||||||
/* PPC Relocation Types */
 | 
					 | 
				
			||||||
#define R_PPC_NONE              0
 | 
					 | 
				
			||||||
#define R_PPC_COPY              1
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_ENT          2
 | 
					 | 
				
			||||||
#define R_PPC_8                 4
 | 
					 | 
				
			||||||
#define R_PPC_8S                5
 | 
					 | 
				
			||||||
#define R_PPC_16S               7
 | 
					 | 
				
			||||||
#define R_PPC_14                8
 | 
					 | 
				
			||||||
#define R_PPC_DISP14            9
 | 
					 | 
				
			||||||
#define R_PPC_24                10
 | 
					 | 
				
			||||||
#define R_PPC_DISP24            11
 | 
					 | 
				
			||||||
#define R_PPC_PLT_DISP24        14
 | 
					 | 
				
			||||||
#define R_PPC_BBASED_16HU       15
 | 
					 | 
				
			||||||
#define R_PPC_BBASED_32         16
 | 
					 | 
				
			||||||
#define R_PPC_BBASED_32UA       17
 | 
					 | 
				
			||||||
#define R_PPC_BBASED_16H        18
 | 
					 | 
				
			||||||
#define R_PPC_BBASED_16L        19
 | 
					 | 
				
			||||||
#define R_PPC_ABDIFF_16HU       23
 | 
					 | 
				
			||||||
#define R_PPC_ABDIFF_32         24
 | 
					 | 
				
			||||||
#define R_PPC_ABDIFF_32UA       25
 | 
					 | 
				
			||||||
#define R_PPC_ABDIFF_16H        26
 | 
					 | 
				
			||||||
#define R_PPC_ABDIFF_16L        27
 | 
					 | 
				
			||||||
#define R_PPC_ABDIFF_16         28
 | 
					 | 
				
			||||||
#define R_PPC_16HU              31
 | 
					 | 
				
			||||||
#define R_PPC_32                32
 | 
					 | 
				
			||||||
#define R_PPC_32UA              33
 | 
					 | 
				
			||||||
#define R_PPC_16H               34
 | 
					 | 
				
			||||||
#define R_PPC_16L               35
 | 
					 | 
				
			||||||
#define R_PPC_16                36
 | 
					 | 
				
			||||||
#define R_PPC_GOT_16HU          39
 | 
					 | 
				
			||||||
#define R_PPC_GOT_32            40
 | 
					 | 
				
			||||||
#define R_PPC_GOT_32UA          41
 | 
					 | 
				
			||||||
#define R_PPC_GOT_16H           42
 | 
					 | 
				
			||||||
#define R_PPC_GOT_16L           43
 | 
					 | 
				
			||||||
#define R_PPC_GOT_16            44
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_16HU         47
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_32           48
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_32UA         49
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_16H          50
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_16L          51
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_16           52
 | 
					 | 
				
			||||||
#define R_PPC_PLT_16HU          55
 | 
					 | 
				
			||||||
#define R_PPC_PLT_32            56
 | 
					 | 
				
			||||||
#define R_PPC_PLT_32UA          57
 | 
					 | 
				
			||||||
#define R_PPC_PLT_16H           58
 | 
					 | 
				
			||||||
#define R_PPC_PLT_16L           59
 | 
					 | 
				
			||||||
#define R_PPC_PLT_16            60
 | 
					 | 
				
			||||||
#define R_PPC_ABREL_16HU        63
 | 
					 | 
				
			||||||
#define R_PPC_ABREL_32          64
 | 
					 | 
				
			||||||
#define R_PPC_ABREL_32UA        65
 | 
					 | 
				
			||||||
#define R_PPC_ABREL_16H         66
 | 
					 | 
				
			||||||
#define R_PPC_ABREL_16L         67
 | 
					 | 
				
			||||||
#define R_PPC_ABREL_16          68
 | 
					 | 
				
			||||||
#define R_PPC_GOT_ABREL_16HU    71
 | 
					 | 
				
			||||||
#define R_PPC_GOT_ABREL_32      72
 | 
					 | 
				
			||||||
#define R_PPC_GOT_ABREL_32UA    73
 | 
					 | 
				
			||||||
#define R_PPC_GOT_ABREL_16H     74
 | 
					 | 
				
			||||||
#define R_PPC_GOT_ABREL_16L     75
 | 
					 | 
				
			||||||
#define R_PPC_GOT_ABREL_16      76
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_ABREL_16HU   79
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_ABREL_32     80
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_ABREL_32UA   81
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_ABREL_16H    82
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_ABREL_16L    83
 | 
					 | 
				
			||||||
#define R_PPC_GOTP_ABREL_16     84
 | 
					 | 
				
			||||||
#define R_PPC_PLT_ABREL_16HU    87
 | 
					 | 
				
			||||||
#define R_PPC_PLT_ABREL_32      88
 | 
					 | 
				
			||||||
#define R_PPC_PLT_ABREL_32UA    89
 | 
					 | 
				
			||||||
#define R_PPC_PLT_ABREL_16H     90
 | 
					 | 
				
			||||||
#define R_PPC_PLT_ABREL_16L     91
 | 
					 | 
				
			||||||
#define R_PPC_PLT_ABREL_16      92
 | 
					 | 
				
			||||||
#define R_PPC_SREL_16HU         95
 | 
					 | 
				
			||||||
#define R_PPC_SREL_32           96
 | 
					 | 
				
			||||||
#define R_PPC_SREL_32UA         97
 | 
					 | 
				
			||||||
#define R_PPC_SREL_16H          98
 | 
					 | 
				
			||||||
#define R_PPC_SREL_16L          99
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * The Linux version
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define R_PPC_NONE		0
 | 
					 | 
				
			||||||
#define R_PPC_ADDR32		1
 | 
					 | 
				
			||||||
#define R_PPC_ADDR24		2
 | 
					 | 
				
			||||||
#define R_PPC_ADDR16		3
 | 
					 | 
				
			||||||
#define R_PPC_ADDR16_LO		4
 | 
					 | 
				
			||||||
#define R_PPC_ADDR16_HI		5
 | 
					 | 
				
			||||||
#define R_PPC_ADDR16_HA		6
 | 
					 | 
				
			||||||
#define R_PPC_ADDR14		7
 | 
					 | 
				
			||||||
#define R_PPC_ADDR14_BRTAKEN	8
 | 
					 | 
				
			||||||
#define R_PPC_ADDR14_BRNTAKEN	9
 | 
					 | 
				
			||||||
#define R_PPC_REL24		10
 | 
					 | 
				
			||||||
#define R_PPC_REL14		11
 | 
					 | 
				
			||||||
#define R_PPC_REL14_BRTAKEN	12
 | 
					 | 
				
			||||||
#define R_PPC_REL14_BRNTAKEN	13
 | 
					 | 
				
			||||||
#define R_PPC_GOT16		14
 | 
					 | 
				
			||||||
#define R_PPC_GOT16_LO		15
 | 
					 | 
				
			||||||
#define R_PPC_GOT16_HI		16
 | 
					 | 
				
			||||||
#define R_PPC_GOT16_HA		17
 | 
					 | 
				
			||||||
#define R_PPC_PLTREL24		18
 | 
					 | 
				
			||||||
#define R_PPC_COPY		19
 | 
					 | 
				
			||||||
#define R_PPC_GLOB_DAT		20
 | 
					 | 
				
			||||||
#define R_PPC_JMP_SLOT		21
 | 
					 | 
				
			||||||
#define R_PPC_RELATIVE		22
 | 
					 | 
				
			||||||
#define R_PPC_LOCAL24PC		23
 | 
					 | 
				
			||||||
#define R_PPC_UADDR32		24
 | 
					 | 
				
			||||||
#define R_PPC_UADDR16		25
 | 
					 | 
				
			||||||
#define R_PPC_REL32		26
 | 
					 | 
				
			||||||
#define R_PPC_PLT32		27
 | 
					 | 
				
			||||||
#define R_PPC_PLTREL32		28
 | 
					 | 
				
			||||||
#define R_PPC_PLT16_LO		29
 | 
					 | 
				
			||||||
#define R_PPC_PLT16_HI		30
 | 
					 | 
				
			||||||
#define R_PPC_PLT16_HA		31
 | 
					 | 
				
			||||||
#define R_PPC_SDAREL16		32
 | 
					 | 
				
			||||||
#define R_PPC_SECTOFF		33
 | 
					 | 
				
			||||||
#define R_PPC_SECTOFF_LO	34
 | 
					 | 
				
			||||||
#define R_PPC_SECTOFF_HI	35
 | 
					 | 
				
			||||||
#define R_PPC_SECTOFF_HA	36
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ARM relocs.  */
 | 
					 | 
				
			||||||
#define R_ARM_NONE		0	/* No reloc */
 | 
					 | 
				
			||||||
#define R_ARM_PC24		1	/* PC relative 26 bit branch */
 | 
					 | 
				
			||||||
#define R_ARM_ABS32		2	/* Direct 32 bit  */
 | 
					 | 
				
			||||||
#define R_ARM_REL32		3	/* PC relative 32 bit */
 | 
					 | 
				
			||||||
#define R_ARM_PC13		4
 | 
					 | 
				
			||||||
#define R_ARM_ABS16		5	/* Direct 16 bit */
 | 
					 | 
				
			||||||
#define R_ARM_ABS12		6	/* Direct 12 bit */
 | 
					 | 
				
			||||||
#define R_ARM_THM_ABS5		7
 | 
					 | 
				
			||||||
#define R_ARM_ABS8		8	/* Direct 8 bit */
 | 
					 | 
				
			||||||
#define R_ARM_SBREL32		9
 | 
					 | 
				
			||||||
#define R_ARM_THM_PC22		10
 | 
					 | 
				
			||||||
#define R_ARM_THM_PC8		11
 | 
					 | 
				
			||||||
#define R_ARM_AMP_VCALL9	12
 | 
					 | 
				
			||||||
#define R_ARM_SWI24		13
 | 
					 | 
				
			||||||
#define R_ARM_THM_SWI8		14
 | 
					 | 
				
			||||||
#define R_ARM_XPC25		15
 | 
					 | 
				
			||||||
#define R_ARM_THM_XPC22		16
 | 
					 | 
				
			||||||
#define R_ARM_COPY		20	/* Copy symbol at runtime */
 | 
					 | 
				
			||||||
#define R_ARM_GLOB_DAT		21	/* Create GOT entry */
 | 
					 | 
				
			||||||
#define R_ARM_JUMP_SLOT		22	/* Create PLT entry */
 | 
					 | 
				
			||||||
#define R_ARM_RELATIVE		23	/* Adjust by program base */
 | 
					 | 
				
			||||||
#define R_ARM_GOTOFF		24	/* 32 bit offset to GOT */
 | 
					 | 
				
			||||||
#define R_ARM_GOTPC		25	/* 32 bit PC relative offset to GOT */
 | 
					 | 
				
			||||||
#define R_ARM_GOT32		26	/* 32 bit GOT entry */
 | 
					 | 
				
			||||||
#define R_ARM_PLT32		27	/* 32 bit PLT address */
 | 
					 | 
				
			||||||
#define R_ARM_GNU_VTENTRY	100
 | 
					 | 
				
			||||||
#define R_ARM_GNU_VTINHERIT	101
 | 
					 | 
				
			||||||
#define R_ARM_THM_PC11		102	/* thumb unconditional branch */
 | 
					 | 
				
			||||||
#define R_ARM_THM_PC9		103	/* thumb conditional branch */
 | 
					 | 
				
			||||||
#define R_ARM_RXPC25		249
 | 
					 | 
				
			||||||
#define R_ARM_RSBREL32		250
 | 
					 | 
				
			||||||
#define R_ARM_THM_RPC22		251
 | 
					 | 
				
			||||||
#define R_ARM_RREL32		252
 | 
					 | 
				
			||||||
#define R_ARM_RABS22		253
 | 
					 | 
				
			||||||
#define R_ARM_RPC24		254
 | 
					 | 
				
			||||||
#define R_ARM_RBASE		255
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf32_rel {
 | 
					 | 
				
			||||||
    Elf32_Addr r_offset;
 | 
					 | 
				
			||||||
    Elf32_Word r_info;
 | 
					 | 
				
			||||||
} Elf32_Rel;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf64_rel {
 | 
					 | 
				
			||||||
    Elf64_Addr r_offset;
 | 
					 | 
				
			||||||
    Elf64_Xword r_info;
 | 
					 | 
				
			||||||
} Elf64_Rel;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf32_rela {
 | 
					 | 
				
			||||||
    Elf32_Addr r_offset;
 | 
					 | 
				
			||||||
    Elf32_Word r_info;
 | 
					 | 
				
			||||||
    Elf32_Sword r_addend;
 | 
					 | 
				
			||||||
} Elf32_Rela;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf64_rela {
 | 
					 | 
				
			||||||
    Elf64_Addr r_offset;
 | 
					 | 
				
			||||||
    Elf64_Xword r_info;
 | 
					 | 
				
			||||||
    Elf64_Sxword r_addend;
 | 
					 | 
				
			||||||
} Elf64_Rela;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf32_sym {
 | 
					 | 
				
			||||||
    Elf32_Word st_name;
 | 
					 | 
				
			||||||
    Elf32_Addr st_value;
 | 
					 | 
				
			||||||
    Elf32_Word st_size;
 | 
					 | 
				
			||||||
    unsigned char st_info;
 | 
					 | 
				
			||||||
    unsigned char st_other;
 | 
					 | 
				
			||||||
    Elf32_Half st_shndx;
 | 
					 | 
				
			||||||
} Elf32_Sym;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf64_sym {
 | 
					 | 
				
			||||||
    Elf64_Word st_name;
 | 
					 | 
				
			||||||
    unsigned char st_info;
 | 
					 | 
				
			||||||
    unsigned char st_other;
 | 
					 | 
				
			||||||
    Elf64_Half st_shndx;
 | 
					 | 
				
			||||||
    Elf64_Addr st_value;
 | 
					 | 
				
			||||||
    Elf64_Xword st_size;
 | 
					 | 
				
			||||||
} Elf64_Sym;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define EI_NIDENT	16
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf32hdr {
 | 
					 | 
				
			||||||
    unsigned char e_ident[EI_NIDENT];
 | 
					 | 
				
			||||||
    Elf32_Half e_type;
 | 
					 | 
				
			||||||
    Elf32_Half e_machine;
 | 
					 | 
				
			||||||
    Elf32_Word e_version;
 | 
					 | 
				
			||||||
    Elf32_Addr e_entry;		/* Entry point */
 | 
					 | 
				
			||||||
    Elf32_Off e_phoff;
 | 
					 | 
				
			||||||
    Elf32_Off e_shoff;
 | 
					 | 
				
			||||||
    Elf32_Word e_flags;
 | 
					 | 
				
			||||||
    Elf32_Half e_ehsize;
 | 
					 | 
				
			||||||
    Elf32_Half e_phentsize;
 | 
					 | 
				
			||||||
    Elf32_Half e_phnum;
 | 
					 | 
				
			||||||
    Elf32_Half e_shentsize;
 | 
					 | 
				
			||||||
    Elf32_Half e_shnum;
 | 
					 | 
				
			||||||
    Elf32_Half e_shstrndx;
 | 
					 | 
				
			||||||
} Elf32_Ehdr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf64hdr {
 | 
					 | 
				
			||||||
    unsigned char e_ident[EI_NIDENT];
 | 
					 | 
				
			||||||
    Elf64_Half e_type;
 | 
					 | 
				
			||||||
    Elf64_Half e_machine;
 | 
					 | 
				
			||||||
    Elf64_Word e_version;
 | 
					 | 
				
			||||||
    Elf64_Addr e_entry;
 | 
					 | 
				
			||||||
    Elf64_Off e_phoff;
 | 
					 | 
				
			||||||
    Elf64_Off e_shoff;
 | 
					 | 
				
			||||||
    Elf64_Word e_flags;
 | 
					 | 
				
			||||||
    Elf64_Half e_ehsize;
 | 
					 | 
				
			||||||
    Elf64_Half e_phentsize;
 | 
					 | 
				
			||||||
    Elf64_Half e_phnum;
 | 
					 | 
				
			||||||
    Elf64_Half e_shentsize;
 | 
					 | 
				
			||||||
    Elf64_Half e_shnum;
 | 
					 | 
				
			||||||
    Elf64_Half e_shstrndx;
 | 
					 | 
				
			||||||
} Elf64_Ehdr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* These constants define the permissions on sections in the program
 | 
					 | 
				
			||||||
   header, p_flags. */
 | 
					 | 
				
			||||||
#define PF_R		0x4
 | 
					 | 
				
			||||||
#define PF_W		0x2
 | 
					 | 
				
			||||||
#define PF_X		0x1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct elf_phdr {
 | 
					 | 
				
			||||||
    Elf32_Word p_type;
 | 
					 | 
				
			||||||
    Elf32_Off p_offset;
 | 
					 | 
				
			||||||
    Elf32_Addr p_vaddr;
 | 
					 | 
				
			||||||
    Elf32_Addr p_paddr;
 | 
					 | 
				
			||||||
    Elf32_Word p_filesz;
 | 
					 | 
				
			||||||
    Elf32_Word p_memsz;
 | 
					 | 
				
			||||||
    Elf32_Word p_flags;
 | 
					 | 
				
			||||||
    Elf32_Word p_align;
 | 
					 | 
				
			||||||
} Elf32_Phdr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
    Elf64_Word p_type;
 | 
					 | 
				
			||||||
    Elf64_Word p_flags;
 | 
					 | 
				
			||||||
    Elf64_Off p_offset;
 | 
					 | 
				
			||||||
    Elf64_Addr p_vaddr;
 | 
					 | 
				
			||||||
    Elf64_Addr p_paddr;
 | 
					 | 
				
			||||||
    Elf64_Xword p_filesz;
 | 
					 | 
				
			||||||
    Elf64_Xword p_memsz;
 | 
					 | 
				
			||||||
    Elf64_Xword p_align;
 | 
					 | 
				
			||||||
} Elf64_Phdr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* sh_type */
 | 
					 | 
				
			||||||
#define SHT_NULL	0
 | 
					 | 
				
			||||||
#define SHT_PROGBITS	1
 | 
					 | 
				
			||||||
#define SHT_SYMTAB	2
 | 
					 | 
				
			||||||
#define SHT_STRTAB	3
 | 
					 | 
				
			||||||
#define SHT_RELA	4
 | 
					 | 
				
			||||||
#define SHT_HASH	5
 | 
					 | 
				
			||||||
#define SHT_DYNAMIC	6
 | 
					 | 
				
			||||||
#define SHT_NOTE	7
 | 
					 | 
				
			||||||
#define SHT_NOBITS	8
 | 
					 | 
				
			||||||
#define SHT_REL		9
 | 
					 | 
				
			||||||
#define SHT_SHLIB	10
 | 
					 | 
				
			||||||
#define SHT_DYNSYM	11
 | 
					 | 
				
			||||||
#define SHT_NUM		12
 | 
					 | 
				
			||||||
#define SHT_LOPROC	0x70000000
 | 
					 | 
				
			||||||
#define SHT_HIPROC	0x7fffffff
 | 
					 | 
				
			||||||
#define SHT_LOUSER	0x80000000
 | 
					 | 
				
			||||||
#define SHT_HIUSER	0xffffffff
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define SHT_IA_64_UNWIND	(SHT_LOPROC + 1)	/* unwind bits */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* sh_flags */
 | 
					 | 
				
			||||||
#define SHF_WRITE	0x1
 | 
					 | 
				
			||||||
#define SHF_ALLOC	0x2
 | 
					 | 
				
			||||||
#define SHF_EXECINSTR	0x4
 | 
					 | 
				
			||||||
#define SHF_MASKPROC	0xf0000000
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* special section indexes */
 | 
					 | 
				
			||||||
#define SHN_UNDEF	0
 | 
					 | 
				
			||||||
#define SHN_LORESERVE	0xff00
 | 
					 | 
				
			||||||
#define SHN_LOPROC	0xff00
 | 
					 | 
				
			||||||
#define SHN_HIPROC	0xff1f
 | 
					 | 
				
			||||||
#define SHN_ABS		0xfff1
 | 
					 | 
				
			||||||
#define SHN_COMMON	0xfff2
 | 
					 | 
				
			||||||
#define SHN_HIRESERVE	0xffff
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
    Elf32_Word sh_name;
 | 
					 | 
				
			||||||
    Elf32_Word sh_type;
 | 
					 | 
				
			||||||
    Elf32_Word sh_flags;
 | 
					 | 
				
			||||||
    Elf32_Addr sh_addr;
 | 
					 | 
				
			||||||
    Elf32_Off sh_offset;
 | 
					 | 
				
			||||||
    Elf32_Word sh_size;
 | 
					 | 
				
			||||||
    Elf32_Word sh_link;
 | 
					 | 
				
			||||||
    Elf32_Word sh_info;
 | 
					 | 
				
			||||||
    Elf32_Word sh_addralign;
 | 
					 | 
				
			||||||
    Elf32_Word sh_entsize;
 | 
					 | 
				
			||||||
} Elf32_Shdr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct {
 | 
					 | 
				
			||||||
    Elf64_Word sh_name;
 | 
					 | 
				
			||||||
    Elf64_Word sh_type;
 | 
					 | 
				
			||||||
    Elf64_Xword sh_flags;
 | 
					 | 
				
			||||||
    Elf64_Addr sh_addr;
 | 
					 | 
				
			||||||
    Elf64_Off sh_offset;
 | 
					 | 
				
			||||||
    Elf64_Xword sh_size;
 | 
					 | 
				
			||||||
    Elf64_Word sh_link;
 | 
					 | 
				
			||||||
    Elf64_Word sh_info;
 | 
					 | 
				
			||||||
    Elf64_Xword sh_addralign;
 | 
					 | 
				
			||||||
    Elf64_Xword sh_entsize;
 | 
					 | 
				
			||||||
} Elf64_Shdr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define	EI_MAG0		0	/* e_ident[] indexes */
 | 
					 | 
				
			||||||
#define	EI_MAG1		1
 | 
					 | 
				
			||||||
#define	EI_MAG2		2
 | 
					 | 
				
			||||||
#define	EI_MAG3		3
 | 
					 | 
				
			||||||
#define	EI_CLASS	4
 | 
					 | 
				
			||||||
#define	EI_DATA		5
 | 
					 | 
				
			||||||
#define	EI_VERSION	6
 | 
					 | 
				
			||||||
#define	EI_PAD		7
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define	ELFMAG0		0x7f	/* EI_MAG */
 | 
					 | 
				
			||||||
#define	ELFMAG1		'E'
 | 
					 | 
				
			||||||
#define	ELFMAG2		'L'
 | 
					 | 
				
			||||||
#define	ELFMAG3		'F'
 | 
					 | 
				
			||||||
#define	ELFMAG		"\177ELF"
 | 
					 | 
				
			||||||
#define	SELFMAG		4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define	ELFDLMAG	3
 | 
					 | 
				
			||||||
#define	ELFDLOFF	16
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define	ELFCLASSNONE	0	/* EI_CLASS */
 | 
					 | 
				
			||||||
#define	ELFCLASS32	1
 | 
					 | 
				
			||||||
#define	ELFCLASS64	2
 | 
					 | 
				
			||||||
#define	ELFCLASSNUM	3
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ELFDATANONE	0	/* e_ident[EI_DATA] */
 | 
					 | 
				
			||||||
#define ELFDATA2LSB	1
 | 
					 | 
				
			||||||
#define ELFDATA2MSB	2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define EV_NONE		0	/* e_version, EI_VERSION */
 | 
					 | 
				
			||||||
#define EV_CURRENT	1
 | 
					 | 
				
			||||||
#define EV_NUM		2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Notes used in ET_CORE */
 | 
					 | 
				
			||||||
#define NT_PRSTATUS	1
 | 
					 | 
				
			||||||
#define NT_PRFPREG	2
 | 
					 | 
				
			||||||
#define NT_PRPSINFO	3
 | 
					 | 
				
			||||||
#define NT_TASKSTRUCT	4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Note header in a PT_NOTE section */
 | 
					 | 
				
			||||||
typedef struct elf_note {
 | 
					 | 
				
			||||||
    Elf32_Word n_namesz;	/* Name size */
 | 
					 | 
				
			||||||
    Elf32_Word n_descsz;	/* Content size */
 | 
					 | 
				
			||||||
    Elf32_Word n_type;		/* Content type */
 | 
					 | 
				
			||||||
} Elf32_Nhdr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define ELF_START_MMAP 0x80000000
 | 
					 | 
				
			||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
					@ -1,38 +0,0 @@
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Copyright 1997,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.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/elfloader.h,v 1.3 1998/09/20 14:41:05 dawes Exp $ */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_XORG_CONFIG_H
 | 
					 | 
				
			||||||
#include <xorg-config.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef _ELFLOADER_H
 | 
					 | 
				
			||||||
#define _ELFLOADER_H
 | 
					 | 
				
			||||||
/* elfloader.c */
 | 
					 | 
				
			||||||
extern void *ELFLoadModule(loaderPtr, int, LOOKUP **, int flags);
 | 
					 | 
				
			||||||
extern void ELFResolveSymbols(void *);
 | 
					 | 
				
			||||||
extern int ELFCheckForUnresolved(void *);
 | 
					 | 
				
			||||||
extern char *ELFAddressToSection(void *, unsigned long);
 | 
					 | 
				
			||||||
extern void ELFUnloadModule(void *);
 | 
					 | 
				
			||||||
#endif /* _ELFLOADER_h */
 | 
					 | 
				
			||||||
| 
						 | 
					@ -69,9 +69,6 @@
 | 
				
			||||||
#include <malloc.h>
 | 
					#include <malloc.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#include <stdarg.h>
 | 
					#include <stdarg.h>
 | 
				
			||||||
#include "ar.h"
 | 
					 | 
				
			||||||
#include "elf.h"
 | 
					 | 
				
			||||||
#include "coff.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "os.h"
 | 
					#include "os.h"
 | 
				
			||||||
#include "sym.h"
 | 
					#include "sym.h"
 | 
				
			||||||
| 
						 | 
					@ -259,23 +256,10 @@ static int fatalReqSym = 0;
 | 
				
			||||||
static int _GetModuleType(int, long);
 | 
					static int _GetModuleType(int, long);
 | 
				
			||||||
static loaderPtr _LoaderListPush(void);
 | 
					static loaderPtr _LoaderListPush(void);
 | 
				
			||||||
static loaderPtr _LoaderListPop(int);
 | 
					static loaderPtr _LoaderListPop(int);
 | 
				
			||||||
 /*ARGSUSED*/ static void
 | 
					 | 
				
			||||||
ARCHIVEResolveSymbols(void *unused)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 /*ARGSUSED*/ static int
 | 
					 | 
				
			||||||
ARCHIVECheckForUnresolved(void *v)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 /*ARGSUSED*/ static char *
 | 
					 /*ARGSUSED*/ static char *
 | 
				
			||||||
ARCHIVEAddressToSection(void *modptr, unsigned long address)
 | 
					ARCHIVEAddressToSection(void *modptr, unsigned long address)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 /*ARGSUSED*/ static void
 | 
					 | 
				
			||||||
ARCHIVEUnload(void *unused2)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					@ -283,64 +267,12 @@ ARCHIVEUnload(void *unused2)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static loader_funcs funcs[] = {
 | 
					static loader_funcs funcs[] = {
 | 
				
			||||||
    /* LD_ARCHIVE */
 | 
					 | 
				
			||||||
    {ARCHIVELoadModule,
 | 
					 | 
				
			||||||
     ARCHIVEResolveSymbols,
 | 
					 | 
				
			||||||
     ARCHIVECheckForUnresolved,
 | 
					 | 
				
			||||||
     ARCHIVEAddressToSection,
 | 
					 | 
				
			||||||
     ARCHIVEUnload, {0, 0, 0, 0, 0}},
 | 
					 | 
				
			||||||
    /* LD_ELFOBJECT */
 | 
					 | 
				
			||||||
    {ELFLoadModule,
 | 
					 | 
				
			||||||
     ELFResolveSymbols,
 | 
					 | 
				
			||||||
     ELFCheckForUnresolved,
 | 
					 | 
				
			||||||
     ELFAddressToSection,
 | 
					 | 
				
			||||||
     ELFUnloadModule, {0, 0, 0, 0, 0}},
 | 
					 | 
				
			||||||
    /* LD_COFFOBJECT */
 | 
					 | 
				
			||||||
    {COFFLoadModule,
 | 
					 | 
				
			||||||
     COFFResolveSymbols,
 | 
					 | 
				
			||||||
     COFFCheckForUnresolved,
 | 
					 | 
				
			||||||
     COFFAddressToSection,
 | 
					 | 
				
			||||||
     COFFUnloadModule, {0, 0, 0, 0, 0}},
 | 
					 | 
				
			||||||
    /* LD_XCOFFOBJECT */
 | 
					 | 
				
			||||||
    {COFFLoadModule,
 | 
					 | 
				
			||||||
     COFFResolveSymbols,
 | 
					 | 
				
			||||||
     COFFCheckForUnresolved,
 | 
					 | 
				
			||||||
     COFFAddressToSection,
 | 
					 | 
				
			||||||
     COFFUnloadModule, {0, 0, 0, 0, 0}},
 | 
					 | 
				
			||||||
    /* LD_AOUTOBJECT */
 | 
					 | 
				
			||||||
    {AOUTLoadModule,
 | 
					 | 
				
			||||||
     AOUTResolveSymbols,
 | 
					 | 
				
			||||||
     AOUTCheckForUnresolved,
 | 
					 | 
				
			||||||
     AOUTAddressToSection,
 | 
					 | 
				
			||||||
     AOUTUnloadModule, {0, 0, 0, 0, 0}},
 | 
					 | 
				
			||||||
    /* LD_AOUTDLOBJECT */
 | 
					 | 
				
			||||||
#ifdef DLOPEN_SUPPORT
 | 
					 | 
				
			||||||
    {DLLoadModule,
 | 
					 | 
				
			||||||
     DLResolveSymbols,
 | 
					 | 
				
			||||||
     DLCheckForUnresolved,
 | 
					 | 
				
			||||||
     ARCHIVEAddressToSection,
 | 
					 | 
				
			||||||
     DLUnloadModule, {0, 0, 0, 0, 0}},
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    {AOUTLoadModule,
 | 
					 | 
				
			||||||
     AOUTResolveSymbols,
 | 
					 | 
				
			||||||
     AOUTCheckForUnresolved,
 | 
					 | 
				
			||||||
     AOUTAddressToSection,
 | 
					 | 
				
			||||||
     AOUTUnloadModule, {0, 0, 0, 0, 0}},
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    /* LD_ELFDLOBJECT */
 | 
					    /* LD_ELFDLOBJECT */
 | 
				
			||||||
#ifdef DLOPEN_SUPPORT
 | 
					 | 
				
			||||||
    {DLLoadModule,
 | 
					    {DLLoadModule,
 | 
				
			||||||
     DLResolveSymbols,
 | 
					     DLResolveSymbols,
 | 
				
			||||||
     DLCheckForUnresolved,
 | 
					     DLCheckForUnresolved,
 | 
				
			||||||
     ARCHIVEAddressToSection,
 | 
					     ARCHIVEAddressToSection,
 | 
				
			||||||
     DLUnloadModule, {0, 0, 0, 0, 0}},
 | 
					     DLUnloadModule, {0, 0, 0, 0, 0}},
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    {ELFLoadModule,
 | 
					 | 
				
			||||||
     ELFResolveSymbols,
 | 
					 | 
				
			||||||
     ELFCheckForUnresolved,
 | 
					 | 
				
			||||||
     ELFAddressToSection,
 | 
					 | 
				
			||||||
     ELFUnloadModule, {0, 0, 0, 0, 0}},
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int numloaders = sizeof(funcs) / sizeof(loader_funcs);
 | 
					int numloaders = sizeof(funcs) / sizeof(loader_funcs);
 | 
				
			||||||
| 
						 | 
					@ -434,69 +366,7 @@ LoaderInit(void)
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
_GetModuleType(int fd, long offset)
 | 
					_GetModuleType(int fd, long offset)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    unsigned char buf[256];	/* long enough for the largest magic type */
 | 
					    return LD_ELFDLOBJECT;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (read(fd, buf, sizeof(buf)) < 0) {
 | 
					 | 
				
			||||||
	return -1;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#ifdef DEBUG
 | 
					 | 
				
			||||||
    ErrorF("Checking module type %10s\n", buf);
 | 
					 | 
				
			||||||
    ErrorF("Checking module type %x %x %x %x\n", buf[0], buf[1], buf[2],
 | 
					 | 
				
			||||||
	   buf[3]);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    lseek(fd, offset, SEEK_SET);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (strncmp((char *)buf, ARMAG, SARMAG) == 0) {
 | 
					 | 
				
			||||||
	return LD_ARCHIVE;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#if defined(AIAMAG)
 | 
					 | 
				
			||||||
    /* LynxOS PPC style archives */
 | 
					 | 
				
			||||||
    if (strncmp((char *)buf, AIAMAG, SAIAMAG) == 0) {
 | 
					 | 
				
			||||||
	return LD_ARCHIVE;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (strncmp((char *)buf, ELFMAG, SELFMAG) == 0) {
 | 
					 | 
				
			||||||
	if (*((Elf32_Half *) (buf + ELFDLOFF)) == ELFDLMAG) {
 | 
					 | 
				
			||||||
	    return LD_ELFDLOBJECT;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
	    return LD_ELFOBJECT;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (buf[0] == 0x4c && buf[1] == 0x01) {
 | 
					 | 
				
			||||||
	/* I386MAGIC */
 | 
					 | 
				
			||||||
	return LD_COFFOBJECT;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (buf[0] == 0x01 && buf[1] == 0xdf) {
 | 
					 | 
				
			||||||
	/* XCOFFMAGIC */
 | 
					 | 
				
			||||||
	return LD_COFFOBJECT;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (buf[0] == 0x0d && buf[1] == 0x01) {
 | 
					 | 
				
			||||||
	/* ZCOFFMAGIC (LynxOS) */
 | 
					 | 
				
			||||||
	return LD_COFFOBJECT;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (buf[0] == 0x00 && buf[1] == 0x86 && buf[2] == 0x01 && buf[3] == 0x07) {
 | 
					 | 
				
			||||||
	/* AOUTMAGIC */
 | 
					 | 
				
			||||||
	return LD_AOUTOBJECT;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (buf[0] == 0x07 && buf[1] == 0x01
 | 
					 | 
				
			||||||
	&& (buf[2] == 0x64 || buf[2] == 0x86)) {
 | 
					 | 
				
			||||||
	/* AOUTMAGIC, (Linux OMAGIC, old impure format, also used by OS/2 */
 | 
					 | 
				
			||||||
	return LD_AOUTOBJECT;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (buf[0] == 0x07 && buf[1] == 0x01 && buf[2] == 0x00 && buf[3] == 0x00) {
 | 
					 | 
				
			||||||
	/* AOUTMAGIC, BSDI */
 | 
					 | 
				
			||||||
	return LD_AOUTOBJECT;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if ((buf[0] == 0xc0 && buf[1] == 0x86) ||	/* big endian form */
 | 
					 | 
				
			||||||
	(buf[3] == 0xc0 && buf[2] == 0x86)) {	/* little endian form */
 | 
					 | 
				
			||||||
	/* i386 shared object */
 | 
					 | 
				
			||||||
	return LD_AOUTDLOBJECT;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return LD_UNKNOWN;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int offsetbias = 0;	/* offset into archive */
 | 
					static int offsetbias = 0;	/* offset into archive */
 | 
				
			||||||
| 
						 | 
					@ -971,255 +841,6 @@ _LoaderHandleUnresolved(char *symbol, char *module)
 | 
				
			||||||
    return (fatalsym);
 | 
					    return (fatalsym);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * Handle an archive.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
void *
 | 
					 | 
				
			||||||
ARCHIVELoadModule(loaderPtr modrec, int arfd, LOOKUP ** ppLookup, int flags)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    loaderPtr tmp = NULL;
 | 
					 | 
				
			||||||
    void *ret = NULL;
 | 
					 | 
				
			||||||
    unsigned char magic[SARMAG];
 | 
					 | 
				
			||||||
    struct ar_hdr hdr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if defined(__powerpc__) && defined(Lynx)
 | 
					 | 
				
			||||||
    struct fl_hdr fhdr;
 | 
					 | 
				
			||||||
    char name[255];
 | 
					 | 
				
			||||||
    int namlen;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    unsigned int size;
 | 
					 | 
				
			||||||
    unsigned int offset;
 | 
					 | 
				
			||||||
    int arnamesize, modnamesize;
 | 
					 | 
				
			||||||
    char *slash, *longname;
 | 
					 | 
				
			||||||
    char *nametable = NULL;
 | 
					 | 
				
			||||||
    int nametablelen = 0;
 | 
					 | 
				
			||||||
    LOOKUP *lookup_ret, *p;
 | 
					 | 
				
			||||||
    LOOKUP *myLookup = NULL;	/* Does realloc behave if ptr == 0? */
 | 
					 | 
				
			||||||
    int modtype;
 | 
					 | 
				
			||||||
    int i;
 | 
					 | 
				
			||||||
    int numsyms = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* lookup_ret = xf86loadermalloc(sizeof (LOOKUP *)); */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    arnamesize = strlen(modrec->name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if !(defined(__powerpc__) && defined(Lynx))
 | 
					 | 
				
			||||||
    read(arfd, magic, SARMAG);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (strncmp((const char *)magic, ARMAG, SARMAG) != 0) {
 | 
					 | 
				
			||||||
	ErrorF("ARCHIVELoadModule: wrong magic!!\n");
 | 
					 | 
				
			||||||
	return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    read(arfd, &fhdr, FL_HSZ);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (strncmp(fhdr.fl_magic, AIAMAG, SAIAMAG) != 0) {
 | 
					 | 
				
			||||||
	ErrorF("ARCHIVELoadModule: wrong magic!!\n");
 | 
					 | 
				
			||||||
	return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#endif /* __powerpc__ && Lynx */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef DEBUGAR
 | 
					 | 
				
			||||||
    ErrorF("Looking for archive members starting at offset %o\n", offset);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    while (read(arfd, &hdr, sizeof(struct ar_hdr))) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	longname = NULL;
 | 
					 | 
				
			||||||
	sscanf(hdr.ar_size, "%u", &size);
 | 
					 | 
				
			||||||
#if defined(__powerpc__) && defined(Lynx)
 | 
					 | 
				
			||||||
	sscanf(hdr.ar_namlen, "%d", &namlen);
 | 
					 | 
				
			||||||
	name[0] = hdr.ar_name[0];
 | 
					 | 
				
			||||||
	name[1] = hdr.ar_name[1];
 | 
					 | 
				
			||||||
	read(arfd, &name[2], namlen);
 | 
					 | 
				
			||||||
	name[namlen] = '\0';
 | 
					 | 
				
			||||||
	offset = lseek(arfd, 0, SEEK_CUR);
 | 
					 | 
				
			||||||
	if (offset & 0x1)	/* odd value */
 | 
					 | 
				
			||||||
	    offset = lseek(arfd, 1, SEEK_CUR);	/* make it an even boundary */
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	offset = lseek(arfd, 0, SEEK_CUR);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Check for a Symbol Table */
 | 
					 | 
				
			||||||
	if ((hdr.ar_name[0] == '/' && hdr.ar_name[1] == ' ') ||
 | 
					 | 
				
			||||||
#if defined(__powerpc__) && defined(Lynx)
 | 
					 | 
				
			||||||
	    namlen == 0 ||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	    strncmp(hdr.ar_name, "__.SYMDEF", 9) == 0) {
 | 
					 | 
				
			||||||
	    /* If the file name is NULL, then it is a symbol table */
 | 
					 | 
				
			||||||
#ifdef DEBUGAR
 | 
					 | 
				
			||||||
	    ErrorF("Symbol Table Member '%16.16s', size %d, offset %d\n",
 | 
					 | 
				
			||||||
		   hdr.ar_name, size, offset);
 | 
					 | 
				
			||||||
	    ErrorF("Symbol table size %d\n", size);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	    offset = lseek(arfd, offset + size, SEEK_SET);
 | 
					 | 
				
			||||||
	    if (offset & 0x1)	/* odd value */
 | 
					 | 
				
			||||||
		offset = lseek(arfd, 1, SEEK_CUR);	/* make it an even boundary */
 | 
					 | 
				
			||||||
	    continue;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Check for a String Table */
 | 
					 | 
				
			||||||
	if (hdr.ar_name[0] == '/' && hdr.ar_name[1] == '/') {
 | 
					 | 
				
			||||||
	    /* If the file name is '/', then it is a string table */
 | 
					 | 
				
			||||||
#ifdef DEBUGAR
 | 
					 | 
				
			||||||
	    ErrorF("String Table Member '%16.16s', size %d, offset %d\n",
 | 
					 | 
				
			||||||
		   hdr.ar_name, size, offset);
 | 
					 | 
				
			||||||
	    ErrorF("String table size %d\n", size);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	    nametablelen = size;
 | 
					 | 
				
			||||||
	    nametable = (char *)xf86loadermalloc(nametablelen);
 | 
					 | 
				
			||||||
	    read(arfd, nametable, size);
 | 
					 | 
				
			||||||
	    offset = lseek(arfd, 0, SEEK_CUR);
 | 
					 | 
				
			||||||
	    /* offset=lseek(arfd,offset+size,SEEK_SET); */
 | 
					 | 
				
			||||||
	    if (offset & 0x1)	/* odd value */
 | 
					 | 
				
			||||||
		offset = lseek(arfd, 1, SEEK_CUR);	/* make it an even boundary */
 | 
					 | 
				
			||||||
	    continue;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (hdr.ar_name[0] == '/') {
 | 
					 | 
				
			||||||
	    /*  SYS V r4 style long member name */
 | 
					 | 
				
			||||||
	    int nameoffset = atol(&hdr.ar_name[1]);
 | 
					 | 
				
			||||||
	    char *membername;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    if (!nametable) {
 | 
					 | 
				
			||||||
		ErrorF("Missing string table whilst processing %s\n",
 | 
					 | 
				
			||||||
		       modrec->name);
 | 
					 | 
				
			||||||
		offsetbias = 0;
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    if (nameoffset > nametablelen) {
 | 
					 | 
				
			||||||
		ErrorF("Invalid string table offset (%s) whilst processing %s\n", hdr.ar_name, modrec->name);
 | 
					 | 
				
			||||||
		offsetbias = 0;
 | 
					 | 
				
			||||||
		xf86loaderfree(nametable);
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    membername = nametable + nameoffset;
 | 
					 | 
				
			||||||
	    slash = strchr(membername, '/');
 | 
					 | 
				
			||||||
	    if (slash)
 | 
					 | 
				
			||||||
		*slash = '\0';
 | 
					 | 
				
			||||||
	    longname = xf86loadermalloc(arnamesize + strlen(membername) + 2);
 | 
					 | 
				
			||||||
	    strcpy(longname, modrec->name);
 | 
					 | 
				
			||||||
	    strcat(longname, ":");
 | 
					 | 
				
			||||||
	    strcat(longname, membername);
 | 
					 | 
				
			||||||
	} else if (hdr.ar_name[0] == '#' && hdr.ar_name[1] == '1' &&
 | 
					 | 
				
			||||||
		   hdr.ar_name[2] == '/') {
 | 
					 | 
				
			||||||
	    /* BSD 4.4 style long member name */
 | 
					 | 
				
			||||||
	    if (sscanf(hdr.ar_name + 3, "%d", &modnamesize) != 1) {
 | 
					 | 
				
			||||||
		ErrorF("Bad archive member %s\n", hdr.ar_name);
 | 
					 | 
				
			||||||
		offsetbias = 0;
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    /* allocate space for fully qualified name */
 | 
					 | 
				
			||||||
	    longname = xf86loadermalloc(arnamesize + modnamesize + 2);
 | 
					 | 
				
			||||||
	    strcpy(longname, modrec->name);
 | 
					 | 
				
			||||||
	    strcat(longname, ":");
 | 
					 | 
				
			||||||
	    i = read(arfd, longname + modnamesize + 1, modnamesize);
 | 
					 | 
				
			||||||
	    if (i != modnamesize) {
 | 
					 | 
				
			||||||
		ErrorF("Bad archive member %s\n", hdr.ar_name);
 | 
					 | 
				
			||||||
		xf86loaderfree(longname);
 | 
					 | 
				
			||||||
		offsetbias = 0;
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    longname[i] = '\0';
 | 
					 | 
				
			||||||
	    offset += i;
 | 
					 | 
				
			||||||
	    size -= i;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
	    /* Regular archive member */
 | 
					 | 
				
			||||||
#ifdef DEBUGAR
 | 
					 | 
				
			||||||
	    ErrorF("Member '%16.16s', size %d, offset %x\n",
 | 
					 | 
				
			||||||
#if !(defined(__powerpc__) && defined(Lynx))
 | 
					 | 
				
			||||||
		   hdr.ar_name,
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
		   name,
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		   size, offset);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    slash = strchr(hdr.ar_name, '/');
 | 
					 | 
				
			||||||
	    if (slash == NULL) {
 | 
					 | 
				
			||||||
		/* BSD format without trailing slash */
 | 
					 | 
				
			||||||
		slash = strchr(hdr.ar_name, ' ');
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    /* SM: Make sure we do not overwrite other parts of struct */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    if ((slash - hdr.ar_name) > sizeof(hdr.ar_name))
 | 
					 | 
				
			||||||
		slash = hdr.ar_name + sizeof(hdr.ar_name) - 1;
 | 
					 | 
				
			||||||
	    *slash = '\000';
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if ((modtype = _GetModuleType(arfd, offset)) < 0) {
 | 
					 | 
				
			||||||
	    ErrorF("%s is an unrecognized module type\n", hdr.ar_name);
 | 
					 | 
				
			||||||
	    offsetbias = 0;
 | 
					 | 
				
			||||||
	    if (nametable)
 | 
					 | 
				
			||||||
		xf86loaderfree(nametable);
 | 
					 | 
				
			||||||
	    return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	tmp = _LoaderListPush();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	tmp->handle = modrec->handle;
 | 
					 | 
				
			||||||
	tmp->module = moduleseq++;
 | 
					 | 
				
			||||||
	tmp->cname = xf86loadermalloc(strlen(modrec->cname) + 1);
 | 
					 | 
				
			||||||
	strcpy(tmp->cname, modrec->cname);
 | 
					 | 
				
			||||||
	tmp->funcs = &funcs[modtype];
 | 
					 | 
				
			||||||
	if (longname == NULL) {
 | 
					 | 
				
			||||||
	    modnamesize = strlen(hdr.ar_name);
 | 
					 | 
				
			||||||
	    tmp->name =
 | 
					 | 
				
			||||||
		    (char *)xf86loadermalloc(arnamesize + modnamesize + 2);
 | 
					 | 
				
			||||||
	    strcpy(tmp->name, modrec->name);
 | 
					 | 
				
			||||||
	    strcat(tmp->name, ":");
 | 
					 | 
				
			||||||
	    strcat(tmp->name, hdr.ar_name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
	    tmp->name = longname;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	offsetbias = offset;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if ((tmp->private = funcs[modtype].LoadModule(tmp, arfd, &lookup_ret, LD_FLAG_GLOBAL))
 | 
					 | 
				
			||||||
	    == NULL) {
 | 
					 | 
				
			||||||
	    ErrorF("Failed to load %s\n", hdr.ar_name);
 | 
					 | 
				
			||||||
	    offsetbias = 0;
 | 
					 | 
				
			||||||
	    if (nametable)
 | 
					 | 
				
			||||||
		xf86loaderfree(nametable);
 | 
					 | 
				
			||||||
	    return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	offset = lseek(arfd, offset + size, SEEK_SET);
 | 
					 | 
				
			||||||
	if (offset & 0x1)	/* odd value */
 | 
					 | 
				
			||||||
	    lseek(arfd, 1, SEEK_CUR);	/* make it an even boundary */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (tmp->private == (void *)-1L) {
 | 
					 | 
				
			||||||
	    xf86Msg(X_INFO, "Skipping \"%s\":  "
 | 
					 | 
				
			||||||
		    "object file contains no symbols\n",
 | 
					 | 
				
			||||||
		    tmp->name);
 | 
					 | 
				
			||||||
	    continue;
 | 
					 | 
				
			||||||
	} else
 | 
					 | 
				
			||||||
	    ret = tmp->private;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* Add the lookup table returned from funcs.LoadModule to the
 | 
					 | 
				
			||||||
	 * one we're going to return.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	for (i = 0, p = lookup_ret; p && p->symName; i++, p++) ;
 | 
					 | 
				
			||||||
	if (i) {
 | 
					 | 
				
			||||||
	    myLookup = xf86loaderrealloc(myLookup, (numsyms + i + 1)
 | 
					 | 
				
			||||||
					 * sizeof(LOOKUP));
 | 
					 | 
				
			||||||
	    if (!myLookup)
 | 
					 | 
				
			||||||
		continue;	/* Oh well! */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	    memcpy(&(myLookup[numsyms]), lookup_ret, i * sizeof(LOOKUP));
 | 
					 | 
				
			||||||
	    numsyms += i;
 | 
					 | 
				
			||||||
	    myLookup[numsyms].symName = 0;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	xf86loaderfree(lookup_ret);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    /* xf86loaderfree(lookup_ret); */
 | 
					 | 
				
			||||||
    offsetbias = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    *ppLookup = myLookup;
 | 
					 | 
				
			||||||
    if (nametable)
 | 
					 | 
				
			||||||
	xf86loaderfree(nametable);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return ret;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Relocation list manipulation routines
 | 
					 * Relocation list manipulation routines
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,13 +70,7 @@
 | 
				
			||||||
/* For LOOKUP definition */
 | 
					/* For LOOKUP definition */
 | 
				
			||||||
#include "sym.h"
 | 
					#include "sym.h"
 | 
				
			||||||
#define LD_UNKNOWN	-1
 | 
					#define LD_UNKNOWN	-1
 | 
				
			||||||
#define LD_ARCHIVE	0
 | 
					#define LD_ELFDLOBJECT	0
 | 
				
			||||||
#define LD_ELFOBJECT	1
 | 
					 | 
				
			||||||
#define LD_COFFOBJECT	2
 | 
					 | 
				
			||||||
#define LD_XCOFFOBJECT	3
 | 
					 | 
				
			||||||
#define LD_AOUTOBJECT   4
 | 
					 | 
				
			||||||
#define LD_AOUTDLOBJECT	5
 | 
					 | 
				
			||||||
#define LD_ELFDLOBJECT	6
 | 
					 | 
				
			||||||
#define LD_PROCESSED_ARCHIVE -1
 | 
					#define LD_PROCESSED_ARCHIVE -1
 | 
				
			||||||
/* #define UNINIT_SECTION */
 | 
					/* #define UNINIT_SECTION */
 | 
				
			||||||
#define HANDLE_IN_HASH_ENTRY
 | 
					#define HANDLE_IN_HASH_ENTRY
 | 
				
			||||||
| 
						 | 
					@ -85,29 +79,13 @@
 | 
				
			||||||
 * namespace, default is to keep symbols local to module. */
 | 
					 * namespace, default is to keep symbols local to module. */
 | 
				
			||||||
#define LD_FLAG_GLOBAL 1
 | 
					#define LD_FLAG_GLOBAL 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * COFF Section nmumbers
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define N_TEXT       1
 | 
					 | 
				
			||||||
#define N_DATA       2
 | 
					 | 
				
			||||||
#define N_BSS        3
 | 
					 | 
				
			||||||
#define N_COMMENT    4
 | 
					 | 
				
			||||||
#define TestFree(a) if (a) { xfree (a); a = NULL; }
 | 
					#define TestFree(a) if (a) { xfree (a); a = NULL; }
 | 
				
			||||||
#define HASHDIV 10
 | 
					#define HASHDIV 10
 | 
				
			||||||
#define HASHSIZE (1<<HASHDIV)
 | 
					#define HASHSIZE (1<<HASHDIV)
 | 
				
			||||||
typedef struct _elf_reloc *ELFRelocPtr;
 | 
					 | 
				
			||||||
typedef struct _elf_COMMON *ELFCommonPtr;
 | 
					 | 
				
			||||||
typedef struct _coff_reloc *COFFRelocPtr;
 | 
					 | 
				
			||||||
typedef struct _coff_COMMON *COFFCommonPtr;
 | 
					 | 
				
			||||||
typedef struct AOUT_RELOC *AOUTRelocPtr;
 | 
					 | 
				
			||||||
typedef struct AOUT_COMMON *AOUTCommonPtr;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct _LoaderReloc {
 | 
					typedef struct _LoaderReloc {
 | 
				
			||||||
    int modtype;
 | 
					    int modtype;
 | 
				
			||||||
    struct _LoaderReloc *next;
 | 
					    struct _LoaderReloc *next;
 | 
				
			||||||
    COFFRelocPtr coff_reloc;
 | 
					 | 
				
			||||||
    ELFRelocPtr elf_reloc;
 | 
					 | 
				
			||||||
    AOUTRelocPtr aout_reloc;
 | 
					 | 
				
			||||||
} LoaderRelocRec, *LoaderRelocPtr;
 | 
					} LoaderRelocRec, *LoaderRelocPtr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct _loader_item *itemPtr;
 | 
					typedef struct _loader_item *itemPtr;
 | 
				
			||||||
| 
						 | 
					@ -126,7 +104,6 @@ typedef struct _loader_item {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    union {
 | 
					    union {
 | 
				
			||||||
	unsigned short plt[8];	/* ELF */
 | 
						unsigned short plt[8];	/* ELF */
 | 
				
			||||||
	unsigned short glink[14];	/* XCOFF */
 | 
					 | 
				
			||||||
    } code;
 | 
					    } code;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
} itemRec;
 | 
					} itemRec;
 | 
				
			||||||
| 
						 | 
					@ -285,12 +262,7 @@ char *_LoaderHandleToCanonicalName(int handle);
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Entry points for the different loader types
 | 
					 * Entry points for the different loader types
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#include "aoutloader.h"
 | 
					 | 
				
			||||||
#include "coffloader.h"
 | 
					 | 
				
			||||||
#include "elfloader.h"
 | 
					 | 
				
			||||||
#include "dlloader.h"
 | 
					#include "dlloader.h"
 | 
				
			||||||
/* LD_ARCHIVE */
 | 
					 | 
				
			||||||
void *ARCHIVELoadModule(loaderPtr, int, LOOKUP **, int flags);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern void _loader_debug_state(void);
 | 
					extern void _loader_debug_state(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue