xref: /illumos-gate/usr/src/cmd/sgs/include/libld.h (revision a48fdbef)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21c174926fSrie 
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *	Copyright (c) 1988 AT&T
247c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
257c478bd9Sstevel@tonic-gate  *
26bf994817SAli Bahrami  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
27*a48fdbefSBryan Cantrill  * Copyright 2024 Oxide Computer Company
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef	_LIBLD_H
317c478bd9Sstevel@tonic-gate #define	_LIBLD_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #include <libelf.h>
357c478bd9Sstevel@tonic-gate #include <sgs.h>
36ba2be530Sab #include <_machelf.h>
377c478bd9Sstevel@tonic-gate #include <string_table.h>
387c478bd9Sstevel@tonic-gate #include <sys/avl.h>
397c478bd9Sstevel@tonic-gate #include <alist.h>
4069112eddSAli Bahrami #include <elfcap.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
437c478bd9Sstevel@tonic-gate extern "C" {
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Default directory search path manipulation for the link-editor.  YLDIR
487c478bd9Sstevel@tonic-gate  * indicates which directory in LIBPATH is replaced by the -YL option to cc
497c478bd9Sstevel@tonic-gate  * and ld.  YUDIR indicates which directory is replaced by -YU.
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate #define	YLDIR	1
527c478bd9Sstevel@tonic-gate #define	YUDIR	2
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Define a hash value that can never be returned from elf_hash().
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate #define	SYM_NOHASH	(~(Word)0)
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
60240e56feSab  * Macro that can be used to represent both ORDER flags
61240e56feSab  * in a section header.
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate #define	ALL_SHF_ORDER	(SHF_ORDERED | SHF_LINK_ORDER)
64240e56feSab 
65240e56feSab /*
66240e56feSab  * The linker merges (concatenates) sections with the same name and
67240e56feSab  * compatible section header flags. When comparing these flags,
68240e56feSab  * there are some that should not be included in the decision.
69240e56feSab  * The ALL_SHF_IGNORE constant defines these flags.
70240e56feSab  *
71240e56feSab  * NOTE: SHF_MERGE|SHF_STRINGS:
72240e56feSab  * The compiler is allowed to set the SHF_MERGE|SHF_STRINGS flags in
73240e56feSab  * order to tell the linker that:
74240e56feSab  *
75240e56feSab  *      1) There is nothing in the section except null terminated strings.
76cce0e03bSab  *	2) Those strings do not contain NULL bytes, except as termination.
77cce0e03bSab  *	3) All references to these strings occur via standard relocation
78cce0e03bSab  *		records.
79cce0e03bSab  *
80cce0e03bSab  * As a result, if two compatible sections both have these flags set, it is
81cce0e03bSab  * OK to combine the strings they contain into a single merged string table
82cce0e03bSab  * with duplicates removed and tail strings merged.
83240e56feSab  *
84240e56feSab  * This is a different meaning than the simple concatenating of sections
85240e56feSab  * that the linker always does. It is a hint that an additional optimization
86240e56feSab  * is possible, but not required. This means that sections that do not
87cce0e03bSab  * share the same SHF_MERGE|SHF_STRINGS values can be concatenated,
88cce0e03bSab  * but cannot have their duplicate strings combined. Hence, the
89cce0e03bSab  * SHF_MERGE|SHF_STRINGS flags should be ignored when deciding whether
90cce0e03bSab  * two sections can be concatenated.
91240e56feSab  */
92240e56feSab #define	ALL_SHF_IGNORE	(ALL_SHF_ORDER | SHF_GROUP | SHF_MERGE | SHF_STRINGS)
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * Define symbol reference types for use in symbol resolution.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate typedef enum {
987c478bd9Sstevel@tonic-gate 	REF_DYN_SEEN,			/* a .so symbol has been seen */
997c478bd9Sstevel@tonic-gate 	REF_DYN_NEED,			/* a .so symbol satisfies a .o symbol */
1007c478bd9Sstevel@tonic-gate 	REF_REL_NEED,			/* a .o symbol */
1017c478bd9Sstevel@tonic-gate 	REF_NUM				/* the number of symbol references */
1027c478bd9Sstevel@tonic-gate } Symref;
1037c478bd9Sstevel@tonic-gate 
104bf994817SAli Bahrami /*
105bf994817SAli Bahrami  * Relocation descriptor cache
106bf994817SAli Bahrami  */
107bf994817SAli Bahrami struct rel_cache {
108bf994817SAli Bahrami 	APlist		*rc_list;	/* list of Rel_cachebuf */
109b6a0e2cdSRichard Lowe 	Word		rc_cnt;		/*	and count */
110bf994817SAli Bahrami };
111bf994817SAli Bahrami 
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * GOT reference models
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate typedef enum {
1167c478bd9Sstevel@tonic-gate 	GOT_REF_GENERIC,	/* generic symbol reference */
1177c478bd9Sstevel@tonic-gate 	GOT_REF_TLSIE,		/* TLS initial exec (gnu) reference */
1187c478bd9Sstevel@tonic-gate 	GOT_REF_TLSLD,		/* TLS local dynamic reference */
1197c478bd9Sstevel@tonic-gate 	GOT_REF_TLSGD		/* TLS general dynamic reference */
1207c478bd9Sstevel@tonic-gate } Gotref;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate typedef struct {
1237c478bd9Sstevel@tonic-gate 	Xword		gn_addend;	/* addend associated with GOT entry */
1247c478bd9Sstevel@tonic-gate 	Sword		gn_gotndx;	/* GOT table index */
1257c478bd9Sstevel@tonic-gate 	Gotref		gn_gotref;
1267c478bd9Sstevel@tonic-gate } Gotndx;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Got debugging structure.  The got index is defined as a signed value as we
1307c478bd9Sstevel@tonic-gate  * do so much mucking around with negative and positive gots on SPARC, and sign
1317c478bd9Sstevel@tonic-gate  * extension is necessary when building 64-bit objects.  On intel we explicitly
1327c478bd9Sstevel@tonic-gate  * cast this variable to an unsigned value.
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate typedef struct {
13557ef7aa9SRod Evans 	Sym_desc	*gt_sym;
1367c478bd9Sstevel@tonic-gate 	Gotndx		gt_gndx;
1377c478bd9Sstevel@tonic-gate } Gottable;
1387c478bd9Sstevel@tonic-gate 
1396b3ba5bdSAli Bahrami /*
1406b3ba5bdSAli Bahrami  * The link-editor caches the results of sloppy relocation processing
14140e53e87SAli Bahrami  * in a variable of type Rlxrel_cache. Symbols come for processing in sorted
14240e53e87SAli Bahrami  * order, so a single item cache suffices to eliminate duplicate lookups.
14340e53e87SAli Bahrami  *
14440e53e87SAli Bahrami  * When sloppy relocation processing fails, the Rlxrel_rej enum reports
14540e53e87SAli Bahrami  * the underlying reason.
1466b3ba5bdSAli Bahrami  */
14740e53e87SAli Bahrami typedef enum {
14840e53e87SAli Bahrami 	RLXREL_REJ_NONE = 0,	/* Replacement symbol was found */
14940e53e87SAli Bahrami 	RLXREL_REJ_TARGET,	/* Target sec disallows relaxed relocations */
15040e53e87SAli Bahrami 	RLXREL_REJ_SECTION,	/* Either there is no replacement section, */
151b6a0e2cdSRichard Lowe 				/*	or its attributes are incompatible */
15240e53e87SAli Bahrami 	RLXREL_REJ_SYMBOL,	/* Replacement symbol not found */
15340e53e87SAli Bahrami } Rlxrel_rej;
15440e53e87SAli Bahrami 
1556b3ba5bdSAli Bahrami typedef struct sreloc_cache {
1566b3ba5bdSAli Bahrami 	Sym_desc	*sr_osdp;	/* Original symbol */
1576b3ba5bdSAli Bahrami 	Sym_desc	*sr_rsdp;	/* Replacement symbol */
15840e53e87SAli Bahrami 	Rlxrel_rej	sr_rej;		/* Reason for failure if NULL sr_rsdp */
15940e53e87SAli Bahrami } Rlxrel_cache;
1606b3ba5bdSAli Bahrami 
161cdcc71c0SAli Bahrami /*
162cdcc71c0SAli Bahrami  * Nodes in an ofl_wrap AVL tree
163cdcc71c0SAli Bahrami  *
164cdcc71c0SAli Bahrami  * wsn_name is the name of the symbol to be wrapped. wsn_wrapname is used
165cdcc71c0SAli Bahrami  * when we need to refer to the wrap symbol, and consists of the symbol
166cdcc71c0SAli Bahrami  * name with a __wrap_ prefix.
167cdcc71c0SAli Bahrami  */
168cdcc71c0SAli Bahrami typedef struct wrap_sym_node {
169cdcc71c0SAli Bahrami 	avl_node_t	wsn_avlnode;	/* AVL book-keeping */
170cdcc71c0SAli Bahrami 	const char	*wsn_name;	/* Symbol name: XXX */
171cdcc71c0SAli Bahrami 	const char	*wsn_wrapname;	/* Wrap symbol name: __wrap_XXX */
172cdcc71c0SAli Bahrami } WrapSymNode;
173cdcc71c0SAli Bahrami 
17408278a5eSRod Evans /*
17508278a5eSRod Evans  * Capabilities structures, used to maintain a capabilities set.
17608278a5eSRod Evans  *
17708278a5eSRod Evans  * Capabilities can be defined within input relocatable objects, and can be
17808278a5eSRod Evans  * augmented or replaced by mapfile directives.  In addition, mapfile directives
17908278a5eSRod Evans  * can be used to exclude capabilities that would otherwise be carried over to
18008278a5eSRod Evans  * the output object.
18108278a5eSRod Evans  *
18208278a5eSRod Evans  * CA_SUNW_HW_1, CA_SUNW_SF_1 and CA_SUNW_HW_2 values are bitmasks.  A current
18308278a5eSRod Evans  * value, and an exclude value are maintained for each capability.
18408278a5eSRod Evans  *
18508278a5eSRod Evans  * There can be multiple CA_SUNW_PLAT and CA_SUNW_MACH entries and thus Alists
18608278a5eSRod Evans  * are used to collect these entries.  A current list for each capability is
18708278a5eSRod Evans  * maintained as Capstr entries, which provide for maintaining the strings
18808278a5eSRod Evans  * eventual index into a string table.  An exclude list is maintained as a
18908278a5eSRod Evans  * list of string pointers.
19008278a5eSRod Evans  */
19108278a5eSRod Evans typedef struct {
19208278a5eSRod Evans 	elfcap_mask_t	cm_val;		/* bitmask value */
19308278a5eSRod Evans 	elfcap_mask_t	cm_exc;		/* bits to exclude from final object */
19408278a5eSRod Evans } Capmask;
19508278a5eSRod Evans 
19608278a5eSRod Evans typedef struct {
19708278a5eSRod Evans 	Alist		*cl_val;	/* string (Capstr) value */
19808278a5eSRod Evans 	APlist		*cl_exc;	/* strings to exclude from final */
19908278a5eSRod Evans } Caplist;				/*	object */
20008278a5eSRod Evans 
20108278a5eSRod Evans typedef	struct {
20208278a5eSRod Evans 	char		*cs_str;	/* platform or machine name */
20308278a5eSRod Evans 	Word		cs_ndx;		/* the entries output Cap index */
20408278a5eSRod Evans } Capstr;
20508278a5eSRod Evans 
20608278a5eSRod Evans typedef	uint_t		oc_flag_t;
20708278a5eSRod Evans typedef	struct {
20808278a5eSRod Evans 	Capmask		oc_hw_1;	/* CA_SUNW_HW_1 capabilities */
20908278a5eSRod Evans 	Capmask		oc_sf_1;	/* CA_SUNW_SF_1 capabilities */
21008278a5eSRod Evans 	Capmask		oc_hw_2;	/* CA_SUNW_HW_2 capabilities */
21108278a5eSRod Evans 	Caplist		oc_plat;	/* CA_SUNW_PLAT capabilities */
21208278a5eSRod Evans 	Caplist		oc_mach;	/* CA_SUNW_MACH capabilities */
21308278a5eSRod Evans 	Capstr		oc_id;		/* CA_SUNW_ID capability */
21456726c7eSRobert Mustacchi 	Capmask		oc_hw_3;	/* CA_SUNW_HW_3 capabilities */
21508278a5eSRod Evans 	oc_flag_t	oc_flags;
21608278a5eSRod Evans } Objcapset;
21708278a5eSRod Evans 
21808278a5eSRod Evans #define	FLG_OCS_USRDEFID	0x1	/* user defined CA_SUNW_ID */
219cdcc71c0SAli Bahrami 
22069112eddSAli Bahrami /*
22169112eddSAli Bahrami  * Bitmasks for a single capability. Capabilities come from input objects,
22269112eddSAli Bahrami  * augmented or replaced by mapfile directives. In addition, mapfile directives
22369112eddSAli Bahrami  * can be used to exclude bits that would otherwise be set in the output object.
22469112eddSAli Bahrami  */
22569112eddSAli Bahrami typedef struct {
22669112eddSAli Bahrami 	elfcap_mask_t	cm_value;	/* Bitmask value */
22769112eddSAli Bahrami 	elfcap_mask_t	cm_exclude;	/* Bits to remove from final object */
22869112eddSAli Bahrami } CapMask;
22969112eddSAli Bahrami 
23069112eddSAli Bahrami /*
23169112eddSAli Bahrami  * Combine the bitmask in a CapMask with the exclusion mask and
23269112eddSAli Bahrami  * return the resulting final value.
23369112eddSAli Bahrami  */
23469112eddSAli Bahrami #define	CAPMASK_VALUE(_cbmp) ((_cbmp)->cm_value & ~(_cbmp)->cm_exclude)
23569112eddSAli Bahrami 
23669112eddSAli Bahrami typedef struct {
23769112eddSAli Bahrami 	CapMask		c_hw_1;		/* CA_SUNW_HW_1 capabilities */
23869112eddSAli Bahrami 	CapMask		c_sf_1;		/* CA_SUNW_SF_1 capabilities */
23969112eddSAli Bahrami 	CapMask		c_hw_2;		/* CA_SUNW_HW_2 capabilities */
24069112eddSAli Bahrami } Outcapset;
24169112eddSAli Bahrami 
24269112eddSAli Bahrami 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * Output file processing structure
2457c478bd9Sstevel@tonic-gate  */
2461007fd6fSAli Bahrami typedef Lword	ofl_flag_t;
2471007fd6fSAli Bahrami typedef Word	ofl_guideflag_t;
2487c478bd9Sstevel@tonic-gate struct ofl_desc {
2497c478bd9Sstevel@tonic-gate 	char		*ofl_sgsid;	/* link-editor identification */
2507c478bd9Sstevel@tonic-gate 	const char	*ofl_name;	/* full file name */
2517c478bd9Sstevel@tonic-gate 	Elf		*ofl_elf;	/* elf_memory() elf descriptor */
2527c478bd9Sstevel@tonic-gate 	Elf		*ofl_welf;	/* ELF_C_WRITE elf descriptor */
2535aefb655Srie 	Ehdr		*ofl_dehdr;	/* default elf header, and new elf */
2545aefb655Srie 	Ehdr		*ofl_nehdr;	/*	header describing this file */
2557c478bd9Sstevel@tonic-gate 	Phdr		*ofl_phdr;	/* program header descriptor */
2567c478bd9Sstevel@tonic-gate 	Phdr		*ofl_tlsphdr;	/* TLS phdr */
2577c478bd9Sstevel@tonic-gate 	int		ofl_fd;		/* file descriptor */
2587c478bd9Sstevel@tonic-gate 	size_t		ofl_size;	/* image size */
25957ef7aa9SRod Evans 	APlist		*ofl_maps;	/* list of input mapfiles */
26057ef7aa9SRod Evans 	APlist		*ofl_segs;	/* list of segments */
26169112eddSAli Bahrami 	APlist		*ofl_segs_order; /* SEGMENT_ORDER segments */
26269112eddSAli Bahrami 	avl_tree_t	ofl_segs_avl;	/* O(log N) access to named segments */
26369112eddSAli Bahrami 	APlist		*ofl_ents;	/* list of entrance descriptors */
26469112eddSAli Bahrami 	avl_tree_t	ofl_ents_avl;	/* O(log N) access to named ent. desc */
26557ef7aa9SRod Evans 	APlist		*ofl_objs;	/* relocatable object file list */
266b6a0e2cdSRichard Lowe 	Word		ofl_objscnt;	/*	and count */
26757ef7aa9SRod Evans 	APlist		*ofl_ars;	/* archive library list */
268b6a0e2cdSRichard Lowe 	Word		ofl_arscnt;	/*	and count */
269551cffe3SAli Bahrami 	int		ofl_ars_gsandx; /* archive group argv index. 0 means */
270551cffe3SAli Bahrami 					/*	no current group, < 0 means */
271551cffe3SAli Bahrami 					/*	error reported. >0 is cur ndx */
272551cffe3SAli Bahrami 	Word		ofl_ars_gsndx;	/* current -zrescan-start ofl_ars ndx */
27357ef7aa9SRod Evans 	APlist		*ofl_sos;	/* shared object list */
274b6a0e2cdSRichard Lowe 	Word		ofl_soscnt;	/*	and count */
27557ef7aa9SRod Evans 	APlist		*ofl_soneed;	/* list of implicitly required .so's */
27657ef7aa9SRod Evans 	APlist		*ofl_socntl;	/* list of .so control definitions */
277bf994817SAli Bahrami 	Rel_cache	ofl_outrels;	/* list of output relocations */
278bf994817SAli Bahrami 	Rel_cache	ofl_actrels;	/* list of relocations to perform */
279bf994817SAli Bahrami 	APlist		*ofl_relaux;	/* Rel_aux cache for outrels/actrels */
280c174926fSrie 	Word		ofl_entrelscnt;	/* no of relocations entered */
28157ef7aa9SRod Evans 	Alist		*ofl_copyrels;	/* list of copy relocations */
28257ef7aa9SRod Evans 	APlist		*ofl_ordered;	/* list of shf_ordered sections */
283635216b6SRod Evans 	APlist		*ofl_symdtent;	/* list of syminfo symbols that need */
284635216b6SRod Evans 					/*	to reference .dynamic entries */
28557ef7aa9SRod Evans 	APlist		*ofl_ismove;	/* list of .SUNW_move sections */
28657ef7aa9SRod Evans 	APlist		*ofl_ismoverel;	/* list of relocation input section */
2877c478bd9Sstevel@tonic-gate 					/* targeting to expanded area */
288b6a0e2cdSRichard Lowe 	APlist		*ofl_parsyms;	/* list of partially initialized */
28957ef7aa9SRod Evans 					/*	symbols (ie. move symbols) */
29057ef7aa9SRod Evans 	APlist		*ofl_extrarels;	/* relocation sections which have */
2917c478bd9Sstevel@tonic-gate 					/*    a NULL sh_info */
292cc7efc4fSrie 	avl_tree_t	*ofl_groups;	/* pointer to head of Groups AVL tree */
29357ef7aa9SRod Evans 	APlist		*ofl_initarray;	/* list of init array func names */
29457ef7aa9SRod Evans 	APlist		*ofl_finiarray;	/* list of fini array func names */
29557ef7aa9SRod Evans 	APlist		*ofl_preiarray;	/* list of preinit array func names */
29657ef7aa9SRod Evans 	APlist		*ofl_rtldinfo;	/* list of rtldinfo syms */
29757ef7aa9SRod Evans 	APlist		*ofl_osgroups;	/* list of output GROUP sections */
29857ef7aa9SRod Evans 	APlist		*ofl_ostlsseg;	/* pointer to sections in TLS segment */
2997e16fca0SAli Bahrami 	APlist		*ofl_unwind;	/* list of unwind output sections */
3007c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_unwindhdr;	/* Unwind hdr */
3017c478bd9Sstevel@tonic-gate 	avl_tree_t	ofl_symavl;	/* pointer to head of Syms AVL tree */
3027c478bd9Sstevel@tonic-gate 	Sym_desc	**ofl_regsyms;	/* array of potential register */
3037c478bd9Sstevel@tonic-gate 	Word		ofl_regsymsno;	/*    symbols and array count */
3047c478bd9Sstevel@tonic-gate 	Word		ofl_regsymcnt;	/* no. of output register symbols */
3057c478bd9Sstevel@tonic-gate 	Word		ofl_lregsymcnt;	/* no. of local register symbols */
3067c478bd9Sstevel@tonic-gate 	Sym_desc	*ofl_dtracesym;	/* ld -zdtrace= */
3071d9df23bSab 	ofl_flag_t	ofl_flags;	/* various state bits, args etc. */
3081d9df23bSab 	ofl_flag_t	ofl_flags1;	/*	more flags */
3097c478bd9Sstevel@tonic-gate 	void		*ofl_entry;	/* entry point (-e and Sym_desc *) */
3107c478bd9Sstevel@tonic-gate 	char		*ofl_filtees;	/* shared objects we are a filter for */
3117c478bd9Sstevel@tonic-gate 	const char	*ofl_soname;	/* (-h option) output file name for */
3127c478bd9Sstevel@tonic-gate 					/*	dynamic structure */
3137c478bd9Sstevel@tonic-gate 	const char	*ofl_interp;	/* interpreter name used by exec() */
3147c478bd9Sstevel@tonic-gate 	char		*ofl_rpath;	/* run path to store in .dynamic */
3157c478bd9Sstevel@tonic-gate 	char		*ofl_config;	/* config path to store in .dynamic */
31657ef7aa9SRod Evans 	APlist		*ofl_ulibdirs;	/* user supplied library search list */
31757ef7aa9SRod Evans 	APlist		*ofl_dlibdirs;	/* default library search list */
3187c478bd9Sstevel@tonic-gate 	Word		ofl_vercnt;	/* number of versions to generate */
31957ef7aa9SRod Evans 	APlist		*ofl_verdesc;	/* list of version descriptors */
3207c478bd9Sstevel@tonic-gate 	size_t		ofl_verdefsz;	/* size of version definition section */
3217c478bd9Sstevel@tonic-gate 	size_t		ofl_verneedsz;	/* size of version needed section */
3227c478bd9Sstevel@tonic-gate 	Word		ofl_entercnt;	/* no. of global symbols entered */
3237c478bd9Sstevel@tonic-gate 	Word		ofl_globcnt;	/* no. of global symbols to output */
3247c478bd9Sstevel@tonic-gate 	Word		ofl_scopecnt;	/* no. of scoped symbols to output */
3259039eeafSab 	Word		ofl_dynscopecnt; /* no. scoped syms in .SUNW_ldynsym */
3267c478bd9Sstevel@tonic-gate 	Word		ofl_elimcnt;	/* no. of eliminated symbols */
3279039eeafSab 	Word		ofl_locscnt;	/* no. of local symbols in .symtab */
3289039eeafSab 	Word		ofl_dynlocscnt;	/* no. local symbols in .SUNW_ldynsym */
329d579eb63Sab 	Word		ofl_dynsymsortcnt; /* no. ndx in .SUNW_dynsymsort */
330d579eb63Sab 	Word		ofl_dyntlssortcnt; /* no. ndx in .SUNW_dyntlssort */
3317c478bd9Sstevel@tonic-gate 	Word		ofl_dynshdrcnt;	/* no. of output section in .dynsym */
3327c478bd9Sstevel@tonic-gate 	Word		ofl_shdrcnt;	/* no. of output sections */
33308278a5eSRod Evans 	Word		ofl_caploclcnt;	/* no. of local capabilities symbols */
33408278a5eSRod Evans 	Word		ofl_capsymcnt;	/* no. of symbol capabilities entries */
33508278a5eSRod Evans 					/*	required */
33608278a5eSRod Evans 	Word		ofl_capchaincnt; /* no. of Capchain symbols */
33708278a5eSRod Evans 	APlist		*ofl_capgroups;	/* list of capabilities groups */
33808278a5eSRod Evans 	avl_tree_t	*ofl_capfamilies; /* capability family AVL tree */
3397c478bd9Sstevel@tonic-gate 	Str_tbl		*ofl_shdrsttab;	/* Str_tbl for shdr strtab */
3407c478bd9Sstevel@tonic-gate 	Str_tbl		*ofl_strtab;	/* Str_tbl for symtab strtab */
3417c478bd9Sstevel@tonic-gate 	Str_tbl		*ofl_dynstrtab;	/* Str_tbl for dymsym strtab */
3427c478bd9Sstevel@tonic-gate 	Gotndx		*ofl_tlsldgotndx; /* index to LD TLS_index structure */
3437c478bd9Sstevel@tonic-gate 	Xword		ofl_relocsz;	/* size of output relocations */
3447c478bd9Sstevel@tonic-gate 	Xword		ofl_relocgotsz;	/* size of .got relocations */
3457c478bd9Sstevel@tonic-gate 	Xword		ofl_relocpltsz;	/* size of .plt relocations */
3467c478bd9Sstevel@tonic-gate 	Xword		ofl_relocbsssz;	/* size of .bss (copy) relocations */
3477c478bd9Sstevel@tonic-gate 	Xword		ofl_relocrelsz;	/* size of .rel[a] relocations */
3487c478bd9Sstevel@tonic-gate 	Word		ofl_relocincnt;	/* no. of input relocations */
3497c478bd9Sstevel@tonic-gate 	Word		ofl_reloccnt;	/* tot number of output relocations */
3507c478bd9Sstevel@tonic-gate 	Word		ofl_reloccntsub; /* tot numb of output relocations to */
3517c478bd9Sstevel@tonic-gate 					/*	skip (-zignore) */
3527c478bd9Sstevel@tonic-gate 	Word		ofl_relocrelcnt; /* tot number of relative */
3537c478bd9Sstevel@tonic-gate 					/*	relocations */
3547c478bd9Sstevel@tonic-gate 	Word		ofl_gotcnt;	/* no. of .got entries */
3557c478bd9Sstevel@tonic-gate 	Word		ofl_pltcnt;	/* no. of .plt entries */
3567c478bd9Sstevel@tonic-gate 	Word		ofl_pltpad;	/* no. of .plt padd entries */
3577c478bd9Sstevel@tonic-gate 	Word		ofl_hashbkts;	/* no. of hash buckets required */
3587c478bd9Sstevel@tonic-gate 	Is_desc		*ofl_isbss;	/* .bss input section (globals) */
35954d82594Sseizo 	Is_desc		*ofl_islbss;	/* .lbss input section (globals) */
3607c478bd9Sstevel@tonic-gate 	Is_desc		*ofl_istlsbss;	/* .tlsbss input section (globals) */
36135450702SAli Bahrami 	Is_desc		*ofl_isparexpn;	/* -z nopartial .data input section */
3627c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osdynamic;	/* .dynamic output section */
3637c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osdynsym;	/* .dynsym output section */
3649039eeafSab 	Os_desc		*ofl_osldynsym;	/* .SUNW_ldynsym output section */
3657c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osdynstr;	/* .dynstr output section */
366d579eb63Sab 	Os_desc		*ofl_osdynsymsort; /* .SUNW_dynsymsort output section */
367d579eb63Sab 	Os_desc		*ofl_osdyntlssort; /* .SUNW_dyntlssort output section */
3687c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osgot;	/* .got output section */
3697c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_oshash;	/* .hash output section */
370b23a7923SAli Bahrami 	Os_desc		*ofl_osinitarray; /* .init_array output section */
371b23a7923SAli Bahrami 	Os_desc		*ofl_osfiniarray; /* .fini_array output section */
372b23a7923SAli Bahrami 	Os_desc		*ofl_ospreinitarray; /* .preinit_array output section */
3737c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osinterp;	/* .interp output section */
3747c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_oscap;	/* .SUNW_cap output section */
37508278a5eSRod Evans 	Os_desc		*ofl_oscapinfo;	/* .SUNW_capinfo output section */
37608278a5eSRod Evans 	Os_desc		*ofl_oscapchain; /* .SUNW_capchain output section */
3777c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osplt;	/* .plt output section */
3787c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osmove;	/* .SUNW_move output section */
3797c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osrelhead;	/* first relocation section */
3807c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osrel;	/* .rel[a] relocation section */
3817c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osshstrtab; /* .shstrtab output section */
3827c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osstrtab;	/* .strtab output section */
3837c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_ossymtab;	/* .symtab output section */
3847c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_ossymshndx; /* .symtab_shndx output section */
3857c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osdynshndx; /* .dynsym_shndx output section */
3869039eeafSab 	Os_desc		*ofl_osldynshndx; /* .SUNW_ldynsym_shndx output sec */
3877c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osverdef;	/* .version definition output section */
3887c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osverneed;	/* .version needed output section */
3897c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_osversym;	/* .version symbol ndx output section */
3907c478bd9Sstevel@tonic-gate 	Word		ofl_dtflags_1;	/* DT_FLAGS_1 entries */
3917c478bd9Sstevel@tonic-gate 	Word		ofl_dtflags;	/* DT_FLAGS entries */
3927c478bd9Sstevel@tonic-gate 	Os_desc		*ofl_ossyminfo;	/* .SUNW_syminfo output section */
39335450702SAli Bahrami 	Half		ofl_parexpnndx;	/* -z nopartial section index */
3947c478bd9Sstevel@tonic-gate 					/* Ref. at perform_outreloc() in */
3957c478bd9Sstevel@tonic-gate 					/* libld/{mach}/machrel.c */
3967c478bd9Sstevel@tonic-gate 	Xword		*ofl_checksum;	/* DT_CHECKSUM value address */
3977c478bd9Sstevel@tonic-gate 	char		*ofl_depaudit;	/* dependency auditing required (-P) */
3987c478bd9Sstevel@tonic-gate 	char		*ofl_audit;	/* object auditing required (-p) */
3997c478bd9Sstevel@tonic-gate 	Alist		*ofl_symfltrs;	/* per-symbol filtees and their */
4007c478bd9Sstevel@tonic-gate 	Alist		*ofl_dtsfltrs;	/*	associated .dynamic/.dynstrs */
40108278a5eSRod Evans 	Objcapset	ofl_ocapset;	/* object capabilities */
4025aefb655Srie 	Lm_list		*ofl_lml;	/* runtime link-map list */
403d326b23bSrie 	Gottable	*ofl_gottable;	/* debugging got information */
40440e53e87SAli Bahrami 	Rlxrel_cache	ofl_sr_cache;	/* Cache last result from */
4056b3ba5bdSAli Bahrami 					/*	sloppy_comdat_reloc() */
40657ef7aa9SRod Evans 	APlist		*ofl_maptext;	/* mapfile added text sections */
40757ef7aa9SRod Evans 	APlist		*ofl_mapdata;	/* mapfile added data sections */
408635216b6SRod Evans 	avl_tree_t	*ofl_wrap;	/* -z wrap symbols */
4091007fd6fSAli Bahrami 	ofl_guideflag_t	ofl_guideflags;	/* -z guide flags */
410b533f56bSRobert Mustacchi 	APlist		*ofl_assdeflib;	/* -z assert-deflib exceptions */
411d2a70789SRichard Lowe 	int		ofl_aslr;	/* -z aslr, -1 disable, 1 enable */
4128222814eSRichard Lowe 	APlist		*ofl_symasserts; /* assertions about symbols */
4138222814eSRichard Lowe 					/* from mapfiles */
4147c478bd9Sstevel@tonic-gate };
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate #define	FLG_OF_DYNAMIC	0x00000001	/* generate dynamic output module */
4177c478bd9Sstevel@tonic-gate #define	FLG_OF_STATIC	0x00000002	/* generate static output module */
4187c478bd9Sstevel@tonic-gate #define	FLG_OF_EXEC	0x00000004	/* generate an executable */
4197c478bd9Sstevel@tonic-gate #define	FLG_OF_RELOBJ	0x00000008	/* generate a relocatable object */
4207c478bd9Sstevel@tonic-gate #define	FLG_OF_SHAROBJ	0x00000010	/* generate a shared object */
4217c478bd9Sstevel@tonic-gate #define	FLG_OF_BFLAG	0x00000020	/* do no special plt building: -b */
4227c478bd9Sstevel@tonic-gate #define	FLG_OF_IGNENV	0x00000040	/* ignore LD_LIBRARY_PATH: -i */
4237c478bd9Sstevel@tonic-gate #define	FLG_OF_STRIP	0x00000080	/* strip output: -s */
4247c478bd9Sstevel@tonic-gate #define	FLG_OF_NOWARN	0x00000100	/* disable symbol warnings: -t */
4257c478bd9Sstevel@tonic-gate #define	FLG_OF_NOUNDEF	0x00000200	/* allow no undefined symbols: -zdefs */
426635216b6SRod Evans #define	FLG_OF_PURETXT	0x00000400	/* allow no text relocations: -ztext */
4277c478bd9Sstevel@tonic-gate #define	FLG_OF_GENMAP	0x00000800	/* generate a memory map: -m */
4287c478bd9Sstevel@tonic-gate #define	FLG_OF_DYNLIBS	0x00001000	/* dynamic input allowed: -Bdynamic */
4297c478bd9Sstevel@tonic-gate #define	FLG_OF_SYMBOLIC	0x00002000	/* bind global symbols: -Bsymbolic */
4307c478bd9Sstevel@tonic-gate #define	FLG_OF_ADDVERS	0x00004000	/* add version stamp: -Qy */
4319039eeafSab #define	FLG_OF_NOLDYNSYM 0x00008000	/* -znoldynsym set */
43269112eddSAli Bahrami #define	FLG_OF_IS_ORDER	0x00010000	/* input section ordering within a */
43369112eddSAli Bahrami 					/*	segment is required */
43469112eddSAli Bahrami #define	FLG_OF_EC_FILES	0x00020000	/* Ent_desc exist w/non-NULL ec_files */
4357c478bd9Sstevel@tonic-gate #define	FLG_OF_TEXTREL	0x00040000	/* text relocations have been found */
4367c478bd9Sstevel@tonic-gate #define	FLG_OF_MULDEFS	0x00080000	/* multiple symbols are allowed */
437dd94ecefSrie #define	FLG_OF_TLSPHDR	0x00100000	/* a TLS program header is required */
4387c478bd9Sstevel@tonic-gate #define	FLG_OF_BLDGOT	0x00200000	/* build GOT table */
4397c478bd9Sstevel@tonic-gate #define	FLG_OF_VERDEF	0x00400000	/* record version definitions */
4407c478bd9Sstevel@tonic-gate #define	FLG_OF_VERNEED	0x00800000	/* record version dependencies */
4417c478bd9Sstevel@tonic-gate #define	FLG_OF_NOVERSEC 0x01000000	/* don't record version sections */
4420e233487SRod Evans #define	FLG_OF_KEY	0x02000000	/* file requires sort keys */
4437c478bd9Sstevel@tonic-gate #define	FLG_OF_PROCRED	0x04000000	/* process any symbol reductions by */
4447c478bd9Sstevel@tonic-gate 					/*	effecting the symbol table */
4457c478bd9Sstevel@tonic-gate 					/*	output and relocations */
4467c478bd9Sstevel@tonic-gate #define	FLG_OF_SYMINFO	0x08000000	/* create a syminfo section */
4477c478bd9Sstevel@tonic-gate #define	FLG_OF_AUX	0x10000000	/* ofl_filter is an auxiliary filter */
4487c478bd9Sstevel@tonic-gate #define	FLG_OF_FATAL	0x20000000	/* fatal error during input */
4497c478bd9Sstevel@tonic-gate #define	FLG_OF_WARN	0x40000000	/* warning during input processing. */
4507c478bd9Sstevel@tonic-gate #define	FLG_OF_VERBOSE	0x80000000	/* -z verbose flag set */
4517c478bd9Sstevel@tonic-gate 
4529a411307Srie #define	FLG_OF_MAPSYMB	0x000100000000	/* symbolic scope definition seen */
4539a411307Srie #define	FLG_OF_MAPGLOB	0x000200000000	/* global scope definition seen */
454e38a713aSrie #define	FLG_OF_COMREL	0x000400000000	/* -z combreloc set, which enables */
455e38a713aSrie 					/*	DT_RELACNT tracking, */
456e38a713aSrie #define	FLG_OF_NOCOMREL	0x000800000000	/* -z nocombreloc set */
45744bac77bSrie #define	FLG_OF_AUTOLCL	0x001000000000	/* automatically reduce unspecified */
45844bac77bSrie 					/*	global symbols to locals */
459635216b6SRod Evans #define	FLG_OF_AUTOELM	0x002000000000	/* automatically eliminate */
46044bac77bSrie 					/*	unspecified global symbols */
46144bac77bSrie #define	FLG_OF_REDLSYM	0x004000000000	/* reduce local symbols */
46269112eddSAli Bahrami #define	FLG_OF_OS_ORDER	0x008000000000	/* output section ordering required */
463635216b6SRod Evans #define	FLG_OF_OSABI	0x010000000000	/* tag object as ELFOSABI_SOLARIS */
46408278a5eSRod Evans #define	FLG_OF_ADJOSCNT	0x020000000000	/* adjust ofl_shdrcnt to accommodate */
465e64d0ff9SAli Bahrami 					/*	discarded sections */
46608278a5eSRod Evans #define	FLG_OF_OTOSCAP	0x040000000000	/* convert object capabilities to */
46708278a5eSRod Evans 					/*	symbol capabilities */
46808278a5eSRod Evans #define	FLG_OF_PTCAP	0x080000000000	/* PT_SUNWCAP required */
46908278a5eSRod Evans #define	FLG_OF_CAPSTRS	0x100000000000	/* capability strings are required */
470d444b03eSAli Bahrami #define	FLG_OF_EHFRAME	0x200000000000	/* output contains .eh_frame section */
4711007fd6fSAli Bahrami #define	FLG_OF_FATWARN	0x400000000000	/* make warnings fatal */
472b533f56bSRobert Mustacchi #define	FLG_OF_ADEFLIB	0x800000000000	/* no libraries in default path */
4739a411307Srie 
474b6a0e2cdSRichard Lowe #define	FLG_OF_KMOD	0x1000000000000	/* output is a kernel module */
475b6a0e2cdSRichard Lowe 
4767c478bd9Sstevel@tonic-gate /*
4777c478bd9Sstevel@tonic-gate  * In the flags1 arena, establish any options that are applicable to archive
4787c478bd9Sstevel@tonic-gate  * extraction first, and associate a mask.  These values are recorded with any
4797c478bd9Sstevel@tonic-gate  * archive descriptor so that they may be reset should the archive require a
4807c478bd9Sstevel@tonic-gate  * rescan to try and resolve undefined symbols.
4817c478bd9Sstevel@tonic-gate  */
48269112eddSAli Bahrami #define	FLG_OF1_ALLEXRT	0x0000000001	/* extract all members from an */
4837c478bd9Sstevel@tonic-gate 					/*	archive file */
48469112eddSAli Bahrami #define	FLG_OF1_WEAKEXT	0x0000000002	/* allow archive extraction to */
4857c478bd9Sstevel@tonic-gate 					/*	resolve weak references */
48669112eddSAli Bahrami #define	MSK_OF1_ARCHIVE	0x0000000003	/* archive flags mask */
48769112eddSAli Bahrami 
48869112eddSAli Bahrami #define	FLG_OF1_NOINTRP	0x0000000008	/* -z nointerp flag set */
48969112eddSAli Bahrami #define	FLG_OF1_ZDIRECT	0x0000000010	/* -z direct flag set */
49069112eddSAli Bahrami #define	FLG_OF1_NDIRECT	0x0000000020	/* no-direct bindings specified */
491f441771bSRod Evans #define	FLG_OF1_DEFERRED 0x0000000040	/* deferred dependency recording */
49269112eddSAli Bahrami 
49369112eddSAli Bahrami #define	FLG_OF1_RELDYN	0x0000000100	/* process .dynamic in rel obj */
49469112eddSAli Bahrami #define	FLG_OF1_NRLXREL	0x0000000200	/* -z norelaxreloc flag set */
49569112eddSAli Bahrami #define	FLG_OF1_RLXREL	0x0000000400	/* -z relaxreloc flag set */
49669112eddSAli Bahrami #define	FLG_OF1_IGNORE	0x0000000800	/* ignore unused dependencies */
49769112eddSAli Bahrami #define	FLG_OF1_NOSGHND	0x0000001000	/* -z nosighandler flag set */
49869112eddSAli Bahrami #define	FLG_OF1_TEXTOFF 0x0000002000	/* text relocations are ok */
49969112eddSAli Bahrami #define	FLG_OF1_ABSEXEC	0x0000004000	/* -zabsexec set */
50069112eddSAli Bahrami #define	FLG_OF1_LAZYLD	0x0000008000	/* lazy loading of objects enabled */
50169112eddSAli Bahrami #define	FLG_OF1_GRPPRM	0x0000010000	/* dependencies are to have */
5027c478bd9Sstevel@tonic-gate 					/*	GROUPPERM enabled */
5031007fd6fSAli Bahrami 
50469112eddSAli Bahrami #define	FLG_OF1_NOPARTI	0x0000040000	/* -znopartial set */
50569112eddSAli Bahrami #define	FLG_OF1_BSSOREL	0x0000080000	/* output relocation against bss */
5067c478bd9Sstevel@tonic-gate 					/*	section */
50769112eddSAli Bahrami #define	FLG_OF1_TLSOREL	0x0000100000	/* output relocation against .tlsbss */
5087c478bd9Sstevel@tonic-gate 					/*	section */
50969112eddSAli Bahrami #define	FLG_OF1_MEMORY	0x0000200000	/* produce a memory model */
51069112eddSAli Bahrami #define	FLG_OF1_NGLBDIR	0x0000400000	/* no DT_1_DIRECT flag allowed */
51108278a5eSRod Evans #define	FLG_OF1_ENCDIFF	0x0000800000	/* host running linker has different */
512f3324781Sab 					/*	byte order than output object */
51369112eddSAli Bahrami #define	FLG_OF1_VADDR	0x0001000000	/* a segment defines explicit vaddr */
51469112eddSAli Bahrami #define	FLG_OF1_EXTRACT	0x0002000000	/* archive member has been extracted */
51569112eddSAli Bahrami #define	FLG_OF1_RESCAN	0x0004000000	/* any archives should be rescanned */
51669112eddSAli Bahrami #define	FLG_OF1_IGNPRC	0x0008000000	/* ignore processing required */
51769112eddSAli Bahrami #define	FLG_OF1_NCSTTAB	0x0010000000	/* -znocompstrtab set */
51869112eddSAli Bahrami #define	FLG_OF1_DONE	0x0020000000	/* link-editor processing complete */
51969112eddSAli Bahrami #define	FLG_OF1_NONREG	0x0040000000	/* non-regular file specified as */
5207c478bd9Sstevel@tonic-gate 					/*	the output file */
52169112eddSAli Bahrami #define	FLG_OF1_ALNODIR	0x0080000000	/* establish NODIRECT for all */
5227c478bd9Sstevel@tonic-gate 					/*	exported interfaces. */
52369112eddSAli Bahrami #define	FLG_OF1_OVHWCAP1 0x0100000000	/* override CA_SUNW_HW_1 capabilities */
52469112eddSAli Bahrami #define	FLG_OF1_OVSFCAP1 0x0200000000	/* override CA_SUNW_SF_1 capabilities */
52569112eddSAli Bahrami #define	FLG_OF1_OVHWCAP2 0x0400000000	/* override CA_SUNW_HW_2 capabilities */
52608278a5eSRod Evans #define	FLG_OF1_OVMACHCAP 0x0800000000	/* override CA_SUNW_MACH capability */
52708278a5eSRod Evans #define	FLG_OF1_OVPLATCAP 0x1000000000	/* override CA_SUNW_PLAT capability */
52808278a5eSRod Evans #define	FLG_OF1_OVIDCAP	0x2000000000	/* override CA_SUNW_ID capability */
52956726c7eSRobert Mustacchi #define	FLG_OF1_OVHWCAP3 0x4000000000	/* override CA_SUNW_HW_3 capabilities */
5307c478bd9Sstevel@tonic-gate 
5311007fd6fSAli Bahrami /*
5321007fd6fSAli Bahrami  * Guidance flags. The flags with the FLG_OFG_NO_ prefix are used to suppress
5331007fd6fSAli Bahrami  * messages for a given category, and use the lower 28 bits of the word,
5341007fd6fSAli Bahrami  * The upper nibble is reserved for other guidance status.
5351007fd6fSAli Bahrami  */
5361007fd6fSAli Bahrami #define	FLG_OFG_ENABLE		0x10000000	/* -z guidance option active */
5371007fd6fSAli Bahrami #define	FLG_OFG_ISSUED		0x20000000	/* -z guidance message issued */
5381007fd6fSAli Bahrami 
5391007fd6fSAli Bahrami #define	FLG_OFG_NO_ALL		0x0fffffff	/* disable all guidance */
5401007fd6fSAli Bahrami #define	FLG_OFG_NO_DEFS		0x00000001	/* specify all dependencies */
5411007fd6fSAli Bahrami #define	FLG_OFG_NO_DB		0x00000002	/* use direct bindings */
5421007fd6fSAli Bahrami #define	FLG_OFG_NO_LAZY		0x00000004	/* be explicit about lazyload */
5431007fd6fSAli Bahrami #define	FLG_OFG_NO_MF		0x00000008	/* use v2 mapfile syntax */
5441007fd6fSAli Bahrami #define	FLG_OFG_NO_TEXT		0x00000010	/* verify pure text segment */
5451007fd6fSAli Bahrami #define	FLG_OFG_NO_UNUSED	0x00000020	/* remove unused dependency */
5468222814eSRichard Lowe #define	FLG_OFG_NO_ASSERTS	0x00000040	/* suggest mapfile assertions */
5471007fd6fSAli Bahrami 
5481007fd6fSAli Bahrami /*
5491007fd6fSAli Bahrami  * Test to see if a guidance should be given for a given category
5501007fd6fSAli Bahrami  * or not. _no_flag is one of the FLG_OFG_NO_xxx flags. Returns TRUE
5511007fd6fSAli Bahrami  * if the guidance should be issued, and FALSE to remain silent.
5521007fd6fSAli Bahrami  */
5531007fd6fSAli Bahrami #define	OFL_GUIDANCE(_ofl, _no_flag) (((_ofl)->ofl_guideflags & \
5541007fd6fSAli Bahrami 	(FLG_OFG_ENABLE | (_no_flag))) == FLG_OFG_ENABLE)
5551007fd6fSAli Bahrami 
5569039eeafSab /*
5579039eeafSab  * Test to see if the output file would allow the presence of
5589039eeafSab  * a .dynsym section.
5599039eeafSab  */
560f3324781Sab #define	OFL_ALLOW_DYNSYM(_ofl) (((_ofl)->ofl_flags & \
5619039eeafSab 	(FLG_OF_DYNAMIC | FLG_OF_RELOBJ)) == FLG_OF_DYNAMIC)
5629039eeafSab 
5639039eeafSab /*
5649039eeafSab  * Test to see if the output file would allow the presence of
5659039eeafSab  * a .SUNW_ldynsym section. The requirements are that a .dynsym
5669039eeafSab  * is allowed, and -znoldynsym has not been specified. Note that
5679039eeafSab  * even if the answer is True (1), we will only generate one if there
5689039eeafSab  * are local symbols that require it.
5699039eeafSab  */
570f3324781Sab #define	OFL_ALLOW_LDYNSYM(_ofl) (((_ofl)->ofl_flags & \
5719039eeafSab 	(FLG_OF_DYNAMIC | FLG_OF_RELOBJ | FLG_OF_NOLDYNSYM)) == FLG_OF_DYNAMIC)
5729039eeafSab 
573f3324781Sab /*
574f3324781Sab  * Test to see if relocation processing should be done. This is normally
575f3324781Sab  * true, but can be disabled via the '-z noreloc' option. Note that
576f3324781Sab  * relocatable objects are still relocated even if '-z noreloc' is present.
577f3324781Sab  */
578f3324781Sab #define	OFL_DO_RELOC(_ofl) (((_ofl)->ofl_flags & FLG_OF_RELOBJ) || \
579f3324781Sab 	!((_ofl)->ofl_dtflags_1 & DF_1_NORELOC))
580f3324781Sab 
581635216b6SRod Evans /*
582635216b6SRod Evans  * Determine whether a static executable is being built.
583635216b6SRod Evans  */
584635216b6SRod Evans #define	OFL_IS_STATIC_EXEC(_ofl) (((_ofl)->ofl_flags & \
585635216b6SRod Evans 	(FLG_OF_STATIC | FLG_OF_EXEC)) == (FLG_OF_STATIC | FLG_OF_EXEC))
586635216b6SRod Evans 
587635216b6SRod Evans /*
588635216b6SRod Evans  * Determine whether a static object is being built.  This macro is used
589635216b6SRod Evans  * to select the appropriate string table, and symbol table that other
590635216b6SRod Evans  * sections need to reference.
591635216b6SRod Evans  */
592635216b6SRod Evans #define	OFL_IS_STATIC_OBJ(_ofl) ((_ofl)->ofl_flags & \
593635216b6SRod Evans 	(FLG_OF_RELOBJ | FLG_OF_STATIC))
594635216b6SRod Evans 
595635216b6SRod Evans /*
596635216b6SRod Evans  * Macros for counting symbol table entries.  These are used to size symbol
597635216b6SRod Evans  * tables and associated sections (.syminfo, SUNW_capinfo, .hash, etc.) and
598635216b6SRod Evans  * set required sh_info entries (the offset to the first global symbol).
599635216b6SRod Evans  */
600635216b6SRod Evans #define	SYMTAB_LOC_CNT(_ofl)		/* local .symtab entries */	\
601635216b6SRod Evans 	(2 +				/*    NULL and STT_FILE */	\
602635216b6SRod Evans 	(_ofl)->ofl_shdrcnt +		/*    section symbol */		\
60308278a5eSRod Evans 	(_ofl)->ofl_caploclcnt +	/*    local capabilities */	\
604635216b6SRod Evans 	(_ofl)->ofl_scopecnt +		/*    scoped symbols */		\
605635216b6SRod Evans 	(_ofl)->ofl_locscnt)		/*    standard locals */
606635216b6SRod Evans #define	SYMTAB_ALL_CNT(_ofl)		/* all .symtab entries */	\
607635216b6SRod Evans 	(SYMTAB_LOC_CNT(_ofl) +		/*    .symtab locals */		\
608635216b6SRod Evans 	(_ofl)->ofl_globcnt)		/*    standard globals */
609635216b6SRod Evans 
610635216b6SRod Evans #define	DYNSYM_LOC_CNT(_ofl)		/* local .dynsym entries */	\
611635216b6SRod Evans 	(1 +				/*    NULL */			\
612635216b6SRod Evans 	(_ofl)->ofl_dynshdrcnt +	/*    section symbols */	\
61308278a5eSRod Evans 	(_ofl)->ofl_caploclcnt +	/*    local capabilities */	\
614635216b6SRod Evans 	(_ofl)->ofl_lregsymcnt)		/*    local register symbols */
615635216b6SRod Evans #define	DYNSYM_ALL_CNT(_ofl)		/* all .dynsym entries */	\
616635216b6SRod Evans 	(DYNSYM_LOC_CNT(_ofl) +		/*    .dynsym locals */		\
617635216b6SRod Evans 	(_ofl)->ofl_globcnt)		/*    standard globals */
618635216b6SRod Evans 
61957ef7aa9SRod Evans /*
62057ef7aa9SRod Evans  * Define a move descriptor used within relocation structures.
62157ef7aa9SRod Evans  */
62257ef7aa9SRod Evans typedef struct {
62357ef7aa9SRod Evans 	Move		*mr_move;
62457ef7aa9SRod Evans 	Sym_desc	*mr_sym;
62557ef7aa9SRod Evans } Mv_reloc;
62657ef7aa9SRod Evans 
6277c478bd9Sstevel@tonic-gate /*
6287c478bd9Sstevel@tonic-gate  * Relocation (active & output) processing structure - transparent to common
629bf994817SAli Bahrami  * code. There can be millions of these structures in a large link, so it
630bf994817SAli Bahrami  * is important to keep it small. You should only add new items to Rel_desc
631bf994817SAli Bahrami  * if they are critical, apply to most relocations, and cannot be easily
632bf994817SAli Bahrami  * computed from the other information.
633bf994817SAli Bahrami  *
634bf994817SAli Bahrami  * Items that can be derived should be implemented as a function that accepts
635bf994817SAli Bahrami  * a Rel_desc argument, and returns the desired data. ld_reloc_sym_name() is
636bf994817SAli Bahrami  * an example of this.
637bf994817SAli Bahrami  *
638bf994817SAli Bahrami  * Lesser used relocation data is kept in an auxiliary block, Rel_aux,
639bf994817SAli Bahrami  * that is only allocated as necessary. In exchange for adding one pointer
640bf994817SAli Bahrami  * of overhead to Rel_desc (rel_aux), most relocations are reduced in size
641bf994817SAli Bahrami  * by the size of Rel_aux. This strategy relies on the data in Rel_aux
642bf994817SAli Bahrami  * being rarely needed --- otherwise it will backfire badly.
643cce0e03bSab  *
644cce0e03bSab  * Note that rel_raddend is primarily only of interest to RELA relocations,
645cce0e03bSab  * and is set to 0 for REL. However, there is an exception: If FLG_REL_NADDEND
646cce0e03bSab  * is set, then rel_raddend contains a replacement value for the implicit
647cce0e03bSab  * addend found in the relocation target.
648bf994817SAli Bahrami  *
649bf994817SAli Bahrami  * Fields should be ordered from largest to smallest, to minimize packing
650bf994817SAli Bahrami  * holes in the struct layout.
6517c478bd9Sstevel@tonic-gate  */
6527c478bd9Sstevel@tonic-gate struct rel_desc {
6537c478bd9Sstevel@tonic-gate 	Is_desc		*rel_isdesc;	/* input section reloc is against */
6547c478bd9Sstevel@tonic-gate 	Sym_desc	*rel_sym;	/* sym relocation is against */
655bf994817SAli Bahrami 	Rel_aux		*rel_aux;	/* NULL, or auxiliary data */
6567c478bd9Sstevel@tonic-gate 	Xword		rel_roffset;	/* relocation offset */
6577c478bd9Sstevel@tonic-gate 	Sxword		rel_raddend;	/* addend from input relocation */
658bf994817SAli Bahrami 	Word		rel_flags;	/* misc. flags for relocations */
659bf994817SAli Bahrami 	Word		rel_rtype;	/* relocation type */
660bf994817SAli Bahrami };
661bf994817SAli Bahrami 
662bf994817SAli Bahrami /*
663bf994817SAli Bahrami  * Data that would be kept in Rel_desc if the size of that structure was
664bf994817SAli Bahrami  * not an issue. This auxiliary block is only allocated as needed,
665bf994817SAli Bahrami  * and must only contain rarely needed items. The goal is for the vast
666bf994817SAli Bahrami  * majority of Rel_desc structs to not have an auxiliary block.
667bf994817SAli Bahrami  *
668bf994817SAli Bahrami  * When a Rel_desc does not have an auxiliary block, a default value
669bf994817SAli Bahrami  * is assumed for each auxiliary item:
670bf994817SAli Bahrami  *
671bf994817SAli Bahrami  * -	ra_osdesc:
672bf994817SAli Bahrami  *	Output section to which relocation applies. The default
673bf994817SAli Bahrami  *	value for this is the output section associated with the
674bf994817SAli Bahrami  *	input section (rel_isdesc->is_osdesc), or NULL if there
675bf994817SAli Bahrami  *	is no associated input section.
676bf994817SAli Bahrami  *
677bf994817SAli Bahrami  * -	ra_usym:
678bf994817SAli Bahrami  *	If the symbol associated with a relocation is part of a weak/strong
679bf994817SAli Bahrami  *	pair, then ra_usym contains the strong symbol and rel_sym the weak.
680bf994817SAli Bahrami  *	Otherwise, the default value is the same value as rel_sym.
681bf994817SAli Bahrami  *
682bf994817SAli Bahrami  * -	ra_move:
683bf994817SAli Bahrami  *	Move table data. The default value is NULL.
684bf994817SAli Bahrami  *
685bf994817SAli Bahrami  * -	ra_typedata:
686bf994817SAli Bahrami  *	ELF_R_TYPE_DATA(info). This value applies only to a small
687bf994817SAli Bahrami  *	subset of 64-bit sparc relocations, and is otherwise 0. The
688bf994817SAli Bahrami  *	default value is 0.
689bf994817SAli Bahrami  *
690bf994817SAli Bahrami  * If any value in Rel_aux is non-default, then an auxiliary block is
691bf994817SAli Bahrami  * necessary, and each field contains its actual value. If all the auxiliary
692bf994817SAli Bahrami  * values are default, no Rel_aux is needed, and the RELAUX_GET_xxx()
693bf994817SAli Bahrami  * macros below are able to supply the proper default.
694bf994817SAli Bahrami  *
695bf994817SAli Bahrami  * To set a Rel_aux value, use the ld_reloc_set_aux_XXX() functions.
696bf994817SAli Bahrami  * These functions are written to avoid unnecessary auxiliary allocations,
697bf994817SAli Bahrami  * and know the rules for each item.
698bf994817SAli Bahrami  */
699bf994817SAli Bahrami struct rel_aux {
700bf994817SAli Bahrami 	Os_desc		*ra_osdesc;	/* output section reloc is against */
701bf994817SAli Bahrami 	Sym_desc	*ra_usym;	/* strong sym if this is a weak pair */
702bf994817SAli Bahrami 	Mv_reloc	*ra_move;	/* move table information */
703bf994817SAli Bahrami 	Word		ra_typedata;	/* ELF_R_TYPE_DATA(info) */
7047c478bd9Sstevel@tonic-gate };
7057c478bd9Sstevel@tonic-gate 
706bf994817SAli Bahrami /*
707bf994817SAli Bahrami  * Test a given auxiliary value to determine if it has the default value
708bf994817SAli Bahrami  * for that item, as described above. If all the auxiliary items have
709bf994817SAli Bahrami  * their default values, no auxiliary place is necessary to represent them.
710bf994817SAli Bahrami  * If any one of them is non-default, the auxiliary block is needed.
711bf994817SAli Bahrami  */
712bf994817SAli Bahrami #define	RELAUX_ISDEFAULT_MOVE(_rdesc, _mv) (_mv == NULL)
713bf994817SAli Bahrami #define	RELAUX_ISDEFAULT_USYM(_rdesc, _usym) ((_rdesc)->rel_sym == _usym)
714bf994817SAli Bahrami #define	RELAUX_ISDEFAULT_OSDESC(_rdesc, _osdesc) \
715bf994817SAli Bahrami 	((((_rdesc)->rel_isdesc == NULL) && (_osdesc == NULL)) || \
716bf994817SAli Bahrami 	((_rdesc)->rel_isdesc && ((_rdesc)->rel_isdesc->is_osdesc == _osdesc)))
717bf994817SAli Bahrami #define	RELAUX_ISDEFAULT_TYPEDATA(_rdesc, _typedata) (_typedata == 0)
718bf994817SAli Bahrami 
719bf994817SAli Bahrami /*
720bf994817SAli Bahrami  * Retrieve the value of an auxiliary relocation item, preserving the illusion
721bf994817SAli Bahrami  * that every relocation descriptor has an auxiliary block attached. The
722bf994817SAli Bahrami  * real implementation is that an auxiliary block is only present if one or
723bf994817SAli Bahrami  * more auxiliary items have non-default values. These macros return the true
724bf994817SAli Bahrami  * value if an auxiliary block is present, and the default value for the
725bf994817SAli Bahrami  * item otherwise.
726bf994817SAli Bahrami  */
727bf994817SAli Bahrami #define	RELAUX_GET_MOVE(_rdesc) \
728bf994817SAli Bahrami 	((_rdesc)->rel_aux ? (_rdesc)->rel_aux->ra_move : NULL)
729bf994817SAli Bahrami #define	RELAUX_GET_USYM(_rdesc) \
730bf994817SAli Bahrami 	((_rdesc)->rel_aux ? (_rdesc)->rel_aux->ra_usym : (_rdesc)->rel_sym)
731bf994817SAli Bahrami #define	RELAUX_GET_OSDESC(_rdesc) \
732bf994817SAli Bahrami 	((_rdesc)->rel_aux ? (_rdesc)->rel_aux->ra_osdesc : \
733bf994817SAli Bahrami 	((_rdesc)->rel_isdesc ? (_rdesc)->rel_isdesc->is_osdesc : NULL))
734bf994817SAli Bahrami #define	RELAUX_GET_TYPEDATA(_rdesc) \
735bf994817SAli Bahrami 	((_rdesc)->rel_aux ? (_rdesc)->rel_aux->ra_typedata : 0)
736bf994817SAli Bahrami 
7377c478bd9Sstevel@tonic-gate /*
7387c478bd9Sstevel@tonic-gate  * common flags used on the Rel_desc structure (defined in machrel.h).
7397c478bd9Sstevel@tonic-gate  */
7407c478bd9Sstevel@tonic-gate #define	FLG_REL_GOT	0x00000001	/* relocation against GOT */
7417c478bd9Sstevel@tonic-gate #define	FLG_REL_PLT	0x00000002	/* relocation against PLT */
7427c478bd9Sstevel@tonic-gate #define	FLG_REL_BSS	0x00000004	/* relocation against BSS */
7437c478bd9Sstevel@tonic-gate #define	FLG_REL_LOAD	0x00000008	/* section loadable */
7447c478bd9Sstevel@tonic-gate #define	FLG_REL_SCNNDX	0x00000010	/* use section index for symbol ndx */
7457c478bd9Sstevel@tonic-gate #define	FLG_REL_CLVAL	0x00000020	/* clear VALUE for active relocation */
7467c478bd9Sstevel@tonic-gate #define	FLG_REL_ADVAL	0x00000040	/* add VALUE for output relocation, */
74763360950Smp 					/*	only relevant to SPARC and */
7487c478bd9Sstevel@tonic-gate 					/*	R_SPARC_RELATIVE */
7497c478bd9Sstevel@tonic-gate #define	FLG_REL_GOTCL	0x00000080	/* clear the GOT entry.  This is */
7507c478bd9Sstevel@tonic-gate 					/* relevant to RELA relocations, */
7517c478bd9Sstevel@tonic-gate 					/* not REL (i386) relocations */
7527c478bd9Sstevel@tonic-gate #define	FLG_REL_MOVETAB	0x00000100	/* Relocation against .SUNW_move */
7537c478bd9Sstevel@tonic-gate 					/*	adjustments required before */
7547c478bd9Sstevel@tonic-gate 					/*	actual relocation */
7557c478bd9Sstevel@tonic-gate #define	FLG_REL_NOINFO	0x00000200	/* Relocation comes from a section */
7567c478bd9Sstevel@tonic-gate 					/*	with a null sh_info field */
7577c478bd9Sstevel@tonic-gate #define	FLG_REL_REG	0x00000400	/* Relocation target is reg sym */
7587c478bd9Sstevel@tonic-gate #define	FLG_REL_FPTR	0x00000800	/* relocation against func. desc. */
7597c478bd9Sstevel@tonic-gate #define	FLG_REL_RFPTR1	0x00001000	/* Relative relocation against */
7607c478bd9Sstevel@tonic-gate 					/*   1st part of FD */
7617c478bd9Sstevel@tonic-gate #define	FLG_REL_RFPTR2	0x00002000	/* Relative relocation against */
7627c478bd9Sstevel@tonic-gate 					/*   2nd part of FD */
7637c478bd9Sstevel@tonic-gate #define	FLG_REL_DISP	0x00004000	/* *disp* relocation */
7647c478bd9Sstevel@tonic-gate #define	FLG_REL_STLS	0x00008000	/* IE TLS reference to */
7657c478bd9Sstevel@tonic-gate 					/*	static TLS GOT index */
7667c478bd9Sstevel@tonic-gate #define	FLG_REL_DTLS	0x00010000	/* GD TLS reference relative to */
7677c478bd9Sstevel@tonic-gate 					/*	dynamic TLS GOT index */
7687c478bd9Sstevel@tonic-gate #define	FLG_REL_MTLS	0x00020000	/* LD TLS reference against GOT */
7697c478bd9Sstevel@tonic-gate #define	FLG_REL_STTLS	0x00040000	/* LE TLS reference directly */
7707c478bd9Sstevel@tonic-gate 					/*	to static tls index */
7717c478bd9Sstevel@tonic-gate #define	FLG_REL_TLSFIX	0x00080000	/* relocation points to TLS instr. */
7727c478bd9Sstevel@tonic-gate 					/*	which needs updating */
77357ef7aa9SRod Evans #define	FLG_REL_RELA	0x00100000	/* descriptor captures a Rela */
7747c478bd9Sstevel@tonic-gate #define	FLG_REL_GOTFIX	0x00200000	/* relocation points to GOTOP instr. */
7757c478bd9Sstevel@tonic-gate 					/*	which needs updating */
776cce0e03bSab #define	FLG_REL_NADDEND	0x00400000	/* Replace implicit addend in dest */
777cce0e03bSab 					/*	with value in rel_raddend */
778cce0e03bSab 					/*	Relevant to REL (i386) */
779cce0e03bSab 					/*	relocations, not to RELA. */
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate /*
782bf994817SAli Bahrami  * We often need the name of the symbol contained in a relocation descriptor
783bf994817SAli Bahrami  * for diagnostic or error output. This is usually the symbol name, but
784bf994817SAli Bahrami  * we substitute a constructed name in some cases. Hence, the name is
785bf994817SAli Bahrami  * generated on the fly by a private function within libld. This is the
786bf994817SAli Bahrami  * prototype for that function.
7877c478bd9Sstevel@tonic-gate  */
788bf994817SAli Bahrami typedef const char *(* rel_desc_sname_func_t)(Rel_desc *);
789bf994817SAli Bahrami 
790bf994817SAli Bahrami /*
791bf994817SAli Bahrami  * Header for a relocation descriptor cache buffer.
792bf994817SAli Bahrami  */
793bf994817SAli Bahrami struct rel_cachebuf {
7947c478bd9Sstevel@tonic-gate 	Rel_desc	*rc_end;
7957c478bd9Sstevel@tonic-gate 	Rel_desc	*rc_free;
796bf994817SAli Bahrami 	Rel_desc	rc_arr[1];
797bf994817SAli Bahrami };
798bf994817SAli Bahrami 
799bf994817SAli Bahrami /*
800bf994817SAli Bahrami  * Header for a relocation auxiliary descriptor cache buffer.
801bf994817SAli Bahrami  */
802bf994817SAli Bahrami struct rel_aux_cachebuf {
803bf994817SAli Bahrami 	Rel_aux		*rac_end;
804bf994817SAli Bahrami 	Rel_aux		*rac_free;
805bf994817SAli Bahrami 	Rel_aux		rac_arr[1];
8067c478bd9Sstevel@tonic-gate };
8077c478bd9Sstevel@tonic-gate 
808bf994817SAli Bahrami /*
809bf994817SAli Bahrami  * Convenience macro for traversing every relocation descriptor found within
810bf994817SAli Bahrami  * a given relocation cache, transparently handling the cache buffers and
811bf994817SAli Bahrami  * skipping any unallocated descriptors within the buffers.
812bf994817SAli Bahrami  *
813bf994817SAli Bahrami  * entry:
814bf994817SAli Bahrami  *	_rel_cache - Relocate descriptor cache (Rel_cache) to traverse
815bf994817SAli Bahrami  *	_idx - Aliste index variable for use by the macro
816bf994817SAli Bahrami  *	_rcbp - Cache buffer pointer, for use by the macro
817bf994817SAli Bahrami  *	_orsp - Rel_desc pointer, which will take on the value of a different
818bf994817SAli Bahrami  *		relocation descriptor in the cache in each iteration.
819bf994817SAli Bahrami  *
820bf994817SAli Bahrami  * The caller must not assign new values to _idx, _rcbp, or _orsp within
821bf994817SAli Bahrami  * the scope of REL_CACHE_TRAVERSE.
822bf994817SAli Bahrami  */
823bf994817SAli Bahrami #define	REL_CACHE_TRAVERSE(_rel_cache, _idx, _rcbp, _orsp) \
824bf994817SAli Bahrami 	for (APLIST_TRAVERSE((_rel_cache)->rc_list, _idx, _rcbp)) \
825bf994817SAli Bahrami 		for (_orsp = _rcbp->rc_arr; _orsp < _rcbp->rc_free; _orsp++)
826bf994817SAli Bahrami 
8277c478bd9Sstevel@tonic-gate /*
8287c478bd9Sstevel@tonic-gate  * Symbol value descriptor.  For relocatable objects, each symbols value is
8297c478bd9Sstevel@tonic-gate  * its offset within its associated section.  Therefore, to uniquely define
830bf994817SAli Bahrami  * each symbol within a relocatable object, record and sort the sh_offset and
83108278a5eSRod Evans  * symbol value.  This information is used to search for displacement
8327c478bd9Sstevel@tonic-gate  * relocations as part of copy relocation validation.
8337c478bd9Sstevel@tonic-gate  */
8347c478bd9Sstevel@tonic-gate typedef struct {
8357c478bd9Sstevel@tonic-gate 	Addr		ssv_value;
8367c478bd9Sstevel@tonic-gate 	Sym_desc	*ssv_sdp;
8377c478bd9Sstevel@tonic-gate } Ssv_desc;
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate /*
8407c478bd9Sstevel@tonic-gate  * Input file processing structures.
8417c478bd9Sstevel@tonic-gate  */
8427c478bd9Sstevel@tonic-gate struct ifl_desc {			/* input file descriptor */
8437c478bd9Sstevel@tonic-gate 	const char	*ifl_name;	/* full file name */
8447c478bd9Sstevel@tonic-gate 	const char	*ifl_soname;	/* shared object name */
8457c478bd9Sstevel@tonic-gate 	dev_t		ifl_stdev;	/* device id and inode number for .so */
8467c478bd9Sstevel@tonic-gate 	ino_t		ifl_stino;	/*	multiple inclusion checks */
8477c478bd9Sstevel@tonic-gate 	Ehdr		*ifl_ehdr;	/* elf header describing this file */
8487c478bd9Sstevel@tonic-gate 	Elf		*ifl_elf;	/* elf descriptor for this file */
8497c478bd9Sstevel@tonic-gate 	Sym_desc	**ifl_oldndx;	/* original symbol table indices */
8507c478bd9Sstevel@tonic-gate 	Sym_desc	*ifl_locs;	/* symbol desc version of locals */
8517c478bd9Sstevel@tonic-gate 	Ssv_desc	*ifl_sortsyms;	/* sorted list of symbols by value */
8527c478bd9Sstevel@tonic-gate 	Word		ifl_locscnt;	/* no. of local symbols to process */
8537c478bd9Sstevel@tonic-gate 	Word		ifl_symscnt;	/* total no. of symbols to process */
8547c478bd9Sstevel@tonic-gate 	Word		ifl_sortcnt;	/* no. of sorted symbols to process */
8557c478bd9Sstevel@tonic-gate 	Word		ifl_shnum;	/* number of sections in file */
8567c478bd9Sstevel@tonic-gate 	Word		ifl_shstrndx;	/* index to .shstrtab */
8577c478bd9Sstevel@tonic-gate 	Word		ifl_vercnt;	/* number of versions in file */
85857ef7aa9SRod Evans 	Half		ifl_neededndx;	/* index to NEEDED in .dyn section */
85928bda19cSRod Evans 	Word		ifl_flags;	/* explicit/implicit reference */
8607c478bd9Sstevel@tonic-gate 	Is_desc		**ifl_isdesc;	/* isdesc[scn ndx] = Is_desc ptr */
8617c478bd9Sstevel@tonic-gate 	Sdf_desc	*ifl_sdfdesc;	/* control definition */
8627c478bd9Sstevel@tonic-gate 	Versym		*ifl_versym;	/* version symbol table array */
8637c478bd9Sstevel@tonic-gate 	Ver_index	*ifl_verndx;	/* verndx[ver ndx] = Ver_index */
86457ef7aa9SRod Evans 	APlist		*ifl_verdesc;	/* version descriptor list */
86557ef7aa9SRod Evans 	APlist		*ifl_relsect;	/* relocation section list */
866cc7efc4fSrie 	Alist		*ifl_groups;	/* SHT_GROUP section list */
86708278a5eSRod Evans 	Cap_desc	*ifl_caps;	/* capabilities descriptor */
8687c478bd9Sstevel@tonic-gate };
8697c478bd9Sstevel@tonic-gate 
870d840867fSab #define	FLG_IF_CMDLINE	0x00000001	/* full filename specified from the */
8717c478bd9Sstevel@tonic-gate 					/*	command line (no -l) */
872d840867fSab #define	FLG_IF_NEEDED	0x00000002	/* shared object should be recorded */
873d840867fSab #define	FLG_IF_DIRECT	0x00000004	/* establish direct bindings to this */
8747c478bd9Sstevel@tonic-gate 					/*	object */
875d840867fSab #define	FLG_IF_EXTRACT	0x00000008	/* file extracted from an archive */
876d840867fSab #define	FLG_IF_VERNEED	0x00000010	/* version dependency information is */
8777c478bd9Sstevel@tonic-gate 					/*	required */
878d840867fSab #define	FLG_IF_DEPREQD	0x00000020	/* dependency is required to satisfy */
8797c478bd9Sstevel@tonic-gate 					/*	symbol references */
880d840867fSab #define	FLG_IF_NEEDSTR	0x00000040	/* dependency specified by -Nn */
8817c478bd9Sstevel@tonic-gate 					/*	flag */
882d840867fSab #define	FLG_IF_IGNORE	0x00000080	/* ignore unused dependencies */
883d840867fSab #define	FLG_IF_NODIRECT	0x00000100	/* object contains symbols that */
884635216b6SRod Evans 					/*	cannot be directly bound to */
885f441771bSRod Evans #define	FLG_IF_LAZYLD	0x00000200	/* dependency should be lazy loaded */
886f441771bSRod Evans #define	FLG_IF_GRPPRM	0x00000400	/* dependency establishes a group */
887d840867fSab #define	FLG_IF_DISPPEND 0x00000800	/* displacement relocation done */
8887c478bd9Sstevel@tonic-gate 					/*	in the ld time. */
889d840867fSab #define	FLG_IF_DISPDONE 0x00001000	/* displacement relocation done */
890b6a0e2cdSRichard Lowe 					/*	at the run time */
891d840867fSab #define	FLG_IF_MAPFILE	0x00002000	/* file is a mapfile */
892d840867fSab #define	FLG_IF_HSTRTAB	0x00004000	/* file has a string section */
893d840867fSab #define	FLG_IF_FILEREF	0x00008000	/* file contains a section which */
8947c478bd9Sstevel@tonic-gate 					/*	is included in the output */
8957c478bd9Sstevel@tonic-gate 					/*	allocatable image */
896d840867fSab #define	FLG_IF_GNUVER	0x00010000	/* file used GNU-style versioning */
8970e233487SRod Evans #define	FLG_IF_ORDERED	0x00020000	/* ordered section processing */
8980e233487SRod Evans 					/*	required */
89908278a5eSRod Evans #define	FLG_IF_OTOSCAP	0x00040000	/* convert object capabilities to */
90008278a5eSRod Evans 					/*	symbol capabilities */
901f441771bSRod Evans #define	FLG_IF_DEFERRED	0x00080000	/* dependency is deferred */
9021007fd6fSAli Bahrami #define	FLG_IF_RTLDINF	0x00100000	/* dependency has DT_SUNW_RTLTINF set */
903a8c23f9dSRichard Lowe #define	FLG_IF_GROUPS	0x00200000	/* input file has groups to process */
904f441771bSRod Evans 
905f441771bSRod Evans /*
906f441771bSRod Evans  * Symbol states that require the generation of a DT_POSFLAG_1 .dynamic entry.
907f441771bSRod Evans  */
908f441771bSRod Evans #define	MSK_IF_POSFLAG1	(FLG_IF_LAZYLD | FLG_IF_GRPPRM | FLG_IF_DEFERRED)
909f441771bSRod Evans 
910f441771bSRod Evans /*
911f441771bSRod Evans  * Symbol states that require an associated Syminfo entry.
912f441771bSRod Evans  */
913f441771bSRod Evans #define	MSK_IF_SYMINFO	(FLG_IF_LAZYLD | FLG_IF_DIRECT | FLG_IF_DEFERRED)
914f441771bSRod Evans 
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate struct is_desc {			/* input section descriptor */
9170e233487SRod Evans 	const char	*is_name;	/* original section name */
918bf994817SAli Bahrami 	const char	*is_sym_name;	/* NULL, or name string to use for */
919bf994817SAli Bahrami 					/*	related STT_SECTION symbols */
9207c478bd9Sstevel@tonic-gate 	Shdr		*is_shdr;	/* the elf section header */
9217c478bd9Sstevel@tonic-gate 	Ifl_desc	*is_file;	/* infile desc for this section */
9227c478bd9Sstevel@tonic-gate 	Os_desc		*is_osdesc;	/* new output section for this */
9237c478bd9Sstevel@tonic-gate 					/*	input section */
9247c478bd9Sstevel@tonic-gate 	Elf_Data	*is_indata;	/* input sections raw data */
9257c478bd9Sstevel@tonic-gate 	Is_desc		*is_symshndx;	/* related SHT_SYM_SHNDX section */
9266b3ba5bdSAli Bahrami 	Is_desc		*is_comdatkeep;	/* If COMDAT section is discarded, */
927b6a0e2cdSRichard Lowe 					/*	this is section that was kept */
9287c478bd9Sstevel@tonic-gate 	Word		is_scnndx;	/* original section index in file */
92908278a5eSRod Evans 	Word		is_ordndx;	/* index for section.  Used to decide */
9307c478bd9Sstevel@tonic-gate 					/*	where to insert section when */
931b6a0e2cdSRichard Lowe 					/*	reordering sections */
9321dd9d86fSAli Bahrami 	Word		is_keyident;	/* key for SHF_{ORDERED|LINK_ORDER} */
9331dd9d86fSAli Bahrami 					/*	processing and ident used for */
9341dd9d86fSAli Bahrami 					/*	 placing/ordering sections */
9350e233487SRod Evans 	Word		is_flags;	/* Various flags */
9367c478bd9Sstevel@tonic-gate };
9377c478bd9Sstevel@tonic-gate 
9380e233487SRod Evans #define	FLG_IS_ORDERED	0x0001		/* this is a SHF_ORDERED section */
9390e233487SRod Evans #define	FLG_IS_KEY	0x0002		/* section requires sort keys */
9407c478bd9Sstevel@tonic-gate #define	FLG_IS_DISCARD	0x0004		/* section is to be discarded */
9417c478bd9Sstevel@tonic-gate #define	FLG_IS_RELUPD	0x0008		/* symbol defined here may have moved */
9427c478bd9Sstevel@tonic-gate #define	FLG_IS_SECTREF	0x0010		/* section has been referenced */
9437c478bd9Sstevel@tonic-gate #define	FLG_IS_GDATADEF	0x0020		/* section contains global data sym */
94469112eddSAli Bahrami #define	FLG_IS_EXTERNAL	0x0040		/* isp from a user file */
945cce0e03bSab #define	FLG_IS_INSTRMRG	0x0080		/* Usable SHF_MERGE|SHF_STRINGS sec */
946cce0e03bSab #define	FLG_IS_GNSTRMRG	0x0100		/* Generated mergeable string section */
947a8c23f9dSRichard Lowe 
9480e233487SRod Evans #define	FLG_IS_PLACE	0x0400		/* section requires to be placed */
9490e233487SRod Evans #define	FLG_IS_COMDAT	0x0800		/* section is COMDAT */
9507e16fca0SAli Bahrami #define	FLG_IS_EHFRAME	0x1000		/* section is .eh_frame */
9517c478bd9Sstevel@tonic-gate 
9521dd9d86fSAli Bahrami /*
9531dd9d86fSAli Bahrami  * Output sections contain lists of input sections that are assigned to them.
9541dd9d86fSAli Bahrami  * These items fall into 4 categories:
9551dd9d86fSAli Bahrami  *	BEFORE - Ordered sections that specify SHN_BEFORE, in input order.
9561dd9d86fSAli Bahrami  *	ORDERED - Ordered sections that are sorted using unsorted sections
9571dd9d86fSAli Bahrami  *		as the sort key.
9581dd9d86fSAli Bahrami  *	DEFAULT - Sections that are placed into the output section
9591dd9d86fSAli Bahrami  *		in input order.
9601dd9d86fSAli Bahrami  *	AFTER - Ordered sections that specify SHN_AFTER, in input order.
9611dd9d86fSAli Bahrami  */
9621dd9d86fSAli Bahrami #define	OS_ISD_BEFORE	0
9631dd9d86fSAli Bahrami #define	OS_ISD_ORDERED	1
9641dd9d86fSAli Bahrami #define	OS_ISD_DEFAULT	2
9651dd9d86fSAli Bahrami #define	OS_ISD_AFTER	3
9661dd9d86fSAli Bahrami #define	OS_ISD_NUM	4
9671dd9d86fSAli Bahrami typedef APlist *os_isdecs_arr[OS_ISD_NUM];
9681dd9d86fSAli Bahrami 
9691dd9d86fSAli Bahrami /*
9701dd9d86fSAli Bahrami  * Convenience macro for traversing every input section associated
9711dd9d86fSAli Bahrami  * with a given output section. The primary benefit of this macro
9721dd9d86fSAli Bahrami  * is that it preserves a precious level of code indentation in the
9731dd9d86fSAli Bahrami  * code that uses it.
9741dd9d86fSAli Bahrami  */
9751dd9d86fSAli Bahrami #define	OS_ISDESCS_TRAVERSE(_list_idx, _osp, _idx, _isp) \
9761dd9d86fSAli Bahrami 	for (_list_idx = 0; _list_idx < OS_ISD_NUM; _list_idx++) \
9771dd9d86fSAli Bahrami 		for (APLIST_TRAVERSE(_osp->os_isdescs[_list_idx], _idx, _isp))
9781dd9d86fSAli Bahrami 
9791dd9d86fSAli Bahrami 
9807c478bd9Sstevel@tonic-gate /*
9817c478bd9Sstevel@tonic-gate  * Map file and output file processing structures
9827c478bd9Sstevel@tonic-gate  */
9837c478bd9Sstevel@tonic-gate struct os_desc {			/* Output section descriptor */
9847c478bd9Sstevel@tonic-gate 	const char	*os_name;	/* the section name */
9857c478bd9Sstevel@tonic-gate 	Elf_Scn		*os_scn;	/* the elf section descriptor */
9867c478bd9Sstevel@tonic-gate 	Shdr		*os_shdr;	/* the elf section header */
9877c478bd9Sstevel@tonic-gate 	Os_desc		*os_relosdesc;	/* the output relocation section */
9886b3ba5bdSAli Bahrami 	APlist		*os_relisdescs;	/* reloc input section descriptors */
9897c478bd9Sstevel@tonic-gate 					/*	for this output section */
9901dd9d86fSAli Bahrami 	os_isdecs_arr	os_isdescs;	/* lists of input sections in output */
991cce0e03bSab 	APlist		*os_mstrisdescs; /* FLG_IS_INSTRMRG input sections */
9927c478bd9Sstevel@tonic-gate 	Sg_desc		*os_sgdesc;	/* segment os_desc is placed on */
9937c478bd9Sstevel@tonic-gate 	Elf_Data	*os_outdata;	/* output sections raw data */
9946b3ba5bdSAli Bahrami 	avl_tree_t	*os_comdats;	/* AVL tree of COMDAT input sections */
9956b3ba5bdSAli Bahrami 					/*	associated to output section */
99657ef7aa9SRod Evans 	Word		os_identndx;	/* section identifier for input */
99757ef7aa9SRod Evans 					/*	section processing, followed */
99857ef7aa9SRod Evans 					/*	by section symbol index */
99957ef7aa9SRod Evans 	Word		os_ordndx;	/* index for section.  Used to decide */
10007c478bd9Sstevel@tonic-gate 					/*	where to insert section when */
1001b6a0e2cdSRichard Lowe 					/*	reordering sections */
10027c478bd9Sstevel@tonic-gate 	Xword		os_szoutrels;	/* size of output relocation section */
10037c478bd9Sstevel@tonic-gate 	uint_t		os_namehash;	/* hash on section name */
10047c478bd9Sstevel@tonic-gate 	uchar_t		os_flags;	/* various flags */
1005252adeb3SRichard Lowe 	APlist		*os_mstrsyms;	/* symbols affected by string merge */
1006252adeb3SRichard Lowe 	APlist		*os_mstrrels;	/* section relocs affected by... */
1007252adeb3SRichard Lowe 	Str_tbl		*os_mstrtab;	/* merged string table */
1008*a48fdbefSBryan Cantrill 	Os_desc		*os_hashnext;	/* next hashed */
10097c478bd9Sstevel@tonic-gate };
10107c478bd9Sstevel@tonic-gate 
1011*a48fdbefSBryan Cantrill /*
1012*a48fdbefSBryan Cantrill  * Hash of output section descriptors, by namehash.
1013*a48fdbefSBryan Cantrill  */
1014*a48fdbefSBryan Cantrill typedef struct os_desc_hash {
1015*a48fdbefSBryan Cantrill 	Os_desc		**osh_hashtab;	/* hash table itself */
1016*a48fdbefSBryan Cantrill 	size_t		osh_size;	/* number of elements in hash table */
1017*a48fdbefSBryan Cantrill } os_desc_hash_t;
1018*a48fdbefSBryan Cantrill 
10190e233487SRod Evans #define	FLG_OS_KEY		0x01	/* section requires sort keys */
10207c478bd9Sstevel@tonic-gate #define	FLG_OS_OUTREL		0x02	/* output rel against this section */
1021dd94ecefSrie #define	FLG_OS_SECTREF		0x04	/* isps are not affected by -zignore */
1022d444b03eSAli Bahrami #define	FLG_OS_EHFRAME		0x08	/* section is .eh_frame */
10237c478bd9Sstevel@tonic-gate 
102457ef7aa9SRod Evans /*
102569112eddSAli Bahrami  * The sg_id field of the segment descriptor is used to establish the default
102669112eddSAli Bahrami  * order for program headers and segments in the output object. Segments are
102769112eddSAli Bahrami  * ordered according to the following SGID values that classify them based on
102869112eddSAli Bahrami  * their attributes. The initial set of built in segments are in this order,
102969112eddSAli Bahrami  * and new mapfile defined segments are inserted into these groups. Within a
103069112eddSAli Bahrami  * given SGID group, the position of new segments depends on the syntax
103169112eddSAli Bahrami  * version of the mapfile that creates them. Version 1 (original sysv)
103269112eddSAli Bahrami  * mapfiles place the new segment at the head of their group (reverse creation
103369112eddSAli Bahrami  * order). The newer syntax places them at the end, following the others
103469112eddSAli Bahrami  * (creation order).
103569112eddSAli Bahrami  *
103669112eddSAli Bahrami  * Note that any new segments must always be added after PT_PHDR and
103769112eddSAli Bahrami  * PT_INTERP (refer Generic ABI, Page 5-4).
103857ef7aa9SRod Evans  */
103969112eddSAli Bahrami #define	SGID_PHDR	0	/* PT_PHDR */
104069112eddSAli Bahrami #define	SGID_INTERP	1	/* PT_INTERP */
104169112eddSAli Bahrami #define	SGID_SUNWCAP	2	/* PT_SUNWCAP */
104269112eddSAli Bahrami #define	SGID_TEXT	3	/* PT_LOAD */
104369112eddSAli Bahrami #define	SGID_DATA	4	/* PT_LOAD */
104469112eddSAli Bahrami #define	SGID_BSS	5	/* PT_LOAD */
104557ef7aa9SRod Evans #if	defined(_ELF64)
104669112eddSAli Bahrami #define	SGID_LRODATA	6	/* PT_LOAD (amd64-only) */
104769112eddSAli Bahrami #define	SGID_LDATA	7	/* PT_LOAD (amd64-only) */
104857ef7aa9SRod Evans #endif
104969112eddSAli Bahrami #define	SGID_TEXT_EMPTY	8	/* PT_LOAD, reserved (?E in version 1 syntax) */
105069112eddSAli Bahrami #define	SGID_NULL_EMPTY	9	/* PT_NULL, reserved (?E in version 1 syntax) */
105169112eddSAli Bahrami #define	SGID_DYN	10	/* PT_DYNAMIC */
105269112eddSAli Bahrami #define	SGID_DTRACE	11	/* PT_SUNWDTRACE */
105369112eddSAli Bahrami #define	SGID_TLS	12	/* PT_TLS */
105469112eddSAli Bahrami #define	SGID_UNWIND	13	/* PT_SUNW_UNWIND */
105569112eddSAli Bahrami #define	SGID_SUNWSTACK	14	/* PT_SUNWSTACK */
105669112eddSAli Bahrami #define	SGID_NOTE	15	/* PT_NOTE */
105769112eddSAli Bahrami #define	SGID_NULL	16	/* PT_NULL,  mapfile defined empty phdr slots */
105869112eddSAli Bahrami 				/*	for use by post processors */
105969112eddSAli Bahrami #define	SGID_EXTRA	17	/* PT_NULL (final catchall) */
106069112eddSAli Bahrami 
106169112eddSAli Bahrami typedef Half sg_flags_t;
10627c478bd9Sstevel@tonic-gate struct sg_desc {			/* output segment descriptor */
106369112eddSAli Bahrami 	Word		sg_id;		/* segment identifier (for sorting) */
10647c478bd9Sstevel@tonic-gate 	Phdr		sg_phdr;	/* segment header for output file */
106569112eddSAli Bahrami 	const char	*sg_name;	/* segment name for PT_LOAD, PT_NOTE, */
106669112eddSAli Bahrami 					/*	and PT_NULL, otherwise NULL */
10677c478bd9Sstevel@tonic-gate 	Xword		sg_round;	/* data rounding required (mapfile) */
10687c478bd9Sstevel@tonic-gate 	Xword		sg_length;	/* maximum segment length; if 0 */
10697c478bd9Sstevel@tonic-gate 					/*	segment is not specified */
1070cce0e03bSab 	APlist		*sg_osdescs;	/* list of output section descriptors */
107169112eddSAli Bahrami 	APlist		*sg_is_order;	/* list of entry criteria */
107269112eddSAli Bahrami 					/*	giving input section order */
107369112eddSAli Bahrami 	Alist		*sg_os_order;	/* list specifying output section */
107469112eddSAli Bahrami 					/*	ordering for the segment */
107569112eddSAli Bahrami 	sg_flags_t	sg_flags;
107669112eddSAli Bahrami 	APlist		*sg_sizesym;	/* size symbols for this segment */
107769112eddSAli Bahrami 	Xword		sg_align;	/* LCM of sh_addralign */
10787c478bd9Sstevel@tonic-gate 	Elf_Scn		*sg_fscn;	/* the SCN of the first section. */
107969112eddSAli Bahrami 	avl_node_t	sg_avlnode;	/* AVL book-keeping */
1080*a48fdbefSBryan Cantrill 	os_desc_hash_t	*sg_hashtab;	/* hash table of output descriptors */
10817c478bd9Sstevel@tonic-gate };
10827c478bd9Sstevel@tonic-gate 
108369112eddSAli Bahrami #define	FLG_SG_P_VADDR		0x0001	/* p_vaddr segment attribute set */
108469112eddSAli Bahrami #define	FLG_SG_P_PADDR		0x0002	/* p_paddr segment attribute set */
108569112eddSAli Bahrami #define	FLG_SG_LENGTH		0x0004	/* length segment attribute set */
108669112eddSAli Bahrami #define	FLG_SG_P_ALIGN		0x0008	/* p_align segment attribute set */
108769112eddSAli Bahrami #define	FLG_SG_ROUND		0x0010	/* round segment attribute set */
108869112eddSAli Bahrami #define	FLG_SG_P_FLAGS		0x0020	/* p_flags segment attribute set */
108969112eddSAli Bahrami #define	FLG_SG_P_TYPE		0x0040	/* p_type segment attribute set */
109069112eddSAli Bahrami #define	FLG_SG_IS_ORDER		0x0080	/* input section ordering is required */
1091b6a0e2cdSRichard Lowe 					/*	for this segment. */
109269112eddSAli Bahrami #define	FLG_SG_NOHDR		0x0100	/* don't map ELF or phdrs into */
109369112eddSAli Bahrami 					/*	this segment */
109469112eddSAli Bahrami #define	FLG_SG_EMPTY		0x0200	/* an empty segment specification */
10957c478bd9Sstevel@tonic-gate 					/*	no input sections will be */
10967c478bd9Sstevel@tonic-gate 					/*	associated to this section */
109769112eddSAli Bahrami #define	FLG_SG_KEY		0x0400	/* segment requires sort keys */
109869112eddSAli Bahrami #define	FLG_SG_NODISABLE	0x0800	/* FLG_SG_DISABLED is not allowed on */
109969112eddSAli Bahrami 					/*	this segment */
110069112eddSAli Bahrami #define	FLG_SG_DISABLED		0x1000	/* this segment is disabled */
110169112eddSAli Bahrami #define	FLG_SG_PHREQ		0x2000	/* this segment requires a program */
110254d82594Sseizo 					/* header */
110369112eddSAli Bahrami #define	FLG_SG_ORDERED		0x4000	/* SEGMENT_ORDER segment */
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate struct sec_order {
11067c478bd9Sstevel@tonic-gate 	const char	*sco_secname;	/* section name to be ordered */
11077c478bd9Sstevel@tonic-gate 	Half		sco_flags;
11087c478bd9Sstevel@tonic-gate };
11097c478bd9Sstevel@tonic-gate 
11107c478bd9Sstevel@tonic-gate #define	FLG_SGO_USED	0x0001		/* was ordering used? */
11117c478bd9Sstevel@tonic-gate 
111269112eddSAli Bahrami typedef Half ec_flags_t;
11137c478bd9Sstevel@tonic-gate struct ent_desc {			/* input section entrance criteria */
111469112eddSAli Bahrami 	const char	*ec_name;	/* entrace criteria name, or NULL */
111569112eddSAli Bahrami 	Alist		*ec_files;	/* files from which to accept */
11167c478bd9Sstevel@tonic-gate 					/*	sections */
111769112eddSAli Bahrami 	const char	*ec_is_name;	/* input section name to match */
111869112eddSAli Bahrami 					/*	(NULL if none) */
11197c478bd9Sstevel@tonic-gate 	Word		ec_type;	/* section type */
112054d82594Sseizo 	Word		ec_attrmask;	/* section attribute mask (AWX) */
112154d82594Sseizo 	Word		ec_attrbits;	/* sections attribute bits */
11227c478bd9Sstevel@tonic-gate 	Sg_desc		*ec_segment;	/* output segment to enter if matched */
112357ef7aa9SRod Evans 	Word		ec_ordndx;	/* index to determine where section */
11247c478bd9Sstevel@tonic-gate 					/*	meeting this criteria should */
11257c478bd9Sstevel@tonic-gate 					/*	inserted. Used for reordering */
11267c478bd9Sstevel@tonic-gate 					/*	of sections. */
112769112eddSAli Bahrami 	ec_flags_t	ec_flags;
112869112eddSAli Bahrami 	avl_node_t	ec_avlnode;	/* AVL book-keeping */
11297c478bd9Sstevel@tonic-gate };
11307c478bd9Sstevel@tonic-gate 
1131e23c41c9SAli Bahrami #define	FLG_EC_BUILTIN	0x0001		/* built in descriptor */
1132e23c41c9SAli Bahrami #define	FLG_EC_USED	0x0002		/* entrance criteria met? */
113369112eddSAli Bahrami #define	FLG_EC_CATCHALL	0x0004		/* Catches any section */
113469112eddSAli Bahrami 
113569112eddSAli Bahrami /*
113669112eddSAli Bahrami  * Ent_desc_file is the type of element maintained in the ec_files Alist
113769112eddSAli Bahrami  * of an entrance criteria descriptor. Each item maintains one file
113869112eddSAli Bahrami  * path, and a set of flags that specify the type of comparison it implies,
113969112eddSAli Bahrami  * and other information about it. The comparison type is maintained in
114069112eddSAli Bahrami  * the bottom byte of the flags.
114169112eddSAli Bahrami  */
114269112eddSAli Bahrami #define	TYP_ECF_MASK		0x00ff  /* Comparison type mask */
114369112eddSAli Bahrami #define	TYP_ECF_PATH		0	/* Compare to file path */
114469112eddSAli Bahrami #define	TYP_ECF_BASENAME	1	/* Compare to file basename */
114569112eddSAli Bahrami #define	TYP_ECF_OBJNAME		2	/* Compare to regular file basename, */
114669112eddSAli Bahrami 					/*	 or to archive member name */
114769112eddSAli Bahrami #define	TYP_ECF_NUM		3
114869112eddSAli Bahrami 
114969112eddSAli Bahrami #define	FLG_ECF_ARMEMBER	0x0100	/* name includes archive member */
115069112eddSAli Bahrami 
115169112eddSAli Bahrami typedef struct {
115269112eddSAli Bahrami 	Word		edf_flags;	/* Type of comparison */
115369112eddSAli Bahrami 	const char	*edf_name;	/* String to compare to */
115469112eddSAli Bahrami 	size_t		edf_name_len;	/* strlen(edf_name) */
115569112eddSAli Bahrami } Ent_desc_file;
11567c478bd9Sstevel@tonic-gate 
11577c478bd9Sstevel@tonic-gate /*
115857ef7aa9SRod Evans  * One structure is allocated for a move entry, and associated to the symbol
115957ef7aa9SRod Evans  * against which a move is targeted.
11607c478bd9Sstevel@tonic-gate  */
116157ef7aa9SRod Evans typedef struct {
116257ef7aa9SRod Evans 	Move		*md_move;	/* original Move entry */
116357ef7aa9SRod Evans 	Xword		md_start;	/* start position */
116457ef7aa9SRod Evans 	Xword		md_len;		/* length of initialization */
1165b6a0e2cdSRichard Lowe 	Word		md_oidx;	/* output Move entry index */
116657ef7aa9SRod Evans } Mv_desc;
11677c478bd9Sstevel@tonic-gate 
11688222814eSRichard Lowe #define	SYM_ASSERT_SIZE		0x01
11698222814eSRichard Lowe #define	SYM_ASSERT_BIND		0x02
11708222814eSRichard Lowe #define	SYM_ASSERT_TYPE		0x04
11718222814eSRichard Lowe #define	SYM_ASSERT_BITS		0x08
11728222814eSRichard Lowe #define	SYM_ASSERT_ALIAS	0x10
11738222814eSRichard Lowe 
11748222814eSRichard Lowe typedef struct {
11758222814eSRichard Lowe 	Sym_desc	*ass_sdp;
11768222814eSRichard Lowe 	char		*ass_file;
11778222814eSRichard Lowe 	Lineno		ass_lineno;
11788222814eSRichard Lowe 	uchar_t		ass_type;
11798222814eSRichard Lowe 	uchar_t		ass_bind;
11808222814eSRichard Lowe 	Lword		ass_size;
11818222814eSRichard Lowe 	Boolean		ass_bits;
11828222814eSRichard Lowe 	const char	*ass_alias;
11838222814eSRichard Lowe 	/* Assertions explicitly enabled by user */
11848222814eSRichard Lowe 	uint_t		ass_enabled;
11858222814eSRichard Lowe } Ass_desc;
11868222814eSRichard Lowe 
11877c478bd9Sstevel@tonic-gate /*
118857ef7aa9SRod Evans  * Symbol descriptor.
11897c478bd9Sstevel@tonic-gate  */
1190635216b6SRod Evans typedef	Lword		sd_flag_t;
11917c478bd9Sstevel@tonic-gate struct sym_desc {
119257ef7aa9SRod Evans 	Alist		*sd_GOTndxs;	/* list of associated GOT entries */
11937c478bd9Sstevel@tonic-gate 	Sym		*sd_sym;	/* pointer to symbol table entry */
11947c478bd9Sstevel@tonic-gate 	Sym		*sd_osym;	/* copy of the original symbol entry */
1195d326b23bSrie 					/*	used only for local partial */
119657ef7aa9SRod Evans 	Alist		*sd_move;	/* move information associated with a */
119757ef7aa9SRod Evans 					/*	partially initialized symbol */
11987c478bd9Sstevel@tonic-gate 	const char	*sd_name;	/* symbols name */
11997c478bd9Sstevel@tonic-gate 	Ifl_desc	*sd_file;	/* file where symbol is taken */
12007c478bd9Sstevel@tonic-gate 	Is_desc		*sd_isc;	/* input section of symbol definition */
12017c478bd9Sstevel@tonic-gate 	Sym_aux		*sd_aux;	/* auxiliary global symbol info. */
12027c478bd9Sstevel@tonic-gate 	Word		sd_symndx;	/* index in output symbol table */
12037c478bd9Sstevel@tonic-gate 	Word		sd_shndx;	/* sect. index sym is associated w/ */
1204635216b6SRod Evans 	sd_flag_t	sd_flags;	/* state flags */
12057c478bd9Sstevel@tonic-gate 	Half		sd_ref;		/* reference definition of symbol */
12068222814eSRichard Lowe 	Ass_desc	*sd_ass;	/* pointer back to symbol assertions */
12077c478bd9Sstevel@tonic-gate };
12087c478bd9Sstevel@tonic-gate 
12097c478bd9Sstevel@tonic-gate /*
12107c478bd9Sstevel@tonic-gate  * The auxiliary symbol descriptor contains the additional information (beyond
12117c478bd9Sstevel@tonic-gate  * the symbol descriptor) required to process global symbols.  These symbols are
12127c478bd9Sstevel@tonic-gate  * accessed via an internal symbol hash table where locality of reference is
12137c478bd9Sstevel@tonic-gate  * important for performance.
12147c478bd9Sstevel@tonic-gate  */
12157c478bd9Sstevel@tonic-gate struct sym_aux {
1216b6a0e2cdSRichard Lowe 	APlist		*sa_dfiles;	/* files where symbol is defined */
12177c478bd9Sstevel@tonic-gate 	Sym		sa_sym;		/* copy of symtab entry */
12187c478bd9Sstevel@tonic-gate 	const char	*sa_vfile;	/* first unavailable definition */
12197c478bd9Sstevel@tonic-gate 	const char	*sa_rfile;	/* file with first symbol referenced */
12207c478bd9Sstevel@tonic-gate 	Word		sa_hash;	/* the pure hash value of symbol */
12217c478bd9Sstevel@tonic-gate 	Word		sa_PLTndx;	/* index into PLT for symbol */
12227c478bd9Sstevel@tonic-gate 	Word		sa_PLTGOTndx;	/* GOT entry indx for PLT indirection */
1223d579eb63Sab 	Word		sa_linkndx;	/* index of associated symbol from */
1224d579eb63Sab 					/*	ET_DYN file */
12257c478bd9Sstevel@tonic-gate 	Half		sa_symspec;	/* special symbol ids */
12267c478bd9Sstevel@tonic-gate 	Half		sa_overndx;	/* output file versioning index */
12277c478bd9Sstevel@tonic-gate 	Half		sa_dverndx;	/* dependency versioning index */
1228b6a0e2cdSRichard Lowe 	Os_desc		*sa_boundsec;	/* output section of SECBOUND_ syms */
12297c478bd9Sstevel@tonic-gate };
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate /*
12327c478bd9Sstevel@tonic-gate  * Nodes used to track symbols in the global AVL symbol dictionary.
12337c478bd9Sstevel@tonic-gate  */
12347c478bd9Sstevel@tonic-gate struct sym_avlnode {
12357c478bd9Sstevel@tonic-gate 	avl_node_t	sav_node;	/* AVL node */
12367c478bd9Sstevel@tonic-gate 	Word		sav_hash;	/* symbol hash value */
12377c478bd9Sstevel@tonic-gate 	const char	*sav_name;	/* symbol name */
1238635216b6SRod Evans 	Sym_desc	*sav_sdp;	/* symbol descriptor */
12397c478bd9Sstevel@tonic-gate };
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate /*
12427c478bd9Sstevel@tonic-gate  * These are the ids for processing of `Special symbols'.  They are used
12437c478bd9Sstevel@tonic-gate  * to set the sym->sd_aux->sa_symspec field.
12447c478bd9Sstevel@tonic-gate  */
1245b6a0e2cdSRichard Lowe #define	SDAUX_ID_ETEXT		1	/* etext && _etext symbol */
1246b6a0e2cdSRichard Lowe #define	SDAUX_ID_EDATA		2	/* edata && _edata symbol */
1247b6a0e2cdSRichard Lowe #define	SDAUX_ID_END		3	/* end, _end, && _END_ symbol */
1248b6a0e2cdSRichard Lowe #define	SDAUX_ID_DYN		4	/* DYNAMIC && _DYNAMIC symbol */
1249b6a0e2cdSRichard Lowe #define	SDAUX_ID_PLT		5	/* _PROCEDURE_LINKAGE_TABLE_ symbol */
1250b6a0e2cdSRichard Lowe #define	SDAUX_ID_GOT		6	/* _GLOBAL_OFFSET_TABLE_ symbol */
1251b6a0e2cdSRichard Lowe #define	SDAUX_ID_START		7	/* START_ && _START_ symbol */
1252b6a0e2cdSRichard Lowe #define	SDAUX_ID_SECBOUND_START	8	/* __start_<section> symbols */
1253b6a0e2cdSRichard Lowe #define	SDAUX_ID_SECBOUND_STOP	9	/* __stop_<section> symbols */
12547c478bd9Sstevel@tonic-gate 
12557c478bd9Sstevel@tonic-gate /*
12567c478bd9Sstevel@tonic-gate  * Flags for sym_desc.sd_flags
12577c478bd9Sstevel@tonic-gate  */
12587c478bd9Sstevel@tonic-gate #define	FLG_SY_MVTOCOMM	0x00000001	/* assign symbol to common (.bss) */
12597c478bd9Sstevel@tonic-gate 					/*	this is a result of a */
12607c478bd9Sstevel@tonic-gate 					/*	copy reloc against sym */
12617c478bd9Sstevel@tonic-gate #define	FLG_SY_GLOBREF	0x00000002	/* a global reference has been seen */
12627c478bd9Sstevel@tonic-gate #define	FLG_SY_WEAKDEF	0x00000004	/* a weak definition has been used */
12637c478bd9Sstevel@tonic-gate #define	FLG_SY_CLEAN	0x00000008	/* `Sym' entry points to original */
12647c478bd9Sstevel@tonic-gate 					/*	input file (read-only). */
12657c478bd9Sstevel@tonic-gate #define	FLG_SY_UPREQD	0x00000010	/* symbol value update is required, */
12667c478bd9Sstevel@tonic-gate 					/*	either it's used as an entry */
12677c478bd9Sstevel@tonic-gate 					/*	point or for relocation, but */
12687c478bd9Sstevel@tonic-gate 					/*	it must be updated even if */
12697c478bd9Sstevel@tonic-gate 					/*	the -s flag is in effect */
12707c478bd9Sstevel@tonic-gate #define	FLG_SY_NOTAVAIL	0x00000020	/* symbol is not available to the */
12717c478bd9Sstevel@tonic-gate 					/*	application either because it */
12727c478bd9Sstevel@tonic-gate 					/*	originates from an implicitly */
1273b6a0e2cdSRichard Lowe 					/*	referenced shared object, or */
12747c478bd9Sstevel@tonic-gate 					/*	because it is not part of a */
12757c478bd9Sstevel@tonic-gate 					/*	specified version. */
12767c478bd9Sstevel@tonic-gate #define	FLG_SY_REDUCED	0x00000040	/* a global is reduced to local */
12777c478bd9Sstevel@tonic-gate #define	FLG_SY_VERSPROM	0x00000080	/* version definition has been */
12787c478bd9Sstevel@tonic-gate 					/*	promoted to output file */
12797c478bd9Sstevel@tonic-gate #define	FLG_SY_PROT	0x00000100	/* stv_protected visibility seen */
12807c478bd9Sstevel@tonic-gate #define	FLG_SY_MAPREF	0x00000200	/* symbol reference generated by user */
12817c478bd9Sstevel@tonic-gate 					/*	from mapfile */
12827c478bd9Sstevel@tonic-gate #define	FLG_SY_REFRSD	0x00000400	/* symbols sd_ref has been raised */
1283b6a0e2cdSRichard Lowe 					/*	due to a copy-relocs */
12847c478bd9Sstevel@tonic-gate 					/*	weak-strong pairing */
12859a411307Srie #define	FLG_SY_INTPOSE	0x00000800	/* symbol defines an interposer */
12867c478bd9Sstevel@tonic-gate #define	FLG_SY_INVALID	0x00001000	/* unwanted/erroneous symbol */
12877c478bd9Sstevel@tonic-gate #define	FLG_SY_SMGOT	0x00002000	/* small got index assigned to symbol */
12887c478bd9Sstevel@tonic-gate 					/*	sparc only */
12897c478bd9Sstevel@tonic-gate #define	FLG_SY_PARENT	0x00004000	/* symbol to be found in parent */
12907c478bd9Sstevel@tonic-gate 					/*    only used with direct bindings */
12917c478bd9Sstevel@tonic-gate #define	FLG_SY_LAZYLD	0x00008000	/* symbol to cause lazyloading of */
12927c478bd9Sstevel@tonic-gate 					/*	parent object */
12937c478bd9Sstevel@tonic-gate #define	FLG_SY_ISDISC	0x00010000	/* symbol is a member of a DISCARDED */
12947c478bd9Sstevel@tonic-gate 					/*	section (COMDAT) */
12957c478bd9Sstevel@tonic-gate #define	FLG_SY_PAREXPN	0x00020000	/* partially init. symbol to be */
12967c478bd9Sstevel@tonic-gate 					/*	expanded */
12977c478bd9Sstevel@tonic-gate #define	FLG_SY_PLTPAD	0x00040000	/* pltpadding has been allocated for */
12987c478bd9Sstevel@tonic-gate 					/*	this symbol */
12997c478bd9Sstevel@tonic-gate #define	FLG_SY_REGSYM	0x00080000	/* REGISTER symbol (sparc only) */
13007c478bd9Sstevel@tonic-gate #define	FLG_SY_SOFOUND	0x00100000	/* compared against an SO definition */
13017c478bd9Sstevel@tonic-gate #define	FLG_SY_EXTERN	0x00200000	/* symbol is external, allows -zdefs */
13027c478bd9Sstevel@tonic-gate 					/*    error suppression */
13037c478bd9Sstevel@tonic-gate #define	FLG_SY_MAPUSED	0x00400000	/* mapfile symbol used (occurred */
13047c478bd9Sstevel@tonic-gate 					/*    within a relocatable object) */
13057c478bd9Sstevel@tonic-gate #define	FLG_SY_COMMEXP	0x00800000	/* COMMON symbol which has been */
13067c478bd9Sstevel@tonic-gate 					/*	allocated */
13077c478bd9Sstevel@tonic-gate #define	FLG_SY_CMDREF	0x01000000	/* symbol was referenced from the */
13087c478bd9Sstevel@tonic-gate 					/*	command line.  (ld -u <>, */
13097c478bd9Sstevel@tonic-gate 					/*	ld -zrtldinfo=<>, ...) */
13107c478bd9Sstevel@tonic-gate #define	FLG_SY_SPECSEC	0x02000000	/* section index is reserved value */
13117c478bd9Sstevel@tonic-gate 					/*	ABS, COMMON, ... */
13127c478bd9Sstevel@tonic-gate #define	FLG_SY_TENTSYM	0x04000000	/* tentative symbol */
13137c478bd9Sstevel@tonic-gate #define	FLG_SY_VISIBLE	0x08000000	/* symbols visibility determined */
13147c478bd9Sstevel@tonic-gate #define	FLG_SY_STDFLTR	0x10000000	/* symbol is a standard filter */
13157c478bd9Sstevel@tonic-gate #define	FLG_SY_AUXFLTR	0x20000000	/* symbol is an auxiliary filter */
1316d579eb63Sab #define	FLG_SY_DYNSORT	0x40000000	/* req. in dyn[sym|tls]sort section */
1317d579eb63Sab #define	FLG_SY_NODYNSORT 0x80000000	/* excluded from dyn[sym_tls]sort sec */
13187c478bd9Sstevel@tonic-gate 
1319635216b6SRod Evans #define	FLG_SY_DEFAULT	0x0000100000000	/* global symbol, default */
1320635216b6SRod Evans #define	FLG_SY_SINGLE	0x0000200000000	/* global symbol, singleton defined */
1321635216b6SRod Evans #define	FLG_SY_PROTECT	0x0000400000000	/* global symbol, protected defined */
1322635216b6SRod Evans #define	FLG_SY_EXPORT	0x0000800000000	/* global symbol, exported defined */
132360758829Srie 
1324635216b6SRod Evans #define	MSK_SY_GLOBAL \
1325635216b6SRod Evans 	(FLG_SY_DEFAULT | FLG_SY_SINGLE | FLG_SY_PROTECT | FLG_SY_EXPORT)
132660758829Srie 					/* this mask indicates that the */
132760758829Srie 					/*    symbol has been explicitly */
132860758829Srie 					/*    defined within a mapfile */
132960758829Srie 					/*    definition, and is a candidate */
133060758829Srie 					/*    for versioning */
133160758829Srie 
1332635216b6SRod Evans #define	FLG_SY_HIDDEN	0x0001000000000	/* global symbol, reduce to local */
1333635216b6SRod Evans #define	FLG_SY_ELIM	0x0002000000000	/* global symbol, eliminate */
1334635216b6SRod Evans #define	FLG_SY_IGNORE	0x0004000000000	/* global symbol, ignored */
13357c478bd9Sstevel@tonic-gate 
1336635216b6SRod Evans #define	MSK_SY_LOCAL	(FLG_SY_HIDDEN | FLG_SY_ELIM | FLG_SY_IGNORE)
133760758829Srie 					/* this mask allows all local state */
133860758829Srie 					/*    flags to be removed when the */
133960758829Srie 					/*    symbol is copy relocated */
134060758829Srie 
1341635216b6SRod Evans #define	FLG_SY_EXPDEF	0x0008000000000	/* symbol visibility defined */
134260758829Srie 					/*    explicitly */
134360758829Srie 
1344635216b6SRod Evans #define	MSK_SY_NOAUTO	(FLG_SY_SINGLE | FLG_SY_EXPORT | FLG_SY_EXPDEF)
134560758829Srie 					/* this mask indicates that the */
1346635216b6SRod Evans 					/*    symbol is not a candidate for */
134760758829Srie 					/*    auto-reduction/elimination */
134860758829Srie 
1349635216b6SRod Evans #define	FLG_SY_MAPFILE	0x0010000000000	/* symbol attribute defined in a */
135060758829Srie 					/*    mapfile */
1351635216b6SRod Evans #define	FLG_SY_DIR	0x0020000000000	/* global symbol, direct bindings */
1352635216b6SRod Evans #define	FLG_SY_NDIR	0x0040000000000	/* global symbol, nondirect bindings */
1353635216b6SRod Evans #define	FLG_SY_OVERLAP	0x0080000000000	/* move entry overlap detected */
135408278a5eSRod Evans #define	FLG_SY_CAP	0x0100000000000	/* symbol is associated with */
135508278a5eSRod Evans 					/*    capabilities */
1356f441771bSRod Evans #define	FLG_SY_DEFERRED	0x0200000000000	/* symbol should not be bound to */
1357f441771bSRod Evans 					/*	during BIND_NOW relocations */
135808278a5eSRod Evans 
13598222814eSRichard Lowe #define	FLG_SY_MAPASSRT	0x0400000000000 /* Symbol has attribute assertions */
13608222814eSRichard Lowe 
136108278a5eSRod Evans /*
136208278a5eSRod Evans  * A symbol can only be truly hidden if it is not a capabilities symbol.
136308278a5eSRod Evans  */
136408278a5eSRod Evans #define	SYM_IS_HIDDEN(_sdp) \
136508278a5eSRod Evans 	(((_sdp)->sd_flags & (FLG_SY_HIDDEN | FLG_SY_CAP)) == FLG_SY_HIDDEN)
13667c478bd9Sstevel@tonic-gate 
13677c478bd9Sstevel@tonic-gate /*
136860758829Srie  * Create a mask for (sym.st_other & visibility) since the gABI does not yet
136960758829Srie  * define a ELF*_ST_OTHER macro.
13707c478bd9Sstevel@tonic-gate  */
137160758829Srie #define	MSK_SYM_VISIBILITY	0x7
13727c478bd9Sstevel@tonic-gate 
13737c478bd9Sstevel@tonic-gate /*
13747c478bd9Sstevel@tonic-gate  * Structure to manage the shared object definition lists.  There are two lists
13757c478bd9Sstevel@tonic-gate  * that use this structure:
13767c478bd9Sstevel@tonic-gate  *
137728bda19cSRod Evans  *  -	ofl_soneed; maintain the list of implicitly required dependencies
13787c478bd9Sstevel@tonic-gate  *	(ie. shared objects needed by other shared objects).  These definitions
13797c478bd9Sstevel@tonic-gate  *	may include RPATH's required to locate the dependencies, and any
13807c478bd9Sstevel@tonic-gate  *	version requirements.
13817c478bd9Sstevel@tonic-gate  *
138228bda19cSRod Evans  *  -	ofl_socntl; maintains the shared object control definitions.  These are
13837c478bd9Sstevel@tonic-gate  *	provided by the user (via a mapfile) and are used to indicate any
138428bda19cSRod Evans  *	version control requirements.
13857c478bd9Sstevel@tonic-gate  */
13867c478bd9Sstevel@tonic-gate struct	sdf_desc {
13877c478bd9Sstevel@tonic-gate 	const char	*sdf_name;	/* the shared objects file name */
13887c478bd9Sstevel@tonic-gate 	char		*sdf_rpath;	/* library search path DT_RPATH */
13897c478bd9Sstevel@tonic-gate 	const char	*sdf_rfile;	/* referencing file for diagnostics */
13907c478bd9Sstevel@tonic-gate 	Ifl_desc	*sdf_file;	/* the final input file descriptor */
139157ef7aa9SRod Evans 	Alist		*sdf_vers;	/* list of versions that are required */
13927c478bd9Sstevel@tonic-gate 					/*	from this object */
139357ef7aa9SRod Evans 	Alist		*sdf_verneed;	/* list of VERNEEDS to create for */
13944a8d0ea7SAli Bahrami 					/*	object via mapfile ADDVERS */
13957c478bd9Sstevel@tonic-gate 	Word		sdf_flags;
13967c478bd9Sstevel@tonic-gate };
13977c478bd9Sstevel@tonic-gate 
13984a8d0ea7SAli Bahrami #define	FLG_SDF_SELECT	0x01		/* version control selection required */
13994a8d0ea7SAli Bahrami #define	FLG_SDF_VERIFY	0x02		/* version definition verification */
14007c478bd9Sstevel@tonic-gate 					/*	required */
14014a8d0ea7SAli Bahrami #define	FLG_SDF_ADDVER	0x04		/* add VERNEED references */
14027c478bd9Sstevel@tonic-gate 
14037c478bd9Sstevel@tonic-gate /*
14047c478bd9Sstevel@tonic-gate  * Structure to manage shared object version usage requirements.
14057c478bd9Sstevel@tonic-gate  */
14067c478bd9Sstevel@tonic-gate struct	sdv_desc {
14077c478bd9Sstevel@tonic-gate 	const char	*sdv_name;	/* version name */
14087c478bd9Sstevel@tonic-gate 	const char	*sdv_ref;	/* versions reference */
14097c478bd9Sstevel@tonic-gate 	Word		sdv_flags;	/* flags */
14107c478bd9Sstevel@tonic-gate };
14117c478bd9Sstevel@tonic-gate 
14127c478bd9Sstevel@tonic-gate #define	FLG_SDV_MATCHED	0x01		/* VERDEF found and matched */
14137c478bd9Sstevel@tonic-gate 
14147c478bd9Sstevel@tonic-gate /*
14157c478bd9Sstevel@tonic-gate  * Structures to manage versioning information.  Two versioning structures are
14167c478bd9Sstevel@tonic-gate  * defined:
14177c478bd9Sstevel@tonic-gate  *
141828bda19cSRod Evans  *   -	a version descriptor maintains a linked list of versions and their
14197c478bd9Sstevel@tonic-gate  *	associated dependencies.  This is used to build the version definitions
14207c478bd9Sstevel@tonic-gate  *	for an image being created (see map_symbol), and to determine the
14217c478bd9Sstevel@tonic-gate  *	version dependency graph for any input files that are versioned.
14227c478bd9Sstevel@tonic-gate  *
142328bda19cSRod Evans  *   -	a version index array contains each version of an input file that is
14247c478bd9Sstevel@tonic-gate  *	being processed.  It informs us which versions are available for
14257c478bd9Sstevel@tonic-gate  *	binding, and is used to generate any version dependency information.
14267c478bd9Sstevel@tonic-gate  */
14277c478bd9Sstevel@tonic-gate struct	ver_desc {
14287c478bd9Sstevel@tonic-gate 	const char	*vd_name;	/* version name */
14297c478bd9Sstevel@tonic-gate 	Ifl_desc	*vd_file;	/* file that defined version */
143057ef7aa9SRod Evans 	Word		vd_hash;	/* hash value of name */
14317c478bd9Sstevel@tonic-gate 	Half		vd_ndx;		/* coordinates with symbol index */
14327c478bd9Sstevel@tonic-gate 	Half		vd_flags;	/* version information */
143357ef7aa9SRod Evans 	APlist		*vd_deps;	/* version dependencies */
14347c478bd9Sstevel@tonic-gate 	Ver_desc	*vd_ref;	/* dependency's first reference */
14357c478bd9Sstevel@tonic-gate };
14367c478bd9Sstevel@tonic-gate 
14377c478bd9Sstevel@tonic-gate struct	ver_index {
14387c478bd9Sstevel@tonic-gate 	const char	*vi_name;	/* dependency version name */
14397c478bd9Sstevel@tonic-gate 	Half		vi_flags;	/* communicates availability */
144008278a5eSRod Evans 	Half		vi_overndx;	/* index assigned to this version in */
1441090a8d9eSAli Bahrami 					/*	output object Verneed section */
14427c478bd9Sstevel@tonic-gate 	Ver_desc	*vi_desc;	/* cross reference to descriptor */
14437c478bd9Sstevel@tonic-gate };
14447c478bd9Sstevel@tonic-gate 
14457c478bd9Sstevel@tonic-gate /*
14467c478bd9Sstevel@tonic-gate  * Define any internal version descriptor flags ([vd|vi]_flags).  Note that the
14477c478bd9Sstevel@tonic-gate  * first byte is reserved for user visible flags (refer VER_FLG's in link.h).
14487c478bd9Sstevel@tonic-gate  */
14497c478bd9Sstevel@tonic-gate #define	MSK_VER_USER	0x0f		/* mask for user visible flags */
14507c478bd9Sstevel@tonic-gate 
14517c478bd9Sstevel@tonic-gate #define	FLG_VER_AVAIL	0x10		/* version is available for binding */
14527c478bd9Sstevel@tonic-gate #define	FLG_VER_REFER	0x20		/* version has been referenced */
14534a8d0ea7SAli Bahrami #define	FLG_VER_CYCLIC	0x40		/* a member of cyclic dependency */
14547c478bd9Sstevel@tonic-gate 
14557c478bd9Sstevel@tonic-gate /*
14567c478bd9Sstevel@tonic-gate  * isalist(1) descriptor - used to break an isalist string into its component
14577c478bd9Sstevel@tonic-gate  * options.
14587c478bd9Sstevel@tonic-gate  */
14597c478bd9Sstevel@tonic-gate struct	isa_opt {
14607c478bd9Sstevel@tonic-gate 	char		*isa_name;	/* individual isa option name */
14617c478bd9Sstevel@tonic-gate 	size_t		isa_namesz;	/*	and associated size */
14627c478bd9Sstevel@tonic-gate };
14637c478bd9Sstevel@tonic-gate 
14647c478bd9Sstevel@tonic-gate struct	isa_desc {
14657c478bd9Sstevel@tonic-gate 	char		*isa_list;	/* sysinfo(SI_ISALIST) list */
14667c478bd9Sstevel@tonic-gate 	size_t		isa_listsz;	/*	and associated size */
14677c478bd9Sstevel@tonic-gate 	Isa_opt		*isa_opt;	/* table of individual isa options */
14687c478bd9Sstevel@tonic-gate 	size_t		isa_optno;	/*	and associated number */
14697c478bd9Sstevel@tonic-gate };
14707c478bd9Sstevel@tonic-gate 
14717c478bd9Sstevel@tonic-gate /*
14727c478bd9Sstevel@tonic-gate  * uname(2) descriptor - used to break a utsname structure into its component
14737c478bd9Sstevel@tonic-gate  * options (at least those that we're interested in).
14747c478bd9Sstevel@tonic-gate  */
14757c478bd9Sstevel@tonic-gate struct	uts_desc {
14767c478bd9Sstevel@tonic-gate 	char		*uts_osname;	/* operating system name */
14777c478bd9Sstevel@tonic-gate 	size_t		uts_osnamesz;	/*	and associated size */
14787c478bd9Sstevel@tonic-gate 	char		*uts_osrel;	/* operating system release */
14797c478bd9Sstevel@tonic-gate 	size_t		uts_osrelsz;	/*	and associated size */
14807c478bd9Sstevel@tonic-gate };
14817c478bd9Sstevel@tonic-gate 
14827c478bd9Sstevel@tonic-gate /*
14837c478bd9Sstevel@tonic-gate  * SHT_GROUP descriptor - used to track group sections at the global
14840e233487SRod Evans  * level to resolve conflicts and determine which to keep.
14857c478bd9Sstevel@tonic-gate  */
14867c478bd9Sstevel@tonic-gate struct group_desc {
14870e233487SRod Evans 	Is_desc		*gd_isc;	/* input section descriptor */
14880e233487SRod Evans 	Is_desc		*gd_oisc;	/* overriding input section */
14890e233487SRod Evans 					/*	descriptor when discarded */
14900e233487SRod Evans 	const char	*gd_name;	/* group name (signature symbol) */
1491cc7efc4fSrie 	Word		*gd_data;	/* data for group section */
1492cc7efc4fSrie 	size_t		gd_cnt;		/* number of entries in group data */
14937c478bd9Sstevel@tonic-gate };
14947c478bd9Sstevel@tonic-gate 
14957c478bd9Sstevel@tonic-gate /*
14967c478bd9Sstevel@tonic-gate  * Indexes into the ld_support_funcs[] table.
14977c478bd9Sstevel@tonic-gate  */
14987c478bd9Sstevel@tonic-gate typedef enum {
1499d2d5cf7cSAli Bahrami 	LDS_VERSION = 0,	/* Must be first and have value 0 */
15007c478bd9Sstevel@tonic-gate 	LDS_INPUT_DONE,
15017c478bd9Sstevel@tonic-gate 	LDS_START,
15027c478bd9Sstevel@tonic-gate 	LDS_ATEXIT,
15033906e0c2Srie 	LDS_OPEN,
15047c478bd9Sstevel@tonic-gate 	LDS_FILE,
15052926dd2eSrie 	LDS_INSEC,
15062926dd2eSrie 	LDS_SEC,
15077c478bd9Sstevel@tonic-gate 	LDS_NUM
15087c478bd9Sstevel@tonic-gate } Support_ndx;
15097c478bd9Sstevel@tonic-gate 
15107c478bd9Sstevel@tonic-gate /*
15117c478bd9Sstevel@tonic-gate  * Structure to manage archive member caching.  Each archive has an archive
15127c478bd9Sstevel@tonic-gate  * descriptor (Ar_desc) associated with it.  This contains pointers to the
1513bbf21555SRichard Lowe  * archive symbol table (obtained by elf_getarsyms(3ELF)) and an auxiliary
15147c478bd9Sstevel@tonic-gate  * structure (Ar_uax[]) that parallels this symbol table.  The member element
15157c478bd9Sstevel@tonic-gate  * of this auxiliary table indicates whether the archive member associated with
15167c478bd9Sstevel@tonic-gate  * the symbol offset has already been extracted (AREXTRACTED) or partially
15177c478bd9Sstevel@tonic-gate  * processed (refer process_member()).
15187c478bd9Sstevel@tonic-gate  */
15197c478bd9Sstevel@tonic-gate typedef struct ar_mem {
15207c478bd9Sstevel@tonic-gate 	Elf		*am_elf;	/* elf descriptor for this member */
1521dc0f59e5SAli Bahrami 	const char	*am_name;	/* members name */
1522dc0f59e5SAli Bahrami 	const char	*am_path;	/* path (ie. lib(foo.o)) */
15237c478bd9Sstevel@tonic-gate 	Sym		*am_syms;	/* start of global symbols */
15247c478bd9Sstevel@tonic-gate 	char		*am_strs;	/* associated string table start */
15257c478bd9Sstevel@tonic-gate 	Xword		am_symn;	/* no. of global symbols */
15267c478bd9Sstevel@tonic-gate } Ar_mem;
15277c478bd9Sstevel@tonic-gate 
15287c478bd9Sstevel@tonic-gate typedef struct ar_aux {
15297c478bd9Sstevel@tonic-gate 	Sym_desc	*au_syms;	/* internal symbol descriptor */
15307c478bd9Sstevel@tonic-gate 	Ar_mem		*au_mem;	/* associated member */
15317c478bd9Sstevel@tonic-gate } Ar_aux;
15327c478bd9Sstevel@tonic-gate 
15337c478bd9Sstevel@tonic-gate #define	FLG_ARMEM_PROC	(Ar_mem *)-1
15347c478bd9Sstevel@tonic-gate 
15357c478bd9Sstevel@tonic-gate typedef struct ar_desc {
15367c478bd9Sstevel@tonic-gate 	const char	*ad_name;	/* archive file name */
15377c478bd9Sstevel@tonic-gate 	Elf		*ad_elf;	/* elf descriptor for the archive */
15387c478bd9Sstevel@tonic-gate 	Elf_Arsym	*ad_start;	/* archive symbol table start */
15397c478bd9Sstevel@tonic-gate 	Ar_aux		*ad_aux;	/* auxiliary symbol information */
15407c478bd9Sstevel@tonic-gate 	dev_t		ad_stdev;	/* device id and inode number for */
15417c478bd9Sstevel@tonic-gate 	ino_t		ad_stino;	/*	multiple inclusion checks */
15421d9df23bSab 	ofl_flag_t	ad_flags;	/* archive specific cmd line flags */
1543b3403853SRichard Lowe 	Boolean		ad_allextract;	/* archive has been allextract'ed */
15447c478bd9Sstevel@tonic-gate } Ar_desc;
15457c478bd9Sstevel@tonic-gate 
15467c478bd9Sstevel@tonic-gate /*
15477c478bd9Sstevel@tonic-gate  * Define any archive descriptor flags.  NOTE, make sure they do not clash with
15487c478bd9Sstevel@tonic-gate  * any output file descriptor archive extraction flags, as these are saved in
15497c478bd9Sstevel@tonic-gate  * the same entry (see MSK_OF1_ARCHIVE).
15507c478bd9Sstevel@tonic-gate  */
15517c478bd9Sstevel@tonic-gate #define	FLG_ARD_EXTRACT	0x00010000	/* archive member has been extracted */
15527c478bd9Sstevel@tonic-gate 
155369112eddSAli Bahrami /* Mapfile versions supported by libld */
155469112eddSAli Bahrami #define	MFV_NONE	0	/* Not a valid version */
155569112eddSAli Bahrami #define	MFV_SYSV	1	/* Original System V syntax */
155669112eddSAli Bahrami #define	MFV_SOLARIS	2	/* Solaris mapfile syntax */
155769112eddSAli Bahrami #define	MFV_NUM		3	/* # of mapfile versions */
155869112eddSAli Bahrami 
155969112eddSAli Bahrami 
15607c478bd9Sstevel@tonic-gate /*
15615aefb655Srie  * Function Declarations.
15627c478bd9Sstevel@tonic-gate  */
15635aefb655Srie #if	defined(_ELF64)
15645aefb655Srie 
15655aefb655Srie #define	ld_create_outfile	ld64_create_outfile
15665aefb655Srie #define	ld_ent_setup		ld64_ent_setup
1567c1c6f601Srie #define	ld_init_strings		ld64_init_strings
1568ba2be530Sab #define	ld_init_target		ld64_init_target
15695aefb655Srie #define	ld_make_sections	ld64_make_sections
15705aefb655Srie #define	ld_main			ld64_main
15712926dd2eSrie #define	ld_ofl_cleanup		ld64_ofl_cleanup
157256deab07SRod Evans #define	ld_process_mem		ld64_process_mem
15735aefb655Srie #define	ld_reloc_init		ld64_reloc_init
15745aefb655Srie #define	ld_reloc_process	ld64_reloc_process
15755aefb655Srie #define	ld_sym_validate		ld64_sym_validate
15765aefb655Srie #define	ld_update_outfile	ld64_update_outfile
15775aefb655Srie 
15785aefb655Srie #else
15795aefb655Srie 
15805aefb655Srie #define	ld_create_outfile	ld32_create_outfile
15815aefb655Srie #define	ld_ent_setup		ld32_ent_setup
1582c1c6f601Srie #define	ld_init_strings		ld32_init_strings
1583ba2be530Sab #define	ld_init_target		ld32_init_target
15845aefb655Srie #define	ld_make_sections	ld32_make_sections
15855aefb655Srie #define	ld_main			ld32_main
15862926dd2eSrie #define	ld_ofl_cleanup		ld32_ofl_cleanup
158756deab07SRod Evans #define	ld_process_mem		ld32_process_mem
15885aefb655Srie #define	ld_reloc_init		ld32_reloc_init
15895aefb655Srie #define	ld_reloc_process	ld32_reloc_process
15905aefb655Srie #define	ld_sym_validate		ld32_sym_validate
15915aefb655Srie #define	ld_update_outfile	ld32_update_outfile
15925aefb655Srie 
15935aefb655Srie #endif
15945aefb655Srie 
159592a02081SRod Evans extern int		ld_getopt(Lm_list *, int, int, char **);
159692a02081SRod Evans 
1597ba2be530Sab extern int		ld32_main(int, char **, Half);
1598ba2be530Sab extern int		ld64_main(int, char **, Half);
15995aefb655Srie 
16005aefb655Srie extern uintptr_t	ld_create_outfile(Ofl_desc *);
16015aefb655Srie extern uintptr_t	ld_ent_setup(Ofl_desc *, Xword);
1602c1c6f601Srie extern uintptr_t	ld_init_strings(Ofl_desc *);
1603ba2be530Sab extern int		ld_init_target(Lm_list *, Half mach);
16045aefb655Srie extern uintptr_t	ld_make_sections(Ofl_desc *);
16052926dd2eSrie extern void		ld_ofl_cleanup(Ofl_desc *);
160656deab07SRod Evans extern Ifl_desc		*ld_process_mem(const char *, const char *, char *,
160756deab07SRod Evans 			    size_t, Ofl_desc *, Rej_desc *);
16085aefb655Srie extern uintptr_t	ld_reloc_init(Ofl_desc *);
16095aefb655Srie extern uintptr_t	ld_reloc_process(Ofl_desc *);
16105aefb655Srie extern uintptr_t	ld_sym_validate(Ofl_desc *);
16115aefb655Srie extern uintptr_t	ld_update_outfile(Ofl_desc *);
16125aefb655Srie 
16137c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
16147c478bd9Sstevel@tonic-gate }
16157c478bd9Sstevel@tonic-gate #endif
16167c478bd9Sstevel@tonic-gate 
16177c478bd9Sstevel@tonic-gate #endif	/* _LIBLD_H */
1618