resolve.h revision 1.22
1/*	$OpenBSD: resolve.h,v 1.22 2003/02/15 22:39:13 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	Elf_Addr	got_start;
66	size_t		got_size;
67	Elf_Addr	plt_start;
68	size_t		plt_size;
69
70	union {
71		u_long		info[DT_NUM + DT_PROCNUM];
72		struct {
73			Elf_Addr	null;		/* Not used */
74			Elf_Addr	needed;		/* Not used */
75			Elf_Addr	pltrelsz;
76			Elf_Addr	*pltgot;
77			Elf_Addr	*hash;
78			const char	*strtab;
79			const Elf_Sym	*symtab;
80			Elf_RelA	*rela;
81			Elf_Addr	relasz;
82			Elf_Addr	relaent;
83			Elf_Addr	strsz;
84			Elf_Addr	syment;
85			void		(*init)(void);
86			void		(*fini)(void);
87			const char	*soname;
88			const char	*rpath;
89			Elf_Addr	symbolic;
90			Elf_Rel	*rel;
91			Elf_Addr	relsz;
92			Elf_Addr	relent;
93			Elf_Addr	pltrel;
94			Elf_Addr	debug;
95			Elf_Addr	textrel;
96			Elf_Addr	jmprel;
97			Elf_Addr	bind_now;
98		} u;
99	} Dyn;
100#define dyn Dyn.u
101
102	struct elf_object *dep_next;	/* Shadow objects for resolve search */
103
104	int		status;
105#define	STAT_RELOC_DONE	1
106#define	STAT_GOT_DONE	2
107#define	STAT_INIT_DONE	4
108
109	Elf_Phdr	*phdrp;
110	int		phdrc;
111
112	int		refcount;
113	int		obj_type;
114#define	OBJTYPE_LDR	1
115#define	OBJTYPE_EXE	2
116#define	OBJTYPE_LIB	3
117#define	OBJTYPE_DLO	4
118
119	Elf_Word	*buckets;
120	u_int32_t	nbuckets;
121	Elf_Word	*chains;
122	u_int32_t	nchains;
123	Elf_Dyn	*dynamic;
124
125	struct dep_node *first_child;
126	struct dep_node *last_child;
127} elf_object_t;
128
129struct dep_node {
130	struct dep_node *next_sibling;
131	elf_object_t *data;
132};
133
134extern void _dl_rt_resolve(void);
135
136extern elf_object_t *_dl_add_object(const char *objname, Elf_Dyn *dynp,
137	    const u_long *, const int objtype,
138	    const long laddr, const long loff);
139extern void	_dl_remove_object(elf_object_t *object);
140
141extern elf_object_t *_dl_lookup_object(const char *objname);
142extern elf_object_t *_dl_load_shlib(const char *, elf_object_t *, int);
143extern void	_dl_unload_shlib(elf_object_t *object);
144
145extern int  _dl_md_reloc(elf_object_t *object, int rel, int relsz);
146extern void _dl_md_reloc_got(elf_object_t *object, int lazy);
147
148Elf_Addr _dl_find_symbol(const char *name, elf_object_t *startlook,
149    const Elf_Sym **ref, int flags, int sym_size, const char *module_name);
150/*
151 * defines for _dl_find_symbol() flag field, three bits of meaning
152 * myself	- clear: search all objects,	set: search only this object
153 * warnnotfound - clear: no warning,		set: warn if not found
154 * inplt	- clear: possible plt ref	set: real matching function.
155 *
156 * inplt - due to how ELF handles function addresses in shared libraries
157 * &func may actually refer to the plt entry in the main program
158 * rather than the actual function address in the .so file.
159 * This rather bizarre behavior is documented in the SVR4 ABI.
160 * when getting the function address to relocate a PLT entry
161 * the 'real' function address is necessary, not the possible PLT address.
162 */
163/* myself */
164#define SYM_SEARCH_ALL		0
165#define SYM_SEARCH_SELF		1
166/* warnnotfound */
167#define SYM_NOWARNNOTFOUND	0
168#define SYM_WARNNOTFOUND	2
169/* inplt */
170#define SYM_NOTPLT		0
171#define SYM_PLT			4
172
173void _dl_rtld(elf_object_t *object);
174void _dl_call_init(elf_object_t *object);
175
176extern elf_object_t *_dl_objects;
177extern elf_object_t *_dl_last_object;
178
179extern const char *_dl_progname;
180extern struct r_debug *_dl_debug_map;
181
182extern int  _dl_pagesz;
183extern int  _dl_errno;
184
185extern char *_dl_libpath;
186extern char *_dl_preload;
187extern char *_dl_bindnow;
188extern char *_dl_traceld;
189extern char *_dl_debug;
190
191#define DL_DEB(P) do { if (_dl_debug) _dl_printf P ; } while (0)
192
193#define	DL_NOT_FOUND		1
194#define	DL_CANT_OPEN		2
195#define	DL_NOT_ELF		3
196#define	DL_CANT_OPEN_REF	4
197#define	DL_CANT_MMAP		5
198#define	DL_NO_SYMBOL		6
199#define	DL_INVALID_HANDLE	7
200#define	DL_INVALID_CTL		8
201
202#define ELF_ROUND(x,malign) (((x) + (malign)-1) & ~((malign)-1))
203#define ELF_TRUNC(x,malign) ((x) & ~((malign)-1))
204
205#endif /* _RESOLVE_H_ */
206