rtld.h revision 38816
1163953Srrs/*- 2169382Srrs * Copyright 1996-1998 John D. Polstra. 3163953Srrs * All rights reserved. 4163953Srrs * 5163953Srrs * Redistribution and use in source and binary forms, with or without 6163953Srrs * modification, are permitted provided that the following conditions 7163953Srrs * are met: 8163953Srrs * 1. Redistributions of source code must retain the above copyright 9163953Srrs * notice, this list of conditions and the following disclaimer. 10163953Srrs * 2. Redistributions in binary form must reproduce the above copyright 11163953Srrs * notice, this list of conditions and the following disclaimer in the 12163953Srrs * documentation and/or other materials provided with the distribution. 13163953Srrs * 14163953Srrs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15163953Srrs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16163953Srrs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17163953Srrs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18163953Srrs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19163953Srrs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20163953Srrs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21163953Srrs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22163953Srrs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23163953Srrs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24163953Srrs * 25163953Srrs * $Id: rtld.h,v 1.4 1998/09/02 02:51:12 jdp Exp $ 26163953Srrs */ 27163953Srrs 28163953Srrs#ifndef RTLD_H /* { */ 29163953Srrs#define RTLD_H 1 30163953Srrs 31163953Srrs#include <sys/types.h> 32163953Srrs 33163953Srrs#include <link.h> 34163953Srrs#include <elf.h> 35163953Srrs#include <stddef.h> 36163953Srrs 37163953Srrs#ifndef STANDARD_LIBRARY_PATH 38167598Srrs#define STANDARD_LIBRARY_PATH "/usr/lib/elf:/usr/lib" 39163953Srrs#endif 40163953Srrs 41163953Srrs#define NEW(type) ((type *) xmalloc(sizeof(type))) 42163953Srrs#define CNEW(type) ((type *) xcalloc(sizeof(type))) 43163953Srrs 44163953Srrs/* We might as well do booleans like C++. */ 45163953Srrstypedef unsigned char bool; 46163953Srrs#define false 0 47170091Srrs#define true 1 48163953Srrs 49163953Srrsstruct Struct_Obj_Entry; 50163953Srrs 51163953Srrstypedef struct Struct_Needed_Entry { 52163953Srrs struct Struct_Needed_Entry *next; 53163953Srrs struct Struct_Obj_Entry *obj; 54163953Srrs unsigned long name; /* Offset of name in string table */ 55163953Srrs} Needed_Entry; 56165220Srrs 57165220Srrs/* 58165220Srrs * Shared object descriptor. 59165220Srrs * 60165220Srrs * Items marked with "(%)" are dynamically allocated, and must be freed 61163953Srrs * when the structure is destroyed. 62163953Srrs */ 63165220Srrstypedef struct Struct_Obj_Entry { 64163953Srrs /* 65163953Srrs * These two items have to be set right for compatibility with the 66163953Srrs * original ElfKit crt1.o. 67165220Srrs */ 68165220Srrs Elf_Word magic; /* Magic number (sanity check) */ 69165220Srrs Elf_Word version; /* Version number of struct format */ 70165220Srrs 71165220Srrs struct Struct_Obj_Entry *next; 72165220Srrs char *path; /* Pathname of underlying file (%) */ 73163953Srrs int refcount; 74163953Srrs int dl_refcount; /* Number of times loaded by dlopen */ 75163953Srrs 76163953Srrs /* These items are computed by map_object() or by digest_phdr(). */ 77163953Srrs caddr_t mapbase; /* Base address of mapped region */ 78163953Srrs size_t mapsize; /* Size of mapped region in bytes */ 79163953Srrs size_t textsize; /* Size of text segment in bytes */ 80163953Srrs Elf_Addr vaddrbase; /* Base address in shared object file */ 81170181Srrs caddr_t relocbase; /* Relocation constant = mapbase - vaddrbase */ 82163953Srrs const Elf_Dyn *dynamic; /* Dynamic section */ 83163953Srrs caddr_t entry; /* Entry point */ 84163953Srrs const Elf_Phdr *phdr; /* Program header if it is mapped, else NULL */ 85163953Srrs size_t phsize; /* Size of program header in bytes */ 86163953Srrs 87169420Srrs /* Items from the dynamic section. */ 88169420Srrs Elf_Addr *got; /* GOT table */ 89163953Srrs const Elf_Rel *rel; /* Relocation entries */ 90163953Srrs unsigned long relsize; /* Size in bytes of relocation info */ 91163953Srrs const Elf_Rela *rela; /* Relocation entries with addend */ 92163953Srrs unsigned long relasize; /* Size in bytes of addend relocation info */ 93169420Srrs const Elf_Rel *pltrel; /* PLT relocation entries */ 94169420Srrs unsigned long pltrelsize; /* Size in bytes of PLT relocation info */ 95169420Srrs const Elf_Rela *pltrela; /* PLT relocation entries with addend */ 96163953Srrs unsigned long pltrelasize; /* Size in bytes of PLT addend reloc info */ 97163953Srrs const Elf_Sym *symtab; /* Symbol table */ 98163953Srrs const char *strtab; /* String table */ 99163953Srrs unsigned long strsize; /* Size in bytes of string table */ 100169352Srrs 101170181Srrs const Elf_Addr *buckets; /* Hash table buckets array */ 102168299Srrs unsigned long nbuckets; /* Number of buckets */ 103168299Srrs const Elf_Addr *chains; /* Hash table chain array */ 104163953Srrs unsigned long nchains; /* Number of chains */ 105163953Srrs 106163953Srrs const char *rpath; /* Search path specified in object */ 107163953Srrs Needed_Entry *needed; /* Shared objects needed by this one (%) */ 108163953Srrs 109169352Srrs void (*init)(void); /* Initialization function to call */ 110170181Srrs void (*fini)(void); /* Termination function to call */ 111168299Srrs 112168299Srrs bool mainprog; /* True if this is the main program */ 113163953Srrs bool rtld; /* True if this is the dynamic linker */ 114163953Srrs bool textrel; /* True if there are relocations to text seg */ 115163953Srrs bool symbolic; /* True if generated with "-Bsymbolic" */ 116163953Srrs bool traced; /* Already printed in ldd trace output */ 117163953Srrs 118163953Srrs struct link_map linkmap; /* for GDB */ 119169352Srrs} Obj_Entry; 120170181Srrs 121168299Srrs#define RTLD_MAGIC 0xd550b87a 122168299Srrs#define RTLD_VERSION 1 123163953Srrs 124163953Srrsextern void _rtld_error(const char *, ...); 125163953Srrsextern Obj_Entry *map_object(int); 126163953Srrsextern void *xcalloc(size_t); 127163953Srrsextern void *xmalloc(size_t); 128169352Srrsextern char *xstrdup(const char *); 129170181Srrsextern Elf_Addr _GLOBAL_OFFSET_TABLE_[]; 130163953Srrs 131163953Srrs/* 132163953Srrs * Function declarations. 133163953Srrs */ 134163953Srrsint do_copy_relocations(Obj_Entry *); 135169352Srrsint reloc_non_plt(Obj_Entry *, Obj_Entry *); 136170181Srrsint reloc_plt(Obj_Entry *, bool); 137168299Srrsunsigned long elf_hash(const char *); 138168299Srrsconst Elf_Sym *find_symdef(unsigned long, const Obj_Entry *, 139163953Srrs const Obj_Entry **, bool); 140163953Srrsconst Elf_Sym *symlook_obj(const char *, unsigned long, 141163953Srrs const Obj_Entry *, bool); 142163953Srrs 143163953Srrs#endif /* } */ 144169352Srrs