xref: /titanic_50/usr/src/cmd/sgs/include/rtld.h (revision 5e1c72e1529d41fe7e1babf69acebeed897f9610)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #ifndef	_RTLD_H
27 #define	_RTLD_H
28 
29 /*
30  * Global include file for the runtime linker.
31  */
32 #include <sys/mman.h>
33 #include <time.h>
34 #include <sgs.h>
35 #include <thread.h>
36 #include <synch.h>
37 #include <link.h>
38 #include <sys/avl.h>
39 #include <alist.h>
40 #include <libc_int.h>
41 
42 #ifdef	_SYSCALL32
43 #include <inttypes.h>
44 #endif
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 /*
51  * We use rtld_ino_t instead of ino_t so that we can get
52  * access to large inode values from 32-bit code.
53  */
54 #ifdef _LP64
55 typedef ino_t		rtld_ino_t;
56 #else
57 typedef ino64_t		rtld_ino_t;
58 #endif
59 
60 typedef struct rt_map	Rt_map;
61 typedef struct slookup	Slookup;
62 
63 /*
64  * A binding descriptor.  Establishes the binding relationship between two
65  * objects, the caller (originator) and the dependency (destination).
66  *
67  * Every relationship between two objects is tracked by a binding descriptor.
68  * This descriptor is referenced from a link-map's DEPENDS and CALLERS lists.
69  * Note, Aplist's are diagramed to fully expose the allocations required to
70  * establish the data structure relationships.
71  *
72  *                                  Bnd_desc
73  *                                 ----------
74  *                    ------------| b_caller |
75  *                   |            | b_depend | ----------
76  *                   |            |          |           |
77  *      Rt_map       |             ----------            |       Rt_map
78  *    ----------     |                ^ ^                |     ----------
79  *   |          | <--                 | |                 --> |          |
80  *   |          |        --------     | |                     |          |
81  *   | DEPENDS  | ----> |        |    | |     --------        |          |
82  *   |          |       |        |    | |    |        | <---- | CALLERS  |
83  *   |          |       |        | ---  |    |        |       |          |
84  *   |          |       |        |       --- |        |       |          |
85  *   |          |        --------            |        |       |          |
86  *    ----------          Aplist              --------         ----------
87  *                                             Aplist
88  */
89 typedef struct {
90 	Rt_map		*b_caller;	/* caller (originator) of a binding */
91 	Rt_map		*b_depend;	/* dependency (destination) of a */
92 					/*	binding */
93 	uint_t		b_flags;	/* relationship of caller to the */
94 					/*	dependency */
95 } Bnd_desc;
96 
97 #define	BND_NEEDED	0x0001		/* caller NEEDED the dependency */
98 #define	BND_REFER	0x0002		/* caller relocation references the */
99 					/*	dependency */
100 #define	BND_FILTER	0x0004		/* binding identifies filter, used */
101 					/*	for diagnostics only */
102 /*
103  * Private structure for communication between rtld_db and rtld.
104  *
105  * We must bump the version number when ever an update in one of the
106  * structures/fields that rtld_db reads is updated.  This hopefully permits
107  * rtld_db implementations of the future to recognize core files produced on
108  * older systems and deal with these core files accordingly.
109  *
110  * As of version 'R_RTLDDB_VERSION <= 2' the following fields were valid for
111  * core file examination (basically the public Link_map):
112  *
113  *		ADDR()
114  *		NAME()
115  *		DYN()
116  *		NEXT()
117  *		PREV()
118  *
119  * Valid fields for R_RTLDDB_VERSION3
120  *
121  *		PATHNAME()
122  *		PADSTART()
123  *		PADIMLEN()
124  *		MSIZE()
125  *		FLAGS()
126  *		FLAGS1()
127  *
128  * Valid fields for R_RTLDDB_VERSION4
129  *
130  *		TLSMODID()
131  *
132  * Valid fields for R_RTLDDB_VERSION5
133  *
134  *		Added rtld_flags & FLG_RT_RELOCED to stable flags range
135  *
136  */
137 #define	R_RTLDDB_VERSION1	1	/* base version level - used for core */
138 					/*	file examination */
139 #define	R_RTLDDB_VERSION2	2	/* minor revision - not relevant for */
140 					/*	core files */
141 #define	R_RTLDDB_VERSION3	3
142 #define	R_RTLDDB_VERSION4	4
143 #define	R_RTLDDB_VERSION5	5
144 #define	R_RTLDDB_VERSION	R_RTLDDB_VERSION5	/* current version */
145 
146 typedef struct rtld_db_priv {
147 	struct r_debug	rtd_rdebug;	/* original r_debug structure */
148 	Word		rtd_version;	/* version no. */
149 	size_t		rtd_objpad;	/* padding around mmap()ed objects */
150 	APlist		**rtd_dynlmlst;	/* pointer to dynlm_list pointer */
151 } Rtld_db_priv;
152 
153 #ifdef _SYSCALL32
154 typedef struct rtld_db_priv32 {
155 	struct r_debug32 rtd_rdebug;	/* original r_debug structure */
156 	Elf32_Word	rtd_version;	/* version no. */
157 	Elf32_Word	rtd_objpad;	/* padding around mmap()ed objects */
158 	Elf32_Addr	rtd_dynlmlst;	/* pointer to dynlm_list */
159 } Rtld_db_priv32;
160 #endif	/* _SYSCALL32 */
161 
162 /*
163  * External function definitions.  ld.so.1 must convey information to libc in
164  * regards to threading.  libc also provides routines for atexit() and message
165  * localization.  libc provides the necessary interfaces via its RTLDINFO
166  * structure and/or later _ld_libc() calls.
167  *
168  * These external functions are maintained for each link-map list, and used
169  * where appropriate.  The functions are associated with the object that
170  * provided them, so that should the object be deleted (say, from an alternative
171  * link-map), the functions can be removed.
172  */
173 typedef struct {
174 	Rt_map	*lc_lmp;			/* function provider */
175 	union {
176 		int		(*lc_func)();	/* external function pointer */
177 		uintptr_t	lc_val;		/* external value */
178 		char    	*lc_ptr;	/* external character pointer */
179 	} lc_un;
180 } Lc_desc;
181 
182 /*
183  * Link map list definition.  Link-maps are used to describe each loaded object.
184  * Lists of these link-maps describe the various namespaces within a process.
185  * The process executable and its dependencies are maintained on the lml_main
186  * list.  The runtime linker, and its dependencies are maintained on the
187  * lml_rtld list.  Additional lists can be created (see dlmopen()) for such
188  * things as auditors and their dependencies.
189  *
190  * Each link-map list maintains an Alist of one, or more, linked lists of
191  * link-maps.  For backward compatibility, the lm_head/lm_tail elements are
192  * initialized to the first linked-list of link-maps:
193  *
194  *      Lm_list
195  *    ----------
196  *   | lm_tail  | ------------------------------------
197  *   | lm_head  | --------------------                |
198  *   |          |                     |     Rt_map    |     Rt_map
199  *   |          |                     |     ------    |     ------
200  *   |          |          Alist       --> |      |   |--> |      |
201  *   |          |        ---------    |    |      | --     |      |
202  *   | lm_lists | ----> |         |   |    |      |    --> |      |
203  *   |          |       |---------|   |    |      |   |    |      |
204  *   |          |       | lc_head | --      ------    |     ------
205  *   |          |       | lc_tail | ------------------
206  *   |          |       |---------|
207  *    ----------        | lc_head |
208  *                      | lc_tail |
209  *                      |---------|
210  *
211  * Multiple link-map lists exist to support the addition of lazy loaded
212  * families, filtee families, and dlopen() families.  The intent of these
213  * lists is to insure that a family of objects that are to be loaded are
214  * fully relocatable, and hence usable, before they become part of the main
215  * (al_data[0]) link-map control list.  This main link-map control list is
216  * the only list in existence when control is transferred to user code.
217  *
218  * During process initialization, the dynamic executable and its non-lazy
219  * dependencies are maintained on al_data[0].  If a new object is loaded, then
220  * this object is added to the next available control list [1], typically
221  * al_data[1].  Any dependencies of this object that have not already been
222  * loaded are added to the same control list.  Once all of the objects on the
223  * new control list have been successfully relocated, the objects are moved from
224  * the new control list to the highest control list to which objects of the new
225  * control list bound to, typically al_data[1] to al_data[0].
226  *
227  * Each loading scenario can be broken down as follows:
228  *
229  *  setup() - only the initial link-map control list is used:
230  *   i.	  create al_data[0]
231  *   ii.  add new link-map for main on al_data[0]
232  *   iii. analyze al_data[0] to add all non-lazy dependencies
233  *   iv.  relocate al_data[0] dependencies.
234  *
235  *  dlopen() - the initiator can only be the initial link-map control list:
236  *   i.   create al_data[1] from caller al_data[0]
237  *   ii.  add new link-map for the dlopen'ed object on al_data[1]
238  *   iii. analyze al_data[1] to add all non-lazy dependencies
239  *   iv.  relocate al_data[1] dependencies, and move to al_data[0].
240  *
241  *  filtee and lazy loading processing - the initiator can be any link-map
242  *  control list that is being relocated:
243  *   i.   create al_data[y] from caller al_data[x]
244  *   ii.  add new link-map for the new object on al_data[y]
245  *   iii. analyze al_data[y] to add all non-lazy dependencies
246  *   iv.  relocate al_data[y] dependencies, and move to al_data[x].
247  *
248  * This Alist therefore maintains a stack of link-map control lists.  The newest
249  * link-map control list can locate symbols within any of the former lists,
250  * however, control is not passed to a former list until the newest lists
251  * processing is complete.  Thus, objects can't bind to new objects until they
252  * have been fully analyzed and relocated.
253  *
254  * [1]  Note, additional link-map control list creation occurs after the head
255  * link-map object (typically the dynamic executable) has been relocated.  This
256  * staging is required to satisfy the binding requirements of copy relocations.
257  * Copy relocations, effectively, transfer the bindings of the copied data
258  * (say _iob in libc.so.1) to the copy location (_iob in the application).
259  * Thus an object that might bind to the original copy data must be redirected
260  * to the copy reference.  As the knowledge of a copy relocation having taken
261  * place is only known after relocating the application, link-map control list
262  * additions are suspended until after this relocation has completed.
263  */
264 typedef struct {
265 	Rt_map		*lc_head;
266 	Rt_map		*lc_tail;
267 	APlist		*lc_now;	/* pending promoted bind-now objects */
268 	uint_t		lc_flags;
269 } Lm_cntl;
270 
271 #define	LMC_FLG_ANALYZING	0x01	/* control list is being analyzed */
272 #define	LMC_FLG_RELOCATING	0x02	/* control list is being relocated */
273 #define	LMC_FLG_REANALYZE	0x04	/* repeat analysis (established when */
274 					/*	interposers are added */
275 
276 struct lm_list {
277 	/*
278 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
279 	 */
280 	Rt_map		*lm_head;	/* linked list pointers to active */
281 	Rt_map		*lm_tail;	/*	link-map list */
282 	APlist		*lm_handle;	/* not used by rtld_db - but spacing */
283 					/*	is required for flags */
284 	Word		lm_flags;
285 	/*
286 	 * END: Exposed to rtld_db - don't move, don't delete
287 	 */
288 	Alist		*lm_rti;	/* list of RTLDINFO tables */
289 	Audit_list	*lm_alp;	/* audit list descriptor */
290 	avl_tree_t	*lm_fpavl;	/* avl tree of objects loaded */
291 	Alist		*lm_lists;	/* active and pending link-map lists */
292 	char		***lm_environ;	/* pointer to environment array */
293 	Word		lm_tflags;	/* transferable flags */
294 	uint_t		lm_obj;		/* total number of objs on link-map */
295 	uint_t		lm_init;	/* new obj since last init processing */
296 	uint_t		lm_lazy;	/* obj with pending lazy dependencies */
297 	uint_t		lm_tls;		/* new obj that require TLS */
298 	uint_t		lm_lmid;	/* unique link-map list identifier, */
299 	char		*lm_lmidstr;	/* and associated diagnostic string */
300 	APlist		*lm_actaudit;	/* list of pending audit activity */
301 	Lc_desc		lm_lcs[CI_MAX];	/* external libc functions */
302 };
303 
304 #ifdef	_SYSCALL32
305 struct lm_list32 {
306 	/*
307 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
308 	 */
309 	Elf32_Addr	lm_head;
310 	Elf32_Addr	lm_tail;
311 	Elf32_Addr	lm_handle;
312 	Elf32_Word	lm_flags;
313 	/*
314 	 * END: Exposed to rtld_db - don't move, don't delete
315 	 */
316 	Elf32_Addr	lm_rti;
317 	Elf32_Addr	lm_fpavl;
318 	Elf32_Addr	lm_lists;
319 	Elf32_Addr	lm_environ;
320 	Elf32_Word	lm_tflags;
321 	uint_t		lm_obj;
322 	uint_t		lm_init;
323 	uint_t		lm_lazy;
324 	uint_t		lm_tls;
325 	uint_t		lm_lmid;
326 	Elf32_Addr	lm_lmidstr;
327 	Elf32_Addr	lm_actaudit;
328 	Elf32_Addr	lm_lcs[CI_MAX];
329 };
330 #endif /* _SYSCALL32 */
331 
332 /*
333  * Possible Link_map list flags (Lm_list.lm_flags)
334  */
335 /*
336  * BEGIN: Exposed to rtld_db - don't move, don't delete
337  */
338 #define	LML_FLG_BASELM		0x00000001	/* primary link-map */
339 #define	LML_FLG_RTLDLM		0x00000002	/* rtld link-map */
340 /*
341  * END: Exposed to rtld_db - don't move, don't delete
342  */
343 #define	LML_FLG_NOAUDIT		0x00000004	/* symbol auditing disabled */
344 #define	LML_FLG_PLTREL		0x00000008	/* deferred plt relocation */
345 						/* 	initialization */
346 						/*	(ld.so.1 only) */
347 #define	LML_FLG_HOLDLOCK	0x00000010	/* hold the rtld mutex lock */
348 #define	LML_FLG_ENVIRON		0x00000020	/* environ var initialized */
349 #define	LML_FLG_INTRPOSE	0x00000040	/* interposing objs on list */
350 #define	LML_FLG_LOCAUDIT	0x00000080	/* local auditors exists for */
351 						/*	this link-map list */
352 #define	LML_FLG_LOADAVAIL	0x00000100	/* load anything available */
353 #define	LML_FLG_IGNRELERR	0x00000200	/* ignore relocation errors - */
354 						/*	internal for crle(1) */
355 #define	LML_FLG_DBNOTIF		0x00000400	/* binding activity going on */
356 #define	LML_FLG_STARTREL	0x00000800	/* relocation started */
357 #define	LML_FLG_ATEXIT		0x00001000	/* atexit processing */
358 #define	LML_FLG_OBJADDED	0x00002000	/* object(s) added */
359 #define	LML_FLG_OBJDELETED	0x00004000	/* object(s) deleted */
360 #define	LML_FLG_OBJREEVAL	0x00008000	/* existing object(s) needs */
361 						/*	tsort reevaluation */
362 #define	LML_FLG_NOPENDGLBLAZY	0x00010000	/* no pending, global, lazy */
363 						/*	dependencies remain */
364 #define	LML_FLG_INTRPOSETSORT	0x00020000	/* interpose tsorting done */
365 #define	LML_FLG_AUDITNOTIFY	0x00040000	/* audit consistent required */
366 #define	LML_FLG_GROUPSEXIST	0x00080000	/* local groups exist */
367 
368 #define	LML_FLG_TRC_LDDSTUB	0x00100000	/* identify lddstub */
369 #define	LML_FLG_TRC_ENABLE	0x00200000	/* tracing enabled (ldd) */
370 #define	LML_FLG_TRC_WARN	0x00400000	/* print warnings for undefs */
371 #define	LML_FLG_TRC_VERBOSE	0x00800000	/* verbose (versioning) trace */
372 #define	LML_FLG_TRC_SEARCH	0x01000000	/* trace search paths */
373 #define	LML_FLG_TRC_UNREF	0x02000000	/* trace unreferenced */
374 						/*	dependencies */
375 #define	LML_FLG_TRC_UNUSED	0x04000000	/* trace unused dependencies */
376 #define	LML_FLG_TRC_INIT	0x08000000	/* print .init order */
377 #define	LML_FLG_TRC_NOUNRESWEAK	0x10000000	/* unresolved weak references */
378 						/*	are not allowed */
379 #define	LML_FLG_TRC_NOPAREXT	0x20000000	/* unresolved PARENT/EXTERN */
380 						/*	references are not */
381 						/*	allowed */
382 #define	LML_MSK_TRC		0xfff00000	/* tracing mask */
383 
384 /*
385  * Possible Link_map transferable flags (Lm_list.lm_tflags), i.e., link-map
386  * list flags that can be propagated to any new link-map list created.
387  */
388 #define	LML_TFLG_NOLAZYLD	0x00000001	/* lazy loading disabled */
389 #define	LML_TFLG_NODIRECT	0x00000002	/* direct bindings disabled */
390 
391 #define	LML_TFLG_LOADFLTR	0x00000008	/* trigger filtee loading */
392 
393 #define	LML_TFLG_AUD_PREINIT	0x00001000	/* preinit (audit) exists */
394 #define	LML_TFLG_AUD_OBJSEARCH	0x00002000	/* objsearch (audit) exists */
395 #define	LML_TFLG_AUD_OBJOPEN	0x00004000	/* objopen (audit) exists */
396 #define	LML_TFLG_AUD_OBJFILTER	0x00008000	/* objfilter (audit) exists */
397 #define	LML_TFLG_AUD_OBJCLOSE	0x00010000	/* objclose (audit) exists */
398 #define	LML_TFLG_AUD_SYMBIND	0x00020000	/* symbind (audit) exists */
399 #define	LML_TFLG_AUD_PLTENTER	0x00040000	/* pltenter (audit) exists */
400 #define	LML_TFLG_AUD_PLTEXIT	0x00080000	/* pltexit (audit) exists */
401 #define	LML_TFLG_AUD_ACTIVITY	0x00100000	/* activity (audit) exists */
402 
403 /*
404  * NOTE: Each auditing module establishes a set of audit flags, AFLAGS(), that
405  * define the auditing interfaces the module offers.  These auditing flags are
406  * the LML_TFLG_AUD_ flags defined above.  Global auditors result in setting
407  * the lm_tflags too.  Local auditors only use the AFLAGS().  All tests for
408  * auditing inspect the lm_tflags and AFLAGS() for a specific auditing
409  * interface, and thus use the same flag to test for both types of auditors.
410  */
411 #define	LML_TFLG_AUD_MASK	0x0ffff000	/* audit interfaces mask */
412 
413 /*
414  * Define a Group Handle.
415  *
416  * The capability of ld.so.1 to associate a group of objects, look for symbols
417  * within that group, ensure that groups are isolated from one another (with
418  * regard to relocations), and to unload a group, centers around a handle.
419  *
420  * Dependencies can be added to an existing handle as the dependencies are
421  * lazily loaded.  The core dependencies on the handle are the ldd(1) list of
422  * the referenced object.
423  *
424  * Handles can be created from:
425  *
426  *  -	a dlopen() request.  This associates a caller to a reference object,
427  * 	and the referenced objects dependencies.  This group of objects can
428  *	then be inspected for symbols (dlsym()).
429  *  -	a filtering request.  This associates a filter (caller) to a referenced
430  *	object (filtee).  The redirection of filter symbols to their filtee
431  *	counterpart is essentially a dlsym() using the filtee's handle.
432  *
433  * The handle created for these events is referred to as a public handle.  This
434  * handle tracks the referenced object, all of the dependencies of the
435  * referenced object, and the caller (parent).
436  *
437  * Presently, an object may have two handles, one requested with RTLD_FIRST
438  * and one without.
439  *
440  * A handle may be referenced by any number of callers (parents).  A reference
441  * count tracks the number.  A dlclose() operation drops the reference count,
442  * and when the count is zero, the handle is used to determine the family of
443  * objects to unload.  As bindings may occur to objects on the handle from
444  * other handles, it may not be possible to remove a complete family of objects
445  * or the handle itself.  Handles in this state are moved to an orphan list.
446  * A handle on the orphan list is taken off the orphan list if the associated
447  * object is reopened.  Otherwise, the handle remains on the orphan list for
448  * the duration of the process.  The orphan list is inspected any time objects
449  * are unloaded, to determine if the orphaned objects can also be unloaded.
450  *
451  * Handles can also be created for internal uses:
452  *
453  *  -	to promote objects to RTLD_NOW.
454  *  -	to establish families for symbol binding fallback, required when lazy
455  *	loadable objects are still pending.
456  *
457  * The handle created for these events is referred to as a private handle.  This
458  * handle does not need to track the caller (parent), and because of this, does
459  * not need to be considered during dlclose() operations, as the handle can not
460  * be referenced by callers outside of the referenced objects family.
461  *
462  * Note, a private handle is essentially a subset of a public handle.  Should
463  * an internal operation require a private handle, and a public handle already
464  * exist, the public handle can be used.  Should an external operation require
465  * a public handle, and a private handle exist, the private handle is promoted
466  * to a public handle.  Any handle that gets created will remain in existence
467  * for the life time of the referenced object.
468  *
469  * Objects can be dlopened using RTLD_NOW.  This attribute requires that all
470  * relocations of the object, and its dependencies are processed immediately,
471  * before return to the caller.  Typically, an object is loaded without
472  * RTLD_NOW, and procedure linkage relocations are satisfied when their
473  * associated function is first called.  If an object is already loaded, and an
474  * RTLD_NOW request is made, then the object, and its dependencies, most undergo
475  * additional relocation processing.   This promotion from lazy binding to
476  * immediate binding is carried out using handles, as the handle defines the
477  * dependencies that must be processed.
478  *
479  * To ensure that objects within a lazy loadable environment can be relocated,
480  * no matter whether the objects have their dependencies described completely,
481  * a symbol lookup fallback is employed.  Any pending lazy loadable objects are
482  * loaded, and a handle established to search the object and it's dependencies
483  * for the required symbol.
484  *
485  * A group handle (and its associated group descriptors), is referenced from
486  * a link-map's HANDLES and GROUPS lists.  Note, Aplist's are diagramed to
487  * fully expose the allocations required to establish the data structure
488  * relationships.
489  *
490  *                                  Grp_desc
491  *                                   Alist
492  *                                 -----------
493  *                            --> |           |
494  *                           |    |-----------|
495  *                           |    | gd_depend | ---------
496  *                           |    |           |          |
497  *                           |    |-----------|          |
498  *                   --------|--- | gd_depend |          |
499  *                  |        |    | (parent)  |          |
500  *                  |        |    |-----------|          |
501  *                  |        |    | gd_depend |          |
502  *                  |        |    |           |          |
503  *                  |        |    |           |          |
504  *                  |        |     -----------           |
505  *                  |        |                           |
506  *                  |        |      Grp_hdl              |
507  *                  |        |    -----------            |
508  *                  |         -- | gh_depends |          |
509  *                  |  --------- | gh_ownlmp  |          |
510  *                  | |          |            |          |
511  *                  | |          |            |          |
512  *                  | |          |            |          |
513  *      Rt_map      | |           ------------           |       Rt_map
514  *    ----------    | |               ^ ^                |     ----------
515  *   |          | <-  |               | |                 --> |          |
516  *   |          | <---   --------     | |                     |          |
517  *   | HANDLES  | ----> |        |    | |     --------        |          |
518  *   |          |       |        |    | |    |        | <---- |  GROUPS  |
519  *   |          |       |        | ---  |    |        |       |          |
520  *   |          |       |        |       --- |        |       |          |
521  *   |          |        --------            |        |       |          |
522  *    ----------          Aplist              --------         ----------
523  *                                             Aplist
524  */
525 typedef struct {
526 	Alist		*gh_depends;	/* handle dependency list */
527 	Rt_map		*gh_ownlmp;	/* handle owners link-map */
528 	Lm_list		*gh_ownlml;	/* handle owners link-map list */
529 	uint_t		gh_refcnt;	/* handle reference count */
530 	uint_t		gh_flags;	/* handle flags (GPH_ values) */
531 } Grp_hdl;
532 
533 /*
534  * Define the two categories of handle.
535  */
536 #define	GPH_PUBLIC	0x0001		/* handle returned to caller(s) */
537 #define	GPH_PRIVATE	0x0002		/* handle used internally */
538 
539 /*
540  * Define any flags that affects how the handle is used.
541  */
542 #define	GPH_ZERO	0x0010		/* special handle for dlopen(0) */
543 #define	GPH_LDSO	0x0020		/* special handle for ld.so.1 */
544 #define	GPH_FIRST	0x0040		/* dlsym() can only use originating */
545 					/*	dependency */
546 #define	GPH_FILTEE	0x0080		/* handle identifies a filtee, used */
547 					/*	for diagnostics only */
548 /*
549  * Define any state that is associated with the handle.
550  */
551 #define	GPH_INITIAL	0x0100		/* handle is initialized */
552 #define	GPH_NOPENDLAZY	0x0200		/* no pending lazy dependencies */
553 					/*	remain for this handle */
554 /*
555  * Define a Group Descriptor.
556  *
557  * Each dependency associated with a group handle is maintained by a group
558  * descriptor.  The descriptor defines the associated dependency together with
559  * flags that indicate how the dependency can be used.
560  */
561 typedef struct {
562 	Rt_map		*gd_depend;	/* dependency */
563 	uint_t		gd_flags;	/* dependency flags (GPD_ values) */
564 } Grp_desc;
565 
566 #define	GPD_DLSYM	0x0001		/* dependency available to dlsym() */
567 #define	GPD_RELOC	0x0002		/* dependency available to satisfy */
568 					/*	relocation binding */
569 #define	GPD_ADDEPS	0x0004		/* dependencies of this dependency */
570 					/*	should be added to handle */
571 #define	GPD_PARENT	0x0008		/* dependency is a parent */
572 #define	GPD_FILTER	0x0010		/* dependency is our filter */
573 #define	GPD_REMOVE	0x0100		/* descriptor is a candidate for */
574 					/*	removal from the group */
575 #define	GPD_MODECHANGE	0x0200		/* dependency mode has changed, e.g. */
576 					/*	promoted to RTLD_GOBAL */
577 
578 /*
579  * Define threading structures.  For compatibility with libthread (T1_VERSION 1
580  * and TI_VERSION 2) our locking structure is sufficient to hold a mutex or a
581  * readers/writers lock.
582  */
583 typedef struct {
584 	union {
585 		mutex_t		l_mutex;
586 		rwlock_t	l_rwlock;
587 	} u;
588 } Rt_lock;
589 
590 typedef	cond_t	Rt_cond;
591 
592 /*
593  * Define a dynamic section information descriptor.  This parallels the entries
594  * in the .dynamic section and holds auxiliary information to implement lazy
595  * loading and filtee processing.
596  */
597 typedef struct {
598 	uint_t	di_flags;
599 	void	*di_info;
600 } Dyninfo;
601 
602 #define	FLG_DI_STDFLTR	0x00001		/* .dynamic entry for DT_FILTER */
603 #define	FLG_DI_AUXFLTR	0x00002		/* .dynamic entry for DT_AUXILIARY */
604 #define	FLG_DI_SYMFLTR	0x00004		/* .dynamic entry for DT_SYMFILTER */
605 					/*	and DT_SYMAUXILIARY */
606 #define	MSK_DI_FILTER	0x0000f		/* mask for all filter possibilities */
607 
608 #define	FLG_DI_POSFLAG1	0x00010		/* .dynamic entry for DT_POSFLAG_1 */
609 #define	FLG_DI_NEEDED	0x00020		/* .dynamic entry for DT_NEEDED */
610 #define	FLG_DI_LAZY	0x00100		/* lazy needed entry - preceded by */
611 					/*    DF_P1_LAZYLOAD (DT_POSFLAG_1) */
612 #define	FLG_DI_GROUP	0x00200		/* group needed entry - preceded by */
613 					/*    DF_P1_GROUPPERM (DT_POSFLAG_1) */
614 
615 #define	FLG_DI_LDD_DONE	0x01000		/* entry has been processed (ldd) */
616 #define	FLG_DI_LAZYFAIL	0x02000		/* the lazy loading of this entry */
617 					/*    failed */
618 /*
619  * Data structure to track AVL tree of pathnames.  This structure provides the
620  * basis of both the "not-found" node tree, and the "full-path" node tree.  Both
621  * of these trees persist for the life of a process, although the "not-found"
622  * tree may be moved aside during a dlopen() or dlsym() fall back operation.
623  */
624 typedef struct {
625 	const char	*pn_name;	/* path name */
626 	avl_node_t	pn_avl;		/* avl book-keeping (see SGSOFFSETOF) */
627 	uint_t		pn_hash;	/* path name hash value */
628 } PathNode;
629 
630 /*
631  * Data structure to track AVL tree for full path names of objects that are
632  * loaded into memory.
633  */
634 typedef struct {
635 	PathNode	fpn_node;	/* path node */
636 	Rt_map		*fpn_lmp;	/* object link-map */
637 } FullPathNode;
638 
639 /*
640  * A given link-map can hold either a supplier or receiver copy
641  * relocation list, but not both. This union is used to overlap
642  * the space used for the two lists.
643  */
644 typedef union {
645 	Alist	*rtc_r;		/* receiver list (Rel_copy) */
646 	APlist	*rtc_s;		/* supplier list (Rt_map *) */
647 } Rt_map_copy;
648 
649 
650 /*
651  * Link-map definition.
652  */
653 struct rt_map {
654 	/*
655 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
656 	 */
657 	Link_map	rt_public;	/* public data */
658 	const char	*rt_pathname;	/* full pathname of loaded object */
659 	ulong_t		rt_padstart;	/* start of image (including padding) */
660 	ulong_t		rt_padimlen;	/* size of image (including padding */
661 	ulong_t		rt_msize;	/* total memory reservation range */
662 	uint_t		rt_flags;	/* state flags, see FLG below */
663 	uint_t		rt_flags1;	/* state flags1, see FL1 below */
664 	ulong_t		rt_tlsmodid;	/* TLS module id */
665 	/*
666 	 * END: Exposed to rtld_db - don't move, don't delete
667 	 */
668 	APlist		*rt_alias;	/* list of linked file names */
669 	APlist		*rt_fpnode;	/* list of FullpathNode AVL nodes */
670 	char		*rt_runpath;	/* LD_RUN_PATH and its equivalent */
671 	Alist		*rt_runlist;	/*	Pdesc structures */
672 	APlist		*rt_depends;	/* list of dependencies */
673 	APlist		*rt_callers;	/* list of callers */
674 	APlist		*rt_handles;	/* dlopen handles */
675 	APlist		*rt_groups;	/* groups we're a member of */
676 	struct fct	*rt_fct;	/* file class table for this object */
677 	void		*rt_priv;	/* private data, object type specific */
678 	Lm_list		*rt_list;	/* link map list we belong to */
679 	uint_t		rt_objfltrndx;	/* object filtees .dynamic index */
680 	uint_t		rt_symsfltrcnt;	/* number of standard symbol filtees */
681 	uint_t		rt_symafltrcnt;	/* number of auxiliary symbol filtees */
682 	int		rt_mode;	/* usage mode, see RTLD mode flags */
683 	int		rt_sortval;	/* temporary buffer to traverse graph */
684 	uint_t		rt_cycgroup;	/* cyclic group */
685 	dev_t		rt_stdev;	/* device id and inode number for .so */
686 	rtld_ino_t	rt_stino;	/*	multiple inclusion checks */
687 	const char	*rt_origname;	/* original pathname of loaded object */
688 	size_t		rt_dirsz;	/*	and its size */
689 	size_t		rt_lmsize;	/* size of the link-map allocation */
690 	Rt_map_copy	rt_copy;	/* list of copy relocations */
691 	Audit_desc	*rt_auditors;	/* audit descriptor array */
692 	Audit_info	*rt_audinfo;	/* audit information descriptor */
693 	Syminfo		*rt_syminfo;	/* elf .syminfo section - here */
694 					/*	because it is checked in */
695 					/*	common code */
696 	Addr		*rt_initarray;	/* .initarray table */
697 	Addr		*rt_finiarray;	/* .finiarray table */
698 	Addr		*rt_preinitarray; /* .preinitarray table */
699 	mmapobj_result_t *rt_mmaps;	/* array of mapping information */
700 	uint_t		rt_mmapcnt;	/*	and associated number */
701 	uint_t		rt_initarraysz;	/* size of .initarray table */
702 	uint_t		rt_finiarraysz;	/* size of .finiarray table */
703 	uint_t		rt_preinitarraysz; /* size of .preinitarray table */
704 	Dyninfo		*rt_dyninfo;	/* .dynamic information descriptors */
705 	uint_t		rt_dyninfocnt;	/* count of dyninfo entries */
706 	uint_t		rt_relacount;	/* no. of RELATIVE relocations */
707 	uint_t		rt_idx;		/* hold index within linkmap list */
708 	uint_t		rt_lazy;	/* lazy dependencies pending */
709 	Xword		rt_hwcap;	/* hardware capabilities */
710 	Xword		rt_sfcap;	/* software capabilities */
711 	uint_t		rt_cntl;	/* link-map control list we belong to */
712 	uint_t		rt_aflags;	/* auditor flags, see LML_TFLG_AUD_ */
713 					/* address of _init */
714 	void		(*rt_init)(void);
715 					/* address of _fini */
716 	void		(*rt_fini)(void);
717 					/* link map symbol interpreter */
718 	Sym		*(*rt_symintp)(Slookup *, Rt_map **, uint_t *, int *);
719 };
720 
721 #ifdef _SYSCALL32
722 /*
723  * Structure to allow 64-bit rtld_db to read 32-bit processes out of procfs.
724  */
725 typedef union {
726 	uint32_t	rtc_r;
727 	uint32_t	rtc_s;
728 } Rt_map_copy32;
729 
730 typedef struct rt_map32 {
731 	/*
732 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
733 	 */
734 	Link_map32	rt_public;
735 	uint32_t	rt_pathname;
736 	uint32_t	rt_padstart;
737 	uint32_t	rt_padimlen;
738 	uint32_t	rt_msize;
739 	uint32_t	rt_flags;
740 	uint32_t	rt_flags1;
741 	uint32_t	rt_tlsmodid;
742 	/*
743 	 * END: Exposed to rtld_db - don't move, don't delete
744 	 */
745 	uint32_t	rt_alias;
746 	uint32_t	rt_fpnode;
747 	uint32_t	rt_runpath;
748 	uint32_t	rt_runlist;
749 	uint32_t	rt_depends;
750 	uint32_t	rt_callers;
751 	uint32_t	rt_handles;
752 	uint32_t	rt_groups;
753 	uint32_t	rt_fct;
754 	uint32_t	rt_priv;
755 	uint32_t 	rt_list;
756 	uint32_t 	rt_objfltrndx;
757 	uint32_t 	rt_symsfltrcnt;
758 	uint32_t 	rt_symafltrcnt;
759 	int32_t		rt_mode;
760 	int32_t		rt_sortval;
761 	uint32_t	rt_cycgroup;
762 	uint32_t	rt_stdev;
763 	uint32_t	rt_stino;
764 	uint32_t	rt_origname;
765 	uint32_t	rt_dirsz;
766 	Rt_map_copy32	rt_copy;
767 	uint32_t 	rt_auditors;
768 	uint32_t 	rt_audinfo;
769 	uint32_t	rt_syminfo;
770 	uint32_t	rt_initarray;
771 	uint32_t	rt_finiarray;
772 	uint32_t	rt_preinitarray;
773 	uint32_t	rt_mmaps;
774 	uint32_t	rt_mmapcnt;
775 	uint32_t	rt_initarraysz;
776 	uint32_t	rt_finiarraysz;
777 	uint32_t	rt_preinitarraysz;
778 	uint32_t 	rt_dyninfo;
779 	uint32_t 	rt_dyninfocnt;
780 	uint32_t	rt_relacount;
781 	uint32_t	rt_idx;
782 	uint32_t	rt_lazy;
783 	uint32_t	rt_hwcap;
784 	uint32_t	rt_sfcap;
785 	uint32_t	rt_cntl;
786 	uint32_t	rt_aflags;
787 	uint32_t 	rt_init;
788 	uint32_t	rt_fini;
789 	uint32_t	rt_symintp;
790 } Rt_map32;
791 
792 #endif	/* _SYSCALL32 */
793 
794 /*
795  * Link map state flags.
796  */
797 /*
798  * BEGIN: Exposed to rtld_db - don't move, don't delete
799  */
800 #define	FLG_RT_ISMAIN	0x00000001	/* object represents main executable */
801 #define	FLG_RT_IMGALLOC	0x00000002	/* image is allocated (not mmap'ed) */
802 	/*
803 	 * Available for r_debug version >= R_RTLDDB_VERSION5
804 	 */
805 #define	FLG_RT_RELOCED	0x00000004	/* object has been relocated */
806 /*
807  * END: Exposed to rtld_db - don't move, don't delete
808  */
809 #define	FLG_RT_SETGROUP	0x00000008	/* group establishment required */
810 #define	FLG_RT_HWCAP	0x00000010	/* process $HWCAP expansion */
811 #define	FLG_RT_OBJECT	0x00000020	/* object processing (ie. .o's) */
812 #define	FLG_RT_NEWLOAD	0x00000040	/* object is newly loaded */
813 #define	FLG_RT_NODUMP	0x00000080	/* object can't be dldump(3x)'ed */
814 #define	FLG_RT_DELETE	0x00000100	/* object can be deleted */
815 #define	FLG_RT_ANALYZED	0x00000200	/* object has been analyzed */
816 #define	FLG_RT_INITDONE	0x00000400	/* objects .init has been completed */
817 #define	FLG_RT_TRANS	0x00000800	/* object is acting as a translator */
818 #define	FLG_RT_FIXED	0x00001000	/* image location is fixed */
819 #define	FLG_RT_PRELOAD	0x00002000	/* object was preloaded */
820 #define	FLG_RT_ALTER	0x00004000	/* alternative object used */
821 #define	FLG_RT_LOADFLTR	0x00008000	/* trigger filtee loading */
822 #define	FLG_RT_AUDIT	0x00010000	/* object is an auditor */
823 #define	FLG_RT_MODESET	0x00020000	/* MODE() has been initialized */
824 #define	FLG_RT_ANALZING	0x00040000	/* object is being analyzed */
825 #define	FLG_RT_INITFRST 0x00080000	/* execute .init first */
826 #define	FLG_RT_NOOPEN	0x00100000	/* dlopen() not allowed */
827 #define	FLG_RT_FINICLCT	0x00200000	/* fini has been collected (tsort) */
828 #define	FLG_RT_INITCALL	0x00400000	/* objects .init has been called */
829 #define	FLG_RT_OBJINTPO	0x00800000	/* object is a global interposer */
830 #define	FLG_RT_SYMINTPO	0x01000000	/* object contains symbol interposer */
831 #define	MSK_RT_INTPOSE	0x01800000	/* mask for all interposer */
832 					/*	possibilities */
833 #define	FLG_RT_MOVE	0x02000000	/* object needs move operation */
834 #define	FLG_RT_RELOCING	0x04000000	/* object is being relocated */
835 #define	FLG_RT_REGSYMS	0x08000000	/* object has DT_REGISTER entries */
836 #define	FLG_RT_INITCLCT	0x10000000	/* init has been collected (tsort) */
837 #define	FLG_RT_PUBHDL	0x20000000	/* generate a handle for this object */
838 #define	FLG_RT_PRIHDL	0x40000000	/*	either public or private */
839 
840 #define	FL1_RT_COPYTOOK	0x00000001	/* copy relocation taken */
841 
842 #define	FL1_RT_CONFSET	0x00000004	/* object was loaded by crle(1) */
843 #define	FL1_RT_NODEFLIB	0x00000008	/* ignore default library search */
844 #define	FL1_RT_ENDFILTE	0x00000010	/* filtee terminates filters search */
845 #define	FL1_RT_DISPREL	0x00000020	/* object has *disp* relocation */
846 #define	FL1_RT_DTFLAGS	0x00000040	/* DT_FLAGS element exists */
847 
848 #define	FL1_RT_LDDSTUB	0x00000100	/* identify lddstub */
849 #define	FL1_RT_NOINIFIN	0x00000200	/* no .init or .fini exists */
850 #define	FL1_RT_USED	0x00000400	/* symbol referenced from this object */
851 #define	FL1_RT_SYMBOLIC	0x00000800	/* DF_SYMBOLIC was set - use */
852 					/*	symbolic sym resolution */
853 #define	FL1_RT_OBJSFLTR	0x00001000	/* object is acting as a standard */
854 #define	FL1_RT_OBJAFLTR	0x00002000	/*	or auxiliary filter */
855 #define	FL1_RT_SYMSFLTR	0x00004000	/* symbol is acting as a standard */
856 #define	FL1_RT_SYMAFLTR	0x00008000	/*	or auxiliary filter */
857 #define	MSK_RT_FILTER	0x0000f000	/* mask for all filter possibilities */
858 
859 #define	FL1_RT_TLSADD	0x00010000	/* objects TLS has been registered */
860 #define	FL1_RT_TLSSTAT	0x00020000	/* object requires static TLS */
861 #define	FL1_RT_DIRECT	0x00040000	/* object has DIRECT bindings enabled */
862 #define	FL1_RT_GLOBAUD	0x00080000	/* establish global auditing */
863 
864 /*
865  * Flags for the tls_modactivity() routine
866  */
867 #define	TM_FLG_MODADD	0x01		/* call tls_modadd() interface */
868 #define	TM_FLG_MODREM	0x02		/* call tls_modrem() interface */
869 
870 /*
871  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION <= 2).
872  */
873 #define	ADDR(X)		((X)->rt_public.l_addr)
874 #define	NAME(X)		((X)->rt_public.l_name)
875 #define	DYN(X)		((X)->rt_public.l_ld)
876 #define	NEXT(X)		((X)->rt_public.l_next)
877 #define	PREV(X)		((X)->rt_public.l_prev)
878 #define	REFNAME(X)	((X)->rt_public.l_refname)
879 
880 /*
881  * An Rt_map starts with a Link_map, followed by other information.
882  * ld.so.1 allocates Rt_map structures, and then casts them to Link_map,
883  * and back, depending on context.
884  *
885  * On some platforms, Rt_map can have a higher alignment requirement
886  * than Link_map. On such platforms, the cast from Link_map to Rt_map will
887  * draw an E_BAD_PTR_CAST_ALIGN warning from lint. Since we allocate
888  * the memory as the higher alignment Rt_map, we know that this is a safe
889  * conversion. The LINKMAP_TO_RTMAP macro is used to handle the conversion
890  * in a manner that satisfies lint.
891  */
892 #ifdef lint
893 #define	LINKMAP_TO_RTMAP(X)	(Rt_map *)(void *)(X)
894 #else
895 #define	LINKMAP_TO_RTMAP(X)	(Rt_map *)(X)
896 #endif
897 
898 /*
899  * Convenience macros for the common case of using
900  * NEXT()/PREV() and casting the result to (Rt_map *)
901  */
902 #define	NEXT_RT_MAP(X)	LINKMAP_TO_RTMAP(NEXT(X))
903 #define	PREV_RT_MAP(X)	LINKMAP_TO_RTMAP(PREV(X))
904 
905 /*
906  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION3).
907  */
908 #define	PATHNAME(X)	((X)->rt_pathname)
909 #define	PADSTART(X)	((X)->rt_padstart)
910 #define	PADIMLEN(X)	((X)->rt_padimlen)
911 #define	MSIZE(X)	((X)->rt_msize)
912 #define	FLAGS(X)	((X)->rt_flags)
913 #define	FLAGS1(X)	((X)->rt_flags1)
914 
915 /*
916  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION4).
917  */
918 #define	TLSMODID(X)	((X)->rt_tlsmodid)
919 
920 /*
921  * Macros for getting to unexposed, link-map data.
922  */
923 #define	LMSIZE(X)	((X)->rt_lmsize)
924 #define	AFLAGS(X)	((X)->rt_aflags)
925 #define	ALIAS(X)	((X)->rt_alias)
926 #define	FPNODE(X)	((X)->rt_fpnode)
927 #define	INIT(X)		((X)->rt_init)
928 #define	FINI(X)		((X)->rt_fini)
929 #define	RPATH(X)	((X)->rt_runpath)
930 #define	RLIST(X)	((X)->rt_runlist)
931 #define	DEPENDS(X)	((X)->rt_depends)
932 #define	CALLERS(X)	((X)->rt_callers)
933 #define	HANDLES(X)	((X)->rt_handles)
934 #define	GROUPS(X)	((X)->rt_groups)
935 #define	FCT(X)		((X)->rt_fct)
936 #define	SYMINTP(X)	((X)->rt_symintp)
937 #define	LIST(X)		((X)->rt_list)
938 #define	OBJFLTRNDX(X)	((X)->rt_objfltrndx)
939 #define	SYMSFLTRCNT(X)	((X)->rt_symsfltrcnt)
940 #define	SYMAFLTRCNT(X)	((X)->rt_symafltrcnt)
941 #define	MODE(X)		((X)->rt_mode)
942 #define	SORTVAL(X)	((X)->rt_sortval)
943 #define	CYCGROUP(X)	((X)->rt_cycgroup)
944 #define	STDEV(X)	((X)->rt_stdev)
945 #define	STINO(X)	((X)->rt_stino)
946 #define	ORIGNAME(X)	((X)->rt_origname)
947 #define	DIRSZ(X)	((X)->rt_dirsz)
948 #define	COPY_R(X)	((X)->rt_copy.rtc_r)
949 #define	COPY_S(X)	((X)->rt_copy.rtc_s)
950 #define	AUDITORS(X)	((X)->rt_auditors)
951 #define	AUDINFO(X)	((X)->rt_audinfo)
952 #define	SYMINFO(X)	((X)->rt_syminfo)
953 #define	INITARRAY(X)	((X)->rt_initarray)
954 #define	FINIARRAY(X)	((X)->rt_finiarray)
955 #define	PREINITARRAY(X)	((X)->rt_preinitarray)
956 #define	MMAPS(X)	((X)->rt_mmaps)
957 #define	MMAPCNT(X)	((X)->rt_mmapcnt)
958 #define	INITARRAYSZ(X)	((X)->rt_initarraysz)
959 #define	FINIARRAYSZ(X)	((X)->rt_finiarraysz)
960 #define	PREINITARRAYSZ(X) ((X)->rt_preinitarraysz)
961 #define	DYNINFO(X)	((X)->rt_dyninfo)
962 #define	DYNINFOCNT(X)	((X)->rt_dyninfocnt)
963 #define	RELACOUNT(X)	((X)->rt_relacount)
964 #define	IDX(X)		((X)->rt_idx)
965 #define	LAZY(X)		((X)->rt_lazy)
966 #define	CNTL(X)		((X)->rt_cntl)
967 #define	HWCAP(X)	((X)->rt_hwcap)
968 #define	SFCAP(X)	((X)->rt_sfcap)
969 
970 /*
971  * Flags for tsorting.
972  */
973 #define	RT_SORT_FWD	0x01		/* topological sort (.fini) */
974 #define	RT_SORT_REV	0x02		/* reverse topological sort (.init) */
975 #define	RT_SORT_DELETE	0x10		/* process FLG_RT_DELETE objects */
976 					/*	only (called via dlclose()) */
977 #define	RT_SORT_INTPOSE	0x20		/* process interposer objects */
978 
979 /*
980  * Flags for lookup_sym (and hence find_sym) routines.
981  */
982 #define	LKUP_DEFT	0x0000		/* simple lookup request */
983 #define	LKUP_SPEC	0x0001		/* special ELF lookup (allows address */
984 					/*	resolutions to plt[] entries) */
985 #define	LKUP_LDOT	0x0002		/* indicates the original A_OUT */
986 					/*	symbol had a leading `.' */
987 #define	LKUP_FIRST	0x0004		/* lookup symbol in first link map */
988 					/*	only */
989 #define	LKUP_COPY	0x0008		/* lookup symbol for a COPY reloc, do */
990 					/*	not bind to symbol at head */
991 #define	LKUP_STDRELOC	0x0010		/* lookup originates from a standard */
992 					/*	relocation (elf_reloc()) */
993 #define	LKUP_SELF	0x0020		/* lookup symbol in ourself - undef */
994 					/*	is valid */
995 #define	LKUP_WEAK	0x0040		/* relocation reference is weak */
996 #define	LKUP_NEXT	0x0080		/* request originates from RTLD_NEXT */
997 #define	LKUP_NODESCENT	0x0100		/* don't descend through dependencies */
998 #define	LKUP_NOFALLBACK	0x0200		/* don't fall back to loading */
999 					/*	pending lazy dependencies */
1000 #define	LKUP_DIRECT	0x0400		/* direct binding request */
1001 #define	LKUP_SYMNDX	0x0800		/* establish symbol index */
1002 #define	LKUP_SINGLETON	0x1000		/* search for a singleton symbol */
1003 #define	LKUP_STANDARD	0x2000		/* standard lookup - originated from */
1004 					/* 	head link-map element */
1005 #define	LKUP_WORLD	0x4000		/* ensure world lookup */
1006 
1007 /*
1008  * For the runtime linker to perform a symbol search, a number of data items
1009  * related to the search are required.  An Slookup data structure is used to
1010  * convey this data to lookup_sym(), and in special cases, to other core
1011  * routines that provide the implementation details for lookup_sym()
1012  *
1013  * The symbol name (sl_name), the caller (sl_cmap), and the link-map from which
1014  * to start the search (sl_imap) are fundamental to the symbol search.  The
1015  * initial search link-map might get modified by the core routines that provide
1016  * the implementation details for lookup_sym().  This modification accommodates
1017  * requirements such as processing a handle, direct binding and interposition.
1018  * The association between the caller and the potential destination also
1019  * determines whether the destination is a candidate to search.
1020  *
1021  * The lookup identifier (sl_id) is used to identify a runtime linker operation.
1022  * Within this operation, any lazy loads that fail are not re-examined.  This
1023  * technique keeps the overhead of processing a failed lazy load to a minimum.
1024  *
1025  * Symbol searches that originate from a relocation record are accompanied by
1026  * the relocation index (sl_rsymndx), the symbol reference (sl_rsym) and
1027  * possibly the relocation type (sl_rtype).  This data provides for determining
1028  * lazy loading, direct binding, and special symbol processing requirements
1029  * such as copy relocations and singleton lookup.
1030  *
1031  * The symbols hash value is computed by lookup_sym, and propagated throughout
1032  * the search engine.  Note, occasionally the Slookup data is passed to a core
1033  * routine that provides the implementation details for lookup_sym(), ie.
1034  * elf_find_sym(), in which case the caller must initialize the hash value.
1035  *
1036  * The symbols binding information is established by lookup_sym() when the
1037  * symbols relocation type is supplied.  Weak bindings allow relocations to
1038  * be set to zero should a symbol lookup fail.
1039  *
1040  * The flags allow the caller to control aspects of the search, including the
1041  * interpretation of copy relocations, etc.  Note, a number of flag settings
1042  * are established in lookup_sym() from attributes of the symbol reference.
1043  */
1044 struct slookup {
1045 	const char	*sl_name;	/* symbol name */
1046 	Rt_map		*sl_cmap;	/* callers link-map */
1047 	Rt_map		*sl_imap;	/* initial link-map to search */
1048 	ulong_t		sl_id;		/* identifier for this lookup */
1049 	ulong_t		sl_hash;	/* symbol hash value */
1050 	ulong_t		sl_rsymndx;	/* referencing reloc symndx */
1051 	Sym		*sl_rsym;	/* referencing symbol */
1052 	uchar_t		sl_rtype;	/* relocation type associate with */
1053 					/*    symbol */
1054 	uchar_t		sl_bind;	/* symbols binding (returned) */
1055 	uint_t		sl_flags;	/* lookup flags */
1056 };
1057 
1058 #define	SLOOKUP_INIT(sl, name, cmap, imap, id, hash, rsymndx, rsym, rtype, \
1059     flags) \
1060 	(void) (sl.sl_name = (name), sl.sl_cmap = (cmap), sl.sl_imap = (imap), \
1061 	    sl.sl_id = (id), sl.sl_hash = (hash), sl.sl_rsymndx = (rsymndx), \
1062 	    sl.sl_rsym = (rsym), sl.sl_rtype = (rtype), sl.sl_bind = 0, \
1063 	    sl.sl_flags = (flags))
1064 
1065 /*
1066  * Define a number of .plt lookup outcomes, for use in binding diagnostics.
1067  */
1068 typedef	enum {
1069 	PLT_T_NONE = 0,
1070 	PLT_T_21D,
1071 	PLT_T_24D,
1072 	PLT_T_U32,
1073 	PLT_T_U44,
1074 	PLT_T_FULL,
1075 	PLT_T_FAR,
1076 	PLT_T_NUM			/* Must be last */
1077 } Pltbindtype;
1078 
1079 /*
1080  * Prototypes.
1081  */
1082 extern ulong_t		ld_entry_cnt;	/* counter bumped on each entry to */
1083 					/*    ld.so.1. */
1084 extern Lm_list		lml_main;	/* main's link map list */
1085 extern Lm_list		lml_rtld;	/* rtld's link map list */
1086 extern Lm_list		*lml_list[];
1087 
1088 extern Pltbindtype	elf_plt_write(uintptr_t, uintptr_t, void *, uintptr_t,
1089 			    Xword);
1090 extern Rt_map		*is_so_loaded(Lm_list *, const char *, int *);
1091 extern Sym		*lookup_sym(Slookup *, Rt_map **, uint_t *, int *);
1092 extern int		rt_dldump(Rt_map *, const char *, int, Addr);
1093 
1094 #ifdef	__cplusplus
1095 }
1096 #endif
1097 
1098 #endif /* _RTLD_H */
1099