xref: /titanic_51/usr/src/cmd/sgs/libld/common/_libld.h (revision 43a291055ab3951f6372241323fd4e2486098fff)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  *
27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 /*
32  * Local include file for ld library.
33  */
34 
35 #ifndef	_LIBLD_DOT_H
36 #define	_LIBLD_DOT_H
37 
38 #pragma ident	"%Z%%M%	%I%	%E% SMI"
39 
40 #include <libld.h>
41 #include <conv.h>
42 #include <msg.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 /*
49  * Types of segment index.
50  */
51 typedef enum {
52 	LD_PHDR,	LD_INTERP,	LD_SUNWCAP,	LD_TEXT,
53 	LD_DATA,	LD_BSS,		LD_DYN,		LD_DTRACE,
54 	LD_NOTE,	LD_SUNWBSS,	LD_TLS,
55 #if defined(__x86) && defined(_ELF64)
56 	LD_UNWIND,
57 #endif
58 	LD_EXTRA,
59 	LD_NUM
60 } Segment_ndx;
61 
62 /*
63  * Structure to manage the update of weak symbols from their associated alias.
64  */
65 typedef	struct wk_desc {
66 	Sym		*wk_symtab;	/* the .symtab entry */
67 	Sym		*wk_dynsym;	/* the .dynsym entry */
68 	Sym_desc	*wk_weak;	/* the original weak symbol */
69 	Sym_desc	*wk_alias;	/* the real symbol */
70 } Wk_desc;
71 
72 /*
73  * Structure to manage the support library interfaces.
74  */
75 typedef struct func_list {
76 	const char	*fl_obj;	/* name of support object */
77 					/*	function is from */
78 	void		(*fl_fptr)();	/* function pointer */
79 	uint_t		fl_version;	/* ld_version() level */
80 } Func_list;
81 
82 typedef	struct support_list {
83 	const char	*sup_name;	/* ld_support function name */
84 	List		sup_funcs;	/* list of support functions */
85 } Support_list;
86 
87 /*
88  * Structure to manage a sorted output relocation list.
89  *
90  *	rl_key1		->	pointer to needed ndx
91  *	rl_key2		->	pointer to symbol relocation is against
92  *	rl_key3		->	virtual offset of relocation
93  */
94 typedef struct reloc_list {
95 	Sym_desc	*rl_key2;
96 	Xword		rl_key3;
97 	Rel_desc	*rl_rsp;
98 	Half		rl_key1;
99 } Reloc_list;
100 
101 
102 typedef struct sym_s_list {
103 	Word		sl_hval;
104 	Sym_desc *	sl_sdp;
105 } Sym_s_list;
106 
107 /*
108  * ld heap management structure
109  */
110 typedef struct _ld_heap Ld_heap;
111 struct _ld_heap {
112 	Ld_heap		*lh_next;
113 	void		*lh_free;
114 	void		*lh_end;
115 };
116 
117 #define	HEAPBLOCK	0x68000		/* default allocation block size */
118 #define	HEAPALIGN	0x8		/* heap blocks alignment requirement */
119 
120 /*
121  * Dynamic per-symbol filtee string table descriptor.  This associates filtee
122  * strings that will be created in the .dynstr, with .dynamic entries.
123  */
124 typedef struct {
125 	char		*dft_str;	/* dynstr string */
126 	Word		dft_flag;	/* auxiliary/filtee type */
127 	Half		dft_ndx;	/* eventual ndx into .dynamic */
128 } Dfltr_desc;
129 
130 #define	AL_CNT_DFLTR	4
131 #define	AL_CNT_GROUP	20
132 
133 /*
134  * Per-symbol filtee descriptor.  This associates symbol definitions with
135  * their filtees.
136  */
137 typedef struct {
138 	Sym_desc	*sft_sdp;	/* symbol descriptor */
139 	Aliste		sft_off;	/* offset into dtstr descriptor */
140 } Sfltr_desc;
141 
142 #define	AL_CNT_SFLTR	20
143 
144 /*
145  * Return codes for {tls|got}_fixups() routines
146  */
147 typedef enum {
148 	FIX_ERROR,	/* fatal error - time to punt */
149 	FIX_DONE,	/* relocation done - no further processing required */
150 	FIX_RELOC	/* do_reloc() relocation processing required */
151 } Fixupret;
152 
153 #ifndef	FILENAME_MAX
154 #define	FILENAME_MAX	BUFSIZ		/* maximum length of a path name */
155 #endif
156 
157 /*
158  * Relocation buckets are sized based on the number of input relocations and
159  * the following constants.
160  */
161 #define	REL_HAIDESCNO	1000		/* high water mark active buckets */
162 #define	REL_LAIDESCNO	50		/* low water mark active buckets */
163 #define	REL_HOIDESCNO	500		/* high water mark output buckets */
164 #define	REL_LOIDESCNO	10		/* low water mark output buckets */
165 
166 extern Ofl_desc		Ofl;
167 extern char		*Plibpath;
168 extern char		*Llibdir;
169 extern char		*Ulibdir;
170 extern Ehdr		def_ehdr;
171 extern Ld_heap		*ld_heap;
172 extern List		lib_support;
173 extern const Msg	reject[];
174 extern uint_t		dbg_mask;
175 
176 extern int		Verbose;
177 
178 /*
179  * For backward compatibility provide a /dev/zero file descriptor.
180  */
181 extern int		dz_fd;
182 
183 /*
184  * Local functions.
185  */
186 extern uintptr_t	add_actrel(Word, Rel_desc *, Ofl_desc *);
187 extern uintptr_t	add_libdir(Ofl_desc *, const char *);
188 extern uintptr_t	add_outrel(Word, Rel_desc *, Ofl_desc *);
189 extern uintptr_t	add_regsym(Sym_desc *, Ofl_desc *);
190 extern void 		adj_movereloc(Ofl_desc *, Rel_desc *);
191 extern void		*alist_append(Alist **, const void *, size_t, int);
192 extern Sym_desc * 	am_I_partial(Rel_desc *, Xword);
193 extern Ar_desc *	ar_setup(const char *, Elf *, Ofl_desc *);
194 extern void		ar_member(Ar_desc *, Elf_Arsym *, Ar_aux *, Ar_mem *);
195 #if	defined(sparc)
196 extern uintptr_t	allocate_got(Ofl_desc *);
197 extern uintptr_t	assign_got(Sym_desc *);
198 #endif
199 extern uintptr_t	assign_gotndx(List *, Gotndx *, Gotref, Ofl_desc *,
200 			    Rel_desc *, Sym_desc *);
201 extern void		assign_plt_ndx(Sym_desc *, Ofl_desc *);
202 extern Xword		calc_got_offset(Rel_desc *, Ofl_desc *);
203 extern Xword		calc_plt_addr(Sym_desc *, Ofl_desc *);
204 extern int		dbg_setup(const char *);
205 extern const char	*demangle(const char *);
206 extern void		disp_errmsg(const char *, Rel_desc *, Ofl_desc *);
207 extern uintptr_t	do_activerelocs(Ofl_desc *);
208 extern void		ent_check(Ofl_desc *);
209 extern uintptr_t	fillin_gotplt1(Ofl_desc *);
210 extern Addr		fillin_gotplt2(Ofl_desc *);
211 extern Gotndx *		find_gotndx(List *, Gotref, Ofl_desc *, Rel_desc *);
212 extern uintptr_t	find_library(const char *, Ofl_desc *);
213 extern Group_desc *	get_group(Ofl_desc *, Is_desc *);
214 extern Word		hashbkts(Word);
215 extern Xword		lcm(Xword, Xword);
216 extern int		ldexit(void);
217 extern void		ldmap_out(Ofl_desc *);
218 extern uintptr_t	lib_setup(Ofl_desc *);
219 extern Listnode *	list_where(List *, Word);
220 extern void		init();
221 extern Word		init_rel(Rel_desc *, void *);
222 extern const char	*is_regsym(Ifl_desc *, Sym *, const char *, int, Word,
223 			    const char *, Word *);
224 extern void		mach_eflags(Ehdr *, Ofl_desc *);
225 extern void		mach_make_dynamic(Ofl_desc *, size_t *);
226 extern void		mach_update_odynamic(Ofl_desc *, Dyn **);
227 extern int		mach_sym_typecheck(Sym_desc *, Sym *, Ifl_desc *,
228 			    Ofl_desc *);
229 extern uintptr_t	make_bss(Ofl_desc *, Xword, Xword, uint_t);
230 extern uintptr_t	make_got(Ofl_desc *);
231 extern uintptr_t	make_reloc(Ofl_desc *, Os_desc *);
232 extern uintptr_t	make_sunwbss(Ofl_desc *, size_t, Xword);
233 extern uintptr_t	make_sunwdata(Ofl_desc *, size_t, Xword);
234 extern uintptr_t	make_sunwmove(Ofl_desc *, int);
235 extern uintptr_t	map_parse(const char *, Ofl_desc *);
236 extern uintptr_t	perform_outreloc(Rel_desc *, Ofl_desc *);
237 extern Os_desc *	place_section(Ofl_desc *, Is_desc *, int, Word);
238 extern uintptr_t	process_archive(const char *, int, Ar_desc *,
239 			    Ofl_desc *);
240 extern uintptr_t	process_flags(Ofl_desc *, int, char **);
241 extern uintptr_t	process_files(Ofl_desc *, int, char **);
242 extern Ifl_desc *	process_ifl(const char *, const char *, int, Elf *,
243 			    Half, Ofl_desc *, Rej_desc *);
244 extern uintptr_t	process_ordered(Ifl_desc *, Ofl_desc *, Word, Word);
245 extern uintptr_t	process_section(const char *, Ifl_desc *, Shdr *,
246 			    Elf_Scn *, Word, int, Ofl_desc *);
247 extern uintptr_t	process_sym_reloc(Ofl_desc *, Rel_desc *, Rel *,
248 			    Is_desc *, const char *);
249 extern int		reg_check(Sym_desc *, Sym *, const char *, Ifl_desc *,
250 			    Ofl_desc *);
251 extern int		reg_enter(Sym_desc *, Ofl_desc *);
252 extern Sym_desc *	reg_find(Sym *, Ofl_desc *);
253 extern uintptr_t	reloc_local(Rel_desc *, Ofl_desc *);
254 extern uintptr_t	reloc_plt(Rel_desc *, Ofl_desc *);
255 extern uintptr_t	reloc_register(Rel_desc *, Is_desc *, Ofl_desc *);
256 extern uintptr_t	reloc_relobj(Boolean, Rel_desc *, Ofl_desc *);
257 extern void		reloc_remain_entry(Rel_desc *, Os_desc *, Ofl_desc *);
258 extern uintptr_t	reloc_GOT_relative(Boolean, Rel_desc *, Ofl_desc *);
259 extern uintptr_t	reloc_GOTOP(Boolean, Rel_desc *, Ofl_desc *);
260 extern uintptr_t	reloc_TLS(Boolean, Rel_desc *, Ofl_desc *);
261 extern uintptr_t	sort_ordered(Ofl_desc *);
262 extern uintptr_t	sort_seg_list(Ofl_desc *);
263 extern void		sym_adjust_vis(Sym_desc *, Ofl_desc *);
264 extern int		sym_avl_comp(const void *, const void *);
265 extern uintptr_t	sym_copy(Sym_desc *);
266 extern uintptr_t	sym_nodirect(Is_desc *, Ifl_desc *, Ofl_desc *);
267 extern uintptr_t	sym_process(Is_desc *, Ifl_desc *, Ofl_desc *);
268 extern uintptr_t	sym_resolve(Sym_desc *, Sym *, Ifl_desc *, Ofl_desc *,
269 				int, Word, Word);
270 extern uintptr_t	sym_spec(Ofl_desc *);
271 extern uintptr_t	vers_def_process(Is_desc *, Ifl_desc *, Ofl_desc *);
272 extern uintptr_t	vers_need_process(Is_desc *, Ifl_desc *, Ofl_desc *);
273 extern int		vers_sym_process(Is_desc *, Ifl_desc *);
274 extern uintptr_t	vers_check_need(Ofl_desc *);
275 extern void		vers_promote(Sym_desc *, Word, Ifl_desc *, Ofl_desc *);
276 extern int		vers_verify(Ofl_desc *);
277 
278 /*
279  * AMD64 - 64-bit specific functions
280  */
281 #if defined(__x86) && defined(_ELF64)
282 extern uintptr_t	make_amd64_unwindhdr(Ofl_desc *);
283 extern uintptr_t	process_amd64_unwind(const char *, Ifl_desc *, Shdr *,
284 			    Elf_Scn *, Word, int, Ofl_desc *);
285 extern uintptr_t	populate_amd64_unwindhdr(Ofl_desc *);
286 extern uintptr_t	append_amd64_unwind(Os_desc *, Ofl_desc *);
287 #endif
288 
289 #ifdef	__cplusplus
290 }
291 #endif
292 
293 #endif /* _LIBLD_DOT_H */
294