resolve.h revision 1.19
1/*	$OpenBSD: resolve.h,v 1.19 2002/12/18 19:20:01 drahn Exp $ */
2
3/*
4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed under OpenBSD by
17 *	Per Fogelstrom, Opsycon AB, Sweden.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 */
34
35#ifndef _RESOLVE_H_
36#define _RESOLVE_H_
37
38#include <link.h>
39
40struct load_list {
41	struct load_list *next;
42	char	*start;
43	size_t	size;
44	int	prot;
45};
46
47/*
48 *  Structure describing a loaded object.
49 *  The head of this struct must be compatible
50 *  with struct link_map in sys/link.h
51 */
52typedef struct elf_object {
53	Elf_Addr load_addr;		/* Real load address */
54	char	*load_name;		/* Pointer to object name */
55	Elf_Dyn *load_dyn;		/* Pointer to object dynamic data */
56	struct elf_object *next;
57	struct elf_object *prev;
58/* End struct link_map compatible */
59	Elf_Addr load_offs;		/* Load offset from link address */
60
61	struct load_list *load_list;
62
63	u_int32_t  load_size;
64	Elf_Addr	got_addr;
65	size_t		got_size;
66	Elf_Addr	plt_addr;
67	size_t		plt_size;
68
69	union {
70		u_long		info[DT_NUM + DT_PROCNUM];
71		struct {
72			Elf_Addr	null;		/* Not used */
73			Elf_Addr	needed;		/* Not used */
74			Elf_Addr	pltrelsz;
75			Elf_Addr	*pltgot;
76			Elf_Addr	*hash;
77			const char	*strtab;
78			const Elf_Sym	*symtab;
79			Elf_RelA	*rela;
80			Elf_Addr	relasz;
81			Elf_Addr	relaent;
82			Elf_Addr	strsz;
83			Elf_Addr	syment;
84			void		(*init)(void);
85			void		(*fini)(void);
86			const char	*soname;
87			const char	*rpath;
88			Elf_Addr	symbolic;
89			Elf_Rel	*rel;
90			Elf_Addr	relsz;
91			Elf_Addr	relent;
92			Elf_Addr	pltrel;
93			Elf_Addr	debug;
94			Elf_Addr	textrel;
95			Elf_Addr	jmprel;
96			Elf_Addr	bind_now;
97		} u;
98	} Dyn;
99#define dyn Dyn.u
100
101	struct elf_object *dep_next;	/* Shadow objects for resolve search */
102
103	int		status;
104#define	STAT_RELOC_DONE	1
105#define	STAT_GOT_DONE	2
106#define	STAT_INIT_DONE	4
107
108	Elf_Phdr	*phdrp;
109	int		phdrc;
110
111	int		refcount;
112	int		obj_type;
113#define	OBJTYPE_LDR	1
114#define	OBJTYPE_EXE	2
115#define	OBJTYPE_LIB	3
116#define	OBJTYPE_DLO	4
117
118	Elf_Word	*buckets;
119	u_int32_t	nbuckets;
120	Elf_Word	*chains;
121	u_int32_t	nchains;
122	Elf_Dyn	*dynamic;
123
124} elf_object_t;
125
126extern void _dl_rt_resolve(void);
127
128extern elf_object_t *_dl_add_object(const char *objname, Elf_Dyn *dynp,
129	    const u_long *, const int objtype,
130	    const long laddr, const long loff);
131extern void	_dl_remove_object(elf_object_t *object);
132
133extern elf_object_t *_dl_lookup_object(const char *objname);
134extern elf_object_t *_dl_load_shlib(const char *, elf_object_t *, int);
135extern void	_dl_unload_shlib(elf_object_t *object);
136
137extern int  _dl_md_reloc(elf_object_t *object, int rel, int relsz);
138extern void _dl_md_reloc_got(elf_object_t *object, int lazy);
139
140Elf_Addr _dl_find_symbol(const char *name, elf_object_t *startlook,
141    const Elf_Sym **ref, int flags, int sym_size, const char *module_name);
142/*
143 * defines for _dl_find_symbol() flag field, three bits of meaning
144 * myself 	- clear: search all objects,	set: search only this object
145 * warnnotfound - clear: no warning, 		set: warn if not found
146 * inplt	- clear: possible plt ref	set: real matching function.
147 *
148 * inplt - due to how ELF handles function addresses in shared libraries
149 * &func may actually refer to the plt entry in the main program
150 * rather than the actual function address in the .so file.
151 * This rather bizarre behavior is documented in the SVR4 ABI.
152 * when getting the function address to relocate a PLT entry
153 * the 'real' function address is necessary, not the possible PLT address.
154 */
155/* myself */
156#define SYM_SEARCH_ALL		0
157#define SYM_SEARCH_SELF		1
158/* warnnotfound */
159#define SYM_NOWARNNOTFOUND	0
160#define SYM_WARNNOTFOUND	2
161/* inplt */
162#define SYM_NOTPLT		0
163#define SYM_PLT			4
164
165void _dl_rtld(elf_object_t *object);
166void _dl_call_init(elf_object_t *object);
167
168extern elf_object_t *_dl_objects;
169extern elf_object_t *_dl_last_object;
170
171extern const char *_dl_progname;
172extern struct r_debug *_dl_debug_map;
173
174extern int  _dl_pagesz;
175extern int  _dl_errno;
176
177extern char *_dl_libpath;
178extern char *_dl_preload;
179extern char *_dl_bindnow;
180extern char *_dl_traceld;
181extern char *_dl_debug;
182
183#define DL_DEB(P) do { if (_dl_debug) _dl_printf P ; } while (0)
184
185#define	DL_NOT_FOUND		1
186#define	DL_CANT_OPEN		2
187#define	DL_NOT_ELF		3
188#define	DL_CANT_OPEN_REF	4
189#define	DL_CANT_MMAP		5
190#define	DL_NO_SYMBOL		6
191#define	DL_INVALID_HANDLE	7
192#define	DL_INVALID_CTL		8
193
194#endif /* _RESOLVE_H_ */
195