1998-03-07 19:24:35 +00:00
|
|
|
/*-
|
|
|
|
* Copyright 1996-1998 John D. Polstra.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 00:22:10 +00:00
|
|
|
* $FreeBSD$
|
1998-03-07 19:24:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RTLD_H /* { */
|
|
|
|
#define RTLD_H 1
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1999-08-30 01:48:19 +00:00
|
|
|
#include <sys/queue.h>
|
1998-03-07 19:24:35 +00:00
|
|
|
|
1998-04-30 07:48:02 +00:00
|
|
|
#include <link.h>
|
1998-03-07 19:24:35 +00:00
|
|
|
#include <elf.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
1999-04-09 00:28:43 +00:00
|
|
|
#include "rtld_machdep.h"
|
|
|
|
|
1998-03-07 19:24:35 +00:00
|
|
|
#ifndef STANDARD_LIBRARY_PATH
|
|
|
|
#define STANDARD_LIBRARY_PATH "/usr/lib/elf:/usr/lib"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NEW(type) ((type *) xmalloc(sizeof(type)))
|
|
|
|
#define CNEW(type) ((type *) xcalloc(sizeof(type)))
|
|
|
|
|
|
|
|
/* We might as well do booleans like C++. */
|
|
|
|
typedef unsigned char bool;
|
|
|
|
#define false 0
|
|
|
|
#define true 1
|
|
|
|
|
1999-08-30 01:50:41 +00:00
|
|
|
struct stat;
|
1998-03-07 19:24:35 +00:00
|
|
|
struct Struct_Obj_Entry;
|
|
|
|
|
1999-08-30 01:48:19 +00:00
|
|
|
typedef struct Struct_Objlist_Entry {
|
|
|
|
STAILQ_ENTRY(Struct_Objlist_Entry) link;
|
|
|
|
struct Struct_Obj_Entry *obj;
|
|
|
|
} Objlist_Entry;
|
|
|
|
|
|
|
|
typedef STAILQ_HEAD(Struct_Objlist, Struct_Objlist_Entry) Objlist;
|
|
|
|
|
1998-03-07 19:24:35 +00:00
|
|
|
typedef struct Struct_Needed_Entry {
|
|
|
|
struct Struct_Needed_Entry *next;
|
|
|
|
struct Struct_Obj_Entry *obj;
|
|
|
|
unsigned long name; /* Offset of name in string table */
|
|
|
|
} Needed_Entry;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shared object descriptor.
|
|
|
|
*
|
|
|
|
* Items marked with "(%)" are dynamically allocated, and must be freed
|
|
|
|
* when the structure is destroyed.
|
1999-09-05 21:12:53 +00:00
|
|
|
*
|
|
|
|
* CAUTION: It appears that the JDK port peeks into these structures.
|
|
|
|
* It looks at "next" and "mapbase" at least. Don't add new members
|
|
|
|
* near the front, until this can be straightened out.
|
1998-03-07 19:24:35 +00:00
|
|
|
*/
|
|
|
|
typedef struct Struct_Obj_Entry {
|
|
|
|
/*
|
|
|
|
* These two items have to be set right for compatibility with the
|
|
|
|
* original ElfKit crt1.o.
|
|
|
|
*/
|
1998-08-21 03:29:40 +00:00
|
|
|
Elf_Word magic; /* Magic number (sanity check) */
|
|
|
|
Elf_Word version; /* Version number of struct format */
|
1998-03-07 19:24:35 +00:00
|
|
|
|
|
|
|
struct Struct_Obj_Entry *next;
|
|
|
|
char *path; /* Pathname of underlying file (%) */
|
|
|
|
int refcount;
|
|
|
|
int dl_refcount; /* Number of times loaded by dlopen */
|
|
|
|
|
|
|
|
/* These items are computed by map_object() or by digest_phdr(). */
|
|
|
|
caddr_t mapbase; /* Base address of mapped region */
|
|
|
|
size_t mapsize; /* Size of mapped region in bytes */
|
|
|
|
size_t textsize; /* Size of text segment in bytes */
|
1998-08-21 03:29:40 +00:00
|
|
|
Elf_Addr vaddrbase; /* Base address in shared object file */
|
1998-03-07 19:24:35 +00:00
|
|
|
caddr_t relocbase; /* Relocation constant = mapbase - vaddrbase */
|
1998-08-21 03:29:40 +00:00
|
|
|
const Elf_Dyn *dynamic; /* Dynamic section */
|
1998-03-07 19:24:35 +00:00
|
|
|
caddr_t entry; /* Entry point */
|
1998-08-21 03:29:40 +00:00
|
|
|
const Elf_Phdr *phdr; /* Program header if it is mapped, else NULL */
|
1998-03-07 19:24:35 +00:00
|
|
|
size_t phsize; /* Size of program header in bytes */
|
1999-08-30 01:54:13 +00:00
|
|
|
const char *interp; /* Pathname of the interpreter, if any */
|
1998-03-07 19:24:35 +00:00
|
|
|
|
|
|
|
/* Items from the dynamic section. */
|
1999-04-09 00:28:43 +00:00
|
|
|
Elf_Addr *pltgot; /* PLT or GOT, depending on architecture */
|
1998-08-21 03:29:40 +00:00
|
|
|
const Elf_Rel *rel; /* Relocation entries */
|
1998-03-07 19:24:35 +00:00
|
|
|
unsigned long relsize; /* Size in bytes of relocation info */
|
1998-09-04 19:03:57 +00:00
|
|
|
const Elf_Rela *rela; /* Relocation entries with addend */
|
|
|
|
unsigned long relasize; /* Size in bytes of addend relocation info */
|
1998-08-21 03:29:40 +00:00
|
|
|
const Elf_Rel *pltrel; /* PLT relocation entries */
|
1998-03-07 19:24:35 +00:00
|
|
|
unsigned long pltrelsize; /* Size in bytes of PLT relocation info */
|
1998-09-04 19:03:57 +00:00
|
|
|
const Elf_Rela *pltrela; /* PLT relocation entries with addend */
|
|
|
|
unsigned long pltrelasize; /* Size in bytes of PLT addend reloc info */
|
1998-08-21 03:29:40 +00:00
|
|
|
const Elf_Sym *symtab; /* Symbol table */
|
1998-03-07 19:24:35 +00:00
|
|
|
const char *strtab; /* String table */
|
|
|
|
unsigned long strsize; /* Size in bytes of string table */
|
|
|
|
|
1998-09-04 19:03:57 +00:00
|
|
|
const Elf_Addr *buckets; /* Hash table buckets array */
|
1998-03-07 19:24:35 +00:00
|
|
|
unsigned long nbuckets; /* Number of buckets */
|
1998-09-04 19:03:57 +00:00
|
|
|
const Elf_Addr *chains; /* Hash table chain array */
|
1998-03-07 19:24:35 +00:00
|
|
|
unsigned long nchains; /* Number of chains */
|
|
|
|
|
|
|
|
const char *rpath; /* Search path specified in object */
|
|
|
|
Needed_Entry *needed; /* Shared objects needed by this one (%) */
|
|
|
|
|
|
|
|
void (*init)(void); /* Initialization function to call */
|
|
|
|
void (*fini)(void); /* Termination function to call */
|
|
|
|
|
|
|
|
bool mainprog; /* True if this is the main program */
|
|
|
|
bool rtld; /* True if this is the dynamic linker */
|
|
|
|
bool textrel; /* True if there are relocations to text seg */
|
|
|
|
bool symbolic; /* True if generated with "-Bsymbolic" */
|
1998-09-02 02:51:12 +00:00
|
|
|
bool traced; /* Already printed in ldd trace output */
|
1998-04-30 07:48:02 +00:00
|
|
|
|
|
|
|
struct link_map linkmap; /* for GDB */
|
1999-09-05 21:12:53 +00:00
|
|
|
Objlist dldags; /* Object belongs to these dlopened DAGs (%) */
|
|
|
|
Objlist dagmembers; /* DAG has these members (%) */
|
|
|
|
dev_t dev; /* Object's filesystem's device */
|
|
|
|
ino_t ino; /* Object's inode number */
|
|
|
|
unsigned long mark; /* Set to "curmark" to avoid repeat visits */
|
1998-03-07 19:24:35 +00:00
|
|
|
} Obj_Entry;
|
|
|
|
|
|
|
|
#define RTLD_MAGIC 0xd550b87a
|
|
|
|
#define RTLD_VERSION 1
|
|
|
|
|
1999-07-18 00:02:19 +00:00
|
|
|
extern void _rtld_error(const char *, ...) __printflike(1, 2);
|
1999-08-30 01:50:41 +00:00
|
|
|
extern Obj_Entry *map_object(int, const char *, const struct stat *);
|
1998-03-07 19:24:35 +00:00
|
|
|
extern void *xcalloc(size_t);
|
|
|
|
extern void *xmalloc(size_t);
|
|
|
|
extern char *xstrdup(const char *);
|
1998-09-04 19:03:57 +00:00
|
|
|
extern Elf_Addr _GLOBAL_OFFSET_TABLE_[];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function declarations.
|
|
|
|
*/
|
|
|
|
int do_copy_relocations(Obj_Entry *);
|
|
|
|
unsigned long elf_hash(const char *);
|
1999-08-30 01:48:19 +00:00
|
|
|
const Elf_Sym *find_symdef(unsigned long, Obj_Entry *, const Obj_Entry **,
|
|
|
|
bool);
|
1999-04-09 00:28:43 +00:00
|
|
|
void init_pltgot(Obj_Entry *);
|
1999-12-27 04:44:04 +00:00
|
|
|
void lockdflt_acquire(void *);
|
|
|
|
void *lockdflt_create(void *);
|
|
|
|
void lockdflt_destroy(void *);
|
|
|
|
void lockdflt_release(void *);
|
1999-08-30 01:48:19 +00:00
|
|
|
void obj_free(Obj_Entry *);
|
|
|
|
Obj_Entry *obj_new(void);
|
1999-04-09 00:28:43 +00:00
|
|
|
int reloc_non_plt(Obj_Entry *, Obj_Entry *);
|
|
|
|
int reloc_plt(Obj_Entry *, bool);
|
|
|
|
void _rtld_bind_start(void);
|
1998-09-04 19:03:57 +00:00
|
|
|
const Elf_Sym *symlook_obj(const char *, unsigned long,
|
|
|
|
const Obj_Entry *, bool);
|
1998-03-07 19:24:35 +00:00
|
|
|
|
|
|
|
#endif /* } */
|