xref: /illumos-gate/usr/src/cmd/sgs/libld/common/_libld.h (revision a07094369b21309434206d9b3601d162693466fc)
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 /*
24  *	Copyright (c) 1988 AT&T
25  *	  All Rights Reserved
26  *
27  * Copyright 2006 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,
54 #if	(defined(__i386) || defined(__amd64)) && defined(_ELF64)
55 	LD_LRODATA,	LD_LDATA,
56 #endif
57 	LD_DYN,		LD_DTRACE,	 LD_NOTE,	LD_SUNWBSS,
58 	LD_TLS,
59 #if defined(__x86) && defined(_ELF64)
60 	LD_UNWIND,
61 #endif
62 	LD_EXTRA,
63 	LD_NUM
64 } Segment_ndx;
65 
66 /*
67  * Types of bss sections
68  */
69 typedef enum {
70 	MAKE_BSS,
71 	MAKE_LBSS,
72 	MAKE_TLS
73 } Bss_Type;
74 
75 /*
76  * Structure to manage the update of weak symbols from their associated alias.
77  */
78 typedef	struct wk_desc {
79 	Sym		*wk_symtab;	/* the .symtab entry */
80 	Sym		*wk_dynsym;	/* the .dynsym entry */
81 	Sym_desc	*wk_weak;	/* the original weak symbol */
82 	Sym_desc	*wk_alias;	/* the real symbol */
83 } Wk_desc;
84 
85 /*
86  * Structure to manage the support library interfaces.
87  */
88 typedef struct func_list {
89 	const char	*fl_obj;	/* name of support object */
90 					/*	function is from */
91 	void		(*fl_fptr)();	/* function pointer */
92 	uint_t		fl_version;	/* ld_version() level */
93 } Func_list;
94 
95 typedef	struct support_list {
96 	const char	*sup_name;	/* ld_support function name */
97 	List		sup_funcs;	/* list of support functions */
98 } Support_list;
99 
100 /*
101  * Structure to manage a sorted output relocation list.
102  *
103  *	rl_key1		->	pointer to needed ndx
104  *	rl_key2		->	pointer to symbol relocation is against
105  *	rl_key3		->	virtual offset of relocation
106  */
107 typedef struct reloc_list {
108 	Sym_desc	*rl_key2;
109 	Xword		rl_key3;
110 	Rel_desc	*rl_rsp;
111 	Half		rl_key1;
112 } Reloc_list;
113 
114 
115 typedef struct sym_s_list {
116 	Word		sl_hval;
117 	Sym_desc *	sl_sdp;
118 } Sym_s_list;
119 
120 /*
121  * ld heap management structure
122  */
123 typedef struct _ld_heap Ld_heap;
124 struct _ld_heap {
125 	Ld_heap		*lh_next;
126 	void		*lh_free;
127 	void		*lh_end;
128 };
129 
130 #define	HEAPBLOCK	0x68000		/* default allocation block size */
131 #define	HEAPALIGN	0x8		/* heap blocks alignment requirement */
132 
133 /*
134  * Dynamic per-symbol filtee string table descriptor.  This associates filtee
135  * strings that will be created in the .dynstr, with .dynamic entries.
136  */
137 typedef struct {
138 	char		*dft_str;	/* dynstr string */
139 	Word		dft_flag;	/* auxiliary/filtee type */
140 	Half		dft_ndx;	/* eventual ndx into .dynamic */
141 } Dfltr_desc;
142 
143 #define	AL_CNT_DFLTR	4
144 #define	AL_CNT_GROUP	20
145 
146 /*
147  * Per-symbol filtee descriptor.  This associates symbol definitions with
148  * their filtees.
149  */
150 typedef struct {
151 	Sym_desc	*sft_sdp;	/* symbol descriptor */
152 	Aliste		sft_off;	/* offset into dtstr descriptor */
153 } Sfltr_desc;
154 
155 #define	AL_CNT_SFLTR	20
156 
157 /*
158  * Return codes for {tls|got}_fixups() routines
159  */
160 typedef enum {
161 	FIX_ERROR,	/* fatal error - time to punt */
162 	FIX_DONE,	/* relocation done - no further processing required */
163 	FIX_RELOC	/* do_reloc() relocation processing required */
164 } Fixupret;
165 
166 #ifndef	FILENAME_MAX
167 #define	FILENAME_MAX	BUFSIZ		/* maximum length of a path name */
168 #endif
169 
170 /*
171  * Relocation buckets are sized based on the number of input relocations and
172  * the following constants.
173  */
174 #define	REL_HAIDESCNO	1000		/* high water mark active buckets */
175 #define	REL_LAIDESCNO	50		/* low water mark active buckets */
176 #define	REL_HOIDESCNO	500		/* high water mark output buckets */
177 #define	REL_LOIDESCNO	10		/* low water mark output buckets */
178 
179 extern Ofl_desc		Ofl;
180 extern char		*Plibpath;
181 extern char		*Llibdir;
182 extern char		*Ulibdir;
183 extern Ehdr		def_ehdr;
184 extern Ld_heap		*ld_heap;
185 extern List		lib_support;
186 extern const Msg	reject[];
187 extern uint_t		dbg_mask;
188 
189 extern int		Verbose;
190 
191 /*
192  * For backward compatibility provide a /dev/zero file descriptor.
193  */
194 extern int		dz_fd;
195 
196 /*
197  * Local functions.
198  */
199 extern uintptr_t	add_actrel(Word, Rel_desc *, Ofl_desc *);
200 extern uintptr_t	add_libdir(Ofl_desc *, const char *);
201 extern uintptr_t	add_outrel(Word, Rel_desc *, Ofl_desc *);
202 extern uintptr_t	add_regsym(Sym_desc *, Ofl_desc *);
203 extern void 		adj_movereloc(Ofl_desc *, Rel_desc *);
204 extern void		*alist_append(Alist **, const void *, size_t, int);
205 extern Sym_desc * 	am_I_partial(Rel_desc *, Xword);
206 extern Ar_desc *	ar_setup(const char *, Elf *, Ofl_desc *);
207 extern void		ar_member(Ar_desc *, Elf_Arsym *, Ar_aux *, Ar_mem *);
208 #if	defined(sparc)
209 extern uintptr_t	allocate_got(Ofl_desc *);
210 extern uintptr_t	assign_got(Sym_desc *);
211 #endif
212 extern uintptr_t	assign_gotndx(List *, Gotndx *, Gotref, Ofl_desc *,
213 			    Rel_desc *, Sym_desc *);
214 extern void		assign_plt_ndx(Sym_desc *, Ofl_desc *);
215 extern Xword		calc_got_offset(Rel_desc *, Ofl_desc *);
216 extern Xword		calc_plt_addr(Sym_desc *, Ofl_desc *);
217 extern int		dbg_setup(const char *);
218 extern const char	*demangle(const char *);
219 extern void		disp_errmsg(const char *, Rel_desc *, Ofl_desc *);
220 extern uintptr_t	do_activerelocs(Ofl_desc *);
221 extern void		ent_check(Ofl_desc *);
222 extern uintptr_t	fillin_gotplt1(Ofl_desc *);
223 extern Addr		fillin_gotplt2(Ofl_desc *);
224 extern Gotndx *		find_gotndx(List *, Gotref, Ofl_desc *, Rel_desc *);
225 extern uintptr_t	find_library(const char *, Ofl_desc *);
226 extern Group_desc *	get_group(Ofl_desc *, Is_desc *);
227 extern Word		hashbkts(Word);
228 extern Xword		lcm(Xword, Xword);
229 extern int		ldexit(void);
230 extern void		ldmap_out(Ofl_desc *);
231 extern uintptr_t	lib_setup(Ofl_desc *);
232 extern Listnode *	list_where(List *, Word);
233 extern void		init();
234 extern Word		init_rel(Rel_desc *, void *);
235 extern const char	*is_regsym(Ifl_desc *, Sym *, const char *, int, Word,
236 			    const char *, Word *);
237 extern void		mach_eflags(Ehdr *, Ofl_desc *);
238 extern void		mach_make_dynamic(Ofl_desc *, size_t *);
239 extern void		mach_update_odynamic(Ofl_desc *, Dyn **);
240 extern int		mach_sym_typecheck(Sym_desc *, Sym *, Ifl_desc *,
241 			    Ofl_desc *);
242 extern uintptr_t	make_bss(Ofl_desc *, Xword, Xword, Bss_Type);
243 extern uintptr_t	make_got(Ofl_desc *);
244 extern uintptr_t	make_reloc(Ofl_desc *, Os_desc *);
245 extern uintptr_t	make_sunwbss(Ofl_desc *, size_t, Xword);
246 extern uintptr_t	make_sunwdata(Ofl_desc *, size_t, Xword);
247 extern uintptr_t	make_sunwmove(Ofl_desc *, int);
248 extern uintptr_t	map_parse(const char *, Ofl_desc *);
249 extern uintptr_t	perform_outreloc(Rel_desc *, Ofl_desc *);
250 extern Os_desc *	place_section(Ofl_desc *, Is_desc *, int, Word);
251 extern uintptr_t	process_archive(const char *, int, Ar_desc *,
252 			    Ofl_desc *);
253 extern uintptr_t	process_flags(Ofl_desc *, int, char **);
254 extern uintptr_t	process_files(Ofl_desc *, int, char **);
255 extern Ifl_desc *	process_ifl(const char *, const char *, int, Elf *,
256 			    Half, Ofl_desc *, Rej_desc *);
257 extern uintptr_t	process_ordered(Ifl_desc *, Ofl_desc *, Word, Word);
258 extern uintptr_t	process_section(const char *, Ifl_desc *, Shdr *,
259 			    Elf_Scn *, Word, int, Ofl_desc *);
260 extern uintptr_t	process_sym_reloc(Ofl_desc *, Rel_desc *, Rel *,
261 			    Is_desc *, const char *);
262 extern int		reg_check(Sym_desc *, Sym *, const char *, Ifl_desc *,
263 			    Ofl_desc *);
264 extern int		reg_enter(Sym_desc *, Ofl_desc *);
265 extern Sym_desc *	reg_find(Sym *, Ofl_desc *);
266 extern uintptr_t	reloc_local(Rel_desc *, Ofl_desc *);
267 extern uintptr_t	reloc_plt(Rel_desc *, Ofl_desc *);
268 extern uintptr_t	reloc_register(Rel_desc *, Is_desc *, Ofl_desc *);
269 extern void		reloc_remain_entry(Rel_desc *, Os_desc *, Ofl_desc *);
270 extern uintptr_t	reloc_GOT_relative(Boolean, Rel_desc *, Ofl_desc *);
271 extern uintptr_t	reloc_GOTOP(Boolean, Rel_desc *, Ofl_desc *);
272 extern uintptr_t	reloc_TLS(Boolean, Rel_desc *, Ofl_desc *);
273 extern uintptr_t	sort_ordered(Ofl_desc *);
274 extern uintptr_t	sort_seg_list(Ofl_desc *);
275 extern void		sym_adjust_vis(Sym_desc *, Ofl_desc *);
276 extern int		sym_avl_comp(const void *, const void *);
277 extern uintptr_t	sym_copy(Sym_desc *);
278 extern uintptr_t	sym_nodirect(Is_desc *, Ifl_desc *, Ofl_desc *);
279 extern uintptr_t	sym_process(Is_desc *, Ifl_desc *, Ofl_desc *);
280 extern uintptr_t	sym_resolve(Sym_desc *, Sym *, Ifl_desc *, Ofl_desc *,
281 				int, Word, Word);
282 extern uintptr_t	sym_spec(Ofl_desc *);
283 extern uintptr_t	vers_def_process(Is_desc *, Ifl_desc *, Ofl_desc *);
284 extern uintptr_t	vers_need_process(Is_desc *, Ifl_desc *, Ofl_desc *);
285 extern int		vers_sym_process(Is_desc *, Ifl_desc *);
286 extern uintptr_t	vers_check_need(Ofl_desc *);
287 extern void		vers_promote(Sym_desc *, Word, Ifl_desc *, Ofl_desc *);
288 extern int		vers_verify(Ofl_desc *);
289 
290 /*
291  * AMD64 - 64-bit specific functions
292  */
293 #if defined(__x86) && defined(_ELF64)
294 extern uintptr_t	make_amd64_unwindhdr(Ofl_desc *);
295 extern uintptr_t	process_amd64_unwind(const char *, Ifl_desc *, Shdr *,
296 			    Elf_Scn *, Word, int, Ofl_desc *);
297 extern uintptr_t	populate_amd64_unwindhdr(Ofl_desc *);
298 extern uintptr_t	append_amd64_unwind(Os_desc *, Ofl_desc *);
299 #endif
300 
301 #ifdef	__cplusplus
302 }
303 #endif
304 
305 #endif /* _LIBLD_DOT_H */
306