xref: /titanic_52/usr/src/cmd/sgs/include/libld.h (revision c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d)
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 #ifndef	_LIBLD_H
31 #define	_LIBLD_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <stdlib.h>
36 #include <libelf.h>
37 #include <sgs.h>
38 #include <_machelf.h>
39 #include <string_table.h>
40 #include <sys/avl.h>
41 #include <alist.h>
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 /*
48  * Default directory search path manipulation for the link-editor.  YLDIR
49  * indicates which directory in LIBPATH is replaced by the -YL option to cc
50  * and ld.  YUDIR indicates which directory is replaced by -YU.
51  */
52 #define	YLDIR	1
53 #define	YUDIR	2
54 
55 /*
56  * Define a hash value that can never be returned from elf_hash().
57  */
58 #define	SYM_NOHASH	(~(Word)0)
59 
60 /*
61  * Macro that can be used to represent both ORDER flags
62  * in a section header.
63  */
64 #define	ALL_SHF_ORDER	(SHF_ORDERED | SHF_LINK_ORDER)
65 
66 /*
67  * The linker merges (concatenates) sections with the same name and
68  * compatible section header flags. When comparing these flags,
69  * there are some that should not be included in the decision.
70  * The ALL_SHF_IGNORE constant defines these flags.
71  *
72  * NOTE: SHF_MERGE|SHF_STRINGS:
73  * The compiler is allowed to set the SHF_MERGE|SHF_STRINGS flags in
74  * order to tell the linker that:
75  *
76  *      1) There is nothing in the section except null terminated strings.
77  *	2) Those strings do not contain NULL bytes, except as termination.
78  *	3) All references to these strings occur via standard relocation
79  *		records.
80  *
81  * As a result, if two compatible sections both have these flags set, it is
82  * OK to combine the strings they contain into a single merged string table
83  * with duplicates removed and tail strings merged.
84  *
85  * This is a different meaning than the simple concatenating of sections
86  * that the linker always does. It is a hint that an additional optimization
87  * is possible, but not required. This means that sections that do not
88  * share the same SHF_MERGE|SHF_STRINGS values can be concatenated,
89  * but cannot have their duplicate strings combined. Hence, the
90  * SHF_MERGE|SHF_STRINGS flags should be ignored when deciding whether
91  * two sections can be concatenated.
92  */
93 #define	ALL_SHF_IGNORE	(ALL_SHF_ORDER | SHF_GROUP | SHF_MERGE | SHF_STRINGS)
94 
95 /*
96  * Define symbol reference types for use in symbol resolution.
97  */
98 typedef enum {
99 	REF_DYN_SEEN,			/* a .so symbol has been seen */
100 	REF_DYN_NEED,			/* a .so symbol satisfies a .o symbol */
101 	REF_REL_NEED,			/* a .o symbol */
102 	REF_NUM				/* the number of symbol references */
103 } Symref;
104 
105 
106 /*
107  * GOT reference models
108  */
109 typedef enum {
110 	GOT_REF_GENERIC,	/* generic symbol reference */
111 	GOT_REF_TLSIE,		/* TLS initial exec (gnu) reference */
112 	GOT_REF_TLSLD,		/* TLS local dynamic reference */
113 	GOT_REF_TLSGD		/* TLS general dynamic reference */
114 } Gotref;
115 
116 typedef struct {
117 	Xword		gn_addend;	/* addend associated with GOT entry */
118 	Sword		gn_gotndx;	/* GOT table index */
119 	Gotref		gn_gotref;
120 } Gotndx;
121 
122 /*
123  * Got debugging structure.  The got index is defined as a signed value as we
124  * do so much mucking around with negative and positive gots on SPARC, and sign
125  * extension is necessary when building 64-bit objects.  On intel we explicitly
126  * cast this variable to an unsigned value.
127  */
128 typedef struct {
129 	Sym_desc *	gt_sym;
130 	Gotndx		gt_gndx;
131 } Gottable;
132 
133 
134 /*
135  * Output file processing structure
136  */
137 typedef Lword ofl_flag_t;
138 struct ofl_desc {
139 	char		*ofl_sgsid;	/* link-editor identification */
140 	const char	*ofl_name;	/* full file name */
141 	Elf		*ofl_elf;	/* elf_memory() elf descriptor */
142 	Elf		*ofl_welf;	/* ELF_C_WRITE elf descriptor */
143 	Ehdr		*ofl_dehdr;	/* default elf header, and new elf */
144 	Ehdr		*ofl_nehdr;	/*	header describing this file */
145 	Phdr		*ofl_phdr;	/* program header descriptor */
146 	Phdr		*ofl_tlsphdr;	/* TLS phdr */
147 	int		ofl_fd;		/* file descriptor */
148 	size_t		ofl_size;	/* image size */
149 	List		ofl_maps;	/* list of input mapfiles */
150 	List		ofl_segs;	/* list of segments */
151 	List		ofl_ents;	/* list of entrance descriptors */
152 	List		ofl_objs;	/* relocatable object file list */
153 	Word		ofl_objscnt;	/* 	and count */
154 	List		ofl_ars;	/* archive library list */
155 	Word		ofl_arscnt;	/* 	and count */
156 	List		ofl_sos;	/* shared object list */
157 	Word		ofl_soscnt;	/* 	and count */
158 	List		ofl_soneed;	/* list of implicitly required .so's */
159 	List		ofl_socntl;	/* list of .so control definitions */
160 	List		ofl_outrels;	/* list of output relocations */
161 	Word		ofl_outrelscnt;	/* 	and count */
162 	List		ofl_actrels;	/* list of relocations to perform */
163 	Word		ofl_actrelscnt;	/* 	and count */
164 	Word		ofl_entrelscnt;	/* no of relocations entered */
165 	List		ofl_copyrels;	/* list of copy relocations */
166 	List		ofl_ordered;	/* list of shf_ordered sections */
167 	List		ofl_syminfsyms;	/* list of interesting syms */
168 					/*	for syminfo processing */
169 	List		ofl_ismove;	/* list of .SUNW_move sections */
170 	List		ofl_mvrelisdescs; /* list of relocation input section */
171 					/* targeting to expanded area */
172 	List		ofl_parsym; 	/* list of Parsym_info */
173 	List		ofl_extrarels;	/* relocation sections which have */
174 					/*    a NULL sh_info */
175 	avl_tree_t	*ofl_groups;	/* pointer to head of Groups AVL tree */
176 	List		ofl_initarray;	/* list of init array func names */
177 	List		ofl_finiarray;	/* list of fini array func names */
178 	List		ofl_preiarray;	/* list of preinit array func names */
179 	List		ofl_rtldinfo;	/* list of rtldinfo syms */
180 	List		ofl_osgroups;	/* list of output GROUP sections */
181 	List		ofl_ostlsseg;	/* pointer to sections in TLS segment */
182 #if	defined(_ELF64)			/* for amd64 target only */
183 	List		ofl_unwind;	/* list of unwind output sections */
184 	Os_desc		*ofl_unwindhdr;	/* Unwind hdr */
185 #endif
186 	avl_tree_t	ofl_symavl;	/* pointer to head of Syms AVL tree */
187 	Sym_desc	**ofl_regsyms;	/* array of potential register */
188 	Word		ofl_regsymsno;	/*    symbols and array count */
189 	Word		ofl_regsymcnt;	/* no. of output register symbols */
190 	Word		ofl_lregsymcnt;	/* no. of local register symbols */
191 	Sym_desc	*ofl_dtracesym;	/* ld -zdtrace= */
192 	ofl_flag_t	ofl_flags;	/* various state bits, args etc. */
193 	ofl_flag_t	ofl_flags1;	/*	more flags */
194 	Xword		ofl_segorigin;	/* segment origin (start) */
195 	void		*ofl_entry;	/* entry point (-e and Sym_desc *) */
196 	char		*ofl_filtees;	/* shared objects we are a filter for */
197 	const char	*ofl_soname;	/* (-h option) output file name for */
198 					/*	dynamic structure */
199 	const char	*ofl_interp;	/* interpreter name used by exec() */
200 	char		*ofl_rpath;	/* run path to store in .dynamic */
201 	char		*ofl_config;	/* config path to store in .dynamic */
202 	List		ofl_ulibdirs;	/* user supplied library search list */
203 	List		ofl_dlibdirs;	/* default library search list */
204 	Word		ofl_vercnt;	/* number of versions to generate */
205 	List		ofl_verdesc;	/* list of version descriptors */
206 	size_t		ofl_verdefsz;	/* size of version definition section */
207 	size_t		ofl_verneedsz;	/* size of version needed section */
208 	Word		ofl_entercnt;	/* no. of global symbols entered */
209 	Word		ofl_globcnt;	/* no. of global symbols to output */
210 	Word		ofl_scopecnt;	/* no. of scoped symbols to output */
211 	Word		ofl_dynscopecnt; /* no. scoped syms in .SUNW_ldynsym */
212 	Word		ofl_elimcnt;	/* no. of eliminated symbols */
213 	Word		ofl_locscnt;	/* no. of local symbols in .symtab */
214 	Word		ofl_dynlocscnt;	/* no. local symbols in .SUNW_ldynsym */
215 	Word		ofl_dynsymsortcnt; /* no. ndx in .SUNW_dynsymsort */
216 	Word		ofl_dyntlssortcnt; /* no. ndx in .SUNW_dyntlssort */
217 	Word		ofl_dynshdrcnt;	/* no. of output section in .dynsym */
218 	Word		ofl_shdrcnt;	/* no. of output sections */
219 	Str_tbl		*ofl_shdrsttab;	/* Str_tbl for shdr strtab */
220 	Str_tbl		*ofl_strtab;	/* Str_tbl for symtab strtab */
221 	Str_tbl		*ofl_dynstrtab;	/* Str_tbl for dymsym strtab */
222 	Gotndx		*ofl_tlsldgotndx; /* index to LD TLS_index structure */
223 	Xword		ofl_relocsz;	/* size of output relocations */
224 	Xword		ofl_relocgotsz;	/* size of .got relocations */
225 	Xword		ofl_relocpltsz;	/* size of .plt relocations */
226 	Xword		ofl_relocbsssz;	/* size of .bss (copy) relocations */
227 	Xword		ofl_relocrelsz;	/* size of .rel[a] relocations */
228 	Word		ofl_relocincnt;	/* no. of input relocations */
229 	Word		ofl_reloccnt;	/* tot number of output relocations */
230 	Word		ofl_reloccntsub; /* tot numb of output relocations to */
231 					/*	skip (-zignore) */
232 	Word		ofl_relocrelcnt; /* tot number of relative */
233 					/*	relocations */
234 	Word		ofl_gotcnt;	/* no. of .got entries */
235 	Word		ofl_pltcnt;	/* no. of .plt entries */
236 	Word		ofl_pltpad;	/* no. of .plt padd entries */
237 	Word		ofl_hashbkts;	/* no. of hash buckets required */
238 	Is_desc		*ofl_isbss;	/* .bss input section (globals) */
239 	Is_desc		*ofl_islbss;	/* .lbss input section (globals) */
240 	Is_desc		*ofl_istlsbss;	/* .tlsbss input section (globals) */
241 	Is_desc		*ofl_issunwdata1; /* .data input section */
242 					/* 	partially expanded. */
243 	Is_desc		*ofl_issunwbss;	/* .SUNW_bss input section (globals) */
244 	Os_desc		*ofl_osdynamic;	/* .dynamic output section */
245 	Os_desc		*ofl_osdynsym;	/* .dynsym output section */
246 	Os_desc		*ofl_osldynsym;	/* .SUNW_ldynsym output section */
247 	Os_desc		*ofl_osdynstr;	/* .dynstr output section */
248 	Os_desc		*ofl_osdynsymsort; /* .SUNW_dynsymsort output section */
249 	Os_desc		*ofl_osdyntlssort; /* .SUNW_dyntlssort output section */
250 	Os_desc		*ofl_osgot;	/* .got output section */
251 	Os_desc		*ofl_oshash;	/* .hash output section */
252 	Os_desc		*ofl_osinitarray; /* .initarray output section */
253 	Os_desc		*ofl_osfiniarray; /* .finiarray output section */
254 	Os_desc		*ofl_ospreinitarray; /* .preinitarray output section */
255 	Os_desc		*ofl_osinterp;	/* .interp output section */
256 	Os_desc		*ofl_oscap;	/* .SUNW_cap output section */
257 	Os_desc		*ofl_osplt;	/* .plt output section */
258 	Os_desc		*ofl_osmove;	/* .SUNW_move output section */
259 	Os_desc		*ofl_osrelhead;	/* first relocation section */
260 	Os_desc		*ofl_osrel;	/* .rel[a] relocation section */
261 	Os_desc		*ofl_osshstrtab; /* .shstrtab output section */
262 	Os_desc		*ofl_osstrtab;	/* .strtab output section */
263 	Os_desc		*ofl_ossymtab;	/* .symtab output section */
264 	Os_desc		*ofl_ossymshndx; /* .symtab_shndx output section */
265 	Os_desc		*ofl_osdynshndx; /* .dynsym_shndx output section */
266 	Os_desc		*ofl_osldynshndx; /* .SUNW_ldynsym_shndx output sec */
267 	Os_desc		*ofl_osverdef;	/* .version definition output section */
268 	Os_desc		*ofl_osverneed;	/* .version needed output section */
269 	Os_desc		*ofl_osversym;	/* .version symbol ndx output section */
270 	Word		ofl_dtflags_1;	/* DT_FLAGS_1 entries */
271 	Word		ofl_dtflags;	/* DT_FLAGS entries */
272 	Os_desc		*ofl_ossyminfo;	/* .SUNW_syminfo output section */
273 	Half		ofl_sunwdata1ndx; /* section index for sunwdata1  */
274 					/* Ref. at perform_outreloc() in */
275 					/* libld/{mach}/machrel.c */
276 	Xword		*ofl_checksum;	/* DT_CHECKSUM value address */
277 	char		*ofl_depaudit;	/* dependency auditing required (-P) */
278 	char		*ofl_audit;	/* object auditing required (-p) */
279 	Alist		*ofl_symfltrs;	/* per-symbol filtees and their */
280 	Alist		*ofl_dtsfltrs;	/*	associated .dynamic/.dynstrs */
281 	Xword		ofl_hwcap_1;	/* hardware capabilities */
282 	Xword		ofl_sfcap_1;	/* software capabilities */
283 	Lm_list		*ofl_lml;	/* runtime link-map list */
284 	Gottable	*ofl_gottable;	/* debugging got information */
285 };
286 
287 #define	FLG_OF_DYNAMIC	0x00000001	/* generate dynamic output module */
288 #define	FLG_OF_STATIC	0x00000002	/* generate static output module */
289 #define	FLG_OF_EXEC	0x00000004	/* generate an executable */
290 #define	FLG_OF_RELOBJ	0x00000008	/* generate a relocatable object */
291 #define	FLG_OF_SHAROBJ	0x00000010	/* generate a shared object */
292 #define	FLG_OF_BFLAG	0x00000020	/* do no special plt building: -b */
293 #define	FLG_OF_IGNENV	0x00000040	/* ignore LD_LIBRARY_PATH: -i */
294 #define	FLG_OF_STRIP	0x00000080	/* strip output: -s */
295 #define	FLG_OF_NOWARN	0x00000100	/* disable symbol warnings: -t */
296 #define	FLG_OF_NOUNDEF	0x00000200	/* allow no undefined symbols: -zdefs */
297 #define	FLG_OF_PURETXT	0x00000400	/* allow no text relocations: -ztext  */
298 #define	FLG_OF_GENMAP	0x00000800	/* generate a memory map: -m */
299 #define	FLG_OF_DYNLIBS	0x00001000	/* dynamic input allowed: -Bdynamic */
300 #define	FLG_OF_SYMBOLIC	0x00002000	/* bind global symbols: -Bsymbolic */
301 #define	FLG_OF_ADDVERS	0x00004000	/* add version stamp: -Qy */
302 #define	FLG_OF_NOLDYNSYM 0x00008000	/* -znoldynsym set */
303 #define	FLG_OF_SEGORDER	0x00010000	/* segment ordering is required */
304 #define	FLG_OF_SEGSORT	0x00020000	/* segment sorting is required */
305 #define	FLG_OF_TEXTREL	0x00040000	/* text relocations have been found */
306 #define	FLG_OF_MULDEFS	0x00080000	/* multiple symbols are allowed */
307 #define	FLG_OF_TLSPHDR	0x00100000	/* a TLS program header is required */
308 #define	FLG_OF_BLDGOT	0x00200000	/* build GOT table */
309 #define	FLG_OF_VERDEF	0x00400000	/* record version definitions */
310 #define	FLG_OF_VERNEED	0x00800000	/* record version dependencies */
311 #define	FLG_OF_NOVERSEC 0x01000000	/* don't record version sections */
312 
313 #define	FLG_OF_PROCRED	0x04000000	/* process any symbol reductions by */
314 					/*	effecting the symbol table */
315 					/*	output and relocations */
316 #define	FLG_OF_SYMINFO	0x08000000	/* create a syminfo section */
317 #define	FLG_OF_AUX	0x10000000	/* ofl_filter is an auxiliary filter */
318 #define	FLG_OF_FATAL	0x20000000	/* fatal error during input */
319 #define	FLG_OF_WARN	0x40000000	/* warning during input processing. */
320 #define	FLG_OF_VERBOSE	0x80000000	/* -z verbose flag set */
321 
322 #define	FLG_OF_MAPSYMB	0x000100000000	/* symbolic scope definition seen */
323 #define	FLG_OF_MAPGLOB	0x000200000000	/* global scope definition seen */
324 #define	FLG_OF_COMREL	0x000400000000	/* -z combreloc set, which enables */
325 					/*	DT_RELACNT tracking, */
326 #define	FLG_OF_NOCOMREL	0x000800000000	/* -z nocombreloc set */
327 #define	FLG_OF_AUTOLCL	0x001000000000	/* automatically reduce unspecified */
328 					/*	global symbols to locals */
329 #define	FLG_OF_AUTOELM	0x002000000000	/* automatically eliminate  */
330 					/*	unspecified global symbols */
331 #define	FLG_OF_REDLSYM	0x004000000000	/* reduce local symbols */
332 
333 /*
334  * In the flags1 arena, establish any options that are applicable to archive
335  * extraction first, and associate a mask.  These values are recorded with any
336  * archive descriptor so that they may be reset should the archive require a
337  * rescan to try and resolve undefined symbols.
338  */
339 #define	FLG_OF1_ALLEXRT	0x00000001	/* extract all members from an */
340 					/*	archive file */
341 #define	FLG_OF1_WEAKEXT	0x00000002	/* allow archive extraction to */
342 					/*	resolve weak references */
343 #define	MSK_OF1_ARCHIVE	0x00000003	/* archive flags mask */
344 
345 #define	FLG_OF1_NOINTRP	0x00000008	/* -z nointerp flag set */
346 #define	FLG_OF1_ZDIRECT	0x00000010	/* -z direct flag set */
347 #define	FLG_OF1_NDIRECT	0x00000020	/* no-direct bindings specified */
348 #define	FLG_OF1_OVHWCAP	0x00000040	/* override any input hardware or */
349 #define	FLG_OF1_OVSFCAP	0x00000080	/*	software capabilities */
350 #define	FLG_OF1_RELDYN	0x00000100	/* process .dynamic in rel obj */
351 
352 #define	FLG_OF1_IGNORE	0x00000800	/* ignore unused dependencies */
353 
354 #define	FLG_OF1_TEXTOFF 0x00002000	/* text relocations are ok */
355 #define	FLG_OF1_ABSEXEC	0x00004000	/* -zabsexec set */
356 #define	FLG_OF1_LAZYLD	0x00008000	/* lazy loading of objects enabled */
357 #define	FLG_OF1_GRPPRM	0x00010000	/* dependencies are to have */
358 					/*	GROUPPERM enabled */
359 #define	FLG_OF1_OVRFLW	0x00020000	/* size exceeds 32-bit limitation */
360 					/*	of 32-bit libld */
361 #define	FLG_OF1_NOPARTI	0x00040000	/* -znopartial set */
362 #define	FLG_OF1_BSSOREL	0x00080000	/* output relocation against bss */
363 					/*	section */
364 #define	FLG_OF1_TLSOREL	0x00100000	/* output relocation against .tlsbss */
365 					/*	section */
366 #define	FLG_OF1_MEMORY	0x00200000	/* produce a memory model */
367 #define	FLG_OF1_RLXREL	0x00400000	/* -z relaxreloc flag set */
368 #define	FLG_OF1_ENCDIFF	0x00800000	/* Host running linker has different */
369 					/*	byte order than output object */
370 #define	FLG_OF1_VADDR	0x01000000	/* vaddr was explicitly set */
371 #define	FLG_OF1_EXTRACT	0x02000000	/* archive member has been extracted */
372 #define	FLG_OF1_RESCAN	0x04000000	/* any archives should be rescanned */
373 #define	FLG_OF1_IGNPRC	0x08000000	/* ignore processing required */
374 #define	FLG_OF1_NCSTTAB	0x10000000	/* -znocompstrtab set */
375 #define	FLG_OF1_DONE	0x20000000	/* link-editor processing complete */
376 #define	FLG_OF1_NONREG	0x40000000	/* non-regular file specified as */
377 					/*	the output file */
378 #define	FLG_OF1_ALNODIR	0x80000000	/* establish NODIRECT for all */
379 					/*	exported interfaces. */
380 
381 /*
382  * Test to see if the output file would allow the presence of
383  * a .dynsym section.
384  */
385 #define	OFL_ALLOW_DYNSYM(_ofl) (((_ofl)->ofl_flags & \
386 	(FLG_OF_DYNAMIC | FLG_OF_RELOBJ)) == FLG_OF_DYNAMIC)
387 
388 /*
389  * Test to see if the output file would allow the presence of
390  * a .SUNW_ldynsym section. The requirements are that a .dynsym
391  * is allowed, and -znoldynsym has not been specified. Note that
392  * even if the answer is True (1), we will only generate one if there
393  * are local symbols that require it.
394  */
395 #define	OFL_ALLOW_LDYNSYM(_ofl) (((_ofl)->ofl_flags & \
396 	(FLG_OF_DYNAMIC | FLG_OF_RELOBJ | FLG_OF_NOLDYNSYM)) == FLG_OF_DYNAMIC)
397 
398 /*
399  * Test to see if relocation processing should be done. This is normally
400  * true, but can be disabled via the '-z noreloc' option. Note that
401  * relocatable objects are still relocated even if '-z noreloc' is present.
402  */
403 #define	OFL_DO_RELOC(_ofl) (((_ofl)->ofl_flags & FLG_OF_RELOBJ) || \
404 	!((_ofl)->ofl_dtflags_1 & DF_1_NORELOC))
405 
406 /*
407  * Relocation (active & output) processing structure - transparent to common
408  * code.
409  *
410  * Note that rel_raddend is primarily only of interest to RELA relocations,
411  * and is set to 0 for REL. However, there is an exception: If FLG_REL_NADDEND
412  * is set, then rel_raddend contains a replacement value for the implicit
413  * addend found in the relocation target.
414  */
415 struct rel_desc {
416 	Os_desc		*rel_osdesc;	/* output section reloc is against */
417 	Is_desc		*rel_isdesc;	/* input section reloc is against */
418 	const char	*rel_sname;	/* symbol name (may be "unknown") */
419 	Sym_desc	*rel_sym;	/* sym relocation is against */
420 	Sym_desc	*rel_usym;	/* strong sym if this is a weak pair */
421 	Mv_desc		*rel_move;	/* move table information */
422 	Word		rel_flags;	/* misc. flags for relocations */
423 	Word		rel_rtype;	/* relocation type */
424 	Xword		rel_roffset;	/* relocation offset */
425 	Sxword		rel_raddend;	/* addend from input relocation */
426 	Word		rel_typedata;	/* ELF_R_TYPE_DATA(info) */
427 };
428 
429 /*
430  * common flags used on the Rel_desc structure (defined in machrel.h).
431  */
432 #define	FLG_REL_GOT	0x00000001	/* relocation against GOT */
433 #define	FLG_REL_PLT	0x00000002	/* relocation against PLT */
434 #define	FLG_REL_BSS	0x00000004	/* relocation against BSS */
435 #define	FLG_REL_LOAD	0x00000008	/* section loadable */
436 #define	FLG_REL_SCNNDX	0x00000010	/* use section index for symbol ndx */
437 #define	FLG_REL_CLVAL	0x00000020	/* clear VALUE for active relocation */
438 #define	FLG_REL_ADVAL	0x00000040	/* add VALUE for output relocation, */
439 					/*	only relevant to SPARC and */
440 					/*	R_SPARC_RELATIVE */
441 #define	FLG_REL_GOTCL	0x00000080	/* clear the GOT entry.  This is */
442 					/* relevant to RELA relocations, */
443 					/* not REL (i386) relocations */
444 #define	FLG_REL_MOVETAB	0x00000100	/* Relocation against .SUNW_move */
445 					/*	adjustments required before */
446 					/*	actual relocation */
447 #define	FLG_REL_NOINFO	0x00000200	/* Relocation comes from a section */
448 					/*	with a null sh_info field */
449 #define	FLG_REL_REG	0x00000400	/* Relocation target is reg sym */
450 #define	FLG_REL_FPTR	0x00000800	/* relocation against func. desc. */
451 #define	FLG_REL_RFPTR1	0x00001000	/* Relative relocation against */
452 					/*   1st part of FD */
453 #define	FLG_REL_RFPTR2	0x00002000	/* Relative relocation against */
454 					/*   2nd part of FD */
455 #define	FLG_REL_DISP	0x00004000	/* *disp* relocation */
456 #define	FLG_REL_STLS	0x00008000	/* IE TLS reference to */
457 					/*	static TLS GOT index */
458 #define	FLG_REL_DTLS	0x00010000	/* GD TLS reference relative to */
459 					/*	dynamic TLS GOT index */
460 #define	FLG_REL_MTLS	0x00020000	/* LD TLS reference against GOT */
461 #define	FLG_REL_STTLS	0x00040000	/* LE TLS reference directly */
462 					/*	to static tls index */
463 #define	FLG_REL_TLSFIX	0x00080000	/* relocation points to TLS instr. */
464 					/*	which needs updating */
465 #define	FLG_REL_RELA	0x00100000	/* descripter captures a Rela */
466 #define	FLG_REL_GOTFIX	0x00200000	/* relocation points to GOTOP instr. */
467 					/*	which needs updating */
468 #define	FLG_REL_NADDEND	0x00400000	/* Replace implicit addend in dest */
469 					/*	with value in rel_raddend */
470 					/*	Relevant to REL (i386) */
471 					/*	relocations, not to RELA. */
472 
473 /*
474  * Structure to hold a cache of Relocations.
475  */
476 struct rel_cache {
477 	Rel_desc	*rc_end;
478 	Rel_desc	*rc_free;
479 };
480 
481 /*
482  * Symbol value descriptor.  For relocatable objects, each symbols value is
483  * its offset within its associated section.  Therefore, to uniquely define
484  * each symbol within a reloctable object, record and sort the sh_offset and
485  * symbol value.  This information is used to seach for displacement
486  * relocations as part of copy relocation validation.
487  */
488 typedef struct {
489 	Addr		ssv_value;
490 	Sym_desc	*ssv_sdp;
491 } Ssv_desc;
492 
493 /*
494  * Input file processing structures.
495  */
496 struct ifl_desc {			/* input file descriptor */
497 	const char	*ifl_name;	/* full file name */
498 	const char	*ifl_soname;	/* shared object name */
499 	dev_t		ifl_stdev;	/* device id and inode number for .so */
500 	ino_t		ifl_stino;	/*	multiple inclusion checks */
501 	Ehdr		*ifl_ehdr;	/* elf header describing this file */
502 	Elf		*ifl_elf;	/* elf descriptor for this file */
503 	Sym_desc	**ifl_oldndx;	/* original symbol table indices */
504 	Sym_desc	*ifl_locs;	/* symbol desc version of locals */
505 	Ssv_desc	*ifl_sortsyms;	/* sorted list of symbols by value */
506 	Word		ifl_locscnt;	/* no. of local symbols to process */
507 	Word		ifl_symscnt;	/* total no. of symbols to process */
508 	Word		ifl_sortcnt;	/* no. of sorted symbols to process */
509 	Word		ifl_shnum;	/* number of sections in file */
510 	Word		ifl_shstrndx;	/* index to .shstrtab */
511 	Word		ifl_vercnt;	/* number of versions in file */
512 	Is_desc		**ifl_isdesc;	/* isdesc[scn ndx] = Is_desc ptr */
513 	Sdf_desc	*ifl_sdfdesc;	/* control definition */
514 	Versym		*ifl_versym;	/* version symbol table array */
515 	Ver_index	*ifl_verndx;	/* verndx[ver ndx] = Ver_index */
516 	List		ifl_verdesc;	/* version descriptor list */
517 	List		ifl_relsect;	/* relocation section list */
518 	Alist		*ifl_groups;	/* SHT_GROUP section list */
519 	Half		ifl_neededndx;	/* index to NEEDED in .dyn section */
520 	Word		ifl_flags;	/* Explicit/implicit reference */
521 };
522 
523 #define	FLG_IF_CMDLINE	0x00000001	/* full filename specified from the */
524 					/*	command line (no -l) */
525 #define	FLG_IF_NEEDED	0x00000002	/* shared object should be recorded */
526 #define	FLG_IF_DIRECT	0x00000004	/* establish direct bindings to this */
527 					/*	object */
528 #define	FLG_IF_EXTRACT	0x00000008	/* file extracted from an archive */
529 #define	FLG_IF_VERNEED	0x00000010	/* version dependency information is */
530 					/*	required */
531 #define	FLG_IF_DEPREQD	0x00000020	/* dependency is required to satisfy */
532 					/*	symbol references */
533 #define	FLG_IF_NEEDSTR	0x00000040	/* dependency specified by -Nn */
534 					/*	flag */
535 #define	FLG_IF_IGNORE	0x00000080	/* ignore unused dependencies */
536 #define	FLG_IF_NODIRECT	0x00000100	/* object contains symbols that */
537 					/*	cannot be directly bound to. */
538 #define	FLG_IF_LAZYLD	0x00000200	/* bindings to this object should be */
539 					/*	lazy loaded */
540 #define	FLG_IF_GRPPRM	0x00000400	/* this dependency should have the */
541 					/*	DF_P1_GROUPPERM flag set */
542 #define	FLG_IF_DISPPEND 0x00000800	/* displacement relocation done */
543 					/*	in the ld time. */
544 #define	FLG_IF_DISPDONE 0x00001000	/* displacement relocation done */
545 					/* 	at the run time */
546 #define	FLG_IF_MAPFILE	0x00002000	/* file is a mapfile */
547 #define	FLG_IF_HSTRTAB	0x00004000	/* file has a string section */
548 #define	FLG_IF_FILEREF	0x00008000	/* file contains a section which */
549 					/*	is included in the output */
550 					/*	allocatable image */
551 #define	FLG_IF_GNUVER	0x00010000	/* file used GNU-style versioning */
552 
553 struct is_desc {			/* input section descriptor */
554 	const char	*is_name;	/* the section name */
555 	const char	*is_basename;	/* original section name (without */
556 					/*	.<sect>%<func> munging */
557 	Shdr		*is_shdr;	/* the elf section header */
558 	Ifl_desc	*is_file;	/* infile desc for this section */
559 	Os_desc		*is_osdesc;	/* new output section for this */
560 					/*	input section */
561 	Elf_Data	*is_indata;	/* input sections raw data */
562 	Is_desc		*is_symshndx;	/* related SHT_SYM_SHNDX section */
563 	Word		is_scnndx;	/* original section index in file */
564 	Word		is_txtndx;	/* Index for section.  Used to decide */
565 					/*	where to insert section when */
566 					/* 	reordering sections */
567 	Word		is_ident;	/* preserved IDENT used for ordered */
568 					/*	sections. */
569 	uint_t		is_namehash;	/* hash on section name */
570 	Half		is_key;		/* Used for SHF_ORDERED */
571 	Half		is_flags;	/* Various flags */
572 };
573 
574 #define	FLG_IS_ORDERED	0x0001		/* This is a SHF_ORDERED section */
575 #define	FLG_IS_KEY	0x0002		/* This is a section pointed by */
576 					/* sh_info of a SHF_ORDERED section */
577 #define	FLG_IS_DISCARD	0x0004		/* section is to be discarded */
578 #define	FLG_IS_RELUPD	0x0008		/* symbol defined here may have moved */
579 #define	FLG_IS_SECTREF	0x0010		/* section has been referenced */
580 #define	FLG_IS_GDATADEF	0x0020		/* section contains global data sym */
581 #define	FLG_IS_EXTERNAL	0x0040		/* isp from an user file */
582 #define	FLG_IS_INSTRMRG	0x0080		/* Usable SHF_MERGE|SHF_STRINGS sec */
583 #define	FLG_IS_GNSTRMRG	0x0100		/* Generated mergeable string section */
584 
585 
586 /*
587  * Map file and output file processing structures
588  */
589 struct os_desc {			/* Output section descriptor */
590 	const char	*os_name;	/* the section name */
591 	Elf_Scn		*os_scn;	/* the elf section descriptor */
592 	Shdr		*os_shdr;	/* the elf section header */
593 	Os_desc		*os_relosdesc;	/* the output relocation section */
594 	List		os_relisdescs;	/* reloc input section descriptors */
595 					/*	for this output section */
596 	List		os_isdescs;	/* list of input sections in output */
597 	APlist		*os_mstrisdescs; /* FLG_IS_INSTRMRG input sections */
598 	Sort_desc	*os_sort;	/* used for sorting sections */
599 	Sg_desc		*os_sgdesc;	/* segment os_desc is placed on */
600 	Elf_Data	*os_outdata;	/* output sections raw data */
601 	List		os_comdats;	/* list of COMDAT sections present */
602 					/*	in current output section */
603 	Word		os_scnsymndx;	/* index in output symtab of section */
604 					/*	symbol for this section */
605 	Word		os_txtndx;	/* Index for section.  Used to decide */
606 					/*	where to insert section when */
607 					/* 	reordering sections */
608 	Xword		os_szoutrels;	/* size of output relocation section */
609 	uint_t		os_namehash;	/* hash on section name */
610 	uchar_t		os_flags;	/* various flags */
611 };
612 
613 #define	FLG_OS_ORDER_KEY	0x01	/* include a sort key section */
614 #define	FLG_OS_OUTREL		0x02	/* output rel against this section */
615 #define	FLG_OS_SECTREF		0x04	/* isps are not affected by -zignore */
616 
617 /*
618  * For sorting sections.
619  */
620 struct sort_desc {
621 	Is_desc		**st_order;
622 	Word		st_ordercnt;
623 	Is_desc		**st_before;
624 	Word		st_beforecnt;
625 	Is_desc		**st_after;
626 	Word		st_aftercnt;
627 };
628 
629 struct sg_desc {			/* output segment descriptor */
630 	Phdr		sg_phdr;	/* segment header for output file */
631 	const char	*sg_name;	/* segment name */
632 	Xword		sg_round;	/* data rounding required (mapfile) */
633 	Xword		sg_length;	/* maximum segment length; if 0 */
634 					/*	segment is not specified */
635 	APlist		*sg_osdescs;	/* list of output section descriptors */
636 	APlist		*sg_secorder;	/* list specifying section ordering */
637 					/*	for the segment */
638 	Half		sg_flags;
639 	Sym_desc	*sg_sizesym;	/* size symbol for this segment */
640 	Xword		sg_addralign;	/* LCM of sh_addralign */
641 	Elf_Scn		*sg_fscn;	/* the SCN of the first section. */
642 };
643 
644 
645 #define	FLG_SG_VADDR	0x0001		/* vaddr segment attribute set */
646 #define	FLG_SG_PADDR	0x0002		/* paddr segment attribute set */
647 #define	FLG_SG_LENGTH	0x0004		/* length segment attribute set */
648 #define	FLG_SG_ALIGN	0x0008		/* align segment attribute set */
649 #define	FLG_SG_ROUND	0x0010		/* round segment attribute set */
650 #define	FLG_SG_FLAGS	0x0020		/* flags segment attribute set */
651 #define	FLG_SG_TYPE	0x0040		/* type segment attribute set */
652 #define	FLG_SG_ORDER	0x0080		/* has ordering been turned on for */
653 					/* 	this segment. */
654 					/*	i.e. ?[O] option in mapfile */
655 #define	FLG_SG_NOHDR	0x0100		/* don't map ELF or phdrs into */
656 					/* 	this segment */
657 #define	FLG_SG_EMPTY	0x0200		/* an empty segment specification */
658 					/*	no input sections will be */
659 					/*	associated to this section */
660 #define	FLG_SG_KEY	0x0400		/* include a key section */
661 #define	FLG_SG_DISABLED	0x0800		/* this segment is disabled */
662 #define	FLG_SG_PHREQ	0x1000		/* this segment requires a program */
663 					/* header */
664 
665 struct sec_order {
666 	const char	*sco_secname;	/* section name to be ordered */
667 	Word		sco_index;	/* ordering index for section */
668 	Half		sco_flags;
669 };
670 
671 #define	FLG_SGO_USED	0x0001		/* was ordering used? */
672 
673 struct ent_desc {			/* input section entrance criteria */
674 	List		ec_files;	/* files from which to accept */
675 					/*	sections */
676 	const char	*ec_name;	/* name to match (NULL if none) */
677 	Word		ec_type;	/* section type */
678 	Word		ec_attrmask;	/* section attribute mask (AWX) */
679 	Word		ec_attrbits;	/* sections attribute bits */
680 	Sg_desc		*ec_segment;	/* output segment to enter if matched */
681 	Word		ec_ndx;		/* index to determine where section */
682 					/*	meeting this criteria should */
683 					/*	inserted. Used for reordering */
684 					/*	of sections. */
685 	Half		ec_flags;
686 };
687 
688 #define	FLG_EC_USED	0x0001		/* entrance criteria met? */
689 
690 /*
691  *  Move supplementary structures
692  *	Sorted by symbol local/global and then by name.
693  */
694 typedef struct psym_info {
695 	Sym_desc	*psym_symd;	/* partially initialized symbol */
696 	Word 		psym_num;	/* number of move entires */
697 	Half 		psym_flag;	/* various flag */
698 	List 		psym_mvs;	/* the list of move entries */
699 } Psym_info;
700 
701 #define	FLG_PSYM_OVERLAP	0x01	/* Overlapping */
702 
703 /*
704  * One structure is allocated for a move entry.
705  */
706 typedef struct mv_itm {
707 	Xword		mv_start;	/* start position */
708 	Xword		mv_length;	/* The length of initialization */
709 	Half		mv_flag;	/* various flags */
710 	Is_desc		*mv_isp;	/* input desc. this entry is from */
711 	Move		*mv_ientry;	/* Input Move_entry */
712 	Word 		mv_oidx;	/* Output Move_entry index */
713 } Mv_itm;
714 
715 #define	FLG_MV_OUTSECT	0x01	/* Will be in move section */
716 
717 /*
718  * Define a move descripter used within relocation structures.
719  */
720 struct mv_desc {
721 	Move		*mvd_move;
722 	Sym_desc	*mvd_sym;
723 };
724 
725 struct sym_desc {
726 	List		sd_GOTndxs;	/* list of associated GOT entries */
727 	Sym		*sd_sym;	/* pointer to symbol table entry */
728 	Sym		*sd_osym;	/* copy of the original symbol entry */
729 					/*	used only for local partial */
730 	Psym_info	*sd_psyminfo;	/* for partial symbols, maintain a */
731 					/*	pointer to parsym_info */
732 	const char	*sd_name;	/* symbols name */
733 	Ifl_desc	*sd_file;	/* file where symbol is taken */
734 	Is_desc		*sd_isc;	/* input section of symbol definition */
735 	Sym_aux		*sd_aux;	/* auxiliary global symbol info. */
736 	Word		sd_symndx;	/* index in output symbol table */
737 	Word		sd_shndx;	/* sect. index sym is associated w/ */
738 	Word		sd_flags;	/* state flags */
739 	Half		sd_flags1;	/* more symbol flags */
740 	Half		sd_ref;		/* reference definition of symbol */
741 };
742 
743 /*
744  * The auxiliary symbol descriptor contains the additional information (beyond
745  * the symbol descriptor) required to process global symbols.  These symbols are
746  * accessed via an internal symbol hash table where locality of reference is
747  * important for performance.
748  */
749 struct sym_aux {
750 	List 		sa_dfiles;	/* files where symbol is defined */
751 	Sym		sa_sym;		/* copy of symtab entry */
752 	const char	*sa_vfile;	/* first unavailable definition */
753 	Ifl_desc	*sa_bindto;	/* symbol to bind to - for translator */
754 	const char	*sa_rfile;	/* file with first symbol referenced */
755 	Word		sa_hash;	/* the pure hash value of symbol */
756 	Word		sa_PLTndx;	/* index into PLT for symbol */
757 	Word		sa_PLTGOTndx;	/* GOT entry indx for PLT indirection */
758 	Word		sa_linkndx;	/* index of associated symbol from */
759 					/*	ET_DYN file */
760 	Half		sa_symspec;	/* special symbol ids */
761 	Half		sa_overndx;	/* output file versioning index */
762 	Half		sa_dverndx;	/* dependency versioning index */
763 };
764 
765 
766 /*
767  * Nodes used to track symbols in the global AVL symbol dictionary.
768  */
769 struct sym_avlnode {
770 	avl_node_t	sav_node;	/* AVL node */
771 	Word		sav_hash;	/* symbol hash value */
772 	const char	*sav_name;	/* symbol name */
773 	Sym_desc	*sav_symdesc;	/* SymDesc entry */
774 };
775 
776 /*
777  * These are the ids for processing of `Special symbols'.  They are used
778  * to set the sym->sd_aux->sa_symspec field.
779  */
780 #define	SDAUX_ID_ETEXT	1		/* etext && _etext symbol */
781 #define	SDAUX_ID_EDATA	2		/* edata && _edata symbol */
782 #define	SDAUX_ID_END	3		/* end, _end, && _END_ symbol */
783 #define	SDAUX_ID_DYN	4		/* DYNAMIC && _DYNAMIC symbol */
784 #define	SDAUX_ID_PLT	5		/* _PROCEDURE_LINKAGE_TABLE_ symbol */
785 #define	SDAUX_ID_GOT	6		/* _GLOBAL_OFFSET_TABLE_ symbol */
786 #define	SDAUX_ID_START	7		/* START_ && _START_ symbol */
787 
788 /*
789  * Flags for sym_desc.sd_flags
790  */
791 #define	FLG_SY_MVTOCOMM	0x00000001	/* assign symbol to common (.bss) */
792 					/*	this is a result of a */
793 					/*	copy reloc against sym */
794 #define	FLG_SY_GLOBREF	0x00000002	/* a global reference has been seen */
795 #define	FLG_SY_WEAKDEF	0x00000004	/* a weak definition has been used */
796 #define	FLG_SY_CLEAN	0x00000008	/* `Sym' entry points to original */
797 					/*	input file (read-only). */
798 #define	FLG_SY_UPREQD	0x00000010	/* symbol value update is required, */
799 					/*	either it's used as an entry */
800 					/*	point or for relocation, but */
801 					/*	it must be updated even if */
802 					/*	the -s flag is in effect */
803 #define	FLG_SY_NOTAVAIL	0x00000020	/* symbol is not available to the */
804 					/*	application either because it */
805 					/*	originates from an implicitly */
806 					/* 	referenced shared object, or */
807 					/*	because it is not part of a */
808 					/*	specified version. */
809 #define	FLG_SY_REDUCED	0x00000040	/* a global is reduced to local */
810 #define	FLG_SY_VERSPROM	0x00000080	/* version definition has been */
811 					/*	promoted to output file */
812 #define	FLG_SY_PROT	0x00000100	/* stv_protected visibility seen */
813 
814 #define	FLG_SY_MAPREF	0x00000200	/* symbol reference generated by user */
815 					/*	from mapfile */
816 #define	FLG_SY_REFRSD	0x00000400	/* symbols sd_ref has been raised */
817 					/* 	due to a copy-relocs */
818 					/*	weak-strong pairing */
819 #define	FLG_SY_INTPOSE	0x00000800	/* symbol defines an interposer */
820 #define	FLG_SY_INVALID	0x00001000	/* unwanted/erroneous symbol */
821 #define	FLG_SY_SMGOT	0x00002000	/* small got index assigned to symbol */
822 					/*	sparc only */
823 #define	FLG_SY_PARENT	0x00004000	/* symbol to be found in parent */
824 					/*    only used with direct bindings */
825 #define	FLG_SY_LAZYLD	0x00008000	/* symbol to cause lazyloading of */
826 					/*	parent object */
827 #define	FLG_SY_ISDISC	0x00010000	/* symbol is a member of a DISCARDED */
828 					/*	section (COMDAT) */
829 #define	FLG_SY_PAREXPN	0x00020000	/* partially init. symbol to be */
830 					/*	expanded */
831 #define	FLG_SY_PLTPAD	0x00040000	/* pltpadding has been allocated for */
832 					/*	this symbol */
833 #define	FLG_SY_REGSYM	0x00080000	/* REGISTER symbol (sparc only) */
834 #define	FLG_SY_SOFOUND	0x00100000	/* compared against an SO definition */
835 #define	FLG_SY_EXTERN	0x00200000	/* symbol is external, allows -zdefs */
836 					/*    error suppression */
837 #define	FLG_SY_MAPUSED	0x00400000	/* mapfile symbol used (occurred */
838 					/*    within a relocatable object) */
839 #define	FLG_SY_COMMEXP	0x00800000	/* COMMON symbol which has been */
840 					/*	allocated */
841 #define	FLG_SY_CMDREF	0x01000000	/* symbol was referenced from the */
842 					/*	command line.  (ld -u <>, */
843 					/*	ld -zrtldinfo=<>, ...) */
844 #define	FLG_SY_SPECSEC	0x02000000	/* section index is reserved value */
845 					/*	ABS, COMMON, ... */
846 #define	FLG_SY_TENTSYM	0x04000000	/* tentative symbol */
847 #define	FLG_SY_VISIBLE	0x08000000	/* symbols visibility determined */
848 #define	FLG_SY_STDFLTR	0x10000000	/* symbol is a standard filter */
849 #define	FLG_SY_AUXFLTR	0x20000000	/* symbol is an auxiliary filter */
850 #define	FLG_SY_DYNSORT	0x40000000	/* req. in dyn[sym|tls]sort section */
851 #define	FLG_SY_NODYNSORT 0x80000000	/* excluded from dyn[sym_tls]sort sec */
852 
853 /*
854  * Sym_desc.sd_flags1
855  */
856 #define	FLG_SY1_DEFAULT	0x00000001	/* global symbol, default */
857 #define	FLG_SY1_SINGLE	0x00000002	/* global symbol, singleton defined */
858 #define	FLG_SY1_PROTECT	0x00000004	/* global symbol, protected defined */
859 #define	FLG_SY1_EXPORT	0x00000008	/* global symbol, exported defined */
860 
861 #define	MSK_SY1_GLOBAL \
862 	(FLG_SY1_DEFAULT | FLG_SY1_SINGLE | FLG_SY1_PROTECT | FLG_SY1_EXPORT)
863 					/* this mask indicates that the */
864 					/*    symbol has been explicitly */
865 					/*    defined within a mapfile */
866 					/*    definition, and is a candidate */
867 					/*    for versioning */
868 
869 #define	FLG_SY1_HIDDEN	0x00000010	/* global symbol, reduce to local */
870 #define	FLG_SY1_ELIM	0x00000020	/* global symbol, eliminate */
871 #define	FLG_SY1_IGNORE	0x00000040	/* global symbol, ignored */
872 
873 #define	MSK_SY1_LOCAL	(FLG_SY1_HIDDEN | FLG_SY1_ELIM | FLG_SY1_IGNORE)
874 					/* this mask allows all local state */
875 					/*    flags to be removed when the */
876 					/*    symbol is copy relocated */
877 
878 #define	FLG_SY1_EXPDEF	0x00000100	/* symbol visibility defined */
879 					/*    explicitly */
880 
881 #define	MSK_SY1_NOAUTO	(FLG_SY1_SINGLE | FLG_SY1_EXPORT | FLG_SY1_EXPDEF)
882 					/* this mask indicates that the */
883 					/*    symbol is not a  candidate for */
884 					/*    auto-reduction/elimination */
885 
886 #define	FLG_SY1_MAPFILE 0x00000200	/* symbol attribute defined in a */
887 					/*    mapfile */
888 #define	FLG_SY1_DIR	0x00000400	/* global symbol, direct bindings */
889 #define	FLG_SY1_NDIR	0x00000800	/* global symbol, nondirect bindings */
890 
891 /*
892  * Create a mask for (sym.st_other & visibility) since the gABI does not yet
893  * define a ELF*_ST_OTHER macro.
894  */
895 #define	MSK_SYM_VISIBILITY	0x7
896 
897 /*
898  * Structure to manage the shared object definition lists.  There are two lists
899  * that use this structure:
900  *
901  *  o	ofl_soneed; maintain the list of implicitly required dependencies
902  *	(ie. shared objects needed by other shared objects).  These definitions
903  *	may include RPATH's required to locate the dependencies, and any
904  *	version requirements.
905  *
906  *  o	ofl_socntl; maintains the shared object control definitions.  These are
907  *	provided by the user (via a mapfile) and are used to indicate any
908  *	SONAME translations and verion control requirements.
909  */
910 struct	sdf_desc {
911 	const char	*sdf_name;	/* the shared objects file name */
912 	const char	*sdf_soname;	/* the shared objects SONAME */
913 	char		*sdf_rpath;	/* library search path DT_RPATH */
914 	const char	*sdf_rfile;	/* referencing file for diagnostics */
915 	Ifl_desc	*sdf_file;	/* the final input file descriptor */
916 	List		sdf_vers;	/* list of versions that are required */
917 					/*	from this object */
918 	List		sdf_verneed;	/* list of VERNEEDS to create for */
919 					/*	this object (via SPECVERS or */
920 					/*	ADDVERS) */
921 	Word		sdf_flags;
922 };
923 
924 #define	FLG_SDF_SONAME	0x02		/* An alternative SONAME is supplied */
925 #define	FLG_SDF_SELECT	0x04		/* version control selection required */
926 #define	FLG_SDF_VERIFY	0x08		/* version definition verification */
927 					/*	required */
928 #define	FLG_SDF_SPECVER	0x10		/* specify VERNEEDS */
929 #define	FLG_SDF_ADDVER	0x20		/* add VERNEED references */
930 
931 /*
932  * Structure to manage shared object version usage requirements.
933  */
934 struct	sdv_desc {
935 	const char	*sdv_name;	/* version name */
936 	const char	*sdv_ref;	/* versions reference */
937 	Word		sdv_flags;	/* flags */
938 };
939 
940 #define	FLG_SDV_MATCHED	0x01		/* VERDEF found and matched */
941 
942 /*
943  * Structures to manage versioning information.  Two versioning structures are
944  * defined:
945  *
946  *   o	a version descriptor maintains a linked list of versions and their
947  *	associated dependencies.  This is used to build the version definitions
948  *	for an image being created (see map_symbol), and to determine the
949  *	version dependency graph for any input files that are versioned.
950  *
951  *   o	a version index array contains each version of an input file that is
952  *	being processed.  It informs us which versions are available for
953  *	binding, and is used to generate any version dependency information.
954  */
955 struct	ver_desc {
956 	const char	*vd_name;	/* version name */
957 	Word		vd_hash;	/* hash value of name */
958 	Ifl_desc	*vd_file;	/* file that defined version */
959 	Half		vd_ndx;		/* coordinates with symbol index */
960 	Half		vd_flags;	/* version information */
961 	List		vd_deps;	/* version dependencies */
962 	Ver_desc	*vd_ref;	/* dependency's first reference */
963 };
964 
965 struct	ver_index {
966 	const char	*vi_name;	/* dependency version name */
967 	Half		vi_flags;	/* communicates availability */
968 	Ver_desc	*vi_desc;	/* cross reference to descriptor */
969 };
970 
971 /*
972  * Define any internal version descriptor flags ([vd|vi]_flags).  Note that the
973  * first byte is reserved for user visible flags (refer VER_FLG's in link.h).
974  */
975 #define	MSK_VER_USER	0x0f		/* mask for user visible flags */
976 
977 #define	FLG_VER_AVAIL	0x10		/* version is available for binding */
978 #define	FLG_VER_REFER	0x20		/* version has been referenced */
979 #define	FLG_VER_SELECT	0x40		/* version has been selected by user */
980 #define	FLG_VER_CYCLIC	0x80		/* a member of cyclic dependency */
981 
982 
983 /*
984  * isalist(1) descriptor - used to break an isalist string into its component
985  * options.
986  */
987 struct	isa_opt {
988 	char		*isa_name;	/* individual isa option name */
989 	size_t		isa_namesz;	/*	and associated size */
990 };
991 
992 struct	isa_desc {
993 	char		*isa_list;	/* sysinfo(SI_ISALIST) list */
994 	size_t		isa_listsz;	/*	and associated size */
995 	Isa_opt		*isa_opt;	/* table of individual isa options */
996 	size_t		isa_optno;	/*	and associated number */
997 };
998 
999 /*
1000  * uname(2) descriptor - used to break a utsname structure into its component
1001  * options (at least those that we're interested in).
1002  */
1003 struct	uts_desc {
1004 	char		*uts_osname;	/* operating system name */
1005 	size_t		uts_osnamesz;	/*	and associated size */
1006 	char		*uts_osrel;	/* operating system release */
1007 	size_t		uts_osrelsz;	/*	and associated size */
1008 };
1009 
1010 
1011 /*
1012  * SHT_GROUP descriptor - used to track group sections at the global
1013  * level to resolve conflicts/determine which to keep.
1014  */
1015 struct group_desc {
1016 	const char	*gd_gsectname;	/* group section name */
1017 	const char	*gd_symname;	/* symbol name */
1018 	Word		*gd_data;	/* data for group section */
1019 	size_t		gd_scnndx;	/* group section index */
1020 	size_t		gd_cnt;		/* number of entries in group data */
1021 	Word		gd_flags;
1022 };
1023 
1024 #define	GRP_FLG_DISCARD	0x0001		/* group is to be discarded */
1025 
1026 /*
1027  * Indexes into the ld_support_funcs[] table.
1028  */
1029 typedef enum {
1030 	LDS_VERSION = 0,
1031 	LDS_INPUT_DONE,
1032 	LDS_START,
1033 	LDS_ATEXIT,
1034 	LDS_OPEN,
1035 	LDS_FILE,
1036 	LDS_INSEC,
1037 	LDS_SEC,
1038 	LDS_NUM
1039 } Support_ndx;
1040 
1041 
1042 /*
1043  * Structure to manage archive member caching.  Each archive has an archive
1044  * descriptor (Ar_desc) associated with it.  This contains pointers to the
1045  * archive symbol table (obtained by elf_getarsyms(3e)) and an auxiliary
1046  * structure (Ar_uax[]) that parallels this symbol table.  The member element
1047  * of this auxiliary table indicates whether the archive member associated with
1048  * the symbol offset has already been extracted (AREXTRACTED) or partially
1049  * processed (refer process_member()).
1050  */
1051 typedef struct ar_mem {
1052 	Elf		*am_elf;	/* elf descriptor for this member */
1053 	char		*am_name;	/* members name */
1054 	char		*am_path;	/* path (ie. lib(foo.o)) */
1055 	Sym		*am_syms;	/* start of global symbols */
1056 	char		*am_strs;	/* associated string table start */
1057 	Xword		am_symn;	/* no. of global symbols */
1058 } Ar_mem;
1059 
1060 typedef struct ar_aux {
1061 	Sym_desc	*au_syms;	/* internal symbol descriptor */
1062 	Ar_mem		*au_mem;	/* associated member */
1063 } Ar_aux;
1064 
1065 #define	FLG_ARMEM_PROC	(Ar_mem *)-1
1066 
1067 typedef struct ar_desc {
1068 	const char	*ad_name;	/* archive file name */
1069 	Elf		*ad_elf;	/* elf descriptor for the archive */
1070 	Elf_Arsym	*ad_start;	/* archive symbol table start */
1071 	Ar_aux		*ad_aux;	/* auxiliary symbol information */
1072 	dev_t		ad_stdev;	/* device id and inode number for */
1073 	ino_t		ad_stino;	/*	multiple inclusion checks */
1074 	ofl_flag_t	ad_flags;	/* archive specific cmd line flags */
1075 } Ar_desc;
1076 
1077 /*
1078  * Define any archive descriptor flags.  NOTE, make sure they do not clash with
1079  * any output file descriptor archive extraction flags, as these are saved in
1080  * the same entry (see MSK_OF1_ARCHIVE).
1081  */
1082 #define	FLG_ARD_EXTRACT	0x00010000	/* archive member has been extracted */
1083 
1084 /*
1085  * Function Declarations.
1086  */
1087 #if	defined(_ELF64)
1088 
1089 #define	ld_create_outfile	ld64_create_outfile
1090 #define	ld_ent_setup		ld64_ent_setup
1091 #define	ld_init_strings		ld64_init_strings
1092 #define	ld_init_target		ld64_init_target
1093 #define	ld_make_sections	ld64_make_sections
1094 #define	ld_main			ld64_main
1095 #define	ld_ofl_cleanup		ld64_ofl_cleanup
1096 #define	ld_process_open		ld64_process_open
1097 #define	ld_reloc_init		ld64_reloc_init
1098 #define	ld_reloc_process	ld64_reloc_process
1099 #define	ld_sym_validate		ld64_sym_validate
1100 #define	ld_update_outfile	ld64_update_outfile
1101 
1102 #else
1103 
1104 #define	ld_create_outfile	ld32_create_outfile
1105 #define	ld_ent_setup		ld32_ent_setup
1106 #define	ld_init_strings		ld32_init_strings
1107 #define	ld_init_target		ld32_init_target
1108 #define	ld_make_sections	ld32_make_sections
1109 #define	ld_main			ld32_main
1110 #define	ld_ofl_cleanup		ld32_ofl_cleanup
1111 #define	ld_process_open		ld32_process_open
1112 #define	ld_reloc_init		ld32_reloc_init
1113 #define	ld_reloc_process	ld32_reloc_process
1114 #define	ld_sym_validate		ld32_sym_validate
1115 #define	ld_update_outfile	ld32_update_outfile
1116 
1117 #endif
1118 
1119 extern int		ld32_main(int, char **, Half);
1120 extern int		ld64_main(int, char **, Half);
1121 
1122 extern uintptr_t	ld_create_outfile(Ofl_desc *);
1123 extern uintptr_t	ld_ent_setup(Ofl_desc *, Xword);
1124 extern uintptr_t	ld_init_strings(Ofl_desc *);
1125 extern int		ld_init_target(Lm_list *, Half mach);
1126 extern uintptr_t	ld_make_sections(Ofl_desc *);
1127 extern void		ld_ofl_cleanup(Ofl_desc *);
1128 extern Ifl_desc		*ld_process_open(const char *, const char *, int *,
1129 			    Ofl_desc *, Word, Rej_desc *);
1130 extern uintptr_t	ld_reloc_init(Ofl_desc *);
1131 extern uintptr_t	ld_reloc_process(Ofl_desc *);
1132 extern uintptr_t	ld_sym_validate(Ofl_desc *);
1133 extern uintptr_t	ld_update_outfile(Ofl_desc *);
1134 
1135 #ifdef	__cplusplus
1136 }
1137 #endif
1138 
1139 #endif	/* _LIBLD_H */
1140