xref: /titanic_50/usr/src/cmd/sgs/libld/common/_libld.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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 
132 /*
133  * Per-symbol filtee descriptor.  This associates symbol definitions with
134  * their filtees.
135  */
136 typedef struct {
137 	Sym_desc	*sft_sdp;	/* symbol descriptor */
138 	Aliste		sft_off;	/* offset into dtstr descriptor */
139 } Sfltr_desc;
140 
141 #define	AL_CNT_SFLTR	20
142 
143 /*
144  * Return codes for {tls|got}_fixups() routines
145  */
146 typedef enum {
147 	FIX_ERROR,	/* fatal error - time to punt */
148 	FIX_DONE,	/* relocation done - no further processing required */
149 	FIX_RELOC	/* do_reloc() relocation processing required */
150 } Fixupret;
151 
152 #ifndef	FILENAME_MAX
153 #define	FILENAME_MAX	BUFSIZ		/* maximum length of a path name */
154 #endif
155 
156 /*
157  * Relocation buckets are sized based on the number of input relocations and
158  * the following constants.
159  */
160 #define	REL_HAIDESCNO	1000		/* high water mark active buckets */
161 #define	REL_LAIDESCNO	50		/* low water mark active buckets */
162 #define	REL_HOIDESCNO	500		/* high water mark output buckets */
163 #define	REL_LOIDESCNO	10		/* low water mark output buckets */
164 
165 extern Ofl_desc		Ofl;
166 extern char		*Plibpath;
167 extern char		*Llibdir;
168 extern char		*Ulibdir;
169 extern Ehdr		def_ehdr;
170 extern Ld_heap		*ld_heap;
171 extern List		lib_support;
172 extern const Msg	reject[];
173 extern uint_t		dbg_mask;
174 
175 extern int		Verbose;
176 
177 /*
178  * For backward compatibility provide a /dev/zero file descriptor.
179  */
180 extern int		dz_fd;
181 
182 /*
183  * Local functions.
184  */
185 extern uintptr_t	add_actrel(Word, Rel_desc *, Ofl_desc *);
186 extern uintptr_t	add_libdir(Ofl_desc *, const char *);
187 extern uintptr_t	add_outrel(Word, Rel_desc *, Ofl_desc *);
188 extern uintptr_t	add_regsym(Sym_desc *, Ofl_desc *);
189 extern void 		adj_movereloc(Ofl_desc *, Rel_desc *);
190 extern void		*alist_append(Alist **, const void *, size_t, int);
191 extern Sym_desc * 	am_I_partial(Rel_desc *, Xword);
192 extern Ar_desc *	ar_setup(const char *, Elf *, Ofl_desc *);
193 extern void		ar_member(Ar_desc *, Elf_Arsym *, Ar_aux *, Ar_mem *);
194 #if	defined(sparc)
195 extern uintptr_t	allocate_got(Ofl_desc *);
196 extern uintptr_t	assign_got(Sym_desc *);
197 #endif
198 extern uintptr_t	assign_gotndx(List *, Gotndx *, Gotref, Ofl_desc *,
199 			    Rel_desc *, Sym_desc *);
200 extern void		assign_plt_ndx(Sym_desc *, Ofl_desc *);
201 extern Xword		calc_got_offset(Rel_desc *, Ofl_desc *);
202 extern Xword		calc_plt_addr(Sym_desc *, Ofl_desc *);
203 extern int		dbg_setup(const char *);
204 extern const char	*demangle(const char *);
205 extern void		disp_errmsg(const char *, Rel_desc *, Ofl_desc *);
206 extern uintptr_t	do_activerelocs(Ofl_desc *);
207 extern void		ent_check(Ofl_desc *);
208 extern uintptr_t	fillin_gotplt1(Ofl_desc *);
209 extern Addr		fillin_gotplt2(Ofl_desc *);
210 extern Gotndx *		find_gotndx(List *, Gotref, Ofl_desc *, Rel_desc *);
211 extern uintptr_t	find_library(const char *, Ofl_desc *);
212 extern Group_desc *	get_group_desc(Ofl_desc *, Is_desc *);
213 extern Word		hashbkts(Word);
214 extern Xword		lcm(Xword, Xword);
215 extern int		ldexit(void);
216 extern void		ldmap_out(Ofl_desc *);
217 extern uintptr_t	lib_setup(Ofl_desc *);
218 extern Listnode *	list_where(List *, Word);
219 extern void		init();
220 extern Word		init_rel(Rel_desc *, void *);
221 extern const char	*is_regsym(Ifl_desc *, Sym *, const char *, int, Word,
222 			    const char *, Word *);
223 extern void		mach_eflags(Ehdr *, Ofl_desc *);
224 extern void		mach_make_dynamic(Ofl_desc *, size_t *);
225 extern void		mach_update_odynamic(Ofl_desc *, Dyn **);
226 extern int		mach_sym_typecheck(Sym_desc *, Sym *, Ifl_desc *,
227 			    Ofl_desc *);
228 extern uintptr_t	make_bss(Ofl_desc *, Xword, Xword, uint_t);
229 extern uintptr_t	make_got(Ofl_desc *);
230 extern uintptr_t	make_reloc(Ofl_desc *, Os_desc *);
231 extern uintptr_t	make_sunwbss(Ofl_desc *, size_t, Xword);
232 extern uintptr_t	make_sunwdata(Ofl_desc *, size_t, Xword);
233 extern uintptr_t	make_sunwmove(Ofl_desc *, int);
234 extern uintptr_t	map_parse(const char *, Ofl_desc *);
235 extern uintptr_t	perform_outreloc(Rel_desc *, Ofl_desc *);
236 extern Os_desc *	place_section(Ofl_desc *, Is_desc *, int, Word);
237 extern uintptr_t	process_archive(const char *, int, Ar_desc *,
238 			    Ofl_desc *);
239 extern uintptr_t	process_flags(Ofl_desc *, int, char **);
240 extern uintptr_t	process_files(Ofl_desc *, int, char **);
241 extern Ifl_desc *	process_ifl(const char *, const char *, int, Elf *,
242 			    Half, Ofl_desc *, Rej_desc *);
243 extern uintptr_t	process_ordered(Ifl_desc *, Ofl_desc *, Word, Word);
244 extern uintptr_t	process_section(const char *, Ifl_desc *, Shdr *,
245 			    Elf_Scn *, Word, int, Ofl_desc *);
246 extern uintptr_t	process_sym_reloc(Ofl_desc *, Rel_desc *, Rel *,
247 			    Is_desc *, const char *);
248 extern int		reg_check(Sym_desc *, Sym *, const char *, Ifl_desc *,
249 			    Ofl_desc *);
250 extern int		reg_enter(Sym_desc *, Ofl_desc *);
251 extern Sym_desc *	reg_find(Sym *, Ofl_desc *);
252 extern uintptr_t	reloc_local(Rel_desc *, Ofl_desc *);
253 extern uintptr_t	reloc_plt(Rel_desc *, Ofl_desc *);
254 extern uintptr_t	reloc_register(Rel_desc *, Is_desc *, Ofl_desc *);
255 extern uintptr_t	reloc_relobj(Boolean, Rel_desc *, Ofl_desc *);
256 extern void		reloc_remain_entry(Rel_desc *, Os_desc *, Ofl_desc *);
257 extern uintptr_t	reloc_GOT_relative(Boolean, Rel_desc *, Ofl_desc *);
258 extern uintptr_t	reloc_GOTOP(Boolean, Rel_desc *, Ofl_desc *);
259 extern uintptr_t	reloc_TLS(Boolean, Rel_desc *, Ofl_desc *);
260 extern uintptr_t	sort_ordered(Ofl_desc *);
261 extern uintptr_t	sort_seg_list(Ofl_desc *);
262 extern void		sym_adjust_vis(Sym_desc *, Ofl_desc *);
263 extern int		sym_avl_comp(const void *, const void *);
264 extern uintptr_t	sym_copy(Sym_desc *);
265 extern uintptr_t	sym_nodirect(Is_desc *, Ifl_desc *, Ofl_desc *);
266 extern uintptr_t	sym_process(Is_desc *, Ifl_desc *, Ofl_desc *);
267 extern uintptr_t	sym_resolve(Sym_desc *, Sym *, Ifl_desc *, Ofl_desc *,
268 				int, Word, Word);
269 extern uintptr_t	sym_spec(Ofl_desc *);
270 extern uintptr_t	vers_def_process(Is_desc *, Ifl_desc *, Ofl_desc *);
271 extern uintptr_t	vers_need_process(Is_desc *, Ifl_desc *, Ofl_desc *);
272 extern int		vers_sym_process(Is_desc *, Ifl_desc *);
273 extern uintptr_t	vers_check_need(Ofl_desc *);
274 extern void		vers_promote(Sym_desc *, Word, Ifl_desc *, Ofl_desc *);
275 extern int		vers_verify(Ofl_desc *);
276 
277 /*
278  * AMD64 - 64-bit specific functions
279  */
280 #if defined(__x86) && defined(_ELF64)
281 extern uintptr_t	make_amd64_unwindhdr(Ofl_desc *);
282 extern uintptr_t	process_amd64_unwind(const char *, Ifl_desc *, Shdr *,
283 			    Elf_Scn *, Word, int, Ofl_desc *);
284 extern uintptr_t	populate_amd64_unwindhdr(Ofl_desc *);
285 extern uintptr_t	append_amd64_unwind(Os_desc *, Ofl_desc *);
286 #endif
287 
288 #ifdef	__cplusplus
289 }
290 #endif
291 
292 #endif /* _LIBLD_DOT_H */
293