2000-07-26 06:07:34 +04:00
|
|
|
/* $NetBSD: rtld.h,v 1.27 2000/07/26 02:07:35 mycroft Exp $ */
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1996 John D. Polstra.
|
|
|
|
* Copyright 1996 Matt Thomas <matt@3am-software.com>
|
|
|
|
* 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 John Polstra.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1999-03-01 19:40:07 +03:00
|
|
|
#ifndef RTLD_H
|
|
|
|
#define RTLD_H
|
1996-12-16 23:37:55 +03:00
|
|
|
|
1999-11-07 03:21:12 +03:00
|
|
|
#include <dlfcn.h>
|
1996-12-16 23:37:55 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
1999-11-07 03:21:12 +03:00
|
|
|
#include <sys/queue.h>
|
1996-12-16 23:37:55 +03:00
|
|
|
#include <sys/exec_elf.h>
|
|
|
|
#include "rtldenv.h"
|
|
|
|
#include "link.h"
|
|
|
|
|
1999-07-05 21:55:34 +04:00
|
|
|
#if defined(_RTLD_SOURCE)
|
|
|
|
|
1999-03-19 21:25:57 +03:00
|
|
|
#define RTLD_DEFAULT_LIBRARY_PATH "/usr/lib"
|
1999-08-20 03:42:15 +04:00
|
|
|
#define _PATH_LD_HINTS "/etc/ld.so.conf"
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define SVR4_LIBDIR "/usr/lib"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LIBDIRLEN (sizeof LIBDIR - 1)
|
|
|
|
#define SVR4_LIBDIRLEN (sizeof SVR4_LIBDIR - 1)
|
|
|
|
|
1998-07-02 00:42:47 +04:00
|
|
|
#ifndef PAGESIZE
|
1999-04-18 23:40:06 +04:00
|
|
|
# ifdef VARPSZ
|
|
|
|
extern int _rtld_pagesz;
|
|
|
|
# ifdef RTLD_DEBUG
|
|
|
|
# define PAGESIZE (assert(_rtld_pagesz), _rtld_pagesz)
|
|
|
|
# else
|
|
|
|
# define PAGESIZE _rtld_pagesz
|
|
|
|
# endif
|
1999-02-24 21:31:00 +03:00
|
|
|
# else
|
1999-04-18 23:40:06 +04:00
|
|
|
# ifndef __sparc__
|
1999-12-05 21:36:25 +03:00
|
|
|
# define PAGESIZE NBPG
|
1999-04-18 23:40:06 +04:00
|
|
|
# else
|
1999-06-22 20:28:22 +04:00
|
|
|
#error "Sparc has a variable page size"
|
1999-04-18 23:40:06 +04:00
|
|
|
# endif
|
1999-02-24 21:31:00 +03:00
|
|
|
# endif
|
1998-07-02 00:42:47 +04:00
|
|
|
#endif
|
1999-03-01 19:40:07 +03:00
|
|
|
|
1996-12-16 23:37:55 +03:00
|
|
|
#define round_down(x) ((x) & ~(PAGESIZE-1))
|
|
|
|
#define round_up(x) round_down((x) + PAGESIZE - 1)
|
|
|
|
|
|
|
|
#define NEW(type) ((type *) xmalloc(sizeof(type)))
|
|
|
|
#define CNEW(type) ((type *) xcalloc(sizeof(type)))
|
|
|
|
|
1999-07-05 21:55:34 +04:00
|
|
|
#endif /* _RTLD_SOURCE */
|
|
|
|
|
1996-12-16 23:37:55 +03:00
|
|
|
/*
|
|
|
|
* C++ has mandated the use of the following keywords for its new boolean
|
|
|
|
* type. We might as well follow their lead.
|
|
|
|
*/
|
1999-06-16 19:41:24 +04:00
|
|
|
typedef enum {
|
|
|
|
false = 0,
|
|
|
|
true = 1
|
|
|
|
} bool;
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
struct Struct_Obj_Entry;
|
|
|
|
|
1999-11-07 03:21:12 +03:00
|
|
|
typedef struct Struct_Objlist_Entry {
|
|
|
|
SIMPLEQ_ENTRY(Struct_Objlist_Entry) link;
|
|
|
|
struct Struct_Obj_Entry *obj;
|
|
|
|
} Objlist_Entry;
|
|
|
|
|
|
|
|
typedef SIMPLEQ_HEAD(Struct_Objlist, Struct_Objlist_Entry) Objlist;
|
|
|
|
|
1996-12-16 23:37:55 +03:00
|
|
|
typedef struct Struct_Needed_Entry {
|
1999-03-01 19:40:07 +03:00
|
|
|
struct Struct_Needed_Entry *next;
|
|
|
|
struct Struct_Obj_Entry *obj;
|
|
|
|
unsigned long name; /* Offset of name in string table */
|
|
|
|
} Needed_Entry;
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
typedef struct _rtld_search_path_t {
|
1999-03-01 19:40:07 +03:00
|
|
|
struct _rtld_search_path_t *sp_next;
|
|
|
|
const char *sp_path;
|
|
|
|
size_t sp_pathlen;
|
|
|
|
} Search_Path;
|
1996-12-16 23:37:55 +03:00
|
|
|
|
1999-12-13 12:09:34 +03:00
|
|
|
|
|
|
|
#define RTLD_MAX_ENTRY 10
|
|
|
|
#define RTLD_MAX_LIBRARY 4
|
1999-12-15 08:22:37 +03:00
|
|
|
#define RTLD_MAX_CTL 2
|
1999-12-13 12:09:34 +03:00
|
|
|
typedef struct _rtld_library_xform_t {
|
|
|
|
struct _rtld_library_xform_t *next;
|
|
|
|
char *name;
|
1999-12-15 08:22:37 +03:00
|
|
|
int ctl[RTLD_MAX_CTL];
|
|
|
|
int ctltype[RTLD_MAX_CTL];
|
|
|
|
int ctlmax;
|
1999-12-13 12:09:34 +03:00
|
|
|
struct {
|
|
|
|
char *value;
|
|
|
|
char *library[RTLD_MAX_LIBRARY];
|
|
|
|
} entry[RTLD_MAX_ENTRY];
|
|
|
|
} Library_Xform;
|
|
|
|
|
1996-12-16 23:37:55 +03:00
|
|
|
/*
|
|
|
|
* Shared object descriptor.
|
|
|
|
*
|
|
|
|
* Items marked with "(%)" are dynamically allocated, and must be freed
|
|
|
|
* when the structure is destroyed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define RTLD_MAGIC 0xd550b87a
|
|
|
|
#define RTLD_VERSION 1
|
|
|
|
|
|
|
|
typedef struct Struct_Obj_Entry {
|
1999-03-01 19:40:07 +03:00
|
|
|
Elf32_Word magic; /* Magic number (sanity check) */
|
|
|
|
Elf32_Word version; /* Version number of struct format */
|
|
|
|
|
|
|
|
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 */
|
|
|
|
Elf_Addr vaddrbase; /* Base address in shared object file */
|
|
|
|
caddr_t relocbase; /* Reloc const = mapbase - *vaddrbase */
|
|
|
|
Elf_Dyn *dynamic; /* Dynamic section */
|
|
|
|
caddr_t entry; /* Entry point */
|
|
|
|
const Elf_Phdr *phdr; /* Program header if mapped, ow NULL */
|
|
|
|
size_t phsize; /* Size of program header in bytes */
|
|
|
|
|
|
|
|
/* Items from the dynamic section. */
|
|
|
|
Elf_Addr *pltgot; /* PLTGOT table */
|
|
|
|
const Elf_Rel *rel; /* Relocation entries */
|
|
|
|
const Elf_Rel *rellim; /* Limit of Relocation entries */
|
|
|
|
const Elf_RelA *rela; /* Relocation entries */
|
|
|
|
const Elf_RelA *relalim; /* Limit of Relocation entries */
|
|
|
|
const Elf_Rel *pltrel; /* PLT relocation entries */
|
|
|
|
const Elf_Rel *pltrellim; /* Limit of PLT relocation entries */
|
|
|
|
const Elf_RelA *pltrela; /* PLT relocation entries */
|
|
|
|
const Elf_RelA *pltrelalim; /* Limit of PLT relocation entries */
|
|
|
|
const Elf_Sym *symtab; /* Symbol table */
|
|
|
|
const char *strtab; /* String table */
|
|
|
|
unsigned long strsize; /* Size in bytes of string table */
|
1998-03-25 07:12:32 +03:00
|
|
|
#if defined(__mips__)
|
1999-03-01 19:40:07 +03:00
|
|
|
Elf_Word local_gotno; /* Number of local GOT entries */
|
|
|
|
Elf_Word symtabno; /* Number of dynamic symbols */
|
|
|
|
Elf_Word gotsym; /* First dynamic symbol in GOT */
|
1998-03-25 07:12:32 +03:00
|
|
|
#endif
|
1996-12-16 23:37:55 +03:00
|
|
|
|
1999-03-01 19:40:07 +03:00
|
|
|
const Elf_Word *buckets; /* Hash table buckets array */
|
|
|
|
unsigned long nbuckets; /* Number of buckets */
|
|
|
|
const Elf_Word *chains; /* Hash table chain array */
|
|
|
|
unsigned long nchains; /* Number of chains */
|
|
|
|
|
|
|
|
Search_Path *rpaths; /* Search path specified in object */
|
|
|
|
Needed_Entry *needed; /* Shared objects needed by this (%) */
|
|
|
|
|
|
|
|
void (*init) /* Initialization function to call */
|
|
|
|
__P((void));
|
|
|
|
void (*fini) /* Termination function to call */
|
|
|
|
__P((void));
|
|
|
|
|
|
|
|
/* Entry points for dlopen() and friends. */
|
|
|
|
void *(*dlopen) __P((const char *, int));
|
|
|
|
void *(*dlsym) __P((void *, const char *));
|
|
|
|
char *(*dlerror) __P((void));
|
|
|
|
int (*dlclose) __P((void *));
|
2000-02-08 19:22:59 +03:00
|
|
|
int (*dladdr) __P((const void *, Dl_info *));
|
1999-03-01 19:40:07 +03:00
|
|
|
|
2000-07-06 07:16:51 +04:00
|
|
|
u_int32_t mainprog:1, /* True if this is the main program */
|
|
|
|
rtld:1, /* True if this is the dynamic linker */
|
|
|
|
textrel:1, /* True if there are relocations to
|
1999-03-01 19:40:07 +03:00
|
|
|
* text seg */
|
2000-07-06 07:16:51 +04:00
|
|
|
symbolic:1, /* True if generated with
|
1999-03-01 19:40:07 +03:00
|
|
|
* "-Bsymbolic" */
|
2000-07-06 07:16:51 +04:00
|
|
|
printed:1; /* True if ldd has printed it */
|
1999-03-01 19:40:07 +03:00
|
|
|
|
|
|
|
struct link_map linkmap; /* for GDB */
|
1999-11-07 03:21:12 +03:00
|
|
|
|
|
|
|
/* These items are computed by map_object() or by digest_phdr(). */
|
|
|
|
const char *interp; /* Pathname of the interpreter, if any */
|
|
|
|
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 */
|
1999-11-10 21:48:19 +03:00
|
|
|
unsigned long mark; /* Set to "_rtld_curmark" to avoid
|
|
|
|
repeat visits */
|
1996-12-16 23:37:55 +03:00
|
|
|
} Obj_Entry;
|
|
|
|
|
1999-07-05 21:55:34 +04:00
|
|
|
#if defined(_RTLD_SOURCE)
|
|
|
|
|
1996-12-16 23:37:55 +03:00
|
|
|
extern struct r_debug _rtld_debug;
|
1999-08-01 23:47:07 +04:00
|
|
|
extern Search_Path *_rtld_default_paths;
|
1996-12-16 23:37:55 +03:00
|
|
|
extern Obj_Entry *_rtld_objlist;
|
|
|
|
extern Obj_Entry **_rtld_objtail;
|
1999-11-07 03:21:12 +03:00
|
|
|
extern Obj_Entry *_rtld_objmain;
|
1996-12-16 23:37:55 +03:00
|
|
|
extern Obj_Entry _rtld_objself;
|
|
|
|
extern Search_Path *_rtld_paths;
|
1999-12-13 12:09:34 +03:00
|
|
|
extern Library_Xform *_rtld_xforms;
|
1996-12-16 23:37:55 +03:00
|
|
|
extern bool _rtld_trust;
|
|
|
|
extern const char *_rtld_error_message;
|
1999-11-10 21:48:19 +03:00
|
|
|
extern unsigned long _rtld_curmark;
|
1999-11-07 03:21:12 +03:00
|
|
|
extern Objlist _rtld_list_global;
|
|
|
|
extern Objlist _rtld_list_main;
|
|
|
|
extern Elf_Sym _rtld_sym_zero;
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* rtld_start.S */
|
1999-03-01 19:40:07 +03:00
|
|
|
void _rtld_bind_start __P((void));
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* rtld.c */
|
1999-03-01 19:40:07 +03:00
|
|
|
void _rtld_error __P((const char *, ...));
|
|
|
|
void _rtld_die __P((void));
|
|
|
|
char *_rtld_dlerror __P((void));
|
|
|
|
void *_rtld_dlopen __P((const char *, int));
|
2000-04-15 09:41:46 +04:00
|
|
|
void *_rtld_objmain_sym __P((const char *));
|
1999-03-01 19:40:07 +03:00
|
|
|
void *_rtld_dlsym __P((void *, const char *));
|
|
|
|
int _rtld_dlclose __P((void *));
|
1999-11-07 03:21:12 +03:00
|
|
|
int _rtld_dladdr __P((const void *, Dl_info *));
|
1999-03-01 19:40:07 +03:00
|
|
|
void _rtld_debug_state __P((void));
|
|
|
|
void _rtld_linkmap_add __P((Obj_Entry *));
|
|
|
|
void _rtld_linkmap_delete __P((Obj_Entry *));
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* headers.c */
|
1999-03-01 19:40:07 +03:00
|
|
|
void _rtld_digest_dynamic __P((Obj_Entry *));
|
|
|
|
Obj_Entry *_rtld_digest_phdr __P((const Elf_Phdr *, int, caddr_t));
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* load.c */
|
1999-03-01 19:40:07 +03:00
|
|
|
Obj_Entry *_rtld_load_object __P((char *, bool));
|
1999-12-13 12:09:34 +03:00
|
|
|
int _rtld_load_needed_objects __P((Obj_Entry *, bool));
|
1999-05-31 18:48:16 +04:00
|
|
|
int _rtld_preload __P((const char *, bool));
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* path.c */
|
1999-03-01 19:40:07 +03:00
|
|
|
void _rtld_add_paths __P((Search_Path **, const char *, bool));
|
1999-12-13 12:09:34 +03:00
|
|
|
void _rtld_process_hints __P((Search_Path **, Library_Xform **, const char *,
|
|
|
|
bool));
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* reloc.c */
|
1999-03-01 19:40:07 +03:00
|
|
|
int _rtld_do_copy_relocations __P((const Obj_Entry *, bool));
|
1999-11-07 03:21:12 +03:00
|
|
|
caddr_t _rtld_bind __P((Obj_Entry *, Elf_Word));
|
1999-03-01 19:40:07 +03:00
|
|
|
int _rtld_relocate_objects __P((Obj_Entry *, bool, bool));
|
1999-11-07 03:21:12 +03:00
|
|
|
int _rtld_relocate_nonplt_object __P((Obj_Entry *,
|
1999-03-01 19:40:07 +03:00
|
|
|
const Elf_RelA *, bool));
|
1999-11-07 03:21:12 +03:00
|
|
|
int _rtld_relocate_plt_object __P((Obj_Entry *, const Elf_RelA *,
|
1999-03-01 19:40:07 +03:00
|
|
|
caddr_t *, bool, bool));
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* search.c */
|
1999-03-01 19:40:07 +03:00
|
|
|
char *_rtld_find_library __P((const char *, const Obj_Entry *));
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* symbol.c */
|
1999-03-01 19:40:07 +03:00
|
|
|
unsigned long _rtld_elf_hash __P((const char *));
|
|
|
|
const Elf_Sym *_rtld_symlook_obj __P((const char *, unsigned long,
|
|
|
|
const Obj_Entry *, bool));
|
2000-07-26 06:07:34 +04:00
|
|
|
const Elf_Sym *_rtld_find_symdef __P((const Obj_Entry *, Elf_Addr,
|
1999-11-07 03:21:12 +03:00
|
|
|
const char *, Obj_Entry *, const Obj_Entry **, bool));
|
|
|
|
const Elf_Sym *_rtld_symlook_list(const char *, unsigned long,
|
|
|
|
Objlist *, const Obj_Entry **, bool in_plt);
|
1996-12-16 23:37:55 +03:00
|
|
|
|
|
|
|
/* map_object.c */
|
1999-11-07 03:21:12 +03:00
|
|
|
Obj_Entry *_rtld_map_object __P((const char *, int, const struct stat *));
|
|
|
|
void _rtld_obj_free(Obj_Entry *);
|
|
|
|
Obj_Entry *_rtld_obj_new(void);
|
1996-12-16 23:37:55 +03:00
|
|
|
|
1998-03-25 07:12:32 +03:00
|
|
|
#if defined(__mips__)
|
|
|
|
/* mips_reloc.c */
|
1999-03-01 19:40:07 +03:00
|
|
|
void _rtld_relocate_mips_got __P((Obj_Entry *));
|
|
|
|
caddr_t _rtld_bind_mips __P((Elf_Word, Elf_Addr, Elf_Addr, Elf_Addr));
|
1998-03-25 07:12:32 +03:00
|
|
|
#endif
|
|
|
|
|
1998-11-24 14:34:30 +03:00
|
|
|
#if defined(__powerpc__)
|
|
|
|
/* ppc_reloc.c */
|
1999-11-07 09:48:21 +03:00
|
|
|
caddr_t _rtld_bind_powerpc __P((Obj_Entry *, Elf_Word));
|
|
|
|
int _rtld_reloc_powerpc_plt __P((Obj_Entry *, const Elf_RelA *, bool));
|
1999-03-01 19:40:07 +03:00
|
|
|
void _rtld_setup_powerpc_plt __P((const Obj_Entry *));
|
1998-11-24 14:34:30 +03:00
|
|
|
#endif
|
|
|
|
|
1999-07-05 21:55:34 +04:00
|
|
|
#endif /* _RTLD_SOURCE */
|
|
|
|
|
|
|
|
#endif /* RTLD_H */
|