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