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