libld.h revision 3492:cd4326c9ab0e
1193323Sed/*
2193323Sed * CDDL HEADER START
3193323Sed *
4193323Sed * The contents of this file are subject to the terms of the
5193323Sed * Common Development and Distribution License (the "License").
6193323Sed * You may not use this file except in compliance with the License.
7193323Sed *
8193323Sed * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9193323Sed * or http://www.opensolaris.org/os/licensing.
10193323Sed * See the License for the specific language governing permissions
11193323Sed * and limitations under the License.
12193323Sed *
13193323Sed * When distributing Covered Code, include this CDDL HEADER in each
14193323Sed * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15193323Sed * If applicable, add the following below this CDDL HEADER, with the
16193323Sed * fields enclosed by brackets "[]" replaced with your own identifying
17193323Sed * information: Portions Copyright [yyyy] [name of copyright owner]
18193323Sed *
19193323Sed * CDDL HEADER END
20193323Sed */
21193323Sed
22193323Sed/*
23198090Srdivacky *	Copyright (c) 1988 AT&T
24193323Sed *	  All Rights Reserved
25193323Sed *
26193323Sed * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27193323Sed * Use is subject to license terms.
28193323Sed */
29193323Sed
30193323Sed#ifndef	_LIBLD_H
31193323Sed#define	_LIBLD_H
32193323Sed
33198090Srdivacky#pragma ident	"%Z%%M%	%I%	%E% SMI"
34198090Srdivacky
35198090Srdivacky#include <stdlib.h>
36193323Sed#include <libelf.h>
37193323Sed#include <sgs.h>
38193323Sed#include <machdep.h>
39193323Sed#include <string_table.h>
40193323Sed#include <sys/avl.h>
41193323Sed#include <alist.h>
42193323Sed
43193323Sed#ifdef	__cplusplus
44195098Sedextern "C" {
45193323Sed#endif
46193323Sed
47193323Sed/*
48193323Sed * Default directory search path manipulation for the link-editor.  YLDIR
49193323Sed * indicates which directory in LIBPATH is replaced by the -YL option to cc
50193323Sed * and ld.  YUDIR indicates which directory is replaced by -YU.
51198090Srdivacky */
52198090Srdivacky#define	YLDIR	1
53198090Srdivacky#define	YUDIR	2
54193323Sed
55193323Sed/*
56193323Sed * Define a hash value that can never be returned from elf_hash().
57193323Sed */
58193323Sed#define	SYM_NOHASH	(~(Word)0)
59194612Sed
60194612Sed/*
61198090Srdivacky * Macro that can be used to represent both ORDER flags
62198090Srdivacky * in a section header.
63194612Sed */
64194612Sed#define	ALL_SHF_ORDER	(SHF_ORDERED | SHF_LINK_ORDER)
65194612Sed
66194612Sed/*
67193323Sed * The linker merges (concatenates) sections with the same name and
68193323Sed * compatible section header flags. When comparing these flags,
69195340Sed * there are some that should not be included in the decision.
70195340Sed * The ALL_SHF_IGNORE constant defines these flags.
71193323Sed *
72193323Sed * NOTE: SHF_MERGE|SHF_STRINGS:
73193323Sed * The compiler is allowed to set the SHF_MERGE|SHF_STRINGS flags in
74193323Sed * order to tell the linker that:
75193323Sed *
76193323Sed *      1) There is nothing in the section except null terminated strings.
77193323Sed *      2) If two compatible sections both have these flags set, it is
78193323Sed *		OK to combine identical strings into single instances.
79198090Srdivacky *		In this case, the two sections would be modified to both
80198090Srdivacky *		reference a single string copy.
81193323Sed *
82193323Sed * This is a different meaning than the simple concatenating of sections
83195340Sed * that the linker always does. It is a hint that an additional optimization
84199481Srdivacky * is possible, but not required. This means that sections that do not
85193323Sed * share the same SHF_MERGE|SHF_STRINGS values can be merged (concatenated),
86193323Sed * but cannot have their duplicate strings combined. Hence, the values
87195340Sed * of SHF_MERGE|SHF_STRINGS should be ignored when deciding whether two
88193323Sed * sections can be merged (concatenated).
89193323Sed *
90193323Sed * We do not currently implement the SHF_MERGE|SHF_STRINGS optimization,
91193323Sed * but it is possible to add it. If we did, the procedure would be to
92193323Sed * first combine the compatible sections that have these flag bits set,
93193323Sed * and then to concatenate any others to the result.
94193323Sed */
95193323Sed#define	ALL_SHF_IGNORE	(ALL_SHF_ORDER | SHF_GROUP | SHF_MERGE | SHF_STRINGS)
96193323Sed
97193323Sed/*
98193323Sed * Define symbol reference types for use in symbol resolution.
99193323Sed */
100193323Sedtypedef enum {
101193323Sed	REF_DYN_SEEN,			/* a .so symbol has been seen */
102193323Sed	REF_DYN_NEED,			/* a .so symbol satisfies a .o symbol */
103195098Sed	REF_REL_NEED,			/* a .o symbol */
104195098Sed	REF_NUM				/* the number of symbol references */
105195340Sed} Symref;
106195340Sed
107195340Sed
108195340Sed/*
109195340Sed * GOT reference models
110195340Sed */
111195340Sedtypedef enum {
112195340Sed	GOT_REF_GENERIC,	/* generic symbol reference */
113195340Sed	GOT_REF_TLSIE,		/* TLS initial exec (gnu) reference */
114195340Sed	GOT_REF_TLSLD,		/* TLS local dynamic reference */
115195340Sed	GOT_REF_TLSGD		/* TLS general dynamic reference */
116193323Sed} Gotref;
117193323Sed
118193323Sedtypedef struct {
119193323Sed	Xword		gn_addend;	/* addend associated with GOT entry */
120195340Sed	Sword		gn_gotndx;	/* GOT table index */
121195340Sed	Gotref		gn_gotref;
122195340Sed} Gotndx;
123195340Sed
124195340Sed/*
125198090Srdivacky * Got debugging structure.  The got index is defined as a signed value as we
126198090Srdivacky * do so much mucking around with negative and positive gots on SPARC, and sign
127195340Sed * extension is necessary when building 64-bit objects.  On intel we explicitly
128198090Srdivacky * cast this variable to an unsigned value.
129198090Srdivacky */
130198090Srdivackytypedef struct {
131198090Srdivacky	Sym_desc *	gt_sym;
132198090Srdivacky	Gotndx		gt_gndx;
133198090Srdivacky} Gottable;
134198090Srdivacky
135198113Srdivacky/*
136198113Srdivacky * Output file processing structure
137198113Srdivacky */
138198113Srdivackystruct ofl_desc {
139198113Srdivacky	char		*ofl_sgsid;	/* link-editor identification */
140198113Srdivacky	const char	*ofl_name;	/* full file name */
141198113Srdivacky	Elf		*ofl_elf;	/* elf_memory() elf descriptor */
142198090Srdivacky	Elf		*ofl_welf;	/* ELF_C_WRITE elf descriptor */
143198090Srdivacky	Ehdr		*ofl_dehdr;	/* default elf header, and new elf */
144198090Srdivacky	Ehdr		*ofl_nehdr;	/*	header describing this file */
145198090Srdivacky	Phdr		*ofl_phdr;	/* program header descriptor */
146198090Srdivacky	Phdr		*ofl_tlsphdr;	/* TLS phdr */
147198090Srdivacky	int		ofl_fd;		/* file descriptor */
148198090Srdivacky	size_t		ofl_size;	/* image size */
149198090Srdivacky	List		ofl_maps;	/* list of input mapfiles */
150198090Srdivacky	List		ofl_segs;	/* list of segments */
151198090Srdivacky	List		ofl_ents;	/* list of entrance descriptors */
152195340Sed	List		ofl_objs;	/* relocatable object file list */
153195340Sed	Word		ofl_objscnt;	/* 	and count */
154195340Sed	List		ofl_ars;	/* archive library list */
155195340Sed	Word		ofl_arscnt;	/* 	and count */
156195340Sed	List		ofl_sos;	/* shared object list */
157198090Srdivacky	Word		ofl_soscnt;	/* 	and count */
158198090Srdivacky	List		ofl_soneed;	/* list of implicitly required .so's */
159198090Srdivacky	List		ofl_socntl;	/* list of .so control definitions */
160198090Srdivacky	List		ofl_outrels;	/* list of output relocations */
161193323Sed	Word		ofl_outrelscnt;	/* 	and count */
162193323Sed	List		ofl_actrels;	/* list of relocations to perform */
163193323Sed	Word		ofl_actrelscnt;	/* 	and count */
164198090Srdivacky	Word		ofl_entrelscnt;	/* no of relocations entered */
165198090Srdivacky	List		ofl_copyrels;	/* list of copy relocations */
166198090Srdivacky	List		ofl_ordered;	/* list of shf_ordered sections */
167198090Srdivacky	List		ofl_syminfsyms;	/* list of interesting syms */
168198090Srdivacky					/*	for syminfo processing */
169198090Srdivacky	List		ofl_ismove;	/* list of .SUNW_move sections */
170198090Srdivacky	List		ofl_mvrelisdescs; /* list of relocation input section */
171198090Srdivacky					/* targeting to expanded area */
172198090Srdivacky	List		ofl_parsym; 	/* list of Parsym_info */
173198090Srdivacky	List		ofl_extrarels;	/* relocation sections which have */
174198090Srdivacky					/*    a NULL sh_info */
175198090Srdivacky	avl_tree_t	*ofl_groups;	/* pointer to head of Groups AVL tree */
176198090Srdivacky	List		ofl_initarray;	/* list of init array func names */
177198090Srdivacky	List		ofl_finiarray;	/* list of fini array func names */
178198090Srdivacky	List		ofl_preiarray;	/* list of preinit array func names */
179198090Srdivacky	List		ofl_rtldinfo;	/* list of rtldinfo syms */
180198090Srdivacky	List		ofl_osgroups;	/* list of output GROUP sections */
181198090Srdivacky	List		ofl_ostlsseg;	/* pointer to sections in TLS segment */
182198090Srdivacky#if (defined(__i386) || defined(__amd64)) && defined(_ELF64)
183198090Srdivacky	List		ofl_unwind;	/* list of unwind output sections */
184198090Srdivacky	Os_desc		*ofl_unwindhdr;	/* Unwind hdr */
185198090Srdivacky#endif
186198090Srdivacky	avl_tree_t	ofl_symavl;	/* pointer to head of Syms AVL tree */
187198090Srdivacky	Sym_desc	**ofl_regsyms;	/* array of potential register */
188198090Srdivacky	Word		ofl_regsymsno;	/*    symbols and array count */
189193323Sed	Word		ofl_regsymcnt;	/* no. of output register symbols */
190193323Sed	Word		ofl_lregsymcnt;	/* no. of local register symbols */
191193323Sed	Sym_desc	*ofl_dtracesym;	/* ld -zdtrace= */
192193323Sed	Lword		ofl_flags;	/* various state bits, args etc. */
193193323Sed	Lword		ofl_flags1;	/*	more flags */
194195340Sed	Xword		ofl_segorigin;	/* segment origin (start) */
195195340Sed	void		*ofl_entry;	/* entry point (-e and Sym_desc *) */
196195340Sed	char		*ofl_filtees;	/* shared objects we are a filter for */
197195340Sed	const char	*ofl_soname;	/* (-h option) output file name for */
198195340Sed					/*	dynamic structure */
199195340Sed	const char	*ofl_interp;	/* interpreter name used by exec() */
200195340Sed	char		*ofl_rpath;	/* run path to store in .dynamic */
201195340Sed	char		*ofl_config;	/* config path to store in .dynamic */
202195340Sed	List		ofl_ulibdirs;	/* user supplied library search list */
203195340Sed	List		ofl_dlibdirs;	/* default library search list */
204198090Srdivacky	Word		ofl_vercnt;	/* number of versions to generate */
205195340Sed	List		ofl_verdesc;	/* list of version descriptors */
206195340Sed	size_t		ofl_verdefsz;	/* size of version definition section */
207195340Sed	size_t		ofl_verneedsz;	/* size of version needed section */
208195340Sed	Word		ofl_entercnt;	/* no. of global symbols entered */
209195340Sed	Word		ofl_globcnt;	/* no. of global symbols to output */
210195340Sed	Word		ofl_scopecnt;	/* no. of scoped symbols to output */
211195340Sed	Word		ofl_dynscopecnt; /* no. scoped syms in .SUNW_ldynsym */
212195340Sed	Word		ofl_elimcnt;	/* no. of eliminated symbols */
213195340Sed	Word		ofl_locscnt;	/* no. of local symbols in .symtab */
214195340Sed	Word		ofl_dynlocscnt;	/* no. local symbols in .SUNW_ldynsym */
215195340Sed	Word		ofl_dynsymsortcnt; /* no. ndx in .SUNW_dynsymsort */
216195340Sed	Word		ofl_dyntlssortcnt; /* no. ndx in .SUNW_dyntlssort */
217195340Sed	Word		ofl_dynshdrcnt;	/* no. of output section in .dynsym */
218193323Sed	Word		ofl_shdrcnt;	/* no. of output sections */
219193323Sed	Str_tbl		*ofl_shdrsttab;	/* Str_tbl for shdr strtab */
220193323Sed	Str_tbl		*ofl_strtab;	/* Str_tbl for symtab strtab */
221193323Sed	Str_tbl		*ofl_dynstrtab;	/* Str_tbl for dymsym strtab */
222193323Sed	Gotndx		*ofl_tlsldgotndx; /* index to LD TLS_index structure */
223193323Sed	Xword		ofl_relocsz;	/* size of output relocations */
224193323Sed	Xword		ofl_relocgotsz;	/* size of .got relocations */
225193323Sed	Xword		ofl_relocpltsz;	/* size of .plt relocations */
226193323Sed	Xword		ofl_relocbsssz;	/* size of .bss (copy) relocations */
227193323Sed	Xword		ofl_relocrelsz;	/* size of .rel[a] relocations */
228193323Sed	Word		ofl_relocincnt;	/* no. of input relocations */
229193323Sed	Word		ofl_reloccnt;	/* tot number of output relocations */
230193323Sed	Word		ofl_reloccntsub; /* tot numb of output relocations to */
231193323Sed					/*	skip (-zignore) */
232193323Sed	Word		ofl_relocrelcnt; /* tot number of relative */
233193323Sed					/*	relocations */
234193323Sed	Word		ofl_gotcnt;	/* no. of .got entries */
235193323Sed	Word		ofl_pltcnt;	/* no. of .plt entries */
236193323Sed	Word		ofl_pltpad;	/* no. of .plt padd entries */
237193323Sed	Word		ofl_hashbkts;	/* no. of hash buckets required */
238193323Sed	Is_desc		*ofl_isbss;	/* .bss input section (globals) */
239193323Sed	Is_desc		*ofl_islbss;	/* .lbss input section (globals) */
240193323Sed	Is_desc		*ofl_istlsbss;	/* .tlsbss input section (globals) */
241193323Sed	Is_desc		*ofl_issunwdata1; /* .data input section */
242193323Sed					/* 	partially expanded. */
243193323Sed	Is_desc		*ofl_issunwbss;	/* .SUNW_bss input section (globals) */
244193323Sed	Os_desc		*ofl_osdynamic;	/* .dynamic output section */
245193323Sed	Os_desc		*ofl_osdynsym;	/* .dynsym output section */
246193323Sed	Os_desc		*ofl_osldynsym;	/* .SUNW_ldynsym output section */
247193323Sed	Os_desc		*ofl_osdynstr;	/* .dynstr output section */
248193323Sed	Os_desc		*ofl_osdynsymsort; /* .SUNW_dynsymsort output section */
249193323Sed	Os_desc		*ofl_osdyntlssort; /* .SUNW_dyntlssort output section */
250193323Sed	Os_desc		*ofl_osgot;	/* .got output section */
251193323Sed	Os_desc		*ofl_oshash;	/* .hash output section */
252193323Sed	Os_desc		*ofl_osinitarray; /* .initarray output section */
253193323Sed	Os_desc		*ofl_osfiniarray; /* .finiarray output section */
254193323Sed	Os_desc		*ofl_ospreinitarray; /* .preinitarray output section */
255193323Sed	Os_desc		*ofl_osinterp;	/* .interp output section */
256193323Sed	Os_desc		*ofl_oscap;	/* .SUNW_cap output section */
257193323Sed	Os_desc		*ofl_osplt;	/* .plt output section */
258198090Srdivacky	Os_desc		*ofl_osmove;	/* .SUNW_move output section */
259193323Sed	Os_desc		*ofl_osrelhead;	/* first relocation section */
260193323Sed	Os_desc		*ofl_osrel;	/* .rel[a] relocation section */
261193323Sed	Os_desc		*ofl_osshstrtab; /* .shstrtab output section */
262193323Sed	Os_desc		*ofl_osstrtab;	/* .strtab output section */
263193323Sed	Os_desc		*ofl_ossymtab;	/* .symtab output section */
264193323Sed	Os_desc		*ofl_ossymshndx; /* .symtab_shndx output section */
265193323Sed	Os_desc		*ofl_osdynshndx; /* .dynsym_shndx output section */
266193323Sed	Os_desc		*ofl_osldynshndx; /* .SUNW_ldynsym_shndx output sec */
267193323Sed	Os_desc		*ofl_osverdef;	/* .version definition output section */
268193323Sed	Os_desc		*ofl_osverneed;	/* .version needed output section */
269193323Sed	Os_desc		*ofl_osversym;	/* .version symbol ndx output section */
270193323Sed	Word		ofl_dtflags_1;	/* DT_FLAGS_1 entries */
271193323Sed	Word		ofl_dtflags;	/* DT_FLAGS entries */
272193323Sed	Os_desc		*ofl_ossyminfo;	/* .SUNW_syminfo output section */
273193323Sed	Half		ofl_sunwdata1ndx; /* section index for sunwdata1  */
274193323Sed					/* Ref. at perform_outreloc() in */
275193323Sed					/* libld/{mach}/machrel.c */
276193323Sed	Xword		*ofl_checksum;	/* DT_CHECKSUM value address */
277193323Sed	char		*ofl_depaudit;	/* dependency auditing required (-P) */
278193323Sed	char		*ofl_audit;	/* object auditing required (-p) */
279193323Sed	Alist		*ofl_symfltrs;	/* per-symbol filtees and their */
280193323Sed	Alist		*ofl_dtsfltrs;	/*	associated .dynamic/.dynstrs */
281193323Sed	Xword		ofl_hwcap_1;	/* hardware capabilities */
282193323Sed	Xword		ofl_sfcap_1;	/* software capabilities */
283198090Srdivacky	Lm_list		*ofl_lml;	/* runtime link-map list */
284198892Srdivacky	Gottable	*ofl_gottable;	/* debugging got information */
285193323Sed};
286193323Sed
287193323Sed#define	FLG_OF_DYNAMIC	0x00000001	/* generate dynamic output module */
288198090Srdivacky#define	FLG_OF_STATIC	0x00000002	/* generate static output module */
289193323Sed#define	FLG_OF_EXEC	0x00000004	/* generate an executable */
290193323Sed#define	FLG_OF_RELOBJ	0x00000008	/* generate a relocatable object */
291198090Srdivacky#define	FLG_OF_SHAROBJ	0x00000010	/* generate a shared object */
292193323Sed#define	FLG_OF_BFLAG	0x00000020	/* do no special plt building: -b */
293193323Sed#define	FLG_OF_IGNENV	0x00000040	/* ignore LD_LIBRARY_PATH: -i */
294193323Sed#define	FLG_OF_STRIP	0x00000080	/* strip output: -s */
295193323Sed#define	FLG_OF_NOWARN	0x00000100	/* disable symbol warnings: -t */
296193323Sed#define	FLG_OF_NOUNDEF	0x00000200	/* allow no undefined symbols: -zdefs */
297193323Sed#define	FLG_OF_PURETXT	0x00000400	/* allow no text relocations: -ztext  */
298193323Sed#define	FLG_OF_GENMAP	0x00000800	/* generate a memory map: -m */
299193323Sed#define	FLG_OF_DYNLIBS	0x00001000	/* dynamic input allowed: -Bdynamic */
300193323Sed#define	FLG_OF_SYMBOLIC	0x00002000	/* bind global symbols: -Bsymbolic */
301193323Sed#define	FLG_OF_ADDVERS	0x00004000	/* add version stamp: -Qy */
302193323Sed#define	FLG_OF_NOLDYNSYM 0x00008000	/* -znoldynsym set */
303198090Srdivacky#define	FLG_OF_SEGORDER	0x00010000	/* segment ordering is required */
304193323Sed#define	FLG_OF_SEGSORT	0x00020000	/* segment sorting is required */
305193323Sed#define	FLG_OF_TEXTREL	0x00040000	/* text relocations have been found */
306193323Sed#define	FLG_OF_MULDEFS	0x00080000	/* multiple symbols are allowed */
307193323Sed#define	FLG_OF_TLSPHDR	0x00100000	/* a TLS program header is required */
308193323Sed#define	FLG_OF_BLDGOT	0x00200000	/* build GOT table */
309193323Sed#define	FLG_OF_VERDEF	0x00400000	/* record version definitions */
310193323Sed#define	FLG_OF_VERNEED	0x00800000	/* record version dependencies */
311193323Sed#define	FLG_OF_NOVERSEC 0x01000000	/* don't record version sections */
312193323Sed#define	FLG_OF_AUTOLCL	0x02000000	/* automatically reduce unspecified */
313193323Sed					/*	global symbols to locals */
314193323Sed#define	FLG_OF_PROCRED	0x04000000	/* process any symbol reductions by */
315193323Sed					/*	effecting the symbol table */
316193323Sed					/*	output and relocations */
317193323Sed#define	FLG_OF_SYMINFO	0x08000000	/* create a syminfo section */
318193323Sed#define	FLG_OF_AUX	0x10000000	/* ofl_filter is an auxiliary filter */
319193323Sed#define	FLG_OF_FATAL	0x20000000	/* fatal error during input */
320198090Srdivacky#define	FLG_OF_WARN	0x40000000	/* warning during input processing. */
321193323Sed#define	FLG_OF_VERBOSE	0x80000000	/* -z verbose flag set */
322193323Sed
323193323Sed#define	FLG_OF_MAPSYMB	0x000100000000	/* symbolic scope definition seen */
324193323Sed#define	FLG_OF_MAPGLOB	0x000200000000	/* global scope definition seen */
325193323Sed
326193323Sed/*
327193323Sed * In the flags1 arena, establish any options that are applicable to archive
328193323Sed * extraction first, and associate a mask.  These values are recorded with any
329193323Sed * archive descriptor so that they may be reset should the archive require a
330193323Sed * rescan to try and resolve undefined symbols.
331193323Sed */
332193323Sed#define	FLG_OF1_ALLEXRT	0x00000001	/* extract all members from an */
333193323Sed					/*	archive file */
334193323Sed#define	FLG_OF1_WEAKEXT	0x00000002	/* allow archive extraction to */
335193323Sed					/*	resolve weak references */
336193323Sed#define	MSK_OF1_ARCHIVE	0x00000003	/* archive flags mask */
337193323Sed
338193323Sed#define	FLG_OF1_NOINTRP	0x00000008	/* -z nointerp flag set */
339193323Sed#define	FLG_OF1_ZDIRECT	0x00000010	/* -z direct flag set */
340193323Sed#define	FLG_OF1_NDIRECT	0x00000020	/* no-direct bindings specified */
341193323Sed#define	FLG_OF1_OVHWCAP	0x00000040	/* override any input hardware or */
342193323Sed#define	FLG_OF1_OVSFCAP	0x00000080	/*	software capabilities */
343193323Sed#define	FLG_OF1_RELDYN	0x00000100	/* process .dynamic in rel obj */
344193323Sed#define	FLG_OF1_REDLSYM	0x00000200	/* reduce local symbols */
345193323Sed#define	FLG_OF1_AUTOELM	0x00000400	/* automatically eliminate  */
346193323Sed					/*	unspecified global symbols */
347193323Sed#define	FLG_OF1_IGNORE	0x00000800	/* ignore unused dependencies */
348193323Sed#define	FLG_OF1_RELCNT	0x00001000	/* enable DT_RELACNT tracking */
349193323Sed#define	FLG_OF1_TEXTOFF 0x00002000	/* text relocations are ok */
350193323Sed#define	FLG_OF1_ABSEXEC	0x00004000	/* -zabsexec set */
351193323Sed#define	FLG_OF1_LAZYLD	0x00008000	/* lazy loading of objects enabled */
352193323Sed#define	FLG_OF1_GRPPRM	0x00010000	/* dependencies are to have */
353193323Sed					/*	GROUPPERM enabled */
354193323Sed#define	FLG_OF1_OVRFLW	0x00020000	/* size exceeds 32-bit limitation */
355193323Sed					/*	of 32-bit libld */
356193323Sed#define	FLG_OF1_NOPARTI	0x00040000	/* -znopartial set */
357193323Sed#define	FLG_OF1_BSSOREL	0x00080000	/* output relocation against bss */
358193323Sed					/*	section */
359193323Sed#define	FLG_OF1_TLSOREL	0x00100000	/* output relocation against .tlsbss */
360193323Sed					/*	section */
361193323Sed#define	FLG_OF1_MEMORY	0x00200000	/* produce a memory model */
362193323Sed#define	FLG_OF1_RLXREL	0x00400000	/* -z relaxreloc flag set */
363193323Sed
364193323Sed#define	FLG_OF1_VADDR	0x01000000	/* vaddr was explicitly set */
365193323Sed#define	FLG_OF1_EXTRACT	0x02000000	/* archive member has been extracted */
366193323Sed#define	FLG_OF1_RESCAN	0x04000000	/* any archives should be rescanned */
367193323Sed#define	FLG_OF1_IGNPRC	0x08000000	/* ignore processing required */
368193323Sed#define	FLG_OF1_NCSTTAB	0x10000000	/* -znocompstrtab set */
369193323Sed#define	FLG_OF1_DONE	0x20000000	/* link-editor processing complete */
370193323Sed#define	FLG_OF1_NONREG	0x40000000	/* non-regular file specified as */
371193323Sed					/*	the output file */
372193323Sed#define	FLG_OF1_ALNODIR	0x80000000	/* establish NODIRECT for all */
373193323Sed					/*	exported interfaces. */
374193323Sed
375198090Srdivacky/*
376193323Sed * Test to see if the output file would allow the presence of
377193323Sed * a .dynsym section.
378193323Sed */
379193323Sed#define	OFL_ALLOW_DYNSYM(ofl) ((ofl->ofl_flags & \
380193323Sed	(FLG_OF_DYNAMIC | FLG_OF_RELOBJ)) == FLG_OF_DYNAMIC)
381193323Sed
382193323Sed/*
383193323Sed * Test to see if the output file would allow the presence of
384193323Sed * a .SUNW_ldynsym section. The requirements are that a .dynsym
385193323Sed * is allowed, and -znoldynsym has not been specified. Note that
386198090Srdivacky * even if the answer is True (1), we will only generate one if there
387193323Sed * are local symbols that require it.
388193323Sed */
389193323Sed#define	OFL_ALLOW_LDYNSYM(ofl) ((ofl->ofl_flags & \
390193323Sed	(FLG_OF_DYNAMIC | FLG_OF_RELOBJ | FLG_OF_NOLDYNSYM)) == FLG_OF_DYNAMIC)
391193323Sed
392193323Sed/*
393193323Sed * Relocation (active & output) processing structure - transparent to common
394193323Sed * code.
395193323Sed */
396193323Sedstruct rel_desc {
397193323Sed	Os_desc		*rel_osdesc;	/* output section reloc is against */
398193323Sed	Is_desc		*rel_isdesc;	/* input section reloc is against */
399193323Sed	const char	*rel_sname;	/* symbol name (may be "unknown") */
400193323Sed	Sym_desc	*rel_sym;	/* sym relocation is against */
401193323Sed	Sym_desc	*rel_usym;	/* strong sym if this is a weak pair */
402193323Sed	Mv_desc		*rel_move;	/* move table information */
403193323Sed	Word		rel_flags;	/* misc. flags for relocations */
404193323Sed	Word		rel_rtype;	/* relocation type */
405193323Sed	Xword		rel_roffset;	/* relocation offset */
406193323Sed	Sxword		rel_raddend;	/* addend from input relocation */
407193323Sed	Word		rel_typedata;	/* ELF_R_TYPE_DATA(info) */
408198090Srdivacky};
409193323Sed
410193323Sed/*
411193323Sed * common flags used on the Rel_desc structure (defined in machrel.h).
412193323Sed */
413193323Sed#define	FLG_REL_GOT	0x00000001	/* relocation against GOT */
414193323Sed#define	FLG_REL_PLT	0x00000002	/* relocation against PLT */
415193323Sed#define	FLG_REL_BSS	0x00000004	/* relocation against BSS */
416193323Sed#define	FLG_REL_LOAD	0x00000008	/* section loadable */
417193323Sed#define	FLG_REL_SCNNDX	0x00000010	/* use section index for symbol ndx */
418193323Sed#define	FLG_REL_CLVAL	0x00000020	/* clear VALUE for active relocation */
419193323Sed#define	FLG_REL_ADVAL	0x00000040	/* add VALUE for output relocation, */
420193323Sed					/*	only relevent to SPARC and */
421193323Sed					/*	R_SPARC_RELATIVE */
422193323Sed#define	FLG_REL_GOTCL	0x00000080	/* clear the GOT entry.  This is */
423193323Sed					/* relevant to RELA relocations, */
424193323Sed					/* not REL (i386) relocations */
425193323Sed#define	FLG_REL_MOVETAB	0x00000100	/* Relocation against .SUNW_move */
426193323Sed					/*	adjustments required before */
427193323Sed					/*	actual relocation */
428193323Sed#define	FLG_REL_NOINFO	0x00000200	/* Relocation comes from a section */
429193323Sed					/*	with a null sh_info field */
430193323Sed#define	FLG_REL_REG	0x00000400	/* Relocation target is reg sym */
431193323Sed#define	FLG_REL_FPTR	0x00000800	/* relocation against func. desc. */
432193323Sed#define	FLG_REL_RFPTR1	0x00001000	/* Relative relocation against */
433193323Sed					/*   1st part of FD */
434193323Sed#define	FLG_REL_RFPTR2	0x00002000	/* Relative relocation against */
435193323Sed					/*   2nd part of FD */
436193323Sed#define	FLG_REL_DISP	0x00004000	/* *disp* relocation */
437198090Srdivacky#define	FLG_REL_STLS	0x00008000	/* IE TLS reference to */
438198090Srdivacky					/*	static TLS GOT index */
439198090Srdivacky#define	FLG_REL_DTLS	0x00010000	/* GD TLS reference relative to */
440198090Srdivacky					/*	dynamic TLS GOT index */
441198090Srdivacky#define	FLG_REL_MTLS	0x00020000	/* LD TLS reference against GOT */
442198090Srdivacky#define	FLG_REL_STTLS	0x00040000	/* LE TLS reference directly */
443193323Sed					/*	to static tls index */
444193323Sed#define	FLG_REL_TLSFIX	0x00080000	/* relocation points to TLS instr. */
445193323Sed					/*	which needs updating */
446193323Sed#define	FLG_REL_RELA	0x00100000	/* descripter captures a Rela */
447193323Sed#define	FLG_REL_GOTFIX	0x00200000	/* relocation points to GOTOP instr. */
448193323Sed					/*	which needs updating */
449193323Sed
450193323Sed/*
451193323Sed * Structure to hold a cache of Relocations.
452193323Sed */
453193323Sedstruct rel_cache {
454193323Sed	Rel_desc	*rc_end;
455193323Sed	Rel_desc	*rc_free;
456193323Sed};
457193323Sed
458198090Srdivacky/*
459193323Sed * Symbol value descriptor.  For relocatable objects, each symbols value is
460193323Sed * its offset within its associated section.  Therefore, to uniquely define
461193323Sed * each symbol within a reloctable object, record and sort the sh_offset and
462193323Sed * symbol value.  This information is used to seach for displacement
463193323Sed * relocations as part of copy relocation validation.
464193323Sed */
465193323Sedtypedef struct {
466193323Sed	Addr		ssv_value;
467193323Sed	Sym_desc	*ssv_sdp;
468193323Sed} Ssv_desc;
469193323Sed
470193323Sed/*
471193323Sed * Input file processing structures.
472193323Sed */
473193323Sedstruct ifl_desc {			/* input file descriptor */
474193323Sed	const char	*ifl_name;	/* full file name */
475193323Sed	const char	*ifl_soname;	/* shared object name */
476193323Sed	dev_t		ifl_stdev;	/* device id and inode number for .so */
477193323Sed	ino_t		ifl_stino;	/*	multiple inclusion checks */
478193323Sed	Ehdr		*ifl_ehdr;	/* elf header describing this file */
479193323Sed	Elf		*ifl_elf;	/* elf descriptor for this file */
480193323Sed	Sym_desc	**ifl_oldndx;	/* original symbol table indices */
481193323Sed	Sym_desc	*ifl_locs;	/* symbol desc version of locals */
482193323Sed	Ssv_desc	*ifl_sortsyms;	/* sorted list of symbols by value */
483198090Srdivacky	Word		ifl_locscnt;	/* no. of local symbols to process */
484193323Sed	Word		ifl_symscnt;	/* total no. of symbols to process */
485193323Sed	Word		ifl_sortcnt;	/* no. of sorted symbols to process */
486193323Sed	Word		ifl_shnum;	/* number of sections in file */
487193323Sed	Word		ifl_shstrndx;	/* index to .shstrtab */
488193323Sed	Word		ifl_vercnt;	/* number of versions in file */
489193323Sed	Is_desc		**ifl_isdesc;	/* isdesc[scn ndx] = Is_desc ptr */
490195340Sed	Sdf_desc	*ifl_sdfdesc;	/* control definition */
491195340Sed	Versym		*ifl_versym;	/* version symbol table array */
492199481Srdivacky	Ver_index	*ifl_verndx;	/* verndx[ver ndx] = Ver_index */
493195340Sed	List		ifl_verdesc;	/* version descriptor list */
494198090Srdivacky	List		ifl_relsect;	/* relocation section list */
495195340Sed	Alist		*ifl_groups;	/* SHT_GROUP section list */
496195340Sed	Half		ifl_neededndx;	/* index to NEEDED in .dyn section */
497199481Srdivacky	Half		ifl_flags;	/* Explicit/implicit reference */
498199481Srdivacky};
499195340Sed
500195340Sed#define	FLG_IF_CMDLINE	0x00001		/* full filename specified from the */
501195340Sed					/*	command line (no -l) */
502193323Sed#define	FLG_IF_NEEDED	0x00002		/* shared object should be recorded */
503198090Srdivacky#define	FLG_IF_DIRECT	0x00004		/* establish direct bindings to this */
504193323Sed					/*	object */
505193323Sed#define	FLG_IF_EXTRACT	0x00008		/* file extracted from an archive */
506193323Sed#define	FLG_IF_VERNEED	0x00010		/* version dependency information is */
507193323Sed					/*	required */
508193323Sed#define	FLG_IF_DEPREQD	0x00020		/* dependency is required to satisfy */
509193323Sed					/*	symbol references */
510193323Sed#define	FLG_IF_NEEDSTR	0x00040		/* dependency specified by -Nn */
511193323Sed					/*	flag */
512193323Sed#define	FLG_IF_IGNORE	0x00080		/* ignore unused dependencies */
513193323Sed#define	FLG_IF_NODIRECT	0x00100		/* object contains symbols that */
514193323Sed					/*	cannot be directly bound to. */
515193323Sed#define	FLG_IF_LAZYLD	0x00200		/* bindings to this object should be */
516193323Sed					/*	lazy loaded */
517193323Sed#define	FLG_IF_GRPPRM	0x00400		/* this dependency should have the */
518193323Sed					/*	DF_P1_GROUPPERM flag set */
519198090Srdivacky#define	FLG_IF_DISPPEND 0x00800		/* displacement relocation done */
520198090Srdivacky					/*	in the ld time. */
521198090Srdivacky#define	FLG_IF_DISPDONE 0x01000		/* displacement relocation done */
522198090Srdivacky					/* 	at the run time */
523198090Srdivacky#define	FLG_IF_MAPFILE	0x02000		/* file is a mapfile */
524193323Sed#define	FLG_IF_HSTRTAB	0x04000		/* file has a string section */
525193323Sed#define	FLG_IF_FILEREF	0x08000		/* file contains a section which */
526193323Sed					/*	is included in the output */
527193323Sed					/*	allocatable image */
528193323Sed
529193323Sedstruct is_desc {			/* input section descriptor */
530193323Sed	const char	*is_name;	/* the section name */
531193323Sed	const char	*is_basename;	/* original section name (without */
532193323Sed					/*	.<sect>%<func> munging */
533193323Sed	Shdr		*is_shdr;	/* the elf section header */
534193323Sed	Ifl_desc	*is_file;	/* infile desc for this section */
535193323Sed	Os_desc		*is_osdesc;	/* new output section for this */
536193323Sed					/*	input section */
537193323Sed	Elf_Data	*is_indata;	/* input sections raw data */
538193323Sed	Is_desc		*is_symshndx;	/* related SHT_SYM_SHNDX section */
539193323Sed	Word		is_scnndx;	/* original section index in file */
540193323Sed	Word		is_txtndx;	/* Index for section.  Used to decide */
541193323Sed					/*	where to insert section when */
542193323Sed					/* 	reordering sections */
543193323Sed	Word		is_ident;	/* preserved IDENT used for ordered */
544193323Sed					/*	sections. */
545193323Sed	uint_t		is_namehash;	/* hash on section name */
546193323Sed	Half		is_key;		/* Used for SHF_ORDERED */
547193323Sed	Half		is_flags;	/* Various flags */
548193323Sed};
549193323Sed
550193323Sed#define	FLG_IS_ORDERED	0x0001		/* This is a SHF_ORDERED section */
551193323Sed#define	FLG_IS_KEY	0x0002		/* This is a section pointed by */
552193323Sed					/* sh_info of a SHF_ORDERED section */
553193323Sed#define	FLG_IS_DISCARD	0x0004		/* section is to be discarded */
554193323Sed#define	FLG_IS_RELUPD	0x0008		/* symbol defined here may have moved */
555193323Sed#define	FLG_IS_SECTREF	0x0010		/* section has been referenced */
556193323Sed#define	FLG_IS_GDATADEF	0x0020		/* section contains global data sym */
557193323Sed#define	FLG_IS_EXTERNAL	0x0040		/* isp from an user file */
558193323Sed
559193323Sed
560193323Sed/*
561193323Sed * Map file and output file processing structures
562193323Sed */
563193323Sedstruct os_desc {			/* Output section descriptor */
564193323Sed	const char	*os_name;	/* the section name */
565193323Sed	Elf_Scn		*os_scn;	/* the elf section descriptor */
566193323Sed	Shdr		*os_shdr;	/* the elf section header */
567193323Sed	Os_desc		*os_relosdesc;	/* the output relocation section */
568193323Sed	List		os_relisdescs;	/* reloc input section descriptors */
569193323Sed					/*	for this output section */
570193323Sed	List		os_isdescs;	/* list of input sections in output */
571193323Sed	Sort_desc	*os_sort;	/* used for sorting sections */
572193323Sed	Sg_desc		*os_sgdesc;	/* segment os_desc is placed on */
573193323Sed	Elf_Data	*os_outdata;	/* output sections raw data */
574193323Sed	List		os_comdats;	/* list of COMDAT sections present */
575193323Sed					/*	in current output section */
576193323Sed	Word		os_scnsymndx;	/* index in output symtab of section */
577193323Sed					/*	symbol for this section */
578193323Sed	Word		os_txtndx;	/* Index for section.  Used to decide */
579193323Sed					/*	where to insert section when */
580193323Sed					/* 	reordering sections */
581193323Sed	Xword		os_szoutrels;	/* size of output relocation section */
582193323Sed	uint_t		os_namehash;	/* hash on section name */
583193323Sed	uchar_t		os_flags;	/* various flags */
584193323Sed};
585193323Sed
586193323Sed#define	FLG_OS_ORDER_KEY	0x01	/* include a sort key section */
587193323Sed#define	FLG_OS_OUTREL		0x02	/* output rel against this section */
588193323Sed#define	FLG_OS_SECTREF		0x04	/* isps are not affected by -zignore */
589193323Sed
590193323Sed/*
591193323Sed * For sorting sections.
592193323Sed */
593193323Sedstruct sort_desc {
594193323Sed	Is_desc		**st_order;
595193323Sed	Word		st_ordercnt;
596193323Sed	Is_desc		**st_before;
597193323Sed	Word		st_beforecnt;
598193323Sed	Is_desc		**st_after;
599193323Sed	Word		st_aftercnt;
600193323Sed};
601193323Sed
602193323Sedstruct sg_desc {			/* output segment descriptor */
603193323Sed	Phdr		sg_phdr;	/* segment header for output file */
604193323Sed	const char	*sg_name;	/* segment name */
605193323Sed	Xword		sg_round;	/* data rounding required (mapfile) */
606193323Sed	Xword		sg_length;	/* maximum segment length; if 0 */
607193323Sed					/*	segment is not specified */
608193323Sed	Alist		*sg_osdescs;	/* list of output section descriptors */
609193323Sed	Alist		*sg_secorder;	/* list specifying section ordering */
610193323Sed					/*	for the segment */
611193323Sed	Half		sg_flags;
612193323Sed	Sym_desc	*sg_sizesym;	/* size symbol for this segment */
613193323Sed	Xword		sg_addralign;	/* LCM of sh_addralign */
614193323Sed	Elf_Scn		*sg_fscn;	/* the SCN of the first section. */
615193323Sed};
616193323Sed
617193323Sed
618193323Sed#define	FLG_SG_VADDR	0x0001		/* vaddr segment attribute set */
619193323Sed#define	FLG_SG_PADDR	0x0002		/* paddr segment attribute set */
620193323Sed#define	FLG_SG_LENGTH	0x0004		/* length segment attribute set */
621193323Sed#define	FLG_SG_ALIGN	0x0008		/* align segment attribute set */
622193323Sed#define	FLG_SG_ROUND	0x0010		/* round segment attribute set */
623193323Sed#define	FLG_SG_FLAGS	0x0020		/* flags segment attribute set */
624193323Sed#define	FLG_SG_TYPE	0x0040		/* type segment attribute set */
625193323Sed#define	FLG_SG_ORDER	0x0080		/* has ordering been turned on for */
626193323Sed					/* 	this segment. */
627193323Sed					/*	i.e. ?[O] option in mapfile */
628193323Sed#define	FLG_SG_NOHDR	0x0100		/* don't map ELF or phdrs into */
629193323Sed					/* 	this segment */
630193323Sed#define	FLG_SG_EMPTY	0x0200		/* an empty segment specification */
631193323Sed					/*	no input sections will be */
632193323Sed					/*	associated to this section */
633198090Srdivacky#define	FLG_SG_KEY	0x0400		/* include a key section */
634193323Sed#define	FLG_SG_DISABLED	0x0800		/* this segment is disabled */
635193323Sed#define	FLG_SG_PHREQ	0x1000		/* this segment requires a program */
636193323Sed					/* header */
637195098Sed
638195098Sedstruct sec_order {
639195098Sed	const char	*sco_secname;	/* section name to be ordered */
640195098Sed	Word		sco_index;	/* ordering index for section */
641195098Sed	Half		sco_flags;
642195098Sed};
643195098Sed
644195098Sed#define	FLG_SGO_USED	0x0001		/* was ordering used? */
645195098Sed
646195098Sedstruct ent_desc {			/* input section entrance criteria */
647195098Sed	List		ec_files;	/* files from which to accept */
648195098Sed					/*	sections */
649195098Sed	const char	*ec_name;	/* name to match (NULL if none) */
650195098Sed	Word		ec_type;	/* section type */
651195098Sed	Word		ec_attrmask;	/* section attribute mask (AWX) */
652195098Sed	Word		ec_attrbits;	/* sections attribute bits */
653195098Sed	Sg_desc		*ec_segment;	/* output segment to enter if matched */
654195098Sed	Word		ec_ndx;		/* index to determine where section */
655195098Sed					/*	meeting this criteria should */
656195098Sed					/*	inserted. Used for reordering */
657195340Sed					/*	of sections. */
658195340Sed	Half		ec_flags;
659195340Sed};
660195340Sed
661198090Srdivacky#define	FLG_EC_USED	0x0001		/* entrance criteria met? */
662198090Srdivacky
663198090Srdivacky/*
664198090Srdivacky *  Move supplementary structures
665198090Srdivacky *	Sorted by symbol local/global and then by name.
666198090Srdivacky */
667198090Srdivackytypedef struct psym_info {
668198090Srdivacky	Sym_desc	*psym_symd;	/* partially initialized symbol */
669198090Srdivacky	Word 		psym_num;	/* number of move entires */
670198090Srdivacky	Half 		psym_flag;	/* various flag */
671198090Srdivacky	List 		psym_mvs;	/* the list of move entries */
672198090Srdivacky} Psym_info;
673198090Srdivacky
674198090Srdivacky#define	FLG_PSYM_OVERLAP	0x01	/* Overlapping */
675198090Srdivacky
676198090Srdivacky/*
677198090Srdivacky * One structure is allocated for a move entry.
678198090Srdivacky */
679195340Sedtypedef struct mv_itm {
680198090Srdivacky	Xword		mv_start;	/* start position */
681198090Srdivacky	Xword		mv_length;	/* The length of initialization */
682198090Srdivacky	Half		mv_flag;	/* various flags */
683198090Srdivacky	Is_desc		*mv_isp;	/* input desc. this entry is from */
684195340Sed	Move		*mv_ientry;	/* Input Move_entry */
685198090Srdivacky	Word 		mv_oidx;	/* Output Move_entry index */
686198090Srdivacky} Mv_itm;
687198090Srdivacky
688198090Srdivacky#define	FLG_MV_OUTSECT	0x01	/* Will be in move section */
689195340Sed
690198090Srdivacky/*
691198090Srdivacky * Define a move descripter used within relocation structures.
692198090Srdivacky */
693198090Srdivackystruct mv_desc {
694195340Sed	Move		*mvd_move;
695195340Sed	Sym_desc	*mvd_sym;
696195340Sed};
697195340Sed
698195340Sedstruct sym_desc {
699198090Srdivacky	List		sd_GOTndxs;	/* list of associated GOT entries */
700198090Srdivacky	Sym		*sd_sym;	/* pointer to symbol table entry */
701198090Srdivacky	Sym		*sd_osym;	/* copy of the original symbol entry */
702198090Srdivacky					/*	used only for local partial */
703195340Sed	Psym_info	*sd_psyminfo;	/* for partial symbols, maintain a */
704195340Sed					/*	pointer to parsym_info */
705195340Sed	const char	*sd_name;	/* symbols name */
706195340Sed	Ifl_desc	*sd_file;	/* file where symbol is taken */
707198090Srdivacky	Is_desc		*sd_isc;	/* input section of symbol definition */
708198090Srdivacky	Sym_aux		*sd_aux;	/* auxiliary global symbol info. */
709195340Sed	Word		sd_symndx;	/* index in output symbol table */
710198090Srdivacky	Word		sd_shndx;	/* sect. index sym is associated w/ */
711198090Srdivacky	Word		sd_flags;	/* state flags */
712198090Srdivacky	Half		sd_flags1;	/* more symbol flags */
713198090Srdivacky	Half		sd_ref;		/* reference definition of symbol */
714198090Srdivacky};
715198090Srdivacky
716198090Srdivacky/*
717198090Srdivacky * The auxiliary symbol descriptor contains the additional information (beyond
718198090Srdivacky * the symbol descriptor) required to process global symbols.  These symbols are
719198090Srdivacky * accessed via an internal symbol hash table where locality of reference is
720195340Sed * important for performance.
721195340Sed */
722195340Sedstruct sym_aux {
723195340Sed	List 		sa_dfiles;	/* files where symbol is defined */
724195340Sed	Sym		sa_sym;		/* copy of symtab entry */
725195340Sed	const char	*sa_vfile;	/* first unavailable definition */
726195340Sed	Ifl_desc	*sa_bindto;	/* symbol to bind to - for translator */
727195340Sed	const char	*sa_rfile;	/* file with first symbol referenced */
728195340Sed	Word		sa_hash;	/* the pure hash value of symbol */
729195340Sed	Word		sa_PLTndx;	/* index into PLT for symbol */
730195340Sed	Word		sa_PLTGOTndx;	/* GOT entry indx for PLT indirection */
731195340Sed	Word		sa_linkndx;	/* index of associated symbol from */
732195340Sed					/*	ET_DYN file */
733195340Sed	Half		sa_symspec;	/* special symbol ids */
734195340Sed	Half		sa_overndx;	/* output file versioning index */
735195340Sed	Half		sa_dverndx;	/* dependency versioning index */
736195340Sed};
737195340Sed
738198090Srdivacky
739195340Sed/*
740195340Sed * Nodes used to track symbols in the global AVL symbol dictionary.
741195340Sed */
742195340Sedstruct sym_avlnode {
743195340Sed	avl_node_t	sav_node;	/* AVL node */
744195340Sed	Word		sav_hash;	/* symbol hash value */
745195340Sed	const char	*sav_name;	/* symbol name */
746195340Sed	Sym_desc	*sav_symdesc;	/* SymDesc entry */
747195340Sed};
748195340Sed
749195340Sed/*
750195340Sed * These are the ids for processing of `Special symbols'.  They are used
751195340Sed * to set the sym->sd_aux->sa_symspec field.
752195340Sed */
753198090Srdivacky#define	SDAUX_ID_ETEXT	1		/* etext && _etext symbol */
754198090Srdivacky#define	SDAUX_ID_EDATA	2		/* edata && _edata symbol */
755195340Sed#define	SDAUX_ID_END	3		/* end, _end, && _END_ symbol */
756195340Sed#define	SDAUX_ID_DYN	4		/* DYNAMIC && _DYNAMIC symbol */
757195340Sed#define	SDAUX_ID_PLT	5		/* _PROCEDURE_LINKAGE_TABLE_ symbol */
758195340Sed#define	SDAUX_ID_GOT	6		/* _GLOBAL_OFFSET_TABLE_ symbol */
759195340Sed#define	SDAUX_ID_START	7		/* START_ && _START_ symbol */
760195340Sed
761195340Sed/*
762195340Sed * Flags for sym_desc.sd_flags
763195340Sed */
764195340Sed#define	FLG_SY_MVTOCOMM	0x00000001	/* assign symbol to common (.bss) */
765195340Sed					/*	this is a result of a */
766195340Sed					/*	copy reloc against sym */
767195340Sed#define	FLG_SY_GLOBREF	0x00000002	/* a global reference has been seen */
768195340Sed#define	FLG_SY_WEAKDEF	0x00000004	/* a weak definition has been used */
769195340Sed#define	FLG_SY_CLEAN	0x00000008	/* `Sym' entry points to original */
770195340Sed					/*	input file (read-only). */
771195340Sed#define	FLG_SY_UPREQD	0x00000010	/* symbol value update is required, */
772195340Sed					/*	either it's used as an entry */
773195340Sed					/*	point or for relocation, but */
774195340Sed					/*	it must be updated even if */
775195340Sed					/*	the -s flag is in effect */
776195340Sed#define	FLG_SY_NOTAVAIL	0x00000020	/* symbol is not available to the */
777198090Srdivacky					/*	application either because it */
778198090Srdivacky					/*	originates from an implicitly */
779198090Srdivacky					/* 	referenced shared object, or */
780198090Srdivacky					/*	because it is not part of a */
781198090Srdivacky					/*	specified version. */
782198090Srdivacky#define	FLG_SY_REDUCED	0x00000040	/* a global is reduced to local */
783198090Srdivacky#define	FLG_SY_VERSPROM	0x00000080	/* version definition has been */
784198090Srdivacky					/*	promoted to output file */
785198090Srdivacky#define	FLG_SY_PROT	0x00000100	/* stv_protected visibility seen */
786198090Srdivacky
787198090Srdivacky#define	FLG_SY_MAPREF	0x00000200	/* symbol reference generated by user */
788195340Sed					/*	from mapfile */
789195340Sed#define	FLG_SY_REFRSD	0x00000400	/* symbols sd_ref has been raised */
790195340Sed					/* 	due to a copy-relocs */
791195340Sed					/*	weak-strong pairing */
792195340Sed#define	FLG_SY_INTPOSE	0x00000800	/* symbol defines an interposer */
793195340Sed#define	FLG_SY_INVALID	0x00001000	/* unwanted/erroneous symbol */
794195340Sed#define	FLG_SY_SMGOT	0x00002000	/* small got index assigned to symbol */
795195340Sed					/*	sparc only */
796195340Sed#define	FLG_SY_PARENT	0x00004000	/* symbol to be found in parent */
797195340Sed					/*    only used with direct bindings */
798195340Sed#define	FLG_SY_LAZYLD	0x00008000	/* symbol to cause lazyloading of */
799195340Sed					/*	parent object */
800195340Sed#define	FLG_SY_ISDISC	0x00010000	/* symbol is a member of a DISCARDED */
801198090Srdivacky					/*	section (COMDAT) */
802198090Srdivacky#define	FLG_SY_PAREXPN	0x00020000	/* partially init. symbol to be */
803195340Sed					/*	expanded */
804195340Sed#define	FLG_SY_PLTPAD	0x00040000	/* pltpadding has been allocated for */
805195340Sed					/*	this symbol */
806195340Sed#define	FLG_SY_REGSYM	0x00080000	/* REGISTER symbol (sparc only) */
807195340Sed#define	FLG_SY_SOFOUND	0x00100000	/* compared against an SO definition */
808195340Sed#define	FLG_SY_EXTERN	0x00200000	/* symbol is external, allows -zdefs */
809195340Sed					/*    error suppression */
810195340Sed#define	FLG_SY_MAPUSED	0x00400000	/* mapfile symbol used (occurred */
811195340Sed					/*    within a relocatable object) */
812195340Sed#define	FLG_SY_COMMEXP	0x00800000	/* COMMON symbol which has been */
813195340Sed					/*	allocated */
814195340Sed#define	FLG_SY_CMDREF	0x01000000	/* symbol was referenced from the */
815195340Sed					/*	command line.  (ld -u <>, */
816198090Srdivacky					/*	ld -zrtldinfo=<>, ...) */
817198090Srdivacky#define	FLG_SY_SPECSEC	0x02000000	/* section index is reserved value */
818195340Sed					/*	ABS, COMMON, ... */
819195340Sed#define	FLG_SY_TENTSYM	0x04000000	/* tentative symbol */
820195340Sed#define	FLG_SY_VISIBLE	0x08000000	/* symbols visibility determined */
821195340Sed#define	FLG_SY_STDFLTR	0x10000000	/* symbol is a standard filter */
822195340Sed#define	FLG_SY_AUXFLTR	0x20000000	/* symbol is an auxiliary filter */
823195340Sed#define	FLG_SY_DYNSORT	0x40000000	/* req. in dyn[sym|tls]sort section */
824195340Sed#define	FLG_SY_NODYNSORT 0x80000000	/* excluded from dyn[sym_tls]sort sec */
825193323Sed
826193323Sed/*
827193323Sed * Sym_desc.sd_flags1
828193323Sed */
829193323Sed#define	FLG_SY1_GLOB	0x00000001	/* global symbol, remain global */
830195340Sed#define	FLG_SY1_PROT	0x00000002	/* global symbol, reduce to protected */
831195340Sed#define	FLG_SY1_LOCL	0x00000004	/* global symbol, reduce to local */
832195340Sed#define	FLG_SY1_DIR	0x00000008	/* global symbol, direct bindings */
833195340Sed#define	FLG_SY1_NDIR	0x00000010	/* global symbol, nondirect bindings */
834195340Sed#define	FLG_SY1_ELIM	0x00000020	/* global symbol, eliminate */
835193323Sed#define	FLG_SY1_IGNORE	0x00000040	/* symbol should be ignored */
836198090Srdivacky
837195340Sed#define	MSK_SY1_DEFINED	(FLG_SY1_GLOB | FLG_SY1_PROT | FLG_SY1_LOCL)
838195340Sed					/* The above mask indicates that */
839195340Sed					/*    a symbol has been explicitly */
840195340Sed					/*    scoped, and therefore is not */
841195340Sed					/*    a candidate for auto-reduction */
842195340Sed
843195340Sed/*
844195340Sed * create a mask for (Sym.St_other & visibility) since the
845195340Sed * gABI does not yet define a ELF*_ST_OTHER macro.
846195340Sed */
847195340Sed#define	MSK_SYM_VISIBILITY	0x03
848195340Sed
849195340Sed/*
850195340Sed * Structure to manage the shared object definition lists.  There are two lists
851195340Sed * that use this structure:
852195340Sed *
853195340Sed *  o	ofl_soneed; maintain the list of implicitly required dependencies
854195340Sed *	(ie. shared objects needed by other shared objects).  These definitions
855195340Sed *	may include RPATH's required to locate the dependencies, and any
856195340Sed *	version requirements.
857195340Sed *
858195340Sed *  o	ofl_socntl; maintains the shared object control definitions.  These are
859195340Sed *	provided by the user (via a mapfile) and are used to indicate any
860195340Sed *	SONAME translations and verion control requirements.
861195340Sed */
862195340Sedstruct	sdf_desc {
863195340Sed	const char	*sdf_name;	/* the shared objects file name */
864195340Sed	const char	*sdf_soname;	/* the shared objects SONAME */
865195340Sed	char		*sdf_rpath;	/* library search path DT_RPATH */
866195340Sed	const char	*sdf_rfile;	/* referencing file for diagnostics */
867195340Sed	Ifl_desc	*sdf_file;	/* the final input file descriptor */
868195340Sed	List		sdf_vers;	/* list of versions that are required */
869195340Sed					/*	from this object */
870198090Srdivacky	List		sdf_verneed;	/* list of VERNEEDS to create for */
871198090Srdivacky					/*	this object (via SPECVERS or */
872195340Sed					/*	ADDVERS) */
873195340Sed	Word		sdf_flags;
874195340Sed};
875195340Sed
876195340Sed#define	FLG_SDF_SONAME	0x02		/* An alternative SONAME is supplied */
877195340Sed#define	FLG_SDF_SELECT	0x04		/* version control selection required */
878195340Sed#define	FLG_SDF_VERIFY	0x08		/* version definition verification */
879195340Sed					/*	required */
880195340Sed#define	FLG_SDF_SPECVER	0x10		/* specify VERNEEDS */
881195340Sed#define	FLG_SDF_ADDVER	0x20		/* add VERNEED references */
882195340Sed
883198090Srdivacky/*
884195340Sed * Structure to manage shared object version usage requirements.
885195340Sed */
886195340Sedstruct	sdv_desc {
887195340Sed	const char	*sdv_name;	/* version name */
888195340Sed	const char	*sdv_ref;	/* versions reference */
889195340Sed	Word		sdv_flags;	/* flags */
890198090Srdivacky};
891195340Sed
892195340Sed#define	FLG_SDV_MATCHED	0x01		/* VERDEF found and matched */
893195340Sed
894195340Sed/*
895195340Sed * Structures to manage versioning information.  Two versioning structures are
896195340Sed * defined:
897195340Sed *
898195340Sed *   o	a version descriptor maintains a linked list of versions and their
899195340Sed *	associated dependencies.  This is used to build the version definitions
900195340Sed *	for an image being created (see map_symbol), and to determine the
901195340Sed *	version dependency graph for any input files that are versioned.
902195340Sed *
903195340Sed *   o	a version index array contains each version of an input file that is
904195340Sed *	being processed.  It informs us which versions are available for
905195340Sed *	binding, and is used to generate any version dependency information.
906195340Sed */
907195340Sedstruct	ver_desc {
908195340Sed	const char	*vd_name;	/* version name */
909195340Sed	Word		vd_hash;	/* hash value of name */
910195340Sed	Ifl_desc	*vd_file;	/* file that defined version */
911195340Sed	Half		vd_ndx;		/* coordinates with symbol index */
912195340Sed	Half		vd_flags;	/* version information */
913195340Sed	List		vd_deps;	/* version dependencies */
914195340Sed	Ver_desc	*vd_ref;	/* dependency's first reference */
915195340Sed};
916195340Sed
917195340Sedstruct	ver_index {
918198090Srdivacky	const char	*vi_name;	/* dependency version name */
919198090Srdivacky	Half		vi_flags;	/* communicates availability */
920195340Sed	Ver_desc	*vi_desc;	/* cross reference to descriptor */
921195340Sed};
922195340Sed
923195340Sed/*
924195340Sed * Define any internal version descriptor flags ([vd|vi]_flags).  Note that the
925198090Srdivacky * first byte is reserved for user visible flags (refer VER_FLG's in link.h).
926198090Srdivacky */
927198090Srdivacky#define	MSK_VER_USER	0x0f		/* mask for user visible flags */
928198090Srdivacky
929198090Srdivacky#define	FLG_VER_AVAIL	0x10		/* version is available for binding */
930198090Srdivacky#define	FLG_VER_REFER	0x20		/* version has been referenced */
931198090Srdivacky#define	FLG_VER_SELECT	0x40		/* version has been selected by user */
932198090Srdivacky#define	FLG_VER_CYCLIC	0x80		/* a member of cyclic dependency */
933198090Srdivacky
934198090Srdivacky
935198090Srdivacky/*
936198090Srdivacky * isalist(1) descriptor - used to break an isalist string into its component
937198090Srdivacky * options.
938198090Srdivacky */
939198090Srdivackystruct	isa_opt {
940195340Sed	char		*isa_name;	/* individual isa option name */
941198090Srdivacky	size_t		isa_namesz;	/*	and associated size */
942198090Srdivacky};
943198090Srdivacky
944198090Srdivackystruct	isa_desc {
945198090Srdivacky	char		*isa_list;	/* sysinfo(SI_ISALIST) list */
946198090Srdivacky	size_t		isa_listsz;	/*	and associated size */
947198090Srdivacky	Isa_opt		*isa_opt;	/* table of individual isa options */
948198090Srdivacky	size_t		isa_optno;	/*	and associated number */
949198090Srdivacky};
950198090Srdivacky
951198090Srdivacky/*
952198090Srdivacky * uname(2) descriptor - used to break a utsname structure into its component
953198090Srdivacky * options (at least those that we're interested in).
954198090Srdivacky */
955198090Srdivackystruct	uts_desc {
956198090Srdivacky	char		*uts_osname;	/* operating system name */
957198090Srdivacky	size_t		uts_osnamesz;	/*	and associated size */
958198090Srdivacky	char		*uts_osrel;	/* operating system release */
959198090Srdivacky	size_t		uts_osrelsz;	/*	and associated size */
960198090Srdivacky};
961198090Srdivacky
962198090Srdivacky
963198090Srdivacky/*
964198090Srdivacky * SHT_GROUP descriptor - used to track group sections at the global
965198090Srdivacky * level to resolve conflicts/determine which to keep.
966198090Srdivacky */
967198090Srdivackystruct group_desc {
968198090Srdivacky	const char	*gd_gsectname;	/* group section name */
969198090Srdivacky	const char	*gd_symname;	/* symbol name */
970198090Srdivacky	Word		*gd_data;	/* data for group section */
971198090Srdivacky	size_t		gd_scnndx;	/* group section index */
972198090Srdivacky	size_t		gd_cnt;		/* number of entries in group data */
973198090Srdivacky	Word		gd_flags;
974198090Srdivacky};
975198090Srdivacky
976198090Srdivacky#define	GRP_FLG_DISCARD	0x0001		/* group is to be discarded */
977198090Srdivacky
978198090Srdivacky/*
979198090Srdivacky * Indexes into the ld_support_funcs[] table.
980198090Srdivacky */
981198090Srdivackytypedef enum {
982198090Srdivacky	LDS_VERSION = 0,
983198090Srdivacky	LDS_INPUT_DONE,
984198090Srdivacky	LDS_START,
985198090Srdivacky	LDS_ATEXIT,
986198090Srdivacky	LDS_OPEN,
987198090Srdivacky	LDS_FILE,
988198090Srdivacky	LDS_INSEC,
989198090Srdivacky	LDS_SEC,
990198090Srdivacky	LDS_NUM
991198090Srdivacky} Support_ndx;
992198090Srdivacky
993198090Srdivacky
994198090Srdivacky/*
995198090Srdivacky * Structure to manage archive member caching.  Each archive has an archive
996198090Srdivacky * descriptor (Ar_desc) associated with it.  This contains pointers to the
997198090Srdivacky * archive symbol table (obtained by elf_getarsyms(3e)) and an auxiliary
998198090Srdivacky * structure (Ar_uax[]) that parallels this symbol table.  The member element
999198090Srdivacky * of this auxiliary table indicates whether the archive member associated with
1000198090Srdivacky * the symbol offset has already been extracted (AREXTRACTED) or partially
1001198090Srdivacky * processed (refer process_member()).
1002198090Srdivacky */
1003198090Srdivackytypedef struct ar_mem {
1004198090Srdivacky	Elf		*am_elf;	/* elf descriptor for this member */
1005198090Srdivacky	char		*am_name;	/* members name */
1006198090Srdivacky	char		*am_path;	/* path (ie. lib(foo.o)) */
1007198090Srdivacky	Sym		*am_syms;	/* start of global symbols */
1008198090Srdivacky	char		*am_strs;	/* associated string table start */
1009198090Srdivacky	Xword		am_symn;	/* no. of global symbols */
1010198090Srdivacky} Ar_mem;
1011198090Srdivacky
1012198090Srdivackytypedef struct ar_aux {
1013199481Srdivacky	Sym_desc	*au_syms;	/* internal symbol descriptor */
1014199481Srdivacky	Ar_mem		*au_mem;	/* associated member */
1015198090Srdivacky} Ar_aux;
1016198090Srdivacky
1017198090Srdivacky#define	FLG_ARMEM_PROC	(Ar_mem *)-1
1018198090Srdivacky
1019198090Srdivackytypedef struct ar_desc {
1020198090Srdivacky	const char	*ad_name;	/* archive file name */
1021198090Srdivacky	Elf		*ad_elf;	/* elf descriptor for the archive */
1022198090Srdivacky	Elf_Arsym	*ad_start;	/* archive symbol table start */
1023198090Srdivacky	Ar_aux		*ad_aux;	/* auxiliary symbol information */
1024198090Srdivacky	dev_t		ad_stdev;	/* device id and inode number for */
1025198090Srdivacky	ino_t		ad_stino;	/*	multiple inclusion checks */
1026198090Srdivacky	Word		ad_flags;	/* archive specific cmd line flags */
1027198090Srdivacky} Ar_desc;
1028198090Srdivacky
1029198090Srdivacky/*
1030198090Srdivacky * Define any archive descriptor flags.  NOTE, make sure they do not clash with
1031198090Srdivacky * any output file descriptor archive extraction flags, as these are saved in
1032198090Srdivacky * the same entry (see MSK_OF1_ARCHIVE).
1033198090Srdivacky */
1034198090Srdivacky#define	FLG_ARD_EXTRACT	0x00010000	/* archive member has been extracted */
1035198090Srdivacky
1036198090Srdivacky/*
1037198090Srdivacky * Function Declarations.
1038198090Srdivacky */
1039199481Srdivacky#if	defined(_ELF64)
1040198090Srdivacky
1041198090Srdivacky#define	ld_create_outfile	ld64_create_outfile
1042199481Srdivacky#define	ld_ent_setup		ld64_ent_setup
1043198090Srdivacky#define	ld_init_strings		ld64_init_strings
1044198090Srdivacky#define	ld_make_sections	ld64_make_sections
1045198090Srdivacky#define	ld_main			ld64_main
1046198090Srdivacky#define	ld_ofl_cleanup		ld64_ofl_cleanup
1047198090Srdivacky#define	ld_process_open		ld64_process_open
1048198090Srdivacky#define	ld_reloc_init		ld64_reloc_init
1049198090Srdivacky#define	ld_reloc_process	ld64_reloc_process
1050199481Srdivacky#define	ld_sym_validate		ld64_sym_validate
1051198090Srdivacky#define	ld_update_outfile	ld64_update_outfile
1052198090Srdivacky
1053199481Srdivacky#else
1054198090Srdivacky
1055198090Srdivacky#define	ld_create_outfile	ld32_create_outfile
1056198090Srdivacky#define	ld_ent_setup		ld32_ent_setup
1057198090Srdivacky#define	ld_init_strings		ld32_init_strings
1058198090Srdivacky#define	ld_make_sections	ld32_make_sections
1059198090Srdivacky#define	ld_main			ld32_main
1060198090Srdivacky#define	ld_ofl_cleanup		ld32_ofl_cleanup
1061198090Srdivacky#define	ld_process_open		ld32_process_open
1062198090Srdivacky#define	ld_reloc_init		ld32_reloc_init
1063198090Srdivacky#define	ld_reloc_process	ld32_reloc_process
1064198090Srdivacky#define	ld_sym_validate		ld32_sym_validate
1065198090Srdivacky#define	ld_update_outfile	ld32_update_outfile
1066198090Srdivacky
1067198090Srdivacky#endif
1068198090Srdivacky
1069198090Srdivackyextern int		ld32_main(int, char **);
1070198090Srdivackyextern int		ld64_main(int, char **);
1071198090Srdivacky
1072198113Srdivackyextern uintptr_t	ld_create_outfile(Ofl_desc *);
1073198090Srdivackyextern uintptr_t	ld_ent_setup(Ofl_desc *, Xword);
1074199481Srdivackyextern uintptr_t	ld_init_strings(Ofl_desc *);
1075199481Srdivackyextern uintptr_t	ld_make_sections(Ofl_desc *);
1076198090Srdivackyextern void		ld_ofl_cleanup(Ofl_desc *);
1077198090Srdivackyextern Ifl_desc		*ld_process_open(const char *, const char *, int *,
1078198113Srdivacky			    Ofl_desc *, Half, Rej_desc *);
1079198090Srdivackyextern uintptr_t	ld_reloc_init(Ofl_desc *);
1080199481Srdivackyextern uintptr_t	ld_reloc_process(Ofl_desc *);
1081199481Srdivackyextern uintptr_t	ld_sym_validate(Ofl_desc *);
1082199481Srdivackyextern uintptr_t	ld_update_outfile(Ofl_desc *);
1083198090Srdivacky
1084198090Srdivacky#ifdef	__cplusplus
1085198090Srdivacky}
1086198090Srdivacky#endif
1087198090Srdivacky
1088198090Srdivacky#endif	/* _LIBLD_H */
1089198090Srdivacky