xref: /titanic_44/usr/src/cmd/sgs/include/libld.h (revision 0db3240d392634cfff2f95fb6da34b56b8dc574f)
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 2010 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 #include <elfcap.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * Default directory search path manipulation for the link-editor.  YLDIR
48  * indicates which directory in LIBPATH is replaced by the -YL option to cc
49  * and ld.  YUDIR indicates which directory is replaced by -YU.
50  */
51 #define	YLDIR	1
52 #define	YUDIR	2
53 
54 /*
55  * Define a hash value that can never be returned from elf_hash().
56  */
57 #define	SYM_NOHASH	(~(Word)0)
58 
59 /*
60  * Macro that can be used to represent both ORDER flags
61  * in a section header.
62  */
63 #define	ALL_SHF_ORDER	(SHF_ORDERED | SHF_LINK_ORDER)
64 
65 /*
66  * The linker merges (concatenates) sections with the same name and
67  * compatible section header flags. When comparing these flags,
68  * there are some that should not be included in the decision.
69  * The ALL_SHF_IGNORE constant defines these flags.
70  *
71  * NOTE: SHF_MERGE|SHF_STRINGS:
72  * The compiler is allowed to set the SHF_MERGE|SHF_STRINGS flags in
73  * order to tell the linker that:
74  *
75  *      1) There is nothing in the section except null terminated strings.
76  *	2) Those strings do not contain NULL bytes, except as termination.
77  *	3) All references to these strings occur via standard relocation
78  *		records.
79  *
80  * As a result, if two compatible sections both have these flags set, it is
81  * OK to combine the strings they contain into a single merged string table
82  * with duplicates removed and tail strings merged.
83  *
84  * This is a different meaning than the simple concatenating of sections
85  * that the linker always does. It is a hint that an additional optimization
86  * is possible, but not required. This means that sections that do not
87  * share the same SHF_MERGE|SHF_STRINGS values can be concatenated,
88  * but cannot have their duplicate strings combined. Hence, the
89  * SHF_MERGE|SHF_STRINGS flags should be ignored when deciding whether
90  * two sections can be concatenated.
91  */
92 #define	ALL_SHF_IGNORE	(ALL_SHF_ORDER | SHF_GROUP | SHF_MERGE | SHF_STRINGS)
93 
94 /*
95  * Define symbol reference types for use in symbol resolution.
96  */
97 typedef enum {
98 	REF_DYN_SEEN,			/* a .so symbol has been seen */
99 	REF_DYN_NEED,			/* a .so symbol satisfies a .o symbol */
100 	REF_REL_NEED,			/* a .o symbol */
101 	REF_NUM				/* the number of symbol references */
102 } Symref;
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  * The link-editor caches the results of sloppy relocation processing
133  * in a variable of type Rlxrel_cache. Symbols come for processing in sorted
134  * order, so a single item cache suffices to eliminate duplicate lookups.
135  *
136  * When sloppy relocation processing fails, the Rlxrel_rej enum reports
137  * the underlying reason.
138  */
139 typedef enum {
140 	RLXREL_REJ_NONE = 0,	/* Replacement symbol was found */
141 	RLXREL_REJ_TARGET,	/* Target sec disallows relaxed relocations */
142 	RLXREL_REJ_SECTION,	/* Either there is no replacement section, */
143 				/* 	or its attributes are incompatible */
144 	RLXREL_REJ_SYMBOL,	/* Replacement symbol not found */
145 } Rlxrel_rej;
146 
147 typedef struct sreloc_cache {
148 	Sym_desc	*sr_osdp;	/* Original symbol */
149 	Sym_desc	*sr_rsdp;	/* Replacement symbol */
150 	Rlxrel_rej	sr_rej;		/* Reason for failure if NULL sr_rsdp */
151 } Rlxrel_cache;
152 
153 /*
154  * Nodes in an ofl_wrap AVL tree
155  *
156  * wsn_name is the name of the symbol to be wrapped. wsn_wrapname is used
157  * when we need to refer to the wrap symbol, and consists of the symbol
158  * name with a __wrap_ prefix.
159  */
160 typedef struct wrap_sym_node {
161 	avl_node_t	wsn_avlnode;	/* AVL book-keeping */
162 	const char	*wsn_name;	/* Symbol name: XXX */
163 	const char	*wsn_wrapname;	/* Wrap symbol name: __wrap_XXX */
164 } WrapSymNode;
165 
166 /*
167  * Capabilities structures, used to maintain a capabilities set.
168  *
169  * Capabilities can be defined within input relocatable objects, and can be
170  * augmented or replaced by mapfile directives.  In addition, mapfile directives
171  * can be used to exclude capabilities that would otherwise be carried over to
172  * the output object.
173  *
174  * CA_SUNW_HW_1, CA_SUNW_SF_1 and CA_SUNW_HW_2 values are bitmasks.  A current
175  * value, and an exclude value are maintained for each capability.
176  *
177  * There can be multiple CA_SUNW_PLAT and CA_SUNW_MACH entries and thus Alists
178  * are used to collect these entries.  A current list for each capability is
179  * maintained as Capstr entries, which provide for maintaining the strings
180  * eventual index into a string table.  An exclude list is maintained as a
181  * list of string pointers.
182  */
183 typedef struct {
184 	elfcap_mask_t	cm_val;		/* bitmask value */
185 	elfcap_mask_t	cm_exc;		/* bits to exclude from final object */
186 } Capmask;
187 
188 typedef struct {
189 	Alist		*cl_val;	/* string (Capstr) value */
190 	APlist		*cl_exc;	/* strings to exclude from final */
191 } Caplist;				/*	object */
192 
193 typedef	struct {
194 	char		*cs_str;	/* platform or machine name */
195 	Word		cs_ndx;		/* the entries output Cap index */
196 } Capstr;
197 
198 typedef	uint_t		oc_flag_t;
199 typedef	struct {
200 	Capmask		oc_hw_1;	/* CA_SUNW_HW_1 capabilities */
201 	Capmask		oc_sf_1;	/* CA_SUNW_SF_1 capabilities */
202 	Capmask		oc_hw_2;	/* CA_SUNW_HW_2 capabilities */
203 	Caplist		oc_plat;	/* CA_SUNW_PLAT capabilities */
204 	Caplist		oc_mach;	/* CA_SUNW_MACH capabilities */
205 	Capstr		oc_id;		/* CA_SUNW_ID capability */
206 	oc_flag_t	oc_flags;
207 } Objcapset;
208 
209 #define	FLG_OCS_USRDEFID	0x1	/* user defined CA_SUNW_ID */
210 
211 /*
212  * Bitmasks for a single capability. Capabilities come from input objects,
213  * augmented or replaced by mapfile directives. In addition, mapfile directives
214  * can be used to exclude bits that would otherwise be set in the output object.
215  */
216 typedef struct {
217 	elfcap_mask_t	cm_value;	/* Bitmask value */
218 	elfcap_mask_t	cm_exclude;	/* Bits to remove from final object */
219 } CapMask;
220 
221 /*
222  * Combine the bitmask in a CapMask with the exclusion mask and
223  * return the resulting final value.
224  */
225 #define	CAPMASK_VALUE(_cbmp) ((_cbmp)->cm_value & ~(_cbmp)->cm_exclude)
226 
227 typedef struct {
228 	CapMask		c_hw_1;		/* CA_SUNW_HW_1 capabilities */
229 	CapMask		c_sf_1;		/* CA_SUNW_SF_1 capabilities */
230 	CapMask		c_hw_2;		/* CA_SUNW_HW_2 capabilities */
231 } Outcapset;
232 
233 
234 /*
235  * Output file processing structure
236  */
237 typedef Lword ofl_flag_t;
238 struct ofl_desc {
239 	char		*ofl_sgsid;	/* link-editor identification */
240 	const char	*ofl_name;	/* full file name */
241 	Elf		*ofl_elf;	/* elf_memory() elf descriptor */
242 	Elf		*ofl_welf;	/* ELF_C_WRITE elf descriptor */
243 	Ehdr		*ofl_dehdr;	/* default elf header, and new elf */
244 	Ehdr		*ofl_nehdr;	/*	header describing this file */
245 	Phdr		*ofl_phdr;	/* program header descriptor */
246 	Phdr		*ofl_tlsphdr;	/* TLS phdr */
247 	int		ofl_fd;		/* file descriptor */
248 	size_t		ofl_size;	/* image size */
249 	APlist		*ofl_maps;	/* list of input mapfiles */
250 	APlist		*ofl_segs;	/* list of segments */
251 	APlist		*ofl_segs_order; /* SEGMENT_ORDER segments */
252 	avl_tree_t	ofl_segs_avl;	/* O(log N) access to named segments */
253 	APlist		*ofl_ents;	/* list of entrance descriptors */
254 	avl_tree_t	ofl_ents_avl;	/* O(log N) access to named ent. desc */
255 	APlist		*ofl_objs;	/* relocatable object file list */
256 	Word		ofl_objscnt;	/* 	and count */
257 	APlist		*ofl_ars;	/* archive library list */
258 	Word		ofl_arscnt;	/* 	and count */
259 	int		ofl_ars_gsandx; /* archive group argv index. 0 means */
260 					/*	no current group, < 0 means */
261 					/*	error reported. >0 is cur ndx */
262 	Word		ofl_ars_gsndx;	/* current -zrescan-start ofl_ars ndx */
263 	APlist		*ofl_sos;	/* shared object list */
264 	Word		ofl_soscnt;	/* 	and count */
265 	APlist		*ofl_soneed;	/* list of implicitly required .so's */
266 	APlist		*ofl_socntl;	/* list of .so control definitions */
267 	APlist		*ofl_outrels;	/* list of output relocations */
268 	Word		ofl_outrelscnt;	/* 	and count */
269 	APlist		*ofl_actrels;	/* list of relocations to perform */
270 	Word		ofl_actrelscnt;	/* 	and count */
271 	Word		ofl_entrelscnt;	/* no of relocations entered */
272 	Alist		*ofl_copyrels;	/* list of copy relocations */
273 	APlist		*ofl_ordered;	/* list of shf_ordered sections */
274 	APlist		*ofl_symdtent;	/* list of syminfo symbols that need */
275 					/*	to reference .dynamic entries */
276 	APlist		*ofl_ismove;	/* list of .SUNW_move sections */
277 	APlist		*ofl_ismoverel;	/* list of relocation input section */
278 					/* targeting to expanded area */
279 	APlist		*ofl_parsyms; 	/* list of partially initialized */
280 					/*	symbols (ie. move symbols) */
281 	APlist		*ofl_extrarels;	/* relocation sections which have */
282 					/*    a NULL sh_info */
283 	avl_tree_t	*ofl_groups;	/* pointer to head of Groups AVL tree */
284 	APlist		*ofl_initarray;	/* list of init array func names */
285 	APlist		*ofl_finiarray;	/* list of fini array func names */
286 	APlist		*ofl_preiarray;	/* list of preinit array func names */
287 	APlist		*ofl_rtldinfo;	/* list of rtldinfo syms */
288 	APlist		*ofl_osgroups;	/* list of output GROUP sections */
289 	APlist		*ofl_ostlsseg;	/* pointer to sections in TLS segment */
290 	APlist		*ofl_unwind;	/* list of unwind output sections */
291 	Os_desc		*ofl_unwindhdr;	/* Unwind hdr */
292 	avl_tree_t	ofl_symavl;	/* pointer to head of Syms AVL tree */
293 	Sym_desc	**ofl_regsyms;	/* array of potential register */
294 	Word		ofl_regsymsno;	/*    symbols and array count */
295 	Word		ofl_regsymcnt;	/* no. of output register symbols */
296 	Word		ofl_lregsymcnt;	/* no. of local register symbols */
297 	Sym_desc	*ofl_dtracesym;	/* ld -zdtrace= */
298 	ofl_flag_t	ofl_flags;	/* various state bits, args etc. */
299 	ofl_flag_t	ofl_flags1;	/*	more flags */
300 	void		*ofl_entry;	/* entry point (-e and Sym_desc *) */
301 	char		*ofl_filtees;	/* shared objects we are a filter for */
302 	const char	*ofl_soname;	/* (-h option) output file name for */
303 					/*	dynamic structure */
304 	const char	*ofl_interp;	/* interpreter name used by exec() */
305 	char		*ofl_rpath;	/* run path to store in .dynamic */
306 	char		*ofl_config;	/* config path to store in .dynamic */
307 	APlist		*ofl_ulibdirs;	/* user supplied library search list */
308 	APlist		*ofl_dlibdirs;	/* default library search list */
309 	Word		ofl_vercnt;	/* number of versions to generate */
310 	APlist		*ofl_verdesc;	/* list of version descriptors */
311 	size_t		ofl_verdefsz;	/* size of version definition section */
312 	size_t		ofl_verneedsz;	/* size of version needed section */
313 	Word		ofl_entercnt;	/* no. of global symbols entered */
314 	Word		ofl_globcnt;	/* no. of global symbols to output */
315 	Word		ofl_scopecnt;	/* no. of scoped symbols to output */
316 	Word		ofl_dynscopecnt; /* no. scoped syms in .SUNW_ldynsym */
317 	Word		ofl_elimcnt;	/* no. of eliminated symbols */
318 	Word		ofl_locscnt;	/* no. of local symbols in .symtab */
319 	Word		ofl_dynlocscnt;	/* no. local symbols in .SUNW_ldynsym */
320 	Word		ofl_dynsymsortcnt; /* no. ndx in .SUNW_dynsymsort */
321 	Word		ofl_dyntlssortcnt; /* no. ndx in .SUNW_dyntlssort */
322 	Word		ofl_dynshdrcnt;	/* no. of output section in .dynsym */
323 	Word		ofl_shdrcnt;	/* no. of output sections */
324 	Word		ofl_caploclcnt;	/* no. of local capabilities symbols */
325 	Word		ofl_capsymcnt;	/* no. of symbol capabilities entries */
326 					/*	required */
327 	Word		ofl_capchaincnt; /* no. of Capchain symbols */
328 	APlist		*ofl_capgroups;	/* list of capabilities groups */
329 	avl_tree_t	*ofl_capfamilies; /* capability family AVL tree */
330 	Str_tbl		*ofl_shdrsttab;	/* Str_tbl for shdr strtab */
331 	Str_tbl		*ofl_strtab;	/* Str_tbl for symtab strtab */
332 	Str_tbl		*ofl_dynstrtab;	/* Str_tbl for dymsym strtab */
333 	Gotndx		*ofl_tlsldgotndx; /* index to LD TLS_index structure */
334 	Xword		ofl_relocsz;	/* size of output relocations */
335 	Xword		ofl_relocgotsz;	/* size of .got relocations */
336 	Xword		ofl_relocpltsz;	/* size of .plt relocations */
337 	Xword		ofl_relocbsssz;	/* size of .bss (copy) relocations */
338 	Xword		ofl_relocrelsz;	/* size of .rel[a] relocations */
339 	Word		ofl_relocincnt;	/* no. of input relocations */
340 	Word		ofl_reloccnt;	/* tot number of output relocations */
341 	Word		ofl_reloccntsub; /* tot numb of output relocations to */
342 					/*	skip (-zignore) */
343 	Word		ofl_relocrelcnt; /* tot number of relative */
344 					/*	relocations */
345 	Word		ofl_gotcnt;	/* no. of .got entries */
346 	Word		ofl_pltcnt;	/* no. of .plt entries */
347 	Word		ofl_pltpad;	/* no. of .plt padd entries */
348 	Word		ofl_hashbkts;	/* no. of hash buckets required */
349 	Is_desc		*ofl_isbss;	/* .bss input section (globals) */
350 	Is_desc		*ofl_islbss;	/* .lbss input section (globals) */
351 	Is_desc		*ofl_istlsbss;	/* .tlsbss input section (globals) */
352 	Is_desc		*ofl_isparexpn;	/* -z nopartial .data input section */
353 	Os_desc		*ofl_osdynamic;	/* .dynamic output section */
354 	Os_desc		*ofl_osdynsym;	/* .dynsym output section */
355 	Os_desc		*ofl_osldynsym;	/* .SUNW_ldynsym output section */
356 	Os_desc		*ofl_osdynstr;	/* .dynstr output section */
357 	Os_desc		*ofl_osdynsymsort; /* .SUNW_dynsymsort output section */
358 	Os_desc		*ofl_osdyntlssort; /* .SUNW_dyntlssort output section */
359 	Os_desc		*ofl_osgot;	/* .got output section */
360 	Os_desc		*ofl_oshash;	/* .hash output section */
361 	Os_desc		*ofl_osinitarray; /* .initarray output section */
362 	Os_desc		*ofl_osfiniarray; /* .finiarray output section */
363 	Os_desc		*ofl_ospreinitarray; /* .preinitarray output section */
364 	Os_desc		*ofl_osinterp;	/* .interp output section */
365 	Os_desc		*ofl_oscap;	/* .SUNW_cap output section */
366 	Os_desc		*ofl_oscapinfo;	/* .SUNW_capinfo output section */
367 	Os_desc		*ofl_oscapchain; /* .SUNW_capchain output section */
368 	Os_desc		*ofl_osplt;	/* .plt output section */
369 	Os_desc		*ofl_osmove;	/* .SUNW_move output section */
370 	Os_desc		*ofl_osrelhead;	/* first relocation section */
371 	Os_desc		*ofl_osrel;	/* .rel[a] relocation section */
372 	Os_desc		*ofl_osshstrtab; /* .shstrtab output section */
373 	Os_desc		*ofl_osstrtab;	/* .strtab output section */
374 	Os_desc		*ofl_ossymtab;	/* .symtab output section */
375 	Os_desc		*ofl_ossymshndx; /* .symtab_shndx output section */
376 	Os_desc		*ofl_osdynshndx; /* .dynsym_shndx output section */
377 	Os_desc		*ofl_osldynshndx; /* .SUNW_ldynsym_shndx output sec */
378 	Os_desc		*ofl_osverdef;	/* .version definition output section */
379 	Os_desc		*ofl_osverneed;	/* .version needed output section */
380 	Os_desc		*ofl_osversym;	/* .version symbol ndx output section */
381 	Word		ofl_dtflags_1;	/* DT_FLAGS_1 entries */
382 	Word		ofl_dtflags;	/* DT_FLAGS entries */
383 	Os_desc		*ofl_ossyminfo;	/* .SUNW_syminfo output section */
384 	Half		ofl_parexpnndx;	/* -z nopartial section index */
385 					/* Ref. at perform_outreloc() in */
386 					/* libld/{mach}/machrel.c */
387 	Xword		*ofl_checksum;	/* DT_CHECKSUM value address */
388 	char		*ofl_depaudit;	/* dependency auditing required (-P) */
389 	char		*ofl_audit;	/* object auditing required (-p) */
390 	Alist		*ofl_symfltrs;	/* per-symbol filtees and their */
391 	Alist		*ofl_dtsfltrs;	/*	associated .dynamic/.dynstrs */
392 	Objcapset	ofl_ocapset;	/* object capabilities */
393 	Lm_list		*ofl_lml;	/* runtime link-map list */
394 	Gottable	*ofl_gottable;	/* debugging got information */
395 	Rlxrel_cache	ofl_sr_cache;	/* Cache last result from */
396 					/*	sloppy_comdat_reloc() */
397 	APlist		*ofl_maptext;	/* mapfile added text sections */
398 	APlist		*ofl_mapdata;	/* mapfile added data sections */
399 	avl_tree_t	*ofl_wrap;	/* -z wrap symbols */
400 };
401 
402 #define	FLG_OF_DYNAMIC	0x00000001	/* generate dynamic output module */
403 #define	FLG_OF_STATIC	0x00000002	/* generate static output module */
404 #define	FLG_OF_EXEC	0x00000004	/* generate an executable */
405 #define	FLG_OF_RELOBJ	0x00000008	/* generate a relocatable object */
406 #define	FLG_OF_SHAROBJ	0x00000010	/* generate a shared object */
407 #define	FLG_OF_BFLAG	0x00000020	/* do no special plt building: -b */
408 #define	FLG_OF_IGNENV	0x00000040	/* ignore LD_LIBRARY_PATH: -i */
409 #define	FLG_OF_STRIP	0x00000080	/* strip output: -s */
410 #define	FLG_OF_NOWARN	0x00000100	/* disable symbol warnings: -t */
411 #define	FLG_OF_NOUNDEF	0x00000200	/* allow no undefined symbols: -zdefs */
412 #define	FLG_OF_PURETXT	0x00000400	/* allow no text relocations: -ztext */
413 #define	FLG_OF_GENMAP	0x00000800	/* generate a memory map: -m */
414 #define	FLG_OF_DYNLIBS	0x00001000	/* dynamic input allowed: -Bdynamic */
415 #define	FLG_OF_SYMBOLIC	0x00002000	/* bind global symbols: -Bsymbolic */
416 #define	FLG_OF_ADDVERS	0x00004000	/* add version stamp: -Qy */
417 #define	FLG_OF_NOLDYNSYM 0x00008000	/* -znoldynsym set */
418 #define	FLG_OF_IS_ORDER	0x00010000	/* input section ordering within a */
419 					/*	segment is required */
420 #define	FLG_OF_EC_FILES	0x00020000	/* Ent_desc exist w/non-NULL ec_files */
421 #define	FLG_OF_TEXTREL	0x00040000	/* text relocations have been found */
422 #define	FLG_OF_MULDEFS	0x00080000	/* multiple symbols are allowed */
423 #define	FLG_OF_TLSPHDR	0x00100000	/* a TLS program header is required */
424 #define	FLG_OF_BLDGOT	0x00200000	/* build GOT table */
425 #define	FLG_OF_VERDEF	0x00400000	/* record version definitions */
426 #define	FLG_OF_VERNEED	0x00800000	/* record version dependencies */
427 #define	FLG_OF_NOVERSEC 0x01000000	/* don't record version sections */
428 #define	FLG_OF_KEY	0x02000000	/* file requires sort keys */
429 #define	FLG_OF_PROCRED	0x04000000	/* process any symbol reductions by */
430 					/*	effecting the symbol table */
431 					/*	output and relocations */
432 #define	FLG_OF_SYMINFO	0x08000000	/* create a syminfo section */
433 #define	FLG_OF_AUX	0x10000000	/* ofl_filter is an auxiliary filter */
434 #define	FLG_OF_FATAL	0x20000000	/* fatal error during input */
435 #define	FLG_OF_WARN	0x40000000	/* warning during input processing. */
436 #define	FLG_OF_VERBOSE	0x80000000	/* -z verbose flag set */
437 
438 #define	FLG_OF_MAPSYMB	0x000100000000	/* symbolic scope definition seen */
439 #define	FLG_OF_MAPGLOB	0x000200000000	/* global scope definition seen */
440 #define	FLG_OF_COMREL	0x000400000000	/* -z combreloc set, which enables */
441 					/*	DT_RELACNT tracking, */
442 #define	FLG_OF_NOCOMREL	0x000800000000	/* -z nocombreloc set */
443 #define	FLG_OF_AUTOLCL	0x001000000000	/* automatically reduce unspecified */
444 					/*	global symbols to locals */
445 #define	FLG_OF_AUTOELM	0x002000000000	/* automatically eliminate */
446 					/*	unspecified global symbols */
447 #define	FLG_OF_REDLSYM	0x004000000000	/* reduce local symbols */
448 #define	FLG_OF_OS_ORDER	0x008000000000	/* output section ordering required */
449 #define	FLG_OF_OSABI	0x010000000000	/* tag object as ELFOSABI_SOLARIS */
450 #define	FLG_OF_ADJOSCNT	0x020000000000	/* adjust ofl_shdrcnt to accommodate */
451 					/*	discarded sections */
452 #define	FLG_OF_OTOSCAP	0x040000000000	/* convert object capabilities to */
453 					/*	symbol capabilities */
454 #define	FLG_OF_PTCAP	0x080000000000	/* PT_SUNWCAP required */
455 #define	FLG_OF_CAPSTRS	0x100000000000	/* capability strings are required */
456 #define	FLG_OF_EHFRAME	0x200000000000	/* output contains .eh_frame section */
457 
458 /*
459  * In the flags1 arena, establish any options that are applicable to archive
460  * extraction first, and associate a mask.  These values are recorded with any
461  * archive descriptor so that they may be reset should the archive require a
462  * rescan to try and resolve undefined symbols.
463  */
464 #define	FLG_OF1_ALLEXRT	0x0000000001	/* extract all members from an */
465 					/*	archive file */
466 #define	FLG_OF1_WEAKEXT	0x0000000002	/* allow archive extraction to */
467 					/*	resolve weak references */
468 #define	MSK_OF1_ARCHIVE	0x0000000003	/* archive flags mask */
469 
470 #define	FLG_OF1_NOINTRP	0x0000000008	/* -z nointerp flag set */
471 #define	FLG_OF1_ZDIRECT	0x0000000010	/* -z direct flag set */
472 #define	FLG_OF1_NDIRECT	0x0000000020	/* no-direct bindings specified */
473 
474 #define	FLG_OF1_RELDYN	0x0000000100	/* process .dynamic in rel obj */
475 #define	FLG_OF1_NRLXREL	0x0000000200	/* -z norelaxreloc flag set */
476 #define	FLG_OF1_RLXREL	0x0000000400	/* -z relaxreloc flag set */
477 #define	FLG_OF1_IGNORE	0x0000000800	/* ignore unused dependencies */
478 #define	FLG_OF1_NOSGHND	0x0000001000	/* -z nosighandler flag set */
479 #define	FLG_OF1_TEXTOFF 0x0000002000	/* text relocations are ok */
480 #define	FLG_OF1_ABSEXEC	0x0000004000	/* -zabsexec set */
481 #define	FLG_OF1_LAZYLD	0x0000008000	/* lazy loading of objects enabled */
482 #define	FLG_OF1_GRPPRM	0x0000010000	/* dependencies are to have */
483 					/*	GROUPPERM enabled */
484 #define	FLG_OF1_OVRFLW	0x0000020000	/* size exceeds 32-bit limitation */
485 					/*	of 32-bit libld */
486 #define	FLG_OF1_NOPARTI	0x0000040000	/* -znopartial set */
487 #define	FLG_OF1_BSSOREL	0x0000080000	/* output relocation against bss */
488 					/*	section */
489 #define	FLG_OF1_TLSOREL	0x0000100000	/* output relocation against .tlsbss */
490 					/*	section */
491 #define	FLG_OF1_MEMORY	0x0000200000	/* produce a memory model */
492 #define	FLG_OF1_NGLBDIR	0x0000400000	/* no DT_1_DIRECT flag allowed */
493 #define	FLG_OF1_ENCDIFF	0x0000800000	/* host running linker has different */
494 					/*	byte order than output object */
495 #define	FLG_OF1_VADDR	0x0001000000	/* a segment defines explicit vaddr */
496 #define	FLG_OF1_EXTRACT	0x0002000000	/* archive member has been extracted */
497 #define	FLG_OF1_RESCAN	0x0004000000	/* any archives should be rescanned */
498 #define	FLG_OF1_IGNPRC	0x0008000000	/* ignore processing required */
499 #define	FLG_OF1_NCSTTAB	0x0010000000	/* -znocompstrtab set */
500 #define	FLG_OF1_DONE	0x0020000000	/* link-editor processing complete */
501 #define	FLG_OF1_NONREG	0x0040000000	/* non-regular file specified as */
502 					/*	the output file */
503 #define	FLG_OF1_ALNODIR	0x0080000000	/* establish NODIRECT for all */
504 					/*	exported interfaces. */
505 #define	FLG_OF1_OVHWCAP1 0x0100000000	/* override CA_SUNW_HW_1 capabilities */
506 #define	FLG_OF1_OVSFCAP1 0x0200000000	/* override CA_SUNW_SF_1 capabilities */
507 #define	FLG_OF1_OVHWCAP2 0x0400000000	/* override CA_SUNW_HW_2 capabilities */
508 #define	FLG_OF1_OVMACHCAP 0x0800000000	/* override CA_SUNW_MACH capability */
509 #define	FLG_OF1_OVPLATCAP 0x1000000000	/* override CA_SUNW_PLAT capability */
510 #define	FLG_OF1_OVIDCAP	0x2000000000	/* override CA_SUNW_ID capability */
511 
512 /*
513  * Test to see if the output file would allow the presence of
514  * a .dynsym section.
515  */
516 #define	OFL_ALLOW_DYNSYM(_ofl) (((_ofl)->ofl_flags & \
517 	(FLG_OF_DYNAMIC | FLG_OF_RELOBJ)) == FLG_OF_DYNAMIC)
518 
519 /*
520  * Test to see if the output file would allow the presence of
521  * a .SUNW_ldynsym section. The requirements are that a .dynsym
522  * is allowed, and -znoldynsym has not been specified. Note that
523  * even if the answer is True (1), we will only generate one if there
524  * are local symbols that require it.
525  */
526 #define	OFL_ALLOW_LDYNSYM(_ofl) (((_ofl)->ofl_flags & \
527 	(FLG_OF_DYNAMIC | FLG_OF_RELOBJ | FLG_OF_NOLDYNSYM)) == FLG_OF_DYNAMIC)
528 
529 /*
530  * Test to see if relocation processing should be done. This is normally
531  * true, but can be disabled via the '-z noreloc' option. Note that
532  * relocatable objects are still relocated even if '-z noreloc' is present.
533  */
534 #define	OFL_DO_RELOC(_ofl) (((_ofl)->ofl_flags & FLG_OF_RELOBJ) || \
535 	!((_ofl)->ofl_dtflags_1 & DF_1_NORELOC))
536 
537 /*
538  * Determine whether a static executable is being built.
539  */
540 #define	OFL_IS_STATIC_EXEC(_ofl) (((_ofl)->ofl_flags & \
541 	(FLG_OF_STATIC | FLG_OF_EXEC)) == (FLG_OF_STATIC | FLG_OF_EXEC))
542 
543 /*
544  * Determine whether a static object is being built.  This macro is used
545  * to select the appropriate string table, and symbol table that other
546  * sections need to reference.
547  */
548 #define	OFL_IS_STATIC_OBJ(_ofl) ((_ofl)->ofl_flags & \
549 	(FLG_OF_RELOBJ | FLG_OF_STATIC))
550 
551 /*
552  * Macros for counting symbol table entries.  These are used to size symbol
553  * tables and associated sections (.syminfo, SUNW_capinfo, .hash, etc.) and
554  * set required sh_info entries (the offset to the first global symbol).
555  */
556 #define	SYMTAB_LOC_CNT(_ofl)		/* local .symtab entries */	\
557 	(2 +				/*    NULL and STT_FILE */	\
558 	(_ofl)->ofl_shdrcnt +		/*    section symbol */		\
559 	(_ofl)->ofl_caploclcnt +	/*    local capabilities */	\
560 	(_ofl)->ofl_scopecnt +		/*    scoped symbols */		\
561 	(_ofl)->ofl_locscnt)		/*    standard locals */
562 #define	SYMTAB_ALL_CNT(_ofl)		/* all .symtab entries */	\
563 	(SYMTAB_LOC_CNT(_ofl) +		/*    .symtab locals */		\
564 	(_ofl)->ofl_globcnt)		/*    standard globals */
565 
566 #define	DYNSYM_LOC_CNT(_ofl)		/* local .dynsym entries */	\
567 	(1 +				/*    NULL */			\
568 	(_ofl)->ofl_dynshdrcnt +	/*    section symbols */	\
569 	(_ofl)->ofl_caploclcnt +	/*    local capabilities */	\
570 	(_ofl)->ofl_lregsymcnt)		/*    local register symbols */
571 #define	DYNSYM_ALL_CNT(_ofl)		/* all .dynsym entries */	\
572 	(DYNSYM_LOC_CNT(_ofl) +		/*    .dynsym locals */		\
573 	(_ofl)->ofl_globcnt)		/*    standard globals */
574 
575 /*
576  * Define a move descriptor used within relocation structures.
577  */
578 typedef struct {
579 	Move		*mr_move;
580 	Sym_desc	*mr_sym;
581 } Mv_reloc;
582 
583 /*
584  * Relocation (active & output) processing structure - transparent to common
585  * code.
586  *
587  * Note that rel_raddend is primarily only of interest to RELA relocations,
588  * and is set to 0 for REL. However, there is an exception: If FLG_REL_NADDEND
589  * is set, then rel_raddend contains a replacement value for the implicit
590  * addend found in the relocation target.
591  */
592 struct rel_desc {
593 	Os_desc		*rel_osdesc;	/* output section reloc is against */
594 	Is_desc		*rel_isdesc;	/* input section reloc is against */
595 	const char	*rel_sname;	/* symbol name (may be "unknown") */
596 	Sym_desc	*rel_sym;	/* sym relocation is against */
597 	Sym_desc	*rel_usym;	/* strong sym if this is a weak pair */
598 	Mv_reloc	*rel_move;	/* move table information */
599 	Word		rel_flags;	/* misc. flags for relocations */
600 	Word		rel_rtype;	/* relocation type */
601 	Xword		rel_roffset;	/* relocation offset */
602 	Sxword		rel_raddend;	/* addend from input relocation */
603 	Word		rel_typedata;	/* ELF_R_TYPE_DATA(info) */
604 };
605 
606 /*
607  * common flags used on the Rel_desc structure (defined in machrel.h).
608  */
609 #define	FLG_REL_GOT	0x00000001	/* relocation against GOT */
610 #define	FLG_REL_PLT	0x00000002	/* relocation against PLT */
611 #define	FLG_REL_BSS	0x00000004	/* relocation against BSS */
612 #define	FLG_REL_LOAD	0x00000008	/* section loadable */
613 #define	FLG_REL_SCNNDX	0x00000010	/* use section index for symbol ndx */
614 #define	FLG_REL_CLVAL	0x00000020	/* clear VALUE for active relocation */
615 #define	FLG_REL_ADVAL	0x00000040	/* add VALUE for output relocation, */
616 					/*	only relevant to SPARC and */
617 					/*	R_SPARC_RELATIVE */
618 #define	FLG_REL_GOTCL	0x00000080	/* clear the GOT entry.  This is */
619 					/* relevant to RELA relocations, */
620 					/* not REL (i386) relocations */
621 #define	FLG_REL_MOVETAB	0x00000100	/* Relocation against .SUNW_move */
622 					/*	adjustments required before */
623 					/*	actual relocation */
624 #define	FLG_REL_NOINFO	0x00000200	/* Relocation comes from a section */
625 					/*	with a null sh_info field */
626 #define	FLG_REL_REG	0x00000400	/* Relocation target is reg sym */
627 #define	FLG_REL_FPTR	0x00000800	/* relocation against func. desc. */
628 #define	FLG_REL_RFPTR1	0x00001000	/* Relative relocation against */
629 					/*   1st part of FD */
630 #define	FLG_REL_RFPTR2	0x00002000	/* Relative relocation against */
631 					/*   2nd part of FD */
632 #define	FLG_REL_DISP	0x00004000	/* *disp* relocation */
633 #define	FLG_REL_STLS	0x00008000	/* IE TLS reference to */
634 					/*	static TLS GOT index */
635 #define	FLG_REL_DTLS	0x00010000	/* GD TLS reference relative to */
636 					/*	dynamic TLS GOT index */
637 #define	FLG_REL_MTLS	0x00020000	/* LD TLS reference against GOT */
638 #define	FLG_REL_STTLS	0x00040000	/* LE TLS reference directly */
639 					/*	to static tls index */
640 #define	FLG_REL_TLSFIX	0x00080000	/* relocation points to TLS instr. */
641 					/*	which needs updating */
642 #define	FLG_REL_RELA	0x00100000	/* descriptor captures a Rela */
643 #define	FLG_REL_GOTFIX	0x00200000	/* relocation points to GOTOP instr. */
644 					/*	which needs updating */
645 #define	FLG_REL_NADDEND	0x00400000	/* Replace implicit addend in dest */
646 					/*	with value in rel_raddend */
647 					/*	Relevant to REL (i386) */
648 					/*	relocations, not to RELA. */
649 
650 /*
651  * Structure to hold a cache of Relocations.
652  */
653 struct rel_cache {
654 	Rel_desc	*rc_end;
655 	Rel_desc	*rc_free;
656 };
657 
658 /*
659  * Symbol value descriptor.  For relocatable objects, each symbols value is
660  * its offset within its associated section.  Therefore, to uniquely define
661  * each symbol within a reloctable object, record and sort the sh_offset and
662  * symbol value.  This information is used to search for displacement
663  * relocations as part of copy relocation validation.
664  */
665 typedef struct {
666 	Addr		ssv_value;
667 	Sym_desc	*ssv_sdp;
668 } Ssv_desc;
669 
670 /*
671  * Input file processing structures.
672  */
673 struct ifl_desc {			/* input file descriptor */
674 	const char	*ifl_name;	/* full file name */
675 	const char	*ifl_soname;	/* shared object name */
676 	dev_t		ifl_stdev;	/* device id and inode number for .so */
677 	ino_t		ifl_stino;	/*	multiple inclusion checks */
678 	Ehdr		*ifl_ehdr;	/* elf header describing this file */
679 	Elf		*ifl_elf;	/* elf descriptor for this file */
680 	Sym_desc	**ifl_oldndx;	/* original symbol table indices */
681 	Sym_desc	*ifl_locs;	/* symbol desc version of locals */
682 	Ssv_desc	*ifl_sortsyms;	/* sorted list of symbols by value */
683 	Word		ifl_locscnt;	/* no. of local symbols to process */
684 	Word		ifl_symscnt;	/* total no. of symbols to process */
685 	Word		ifl_sortcnt;	/* no. of sorted symbols to process */
686 	Word		ifl_shnum;	/* number of sections in file */
687 	Word		ifl_shstrndx;	/* index to .shstrtab */
688 	Word		ifl_vercnt;	/* number of versions in file */
689 	Half		ifl_neededndx;	/* index to NEEDED in .dyn section */
690 	Word		ifl_flags;	/* explicit/implicit reference */
691 	Is_desc		**ifl_isdesc;	/* isdesc[scn ndx] = Is_desc ptr */
692 	Sdf_desc	*ifl_sdfdesc;	/* control definition */
693 	Versym		*ifl_versym;	/* version symbol table array */
694 	Ver_index	*ifl_verndx;	/* verndx[ver ndx] = Ver_index */
695 	APlist		*ifl_verdesc;	/* version descriptor list */
696 	APlist		*ifl_relsect;	/* relocation section list */
697 	Alist		*ifl_groups;	/* SHT_GROUP section list */
698 	Cap_desc	*ifl_caps;	/* capabilities descriptor */
699 };
700 
701 #define	FLG_IF_CMDLINE	0x00000001	/* full filename specified from the */
702 					/*	command line (no -l) */
703 #define	FLG_IF_NEEDED	0x00000002	/* shared object should be recorded */
704 #define	FLG_IF_DIRECT	0x00000004	/* establish direct bindings to this */
705 					/*	object */
706 #define	FLG_IF_EXTRACT	0x00000008	/* file extracted from an archive */
707 #define	FLG_IF_VERNEED	0x00000010	/* version dependency information is */
708 					/*	required */
709 #define	FLG_IF_DEPREQD	0x00000020	/* dependency is required to satisfy */
710 					/*	symbol references */
711 #define	FLG_IF_NEEDSTR	0x00000040	/* dependency specified by -Nn */
712 					/*	flag */
713 #define	FLG_IF_IGNORE	0x00000080	/* ignore unused dependencies */
714 #define	FLG_IF_NODIRECT	0x00000100	/* object contains symbols that */
715 					/*	cannot be directly bound to */
716 #define	FLG_IF_LAZYLD	0x00000200	/* bindings to this object should be */
717 					/*	lazy loaded */
718 #define	FLG_IF_GRPPRM	0x00000400	/* this dependency should have the */
719 					/*	DF_P1_GROUPPERM flag set */
720 #define	FLG_IF_DISPPEND 0x00000800	/* displacement relocation done */
721 					/*	in the ld time. */
722 #define	FLG_IF_DISPDONE 0x00001000	/* displacement relocation done */
723 					/* 	at the run time */
724 #define	FLG_IF_MAPFILE	0x00002000	/* file is a mapfile */
725 #define	FLG_IF_HSTRTAB	0x00004000	/* file has a string section */
726 #define	FLG_IF_FILEREF	0x00008000	/* file contains a section which */
727 					/*	is included in the output */
728 					/*	allocatable image */
729 #define	FLG_IF_GNUVER	0x00010000	/* file used GNU-style versioning */
730 #define	FLG_IF_ORDERED	0x00020000	/* ordered section processing */
731 					/*	required */
732 #define	FLG_IF_OTOSCAP	0x00040000	/* convert object capabilities to */
733 					/*	symbol capabilities */
734 
735 struct is_desc {			/* input section descriptor */
736 	const char	*is_name;	/* original section name */
737 	Shdr		*is_shdr;	/* the elf section header */
738 	Ifl_desc	*is_file;	/* infile desc for this section */
739 	Os_desc		*is_osdesc;	/* new output section for this */
740 					/*	input section */
741 	Elf_Data	*is_indata;	/* input sections raw data */
742 	Is_desc		*is_symshndx;	/* related SHT_SYM_SHNDX section */
743 	Is_desc		*is_comdatkeep;	/* If COMDAT section is discarded, */
744 					/* 	this is section that was kept */
745 	Word		is_scnndx;	/* original section index in file */
746 	Word		is_ordndx;	/* index for section.  Used to decide */
747 					/*	where to insert section when */
748 					/* 	reordering sections */
749 	Word		is_keyident;	/* key for SHF_{ORDERED|LINK_ORDER} */
750 					/*	processing and ident used for */
751 					/*	 placing/ordering sections */
752 	Word		is_flags;	/* Various flags */
753 };
754 
755 #define	FLG_IS_ORDERED	0x0001		/* this is a SHF_ORDERED section */
756 #define	FLG_IS_KEY	0x0002		/* section requires sort keys */
757 #define	FLG_IS_DISCARD	0x0004		/* section is to be discarded */
758 #define	FLG_IS_RELUPD	0x0008		/* symbol defined here may have moved */
759 #define	FLG_IS_SECTREF	0x0010		/* section has been referenced */
760 #define	FLG_IS_GDATADEF	0x0020		/* section contains global data sym */
761 #define	FLG_IS_EXTERNAL	0x0040		/* isp from a user file */
762 #define	FLG_IS_INSTRMRG	0x0080		/* Usable SHF_MERGE|SHF_STRINGS sec */
763 #define	FLG_IS_GNSTRMRG	0x0100		/* Generated mergeable string section */
764 #define	FLG_IS_GROUPS	0x0200		/* section has groups to process */
765 #define	FLG_IS_PLACE	0x0400		/* section requires to be placed */
766 #define	FLG_IS_COMDAT	0x0800		/* section is COMDAT */
767 #define	FLG_IS_EHFRAME	0x1000		/* section is .eh_frame */
768 
769 /*
770  * Output sections contain lists of input sections that are assigned to them.
771  * These items fall into 4 categories:
772  *	BEFORE - Ordered sections that specify SHN_BEFORE, in input order.
773  *	ORDERED - Ordered sections that are sorted using unsorted sections
774  *		as the sort key.
775  *	DEFAULT - Sections that are placed into the output section
776  *		in input order.
777  *	AFTER - Ordered sections that specify SHN_AFTER, in input order.
778  */
779 #define	OS_ISD_BEFORE	0
780 #define	OS_ISD_ORDERED	1
781 #define	OS_ISD_DEFAULT	2
782 #define	OS_ISD_AFTER	3
783 #define	OS_ISD_NUM	4
784 typedef APlist *os_isdecs_arr[OS_ISD_NUM];
785 
786 /*
787  * Convenience macro for traversing every input section associated
788  * with a given output section. The primary benefit of this macro
789  * is that it preserves a precious level of code indentation in the
790  * code that uses it.
791  */
792 #define	OS_ISDESCS_TRAVERSE(_list_idx, _osp, _idx, _isp) \
793 	for (_list_idx = 0; _list_idx < OS_ISD_NUM; _list_idx++) \
794 		for (APLIST_TRAVERSE(_osp->os_isdescs[_list_idx], _idx, _isp))
795 
796 
797 /*
798  * Map file and output file processing structures
799  */
800 struct os_desc {			/* Output section descriptor */
801 	const char	*os_name;	/* the section name */
802 	Elf_Scn		*os_scn;	/* the elf section descriptor */
803 	Shdr		*os_shdr;	/* the elf section header */
804 	Os_desc		*os_relosdesc;	/* the output relocation section */
805 	APlist		*os_relisdescs;	/* reloc input section descriptors */
806 					/*	for this output section */
807 	os_isdecs_arr	os_isdescs;	/* lists of input sections in output */
808 	APlist		*os_mstrisdescs; /* FLG_IS_INSTRMRG input sections */
809 	Sg_desc		*os_sgdesc;	/* segment os_desc is placed on */
810 	Elf_Data	*os_outdata;	/* output sections raw data */
811 	avl_tree_t	*os_comdats;	/* AVL tree of COMDAT input sections */
812 					/*	associated to output section */
813 	Word		os_identndx;	/* section identifier for input */
814 					/*	section processing, followed */
815 					/*	by section symbol index */
816 	Word		os_ordndx;	/* index for section.  Used to decide */
817 					/*	where to insert section when */
818 					/* 	reordering sections */
819 	Xword		os_szoutrels;	/* size of output relocation section */
820 	uint_t		os_namehash;	/* hash on section name */
821 	uchar_t		os_flags;	/* various flags */
822 };
823 
824 #define	FLG_OS_KEY		0x01	/* section requires sort keys */
825 #define	FLG_OS_OUTREL		0x02	/* output rel against this section */
826 #define	FLG_OS_SECTREF		0x04	/* isps are not affected by -zignore */
827 #define	FLG_OS_EHFRAME		0x08	/* section is .eh_frame */
828 
829 /*
830  * The sg_id field of the segment descriptor is used to establish the default
831  * order for program headers and segments in the output object. Segments are
832  * ordered according to the following SGID values that classify them based on
833  * their attributes. The initial set of built in segments are in this order,
834  * and new mapfile defined segments are inserted into these groups. Within a
835  * given SGID group, the position of new segments depends on the syntax
836  * version of the mapfile that creates them. Version 1 (original sysv)
837  * mapfiles place the new segment at the head of their group (reverse creation
838  * order). The newer syntax places them at the end, following the others
839  * (creation order).
840  *
841  * Note that any new segments must always be added after PT_PHDR and
842  * PT_INTERP (refer Generic ABI, Page 5-4).
843  */
844 #define	SGID_PHDR	0	/* PT_PHDR */
845 #define	SGID_INTERP	1	/* PT_INTERP */
846 #define	SGID_SUNWCAP	2	/* PT_SUNWCAP */
847 #define	SGID_TEXT	3	/* PT_LOAD */
848 #define	SGID_DATA	4	/* PT_LOAD */
849 #define	SGID_BSS	5	/* PT_LOAD */
850 #if	defined(_ELF64)
851 #define	SGID_LRODATA	6	/* PT_LOAD (amd64-only) */
852 #define	SGID_LDATA	7	/* PT_LOAD (amd64-only) */
853 #endif
854 #define	SGID_TEXT_EMPTY	8	/* PT_LOAD, reserved (?E in version 1 syntax) */
855 #define	SGID_NULL_EMPTY	9	/* PT_NULL, reserved (?E in version 1 syntax) */
856 #define	SGID_DYN	10	/* PT_DYNAMIC */
857 #define	SGID_DTRACE	11	/* PT_SUNWDTRACE */
858 #define	SGID_TLS	12	/* PT_TLS */
859 #define	SGID_UNWIND	13	/* PT_SUNW_UNWIND */
860 #define	SGID_SUNWSTACK	14	/* PT_SUNWSTACK */
861 #define	SGID_NOTE	15	/* PT_NOTE */
862 #define	SGID_NULL	16	/* PT_NULL,  mapfile defined empty phdr slots */
863 				/*	for use by post processors */
864 #define	SGID_EXTRA	17	/* PT_NULL (final catchall) */
865 
866 typedef Half sg_flags_t;
867 struct sg_desc {			/* output segment descriptor */
868 	Word		sg_id;		/* segment identifier (for sorting) */
869 	Phdr		sg_phdr;	/* segment header for output file */
870 	const char	*sg_name;	/* segment name for PT_LOAD, PT_NOTE, */
871 					/*	and PT_NULL, otherwise NULL */
872 	Xword		sg_round;	/* data rounding required (mapfile) */
873 	Xword		sg_length;	/* maximum segment length; if 0 */
874 					/*	segment is not specified */
875 	APlist		*sg_osdescs;	/* list of output section descriptors */
876 	APlist		*sg_is_order;	/* list of entry criteria */
877 					/*	giving input section order */
878 	Alist		*sg_os_order;	/* list specifying output section */
879 					/*	ordering for the segment */
880 	sg_flags_t	sg_flags;
881 	APlist		*sg_sizesym;	/* size symbols for this segment */
882 	Xword		sg_align;	/* LCM of sh_addralign */
883 	Elf_Scn		*sg_fscn;	/* the SCN of the first section. */
884 	avl_node_t	sg_avlnode;	/* AVL book-keeping */
885 };
886 
887 #define	FLG_SG_P_VADDR		0x0001	/* p_vaddr segment attribute set */
888 #define	FLG_SG_P_PADDR		0x0002	/* p_paddr segment attribute set */
889 #define	FLG_SG_LENGTH		0x0004	/* length segment attribute set */
890 #define	FLG_SG_P_ALIGN		0x0008	/* p_align segment attribute set */
891 #define	FLG_SG_ROUND		0x0010	/* round segment attribute set */
892 #define	FLG_SG_P_FLAGS		0x0020	/* p_flags segment attribute set */
893 #define	FLG_SG_P_TYPE		0x0040	/* p_type segment attribute set */
894 #define	FLG_SG_IS_ORDER		0x0080	/* input section ordering is required */
895 					/* 	for this segment. */
896 #define	FLG_SG_NOHDR		0x0100	/* don't map ELF or phdrs into */
897 					/*	this segment */
898 #define	FLG_SG_EMPTY		0x0200	/* an empty segment specification */
899 					/*	no input sections will be */
900 					/*	associated to this section */
901 #define	FLG_SG_KEY		0x0400	/* segment requires sort keys */
902 #define	FLG_SG_NODISABLE	0x0800	/* FLG_SG_DISABLED is not allowed on */
903 					/*	this segment */
904 #define	FLG_SG_DISABLED		0x1000	/* this segment is disabled */
905 #define	FLG_SG_PHREQ		0x2000	/* this segment requires a program */
906 					/* header */
907 #define	FLG_SG_ORDERED		0x4000	/* SEGMENT_ORDER segment */
908 
909 struct sec_order {
910 	const char	*sco_secname;	/* section name to be ordered */
911 	Half		sco_flags;
912 };
913 
914 #define	FLG_SGO_USED	0x0001		/* was ordering used? */
915 
916 typedef Half ec_flags_t;
917 struct ent_desc {			/* input section entrance criteria */
918 	const char	*ec_name;	/* entrace criteria name, or NULL */
919 	Alist		*ec_files;	/* files from which to accept */
920 					/*	sections */
921 	const char	*ec_is_name;	/* input section name to match */
922 					/*	(NULL if none) */
923 	Word		ec_type;	/* section type */
924 	Word		ec_attrmask;	/* section attribute mask (AWX) */
925 	Word		ec_attrbits;	/* sections attribute bits */
926 	Sg_desc		*ec_segment;	/* output segment to enter if matched */
927 	Word		ec_ordndx;	/* index to determine where section */
928 					/*	meeting this criteria should */
929 					/*	inserted. Used for reordering */
930 					/*	of sections. */
931 	ec_flags_t	ec_flags;
932 	avl_node_t	ec_avlnode;	/* AVL book-keeping */
933 };
934 
935 #define	FLG_EC_BUILTIN	0x0001		/* built in descriptor */
936 #define	FLG_EC_USED	0x0002		/* entrance criteria met? */
937 #define	FLG_EC_CATCHALL	0x0004		/* Catches any section */
938 
939 /*
940  * Ent_desc_file is the type of element maintained in the ec_files Alist
941  * of an entrance criteria descriptor. Each item maintains one file
942  * path, and a set of flags that specify the type of comparison it implies,
943  * and other information about it. The comparison type is maintained in
944  * the bottom byte of the flags.
945  */
946 #define	TYP_ECF_MASK		0x00ff  /* Comparison type mask */
947 #define	TYP_ECF_PATH		0	/* Compare to file path */
948 #define	TYP_ECF_BASENAME	1	/* Compare to file basename */
949 #define	TYP_ECF_OBJNAME		2	/* Compare to regular file basename, */
950 					/*	 or to archive member name */
951 #define	TYP_ECF_NUM		3
952 
953 #define	FLG_ECF_ARMEMBER	0x0100	/* name includes archive member */
954 
955 typedef struct {
956 	Word		edf_flags;	/* Type of comparison */
957 	const char	*edf_name;	/* String to compare to */
958 	size_t		edf_name_len;	/* strlen(edf_name) */
959 } Ent_desc_file;
960 
961 /*
962  * One structure is allocated for a move entry, and associated to the symbol
963  * against which a move is targeted.
964  */
965 typedef struct {
966 	Move		*md_move;	/* original Move entry */
967 	Xword		md_start;	/* start position */
968 	Xword		md_len;		/* length of initialization */
969 	Word 		md_oidx;	/* output Move entry index */
970 } Mv_desc;
971 
972 /*
973  * Symbol descriptor.
974  */
975 typedef	Lword		sd_flag_t;
976 struct sym_desc {
977 	Alist		*sd_GOTndxs;	/* list of associated GOT entries */
978 	Sym		*sd_sym;	/* pointer to symbol table entry */
979 	Sym		*sd_osym;	/* copy of the original symbol entry */
980 					/*	used only for local partial */
981 	Alist		*sd_move;	/* move information associated with a */
982 					/*	partially initialized symbol */
983 	const char	*sd_name;	/* symbols name */
984 	Ifl_desc	*sd_file;	/* file where symbol is taken */
985 	Is_desc		*sd_isc;	/* input section of symbol definition */
986 	Sym_aux		*sd_aux;	/* auxiliary global symbol info. */
987 	Word		sd_symndx;	/* index in output symbol table */
988 	Word		sd_shndx;	/* sect. index sym is associated w/ */
989 	sd_flag_t	sd_flags;	/* state flags */
990 	Half		sd_ref;		/* reference definition of symbol */
991 };
992 
993 /*
994  * The auxiliary symbol descriptor contains the additional information (beyond
995  * the symbol descriptor) required to process global symbols.  These symbols are
996  * accessed via an internal symbol hash table where locality of reference is
997  * important for performance.
998  */
999 struct sym_aux {
1000 	APlist 		*sa_dfiles;	/* files where symbol is defined */
1001 	Sym		sa_sym;		/* copy of symtab entry */
1002 	const char	*sa_vfile;	/* first unavailable definition */
1003 	const char	*sa_rfile;	/* file with first symbol referenced */
1004 	Word		sa_hash;	/* the pure hash value of symbol */
1005 	Word		sa_PLTndx;	/* index into PLT for symbol */
1006 	Word		sa_PLTGOTndx;	/* GOT entry indx for PLT indirection */
1007 	Word		sa_linkndx;	/* index of associated symbol from */
1008 					/*	ET_DYN file */
1009 	Half		sa_symspec;	/* special symbol ids */
1010 	Half		sa_overndx;	/* output file versioning index */
1011 	Half		sa_dverndx;	/* dependency versioning index */
1012 };
1013 
1014 /*
1015  * Nodes used to track symbols in the global AVL symbol dictionary.
1016  */
1017 struct sym_avlnode {
1018 	avl_node_t	sav_node;	/* AVL node */
1019 	Word		sav_hash;	/* symbol hash value */
1020 	const char	*sav_name;	/* symbol name */
1021 	Sym_desc	*sav_sdp;	/* symbol descriptor */
1022 };
1023 
1024 /*
1025  * These are the ids for processing of `Special symbols'.  They are used
1026  * to set the sym->sd_aux->sa_symspec field.
1027  */
1028 #define	SDAUX_ID_ETEXT	1		/* etext && _etext symbol */
1029 #define	SDAUX_ID_EDATA	2		/* edata && _edata symbol */
1030 #define	SDAUX_ID_END	3		/* end, _end, && _END_ symbol */
1031 #define	SDAUX_ID_DYN	4		/* DYNAMIC && _DYNAMIC symbol */
1032 #define	SDAUX_ID_PLT	5		/* _PROCEDURE_LINKAGE_TABLE_ symbol */
1033 #define	SDAUX_ID_GOT	6		/* _GLOBAL_OFFSET_TABLE_ symbol */
1034 #define	SDAUX_ID_START	7		/* START_ && _START_ symbol */
1035 
1036 /*
1037  * Flags for sym_desc.sd_flags
1038  */
1039 #define	FLG_SY_MVTOCOMM	0x00000001	/* assign symbol to common (.bss) */
1040 					/*	this is a result of a */
1041 					/*	copy reloc against sym */
1042 #define	FLG_SY_GLOBREF	0x00000002	/* a global reference has been seen */
1043 #define	FLG_SY_WEAKDEF	0x00000004	/* a weak definition has been used */
1044 #define	FLG_SY_CLEAN	0x00000008	/* `Sym' entry points to original */
1045 					/*	input file (read-only). */
1046 #define	FLG_SY_UPREQD	0x00000010	/* symbol value update is required, */
1047 					/*	either it's used as an entry */
1048 					/*	point or for relocation, but */
1049 					/*	it must be updated even if */
1050 					/*	the -s flag is in effect */
1051 #define	FLG_SY_NOTAVAIL	0x00000020	/* symbol is not available to the */
1052 					/*	application either because it */
1053 					/*	originates from an implicitly */
1054 					/* 	referenced shared object, or */
1055 					/*	because it is not part of a */
1056 					/*	specified version. */
1057 #define	FLG_SY_REDUCED	0x00000040	/* a global is reduced to local */
1058 #define	FLG_SY_VERSPROM	0x00000080	/* version definition has been */
1059 					/*	promoted to output file */
1060 #define	FLG_SY_PROT	0x00000100	/* stv_protected visibility seen */
1061 #define	FLG_SY_MAPREF	0x00000200	/* symbol reference generated by user */
1062 					/*	from mapfile */
1063 #define	FLG_SY_REFRSD	0x00000400	/* symbols sd_ref has been raised */
1064 					/* 	due to a copy-relocs */
1065 					/*	weak-strong pairing */
1066 #define	FLG_SY_INTPOSE	0x00000800	/* symbol defines an interposer */
1067 #define	FLG_SY_INVALID	0x00001000	/* unwanted/erroneous symbol */
1068 #define	FLG_SY_SMGOT	0x00002000	/* small got index assigned to symbol */
1069 					/*	sparc only */
1070 #define	FLG_SY_PARENT	0x00004000	/* symbol to be found in parent */
1071 					/*    only used with direct bindings */
1072 #define	FLG_SY_LAZYLD	0x00008000	/* symbol to cause lazyloading of */
1073 					/*	parent object */
1074 #define	FLG_SY_ISDISC	0x00010000	/* symbol is a member of a DISCARDED */
1075 					/*	section (COMDAT) */
1076 #define	FLG_SY_PAREXPN	0x00020000	/* partially init. symbol to be */
1077 					/*	expanded */
1078 #define	FLG_SY_PLTPAD	0x00040000	/* pltpadding has been allocated for */
1079 					/*	this symbol */
1080 #define	FLG_SY_REGSYM	0x00080000	/* REGISTER symbol (sparc only) */
1081 #define	FLG_SY_SOFOUND	0x00100000	/* compared against an SO definition */
1082 #define	FLG_SY_EXTERN	0x00200000	/* symbol is external, allows -zdefs */
1083 					/*    error suppression */
1084 #define	FLG_SY_MAPUSED	0x00400000	/* mapfile symbol used (occurred */
1085 					/*    within a relocatable object) */
1086 #define	FLG_SY_COMMEXP	0x00800000	/* COMMON symbol which has been */
1087 					/*	allocated */
1088 #define	FLG_SY_CMDREF	0x01000000	/* symbol was referenced from the */
1089 					/*	command line.  (ld -u <>, */
1090 					/*	ld -zrtldinfo=<>, ...) */
1091 #define	FLG_SY_SPECSEC	0x02000000	/* section index is reserved value */
1092 					/*	ABS, COMMON, ... */
1093 #define	FLG_SY_TENTSYM	0x04000000	/* tentative symbol */
1094 #define	FLG_SY_VISIBLE	0x08000000	/* symbols visibility determined */
1095 #define	FLG_SY_STDFLTR	0x10000000	/* symbol is a standard filter */
1096 #define	FLG_SY_AUXFLTR	0x20000000	/* symbol is an auxiliary filter */
1097 #define	FLG_SY_DYNSORT	0x40000000	/* req. in dyn[sym|tls]sort section */
1098 #define	FLG_SY_NODYNSORT 0x80000000	/* excluded from dyn[sym_tls]sort sec */
1099 
1100 #define	FLG_SY_DEFAULT	0x0000100000000	/* global symbol, default */
1101 #define	FLG_SY_SINGLE	0x0000200000000	/* global symbol, singleton defined */
1102 #define	FLG_SY_PROTECT	0x0000400000000	/* global symbol, protected defined */
1103 #define	FLG_SY_EXPORT	0x0000800000000	/* global symbol, exported defined */
1104 
1105 #define	MSK_SY_GLOBAL \
1106 	(FLG_SY_DEFAULT | FLG_SY_SINGLE | FLG_SY_PROTECT | FLG_SY_EXPORT)
1107 					/* this mask indicates that the */
1108 					/*    symbol has been explicitly */
1109 					/*    defined within a mapfile */
1110 					/*    definition, and is a candidate */
1111 					/*    for versioning */
1112 
1113 #define	FLG_SY_HIDDEN	0x0001000000000	/* global symbol, reduce to local */
1114 #define	FLG_SY_ELIM	0x0002000000000	/* global symbol, eliminate */
1115 #define	FLG_SY_IGNORE	0x0004000000000	/* global symbol, ignored */
1116 
1117 #define	MSK_SY_LOCAL	(FLG_SY_HIDDEN | FLG_SY_ELIM | FLG_SY_IGNORE)
1118 					/* this mask allows all local state */
1119 					/*    flags to be removed when the */
1120 					/*    symbol is copy relocated */
1121 
1122 #define	FLG_SY_EXPDEF	0x0008000000000	/* symbol visibility defined */
1123 					/*    explicitly */
1124 
1125 #define	MSK_SY_NOAUTO	(FLG_SY_SINGLE | FLG_SY_EXPORT | FLG_SY_EXPDEF)
1126 					/* this mask indicates that the */
1127 					/*    symbol is not a candidate for */
1128 					/*    auto-reduction/elimination */
1129 
1130 #define	FLG_SY_MAPFILE	0x0010000000000	/* symbol attribute defined in a */
1131 					/*    mapfile */
1132 #define	FLG_SY_DIR	0x0020000000000	/* global symbol, direct bindings */
1133 #define	FLG_SY_NDIR	0x0040000000000	/* global symbol, nondirect bindings */
1134 #define	FLG_SY_OVERLAP	0x0080000000000	/* move entry overlap detected */
1135 #define	FLG_SY_CAP	0x0100000000000	/* symbol is associated with */
1136 					/*    capabilities */
1137 
1138 /*
1139  * A symbol can only be truly hidden if it is not a capabilities symbol.
1140  */
1141 #define	SYM_IS_HIDDEN(_sdp) \
1142 	(((_sdp)->sd_flags & (FLG_SY_HIDDEN | FLG_SY_CAP)) == FLG_SY_HIDDEN)
1143 
1144 /*
1145  * Create a mask for (sym.st_other & visibility) since the gABI does not yet
1146  * define a ELF*_ST_OTHER macro.
1147  */
1148 #define	MSK_SYM_VISIBILITY	0x7
1149 
1150 /*
1151  * Structure to manage the shared object definition lists.  There are two lists
1152  * that use this structure:
1153  *
1154  *  -	ofl_soneed; maintain the list of implicitly required dependencies
1155  *	(ie. shared objects needed by other shared objects).  These definitions
1156  *	may include RPATH's required to locate the dependencies, and any
1157  *	version requirements.
1158  *
1159  *  -	ofl_socntl; maintains the shared object control definitions.  These are
1160  *	provided by the user (via a mapfile) and are used to indicate any
1161  *	version control requirements.
1162  */
1163 struct	sdf_desc {
1164 	const char	*sdf_name;	/* the shared objects file name */
1165 	char		*sdf_rpath;	/* library search path DT_RPATH */
1166 	const char	*sdf_rfile;	/* referencing file for diagnostics */
1167 	Ifl_desc	*sdf_file;	/* the final input file descriptor */
1168 	Alist		*sdf_vers;	/* list of versions that are required */
1169 					/*	from this object */
1170 	Alist		*sdf_verneed;	/* list of VERNEEDS to create for */
1171 					/*	object via mapfile ADDVERS */
1172 	Word		sdf_flags;
1173 };
1174 
1175 #define	FLG_SDF_SELECT	0x01		/* version control selection required */
1176 #define	FLG_SDF_VERIFY	0x02		/* version definition verification */
1177 					/*	required */
1178 #define	FLG_SDF_ADDVER	0x04		/* add VERNEED references */
1179 
1180 /*
1181  * Structure to manage shared object version usage requirements.
1182  */
1183 struct	sdv_desc {
1184 	const char	*sdv_name;	/* version name */
1185 	const char	*sdv_ref;	/* versions reference */
1186 	Word		sdv_flags;	/* flags */
1187 };
1188 
1189 #define	FLG_SDV_MATCHED	0x01		/* VERDEF found and matched */
1190 
1191 /*
1192  * Structures to manage versioning information.  Two versioning structures are
1193  * defined:
1194  *
1195  *   -	a version descriptor maintains a linked list of versions and their
1196  *	associated dependencies.  This is used to build the version definitions
1197  *	for an image being created (see map_symbol), and to determine the
1198  *	version dependency graph for any input files that are versioned.
1199  *
1200  *   -	a version index array contains each version of an input file that is
1201  *	being processed.  It informs us which versions are available for
1202  *	binding, and is used to generate any version dependency information.
1203  */
1204 struct	ver_desc {
1205 	const char	*vd_name;	/* version name */
1206 	Ifl_desc	*vd_file;	/* file that defined version */
1207 	Word		vd_hash;	/* hash value of name */
1208 	Half		vd_ndx;		/* coordinates with symbol index */
1209 	Half		vd_flags;	/* version information */
1210 	APlist		*vd_deps;	/* version dependencies */
1211 	Ver_desc	*vd_ref;	/* dependency's first reference */
1212 };
1213 
1214 struct	ver_index {
1215 	const char	*vi_name;	/* dependency version name */
1216 	Half		vi_flags;	/* communicates availability */
1217 	Half		vi_overndx;	/* index assigned to this version in */
1218 					/*	output object Verneed section */
1219 	Ver_desc	*vi_desc;	/* cross reference to descriptor */
1220 };
1221 
1222 /*
1223  * Define any internal version descriptor flags ([vd|vi]_flags).  Note that the
1224  * first byte is reserved for user visible flags (refer VER_FLG's in link.h).
1225  */
1226 #define	MSK_VER_USER	0x0f		/* mask for user visible flags */
1227 
1228 #define	FLG_VER_AVAIL	0x10		/* version is available for binding */
1229 #define	FLG_VER_REFER	0x20		/* version has been referenced */
1230 #define	FLG_VER_CYCLIC	0x40		/* a member of cyclic dependency */
1231 
1232 /*
1233  * isalist(1) descriptor - used to break an isalist string into its component
1234  * options.
1235  */
1236 struct	isa_opt {
1237 	char		*isa_name;	/* individual isa option name */
1238 	size_t		isa_namesz;	/*	and associated size */
1239 };
1240 
1241 struct	isa_desc {
1242 	char		*isa_list;	/* sysinfo(SI_ISALIST) list */
1243 	size_t		isa_listsz;	/*	and associated size */
1244 	Isa_opt		*isa_opt;	/* table of individual isa options */
1245 	size_t		isa_optno;	/*	and associated number */
1246 };
1247 
1248 /*
1249  * uname(2) descriptor - used to break a utsname structure into its component
1250  * options (at least those that we're interested in).
1251  */
1252 struct	uts_desc {
1253 	char		*uts_osname;	/* operating system name */
1254 	size_t		uts_osnamesz;	/*	and associated size */
1255 	char		*uts_osrel;	/* operating system release */
1256 	size_t		uts_osrelsz;	/*	and associated size */
1257 };
1258 
1259 /*
1260  * SHT_GROUP descriptor - used to track group sections at the global
1261  * level to resolve conflicts and determine which to keep.
1262  */
1263 struct group_desc {
1264 	Is_desc		*gd_isc;	/* input section descriptor */
1265 	Is_desc		*gd_oisc;	/* overriding input section */
1266 					/*	descriptor when discarded */
1267 	const char	*gd_name;	/* group name (signature symbol) */
1268 	Word		*gd_data;	/* data for group section */
1269 	size_t		gd_cnt;		/* number of entries in group data */
1270 };
1271 
1272 /*
1273  * Indexes into the ld_support_funcs[] table.
1274  */
1275 typedef enum {
1276 	LDS_VERSION = 0,	/* Must be first and have value 0 */
1277 	LDS_INPUT_DONE,
1278 	LDS_START,
1279 	LDS_ATEXIT,
1280 	LDS_OPEN,
1281 	LDS_FILE,
1282 	LDS_INSEC,
1283 	LDS_SEC,
1284 	LDS_NUM
1285 } Support_ndx;
1286 
1287 /*
1288  * Structure to manage archive member caching.  Each archive has an archive
1289  * descriptor (Ar_desc) associated with it.  This contains pointers to the
1290  * archive symbol table (obtained by elf_getarsyms(3e)) and an auxiliary
1291  * structure (Ar_uax[]) that parallels this symbol table.  The member element
1292  * of this auxiliary table indicates whether the archive member associated with
1293  * the symbol offset has already been extracted (AREXTRACTED) or partially
1294  * processed (refer process_member()).
1295  */
1296 typedef struct ar_mem {
1297 	Elf		*am_elf;	/* elf descriptor for this member */
1298 	char		*am_name;	/* members name */
1299 	char		*am_path;	/* path (ie. lib(foo.o)) */
1300 	Sym		*am_syms;	/* start of global symbols */
1301 	char		*am_strs;	/* associated string table start */
1302 	Xword		am_symn;	/* no. of global symbols */
1303 } Ar_mem;
1304 
1305 typedef struct ar_aux {
1306 	Sym_desc	*au_syms;	/* internal symbol descriptor */
1307 	Ar_mem		*au_mem;	/* associated member */
1308 } Ar_aux;
1309 
1310 #define	FLG_ARMEM_PROC	(Ar_mem *)-1
1311 
1312 typedef struct ar_desc {
1313 	const char	*ad_name;	/* archive file name */
1314 	Elf		*ad_elf;	/* elf descriptor for the archive */
1315 	Elf_Arsym	*ad_start;	/* archive symbol table start */
1316 	Ar_aux		*ad_aux;	/* auxiliary symbol information */
1317 	dev_t		ad_stdev;	/* device id and inode number for */
1318 	ino_t		ad_stino;	/*	multiple inclusion checks */
1319 	ofl_flag_t	ad_flags;	/* archive specific cmd line flags */
1320 } Ar_desc;
1321 
1322 /*
1323  * Define any archive descriptor flags.  NOTE, make sure they do not clash with
1324  * any output file descriptor archive extraction flags, as these are saved in
1325  * the same entry (see MSK_OF1_ARCHIVE).
1326  */
1327 #define	FLG_ARD_EXTRACT	0x00010000	/* archive member has been extracted */
1328 
1329 /* Mapfile versions supported by libld */
1330 #define	MFV_NONE	0	/* Not a valid version */
1331 #define	MFV_SYSV	1	/* Original System V syntax */
1332 #define	MFV_SOLARIS	2	/* Solaris mapfile syntax */
1333 #define	MFV_NUM		3	/* # of mapfile versions */
1334 
1335 
1336 /*
1337  * Function Declarations.
1338  */
1339 #if	defined(_ELF64)
1340 
1341 #define	ld_create_outfile	ld64_create_outfile
1342 #define	ld_ent_setup		ld64_ent_setup
1343 #define	ld_init_strings		ld64_init_strings
1344 #define	ld_init_target		ld64_init_target
1345 #define	ld_make_sections	ld64_make_sections
1346 #define	ld_main			ld64_main
1347 #define	ld_ofl_cleanup		ld64_ofl_cleanup
1348 #define	ld_process_mem		ld64_process_mem
1349 #define	ld_reloc_init		ld64_reloc_init
1350 #define	ld_reloc_process	ld64_reloc_process
1351 #define	ld_sym_validate		ld64_sym_validate
1352 #define	ld_update_outfile	ld64_update_outfile
1353 
1354 #else
1355 
1356 #define	ld_create_outfile	ld32_create_outfile
1357 #define	ld_ent_setup		ld32_ent_setup
1358 #define	ld_init_strings		ld32_init_strings
1359 #define	ld_init_target		ld32_init_target
1360 #define	ld_make_sections	ld32_make_sections
1361 #define	ld_main			ld32_main
1362 #define	ld_ofl_cleanup		ld32_ofl_cleanup
1363 #define	ld_process_mem		ld32_process_mem
1364 #define	ld_reloc_init		ld32_reloc_init
1365 #define	ld_reloc_process	ld32_reloc_process
1366 #define	ld_sym_validate		ld32_sym_validate
1367 #define	ld_update_outfile	ld32_update_outfile
1368 
1369 #endif
1370 
1371 extern int		ld_getopt(Lm_list *, int, int, char **);
1372 
1373 extern int		ld32_main(int, char **, Half);
1374 extern int		ld64_main(int, char **, Half);
1375 
1376 extern uintptr_t	ld_create_outfile(Ofl_desc *);
1377 extern uintptr_t	ld_ent_setup(Ofl_desc *, Xword);
1378 extern uintptr_t	ld_init_strings(Ofl_desc *);
1379 extern int		ld_init_target(Lm_list *, Half mach);
1380 extern uintptr_t	ld_make_sections(Ofl_desc *);
1381 extern void		ld_ofl_cleanup(Ofl_desc *);
1382 extern Ifl_desc		*ld_process_mem(const char *, const char *, char *,
1383 			    size_t, Ofl_desc *, Rej_desc *);
1384 extern uintptr_t	ld_reloc_init(Ofl_desc *);
1385 extern uintptr_t	ld_reloc_process(Ofl_desc *);
1386 extern uintptr_t	ld_sym_validate(Ofl_desc *);
1387 extern uintptr_t	ld_update_outfile(Ofl_desc *);
1388 
1389 #ifdef	__cplusplus
1390 }
1391 #endif
1392 
1393 #endif	/* _LIBLD_H */
1394