xref: /titanic_50/usr/src/cmd/sgs/include/rtld.h (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_RTLD_H
28 #define	_RTLD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Global include file for the runtime linker support library.
34  */
35 #include <time.h>
36 #include <sgs.h>
37 #include <thread.h>
38 #include <synch.h>
39 #include <machdep.h>
40 #include <sys/avl.h>
41 #include <alist.h>
42 
43 #ifdef	_SYSCALL32
44 #include <inttypes.h>
45 #endif
46 
47 #ifdef	__cplusplus
48 extern "C" {
49 #endif
50 
51 
52 /*
53  * Linked list of directories or filenames (built from colon separated string).
54  */
55 typedef struct pnode {
56 	const char	*p_name;
57 	const char	*p_oname;
58 	size_t		p_len;
59 	uint_t		p_orig;
60 	void		*p_info;
61 	struct pnode	*p_next;
62 } Pnode;
63 
64 typedef struct rt_map	Rt_map;
65 
66 /*
67  * A binding descriptor.  Establishes the binding relationship between two
68  * objects, the caller (originator and the dependency (destination).
69  */
70 typedef struct {
71 	Rt_map		*b_caller;	/* caller (originator) of a binding */
72 	Rt_map		*b_depend;	/* dependency (destination) of a */
73 					/*	binding */
74 	uint_t		b_flags;	/* relationship of caller to the */
75 					/*	dependency */
76 } Bnd_desc;
77 
78 #define	BND_NEEDED	0x0001		/* caller NEEDED the dependency */
79 #define	BND_REFER	0x0002		/* caller relocation references the */
80 					/*	dependency */
81 
82 /*
83  * Private structure for communication between rtld_db and rtld.
84  *
85  * 	We must bump the version number whenever a update in one of
86  *	the structures/fields that rtld_db reads is updated.  This hopefully
87  *	permits rtld_db implementations of the future recognize corefiles
88  *	produced on older system and deal accordingly.
89  *
90  *	As of version 'RTLD_DB_VERSION <= 2' the following fields
91  *	were valid for core file examination (basically the public
92  *	Link_map):
93  *
94  *		ADDR()
95  *		NAME()
96  *		DYN()
97  *		NEXT()
98  *		PREV()
99  *
100  *	Valid fields for RTLD_DB_VERSION3
101  *
102  *		PATHNAME()
103  *		PADSTART()
104  *		PADIMLEN()
105  *		MSIZE()
106  *		FLAGS()
107  *		FLAGS1()
108  *
109  *	Valid fields for RTLD_DB_VERSION4
110  *
111  *		TLSMODID()
112  *
113  *	Valid fields for RTLD_DB_VERSION5
114  *
115  *		Added rtld_flags & FLG_RT_RELOCED to stable flags range
116  *
117  */
118 #define	R_RTLDDB_VERSION1	1	/* base version level - used for core */
119 					/*	file examination */
120 #define	R_RTLDDB_VERSION2	2	/* minor revision - not relavant for */
121 					/*	core files */
122 #define	R_RTLDDB_VERSION3	3
123 #define	R_RTLDDB_VERSION4	4
124 #define	R_RTLDDB_VERSION5	5
125 #define	R_RTLDDB_VERSION	R_RTLDDB_VERSION5	/* current version */
126 
127 typedef struct rtld_db_priv {
128 	struct r_debug	rtd_rdebug;	/* original r_debug structure */
129 	Word		rtd_version;	/* version no. */
130 	size_t		rtd_objpad;	/* padding around mmap()ed objects */
131 	List *		rtd_dynlmlst;	/* pointer to Dynlm_list */
132 } Rtld_db_priv;
133 
134 #ifdef _SYSCALL32
135 typedef struct rtld_db_priv32 {
136 	struct r_debug32 rtd_rdebug;	/* original r_debug structure */
137 	Elf32_Word	rtd_version;	/* version no. */
138 	Elf32_Word	rtd_objpad;	/* padding around mmap()ed objects */
139 	Elf32_Addr	rtd_dynlmlst;	/* pointer to Dynlm_list */
140 } Rtld_db_priv32;
141 #endif	/* _SYSCALL32 */
142 
143 
144 /*
145  * Link map list definition.  Link-maps are used to describe each loaded object.
146  * Lists of these link-maps describe the various namespaces within a process.
147  * The process executable and its dependencies are maintained on the lml_main
148  * list.  The runtime linker, and its dependencies are maintained on the
149  * lml_rtld list.  Additional lists can be created (see dlmopen()) for such
150  * things as auditors and their dependencies.
151  *
152  * Each link-map list maintains an Alist of one, or more, linked lists of
153  * link-maps.  For backward compatibility, the lm_head/lm_tail elements are
154  * initialized to the first linked-list of link-maps:
155  *
156  *      Lm_list
157  *    ----------
158  *   | lm_tail  | ------------------------------------
159  *   | lm_head  | --------------------                |
160  *   |          |                     |     Rt_map    |     Rt_map
161  *   |          |                     |     ------    |     ------
162  *   |          |          Alist       --> |      |   |--> |      |
163  *   |          |        ---------    |    |      | --     |      |
164  *   | lm_lists | ----> |         |   |    |      |    --> |      |
165  *   |          |       |---------|   |    |      |   |    |      |
166  *   |          |       | lc_head | --      ------    |     ------
167  *   |          |       | lc_tail | ------------------
168  *   |          |       |---------|
169  *                      | lc_head |
170  *                      | lc_tail |
171  *                      |---------|
172  *
173  * Multiple link-map lists exist to support the addition of lazy loaded
174  * families, filtee families, and dlopen() families.  The intent of these
175  * lists is to insure that a family of objects that are to be loaded are
176  * fully relocatable, and hence usable, before they become part of the main
177  * (al_data[0]) link-map control list.  This main link-map control list is
178  * the only list in existence when control is transferred to user code.
179  *
180  * During process initialization, the dynamic executable and its non-lazy
181  * dependencies are maintained on al_data[0].  If a new object is loaded, then
182  * this object is added to the next available control list [1], typically
183  * al_data[1].  Any dependencies of this object that have not already been
184  * loaded are added to the same control list.  Once all of the objects on the
185  * new control list have been successfully relocated, the objects are moved from
186  * the new control list to the highest control list to which objects of the new
187  * control list bound to, typically al_data[1] to al_data[0].
188  *
189  * Each loading scenario can be broken down as follows:
190  *
191  *  setup() - only the initial link-map control list is used:
192  *   i.	  create al_data[0]
193  *   ii.  add new link-map for main on al_data[0]
194  *   iii. analyze al_data[0] to add all non-lazy dependencies
195  *   iv.  relocate al_data[0] dependencies.
196  *
197  *  dlopen() - the initiator can only be the initial link-map control list:
198  *   i.   create al_data[1] from caller al_data[0]
199  *   ii.  add new link-map for the dlopen'ed object on al_data[1]
200  *   iii. analyze al_data[1] to add all non-lazy dependencies
201  *   iv.  relocate al_data[1] dependencies, and move to al_data[0].
202  *
203  *  filtee and lazy loading processing - the initiator can be any link-map
204  *  control list that is being relocated:
205  *   i.   create al_data[y] from caller al_data[x]
206  *   ii.  add new link-map for the new object on al_data[y]
207  *   iii. analyze al_data[y] to add all non-lazy dependencies
208  *   iv.  relocate al_data[y] dependencies, and move to al_data[x].
209  *
210  * This Alist therefore maintains a stack of link-map control lists.  The newest
211  * link-map control list can locate symbols within any of the former lists,
212  * however, control is not passed to a former list until the newest lists
213  * processing is complete.  Thus, objects can't bind to new objects until they
214  * have been fully analyzed and relocated.
215  *
216  * [1]  Note, additional link-map control list creation occurs after the head
217  * link-map object (typically the dynamic executable) has been relocated.  This
218  * staging is required to satisfy the binding requirements of copy relocations.
219  * Copy relocations, effectively, transfer the bindings of the copied data
220  * (say _iob in libc.so.1) to the copy location (_iob in the application).
221  * Thus an object that might bind to the original copy data must be redirected
222  * to the copy reference.  As the knowledge of a copy relocation having taken
223  * place is only known after relocating the application, link-map control list
224  * additions are suspended until after this relocation has completed.
225  */
226 typedef struct {
227 	Rt_map		*lc_head;
228 	Rt_map		*lc_tail;
229 	Alist		*lc_now;	/* pending promoted bind-now objects */
230 	uint_t		lc_flags;
231 } Lm_cntl;
232 
233 #define	LMC_FLG_ANALYZING	0x01	/* control list is being analyzed */
234 #define	LMC_FLG_RELOCATING	0x02	/* control list is being relocated */
235 #define	LMC_FLG_REANALYZE	0x04	/* repeat analysis (established when */
236 					/*	interposers are added */
237 
238 typedef	struct {
239 	/*
240 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
241 	 */
242 	Rt_map		*lm_head;	/* linked list pointers to active */
243 	Rt_map		*lm_tail;	/*	link-map list */
244 	Alist		*lm_handle;	/* not used by rtld_db - but spacing */
245 					/*	is required for flags */
246 	Word		lm_flags;
247 	/*
248 	 * END: Exposed to rtld_db - don't move, don't delete
249 	 */
250 	int		(*lm_peh)();	/* atexit() preexec_exit_handlers */
251 	Rt_map		*lm_peh_lmp;	/* and object that contributed them */
252 	Rt_map		*lm_info_lmp;	/* the first object with rtld_info */
253 	Alist		*lm_rtldinfo;	/* list of RTLDINFO tables */
254 	Audit_list	*lm_alp;	/* audit list descripter */
255 	avl_tree_t	*lm_fpavl;	/* avl tree of objects loaded */
256 	Alist		*lm_lists;	/* active and pending link-map lists */
257 	char		***lm_environ;	/* pointer to environment array */
258 	Word		lm_tflags;	/* transferable flags */
259 	int		lm_obj;		/* total number of objs on link-map */
260 	int		lm_init;	/* new obj since last init processing */
261 	int		lm_lazy;	/* obj with pending lazy dependencies */
262 } Lm_list;
263 
264 #ifdef	_SYSCALL32
265 typedef struct {
266 	/*
267 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
268 	 */
269 	Elf32_Addr	lm_head;
270 	Elf32_Addr	lm_tail;
271 	Elf32_Addr	lm_handle;
272 	Elf32_Word	lm_flags;
273 	/*
274 	 * END: Exposed to rtld_db - don't move, don't delete
275 	 */
276 	Elf32_Addr	lm_peh;
277 	Elf32_Addr	lm_peh_lmp;
278 	Elf32_Addr	lm_info_lmp;
279 	Elf32_Addr	lm_alp;
280 	Elf32_Addr	lm_fpavl;
281 	Elf32_Addr	lm_lists;
282 	Elf32_Addr	lm_environ;
283 	Elf32_Word	lm_tflags;
284 	int		lm_obj;
285 	int		lm_init;
286 	int		lm_lazy;
287 } Lm_list32;
288 #endif /* _SYSCALL32 */
289 
290 /*
291  * Possible Link_map list flags (Lm_list.lm_flags)
292  */
293 /*
294  * BEGIN: Exposed to rtld_db - don't move, don't delete
295  */
296 #define	LML_FLG_BASELM		0x00000001	/* primary link-map */
297 #define	LML_FLG_RTLDLM		0x00000002	/* rtld link-map */
298 /*
299  * END: Exposed to rtld_db - don't move, don't delete
300  */
301 #define	LML_FLG_NOAUDIT		0x00000004	/* symbol auditing disabled */
302 #define	LML_FLG_PLTREL		0x00000008	/* deferred plt relocation */
303 						/* 	initialization */
304 						/*	(ld.so.1 only) */
305 #define	LML_FLG_HOLDLOCK	0x00000010	/* hold the rtld mutex lock */
306 #define	LML_FLG_ENVIRON		0x00000020	/* environ var initialized */
307 #define	LML_FLG_INTRPOSE	0x00000040	/* interposing objs on list */
308 #define	LML_FLG_LOCAUDIT	0x00000080	/* local auditors exists for */
309 						/*	this link-map list */
310 #define	LML_FLG_LOADAVAIL	0x00000100	/* load anything available */
311 #define	LML_FLG_IGNRELERR	0x00000200	/* ignore relocation errors - */
312 						/*	internal for crle(1) */
313 #define	LML_FLG_DBNOTIF		0x00000400	/* binding activity going on */
314 #define	LML_FLG_BNDUNINIT	0x00000800	/* binding to a existing */
315 						/*	uninit'd object */
316 #define	LML_FLG_STARTREL	0x00001000	/* relocation started */
317 
318 #define	LML_FLG_TRC_LDDSTUB	0x00100000	/* identify lddstub */
319 #define	LML_FLG_TRC_ENABLE	0x00200000	/* tracing enabled (ldd) */
320 #define	LML_FLG_TRC_WARN	0x00400000	/* print warnings for undefs */
321 #define	LML_FLG_TRC_VERBOSE	0x00800000	/* verbose (versioning) trace */
322 #define	LML_FLG_TRC_SEARCH	0x01000000	/* trace search paths */
323 #define	LML_FLG_TRC_UNREF	0x02000000	/* trace unreferenced */
324 						/*	dependencies */
325 #define	LML_FLG_TRC_UNUSED	0x04000000	/* trace unused dependencies */
326 #define	LML_FLG_TRC_INIT	0x08000000	/* print .init order */
327 
328 #define	LML_MSK_TRC		0xfff00000	/* tracing mask */
329 
330 /*
331  * Possible Link_map transferable flags (Lm_list.lm_tflags), i.e., link-map
332  * list flags that can be propagated to any new link-map list created.
333  */
334 #define	LML_TFLG_NOLAZYLD	0x00000001	/* lazy loading disabled */
335 #define	LML_TFLG_NODIRECT	0x00000002	/* direct bindings disabled */
336 
337 #define	LML_TFLG_LOADFLTR	0x00000008	/* trigger filtee loading */
338 
339 #define	LML_TFLG_AUD_PREINIT	0x00100000	/* preinit (audit) exists */
340 #define	LML_TFLG_AUD_OBJSEARCH	0x00200000	/* objsearch (audit) exists */
341 #define	LML_TFLG_AUD_OBJOPEN	0x00400000	/* objopen (audit) exists */
342 #define	LML_TFLG_AUD_OBJFILTER	0x00800000	/* objfilter (audit) exists */
343 #define	LML_TFLG_AUD_OBJCLOSE	0x01000000	/* objclose (audit) exists */
344 #define	LML_TFLG_AUD_SYMBIND	0x02000000	/* symbind (audit) exists */
345 #define	LML_TFLG_AUD_PLTENTER	0x04000000	/* pltenter (audit) exists */
346 #define	LML_TFLG_AUD_PLTEXIT	0x08000000	/* pltexit (audit) exists */
347 #define	LML_TFLG_AUD_ACTIVITY	0x10000000	/* activity (audit) exists */
348 
349 /*
350  * NOTE: Audit flags have duplicated FLAGS1() values.  If more audit flags are
351  * added, update the FLAGS1() reservation FL1_AUD_RS_STR to FL1_AUD_RS_END
352  * defined later.
353  */
354 #define	LML_TFLG_AUD_MASK	0xfff00000	/* audit interfaces mask */
355 
356 
357 /*
358  * Information for dlopen(), dlsym(), and dlclose() on libraries linked by rtld.
359  * Each shared object referred from a dlopen call has an associated group
360  * handle structure returned that describes a group of one or more objects.
361  */
362 typedef struct {
363 	Alist *		gh_depends;	/* handle dependency list */
364 	Rt_map *	gh_owner;	/* handle owner and the link-map */
365 	uint_t		gh_refcnt;	/* handle reference count */
366 	uint_t		gh_flags;	/* handle flags */
367 } Grp_hdl;
368 
369 #define	GPH_ZERO	0x0001		/* special handle for dlopen(0) */
370 #define	GPH_LDSO	0x0002		/* special handle for ld.so.1 */
371 #define	GPH_FIRST	0x0004		/* dlsym() can only use originating */
372 					/*	dependency */
373 #define	GPH_PARENT	0x0008		/* assign caller as a parent */
374 #define	GPH_FILTEE	0x0010		/* handle used to specify a filtee */
375 #define	GPH_INITIAL	0x0020		/* handle is initialized */
376 #define	GPH_STICKY	0x0040		/* handle is unreferenced, but should */
377 					/*	not trigger object removal */
378 
379 /*
380  * A group descriptor.  A group handle (Grp_hdl) refers to a group of objects,
381  * each object, and its relationship to the handle, is maintained within a
382  * group descriptor.
383  */
384 typedef struct {
385 	Rt_map *	gd_depend;	/* dependency */
386 	uint_t		gd_flags;	/* dependency flags */
387 } Grp_desc;
388 
389 #define	GPD_AVAIL	0x0001		/* dependency available to dlsym() */
390 #define	GPD_ADDEPS	0x0002		/* dependencies of this dependency */
391 					/*	should be added to handle */
392 #define	GPD_PARENT	0x0004		/* dependency is a parent */
393 #define	GPD_FILTER	0x0008		/* dependency is our filter */
394 #define	GPD_REMOVE	0x1000		/* descriptor is a candidate for */
395 					/*	removal from the group */
396 
397 /*
398  * Define threading structures.  For compatibility with libthread (T1_VERSION 1
399  * and TI_VERSION 2) our locking structure is sufficient to hold a mutex or a
400  * readers/writers lock.
401  */
402 typedef struct {
403 	union {
404 		mutex_t		l_mutex;
405 		rwlock_t	l_rwlock;
406 	} u;
407 } Rt_lock;
408 
409 typedef	cond_t	Rt_cond;
410 
411 /*
412  * Define a dynamic section information descriptor.  This parallels the entries
413  * in the .dynamic section and holds auxiliary information to implement lazy
414  * loading and filtee processing.
415  */
416 typedef struct {
417 	uint_t	di_flags;
418 	void	*di_info;
419 } Dyninfo;
420 
421 #define	FLG_DI_STDFLTR	0x00001		/* .dynamic entry for DT_FILTER */
422 #define	FLG_DI_AUXFLTR	0x00002		/* .dynamic entry for DT_AUXILIARY */
423 #define	FLG_DI_SYMFLTR	0x00004		/* .dynamic entry for DT_SYMFILTER */
424 					/*	and DT_SYMAUXILIARY */
425 #define	MSK_DI_FILTER	0x0000f		/* mask for all filter possibilities */
426 
427 #define	FLG_DI_NEEDED	0x00010		/* entry represents a dependency */
428 #define	FLG_DI_GROUP	0x00020		/* open dependency as a group */
429 #define	FLG_DI_PROCESSD	0x00040		/* entry has been processed */
430 
431 /*
432  * Data Structure to track AVL tree for pathnames of objects
433  * loaded into memory
434  */
435 typedef struct {
436 	const char	*fpn_name;	/* object name */
437 	Rt_map		*fpn_lmp;	/* object link-map */
438 	avl_node_t	fpn_avl;	/* avl book-keeping (see SGSOFFSETOF) */
439 	uint_t		fpn_hash;	/* object name hash value */
440 } FullpathNode;
441 
442 /*
443  * Define a mapping structure, which is maintained to describe each mapping
444  * of an object, ie. the text segment, data segment, bss segment, etc.
445  */
446 typedef struct {
447 	caddr_t		m_vaddr;	/* mapping address */
448 	size_t		m_fsize;	/* backing file size */
449 	size_t		m_msize;	/* mapping size */
450 	int		m_perm;		/* mapping permissions */
451 } Mmap;
452 
453 /*
454  * Link-map definition.
455  */
456 struct rt_map {
457 	/*
458 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
459 	 */
460 	Link_map	rt_public;	/* public data */
461 	char		*rt_pathname;	/* full pathname of loaded object */
462 	ulong_t		rt_padstart;	/* start of image (including padding) */
463 	ulong_t		rt_padimlen;	/* size of image (including padding */
464 	ulong_t		rt_msize;	/* total memory mapped */
465 	uint_t		rt_flags;	/* state flags, see FLG below */
466 	uint_t		rt_flags1;	/* state flags1, see FL1 below */
467 	ulong_t		rt_tlsmodid;	/* TLS module id */
468 	/*
469 	 * END: Exposed to rtld_db - don't move, don't delete
470 	 */
471 	Alist		*rt_alias;	/* list of linked file names */
472 	Alist		*rt_fpnode;	/* list of FullpathNode AVL nodes */
473 	void		(*rt_init)();	/* address of _init */
474 	void		(*rt_fini)();	/* address of _fini */
475 	char		*rt_runpath;	/* LD_RUN_PATH and its equivalent */
476 	Pnode		*rt_runlist;	/*	Pnode structures */
477 	Alist		*rt_depends;	/* list of dependencies */
478 	Alist		*rt_callers;	/* list of callers */
479 	Alist		*rt_handles;	/* dlopen handles */
480 	Alist		*rt_groups;	/* groups we're a member of */
481 	ulong_t		rt_etext;	/* etext address */
482 	struct fct	*rt_fct;	/* file class table for this object */
483 	Sym		*(*rt_symintp)(); /* link map symbol interpreter */
484 	void		*rt_priv;	/* private data, object type specific */
485 	Lm_list		*rt_list;	/* link map list we belong to */
486 	uint_t		rt_objfltrndx;	/* object filtees .dynamic index */
487 	uint_t		rt_symsfltrcnt;	/* number of standard symbol filtees */
488 	uint_t		rt_symafltrcnt;	/* number of auxiliary symbol filtees */
489 	int		rt_mode;	/* usage mode, see RTLD mode flags */
490 	uint_t		rt_sortval;	/* temporary buffer to traverse graph */
491 	uint_t		rt_cycgroup;	/* cyclic group */
492 	dev_t		rt_stdev;	/* device id and inode number for .so */
493 	ino_t		rt_stino;	/*	multiple inclusion checks */
494 	char		*rt_origname;	/* original pathname of loaded object */
495 	size_t		rt_dirsz;	/*	and its size */
496 	Alist		*rt_copy;	/* list of copy relocations */
497 	Audit_desc	*rt_auditors;	/* audit descriptor array */
498 	Audit_info	*rt_audinfo;	/* audit information descriptor */
499 	Syminfo		*rt_syminfo;	/* elf .syminfo section - here */
500 					/*	because it is checked in */
501 					/*	common code */
502 	Addr		*rt_initarray;	/* .initarray table */
503 	Addr		*rt_finiarray;	/* .finiarray table */
504 	Addr		*rt_preinitarray; /* .preinitarray table */
505 	Mmap		*rt_mmaps;	/* array of mapping information */
506 	uint_t		rt_mmapcnt;	/*	and associated number */
507 	uint_t		rt_initarraysz;	/* size of .initarray table */
508 	uint_t		rt_finiarraysz;	/* size of .finiarray table */
509 	uint_t		rt_preinitarraysz; /* size of .preinitarray table */
510 	Dyninfo		*rt_dyninfo;	/* .dynamic information descriptors */
511 	uint_t		rt_dyninfocnt;	/* count of dyninfo entries */
512 	uint_t		rt_relacount;	/* no. of RELATIVE relocations */
513 	uint_t		rt_idx;		/* hold index within linkmap list */
514 	uint_t		rt_lazy;	/* lazy dependencies pending */
515 	Rt_cond		*rt_condvar;	/*	variables */
516 	Xword		rt_hwcap;	/* hardware capabilities */
517 	Xword		rt_sfcap;	/* software capabilities */
518 	thread_t	rt_threadid;	/* thread init/fini synchronization */
519 	uint_t		rt_cntl;	/* link-map control list we belong to */
520 };
521 
522 
523 #ifdef _SYSCALL32
524 /*
525  * Structure to allow 64-bit rtld_db to read 32-bit processes out of procfs.
526  */
527 typedef struct rt_map32 {
528 	/*
529 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
530 	 */
531 	Link_map32	rt_public;
532 	uint32_t	rt_pathname;
533 	uint32_t	rt_padstart;
534 	uint32_t	rt_padimlen;
535 	uint32_t	rt_msize;
536 	uint32_t	rt_flags;
537 	uint32_t	rt_flags1;
538 	uint32_t	rt_tlsmodid;
539 	/*
540 	 * END: Exposed to rtld_db - don't move, don't delete
541 	 */
542 	uint32_t	rt_alias;
543 	uint32_t	rt_fpnode;
544 	uint32_t 	rt_init;
545 	uint32_t	rt_fini;
546 	uint32_t	rt_runpath;
547 	uint32_t	rt_runlist;
548 	uint32_t	rt_depends;
549 	uint32_t	rt_callers;
550 	uint32_t	rt_handles;
551 	uint32_t	rt_groups;
552 	uint32_t	rt_etext;
553 	uint32_t	rt_fct;
554 	uint32_t	rt_symintp;
555 	uint32_t	rt_priv;
556 	uint32_t 	rt_list;
557 	uint32_t 	rt_objfltrndx;
558 	uint32_t 	rt_symsfltrcnt;
559 	uint32_t 	rt_symafltrcnt;
560 	uint32_t	rt_mode;
561 	uint32_t	rt_sortval;
562 	uint32_t	rt_cycgroup;
563 	uint32_t	rt_stdev;
564 	uint32_t	rt_stino;
565 	uint32_t	rt_origname;
566 	uint32_t	rt_dirsz;
567 	uint32_t	rt_copy;
568 	uint32_t 	rt_auditors;
569 	uint32_t 	rt_audinfo;
570 	uint32_t	rt_syminfo;
571 	uint32_t	rt_initarray;
572 	uint32_t	rt_finiarray;
573 	uint32_t	rt_preinitarray;
574 	uint32_t	rt_mmaps;
575 	uint32_t	rt_mmapcnt;
576 	uint32_t	rt_initarraysz;
577 	uint32_t	rt_finiarraysz;
578 	uint32_t	rt_preinitarraysz;
579 	uint32_t 	rt_dyninfo;
580 	uint32_t 	rt_dyninfocnt;
581 	uint32_t	rt_relacount;
582 	uint32_t	rt_idx;
583 	uint32_t	rt_lazy;
584 	uint32_t	rt_condvar;
585 	uint32_t	rt_hwcap;
586 	uint32_t	rt_sfcap;
587 	uint32_t	rt_threadid;
588 	uint32_t	rt_cntl;
589 } Rt_map32;
590 
591 #endif	/* _SYSCALL32 */
592 
593 /*
594  * Link map state flags.
595  */
596 /*
597  * BEGIN: Exposed to rtld_db - don't move, don't delete
598  */
599 #define	FLG_RT_ISMAIN	0x00000001	/* object represents main executable */
600 #define	FLG_RT_IMGALLOC	0x00000002	/* image is allocated (not mmap'ed) */
601 	/*
602 	 * Available for r_debug version >= RTLD_DB_VERSION5
603 	 */
604 #define	FLG_RT_RELOCED	0x00000004	/* object has been relocated */
605 /*
606  * END: Exposed to rtld_db - don't move, don't delete
607  */
608 #define	FLG_RT_SETGROUP	0x00000008	/* group establishment required */
609 #define	FLG_RT_HWCAP	0x00000010	/* process $HWCAP expansion */
610 #define	FLG_RT_OBJECT	0x00000020	/* object processing (ie. .o's) */
611 #define	FLG_RT_NEWLOAD	0x00000040	/* object is newly loaded */
612 #define	FLG_RT_NODUMP	0x00000080	/* object can't be dldump(3x)'ed */
613 #define	FLG_RT_DELETE	0x00000100	/* object can be deleted */
614 #define	FLG_RT_ANALYZED	0x00000200	/* object has been analyzed */
615 #define	FLG_RT_INITDONE	0x00000400	/* objects .init has been completed */
616 #define	FLG_RT_TRANS	0x00000800	/* object is acting as a translator */
617 #define	FLG_RT_FIXED	0x00001000	/* image location is fixed */
618 #define	FLG_RT_PRELOAD	0x00002000	/* object was preloaded */
619 #define	FLG_RT_ALTER	0x00004000	/* alternative object used */
620 #define	FLG_RT_LOADFLTR	0x00008000	/* trigger filtee loading */
621 #define	FLG_RT_AUDIT	0x00010000	/* object is an auditor */
622 #define	FLG_RT_MODESET	0x00020000	/* MODE() has been initialized */
623 #define	FLG_RT_ANALZING	0x00040000	/* object is being analyzed */
624 #define	FLG_RT_INITFRST 0x00080000	/* execute .init first */
625 #define	FLG_RT_NOOPEN	0x00100000	/* dlopen() not allowed */
626 #define	FLG_RT_FINICLCT	0x00200000	/* fini has been collected (tsort) */
627 #define	FLG_RT_INITCALL	0x00400000	/* objects .init has been called */
628 #define	FLG_RT_INTRPOSE	0x00800000	/* object is an INTERPOSER */
629 #define	FLG_RT_DIRECT	0x01000000	/* object has DIRECT bindings enabled */
630 #define	FLG_RT_SUNWBSS	0x02000000	/* object with PT_SUNWBSS, not mapped */
631 #define	FLG_RT_MOVE	0x04000000	/* object needs move operation */
632 #define	FLG_RT_DLSYM	0x08000000	/* dlsym in progress on object */
633 #define	FLG_RT_REGSYMS	0x10000000	/* object has DT_REGISTER entries */
634 #define	FLG_RT_INITCLCT	0x20000000	/* init has been collected (tsort) */
635 #define	FLG_RT_HANDLE	0x40000000	/* generate a handle for this object */
636 #define	FLG_RT_RELOCING	0x80000000	/* object is being relocated */
637 
638 #define	FL1_RT_COPYTOOK	0x00000001	/* copy relocation taken */
639 #define	FL1_RT_RELATIVE	0x00000002	/* relative path expansion required */
640 #define	FL1_RT_CONFSET	0x00000004	/* object was loaded by crle(1) */
641 #define	FL1_RT_NODEFLIB	0x00000008	/* ignore default library search */
642 #define	FL1_RT_ENDFILTE	0x00000010	/* filtee terminates filters search */
643 #define	FL1_RT_DISPREL	0x00000020	/* object has *disp* relocation */
644 #define	FL1_RT_TEXTREL	0x00000040	/* DT_TEXTREL set in object */
645 #define	FL1_RT_INITWAIT	0x00000080	/* threads are waiting on .init */
646 #define	FL1_RT_LDDSTUB	0x00000100	/* identify lddstub */
647 #define	FL1_RT_NOINIFIN	0x00000200	/* no .init or .fini exists */
648 #define	FL1_RT_USED	0x00000400	/* symbol referenced from this object */
649 #define	FL1_RT_SYMBOLIC	0x00000800	/* DF_SYMBOLIC was set - use */
650 					/*	symbolic sym resolution */
651 #define	FL1_RT_OBJSFLTR	0x00001000	/* object is acting as a standard */
652 #define	FL1_RT_OBJAFLTR	0x00002000	/*	or auxiliary filter */
653 #define	FL1_RT_SYMSFLTR	0x00004000	/* symbol is acting as a standard */
654 #define	FL1_RT_SYMAFLTR	0x00008000	/*	or auxiliary filter */
655 #define	MSK_RT_FILTER	0x0000f000	/* mask for all filter possibilites */
656 
657 /*
658  * The following range of bits are reserved to hold LML_TFLG_AUD_ values
659  * (although the definitions themselves aren't used anywhere).
660  */
661 #define	FL1_AUD_RS_STR	0x00100000	/* RESERVATION start for AU flags */
662 #define	FL1_AUD_RS_END	0x80000000	/* RESERVATION end for AU flags */
663 
664 
665 /*
666  * Flags for the tls_modactivity() routine
667  */
668 #define	TM_FLG_MODADD	0x01		/* call tls_modadd() interface */
669 #define	TM_FLG_MODREM	0x02		/* call tls_modrem() interface */
670 
671 /*
672  * Macros for getting to link_map data.
673  */
674 #define	ADDR(X)		((X)->rt_public.l_addr)
675 #define	NAME(X)		((X)->rt_public.l_name)
676 #define	DYN(X)		((X)->rt_public.l_ld)
677 #define	NEXT(X)		((X)->rt_public.l_next)
678 #define	PREV(X)		((X)->rt_public.l_prev)
679 #define	REFNAME(X)	((X)->rt_public.l_refname)
680 
681 /*
682  * Macros for getting to linker private data.
683  */
684 #define	PATHNAME(X)	((X)->rt_pathname)
685 #define	PADSTART(X)	((X)->rt_padstart)
686 #define	PADIMLEN(X)	((X)->rt_padimlen)
687 #define	MSIZE(X)	((X)->rt_msize)
688 #define	FLAGS(X)	((X)->rt_flags)
689 #define	FLAGS1(X)	((X)->rt_flags1)
690 #define	TLSMODID(X)	((X)->rt_tlsmodid)
691 
692 #define	ALIAS(X)	((X)->rt_alias)
693 #define	FPNODE(X)	((X)->rt_fpnode)
694 #define	INIT(X)		((X)->rt_init)
695 #define	FINI(X)		((X)->rt_fini)
696 #define	RPATH(X)	((X)->rt_runpath)
697 #define	RLIST(X)	((X)->rt_runlist)
698 #define	DEPENDS(X)	((X)->rt_depends)
699 #define	CALLERS(X)	((X)->rt_callers)
700 #define	HANDLES(X)	((X)->rt_handles)
701 #define	GROUPS(X)	((X)->rt_groups)
702 #define	ETEXT(X)	((X)->rt_etext)
703 #define	FCT(X)		((X)->rt_fct)
704 #define	SYMINTP(X)	((X)->rt_symintp)
705 #define	LIST(X)		((X)->rt_list)
706 #define	OBJFLTRNDX(X)	((X)->rt_objfltrndx)
707 #define	SYMSFLTRCNT(X)	((X)->rt_symsfltrcnt)
708 #define	SYMAFLTRCNT(X)	((X)->rt_symafltrcnt)
709 #define	MODE(X)		((X)->rt_mode)
710 #define	SORTVAL(X)	((X)->rt_sortval)
711 #define	CYCGROUP(X)	((X)->rt_cycgroup)
712 #define	STDEV(X)	((X)->rt_stdev)
713 #define	STINO(X)	((X)->rt_stino)
714 #define	ORIGNAME(X)	((X)->rt_origname)
715 #define	DIRSZ(X)	((X)->rt_dirsz)
716 #define	COPY(X)		((X)->rt_copy)
717 #define	AUDITORS(X)	((X)->rt_auditors)
718 #define	AUDINFO(X)	((X)->rt_audinfo)
719 #define	SYMINFO(X)	((X)->rt_syminfo)
720 #define	INITARRAY(X)	((X)->rt_initarray)
721 #define	FINIARRAY(X)	((X)->rt_finiarray)
722 #define	PREINITARRAY(X)	((X)->rt_preinitarray)
723 #define	MMAPS(X)	((X)->rt_mmaps)
724 #define	MMAPCNT(X)	((X)->rt_mmapcnt)
725 #define	INITARRAYSZ(X)	((X)->rt_initarraysz)
726 #define	FINIARRAYSZ(X)	((X)->rt_finiarraysz)
727 #define	PREINITARRAYSZ(X) ((X)->rt_preinitarraysz)
728 #define	DYNINFO(X)	((X)->rt_dyninfo)
729 #define	DYNINFOCNT(X)	((X)->rt_dyninfocnt)
730 #define	RELACOUNT(X)	((X)->rt_relacount)
731 #define	IDX(X)		((X)->rt_idx)
732 #define	LAZY(X)		((X)->rt_lazy)
733 #define	CONDVAR(X)	((X)->rt_condvar)
734 #define	CNTL(X)		((X)->rt_cntl)
735 #define	HWCAP(X)	((X)->rt_hwcap)
736 #define	SFCAP(X)	((X)->rt_sfcap)
737 #define	THREADID(X)	((X)->rt_threadid)
738 
739 
740 /*
741  * Flags for lookup_sym (and hence find_sym) routines.
742  */
743 #define	LKUP_DEFT	0x0000		/* simple lookup request */
744 #define	LKUP_SPEC	0x0001		/* special ELF lookup (allows address */
745 					/*	resolutions to plt[] entries) */
746 #define	LKUP_LDOT	0x0002		/* indicates the original A_OUT */
747 					/*	symbol had a leading `.' */
748 #define	LKUP_FIRST	0x0004		/* lookup symbol in first link map */
749 					/*	only */
750 #define	LKUP_COPY	0x0008		/* lookup symbol for a COPY reloc, do */
751 					/*	not bind to symbol at head */
752 #define	LKUP_ALLCNTLIST	0x0010		/* lookup symbol in all control lists */
753 #define	LKUP_SELF	0x0020		/* lookup symbol in ourself - undef */
754 					/*	is valid */
755 #define	LKUP_WEAK	0x0040		/* relocation reference is weak */
756 #define	LKUP_NEXT	0x0080		/* request originates from RTLD_NEXT */
757 #define	LKUP_NODESCENT	0x0100		/* don't descend through dependencies */
758 #define	LKUP_NOFALBACK	0x0200		/* don't fall back to loading */
759 					/*	pending lazy dependencies */
760 #define	LKUP_DIRECT	0x0400		/* direct binding request */
761 
762 /*
763  * Data structure for calling lookup_sym()
764  */
765 typedef struct {
766 	const char	*sl_name;	/* symbol name */
767 	Rt_map		*sl_cmap;	/* callers link-map */
768 	Rt_map		*sl_imap;	/* initial link-map to search */
769 	ulong_t		sl_hash;	/* symbol hash value */
770 	ulong_t		sl_rsymndx;	/* referencing reloc symndx */
771 	uint_t		sl_flags;	/* lookup flags */
772 } Slookup;
773 
774 
775 typedef	enum {
776 	PLT_T_NONE = 0,
777 	PLT_T_21D,
778 	PLT_T_24D,
779 	PLT_T_U32,
780 	PLT_T_U44,
781 	PLT_T_FULL,
782 	PLT_T_FAR,
783 	PLT_T_NUM			/* Must be last */
784 } Pltbindtype;
785 
786 /*
787  * Prototypes.
788  */
789 extern Lm_list		lml_main;	/* main's link map list */
790 extern Lm_list		lml_rtld;	/* rtld's link map list */
791 extern Lm_list		*lml_list[];
792 
793 extern int		do_reloc(uchar_t, uchar_t *, Xword *, const char *,
794 			    const char *);
795 extern Pltbindtype	elf_plt_write(uintptr_t, uintptr_t, void *, uintptr_t,
796 			    Xword);
797 extern void		eprintf(Error, const char *, ...);
798 extern Rt_map		*is_so_loaded(Lm_list *, const char *, int);
799 extern Sym		*lookup_sym(Slookup *, Rt_map **, uint_t *);
800 extern int		rt_dldump(Rt_map *, const char *, int, Addr);
801 
802 #ifdef	__cplusplus
803 }
804 #endif
805 
806 #endif /* _RTLD_H */
807