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