xref: /titanic_41/usr/src/cmd/sgs/libld/common/_libld.h (revision 500b1e787b108592a37e3d54dc9b5e676de5386d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  *	Copyright (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 /*
31  * Local include file for ld library.
32  */
33 
34 #ifndef	_LIBLD_DOT_H
35 #define	_LIBLD_DOT_H
36 
37 #include <libld.h>
38 #include <_libelf.h>
39 #include <debug.h>
40 #include <conv.h>
41 #include <msg.h>
42 #include <reloc_defs.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 /*
49  * In order to allow for cross linking, we need to be able to build
50  * libld with support for multiple targets within a single object.
51  * This is done using a global variable (ld_targ) of type Target to
52  * access target-specific code for the current target via indirection.
53  */
54 
55 /*
56  * Machine information for target
57  */
58 typedef struct {
59 	Half		m_mach;		/* ELF machine code for target */
60 	Half		m_machplus;	/* Alt ELF machine code for target */
61 					/*	Used for EM_SPARC32PLUS */
62 	Word		m_flagsplus;	/* ELF header flags used to identify */
63 					/*	a machplus object */
64 	uchar_t		m_class;	/* Target ELFCLASS */
65 	uchar_t		m_data;		/* Target byte order */
66 
67 	Xword		m_segm_align;	/* segment alignment */
68 	Xword		m_segm_origin;	/* Default 1st segment origin */
69 	Xword		m_segm_aorigin;	/* Alternative 1st segment origin */
70 	Word		m_dataseg_perm;	/* data segment permission mask */
71 	Word		m_word_align;	/* alignment to use for Word sections */
72 	const char	*m_def_interp;	/* Def. interpreter for dyn objects */
73 
74 	/* Relocation type codes */
75 	Word		m_r_arrayaddr;
76 	Word		m_r_copy;
77 	Word		m_r_glob_dat;
78 	Word		m_r_jmp_slot;
79 	Word		m_r_num;
80 	Word		m_r_none;
81 	Word		m_r_relative;
82 	Word		m_r_register;
83 
84 	/* Relocation related constants */
85 	Word		m_rel_dt_count;	/* Either DT_REL or DT_RELA */
86 	Word		m_rel_dt_ent;	/* Either DT_RELENT or DT_RELAENT */
87 	Word		m_rel_dt_size;	/* Either DT_RELSZ or DT_RELASZ */
88 	Word		m_rel_dt_type;	/* Either DT_RELCOUNT or DT_RELACOUNT */
89 	Word		m_rel_sht_type;	/* Either SHT_REL or SHT_RELA */
90 
91 	/* GOT related constants */
92 	Word		m_got_entsize;
93 	Word		m_got_xnumber;	/* reserved # of got ents */
94 
95 	/* PLT related constants */
96 	Word		m_plt_align;
97 	Word		m_plt_entsize;
98 	Word		m_plt_reservsz;
99 	Word		m_plt_shf_flags;
100 
101 	/* Section type of .eh_frame/.eh_frame_hdr sections */
102 	Word		m_sht_unwind;
103 
104 	Word		m_dt_register;
105 } Target_mach;
106 
107 
108 /*
109  * Section identifiers, used to order sections in output object
110  */
111 typedef struct {
112 	Word		id_array;
113 	Word		id_bss;
114 	Word		id_cap;
115 	Word		id_data;
116 	Word		id_dynamic;
117 	Word		id_dynsort;
118 	Word		id_dynstr;
119 	Word		id_dynsym;
120 	Word		id_dynsym_ndx;
121 	Word		id_got;
122 	Word		id_gotdata;
123 	Word		id_hash;
124 	Word		id_interp;
125 	Word		id_lbss;
126 	Word		id_ldynsym;
127 	Word		id_note;
128 	Word		id_null;
129 	Word		id_plt;
130 	Word		id_rel;
131 	Word		id_strtab;
132 	Word		id_syminfo;
133 	Word		id_symtab;
134 	Word		id_symtab_ndx;
135 	Word		id_text;
136 	Word		id_tls;
137 	Word		id_tlsbss;
138 	Word		id_unknown;
139 	Word		id_unwind;
140 	Word		id_unwindhdr;
141 	Word		id_user;
142 	Word		id_version;
143 } Target_machid;
144 
145 /*
146  * Target_nullfunc supplies machine code for generating a
147  *
148  *	void (*)(void)
149  *
150  * unnamed function. Such a function can be called, and returns
151  * immediately without doing any work. This is used to back FUNC
152  * symbol definitions added with a mapfile.
153  *
154  * The machine instructions are specified as an array of bytes rather
155  * than a larger integer type in order to avoid byte order issues that
156  * can otherwise occur in cross linking.
157  */
158 typedef struct {
159 	const uchar_t	*nf_template;	/* Array of machine inst. bytes */
160 	size_t		nf_size;	/* # bytes in nf_template */
161 } Target_nullfunc;
162 
163 /*
164  * Target_fill supplies machine code for fill bytes in executable output
165  * sections. Normally, libelf fills the gaps caused by alignment and size
166  * requirements of the constituent input sections with 0. Depending on the
167  * target architecture, it may be desirable to instead fill with executable
168  * NOP instructions. There are two reasons to do this:
169  *
170  * -	So that .init/.fini sections will not contain unexecutable gaps
171  *	that cause the executing program to trap and die.
172  *
173  * -	To eliminate confusing garbage instructions between sections containing
174  *	executable code when viewed with a dissassembler.
175  *
176  * The ff_execfill function is allowed to be NULL if the underlying target
177  * does not require a special fill for executable sections.
178  */
179 typedef struct {
180 	_elf_execfill_func_t	*ff_execfill;
181 } Target_fillfunc;
182 
183 /*
184  * Target_machrel holds pointers to the reloc_table and machrel functions
185  * for a given target machine.
186  *
187  * The following function pointers are allowed to be NULL, if the
188  * underlying target does not require the specified operation. All
189  * other functions must be supplied:
190  *
191  *	mr_assign_got
192  *	mr_reloc_register
193  *	mr_reloc_GOTOP
194  *	mr_allocate_got
195  */
196 typedef struct {
197 	const Rel_entry	*mr_reloc_table;
198 
199 	Word		(* mr_init_rel)(Rel_desc *, void *);
200 	void 		(* mr_mach_eflags)(Ehdr *, Ofl_desc *);
201 	void		(* mr_mach_make_dynamic)(Ofl_desc *, size_t *);
202 	void		(* mr_mach_update_odynamic)(Ofl_desc *, Dyn **);
203 	Xword		(* mr_calc_plt_addr)(Sym_desc *, Ofl_desc *);
204 	uintptr_t	(* mr_perform_outreloc)(Rel_desc *, Ofl_desc *);
205 	uintptr_t	(* mr_do_activerelocs)(Ofl_desc *);
206 	uintptr_t	(* mr_add_outrel)(Word, Rel_desc *, Ofl_desc *);
207 	uintptr_t	(* mr_reloc_register)(Rel_desc *, Is_desc *,
208 			    Ofl_desc *);
209 	uintptr_t	(* mr_reloc_local)(Rel_desc *, Ofl_desc *);
210 	uintptr_t	(* mr_reloc_GOTOP)(Boolean, Rel_desc *, Ofl_desc *);
211 	uintptr_t	(* mr_reloc_TLS)(Boolean, Rel_desc *, Ofl_desc *);
212 	uintptr_t	(* mr_assign_got)(Ofl_desc *, Sym_desc *);
213 
214 	Gotndx		*(* mr_find_got_ndx)(Alist *, Gotref, Ofl_desc *,
215 			    Rel_desc *);
216 	Xword		(* mr_calc_got_offset)(Rel_desc *, Ofl_desc *);
217 	uintptr_t	(* mr_assign_got_ndx)(Alist **, Gotndx *, Gotref,
218 			    Ofl_desc *, Rel_desc *, Sym_desc *);
219 	void		(* mr_assign_plt_ndx)(Sym_desc *, Ofl_desc *);
220 	uintptr_t	(* mr_allocate_got)(Ofl_desc *);
221 	uintptr_t	(* mr_fillin_gotplt)(Ofl_desc *);
222 } Target_machrel;
223 
224 
225 /*
226  * Target_machsym holds pointers to the machsym functions
227  * for a given target machine.
228  *
229  * These fields are allowed to be NULL for targets that do not require
230  * special handling of register symbols. Register symbols are used by
231  * sparc targets. If any of these fields are non-NULL, all of them are
232  * required to be present (use empty stub routines if necessary).
233  */
234 typedef struct {
235 	int		(* ms_reg_check)(Sym_desc *, Sym *, const char *,
236 			    Ifl_desc *, Ofl_desc *);
237 	int		(* ms_mach_sym_typecheck)(Sym_desc *, Sym *,
238 			    Ifl_desc *, Ofl_desc *);
239 	const char	*(* ms_is_regsym)(Ofl_desc *, Ifl_desc *, Sym *,
240 			    const char *, int, Word, const char *, sd_flag_t *);
241 	Sym_desc	*(* ms_reg_find)(Sym * sym, Ofl_desc * ofl);
242 	int		(* ms_reg_enter)(Sym_desc *, Ofl_desc *);
243 } Target_machsym;
244 
245 typedef struct {
246 	Target_mach	t_m;
247 	Target_machid	t_id;
248 	Target_nullfunc	t_nf;
249 	Target_fillfunc	t_ff;
250 	Target_machrel	t_mr;
251 	Target_machsym	t_ms;
252 } Target;
253 
254 /*
255  * Structure to manage the update of weak symbols from their associated alias.
256  */
257 typedef	struct wk_desc {
258 	Sym		*wk_symtab;	/* the .symtab entry */
259 	Sym		*wk_dynsym;	/* the .dynsym entry */
260 	Sym_desc	*wk_weak;	/* the original weak symbol */
261 	Sym_desc	*wk_alias;	/* the real symbol */
262 } Wk_desc;
263 
264 /*
265  * Structure to manage the support library interfaces.
266  */
267 typedef struct func_list {
268 	const char	*fl_obj;	/* name of support object */
269 					/*	function is from */
270 	void		(*fl_fptr)();	/* function pointer */
271 	uint_t		fl_version;	/* ld_version() level */
272 } Func_list;
273 
274 typedef	struct support_list {
275 	const char	*sup_name;	/* ld_support function name */
276 	Alist		*sup_funcs;	/* list of support functions */
277 } Support_list;
278 
279 /*
280  * Structure to manage a sorted output relocation list.
281  *
282  *	rl_key1		->	pointer to needed ndx
283  *	rl_key2		->	pointer to symbol relocation is against
284  *	rl_key3		->	virtual offset of relocation
285  */
286 typedef struct reloc_list {
287 	Sym_desc	*rl_key2;
288 	Xword		rl_key3;
289 	Rel_desc	*rl_rsp;
290 	Half		rl_key1;
291 } Reloc_list;
292 
293 
294 typedef struct sym_s_list {
295 	Word		sl_hval;
296 	Sym_desc	*sl_sdp;
297 } Sym_s_list;
298 
299 /*
300  * ld heap management structure
301  */
302 typedef struct _ld_heap Ld_heap;
303 struct _ld_heap {
304 	Ld_heap		*lh_next;
305 	void		*lh_free;
306 	void		*lh_end;
307 };
308 
309 #define	HEAPBLOCK	0x800000	/* default allocation block size */
310 #define	HEAPALIGN	0x8		/* heap blocks alignment requirement */
311 
312 /*
313  * Dynamic per-symbol filtee string table descriptor.  This associates filtee
314  * strings that will be created in the .dynstr, with .dynamic entries.
315  */
316 typedef struct {
317 	char		*dft_str;	/* dynstr string */
318 	Word		dft_flag;	/* auxiliary/filtee type */
319 	Half		dft_ndx;	/* eventual ndx into .dynamic */
320 } Dfltr_desc;
321 
322 /*
323  * Per-symbol filtee descriptor.  This associates symbol definitions with
324  * their filtees.
325  */
326 typedef struct {
327 	Sym_desc	*sft_sdp;	/* symbol descriptor */
328 	Aliste		sft_idx;	/* index into dtstr descriptor */
329 } Sfltr_desc;
330 
331 /*
332  * Define Alist initialization sizes.
333  */
334 #define	AL_CNT_IFL_GROUPS	20	/* ifl_groups */
335 #define	AL_CNT_IFL_RELSECS	6	/* ifl_relsect */
336 
337 #define	AL_CNT_OFL_DTSFLTRS	4	/* ofl_dtsfltrs */
338 #define	AL_CNT_OFL_SYMFLTRS	20	/* ofl_symfltrs */
339 #define	AL_CNT_OFL_MAPSECS	10	/* ofl_map{text|data} */
340 #define	AL_CNT_OFL_OBJS		50	/* ofl_objs */
341 #define	AL_CNT_OFL_LIBS		10	/* ofl_sos */
342 #define	AL_CNT_OFL_LIBDIRS	10	/* ofl_[ud]libdirs */
343 #define	AL_CNT_OFL_MAPFILES	6	/* ofl_maps */
344 #define	AL_CNT_OFL_ENTRANCE	10	/* ofl_ents */
345 #define	AL_CNT_OFL_RELS		4	/* ofl_outrels */
346 #define	AL_CNT_OFL_COPYRELS	10	/* ofl_copyrels */
347 #define	AL_CNT_OFL_ARRAYS	10	/* ofl_{init|fini|prei}array */
348 #define	AL_CNT_OFL_OSGROUPS	10	/* ofl_osgroups */
349 #define	AL_CNT_OFL_OSTLSSEG	4	/* ofl_ostlsseg */
350 #define	AL_CNT_OFL_ORDERED	4	/* ofl_ordered */
351 #define	AL_CNT_OFL_SYMINFOSYMS	50	/* ofl_syminfsyms */
352 #define	AL_CNT_OFL_MOVE		10	/* ofl_ismove */
353 #define	AL_CNT_OFL_UNWIND	1	/* ofl_unwind */
354 #define	AL_CNT_OFL_PARSYMS	10	/* ofl_parsyms */
355 
356 #define	AL_CNT_OS_MSTRISDESCS	10	/* os_mstrisdescs */
357 #define	AL_CNT_OS_RELISDESCS	100	/* os_relisdescs */
358 #define	AL_CNT_OS_COMDATS	20	/* os_comdats */
359 #define	AL_CNT_OS_ISDESCS_BA	4	/* os_isdesc: BEFORE|AFTER */
360 #define	AL_CNT_OS_ISDESCS	60	/* os_isdesc: ORDERED|DEFAULT */
361 
362 #define	AL_CNT_SG_OSDESC	40	/* sg_osdescs */
363 #define	AL_CNT_SG_SECORDER	40	/* sg_secorder */
364 
365 #define	AL_CNT_SDP_GOT		1	/* sd_GOTndxs */
366 #define	AL_CNT_SDP_MOVE		1	/* sd_move */
367 #define	AL_CNT_SDP_DFILES	1	/* sa_dfiles */
368 
369 #define	AL_CNT_SDF_VERSIONS	2	/* sdf_{vers|verneed} */
370 
371 #define	AL_CNT_EC_FILES		1	/* ec_files */
372 
373 #define	AL_CNT_VERDESCS		20	/* version desc */
374 #define	AL_CNT_WEAK		20	/* weak desc */
375 #define	AL_CNT_SUPPORT		2	/* support libraries */
376 #define	AL_CNT_STRMRGREL	500	/* ld_make_strmerge() reloc alist cnt */
377 #define	AL_CNT_STRMRGSYM	20	/* ld_make_strmerge() sym alist cnt */
378 #define	AL_CNT_SEGMENTS		20	/* ofl_segs */
379 
380 /*
381  * Return codes for {tls|got}_fixups() routines
382  */
383 typedef enum {
384 	FIX_ERROR,	/* fatal error - time to punt */
385 	FIX_DONE,	/* relocation done - no further processing required */
386 	FIX_RELOC	/* do_reloc() relocation processing required */
387 } Fixupret;
388 
389 #ifndef	FILENAME_MAX
390 #define	FILENAME_MAX	BUFSIZ		/* maximum length of a path name */
391 #endif
392 
393 /*
394  * We pad the end of the .dynstr section with a block of DYNSTR_EXTRA_PAD
395  * bytes, and we insert DYNAMIC_EXTRA_ELTS unused items into the
396  * .dynamic section (with value DT_NULL). This provides the resources needed
397  * to add and/or alter string items in the .dynamic section, such as runpath.
398  */
399 #define	DYNSTR_EXTRA_PAD	512
400 #define	DYNAMIC_EXTRA_ELTS	10
401 
402 /*
403  * Relocation buckets are sized based on the number of input relocations and
404  * the following constants.
405  */
406 #define	REL_HAIDESCNO	1000		/* high water mark active buckets */
407 #define	REL_LAIDESCNO	50		/* low water mark active buckets */
408 #define	REL_HOIDESCNO	500		/* high water mark output buckets */
409 #define	REL_LOIDESCNO	10		/* low water mark output buckets */
410 
411 /*
412  * Given a symbol of a type that is allowed within a .SUNW_dynsymsort or
413  * .SUNW_dyntlssort section, examine the symbol attributes to determine
414  * if this particular symbol should be included or not.
415  *
416  * entry:
417  *	The symbol must have an allowed type: Either a type verified by
418  *	dynsymsort_symtype[] or STT_TLS.
419  *
420  *	_sdp - Pointer to symbol descriptor
421  *	_sym - Pointer to symbol referenced by _sdp.
422  *
423  *	_sym is derivable from _sdp: _sdp->sd_sym
424  *	However, most callers assign it to a local variable for efficiency,
425  *	and this macro allows such a variable to be used within. If you
426  *	don't have such a variable, supply _sdp->sd_sym.
427  *
428  * The tests used require some explanation:
429  *
430  *	(_sdp->sd_flags & FLG_SY_DYNSORT)
431  *		Some special symbols are kept even if they don't meet the
432  *		usual requirements. These symbols have the FLG_SY_DYNSORT
433  *		bit set. If this bit isn't set then we look at the other
434  *		attributes.
435  *
436  *	(((_sdp->sd_ref != REF_DYN_NEED) &&
437  *		(_sdp->sd_sym->st_shndx != SHN_UNDEF))
438  *	|| (_sdp->sd_flags & FLG_SY_MVTOCOMM))
439  *		We do not want to include symbols that are not defined within
440  *		the object we are creating. REF_DYN_NEED corresponds to those
441  *		UNDEF items. However, if the symbol is the target of a copy
442  *		relocation, then it effectively becomes defined within the
443  *		object after all. FLG_SY_MVTOCOMM indicates a copy relocation,
444  *		and prevents us from culling those exceptions.
445  *
446  *	(_sym->st_size != 0)
447  *		Symbols with 0 length are labels injected by the compilers
448  *		or the linker for purposes of code generation, and do
449  *		not directly correspond to actual code. In fact, most of the
450  *		symbols we mark with FLG_SY_DYNSORT need that flag set because
451  *		they have size 0. This size test filters out the others.
452  *
453  *	!(_sdp->sd_flags & FLG_SY_NODYNSORT)
454  *		Some symbols are not kept, even though they do meet the usual
455  *		requirements. These symbols have FLG_SY_NODYNSORT set.
456  *		For example, if there are weak and non-weak versions of a given
457  *		symbol, we only want to keep one of them. So, we set
458  *		FLG_SY_NODYNSORT on the one we don't want.
459  */
460 #define	DYNSORT_TEST_ATTR(_sdp, _sym) \
461 	((_sdp->sd_flags & FLG_SY_DYNSORT) || \
462 	((((_sdp->sd_ref != REF_DYN_NEED) && \
463 		(_sdp->sd_sym->st_shndx != SHN_UNDEF)) || \
464 		(_sdp->sd_flags & FLG_SY_MVTOCOMM)) && \
465 	(_sym->st_size != 0) && \
466 	!(_sdp->sd_flags & FLG_SY_NODYNSORT)))
467 
468 /*
469  * We use output section descriptor counters to add up the number of
470  * symbol indexes to put in the .SUNW_dynsort and .SUNW_dyntlssort sections.
471  * Non-TLS symbols are counted by ofl->ofl_dynsymsortcnt, while TLS symbols are
472  * counted by ofl->ofl_dyntlssortcnt. This computation is done inline in
473  * several places. The DYNSORT_COUNT macro allows us to generate this from
474  * a single description.
475  *
476  * entry:
477  *	_sdp, _sym - As per DYNSORT_TEST_ATTR
478  *	_type - Type of symbol (STT_*)
479  *	_inc_or_dec_op - Either ++, or --. This specifies the operation
480  *		to be applied to the counter, and determines whether we
481  *		are adding, or removing, a symbol from .SUNW_dynsymsort.
482  *
483  * Note that _type is derivable from _sym: ELF_ST_TYPE(_sdp->sd_sym->st_info).
484  * Most callers already have it in a variable, so this allows us to use that
485  * variable. If you don't have such a variable, use ELF_ST_TYPE() as shown.
486  */
487 #define	DYNSORT_COUNT(_sdp, _sym, _type, _inc_or_dec_op) \
488 { \
489 	Word *_cnt_var; \
490 	\
491 	if (dynsymsort_symtype[_type]) {	/* Non-TLS counter */ \
492 		_cnt_var = &ofl->ofl_dynsymsortcnt; \
493 	} else if ((_type) == STT_TLS) {	/* TLS counter */ \
494 		_cnt_var = &ofl->ofl_dyntlssortcnt; \
495 	} else {				/* Don't count this symbol */ \
496 		_cnt_var = NULL; \
497 	} \
498 	if ((_cnt_var != NULL) && DYNSORT_TEST_ATTR(_sdp, _sym)) \
499 		(*_cnt_var)_inc_or_dec_op;	/* Increment/Decrement */ \
500 }
501 
502 /*
503  * The OFL_SWAP_RELOC macros are used to determine whether
504  * relocation processing needs to swap the data being relocated.
505  * It is an optimization to ld_swap_reloc_data(), as it avoids
506  * the function call in the case where the linker host and the
507  * target have the same byte order.
508  */
509 #define	OFL_SWAP_RELOC_DATA(_ofl, _rel) \
510 	(((_ofl)->ofl_flags1 & FLG_OF1_ENCDIFF) && \
511 	ld_swap_reloc_data(_ofl, _rel))
512 
513 /*
514  * Define an AVL node for maintaining input section descriptors. AVL trees of
515  * these descriptors are used to process group and COMDAT section.
516  *
517  * Pure COMDAT uses the input section name as the search key, while
518  * SHT_GROUP sections use the name of a special signature symbol. We
519  * support both by using the isd_name field to carry the name. An alternative
520  * design would be to use a separate type for each use, saving the cost
521  * of the unneeded pointer for pure COMDAT. We favor a single implementation
522  * because we believe that SHT_GROUP comdat will be more common going forward,
523  * particularly in the largest objects produced by C++ where SHT_GROUP is
524  * needed to manage the complex section relationships. In contrast, we think
525  * that pure COMDAT is both more rare, and used in smaller objects where the
526  * cost of an extra pointer per node is relatively unimportant.
527  */
528 typedef struct {
529 	avl_node_t	isd_avl;	/* avl book-keeping (see SGSOFFSETOF) */
530 	Is_desc		*isd_isp;	/* input section descriptor */
531 	const char	*isd_name;	/* name used as search key */
532 	uint_t		isd_hash;	/* input section name hash value */
533 } Isd_node;
534 
535 /*
536  * Local data items.
537  */
538 extern char		*Plibpath;
539 extern char		*Llibdir;
540 extern char		*Ulibdir;
541 extern Ld_heap		*ld_heap;
542 extern APlist		*lib_support;
543 extern int		demangle_flag;
544 extern const Msg	reject[];
545 extern int		Verbose;
546 extern const int	ldynsym_symtype[];
547 extern const int	dynsymsort_symtype[];
548 
549 /*
550  * Local functions.
551  */
552 extern char		*add_string(char *, char *);
553 extern const char	*demangle(const char *);
554 
555 extern void		lds_atexit(Ofl_desc *, int);
556 
557 extern void		libld_free(void *);
558 extern void		*libld_malloc(size_t);
559 extern void		*libld_realloc(void *, size_t);
560 
561 extern int		isdavl_compare(const void *, const void *);
562 
563 extern Sdf_desc		*sdf_add(const char *, APlist **);
564 extern Sdf_desc		*sdf_find(const char *, APlist *);
565 
566 #if	defined(_ELF64)
567 
568 #define	ld_add_actrel		ld64_add_actrel
569 #define	ld_add_libdir		ld64_add_libdir
570 #define	ld_add_rel_cache	ld64_add_rel_cache
571 #define	ld_adj_movereloc	ld64_adj_movereloc
572 #define	ld_am_I_partial		ld64_am_I_partial
573 #define	ld_ar_member		ld64_ar_member
574 #define	ld_ar_setup		ld64_ar_setup
575 #define	ld_assign_got_TLS	ld64_assign_got_TLS
576 #define	ld_bswap_Word		ld64_bswap_Word
577 #define	ld_bswap_Xword		ld64_bswap_Xword
578 #define	ld_disp_errmsg		ld64_disp_errmsg
579 #define	ld_ent_check		ld64_ent_check
580 #define	ld_exit			ld64_exit
581 #define	ld_find_library		ld64_find_library
582 #define	ld_finish_libs		ld64_finish_libs
583 #define	ld_get_group		ld64_get_group
584 #define	ld_group_process	ld64_group_process
585 #define	ld_lib_setup		ld64_lib_setup
586 #define	ld_init_sighandler	ld64_init_sighandler
587 #define	ld_lcm			ld64_lcm
588 #define	ld_make_bss		ld64_make_bss
589 #define	ld_make_data		ld64_make_data
590 #define	ld_make_got		ld64_make_got
591 #define	ld_make_parexpn_data	ld64_make_parexpn_data
592 #define	ld_make_sunwmove	ld64_make_sunmove
593 #define	ld_make_text		ld64_make_text
594 #define	ld_map_out		ld64_map_out
595 #define	ld_map_parse		ld64_map_parse
596 #define	ld_open_outfile		ld64_open_outfile
597 #define	ld_os_first_isdesc	ld64_os_first_isdesc
598 #define	ld_place_section	ld64_place_section
599 #define	ld_process_archive	ld64_process_archive
600 #define	ld_process_files	ld64_process_files
601 #define	ld_process_flags	ld64_process_flags
602 #define	ld_process_ifl		ld64_process_ifl
603 #define	ld_process_move		ld64_process_move
604 #define	ld_process_open		ld64_process_open
605 #define	ld_process_ordered	ld64_process_ordered
606 #define	ld_process_sym_reloc	ld64_process_sym_reloc
607 #define	ld_reloc_GOT_relative	ld64_reloc_GOT_relative
608 #define	ld_reloc_plt		ld64_reloc_plt
609 #define	ld_reloc_remain_entry	ld64_reloc_remain_entry
610 #define	ld_reloc_targval_get	ld64_reloc_targval_get
611 #define	ld_reloc_targval_set	ld64_reloc_targval_set
612 #define	ld_sec_validate		ld64_sec_validate
613 #define	ld_sort_ordered		ld64_sort_ordered
614 #define	ld_sort_seg_list	ld64_sort_seg_list
615 #define	ld_stt_section_sym_name	ld64_stt_section_sym_name
616 #define	ld_sunw_ldmach		ld64_sunw_ldmach
617 #define	ld_sup_atexit		ld64_sup_atexit
618 #define	ld_sup_open		ld64_sup_open
619 #define	ld_sup_file		ld64_sup_file
620 #define	ld_sup_loadso		ld64_sup_loadso
621 #define	ld_sup_input_done	ld64_sup_input_done
622 #define	ld_sup_input_section	ld64_sup_input_section
623 #define	ld_sup_section		ld64_sup_section
624 #define	ld_sup_start		ld64_sup_start
625 #define	ld_swap_reloc_data	ld64_swap_reloc_data
626 #define	ld_sym_add_u		ld64_sym_add_u
627 #define	ld_sym_adjust_vis	ld64_sym_adjust_vis
628 #define	ld_sym_avl_comp		ld64_sym_avl_comp
629 #define	ld_sym_copy		ld64_sym_copy
630 #define	ld_sym_enter		ld64_sym_enter
631 #define	ld_sym_find		ld64_sym_find
632 #define	ld_sym_nodirect		ld64_sym_nodirect
633 #define	ld_sym_process		ld64_sym_process
634 #define	ld_sym_resolve		ld64_sym_resolve
635 #define	ld_sym_spec		ld64_sym_spec
636 #define	ld_targ			ld64_targ
637 #define	ld_targ_init_sparc	ld64_targ_init_sparc
638 #define	ld_targ_init_x86	ld64_targ_init_x86
639 #define	ld_unwind_make_hdr	ld64_unwind_make_hdr
640 #define	ld_unwind_populate_hdr	ld64_unwind_populate_hdr
641 #define	ld_unwind_register	ld64_unwind_register
642 #define	ld_vers_base		ld64_vers_base
643 #define	ld_vers_check_defs	ld64_vers_check_defs
644 #define	ld_vers_check_need	ld64_vers_check_need
645 #define	ld_vers_def_process	ld64_vers_def_process
646 #define	ld_vers_desc		ld64_vers_desc
647 #define	ld_vers_find		ld64_vers_find
648 #define	ld_vers_need_process	ld64_vers_need_process
649 #define	ld_vers_promote		ld64_vers_promote
650 #define	ld_vers_sym_process	ld64_vers_sym_process
651 #define	ld_vers_verify		ld64_vers_verify
652 #define	ld_wrap_enter		ld64_wrap_enter
653 
654 #else
655 
656 #define	ld_add_actrel		ld32_add_actrel
657 #define	ld_add_libdir		ld32_add_libdir
658 #define	ld_add_rel_cache	ld32_add_rel_cache
659 #define	ld_adj_movereloc	ld32_adj_movereloc
660 #define	ld_am_I_partial		ld32_am_I_partial
661 #define	ld_ar_member		ld32_ar_member
662 #define	ld_ar_setup		ld32_ar_setup
663 #define	ld_assign_got_TLS	ld32_assign_got_TLS
664 #define	ld_bswap_Word		ld32_bswap_Word
665 #define	ld_bswap_Xword		ld32_bswap_Xword
666 #define	ld_disp_errmsg		ld32_disp_errmsg
667 #define	ld_ent_check		ld32_ent_check
668 #define	ld_exit			ld32_exit
669 #define	ld_find_library		ld32_find_library
670 #define	ld_finish_libs		ld32_finish_libs
671 #define	ld_get_group		ld32_get_group
672 #define	ld_group_process	ld32_group_process
673 #define	ld_lib_setup		ld32_lib_setup
674 #define	ld_init_sighandler	ld32_init_sighandler
675 #define	ld_lcm			ld32_lcm
676 #define	ld_make_bss		ld32_make_bss
677 #define	ld_make_data		ld32_make_data
678 #define	ld_make_got		ld32_make_got
679 #define	ld_make_parexpn_data	ld32_make_parexpn_data
680 #define	ld_make_sunwmove	ld32_make_sunmove
681 #define	ld_make_text		ld32_make_text
682 #define	ld_map_out		ld32_map_out
683 #define	ld_map_parse		ld32_map_parse
684 #define	ld_open_outfile		ld32_open_outfile
685 #define	ld_os_first_isdesc	ld32_os_first_isdesc
686 #define	ld_place_section	ld32_place_section
687 #define	ld_process_archive	ld32_process_archive
688 #define	ld_process_files	ld32_process_files
689 #define	ld_process_flags	ld32_process_flags
690 #define	ld_process_ifl		ld32_process_ifl
691 #define	ld_process_move		ld32_process_move
692 #define	ld_process_open		ld32_process_open
693 #define	ld_process_ordered	ld32_process_ordered
694 #define	ld_process_sym_reloc	ld32_process_sym_reloc
695 #define	ld_reloc_GOT_relative	ld32_reloc_GOT_relative
696 #define	ld_reloc_plt		ld32_reloc_plt
697 #define	ld_reloc_remain_entry	ld32_reloc_remain_entry
698 #define	ld_reloc_targval_get	ld32_reloc_targval_get
699 #define	ld_reloc_targval_set	ld32_reloc_targval_set
700 #define	ld_sec_validate		ld32_sec_validate
701 #define	ld_sort_ordered		ld32_sort_ordered
702 #define	ld_sort_seg_list	ld32_sort_seg_list
703 #define	ld_stt_section_sym_name	ld32_stt_section_sym_name
704 #define	ld_sunw_ldmach		ld32_sunw_ldmach
705 #define	ld_sup_atexit		ld32_sup_atexit
706 #define	ld_sup_open		ld32_sup_open
707 #define	ld_sup_file		ld32_sup_file
708 #define	ld_sup_loadso		ld32_sup_loadso
709 #define	ld_sup_input_done	ld32_sup_input_done
710 #define	ld_sup_input_section	ld32_sup_input_section
711 #define	ld_sup_section		ld32_sup_section
712 #define	ld_sup_start		ld32_sup_start
713 #define	ld_swap_reloc_data	ld32_swap_reloc_data
714 #define	ld_sym_add_u		ld32_sym_add_u
715 #define	ld_sym_adjust_vis	ld32_sym_adjust_vis
716 #define	ld_sym_avl_comp		ld32_sym_avl_comp
717 #define	ld_sym_copy		ld32_sym_copy
718 #define	ld_sym_enter		ld32_sym_enter
719 #define	ld_sym_find		ld32_sym_find
720 #define	ld_sym_nodirect		ld32_sym_nodirect
721 #define	ld_sym_process		ld32_sym_process
722 #define	ld_sym_resolve		ld32_sym_resolve
723 #define	ld_sym_spec		ld32_sym_spec
724 #define	ld_targ			ld32_targ
725 #define	ld_targ_init_sparc	ld32_targ_init_sparc
726 #define	ld_targ_init_x86	ld32_targ_init_x86
727 #define	ld_unwind_make_hdr	ld32_unwind_make_hdr
728 #define	ld_unwind_populate_hdr	ld32_unwind_populate_hdr
729 #define	ld_unwind_register	ld32_unwind_register
730 #define	ld_vers_base		ld32_vers_base
731 #define	ld_vers_check_defs	ld32_vers_check_defs
732 #define	ld_vers_check_need	ld32_vers_check_need
733 #define	ld_vers_def_process	ld32_vers_def_process
734 #define	ld_vers_desc		ld32_vers_desc
735 #define	ld_vers_find		ld32_vers_find
736 #define	ld_vers_need_process	ld32_vers_need_process
737 #define	ld_vers_promote		ld32_vers_promote
738 #define	ld_vers_sym_process	ld32_vers_sym_process
739 #define	ld_vers_verify		ld32_vers_verify
740 #define	ld_wrap_enter		ld32_wrap_enter
741 
742 #endif
743 
744 extern void		dbg_cleanup(void);
745 extern int		dbg_setup(Ofl_desc *, const char *, int);
746 
747 extern uintptr_t	ld_add_actrel(Word, Rel_desc *, Ofl_desc *);
748 extern uintptr_t	ld_add_libdir(Ofl_desc *, const char *);
749 extern Rel_cache	*ld_add_rel_cache(Ofl_desc *, APlist **, size_t *,
750 			    size_t, size_t);
751 extern void 		ld_adj_movereloc(Ofl_desc *, Rel_desc *);
752 extern Sym_desc * 	ld_am_I_partial(Rel_desc *, Xword);
753 extern void		ld_ar_member(Ar_desc *, Elf_Arsym *, Ar_aux *,
754 			    Ar_mem *);
755 extern Ar_desc		*ld_ar_setup(const char *, Elf *, Ofl_desc *);
756 extern uintptr_t	ld_assign_got_TLS(Boolean, Rel_desc *, Ofl_desc *,
757 			    Sym_desc *, Gotndx *, Gotref, Word, Word,
758 			    Word, Word);
759 
760 extern Word		ld_bswap_Word(Word);
761 extern Xword		ld_bswap_Xword(Xword);
762 
763 extern void		ld_disp_errmsg(const char *, Rel_desc *, Ofl_desc *);
764 
765 extern void		ld_ent_check(Ofl_desc *);
766 extern int		ld_exit(Ofl_desc *);
767 
768 extern uintptr_t	ld_find_library(const char *, Ofl_desc *);
769 extern uintptr_t	ld_finish_libs(Ofl_desc *);
770 
771 extern const char	*ld_stt_section_sym_name(Is_desc *);
772 
773 extern Group_desc	*ld_get_group(Ofl_desc *, Is_desc *);
774 extern uintptr_t	ld_group_process(Is_desc *, Ofl_desc *);
775 
776 extern uintptr_t	ld_lib_setup(Ofl_desc *);
777 
778 extern void		ld_init_sighandler(Ofl_desc *);
779 
780 extern Xword		ld_lcm(Xword, Xword);
781 
782 extern uintptr_t	ld_make_bss(Ofl_desc *, Xword, Xword, uint_t);
783 extern Is_desc		*ld_make_data(Ofl_desc *, size_t);
784 extern uintptr_t	ld_make_got(Ofl_desc *);
785 extern uintptr_t	ld_make_parexpn_data(Ofl_desc *, size_t, Xword);
786 extern uintptr_t	ld_make_sunwmove(Ofl_desc *, int);
787 extern Is_desc		*ld_make_text(Ofl_desc *, size_t);
788 extern void		ld_map_out(Ofl_desc *);
789 extern uintptr_t	ld_map_parse(const char *, Ofl_desc *);
790 
791 extern uintptr_t	ld_open_outfile(Ofl_desc *);
792 
793 extern Is_desc		*ld_os_first_isdesc(Os_desc *);
794 extern Os_desc		*ld_place_section(Ofl_desc *, Is_desc *, int,
795 			    const char *);
796 extern uintptr_t	ld_process_archive(const char *, int, Ar_desc *,
797 			    Ofl_desc *);
798 extern uintptr_t	ld_process_files(Ofl_desc *, int, char **);
799 extern uintptr_t	ld_process_flags(Ofl_desc *, int, char **);
800 extern Ifl_desc		*ld_process_ifl(const char *, const char *, int, Elf *,
801 			    Word, Ofl_desc *, Rej_desc *);
802 extern uintptr_t	ld_process_move(Ofl_desc *);
803 extern Ifl_desc		*ld_process_open(const char *, const char *, int *,
804 			    Ofl_desc *, Word, Rej_desc *);
805 extern uintptr_t	ld_process_ordered(Ifl_desc *, Ofl_desc *, Word);
806 extern uintptr_t	ld_process_sym_reloc(Ofl_desc *, Rel_desc *, Rel *,
807 			    Is_desc *, const char *, Word);
808 
809 extern uintptr_t	ld_reloc_GOT_relative(Boolean, Rel_desc *, Ofl_desc *);
810 extern uintptr_t	ld_reloc_plt(Rel_desc *, Ofl_desc *);
811 extern void		ld_reloc_remain_entry(Rel_desc *, Os_desc *,
812 			    Ofl_desc *);
813 extern int		ld_reloc_targval_get(Ofl_desc *, Rel_desc *,
814 			    uchar_t *, Xword *);
815 extern int		ld_reloc_targval_set(Ofl_desc *, Rel_desc *,
816 			    uchar_t *, Xword);
817 
818 extern void		ld_sec_validate(Ofl_desc *);
819 extern uintptr_t	ld_sort_ordered(Ofl_desc *);
820 extern uintptr_t	ld_sort_seg_list(Ofl_desc *);
821 extern Half		ld_sunw_ldmach();
822 extern void		ld_sup_atexit(Ofl_desc *, int);
823 extern void		ld_sup_open(Ofl_desc *, const char **, const char **,
824 			    int *, int, Elf **, Elf *ref, size_t,
825 			    const Elf_Kind);
826 extern void		ld_sup_file(Ofl_desc *, const char *, const Elf_Kind,
827 			    int flags, Elf *);
828 extern uintptr_t	ld_sup_loadso(Ofl_desc *, const char *);
829 extern void		ld_sup_input_done(Ofl_desc *);
830 extern void		ld_sup_section(Ofl_desc *, const char *, Shdr *, Word,
831 			    Elf_Data *, Elf *);
832 extern uintptr_t	ld_sup_input_section(Ofl_desc*, Ifl_desc *,
833 			    const char *, Shdr **, Word, Elf_Scn *, Elf *);
834 extern void		ld_sup_start(Ofl_desc *, const Half, const char *);
835 extern int		ld_swap_reloc_data(Ofl_desc *, Rel_desc *);
836 extern Sym_desc		*ld_sym_add_u(const char *, Ofl_desc *, Msg);
837 extern void		ld_sym_adjust_vis(Sym_desc *, Ofl_desc *);
838 extern int		ld_sym_avl_comp(const void *, const void *);
839 extern uintptr_t	ld_sym_copy(Sym_desc *);
840 extern Sym_desc		*ld_sym_enter(const char *, Sym *, Word, Ifl_desc *,
841 			    Ofl_desc *, Word, Word, sd_flag_t, avl_index_t *);
842 extern Sym_desc		*ld_sym_find(const char *, Word, avl_index_t *,
843 			    Ofl_desc *);
844 extern uintptr_t	ld_sym_nodirect(Is_desc *, Ifl_desc *, Ofl_desc *);
845 extern uintptr_t	ld_sym_process(Is_desc *, Ifl_desc *, Ofl_desc *);
846 extern uintptr_t	ld_sym_resolve(Sym_desc *, Sym *, Ifl_desc *,
847 			    Ofl_desc *, int, Word, sd_flag_t);
848 extern uintptr_t	ld_sym_spec(Ofl_desc *);
849 
850 extern Target		ld_targ;
851 extern const Target	*ld_targ_init_sparc(void);
852 extern const Target	*ld_targ_init_x86(void);
853 
854 extern uintptr_t	ld_unwind_make_hdr(Ofl_desc *);
855 extern uintptr_t	ld_unwind_populate_hdr(Ofl_desc *);
856 extern uintptr_t	ld_unwind_register(Os_desc *, Ofl_desc *);
857 
858 extern Ver_desc		*ld_vers_base(Ofl_desc *);
859 extern uintptr_t	ld_vers_check_defs(Ofl_desc *);
860 extern uintptr_t	ld_vers_check_need(Ofl_desc *);
861 extern uintptr_t	ld_vers_def_process(Is_desc *, Ifl_desc *, Ofl_desc *);
862 extern Ver_desc		*ld_vers_desc(const char *, Word, APlist **);
863 extern Ver_desc		*ld_vers_find(const char *, Word, APlist *);
864 extern uintptr_t	ld_vers_need_process(Is_desc *, Ifl_desc *, Ofl_desc *);
865 extern void		ld_vers_promote(Sym_desc *, Word, Ifl_desc *,
866 			    Ofl_desc *);
867 extern int		ld_vers_sym_process(Lm_list *, Is_desc *, Ifl_desc *);
868 extern int		ld_vers_verify(Ofl_desc *);
869 extern WrapSymNode	*ld_wrap_enter(Ofl_desc *, const char *);
870 
871 extern uintptr_t	add_regsym(Sym_desc *, Ofl_desc *);
872 extern Word		hashbkts(Word);
873 extern Xword		lcm(Xword, Xword);
874 
875 /*
876  * Most platforms have both a 32 and 64-bit variant (e.g. EM_SPARC and
877  * EM_SPARCV9). To support this, there many files in libld that are built
878  * twice, once for ELFCLASS64 (_ELF64), and once for ELFCLASS32. In these
879  * files, we sometimes want to supply one value for the ELFCLASS32 case
880  * and another for ELFCLASS64. The LD_TARG_BYCLASS macro is used to do
881  * this. It is called with both both alternatives, and yields the one
882  * that applies to the current compilation environment.
883  */
884 #ifdef	_ELF64
885 #define	LD_TARG_BYCLASS(_ec32, _ec64) (_ec64)
886 #else
887 #define	LD_TARG_BYCLASS(_ec32, _ec64) (_ec32)
888 #endif
889 
890 
891 #ifdef	__cplusplus
892 }
893 #endif
894 
895 #endif /* _LIBLD_DOT_H */
896