xref: /illumos-gate/usr/src/cmd/sgs/libld/common/_libld.h (revision a48fdbef)
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 (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
27  * Copyright 2024 Oxide Computer Company
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_stack_perm;	/* ABI default stack permission mask */
72 	Word		m_word_align;	/* alignment to use for Word sections */
73 	const char	*m_def_interp;	/* Def. interpreter for dyn objects */
74 
75 	/* Relocation type codes */
76 	Word		m_r_arrayaddr;
77 	Word		m_r_copy;
78 	Word		m_r_glob_dat;
79 	Word		m_r_jmp_slot;
80 	Word		m_r_num;
81 	Word		m_r_none;
82 	Word		m_r_relative;
83 	Word		m_r_register;
84 
85 	/* Relocation related constants */
86 	Word		m_rel_dt_count;	/* Either DT_REL or DT_RELA */
87 	Word		m_rel_dt_ent;	/* Either DT_RELENT or DT_RELAENT */
88 	Word		m_rel_dt_size;	/* Either DT_RELSZ or DT_RELASZ */
89 	Word		m_rel_dt_type;	/* Either DT_RELCOUNT or DT_RELACOUNT */
90 	Word		m_rel_sht_type;	/* Either SHT_REL or SHT_RELA */
91 
92 	/* GOT related constants */
93 	Word		m_got_entsize;
94 	Word		m_got_xnumber;	/* reserved # of got ents */
95 
96 	/* PLT related constants */
97 	Word		m_plt_align;
98 	Word		m_plt_entsize;
99 	Word		m_plt_reservsz;
100 	Word		m_plt_shf_flags;
101 
102 	/* Section type of .eh_frame/.eh_frame_hdr sections */
103 	Word		m_sht_unwind;
104 
105 	Word		m_dt_register;
106 } Target_mach;
107 
108 
109 /*
110  * Section identifiers, used to order sections in output object
111  */
112 typedef struct {
113 	Word		id_array;
114 	Word		id_bss;
115 	Word		id_cap;
116 	Word		id_capinfo;
117 	Word		id_capchain;
118 	Word		id_data;
119 	Word		id_dynamic;
120 	Word		id_dynsort;
121 	Word		id_dynstr;
122 	Word		id_dynsym;
123 	Word		id_dynsym_ndx;
124 	Word		id_got;
125 	Word		id_gotdata;
126 	Word		id_hash;
127 	Word		id_interp;
128 	Word		id_lbss;
129 	Word		id_ldynsym;
130 	Word		id_note;
131 	Word		id_null;
132 	Word		id_plt;
133 	Word		id_rel;
134 	Word		id_strtab;
135 	Word		id_syminfo;
136 	Word		id_symtab;
137 	Word		id_symtab_ndx;
138 	Word		id_text;
139 	Word		id_tls;
140 	Word		id_tlsbss;
141 	Word		id_unknown;
142 	Word		id_unwind;
143 	Word		id_unwindhdr;
144 	Word		id_user;
145 	Word		id_version;
146 } Target_machid;
147 
148 /*
149  * Target_nullfunc supplies machine code for generating a
150  *
151  *	void (*)(void)
152  *
153  * unnamed function. Such a function can be called, and returns
154  * immediately without doing any work. This is used to back FUNC
155  * symbol definitions added with a mapfile.
156  *
157  * The machine instructions are specified as an array of bytes rather
158  * than a larger integer type in order to avoid byte order issues that
159  * can otherwise occur in cross linking.
160  */
161 typedef struct {
162 	const uchar_t	*nf_template;	/* Array of machine inst. bytes */
163 	size_t		nf_size;	/* # bytes in nf_template */
164 } Target_nullfunc;
165 
166 /*
167  * Target_fill supplies machine code for fill bytes in executable output
168  * sections. Normally, libelf fills the gaps caused by alignment and size
169  * requirements of the constituent input sections with 0. Depending on the
170  * target architecture, it may be desirable to instead fill with executable
171  * NOP instructions. There are two reasons to do this:
172  *
173  *  -	So that .init/.fini sections will not contain unexecutable gaps
174  *	that cause the executing program to trap and die.
175  *
176  *  -	To eliminate confusing garbage instructions between sections containing
177  *	executable code when viewed with a disassembler.
178  *
179  * The ff_execfill function is allowed to be NULL if the underlying target
180  * does not require a special fill for executable sections.
181  */
182 typedef struct {
183 	_elf_execfill_func_t	*ff_execfill;
184 } Target_fillfunc;
185 
186 /*
187  * Target_machrel holds pointers to the reloc_table and machrel functions
188  * for a given target machine.
189  *
190  * The following function pointers are allowed to be NULL, if the
191  * underlying target does not require the specified operation. All
192  * other functions must be supplied:
193  *
194  *	mr_assign_got
195  *	mr_reloc_register
196  *	mr_reloc_GOTOP
197  *	mr_allocate_got
198  */
199 typedef struct {
200 	const Rel_entry	*mr_reloc_table;
201 
202 	Word		(* mr_init_rel)(Rel_desc *, Word *, void *);
203 	void		(* mr_mach_eflags)(Ehdr *, Ofl_desc *);
204 	void		(* mr_mach_make_dynamic)(Ofl_desc *, size_t *);
205 	void		(* mr_mach_update_odynamic)(Ofl_desc *, Dyn **);
206 	Xword		(* mr_calc_plt_addr)(Sym_desc *, Ofl_desc *);
207 	uintptr_t	(* mr_perform_outreloc)(Rel_desc *, Ofl_desc *,
208 			    Boolean *);
209 	uintptr_t	(* mr_do_activerelocs)(Ofl_desc *);
210 	uintptr_t	(* mr_add_outrel)(Word, Rel_desc *, Ofl_desc *);
211 	uintptr_t	(* mr_reloc_register)(Rel_desc *, Is_desc *,
212 			    Ofl_desc *);
213 	uintptr_t	(* mr_reloc_local)(Rel_desc *, Ofl_desc *);
214 	uintptr_t	(* mr_reloc_GOTOP)(Boolean, Rel_desc *, Ofl_desc *);
215 	uintptr_t	(* mr_reloc_TLS)(Boolean, Rel_desc *, Ofl_desc *);
216 	uintptr_t	(* mr_assign_got)(Ofl_desc *, Sym_desc *);
217 
218 	Gotndx		*(* mr_find_got_ndx)(Alist *, Gotref, Ofl_desc *,
219 			    Rel_desc *);
220 	Xword		(* mr_calc_got_offset)(Rel_desc *, Ofl_desc *);
221 	uintptr_t	(* mr_assign_got_ndx)(Alist **, Gotndx *, Gotref,
222 			    Ofl_desc *, Rel_desc *, Sym_desc *);
223 	void		(* mr_assign_plt_ndx)(Sym_desc *, Ofl_desc *);
224 	uintptr_t	(* mr_allocate_got)(Ofl_desc *);
225 	uintptr_t	(* mr_fillin_gotplt)(Ofl_desc *);
226 } Target_machrel;
227 
228 
229 /*
230  * Target_machsym holds pointers to the machsym functions
231  * for a given target machine.
232  *
233  * These fields are allowed to be NULL for targets that do not require
234  * special handling of register symbols. Register symbols are used by
235  * sparc targets. If any of these fields are non-NULL, all of them are
236  * required to be present (use empty stub routines if necessary).
237  */
238 typedef struct {
239 	int		(* ms_reg_check)(Sym_desc *, Sym *, const char *,
240 			    Ifl_desc *, Ofl_desc *);
241 	int		(* ms_mach_sym_typecheck)(Sym_desc *, Sym *,
242 			    Ifl_desc *, Ofl_desc *);
243 	const char	*(* ms_is_regsym)(Ofl_desc *, Ifl_desc *, Sym *,
244 			    const char *, int, Word, const char *, sd_flag_t *);
245 	Sym_desc	*(* ms_reg_find)(Sym * sym, Ofl_desc * ofl);
246 	int		(* ms_reg_enter)(Sym_desc *, Ofl_desc *);
247 } Target_machsym;
248 
249 typedef struct {
250 	Target_mach	t_m;
251 	Target_machid	t_id;
252 	Target_nullfunc	t_nf;
253 	Target_fillfunc	t_ff;
254 	Target_machrel	t_mr;
255 	Target_machsym	t_ms;
256 } Target;
257 
258 /*
259  * Structure to manage the update of weak symbols from their associated alias.
260  */
261 typedef	struct wk_desc {
262 	Sym		*wk_symtab;	/* the .symtab entry */
263 	Sym		*wk_dynsym;	/* the .dynsym entry */
264 	Sym_desc	*wk_weak;	/* the original weak symbol */
265 	Sym_desc	*wk_alias;	/* the real symbol */
266 } Wk_desc;
267 
268 /*
269  * Structure to manage the support library interfaces.
270  */
271 typedef struct func_list {
272 	const char	*fl_obj;	/* name of support object */
273 					/*	function is from */
274 	void		(*fl_fptr)();	/* function pointer */
275 	uint_t		fl_version;	/* ld_version() level */
276 } Func_list;
277 
278 typedef	struct support_list {
279 	const char	*sup_name;	/* ld_support function name */
280 	Alist		*sup_funcs;	/* list of support functions */
281 } Support_list;
282 
283 /*
284  * Structure to manage a sorted output relocation list.
285  *
286  *	rl_key1		->	pointer to needed ndx
287  *	rl_key2		->	pointer to symbol relocation is against
288  *	rl_key3		->	virtual offset of relocation
289  */
290 typedef struct reloc_list {
291 	Sym_desc	*rl_key2;
292 	Xword		rl_key3;
293 	Rel_desc	*rl_rsp;
294 	Half		rl_key1;
295 } Reloc_list;
296 
297 
298 typedef struct sym_s_list {
299 	Word		sl_hval;
300 	Sym_desc	*sl_sdp;
301 } Sym_s_list;
302 
303 /*
304  * Dynamic per-symbol filtee string table descriptor.  This associates filtee
305  * strings that will be created in the .dynstr, with .dynamic entries.
306  */
307 typedef struct {
308 	const char	*dft_str;	/* dynstr string */
309 	Word		dft_flag;	/* auxiliary/filtee type */
310 	Half		dft_ndx;	/* eventual ndx into .dynamic */
311 } Dfltr_desc;
312 
313 /*
314  * Per-symbol filtee descriptor.  This associates symbol definitions with
315  * their filtees.
316  */
317 typedef struct {
318 	Sym_desc	*sft_sdp;	/* symbol descriptor */
319 	Aliste		sft_idx;	/* index into dtstr descriptor */
320 } Sfltr_desc;
321 
322 /*
323  * Capabilities descriptor, and capabilities group descriptor, used to track
324  * the symbol capabilities of any input files and the output file.
325  *
326  * A relocatable object input file may contain one or more symbol capabilities
327  * groups.  The Cap_desc structures keep track of all unique groups that are
328  * collected for the output file.  Relocatable objects that contain an object
329  * capabilities group, and the -z symbolcap option is in effect, have their
330  * object group translated to a symbol capabilities group.
331  *
332  * Individual capabilities groups are maintained with the Cap_group descriptor.
333  * A group can consist of one or more capabilities definitions.  One or more
334  * symbols can be associated with each group.
335  *
336  * For the output file, capabilities families are used to track the symbols of
337  * a given family, each symbol being associated with a different group.  This
338  * collection of data is used to create the final Capinfo structure, and for
339  * dynamic objects, the Capchain structure.
340  *
341  * For example, an object may contain two capabilities groups:
342  *
343  *	CA_SUNW_MACH - sun4u		CA_SUNW_MACH - sun4v
344  *
345  * Two symbols can be associated with each group:
346  *
347  *	foo%sun4u			foo%sun4v
348  *	bar%sun4u			bar%sun4v
349  *
350  * Two families are maintained, and include the generic, or lead, instance of
351  * the capabilities members:
352  *
353  *	foo,  foo%sun4u,  foo%sun4v
354  *	bar,  bar%sun4u,  bar%sun4v
355  */
356 struct cap_desc {
357 	APlist		*ca_groups;	/* capabilities groups (Cap_group) */
358 	APlist		*ca_syms;	/* copies of symbols that are being */
359 					/*	translated from object to */
360 };					/*	symbol capabilities */
361 
362 typedef struct {
363 	Objcapset	cg_set;		/* unpacked SHT_SUNW_cap elements */
364 	APlist		*cg_secs;	/* sections, and hence files, that */
365 					/*	use this descriptor */
366 	Word		cg_num;		/* number of comparable elements in */
367 					/*	the group */
368 	Word		cg_ndx;		/* final capability group index */
369 } Cap_group;
370 
371 /*
372  * A Capabilities family node, extends a symbol node, and provides for tracking
373  * capabilities families.  A family is defined by its lead symbol (for example,
374  * a generic, non-capabilities aware foo()), and one or more capabilities
375  * members (for example, capabilities instances foo%sun4u(), foo%sun4v(), etc.).
376  *
377  * Each member associates a symbol with its group using a Cap_sym structure.
378  */
379 typedef struct {
380 	Sym_avlnode	cn_symavlnode;
381 	APlist		*cn_members;
382 	APlist		*cn_aliases;
383 } Cap_avlnode;
384 
385 typedef struct {
386 	Sym_desc	*cs_sdp;	/* capabilities symbol descriptor */
387 	Cap_group	*cs_group;	/* associated capabilities group */
388 } Cap_sym;
389 
390 /*
391  * Define Alist initialization sizes.
392  */
393 #define	AL_CNT_IFL_GROUPS	20	/* ifl_groups */
394 #define	AL_CNT_IFL_RELSECS	6	/* ifl_relsect */
395 
396 #define	AL_CNT_CAP_DESCS	4	/* symbol capabilities descriptors */
397 #define	AL_CNT_CAP_SYMS		20	/* capabilities symbols */
398 #define	AL_CNT_CAP_SECS		10	/* capabilities sections */
399 #define	AL_CNT_CAP_NAMES	10	/* Objcapset platform and machine */
400 					/*	names */
401 #define	AL_CNT_CAP_MEMS		10	/* capability family members */
402 #define	AL_CNT_CAP_PAIRS	10	/* capability symbol pairs */
403 #define	AL_CNT_CAP_ALIASES	2	/* capability lead symbol aliases */
404 
405 #define	AL_CNT_OFL_DTSFLTRS	4	/* ofl_dtsfltrs */
406 #define	AL_CNT_OFL_SYMFLTRS	20	/* ofl_symfltrs */
407 #define	AL_CNT_OFL_MAPSECS	10	/* ofl_map{text|data} */
408 #define	AL_CNT_OFL_OBJS		50	/* ofl_objs */
409 #define	AL_CNT_OFL_LIBS		10	/* ofl_sos */
410 #define	AL_CNT_OFL_LIBDIRS	10	/* ofl_[ud]libdirs */
411 #define	AL_CNT_OFL_MAPFILES	6	/* ofl_maps */
412 #define	AL_CNT_OFL_ENTRANCE	10	/* ofl_ents */
413 #define	AL_CNT_OFL_RELS		4	/* ofl_outrels */
414 #define	AL_CNT_OFL_COPYRELS	10	/* ofl_copyrels */
415 #define	AL_CNT_OFL_ARRAYS	10	/* ofl_{init|fini|prei}array */
416 #define	AL_CNT_OFL_OSGROUPS	10	/* ofl_osgroups */
417 #define	AL_CNT_OFL_OSTLSSEG	4	/* ofl_ostlsseg */
418 #define	AL_CNT_OFL_ORDERED	4	/* ofl_ordered */
419 #define	AL_CNT_OFL_SYMINFOSYMS	50	/* ofl_syminfsyms */
420 #define	AL_CNT_OFL_MOVE		10	/* ofl_ismove */
421 #define	AL_CNT_OFL_UNWIND	1	/* ofl_unwind */
422 #define	AL_CNT_OFL_PARSYMS	10	/* ofl_parsyms */
423 
424 #define	AL_CNT_OS_MSTRISDESCS	10	/* os_mstrisdescs */
425 #define	AL_CNT_OS_RELISDESCS	100	/* os_relisdescs */
426 #define	AL_CNT_OS_COMDATS	20	/* os_comdats */
427 #define	AL_CNT_OS_ISDESCS_BA	4	/* os_isdesc: BEFORE|AFTER */
428 #define	AL_CNT_OS_ISDESCS	60	/* os_isdesc: ORDERED|DEFAULT */
429 
430 #define	AL_CNT_SG_IS_ORDER	40	/* sg_is_order */
431 #define	AL_CNT_SG_OSDESC	40	/* sg_osdescs */
432 #define	AL_CNT_SG_SECORDER	40	/* sg_secorder */
433 #define	AL_CNT_SG_SIZESYM	1	/* sg_sizesym */
434 
435 #define	AL_CNT_SDP_GOT		1	/* sd_GOTndxs */
436 #define	AL_CNT_SDP_MOVE		1	/* sd_move */
437 #define	AL_CNT_SDP_DFILES	1	/* sa_dfiles */
438 
439 #define	AL_CNT_SDF_VERSIONS	2	/* sdf_{vers|verneed} */
440 
441 #define	AL_CNT_EC_FILES		1	/* ec_files */
442 
443 #define	AL_CNT_VERDESCS		20	/* version desc */
444 #define	AL_CNT_WEAK		20	/* weak desc */
445 #define	AL_CNT_SUPPORT		2	/* support libraries */
446 #define	AL_CNT_STRMRGREL	500	/* ld_make_strmerge() reloc alist cnt */
447 #define	AL_CNT_STRMRGSYM	20	/* ld_make_strmerge() sym alist cnt */
448 #define	AL_CNT_SEGMENTS		20	/* ofl_segs */
449 
450 #define	AL_CNT_ASSDEFLIB	4	/* ofl_assdeflib exceptions count */
451 #define	AL_CNT_MAPASSERT	10	/* mapfile assertions */
452 
453 /*
454  * Return codes for {tls|got}_fixups() routines
455  */
456 typedef enum {
457 	FIX_ERROR,	/* fatal error - time to punt */
458 	FIX_DONE,	/* relocation done - no further processing required */
459 	FIX_RELOC	/* do_reloc() relocation processing required */
460 } Fixupret;
461 
462 #ifndef	FILENAME_MAX
463 #define	FILENAME_MAX	BUFSIZ		/* maximum length of a path name */
464 #endif
465 
466 /*
467  * We pad the end of the .dynstr section with a block of DYNSTR_EXTRA_PAD
468  * bytes, and we insert DYNAMIC_EXTRA_ELTS unused items into the
469  * .dynamic section (with value DT_NULL). This provides the resources needed
470  * to add and/or alter string items in the .dynamic section, such as runpath.
471  */
472 #define	DYNSTR_EXTRA_PAD	512
473 #define	DYNAMIC_EXTRA_ELTS	10
474 
475 /*
476  * Default relocation cache allocation unit. This number should be small
477  * enough to not hurt memory use significantly, but large enough to avoid
478  * the need for too many subsequent allocations.
479  */
480 #define	REL_CACHEBUF_ALLOC	3000
481 #define	RELAUX_CACHEBUF_ALLOC	1500
482 
483 /*
484  * Given a symbol of a type that is allowed within a .SUNW_dynsymsort or
485  * .SUNW_dyntlssort section, examine the symbol attributes to determine
486  * if this particular symbol should be included or not.
487  *
488  * entry:
489  *	The symbol must have an allowed type: Either a type verified by
490  *	dynsymsort_symtype[] or STT_TLS.
491  *
492  *	_sdp - Pointer to symbol descriptor
493  *	_sym - Pointer to symbol referenced by _sdp.
494  *
495  *	_sym is derivable from _sdp: _sdp->sd_sym
496  *	However, most callers assign it to a local variable for efficiency,
497  *	and this macro allows such a variable to be used within. If you
498  *	don't have such a variable, supply _sdp->sd_sym.
499  *
500  * The tests used require some explanation:
501  *
502  *	(_sdp->sd_flags & FLG_SY_DYNSORT)
503  *		Some special symbols are kept even if they don't meet the
504  *		usual requirements. These symbols have the FLG_SY_DYNSORT
505  *		bit set. If this bit isn't set then we look at the other
506  *		attributes.
507  *
508  *	(((_sdp->sd_ref != REF_DYN_NEED) &&
509  *		(_sdp->sd_sym->st_shndx != SHN_UNDEF))
510  *	|| (_sdp->sd_flags & FLG_SY_MVTOCOMM))
511  *		We do not want to include symbols that are not defined within
512  *		the object we are creating. REF_DYN_NEED corresponds to those
513  *		UNDEF items. However, if the symbol is the target of a copy
514  *		relocation, then it effectively becomes defined within the
515  *		object after all. FLG_SY_MVTOCOMM indicates a copy relocation,
516  *		and prevents us from culling those exceptions.
517  *
518  *	(_sym->st_size != 0)
519  *		Symbols with 0 length are labels injected by the compilers
520  *		or the linker for purposes of code generation, and do
521  *		not directly correspond to actual code. In fact, most of the
522  *		symbols we mark with FLG_SY_DYNSORT need that flag set because
523  *		they have size 0. This size test filters out the others.
524  *
525  *	!(_sdp->sd_flags & FLG_SY_NODYNSORT)
526  *		Some symbols are not kept, even though they do meet the usual
527  *		requirements. These symbols have FLG_SY_NODYNSORT set.
528  *		For example, if there are weak and non-weak versions of a given
529  *		symbol, we only want to keep one of them. So, we set
530  *		FLG_SY_NODYNSORT on the one we don't want.
531  */
532 #define	DYNSORT_TEST_ATTR(_sdp, _sym) \
533 	((_sdp->sd_flags & FLG_SY_DYNSORT) || \
534 	((((_sdp->sd_ref != REF_DYN_NEED) && \
535 		(_sdp->sd_sym->st_shndx != SHN_UNDEF)) || \
536 		(_sdp->sd_flags & FLG_SY_MVTOCOMM)) && \
537 	(_sym->st_size != 0) && \
538 	!(_sdp->sd_flags & FLG_SY_NODYNSORT)))
539 
540 /*
541  * We use output section descriptor counters to add up the number of
542  * symbol indexes to put in the .SUNW_dynsort and .SUNW_dyntlssort sections.
543  * Non-TLS symbols are counted by ofl->ofl_dynsymsortcnt, while TLS symbols are
544  * counted by ofl->ofl_dyntlssortcnt. This computation is done inline in
545  * several places. The DYNSORT_COUNT macro allows us to generate this from
546  * a single description.
547  *
548  * entry:
549  *	_sdp, _sym - As per DYNSORT_TEST_ATTR
550  *	_type - Type of symbol (STT_*)
551  *	_inc_or_dec_op - Either ++, or --. This specifies the operation
552  *		to be applied to the counter, and determines whether we
553  *		are adding, or removing, a symbol from .SUNW_dynsymsort.
554  *
555  * Note that _type is derivable from _sym: ELF_ST_TYPE(_sdp->sd_sym->st_info).
556  * Most callers already have it in a variable, so this allows us to use that
557  * variable. If you don't have such a variable, use ELF_ST_TYPE() as shown.
558  */
559 #define	DYNSORT_COUNT(_sdp, _sym, _type, _inc_or_dec_op) \
560 { \
561 	Word *_cnt_var; \
562 	\
563 	if (dynsymsort_symtype[_type]) {	/* Non-TLS counter */ \
564 		_cnt_var = &ofl->ofl_dynsymsortcnt; \
565 	} else if ((_type) == STT_TLS) {	/* TLS counter */ \
566 		_cnt_var = &ofl->ofl_dyntlssortcnt; \
567 	} else {				/* Don't count this symbol */ \
568 		_cnt_var = NULL; \
569 	} \
570 	if ((_cnt_var != NULL) && DYNSORT_TEST_ATTR(_sdp, _sym)) \
571 		(*_cnt_var)_inc_or_dec_op;	/* Increment/Decrement */ \
572 }
573 
574 /*
575  * The OFL_SWAP_RELOC macros are used to determine whether
576  * relocation processing needs to swap the data being relocated.
577  * It is an optimization to ld_swap_reloc_data(), as it avoids
578  * the function call in the case where the linker host and the
579  * target have the same byte order.
580  */
581 #define	OFL_SWAP_RELOC_DATA(_ofl, _rel) \
582 	(((_ofl)->ofl_flags1 & FLG_OF1_ENCDIFF) && \
583 	ld_swap_reloc_data(_ofl, _rel))
584 
585 /*
586  * Define an AVL node for maintaining input section descriptors. AVL trees of
587  * these descriptors are used to process group and COMDAT section.
588  *
589  * Pure COMDAT uses the input section name as the search key, while
590  * SHT_GROUP sections use the name of a special signature symbol. We
591  * support both by using the isd_name field to carry the name. An alternative
592  * design would be to use a separate type for each use, saving the cost
593  * of the unneeded pointer for pure COMDAT. We favor a single implementation
594  * because we believe that SHT_GROUP comdat will be more common going forward,
595  * particularly in the largest objects produced by C++ where SHT_GROUP is
596  * needed to manage the complex section relationships. In contrast, we think
597  * that pure COMDAT is both more rare, and used in smaller objects where the
598  * cost of an extra pointer per node is relatively unimportant.
599  */
600 typedef struct {
601 	avl_node_t	isd_avl;	/* avl book-keeping (see SGSOFFSETOF) */
602 	Is_desc		*isd_isp;	/* input section descriptor */
603 	const char	*isd_name;	/* name used as search key */
604 	uint_t		isd_hash;	/* input section name hash value */
605 } Isd_node;
606 
607 /*
608  * Type used to break down an input file path into its component parts,
609  * as used by ld_place_section() to compare an input file path to
610  * entrance criteria ec_files file strings.
611  *
612  * We define a path in the usual Unix '/' separated manner, augmented
613  * with an optional archive member suffix enclosed in parenthesis:
614  *
615  *	/dir/.../dir/basename(armember)
616  *
617  * The basename is the final path component, and includes the archive
618  * member, if present. The meaning of "object name" depends on whether or
619  * not the file comes from an archive or not. If not an archive, it is the
620  * same as the basename. If an archive, it is the name of the archive member
621  * from within the file.
622  *
623  * Variables of this type are initialized with ld_place_path_info_init().
624  */
625 typedef struct {
626 	const char	*ppi_path;	/* Full path */
627 	const char	*ppi_bname;	/* basename(ppi_path) */
628 	const char	*ppi_oname;	/* object name: Not NULL terminated */
629 	Boolean		ppi_isar;	/* TRUE if path has archive member */
630 	size_t		ppi_path_len;	/* strlen(ppi_path) */
631 	size_t		ppi_bname_len;	/* strlen(ppi_bname) */
632 	size_t		ppi_oname_len;	/* strlen(ppi_oname) */
633 } Place_path_info;
634 
635 /*
636  * Local data items.
637  */
638 extern char		*Plibpath;
639 extern char		*Llibdir;
640 extern char		*Ulibdir;
641 extern APlist		*lib_support;
642 extern int		demangle_flag;
643 extern const Msg	reject[];
644 extern int		Verbose;
645 extern const int	ldynsym_symtype[];
646 extern const int	dynsymsort_symtype[];
647 
648 /*
649  * Local functions.
650  */
651 extern char		*add_string(char *, char *);
652 extern const char	*demangle(const char *);
653 extern int		cap_names_match(Alist *, Alist *);
654 
655 extern void		lds_atexit(Ofl_desc *, int);
656 
657 /*
658  * Note that libld has a long history of assuming that all allocations are
659  * 0-initialized.  libld_malloc must maintain this.
660  */
661 #define	libld_free(x)		free(x)
662 #define	libld_malloc(x)		calloc(1, x)
663 #define	libld_realloc(x, s)	realloc(x, s)
664 #define	libld_calloc(n, s)	calloc(n, s)
665 
666 extern int		isdavl_compare(const void *, const void *);
667 extern int		osdesc_compare(const Os_desc *, const Os_desc *);
668 
669 extern Sdf_desc		*sdf_add(const char *, APlist **);
670 extern Sdf_desc		*sdf_find(const char *, APlist *);
671 
672 #if	defined(_ELF64)
673 
674 #define	ld_add_actrel		ld64_add_actrel
675 #define	ld_add_libdir		ld64_add_libdir
676 #define	ld_adj_movereloc	ld64_adj_movereloc
677 #define	ld_am_I_partial		ld64_am_I_partial
678 #define	ld_ar_member		ld64_ar_member
679 #define	ld_ar_setup		ld64_ar_setup
680 #define	ld_assign_got_TLS	ld64_assign_got_TLS
681 #define	ld_bswap_Word		ld64_bswap_Word
682 #define	ld_bswap_Xword		ld64_bswap_Xword
683 #define	ld_cap_add_family	ld64_cap_add_family
684 #define	ld_cap_move_symtoobj	ld64_cap_move_symtoobj
685 #define	ld_comdat_validate	ld64_comdat_validate
686 #define	ld_disp_errmsg		ld64_disp_errmsg
687 #define	ld_ent_check		ld64_ent_check
688 #define	ld_ent_lookup		ld64_ent_lookup
689 #define	ld_eprintf		ld64_eprintf
690 #define	ld_exit			ld64_exit
691 #define	ld_find_library		ld64_find_library
692 #define	ld_finish_libs		ld64_finish_libs
693 #define	ld_get_group		ld64_get_group
694 #define	ld_group_process	ld64_group_process
695 #define	ld_lib_setup		ld64_lib_setup
696 #define	ld_init_sighandler	ld64_init_sighandler
697 #define	ld_lcm			ld64_lcm
698 #define	ld_make_bss		ld64_make_bss
699 #define	ld_make_data		ld64_make_data
700 #define	ld_make_got		ld64_make_got
701 #define	ld_make_parexpn_data	ld64_make_parexpn_data
702 #define	ld_make_sunwmove	ld64_make_sunmove
703 #define	ld_make_text		ld64_make_text
704 #define	ld_map_out		ld64_map_out
705 #define	ld_map_parse		ld64_map_parse
706 #define	ld_map_post_process	ld64_map_post_process
707 #define	ld_open_outfile		ld64_open_outfile
708 #define	ld_os_first_isdesc	ld64_os_first_isdesc
709 #define	ld_place_path_info_init	ld64_place_path_info_init
710 #define	ld_place_section	ld64_place_section
711 #define	ld_process_archive	ld64_process_archive
712 #define	ld_process_files	ld64_process_files
713 #define	ld_process_flags	ld64_process_flags
714 #define	ld_process_ifl		ld64_process_ifl
715 #define	ld_process_move		ld64_process_move
716 #define	ld_process_open		ld64_process_open
717 #define	ld_process_ordered	ld64_process_ordered
718 #define	ld_process_sym_reloc	ld64_process_sym_reloc
719 #define	ld_reloc_enter		ld64_reloc_enter
720 #define	ld_reloc_GOT_relative	ld64_reloc_GOT_relative
721 #define	ld_reloc_plt		ld64_reloc_plt
722 #define	ld_reloc_remain_entry	ld64_reloc_remain_entry
723 #define	ld_reloc_set_aux_osdesc	ld64_reloc_set_aux_osdesc
724 #define	ld_reloc_set_aux_usym	ld64_reloc_set_aux_usym
725 #define	ld_reloc_sym_name	ld64_reloc_sym_name
726 #define	ld_reloc_targval_get	ld64_reloc_targval_get
727 #define	ld_reloc_targval_set	ld64_reloc_targval_set
728 #define	ld_sec_validate		ld64_sec_validate
729 #define	ld_seg_lookup		ld64_seg_lookup
730 #define	ld_sort_ordered		ld64_sort_ordered
731 #define	ld_stt_section_sym_name	ld64_stt_section_sym_name
732 #define	ld_sunw_ldmach		ld64_sunw_ldmach
733 #define	ld_sup_atexit		ld64_sup_atexit
734 #define	ld_sup_open		ld64_sup_open
735 #define	ld_sup_file		ld64_sup_file
736 #define	ld_sup_loadso		ld64_sup_loadso
737 #define	ld_sup_input_done	ld64_sup_input_done
738 #define	ld_sup_input_section	ld64_sup_input_section
739 #define	ld_sup_section		ld64_sup_section
740 #define	ld_sup_start		ld64_sup_start
741 #define	ld_swap_reloc_data	ld64_swap_reloc_data
742 #define	ld_sym_add_u		ld64_sym_add_u
743 #define	ld_sym_adjust_vis	ld64_sym_adjust_vis
744 #define	ld_sym_avl_comp		ld64_sym_avl_comp
745 #define	ld_sym_copy		ld64_sym_copy
746 #define	ld_sym_enter		ld64_sym_enter
747 #define	ld_sym_find		ld64_sym_find
748 #define	ld_sym_nodirect		ld64_sym_nodirect
749 #define	ld_sym_process		ld64_sym_process
750 #define	ld_sym_resolve		ld64_sym_resolve
751 #define	ld_sym_reducable	ld64_sym_reducable
752 #define	ld_sym_spec		ld64_sym_spec
753 #define	ld_targ			ld64_targ
754 #define	ld_targ_init_sparc	ld64_targ_init_sparc
755 #define	ld_targ_init_x86	ld64_targ_init_x86
756 #define	ld_unwind_make_hdr	ld64_unwind_make_hdr
757 #define	ld_unwind_populate_hdr	ld64_unwind_populate_hdr
758 #define	ld_unwind_register	ld64_unwind_register
759 #define	ld_vers_base		ld64_vers_base
760 #define	ld_vers_check_defs	ld64_vers_check_defs
761 #define	ld_vers_check_need	ld64_vers_check_need
762 #define	ld_vers_def_process	ld64_vers_def_process
763 #define	ld_vers_desc		ld64_vers_desc
764 #define	ld_vers_find		ld64_vers_find
765 #define	ld_vers_need_process	ld64_vers_need_process
766 #define	ld_vers_promote		ld64_vers_promote
767 #define	ld_vers_sym_process	ld64_vers_sym_process
768 #define	ld_vers_verify		ld64_vers_verify
769 #define	ld_wrap_enter		ld64_wrap_enter
770 
771 #else
772 
773 #define	ld_add_actrel		ld32_add_actrel
774 #define	ld_add_libdir		ld32_add_libdir
775 #define	ld_adj_movereloc	ld32_adj_movereloc
776 #define	ld_am_I_partial		ld32_am_I_partial
777 #define	ld_ar_member		ld32_ar_member
778 #define	ld_ar_setup		ld32_ar_setup
779 #define	ld_assign_got_TLS	ld32_assign_got_TLS
780 #define	ld_bswap_Word		ld32_bswap_Word
781 #define	ld_bswap_Xword		ld32_bswap_Xword
782 #define	ld_cap_add_family	ld32_cap_add_family
783 #define	ld_cap_move_symtoobj	ld32_cap_move_symtoobj
784 #define	ld_comdat_validate	ld32_comdat_validate
785 #define	ld_disp_errmsg		ld32_disp_errmsg
786 #define	ld_ent_check		ld32_ent_check
787 #define	ld_ent_lookup		ld32_ent_lookup
788 #define	ld_eprintf		ld32_eprintf
789 #define	ld_exit			ld32_exit
790 #define	ld_find_library		ld32_find_library
791 #define	ld_finish_libs		ld32_finish_libs
792 #define	ld_get_group		ld32_get_group
793 #define	ld_group_process	ld32_group_process
794 #define	ld_lib_setup		ld32_lib_setup
795 #define	ld_init_sighandler	ld32_init_sighandler
796 #define	ld_lcm			ld32_lcm
797 #define	ld_make_bss		ld32_make_bss
798 #define	ld_make_data		ld32_make_data
799 #define	ld_make_got		ld32_make_got
800 #define	ld_make_parexpn_data	ld32_make_parexpn_data
801 #define	ld_make_sunwmove	ld32_make_sunmove
802 #define	ld_make_text		ld32_make_text
803 #define	ld_map_out		ld32_map_out
804 #define	ld_map_parse		ld32_map_parse
805 #define	ld_map_post_process	ld32_map_post_process
806 #define	ld_open_outfile		ld32_open_outfile
807 #define	ld_os_first_isdesc	ld32_os_first_isdesc
808 #define	ld_place_path_info_init	ld32_place_path_info_init
809 #define	ld_place_section	ld32_place_section
810 #define	ld_process_archive	ld32_process_archive
811 #define	ld_process_files	ld32_process_files
812 #define	ld_process_flags	ld32_process_flags
813 #define	ld_process_ifl		ld32_process_ifl
814 #define	ld_process_move		ld32_process_move
815 #define	ld_process_open		ld32_process_open
816 #define	ld_process_ordered	ld32_process_ordered
817 #define	ld_process_sym_reloc	ld32_process_sym_reloc
818 #define	ld_reloc_enter		ld32_reloc_enter
819 #define	ld_reloc_GOT_relative	ld32_reloc_GOT_relative
820 #define	ld_reloc_plt		ld32_reloc_plt
821 #define	ld_reloc_remain_entry	ld32_reloc_remain_entry
822 #define	ld_reloc_set_aux_osdesc	ld32_reloc_set_aux_osdesc
823 #define	ld_reloc_set_aux_usym	ld32_reloc_set_aux_usym
824 #define	ld_reloc_sym_name	ld32_reloc_sym_name
825 #define	ld_reloc_targval_get	ld32_reloc_targval_get
826 #define	ld_reloc_targval_set	ld32_reloc_targval_set
827 #define	ld_sec_validate		ld32_sec_validate
828 #define	ld_seg_lookup		ld32_seg_lookup
829 #define	ld_sort_ordered		ld32_sort_ordered
830 #define	ld_stt_section_sym_name	ld32_stt_section_sym_name
831 #define	ld_sunw_ldmach		ld32_sunw_ldmach
832 #define	ld_sup_atexit		ld32_sup_atexit
833 #define	ld_sup_open		ld32_sup_open
834 #define	ld_sup_file		ld32_sup_file
835 #define	ld_sup_loadso		ld32_sup_loadso
836 #define	ld_sup_input_done	ld32_sup_input_done
837 #define	ld_sup_input_section	ld32_sup_input_section
838 #define	ld_sup_section		ld32_sup_section
839 #define	ld_sup_start		ld32_sup_start
840 #define	ld_swap_reloc_data	ld32_swap_reloc_data
841 #define	ld_sym_add_u		ld32_sym_add_u
842 #define	ld_sym_adjust_vis	ld32_sym_adjust_vis
843 #define	ld_sym_avl_comp		ld32_sym_avl_comp
844 #define	ld_sym_copy		ld32_sym_copy
845 #define	ld_sym_enter		ld32_sym_enter
846 #define	ld_sym_find		ld32_sym_find
847 #define	ld_sym_nodirect		ld32_sym_nodirect
848 #define	ld_sym_process		ld32_sym_process
849 #define	ld_sym_resolve		ld32_sym_resolve
850 #define	ld_sym_reducable	ld32_sym_reducable
851 #define	ld_sym_spec		ld32_sym_spec
852 #define	ld_targ			ld32_targ
853 #define	ld_targ_init_sparc	ld32_targ_init_sparc
854 #define	ld_targ_init_x86	ld32_targ_init_x86
855 #define	ld_unwind_make_hdr	ld32_unwind_make_hdr
856 #define	ld_unwind_populate_hdr	ld32_unwind_populate_hdr
857 #define	ld_unwind_register	ld32_unwind_register
858 #define	ld_vers_base		ld32_vers_base
859 #define	ld_vers_check_defs	ld32_vers_check_defs
860 #define	ld_vers_check_need	ld32_vers_check_need
861 #define	ld_vers_def_process	ld32_vers_def_process
862 #define	ld_vers_desc		ld32_vers_desc
863 #define	ld_vers_find		ld32_vers_find
864 #define	ld_vers_need_process	ld32_vers_need_process
865 #define	ld_vers_promote		ld32_vers_promote
866 #define	ld_vers_sym_process	ld32_vers_sym_process
867 #define	ld_vers_verify		ld32_vers_verify
868 #define	ld_wrap_enter		ld32_wrap_enter
869 
870 #endif
871 
872 extern void		dbg_cleanup(void);
873 extern int		dbg_setup(Ofl_desc *, const char *, int);
874 
875 extern uintptr_t	ld_add_actrel(Word, Rel_desc *, Ofl_desc *);
876 extern uintptr_t	ld_add_libdir(Ofl_desc *, const char *);
877 extern void		ld_adj_movereloc(Ofl_desc *, Rel_desc *);
878 extern Sym_desc *	ld_am_I_partial(Rel_desc *, Xword);
879 extern void		ld_ar_member(Ar_desc *, Elf_Arsym *, Ar_aux *,
880 			    Ar_mem *);
881 extern Ar_desc		*ld_ar_setup(const char *, Elf *, Ofl_desc *);
882 extern uintptr_t	ld_assign_got_TLS(Boolean, Rel_desc *, Ofl_desc *,
883 			    Sym_desc *, Gotndx *, Gotref, Word, Word,
884 			    Word, Word);
885 
886 extern Word		ld_bswap_Word(Word);
887 extern Xword		ld_bswap_Xword(Xword);
888 
889 extern uintptr_t	ld_cap_add_family(Ofl_desc *, Sym_desc *, Sym_desc *,
890 			    Cap_group *, APlist **);
891 extern void		ld_cap_move_symtoobj(Ofl_desc *);
892 
893 extern void		ld_comdat_validate(Ofl_desc *, Ifl_desc *);
894 
895 extern void		ld_disp_errmsg(const char *, Rel_desc *, Ofl_desc *);
896 
897 extern void		ld_ent_check(Ofl_desc *);
898 extern Ent_desc		*ld_ent_lookup(Ofl_desc *, const char *name,
899 			    avl_index_t *where);
900 extern void		ld_eprintf(Ofl_desc *, Error, const char *, ...);
901 extern int		ld_exit(Ofl_desc *);
902 
903 extern uintptr_t	ld_find_library(const char *, Ofl_desc *);
904 extern uintptr_t	ld_finish_libs(Ofl_desc *);
905 
906 extern const char	*ld_stt_section_sym_name(Is_desc *);
907 
908 extern Group_desc	*ld_get_group(Ofl_desc *, Is_desc *);
909 extern uintptr_t	ld_group_process(Is_desc *, Ofl_desc *);
910 
911 extern uintptr_t	ld_lib_setup(Ofl_desc *);
912 
913 extern void		ld_init_sighandler(Ofl_desc *);
914 
915 extern Xword		ld_lcm(Xword, Xword);
916 
917 extern uintptr_t	ld_make_bss(Ofl_desc *, Xword, Xword, uint_t);
918 extern Is_desc		*ld_make_data(Ofl_desc *, size_t);
919 extern uintptr_t	ld_make_got(Ofl_desc *);
920 extern uintptr_t	ld_make_parexpn_data(Ofl_desc *, size_t, Xword);
921 extern uintptr_t	ld_make_sunwmove(Ofl_desc *, int);
922 extern Is_desc		*ld_make_text(Ofl_desc *, size_t);
923 extern void		ld_map_out(Ofl_desc *);
924 extern Boolean		ld_map_parse(const char *, Ofl_desc *);
925 extern Boolean		ld_map_post_process(Ofl_desc *);
926 
927 extern uintptr_t	ld_open_outfile(Ofl_desc *);
928 
929 extern Is_desc		*ld_os_first_isdesc(Os_desc *);
930 extern Place_path_info	*ld_place_path_info_init(Ofl_desc *, Ifl_desc *,
931 			    Place_path_info *);
932 extern Os_desc		*ld_place_section(Ofl_desc *, Is_desc *,
933 			    Place_path_info *path_info,  int, const char *);
934 extern Boolean		ld_process_archive(const char *, int, Ar_desc *,
935 			    Ofl_desc *);
936 extern uintptr_t	ld_process_files(Ofl_desc *, int, char **);
937 extern uintptr_t	ld_process_flags(Ofl_desc *, int, char **);
938 extern uintptr_t	ld_process_ifl(const char *, const char *, int, Elf *,
939 			    Word, Ofl_desc *, Rej_desc *, Ifl_desc **);
940 extern uintptr_t	ld_process_move(Ofl_desc *);
941 extern uintptr_t	ld_process_open(const char *, const char *, int *,
942 			    Ofl_desc *, Word, Rej_desc *, Ifl_desc **);
943 extern uintptr_t	ld_process_ordered(Ofl_desc *, Ifl_desc *,
944 			    Place_path_info *path_info,  Word);
945 extern uintptr_t	ld_process_sym_reloc(Ofl_desc *, Rel_desc *, Rel *,
946 			    Is_desc *, const char *, Word);
947 
948 extern Rel_desc		*ld_reloc_enter(Ofl_desc *, Rel_cache *, Rel_desc *,
949 			    Word);
950 extern uintptr_t	ld_reloc_GOT_relative(Boolean, Rel_desc *, Ofl_desc *);
951 extern uintptr_t	ld_reloc_plt(Rel_desc *, Ofl_desc *);
952 extern void		ld_reloc_remain_entry(Rel_desc *, Os_desc *,
953 			    Ofl_desc *, Boolean *);
954 extern Boolean		ld_reloc_set_aux_osdesc(Ofl_desc *, Rel_desc *,
955 			    Os_desc *);
956 extern Boolean		ld_reloc_set_aux_usym(Ofl_desc *, Rel_desc *,
957 			    Sym_desc *);
958 
959 extern const char	*ld_reloc_sym_name(Rel_desc *);
960 extern int		ld_reloc_targval_get(Ofl_desc *, Rel_desc *,
961 			    uchar_t *, Xword *);
962 extern int		ld_reloc_targval_set(Ofl_desc *, Rel_desc *,
963 			    uchar_t *, Xword);
964 
965 extern Sg_desc		*ld_seg_lookup(Ofl_desc *, const char *,
966 			    avl_index_t *where);
967 extern void		ld_sec_validate(Ofl_desc *);
968 extern uintptr_t	ld_sort_ordered(Ofl_desc *);
969 extern Half		ld_sunw_ldmach();
970 extern void		ld_sup_atexit(Ofl_desc *, int);
971 extern void		ld_sup_open(Ofl_desc *, const char **, const char **,
972 			    int *, int, Elf **, Elf *ref, size_t,
973 			    const Elf_Kind);
974 extern void		ld_sup_file(Ofl_desc *, const char *, const Elf_Kind,
975 			    int flags, Elf *);
976 extern uintptr_t	ld_sup_loadso(Ofl_desc *, const char *);
977 extern void		ld_sup_input_done(Ofl_desc *);
978 extern void		ld_sup_section(Ofl_desc *, const char *, Shdr *, Word,
979 			    Elf_Data *, Elf *);
980 extern uintptr_t	ld_sup_input_section(Ofl_desc*, Ifl_desc *,
981 			    const char *, Shdr **, Word, Elf_Scn *, Elf *);
982 extern void		ld_sup_start(Ofl_desc *, const Half, const char *);
983 extern int		ld_swap_reloc_data(Ofl_desc *, Rel_desc *);
984 extern Sym_desc		*ld_sym_add_u(const char *, Ofl_desc *, Msg);
985 extern void		ld_sym_adjust_vis(Sym_desc *, Ofl_desc *);
986 extern int		ld_sym_avl_comp(const void *, const void *);
987 extern uintptr_t	ld_sym_copy(Sym_desc *);
988 extern Sym_desc		*ld_sym_enter(const char *, Sym *, Word, Ifl_desc *,
989 			    Ofl_desc *, Word, Word, sd_flag_t, avl_index_t *);
990 extern Sym_desc		*ld_sym_find(const char *, Word, avl_index_t *,
991 			    Ofl_desc *);
992 extern uintptr_t	ld_sym_nodirect(Is_desc *, Ifl_desc *, Ofl_desc *);
993 extern uintptr_t	ld_sym_process(Is_desc *, Ifl_desc *, Ofl_desc *);
994 extern uintptr_t	ld_sym_resolve(Sym_desc *, Sym *, Ifl_desc *,
995 			    Ofl_desc *, int, Word, sd_flag_t);
996 extern Boolean		ld_sym_reducable(Ofl_desc *, Sym_desc *);
997 extern uintptr_t	ld_sym_spec(Ofl_desc *);
998 
999 extern Target		ld_targ;
1000 extern const Target	*ld_targ_init_sparc(void);
1001 extern const Target	*ld_targ_init_x86(void);
1002 
1003 extern uintptr_t	ld_unwind_make_hdr(Ofl_desc *);
1004 extern uintptr_t	ld_unwind_populate_hdr(Ofl_desc *);
1005 extern uintptr_t	ld_unwind_register(Os_desc *, Ofl_desc *);
1006 
1007 extern Ver_desc		*ld_vers_base(Ofl_desc *);
1008 extern uintptr_t	ld_vers_check_defs(Ofl_desc *);
1009 extern uintptr_t	ld_vers_check_need(Ofl_desc *);
1010 extern uintptr_t	ld_vers_def_process(Is_desc *, Ifl_desc *, Ofl_desc *);
1011 extern Ver_desc		*ld_vers_desc(const char *, Word, APlist **);
1012 extern Ver_desc		*ld_vers_find(const char *, Word, APlist *);
1013 extern uintptr_t	ld_vers_need_process(Is_desc *, Ifl_desc *, Ofl_desc *);
1014 extern void		ld_vers_promote(Sym_desc *, Word, Ifl_desc *,
1015 			    Ofl_desc *);
1016 extern int		ld_vers_sym_process(Ofl_desc *, Is_desc *, Ifl_desc *);
1017 extern int		ld_vers_verify(Ofl_desc *);
1018 extern WrapSymNode	*ld_wrap_enter(Ofl_desc *, const char *);
1019 
1020 extern uintptr_t	add_regsym(Sym_desc *, Ofl_desc *);
1021 extern Word		hashbkts(Word);
1022 extern Xword		lcm(Xword, Xword);
1023 
1024 /*
1025  * Most platforms have both a 32 and 64-bit variant (e.g. EM_SPARC and
1026  * EM_SPARCV9). To support this, there many files in libld that are built
1027  * twice, once for ELFCLASS64 (_ELF64), and once for ELFCLASS32. In these
1028  * files, we sometimes want to supply one value for the ELFCLASS32 case
1029  * and another for ELFCLASS64. The LD_TARG_BYCLASS macro is used to do
1030  * this. It is called with both both alternatives, and yields the one
1031  * that applies to the current compilation environment.
1032  */
1033 #ifdef	_ELF64
1034 #define	LD_TARG_BYCLASS(_ec32, _ec64) (_ec64)
1035 #else
1036 #define	LD_TARG_BYCLASS(_ec32, _ec64) (_ec32)
1037 #endif
1038 
1039 
1040 #ifdef	__cplusplus
1041 }
1042 #endif
1043 
1044 #endif /* _LIBLD_DOT_H */
1045