xref: /illumos-gate/usr/src/cmd/sgs/libld/common/_libld.h (revision 86c48bbfeb72d5a6ee171e713059939bab658b77)
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 	Word		m_dt_register;
102 } Target_mach;
103 
104 
105 /*
106  * Section identifiers, used to order sections in output object
107  */
108 typedef struct {
109 	Word		id_array;
110 	Word		id_bss;
111 	Word		id_cap;
112 	Word		id_data;
113 	Word		id_dynamic;
114 	Word		id_dynsort;
115 	Word		id_dynstr;
116 	Word		id_dynsym;
117 	Word		id_dynsym_ndx;
118 	Word		id_got;
119 	Word		id_gotdata;
120 	Word		id_hash;
121 	Word		id_interp;
122 	Word		id_lbss;
123 	Word		id_ldynsym;
124 	Word		id_note;
125 	Word		id_null;
126 	Word		id_plt;
127 	Word		id_rel;
128 	Word		id_strtab;
129 	Word		id_syminfo;
130 	Word		id_symtab;
131 	Word		id_symtab_ndx;
132 	Word		id_text;
133 	Word		id_tls;
134 	Word		id_tlsbss;
135 	Word		id_unknown;
136 	Word		id_unwind;
137 	Word		id_user;
138 	Word		id_version;
139 } Target_machid;
140 
141 /*
142  * Target_nullfunc supplies machine code for generating a
143  *
144  *	void (*)(void)
145  *
146  * unnamed function. Such a function can be called, and returns
147  * immediately without doing any work. This is used to back FUNC
148  * symbol definitions added with a mapfile.
149  *
150  * The machine instructions are specified as an array of bytes rather
151  * than a larger integer type in order to avoid byte order issues that
152  * can otherwise occur in cross linking.
153  */
154 typedef struct {
155 	const uchar_t	*nf_template;	/* Array of machine inst. bytes */
156 	size_t		nf_size;	/* # bytes in nf_template */
157 } Target_nullfunc;
158 
159 /*
160  * Target_machrel holds pointers to the reloc_table and machrel functions
161  * for a given target machine.
162  *
163  * The following function pointers are allowed to be NULL, if the
164  * underlying target does not require the specified operation. All
165  * other functions must be supplied:
166  *
167  *	mr_assign_got
168  *	mr_reloc_register
169  *	mr_reloc_GOTOP
170  *	mr_allocate_got
171  */
172 typedef struct {
173 	const Rel_entry	*mr_reloc_table;
174 
175 	Word		(* mr_init_rel)(Rel_desc *, void *);
176 	void 		(* mr_mach_eflags)(Ehdr *, Ofl_desc *);
177 	void		(* mr_mach_make_dynamic)(Ofl_desc *, size_t *);
178 	void		(* mr_mach_update_odynamic)(Ofl_desc *, Dyn **);
179 	Xword		(* mr_calc_plt_addr)(Sym_desc *, Ofl_desc *);
180 	uintptr_t	(* mr_perform_outreloc)(Rel_desc *, Ofl_desc *);
181 	uintptr_t	(* mr_do_activerelocs)(Ofl_desc *);
182 	uintptr_t	(* mr_add_outrel)(Word, Rel_desc *, Ofl_desc *);
183 	uintptr_t	(* mr_reloc_register)(Rel_desc *, Is_desc *,
184 			    Ofl_desc *);
185 	uintptr_t	(* mr_reloc_local)(Rel_desc *, Ofl_desc *);
186 	uintptr_t	(* mr_reloc_GOTOP)(Boolean, Rel_desc *, Ofl_desc *);
187 	uintptr_t	(* mr_reloc_TLS)(Boolean, Rel_desc *, Ofl_desc *);
188 	uintptr_t	(* mr_assign_got)(Ofl_desc *, Sym_desc *);
189 
190 	Gotndx		*(* mr_find_gotndx)(List *, Gotref, Ofl_desc *,
191 			    Rel_desc *);
192 	Xword		(* mr_calc_got_offset)(Rel_desc *, Ofl_desc *);
193 	uintptr_t	(* mr_assign_got_ndx)(List *, Gotndx *, Gotref,
194 			    Ofl_desc *, Rel_desc *, Sym_desc *);
195 	void		(* mr_assign_plt_ndx)(Sym_desc *, Ofl_desc *);
196 	uintptr_t	(* mr_allocate_got)(Ofl_desc *);
197 	uintptr_t	(* mr_fillin_gotplt)(Ofl_desc *);
198 } Target_machrel;
199 
200 
201 /*
202  * Target_machsym holds pointers to the machsym functions
203  * for a given target machine.
204  *
205  * These fields are allowed to be NULL for targets that do not require
206  * special handling of register symbols. Register symbols are used by
207  * sparc targets. If any of these fields are non-NULL, all of them are
208  * required to be present (use empty stub routines if necessary).
209  */
210 typedef struct {
211 	int		(* ms_reg_check)(Sym_desc *, Sym *, const char *,
212 			    Ifl_desc *, Ofl_desc *);
213 	int		(* ms_mach_sym_typecheck)(Sym_desc *, Sym *,
214 			    Ifl_desc *, Ofl_desc *);
215 	const char	*(* ms_is_regsym)(Ofl_desc *, Ifl_desc *, Sym *,
216 			    const char *, int, Word, const char *, Word *);
217 	Sym_desc	*(* ms_reg_find)(Sym * sym, Ofl_desc * ofl);
218 	int		(* ms_reg_enter)(Sym_desc *, Ofl_desc *);
219 } Target_machsym;
220 
221 /*
222  * amd64 unwind header support
223  *
224  * These fields are allowed to be NULL for targets that do not support
225  * amd64 unwind headers. If any of these fields are non-NULL, all of them are
226  * required to be present (use empty stub routines if necessary).
227  */
228 typedef struct {
229 	uintptr_t	(* uw_make_unwindhdr)(Ofl_desc *);
230 	uintptr_t	(* uw_populate_unwindhdr)(Ofl_desc *);
231 	uintptr_t	(* uw_append_unwind)(Os_desc *, Ofl_desc *);
232 } Target_unwind;
233 
234 typedef struct {
235 	Target_mach	t_m;
236 	Target_machid	t_id;
237 	Target_nullfunc	t_nf;
238 	Target_machrel	t_mr;
239 	Target_machsym	t_ms;
240 	Target_unwind	t_uw;
241 } Target;
242 
243 
244 /*
245  * Types of bss sections
246  */
247 typedef enum {
248 	MAKE_BSS,
249 	MAKE_LBSS,
250 	MAKE_TLS
251 } Bss_Type;
252 
253 /*
254  * Structure to manage the update of weak symbols from their associated alias.
255  */
256 typedef	struct wk_desc {
257 	Sym		*wk_symtab;	/* the .symtab entry */
258 	Sym		*wk_dynsym;	/* the .dynsym entry */
259 	Sym_desc	*wk_weak;	/* the original weak symbol */
260 	Sym_desc	*wk_alias;	/* the real symbol */
261 } Wk_desc;
262 
263 /*
264  * Structure to manage the support library interfaces.
265  */
266 typedef struct func_list {
267 	const char	*fl_obj;	/* name of support object */
268 					/*	function is from */
269 	void		(*fl_fptr)();	/* function pointer */
270 	uint_t		fl_version;	/* ld_version() level */
271 } Func_list;
272 
273 typedef	struct support_list {
274 	const char	*sup_name;	/* ld_support function name */
275 	List		sup_funcs;	/* list of support functions */
276 } Support_list;
277 
278 /*
279  * Structure to manage a sorted output relocation list.
280  *
281  *	rl_key1		->	pointer to needed ndx
282  *	rl_key2		->	pointer to symbol relocation is against
283  *	rl_key3		->	virtual offset of relocation
284  */
285 typedef struct reloc_list {
286 	Sym_desc	*rl_key2;
287 	Xword		rl_key3;
288 	Rel_desc	*rl_rsp;
289 	Half		rl_key1;
290 } Reloc_list;
291 
292 
293 typedef struct sym_s_list {
294 	Word		sl_hval;
295 	Sym_desc	*sl_sdp;
296 } Sym_s_list;
297 
298 /*
299  * ld heap management structure
300  */
301 typedef struct _ld_heap Ld_heap;
302 struct _ld_heap {
303 	Ld_heap		*lh_next;
304 	void		*lh_free;
305 	void		*lh_end;
306 };
307 
308 #define	HEAPBLOCK	0x800000	/* default allocation block size */
309 #define	HEAPALIGN	0x8		/* heap blocks alignment requirement */
310 
311 /*
312  * Dynamic per-symbol filtee string table descriptor.  This associates filtee
313  * strings that will be created in the .dynstr, with .dynamic entries.
314  */
315 typedef struct {
316 	char		*dft_str;	/* dynstr string */
317 	Word		dft_flag;	/* auxiliary/filtee type */
318 	Half		dft_ndx;	/* eventual ndx into .dynamic */
319 } Dfltr_desc;
320 
321 /*
322  * Per-symbol filtee descriptor.  This associates symbol definitions with
323  * their filtees.
324  */
325 typedef struct {
326 	Sym_desc	*sft_sdp;	/* symbol descriptor */
327 	Aliste		sft_idx;	/* index into dtstr descriptor */
328 } Sfltr_desc;
329 
330 /*
331  * Define Alist initialization sizes.
332  */
333 #define	AL_CNT_IFL_GROUPS	20	/* ifl_groups initial alist count */
334 #define	AL_CNT_OFL_DTSFLTRS	4	/* ofl_dtsfltrs initial alist count */
335 #define	AL_CNT_OFL_SYMFLTRS	20	/* ofl_symfltrs initial alist count */
336 #define	AL_CNT_OS_MSTRISDESCS	10	/* os_mstrisdescs */
337 #define	AL_CNT_OS_RELISDESCS	100	/* os_relisdescs */
338 #define	AL_CNT_OS_COMDATS	20	/* os_comdats */
339 #define	AL_CNT_SG_OSDESC	40	/* sg_osdescs initial alist count */
340 #define	AL_CNT_SG_SECORDER	40	/* sg_secorder initial alist count */
341 #define	AL_CNT_STRMRGREL	500	/* ld_make_strmerge() reloc alist cnt */
342 #define	AL_CNT_STRMRGSYM	20	/* ld_make_strmerge() sym alist cnt */
343 
344 /*
345  * Return codes for {tls|got}_fixups() routines
346  */
347 typedef enum {
348 	FIX_ERROR,	/* fatal error - time to punt */
349 	FIX_DONE,	/* relocation done - no further processing required */
350 	FIX_RELOC	/* do_reloc() relocation processing required */
351 } Fixupret;
352 
353 #ifndef	FILENAME_MAX
354 #define	FILENAME_MAX	BUFSIZ		/* maximum length of a path name */
355 #endif
356 
357 /*
358  * We pad the end of the .dynstr section with a block of DYNSTR_EXTRA_PAD
359  * bytes, and we insert DYNAMIC_EXTRA_ELTS unused items into the
360  * .dynamic section (with value DT_NULL). This provides the resources needed
361  * to add and/or alter string items in the .dynamic section, such as runpath.
362  */
363 #define	DYNSTR_EXTRA_PAD	512
364 #define	DYNAMIC_EXTRA_ELTS	10
365 
366 /*
367  * Relocation buckets are sized based on the number of input relocations and
368  * the following constants.
369  */
370 #define	REL_HAIDESCNO	1000		/* high water mark active buckets */
371 #define	REL_LAIDESCNO	50		/* low water mark active buckets */
372 #define	REL_HOIDESCNO	500		/* high water mark output buckets */
373 #define	REL_LOIDESCNO	10		/* low water mark output buckets */
374 
375 extern char		*Plibpath;
376 extern char		*Llibdir;
377 extern char		*Ulibdir;
378 extern Ld_heap		*ld_heap;
379 extern List		lib_support;
380 extern int		demangle_flag;
381 extern const Msg	reject[];
382 extern int		Verbose;
383 extern const int	ldynsym_symtype[];
384 extern const int	dynsymsort_symtype[];
385 
386 
387 /*
388  * Given a symbol of a type that is allowed within a .SUNW_dynsymsort or
389  * .SUNW_dyntlssort section, examine the symbol attributes to determine
390  * if this particular symbol should be included or not.
391  *
392  * entry:
393  *	The symbol must have an allowed type: Either a type verified by
394  *	dynsymsort_symtype[] or STT_TLS.
395  *
396  *	_sdp - Pointer to symbol descriptor
397  *	_sym - Pointer to symbol referenced by _sdp.
398  *
399  *	_sym is derivable from _sdp: _sdp->sd_sym
400  *	However, most callers assign it to a local variable for efficiency,
401  *	and this macro allows such a variable to be used within. If you
402  *	don't have such a variable, supply _sdp->sd_sym.
403  *
404  * The tests used require some explanation:
405  *
406  *	(_sdp->sd_flags & FLG_SY_DYNSORT)
407  *		Some special symbols are kept even if they don't meet the
408  *		usual requirements. These symbols have the FLG_SY_DYNSORT
409  *		bit set. If this bit isn't set then we look at the other
410  *		attributes.
411  *
412  *	(((_sdp->sd_ref != REF_DYN_NEED) &&
413  *		(_sdp->sd_sym->st_shndx != SHN_UNDEF))
414  *	|| (_sdp->sd_flags & FLG_SY_MVTOCOMM))
415  *		We do not want to include symbols that are not defined within
416  *		the object we are creating. REF_DYN_NEED corresponds to those
417  *		UNDEF items. However, if the symbol is the target of a copy
418  *		relocation, then it effectively becomes defined within the
419  *		object after all. FLG_SY_MVTOCOMM indicates a copy relocation,
420  *		and prevents us from culling those exceptions.
421  *
422  *	(_sym->st_size != 0)
423  *		Symbols with 0 length are labels injected by the compilers
424  *		or the linker for purposes of code generation, and do
425  *		not directly correspond to actual code. In fact, most of the
426  *		symbols we mark with FLG_SY_DYNSORT need that flag set because
427  *		they have size 0. This size test filters out the others.
428  *
429  *	!(_sdp->sd_flags & FLG_SY_NODYNSORT)
430  *		Some symbols are not kept, even though they do meet the usual
431  *		requirements. These symbols have FLG_SY_NODYNSORT set.
432  *		For example, if there are weak and non-weak versions of a given
433  *		symbol, we only want to keep one of them. So, we set
434  *		FLG_SY_NODYNSORT on the one we don't want.
435  */
436 #define	DYNSORT_TEST_ATTR(_sdp, _sym) \
437 	((_sdp->sd_flags & FLG_SY_DYNSORT) || \
438 	((((_sdp->sd_ref != REF_DYN_NEED) && \
439 		(_sdp->sd_sym->st_shndx != SHN_UNDEF)) || \
440 		(_sdp->sd_flags & FLG_SY_MVTOCOMM)) && \
441 	(_sym->st_size != 0) && \
442 	!(_sdp->sd_flags & FLG_SY_NODYNSORT)))
443 
444 /*
445  * We use output section descriptor counters to add up the number of
446  * symbol indexes to put in the .SUNW_dynsort and .SUNW_dyntlssort sections.
447  * Non-TLS symbols are counted by ofl->ofl_dynsymsortcnt, while TLS symbols are
448  * counted by ofl->ofl_dyntlssortcnt. This computation is done inline in
449  * several places. The DYNSORT_COUNT macro allows us to generate this from
450  * a single description.
451  *
452  * entry:
453  *	_sdp, _sym - As per DYNSORT_TEST_ATTR
454  *	_type - Type of symbol (STT_*)
455  *	_inc_or_dec_op - Either ++, or --. This specifies the operation
456  *		to be applied to the counter, and determines whether we
457  *		are adding, or removing, a symbol from .SUNW_dynsymsort.
458  *
459  * Note that _type is derivable from _sym: ELF_ST_TYPE(_sdp->sd_sym->st_info).
460  * Most callers already have it in a variable, so this allows us to use that
461  * variable. If you don't have such a variable, use ELF_ST_TYPE() as shown.
462  */
463 #define	DYNSORT_COUNT(_sdp, _sym, _type, _inc_or_dec_op) \
464 { \
465 	Word *_cnt_var; \
466 	\
467 	if (dynsymsort_symtype[_type]) {	/* Non-TLS counter */ \
468 		_cnt_var = &ofl->ofl_dynsymsortcnt; \
469 	} else if ((_type) == STT_TLS) {	/* TLS counter */ \
470 		_cnt_var = &ofl->ofl_dyntlssortcnt; \
471 	} else {				/* Don't count this symbol */ \
472 		_cnt_var = NULL; \
473 	} \
474 	if ((_cnt_var != NULL) && DYNSORT_TEST_ATTR(_sdp, _sym)) \
475 		(*_cnt_var)_inc_or_dec_op;	/* Increment/Decrement */ \
476 }
477 
478 /*
479  * The OFL_SWAP_RELOC macros are used to determine whether
480  * relocation processing needs to swap the data being relocated.
481  * It is an optimization to ld_swap_reloc_data(), as it avoids
482  * the function call in the case where the linker host and the
483  * target have the same byte order.
484  */
485 #define	OFL_SWAP_RELOC_DATA(_ofl, _rel) \
486 	(((_ofl)->ofl_flags1 & FLG_OF1_ENCDIFF) && \
487 	ld_swap_reloc_data(_ofl, _rel))
488 
489 /*
490  * Define an AVL node for maintaining input section descriptors.  AVL trees of
491  * these descriptors are used to process group and COMDAT section.
492  */
493 typedef struct {
494 	avl_node_t	isd_avl;	/* avl book-keeping (see SGSOFFSETOF) */
495 	Is_desc		*isd_isp;	/* input section descriptor */
496 	uint_t		isd_hash;	/* input section name hash value */
497 } Isd_node;
498 
499 /*
500  * Local functions.
501  */
502 extern char		*add_string(char *, char *);
503 extern const char	*demangle(const char *);
504 
505 extern void		lds_atexit(Ofl_desc *, int);
506 
507 extern void		libld_free(void *);
508 extern void		*libld_malloc(size_t);
509 extern void		*libld_realloc(void *, size_t);
510 
511 extern Listnode		*list_appendc(List *, const void *);
512 extern Listnode		*list_insertc(List *, const void *, Listnode *);
513 extern Listnode		*list_prependc(List *, const void *);
514 extern Listnode		*list_where(List *, Word num);
515 
516 extern int		isdavl_compare(const void *, const void *);
517 
518 extern Sdf_desc		*sdf_add(const char *, List *);
519 extern Sdf_desc		*sdf_find(const char *, List *);
520 
521 #if	defined(_ELF64)
522 
523 #define	ld_add_actrel		ld64_add_actrel
524 #define	ld_add_libdir		ld64_add_libdir
525 #define	ld_adj_movereloc	ld64_adj_movereloc
526 #define	ld_am_I_partial		ld64_am_I_partial
527 #define	ld_append_isp		ld64_append_isp
528 #define	ld_ar_member		ld64_ar_member
529 #define	ld_ar_setup		ld64_ar_setup
530 #define	ld_assign_got_TLS	ld64_assign_got_TLS
531 #define	ld_bswap_Word		ld64_bswap_Word
532 #define	ld_bswap_Xword		ld64_bswap_Xword
533 #define	ld_disp_errmsg		ld64_disp_errmsg
534 #define	ld_ent_check		ld64_ent_check
535 #define	ld_exit			ld64_exit
536 #define	ld_find_library		ld64_find_library
537 #define	ld_finish_libs		ld64_finish_libs
538 #define	ld_get_group		ld64_get_group
539 #define	ld_group_process	ld64_group_process
540 #define	ld_lib_setup		ld64_lib_setup
541 #define	ld_init			ld64_init
542 #define	ld_lcm			ld64_lcm
543 #define	ld_make_bss		ld64_make_bss
544 #define	ld_make_data		ld64_make_data
545 #define	ld_make_got		ld64_make_got
546 #define	ld_make_parexpn_data	ld64_make_parexpn_data
547 #define	ld_make_sunwmove	ld64_make_sunmove
548 #define	ld_make_text		ld64_make_text
549 #define	ld_map_out		ld64_map_out
550 #define	ld_map_parse		ld64_map_parse
551 #define	ld_open_outfile		ld64_open_outfile
552 #define	ld_place_section	ld64_place_section
553 #define	ld_process_archive	ld64_process_archive
554 #define	ld_process_files	ld64_process_files
555 #define	ld_process_flags	ld64_process_flags
556 #define	ld_process_ifl		ld64_process_ifl
557 #define	ld_process_open		ld64_process_open
558 #define	ld_process_ordered	ld64_process_ordered
559 #define	ld_process_sym_reloc	ld64_process_sym_reloc
560 #define	ld_reloc_GOT_relative	ld64_reloc_GOT_relative
561 #define	ld_reloc_plt		ld64_reloc_plt
562 #define	ld_reloc_remain_entry	ld64_reloc_remain_entry
563 #define	ld_reloc_targval_get	ld64_reloc_targval_get
564 #define	ld_reloc_targval_set	ld64_reloc_targval_set
565 #define	ld_sec_validate		ld64_sec_validate
566 #define	ld_section_reld_name	ld64_section_reld_name
567 #define	ld_sort_ordered		ld64_sort_ordered
568 #define	ld_sort_seg_list	ld64_sort_seg_list
569 #define	ld_sunw_ldmach		ld64_sunw_ldmach
570 #define	ld_sunwmove_preprocess	ld64_sunwmove_preprocess
571 #define	ld_sup_atexit		ld64_sup_atexit
572 #define	ld_sup_open		ld64_sup_open
573 #define	ld_sup_file		ld64_sup_file
574 #define	ld_sup_loadso		ld64_sup_loadso
575 #define	ld_sup_input_done	ld64_sup_input_done
576 #define	ld_sup_input_section	ld64_sup_input_section
577 #define	ld_sup_section		ld64_sup_section
578 #define	ld_sup_start		ld64_sup_start
579 #define	ld_swap_reloc_data	ld64_swap_reloc_data
580 #define	ld_sym_add_u		ld64_sym_add_u
581 #define	ld_sym_adjust_vis	ld64_sym_adjust_vis
582 #define	ld_sym_avl_comp		ld64_sym_avl_comp
583 #define	ld_sym_copy		ld64_sym_copy
584 #define	ld_sym_enter		ld64_sym_enter
585 #define	ld_sym_find		ld64_sym_find
586 #define	ld_sym_nodirect		ld64_sym_nodirect
587 #define	ld_sym_process		ld64_sym_process
588 #define	ld_sym_resolve		ld64_sym_resolve
589 #define	ld_sym_spec		ld64_sym_spec
590 #define	ld_targ			ld64_targ
591 #define	ld_targ_init_sparc	ld64_targ_init_sparc
592 #define	ld_targ_init_x86	ld64_targ_init_x86
593 #define	ld_vers_base		ld64_vers_base
594 #define	ld_vers_check_defs	ld64_vers_check_defs
595 #define	ld_vers_check_need	ld64_vers_check_need
596 #define	ld_vers_def_process	ld64_vers_def_process
597 #define	ld_vers_desc		ld64_vers_desc
598 #define	ld_vers_find		ld64_vers_find
599 #define	ld_vers_need_process	ld64_vers_need_process
600 #define	ld_vers_promote		ld64_vers_promote
601 #define	ld_vers_sym_process	ld64_vers_sym_process
602 #define	ld_vers_verify		ld64_vers_verify
603 
604 #else
605 
606 #define	ld_add_actrel		ld32_add_actrel
607 #define	ld_add_libdir		ld32_add_libdir
608 #define	ld_adj_movereloc	ld32_adj_movereloc
609 #define	ld_am_I_partial		ld32_am_I_partial
610 #define	ld_append_isp		ld32_append_isp
611 #define	ld_ar_member		ld32_ar_member
612 #define	ld_ar_setup		ld32_ar_setup
613 #define	ld_assign_got_TLS	ld32_assign_got_TLS
614 #define	ld_bswap_Word		ld32_bswap_Word
615 #define	ld_bswap_Xword		ld32_bswap_Xword
616 #define	ld_disp_errmsg		ld32_disp_errmsg
617 #define	ld_ent_check		ld32_ent_check
618 #define	ld_exit			ld32_exit
619 #define	ld_find_library		ld32_find_library
620 #define	ld_finish_libs		ld32_finish_libs
621 #define	ld_section_reld_name	ld32_section_reld_name
622 #define	ld_get_group		ld32_get_group
623 #define	ld_group_process	ld32_group_process
624 #define	ld_lib_setup		ld32_lib_setup
625 #define	ld_init			ld32_init
626 #define	ld_lcm			ld32_lcm
627 #define	ld_make_bss		ld32_make_bss
628 #define	ld_make_data		ld32_make_data
629 #define	ld_make_got		ld32_make_got
630 #define	ld_make_parexpn_data	ld32_make_parexpn_data
631 #define	ld_make_sunwmove	ld32_make_sunmove
632 #define	ld_make_text		ld32_make_text
633 #define	ld_map_out		ld32_map_out
634 #define	ld_map_parse		ld32_map_parse
635 #define	ld_open_outfile		ld32_open_outfile
636 #define	ld_place_section	ld32_place_section
637 #define	ld_process_archive	ld32_process_archive
638 #define	ld_process_files	ld32_process_files
639 #define	ld_process_flags	ld32_process_flags
640 #define	ld_process_ifl		ld32_process_ifl
641 #define	ld_process_open		ld32_process_open
642 #define	ld_process_ordered	ld32_process_ordered
643 #define	ld_process_sym_reloc	ld32_process_sym_reloc
644 #define	ld_reloc_GOT_relative	ld32_reloc_GOT_relative
645 #define	ld_reloc_plt		ld32_reloc_plt
646 #define	ld_reloc_remain_entry	ld32_reloc_remain_entry
647 #define	ld_reloc_targval_get	ld32_reloc_targval_get
648 #define	ld_reloc_targval_set	ld32_reloc_targval_set
649 #define	ld_sec_validate		ld32_sec_validate
650 #define	ld_sort_ordered		ld32_sort_ordered
651 #define	ld_sort_seg_list	ld32_sort_seg_list
652 #define	ld_sunw_ldmach		ld32_sunw_ldmach
653 #define	ld_sunwmove_preprocess	ld32_sunwmove_preprocess
654 #define	ld_sup_atexit		ld32_sup_atexit
655 #define	ld_sup_open		ld32_sup_open
656 #define	ld_sup_file		ld32_sup_file
657 #define	ld_sup_loadso		ld32_sup_loadso
658 #define	ld_sup_input_done	ld32_sup_input_done
659 #define	ld_sup_input_section	ld32_sup_input_section
660 #define	ld_sup_section		ld32_sup_section
661 #define	ld_sup_start		ld32_sup_start
662 #define	ld_swap_reloc_data	ld32_swap_reloc_data
663 #define	ld_sym_add_u		ld32_sym_add_u
664 #define	ld_sym_adjust_vis	ld32_sym_adjust_vis
665 #define	ld_sym_avl_comp		ld32_sym_avl_comp
666 #define	ld_sym_copy		ld32_sym_copy
667 #define	ld_sym_enter		ld32_sym_enter
668 #define	ld_sym_find		ld32_sym_find
669 #define	ld_sym_nodirect		ld32_sym_nodirect
670 #define	ld_sym_process		ld32_sym_process
671 #define	ld_sym_resolve		ld32_sym_resolve
672 #define	ld_sym_spec		ld32_sym_spec
673 #define	ld_targ			ld32_targ
674 #define	ld_targ_init_sparc	ld32_targ_init_sparc
675 #define	ld_targ_init_x86	ld32_targ_init_x86
676 #define	ld_vers_base		ld32_vers_base
677 #define	ld_vers_check_defs	ld32_vers_check_defs
678 #define	ld_vers_check_need	ld32_vers_check_need
679 #define	ld_vers_def_process	ld32_vers_def_process
680 #define	ld_vers_desc		ld32_vers_desc
681 #define	ld_vers_find		ld32_vers_find
682 #define	ld_vers_need_process	ld32_vers_need_process
683 #define	ld_vers_promote		ld32_vers_promote
684 #define	ld_vers_sym_process	ld32_vers_sym_process
685 #define	ld_vers_verify		ld32_vers_verify
686 
687 #endif
688 
689 extern uintptr_t	dbg_setup(const char *, Dbg_desc *, const char **, int);
690 
691 extern uintptr_t	ld_add_actrel(Word, Rel_desc *, Ofl_desc *);
692 extern uintptr_t	ld_add_libdir(Ofl_desc *, const char *);
693 extern void 		ld_adj_movereloc(Ofl_desc *, Rel_desc *);
694 extern Sym_desc * 	ld_am_I_partial(Rel_desc *, Xword);
695 extern int		ld_append_isp(Ofl_desc *, Os_desc *, Is_desc *, int);
696 extern void		ld_ar_member(Ar_desc *, Elf_Arsym *, Ar_aux *,
697 			    Ar_mem *);
698 extern Ar_desc		*ld_ar_setup(const char *, Elf *, Ofl_desc *);
699 extern uintptr_t	ld_assign_got_TLS(Boolean, Rel_desc *, Ofl_desc *,
700 			    Sym_desc *, Gotndx *, Gotref, Word, Word,
701 			    Word, Word);
702 
703 extern Word		ld_bswap_Word(Word);
704 extern Xword		ld_bswap_Xword(Xword);
705 
706 extern void		ld_disp_errmsg(const char *, Rel_desc *, Ofl_desc *);
707 
708 extern void		ld_ent_check(Ofl_desc *);
709 extern int		ld_exit(Ofl_desc *);
710 
711 extern uintptr_t	ld_find_library(const char *, Ofl_desc *);
712 extern uintptr_t	ld_finish_libs(Ofl_desc *);
713 
714 extern const char	*ld_section_reld_name(Sym_desc *, Is_desc *);
715 
716 extern Group_desc	*ld_get_group(Ofl_desc *, Is_desc *);
717 extern uintptr_t	ld_group_process(Is_desc *, Ofl_desc *);
718 
719 extern uintptr_t	ld_lib_setup(Ofl_desc *);
720 
721 extern void		ld_init(Ofl_desc *);
722 
723 extern Xword		ld_lcm(Xword, Xword);
724 
725 extern uintptr_t	ld_make_bss(Ofl_desc *, Xword, Xword, Bss_Type);
726 extern Is_desc		*ld_make_data(Ofl_desc *, size_t);
727 extern uintptr_t	ld_make_got(Ofl_desc *);
728 extern uintptr_t	ld_make_parexpn_data(Ofl_desc *, size_t, Xword);
729 extern uintptr_t	ld_make_sunwmove(Ofl_desc *, int);
730 extern Is_desc		*ld_make_text(Ofl_desc *, size_t);
731 extern void		ld_map_out(Ofl_desc *);
732 extern uintptr_t	ld_map_parse(const char *, Ofl_desc *);
733 
734 extern uintptr_t	ld_open_outfile(Ofl_desc *);
735 
736 extern Os_desc		*ld_place_section(Ofl_desc *, Is_desc *, int, Word);
737 extern uintptr_t	ld_process_archive(const char *, int, Ar_desc *,
738 			    Ofl_desc *);
739 extern uintptr_t	ld_process_files(Ofl_desc *, int, char **);
740 extern uintptr_t	ld_process_flags(Ofl_desc *, int, char **);
741 extern Ifl_desc		*ld_process_ifl(const char *, const char *, int, Elf *,
742 			    Word, Ofl_desc *, Rej_desc *);
743 extern Ifl_desc		*ld_process_open(const char *, const char *, int *,
744 			    Ofl_desc *, Word, Rej_desc *);
745 extern uintptr_t	ld_process_ordered(Ifl_desc *, Ofl_desc *, Word, Word);
746 extern uintptr_t	ld_process_sym_reloc(Ofl_desc *, Rel_desc *, Rel *,
747 			    Is_desc *, const char *);
748 
749 extern uintptr_t	ld_reloc_GOT_relative(Boolean, Rel_desc *, Ofl_desc *);
750 extern uintptr_t	ld_reloc_plt(Rel_desc *, Ofl_desc *);
751 extern void		ld_reloc_remain_entry(Rel_desc *, Os_desc *,
752 			    Ofl_desc *);
753 extern int		ld_reloc_targval_get(Ofl_desc *, Rel_desc *,
754 			    uchar_t *, Xword *);
755 extern int		ld_reloc_targval_set(Ofl_desc *, Rel_desc *,
756 			    uchar_t *, Xword);
757 
758 extern void		ld_sec_validate(Ofl_desc *);
759 extern uintptr_t	ld_sort_ordered(Ofl_desc *);
760 extern uintptr_t	ld_sort_seg_list(Ofl_desc *);
761 extern Half		ld_sunw_ldmach();
762 extern uintptr_t	ld_sunwmove_preprocess(Ofl_desc *);
763 extern void		ld_sup_atexit(Ofl_desc *, int);
764 extern void		ld_sup_open(Ofl_desc *, const char **, const char **,
765 			    int *, int, Elf **, Elf *ref, size_t,
766 			    const Elf_Kind);
767 extern void		ld_sup_file(Ofl_desc *, const char *, const Elf_Kind,
768 			    int flags, Elf *);
769 extern uintptr_t	ld_sup_loadso(Ofl_desc *, const char *);
770 extern void		ld_sup_input_done(Ofl_desc *);
771 extern void		ld_sup_section(Ofl_desc *, const char *, Shdr *, Word,
772 			    Elf_Data *, Elf *);
773 extern uintptr_t	ld_sup_input_section(Ofl_desc*, Ifl_desc *,
774 			    const char *, Shdr **, Word, Elf_Scn *, Elf *);
775 extern void		ld_sup_start(Ofl_desc *, const Half, const char *);
776 extern int		ld_swap_reloc_data(Ofl_desc *, Rel_desc *);
777 extern Sym_desc		*ld_sym_add_u(const char *, Ofl_desc *, Msg);
778 extern void		ld_sym_adjust_vis(Sym_desc *, Ofl_desc *);
779 extern int		ld_sym_avl_comp(const void *, const void *);
780 extern uintptr_t	ld_sym_copy(Sym_desc *);
781 extern Sym_desc		*ld_sym_enter(const char *, Sym *, Word, Ifl_desc *,
782 			    Ofl_desc *, Word, Word, Word, Half, avl_index_t *);
783 extern Sym_desc		*ld_sym_find(const char *, Word, avl_index_t *,
784 			    Ofl_desc *);
785 extern uintptr_t	ld_sym_nodirect(Is_desc *, Ifl_desc *, Ofl_desc *);
786 extern uintptr_t	ld_sym_process(Is_desc *, Ifl_desc *, Ofl_desc *);
787 extern uintptr_t	ld_sym_resolve(Sym_desc *, Sym *, Ifl_desc *,
788 			    Ofl_desc *, int, Word, Word);
789 extern uintptr_t	ld_sym_spec(Ofl_desc *);
790 
791 extern Target		ld_targ;
792 extern const Target	*ld_targ_init_sparc(void);
793 extern const Target	*ld_targ_init_x86(void);
794 
795 extern Ver_desc		*ld_vers_base(Ofl_desc *);
796 extern uintptr_t	ld_vers_check_defs(Ofl_desc *);
797 extern uintptr_t	ld_vers_check_need(Ofl_desc *);
798 extern uintptr_t	ld_vers_def_process(Is_desc *, Ifl_desc *, Ofl_desc *);
799 extern Ver_desc		*ld_vers_desc(const char *, Word, List *);
800 extern Ver_desc		*ld_vers_find(const char *, Word, List *);
801 extern uintptr_t	ld_vers_need_process(Is_desc *, Ifl_desc *, Ofl_desc *);
802 extern void		ld_vers_promote(Sym_desc *, Word, Ifl_desc *,
803 			    Ofl_desc *);
804 extern int		ld_vers_sym_process(Lm_list *, Is_desc *, Ifl_desc *);
805 extern int		ld_vers_verify(Ofl_desc *);
806 
807 extern uintptr_t	add_regsym(Sym_desc *, Ofl_desc *);
808 extern Word		hashbkts(Word);
809 extern Xword		lcm(Xword, Xword);
810 extern Listnode		*list_where(List *, Word);
811 
812 /*
813  * Most platforms have both a 32 and 64-bit variant (e.g. EM_SPARC and
814  * EM_SPARCV9). To support this, there many files in libld that are built
815  * twice, once for ELFCLASS64 (_ELF64), and once for ELFCLASS32. In these
816  * files, we sometimes want to supply one value for the ELFCLASS32 case
817  * and another for ELFCLASS64. The LD_TARG_BYCLASS macro is used to do
818  * this. It is called with both both alternatives, and yields the one
819  * that applies to the current compilation environment.
820  */
821 #ifdef	_ELF64
822 #define	LD_TARG_BYCLASS(_ec32, _ec64) (_ec64)
823 #else
824 #define	LD_TARG_BYCLASS(_ec32, _ec64) (_ec32)
825 #endif
826 
827 
828 #ifdef	__cplusplus
829 }
830 #endif
831 
832 #endif /* _LIBLD_DOT_H */
833