xref: /onnv-gate/usr/src/cmd/sgs/include/rtld.h (revision 9577:dca915fd85d3)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
238598SRod.Evans@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate #ifndef	_RTLD_H
270Sstevel@tonic-gate #define	_RTLD_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
301824Srie  * Global include file for the runtime linker.
310Sstevel@tonic-gate  */
328598SRod.Evans@Sun.COM #include <sys/mman.h>
330Sstevel@tonic-gate #include <time.h>
340Sstevel@tonic-gate #include <sgs.h>
350Sstevel@tonic-gate #include <thread.h>
360Sstevel@tonic-gate #include <synch.h>
376206Sab196087 #include <link.h>
380Sstevel@tonic-gate #include <sys/avl.h>
390Sstevel@tonic-gate #include <alist.h>
401824Srie #include <libc_int.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	_SYSCALL32
430Sstevel@tonic-gate #include <inttypes.h>
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #ifdef	__cplusplus
470Sstevel@tonic-gate extern "C" {
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
518394SAli.Bahrami@Sun.COM  * We use rtld_ino_t instead of ino_t so that we can get
528394SAli.Bahrami@Sun.COM  * access to large inode values from 32-bit code.
538394SAli.Bahrami@Sun.COM  */
548394SAli.Bahrami@Sun.COM #ifdef _LP64
558394SAli.Bahrami@Sun.COM typedef ino_t		rtld_ino_t;
568394SAli.Bahrami@Sun.COM #else
578394SAli.Bahrami@Sun.COM typedef ino64_t		rtld_ino_t;
588394SAli.Bahrami@Sun.COM #endif
598394SAli.Bahrami@Sun.COM 
600Sstevel@tonic-gate typedef struct rt_map	Rt_map;
618598SRod.Evans@Sun.COM typedef struct slookup	Slookup;
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate  * A binding descriptor.  Establishes the binding relationship between two
651618Srie  * objects, the caller (originator) and the dependency (destination).
66*9577SRod.Evans@Sun.COM  *
67*9577SRod.Evans@Sun.COM  * Every relationship between two objects is tracked by a binding descriptor.
68*9577SRod.Evans@Sun.COM  * This descriptor is referenced from a link-map's DEPENDS and CALLERS lists.
69*9577SRod.Evans@Sun.COM  * Note, Aplist's are diagramed to fully expose the allocations required to
70*9577SRod.Evans@Sun.COM  * establish the data structure relationships.
71*9577SRod.Evans@Sun.COM  *
72*9577SRod.Evans@Sun.COM  *                                  Bnd_desc
73*9577SRod.Evans@Sun.COM  *                                 ----------
74*9577SRod.Evans@Sun.COM  *                    ------------| b_caller |
75*9577SRod.Evans@Sun.COM  *                   |            | b_depend | ----------
76*9577SRod.Evans@Sun.COM  *                   |            |          |           |
77*9577SRod.Evans@Sun.COM  *      Rt_map       |             ----------            |       Rt_map
78*9577SRod.Evans@Sun.COM  *    ----------     |                ^ ^                |     ----------
79*9577SRod.Evans@Sun.COM  *   |          | <--                 | |                 --> |          |
80*9577SRod.Evans@Sun.COM  *   |          |        --------     | |                     |          |
81*9577SRod.Evans@Sun.COM  *   | DEPENDS  | ----> |        |    | |     --------        |          |
82*9577SRod.Evans@Sun.COM  *   |          |       |        |    | |    |        | <---- | CALLERS  |
83*9577SRod.Evans@Sun.COM  *   |          |       |        | ---  |    |        |       |          |
84*9577SRod.Evans@Sun.COM  *   |          |       |        |       --- |        |       |          |
85*9577SRod.Evans@Sun.COM  *   |          |        --------            |        |       |          |
86*9577SRod.Evans@Sun.COM  *    ----------          Aplist              --------         ----------
87*9577SRod.Evans@Sun.COM  *                                             Aplist
880Sstevel@tonic-gate  */
890Sstevel@tonic-gate typedef struct {
900Sstevel@tonic-gate 	Rt_map		*b_caller;	/* caller (originator) of a binding */
910Sstevel@tonic-gate 	Rt_map		*b_depend;	/* dependency (destination) of a */
920Sstevel@tonic-gate 					/*	binding */
930Sstevel@tonic-gate 	uint_t		b_flags;	/* relationship of caller to the */
940Sstevel@tonic-gate 					/*	dependency */
950Sstevel@tonic-gate } Bnd_desc;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #define	BND_NEEDED	0x0001		/* caller NEEDED the dependency */
980Sstevel@tonic-gate #define	BND_REFER	0x0002		/* caller relocation references the */
990Sstevel@tonic-gate 					/*	dependency */
100*9577SRod.Evans@Sun.COM #define	BND_FILTER	0x0004		/* binding identifies filter, used */
101*9577SRod.Evans@Sun.COM 					/*	for diagnostics only */
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * Private structure for communication between rtld_db and rtld.
1040Sstevel@tonic-gate  *
1051824Srie  * We must bump the version number when ever an update in one of the
1061824Srie  * structures/fields that rtld_db reads is updated.  This hopefully permits
1071824Srie  * rtld_db implementations of the future to recognize core files produced on
1081824Srie  * older systems and deal with these core files accordingly.
1090Sstevel@tonic-gate  *
1108598SRod.Evans@Sun.COM  * As of version 'R_RTLDDB_VERSION <= 2' the following fields were valid for
1118598SRod.Evans@Sun.COM  * core file examination (basically the public Link_map):
1120Sstevel@tonic-gate  *
1130Sstevel@tonic-gate  *		ADDR()
1140Sstevel@tonic-gate  *		NAME()
1150Sstevel@tonic-gate  *		DYN()
1160Sstevel@tonic-gate  *		NEXT()
1170Sstevel@tonic-gate  *		PREV()
1180Sstevel@tonic-gate  *
1198598SRod.Evans@Sun.COM  * Valid fields for R_RTLDDB_VERSION3
1200Sstevel@tonic-gate  *
1210Sstevel@tonic-gate  *		PATHNAME()
1220Sstevel@tonic-gate  *		PADSTART()
1230Sstevel@tonic-gate  *		PADIMLEN()
1240Sstevel@tonic-gate  *		MSIZE()
1250Sstevel@tonic-gate  *		FLAGS()
1260Sstevel@tonic-gate  *		FLAGS1()
1270Sstevel@tonic-gate  *
1288598SRod.Evans@Sun.COM  * Valid fields for R_RTLDDB_VERSION4
1290Sstevel@tonic-gate  *
1300Sstevel@tonic-gate  *		TLSMODID()
1310Sstevel@tonic-gate  *
1328598SRod.Evans@Sun.COM  * Valid fields for R_RTLDDB_VERSION5
1330Sstevel@tonic-gate  *
1340Sstevel@tonic-gate  *		Added rtld_flags & FLG_RT_RELOCED to stable flags range
1350Sstevel@tonic-gate  *
1360Sstevel@tonic-gate  */
1370Sstevel@tonic-gate #define	R_RTLDDB_VERSION1	1	/* base version level - used for core */
1380Sstevel@tonic-gate 					/*	file examination */
1391824Srie #define	R_RTLDDB_VERSION2	2	/* minor revision - not relevant for */
1400Sstevel@tonic-gate 					/*	core files */
1410Sstevel@tonic-gate #define	R_RTLDDB_VERSION3	3
1420Sstevel@tonic-gate #define	R_RTLDDB_VERSION4	4
1430Sstevel@tonic-gate #define	R_RTLDDB_VERSION5	5
1440Sstevel@tonic-gate #define	R_RTLDDB_VERSION	R_RTLDDB_VERSION5	/* current version */
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate typedef struct rtld_db_priv {
1470Sstevel@tonic-gate 	struct r_debug	rtd_rdebug;	/* original r_debug structure */
1480Sstevel@tonic-gate 	Word		rtd_version;	/* version no. */
1490Sstevel@tonic-gate 	size_t		rtd_objpad;	/* padding around mmap()ed objects */
1509131SRod.Evans@Sun.COM 	APlist		**rtd_dynlmlst;	/* pointer to dynlm_list pointer */
1510Sstevel@tonic-gate } Rtld_db_priv;
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate #ifdef _SYSCALL32
1540Sstevel@tonic-gate typedef struct rtld_db_priv32 {
1550Sstevel@tonic-gate 	struct r_debug32 rtd_rdebug;	/* original r_debug structure */
1560Sstevel@tonic-gate 	Elf32_Word	rtd_version;	/* version no. */
1570Sstevel@tonic-gate 	Elf32_Word	rtd_objpad;	/* padding around mmap()ed objects */
1589131SRod.Evans@Sun.COM 	Elf32_Addr	rtd_dynlmlst;	/* pointer to dynlm_list */
1590Sstevel@tonic-gate } Rtld_db_priv32;
1600Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1610Sstevel@tonic-gate 
1621824Srie /*
1631824Srie  * External function definitions.  ld.so.1 must convey information to libc in
1641824Srie  * regards to threading.  libc also provides routines for atexit() and message
1651824Srie  * localization.  libc provides the necessary interfaces via its RTLDINFO
1661824Srie  * structure and/or later _ld_libc() calls.
1671824Srie  *
1681824Srie  * These external functions are maintained for each link-map list, and used
1691824Srie  * where appropriate.  The functions are associated with the object that
1701824Srie  * provided them, so that should the object be deleted (say, from an alternative
1711824Srie  * link-map), the functions can be removed.
1721824Srie  */
1731824Srie typedef struct {
1741824Srie 	Rt_map	*lc_lmp;			/* function provider */
1751824Srie 	union {
1761824Srie 		int		(*lc_func)();	/* external function pointer */
1771824Srie 		uintptr_t	lc_val;		/* external value */
1781824Srie 		char    	*lc_ptr;	/* external character pointer */
1791824Srie 	} lc_un;
1801824Srie } Lc_desc;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate /*
1830Sstevel@tonic-gate  * Link map list definition.  Link-maps are used to describe each loaded object.
1840Sstevel@tonic-gate  * Lists of these link-maps describe the various namespaces within a process.
1850Sstevel@tonic-gate  * The process executable and its dependencies are maintained on the lml_main
1860Sstevel@tonic-gate  * list.  The runtime linker, and its dependencies are maintained on the
1870Sstevel@tonic-gate  * lml_rtld list.  Additional lists can be created (see dlmopen()) for such
1880Sstevel@tonic-gate  * things as auditors and their dependencies.
1890Sstevel@tonic-gate  *
1900Sstevel@tonic-gate  * Each link-map list maintains an Alist of one, or more, linked lists of
1910Sstevel@tonic-gate  * link-maps.  For backward compatibility, the lm_head/lm_tail elements are
1920Sstevel@tonic-gate  * initialized to the first linked-list of link-maps:
1930Sstevel@tonic-gate  *
1940Sstevel@tonic-gate  *      Lm_list
1950Sstevel@tonic-gate  *    ----------
1960Sstevel@tonic-gate  *   | lm_tail  | ------------------------------------
1970Sstevel@tonic-gate  *   | lm_head  | --------------------                |
1980Sstevel@tonic-gate  *   |          |                     |     Rt_map    |     Rt_map
1990Sstevel@tonic-gate  *   |          |                     |     ------    |     ------
2000Sstevel@tonic-gate  *   |          |          Alist       --> |      |   |--> |      |
2010Sstevel@tonic-gate  *   |          |        ---------    |    |      | --     |      |
2020Sstevel@tonic-gate  *   | lm_lists | ----> |         |   |    |      |    --> |      |
2030Sstevel@tonic-gate  *   |          |       |---------|   |    |      |   |    |      |
2040Sstevel@tonic-gate  *   |          |       | lc_head | --      ------    |     ------
2050Sstevel@tonic-gate  *   |          |       | lc_tail | ------------------
2060Sstevel@tonic-gate  *   |          |       |---------|
207*9577SRod.Evans@Sun.COM  *    ----------        | lc_head |
2080Sstevel@tonic-gate  *                      | lc_tail |
2090Sstevel@tonic-gate  *                      |---------|
2100Sstevel@tonic-gate  *
2110Sstevel@tonic-gate  * Multiple link-map lists exist to support the addition of lazy loaded
2120Sstevel@tonic-gate  * families, filtee families, and dlopen() families.  The intent of these
2130Sstevel@tonic-gate  * lists is to insure that a family of objects that are to be loaded are
2140Sstevel@tonic-gate  * fully relocatable, and hence usable, before they become part of the main
2150Sstevel@tonic-gate  * (al_data[0]) link-map control list.  This main link-map control list is
2160Sstevel@tonic-gate  * the only list in existence when control is transferred to user code.
2170Sstevel@tonic-gate  *
2180Sstevel@tonic-gate  * During process initialization, the dynamic executable and its non-lazy
2190Sstevel@tonic-gate  * dependencies are maintained on al_data[0].  If a new object is loaded, then
2200Sstevel@tonic-gate  * this object is added to the next available control list [1], typically
2210Sstevel@tonic-gate  * al_data[1].  Any dependencies of this object that have not already been
2220Sstevel@tonic-gate  * loaded are added to the same control list.  Once all of the objects on the
2230Sstevel@tonic-gate  * new control list have been successfully relocated, the objects are moved from
2240Sstevel@tonic-gate  * the new control list to the highest control list to which objects of the new
2250Sstevel@tonic-gate  * control list bound to, typically al_data[1] to al_data[0].
2260Sstevel@tonic-gate  *
2270Sstevel@tonic-gate  * Each loading scenario can be broken down as follows:
2280Sstevel@tonic-gate  *
2290Sstevel@tonic-gate  *  setup() - only the initial link-map control list is used:
2300Sstevel@tonic-gate  *   i.	  create al_data[0]
2310Sstevel@tonic-gate  *   ii.  add new link-map for main on al_data[0]
2320Sstevel@tonic-gate  *   iii. analyze al_data[0] to add all non-lazy dependencies
2330Sstevel@tonic-gate  *   iv.  relocate al_data[0] dependencies.
2340Sstevel@tonic-gate  *
2350Sstevel@tonic-gate  *  dlopen() - the initiator can only be the initial link-map control list:
2360Sstevel@tonic-gate  *   i.   create al_data[1] from caller al_data[0]
2370Sstevel@tonic-gate  *   ii.  add new link-map for the dlopen'ed object on al_data[1]
2380Sstevel@tonic-gate  *   iii. analyze al_data[1] to add all non-lazy dependencies
2390Sstevel@tonic-gate  *   iv.  relocate al_data[1] dependencies, and move to al_data[0].
2400Sstevel@tonic-gate  *
2410Sstevel@tonic-gate  *  filtee and lazy loading processing - the initiator can be any link-map
2420Sstevel@tonic-gate  *  control list that is being relocated:
2430Sstevel@tonic-gate  *   i.   create al_data[y] from caller al_data[x]
2440Sstevel@tonic-gate  *   ii.  add new link-map for the new object on al_data[y]
2450Sstevel@tonic-gate  *   iii. analyze al_data[y] to add all non-lazy dependencies
2460Sstevel@tonic-gate  *   iv.  relocate al_data[y] dependencies, and move to al_data[x].
2470Sstevel@tonic-gate  *
2480Sstevel@tonic-gate  * This Alist therefore maintains a stack of link-map control lists.  The newest
2490Sstevel@tonic-gate  * link-map control list can locate symbols within any of the former lists,
2500Sstevel@tonic-gate  * however, control is not passed to a former list until the newest lists
2510Sstevel@tonic-gate  * processing is complete.  Thus, objects can't bind to new objects until they
2520Sstevel@tonic-gate  * have been fully analyzed and relocated.
2530Sstevel@tonic-gate  *
2540Sstevel@tonic-gate  * [1]  Note, additional link-map control list creation occurs after the head
2550Sstevel@tonic-gate  * link-map object (typically the dynamic executable) has been relocated.  This
2560Sstevel@tonic-gate  * staging is required to satisfy the binding requirements of copy relocations.
2570Sstevel@tonic-gate  * Copy relocations, effectively, transfer the bindings of the copied data
2580Sstevel@tonic-gate  * (say _iob in libc.so.1) to the copy location (_iob in the application).
2590Sstevel@tonic-gate  * Thus an object that might bind to the original copy data must be redirected
2600Sstevel@tonic-gate  * to the copy reference.  As the knowledge of a copy relocation having taken
2610Sstevel@tonic-gate  * place is only known after relocating the application, link-map control list
2620Sstevel@tonic-gate  * additions are suspended until after this relocation has completed.
2630Sstevel@tonic-gate  */
2640Sstevel@tonic-gate typedef struct {
2650Sstevel@tonic-gate 	Rt_map		*lc_head;
2660Sstevel@tonic-gate 	Rt_map		*lc_tail;
2675892Sab196087 	APlist		*lc_now;	/* pending promoted bind-now objects */
2680Sstevel@tonic-gate 	uint_t		lc_flags;
2690Sstevel@tonic-gate } Lm_cntl;
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate #define	LMC_FLG_ANALYZING	0x01	/* control list is being analyzed */
2720Sstevel@tonic-gate #define	LMC_FLG_RELOCATING	0x02	/* control list is being relocated */
2730Sstevel@tonic-gate #define	LMC_FLG_REANALYZE	0x04	/* repeat analysis (established when */
2740Sstevel@tonic-gate 					/*	interposers are added */
2750Sstevel@tonic-gate 
2761618Srie struct lm_list {
2770Sstevel@tonic-gate 	/*
2780Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
2790Sstevel@tonic-gate 	 */
2800Sstevel@tonic-gate 	Rt_map		*lm_head;	/* linked list pointers to active */
2810Sstevel@tonic-gate 	Rt_map		*lm_tail;	/*	link-map list */
2825892Sab196087 	APlist		*lm_handle;	/* not used by rtld_db - but spacing */
2830Sstevel@tonic-gate 					/*	is required for flags */
2840Sstevel@tonic-gate 	Word		lm_flags;
2850Sstevel@tonic-gate 	/*
2860Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
2870Sstevel@tonic-gate 	 */
2881824Srie 	Alist		*lm_rti;	/* list of RTLDINFO tables */
2895067Srie 	Audit_list	*lm_alp;	/* audit list descriptor */
2900Sstevel@tonic-gate 	avl_tree_t	*lm_fpavl;	/* avl tree of objects loaded */
2910Sstevel@tonic-gate 	Alist		*lm_lists;	/* active and pending link-map lists */
2926Srie 	char		***lm_environ;	/* pointer to environment array */
2930Sstevel@tonic-gate 	Word		lm_tflags;	/* transferable flags */
2941618Srie 	uint_t		lm_obj;		/* total number of objs on link-map */
2951618Srie 	uint_t		lm_init;	/* new obj since last init processing */
2961618Srie 	uint_t		lm_lazy;	/* obj with pending lazy dependencies */
2971824Srie 	uint_t		lm_tls;		/* new obj that require TLS */
2981618Srie 	uint_t		lm_lmid;	/* unique link-map list identifier, */
2991618Srie 	char		*lm_lmidstr;	/* and associated diagnostic string */
3005892Sab196087 	APlist		*lm_actaudit;	/* list of pending audit activity */
3011824Srie 	Lc_desc		lm_lcs[CI_MAX];	/* external libc functions */
3021618Srie };
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate #ifdef	_SYSCALL32
3051618Srie struct lm_list32 {
3060Sstevel@tonic-gate 	/*
3070Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
3080Sstevel@tonic-gate 	 */
3090Sstevel@tonic-gate 	Elf32_Addr	lm_head;
3100Sstevel@tonic-gate 	Elf32_Addr	lm_tail;
3110Sstevel@tonic-gate 	Elf32_Addr	lm_handle;
3120Sstevel@tonic-gate 	Elf32_Word	lm_flags;
3130Sstevel@tonic-gate 	/*
3140Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
3150Sstevel@tonic-gate 	 */
3161824Srie 	Elf32_Addr	lm_rti;
3170Sstevel@tonic-gate 	Elf32_Addr	lm_fpavl;
3180Sstevel@tonic-gate 	Elf32_Addr	lm_lists;
3196Srie 	Elf32_Addr	lm_environ;
3200Sstevel@tonic-gate 	Elf32_Word	lm_tflags;
3211618Srie 	uint_t		lm_obj;
3221618Srie 	uint_t		lm_init;
3231618Srie 	uint_t		lm_lazy;
3241824Srie 	uint_t		lm_tls;
3251618Srie 	uint_t		lm_lmid;
3261618Srie 	Elf32_Addr	lm_lmidstr;
3274679Srie 	Elf32_Addr	lm_actaudit;
3281824Srie 	Elf32_Addr	lm_lcs[CI_MAX];
3291618Srie };
3300Sstevel@tonic-gate #endif /* _SYSCALL32 */
3310Sstevel@tonic-gate 
3320Sstevel@tonic-gate /*
3330Sstevel@tonic-gate  * Possible Link_map list flags (Lm_list.lm_flags)
3340Sstevel@tonic-gate  */
3350Sstevel@tonic-gate /*
3360Sstevel@tonic-gate  * BEGIN: Exposed to rtld_db - don't move, don't delete
3370Sstevel@tonic-gate  */
3380Sstevel@tonic-gate #define	LML_FLG_BASELM		0x00000001	/* primary link-map */
3390Sstevel@tonic-gate #define	LML_FLG_RTLDLM		0x00000002	/* rtld link-map */
3400Sstevel@tonic-gate /*
3410Sstevel@tonic-gate  * END: Exposed to rtld_db - don't move, don't delete
3420Sstevel@tonic-gate  */
3430Sstevel@tonic-gate #define	LML_FLG_NOAUDIT		0x00000004	/* symbol auditing disabled */
3440Sstevel@tonic-gate #define	LML_FLG_PLTREL		0x00000008	/* deferred plt relocation */
3450Sstevel@tonic-gate 						/* 	initialization */
3460Sstevel@tonic-gate 						/*	(ld.so.1 only) */
3470Sstevel@tonic-gate #define	LML_FLG_HOLDLOCK	0x00000010	/* hold the rtld mutex lock */
3480Sstevel@tonic-gate #define	LML_FLG_ENVIRON		0x00000020	/* environ var initialized */
3490Sstevel@tonic-gate #define	LML_FLG_INTRPOSE	0x00000040	/* interposing objs on list */
3500Sstevel@tonic-gate #define	LML_FLG_LOCAUDIT	0x00000080	/* local auditors exists for */
3510Sstevel@tonic-gate 						/*	this link-map list */
3520Sstevel@tonic-gate #define	LML_FLG_LOADAVAIL	0x00000100	/* load anything available */
3530Sstevel@tonic-gate #define	LML_FLG_IGNRELERR	0x00000200	/* ignore relocation errors - */
3540Sstevel@tonic-gate 						/*	internal for crle(1) */
3550Sstevel@tonic-gate #define	LML_FLG_DBNOTIF		0x00000400	/* binding activity going on */
356280Srie #define	LML_FLG_STARTREL	0x00000800	/* relocation started */
357280Srie #define	LML_FLG_ATEXIT		0x00001000	/* atexit processing */
358280Srie #define	LML_FLG_OBJADDED	0x00002000	/* object(s) added */
359280Srie #define	LML_FLG_OBJDELETED	0x00004000	/* object(s) deleted */
360280Srie #define	LML_FLG_OBJREEVAL	0x00008000	/* existing object(s) needs */
361280Srie 						/*	tsort reevaluation */
3622850Srie #define	LML_FLG_NOPENDGLBLAZY	0x00010000	/* no pending, global, lazy */
3632850Srie 						/*	dependencies remain */
3643817Srie #define	LML_FLG_INTRPOSETSORT	0x00020000	/* interpose tsorting done */
3654679Srie #define	LML_FLG_AUDITNOTIFY	0x00040000	/* audit consistent required */
3665220Srie #define	LML_FLG_GROUPSEXIST	0x00080000	/* local groups exist */
3672850Srie 
3680Sstevel@tonic-gate #define	LML_FLG_TRC_LDDSTUB	0x00100000	/* identify lddstub */
3690Sstevel@tonic-gate #define	LML_FLG_TRC_ENABLE	0x00200000	/* tracing enabled (ldd) */
3700Sstevel@tonic-gate #define	LML_FLG_TRC_WARN	0x00400000	/* print warnings for undefs */
3710Sstevel@tonic-gate #define	LML_FLG_TRC_VERBOSE	0x00800000	/* verbose (versioning) trace */
3720Sstevel@tonic-gate #define	LML_FLG_TRC_SEARCH	0x01000000	/* trace search paths */
3730Sstevel@tonic-gate #define	LML_FLG_TRC_UNREF	0x02000000	/* trace unreferenced */
3740Sstevel@tonic-gate 						/*	dependencies */
3750Sstevel@tonic-gate #define	LML_FLG_TRC_UNUSED	0x04000000	/* trace unused dependencies */
3760Sstevel@tonic-gate #define	LML_FLG_TRC_INIT	0x08000000	/* print .init order */
3774947Srie #define	LML_FLG_TRC_NOUNRESWEAK	0x10000000	/* unresolved weak references */
3784947Srie 						/*	are not allowed */
3796150Srie #define	LML_FLG_TRC_NOPAREXT	0x20000000	/* unresolved PARENT/EXTERN */
3806150Srie 						/*	references are not */
3816150Srie 						/*	allowed */
3820Sstevel@tonic-gate #define	LML_MSK_TRC		0xfff00000	/* tracing mask */
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate /*
3850Sstevel@tonic-gate  * Possible Link_map transferable flags (Lm_list.lm_tflags), i.e., link-map
3860Sstevel@tonic-gate  * list flags that can be propagated to any new link-map list created.
3870Sstevel@tonic-gate  */
3880Sstevel@tonic-gate #define	LML_TFLG_NOLAZYLD	0x00000001	/* lazy loading disabled */
3890Sstevel@tonic-gate #define	LML_TFLG_NODIRECT	0x00000002	/* direct bindings disabled */
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate #define	LML_TFLG_LOADFLTR	0x00000008	/* trigger filtee loading */
3920Sstevel@tonic-gate 
3938598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PREINIT	0x00001000	/* preinit (audit) exists */
3948598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJSEARCH	0x00002000	/* objsearch (audit) exists */
3958598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJOPEN	0x00004000	/* objopen (audit) exists */
3968598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJFILTER	0x00008000	/* objfilter (audit) exists */
3978598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJCLOSE	0x00010000	/* objclose (audit) exists */
3988598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_SYMBIND	0x00020000	/* symbind (audit) exists */
3998598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PLTENTER	0x00040000	/* pltenter (audit) exists */
4008598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PLTEXIT	0x00080000	/* pltexit (audit) exists */
4018598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_ACTIVITY	0x00100000	/* activity (audit) exists */
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate /*
4048598SRod.Evans@Sun.COM  * NOTE: Each auditing module establishes a set of audit flags, AFLAGS(), that
4058598SRod.Evans@Sun.COM  * define the auditing interfaces the module offers.  These auditing flags are
4068598SRod.Evans@Sun.COM  * the LML_TFLG_AUD_ flags defined above.  Global auditors result in setting
4078598SRod.Evans@Sun.COM  * the lm_tflags too.  Local auditors only use the AFLAGS().  All tests for
4088598SRod.Evans@Sun.COM  * auditing inspect the lm_tflags and AFLAGS() for a specific auditing
4098598SRod.Evans@Sun.COM  * interface, and thus use the same flag to test for both types of auditors.
4100Sstevel@tonic-gate  */
4118598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_MASK	0x0ffff000	/* audit interfaces mask */
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate /*
4145067Srie  * Define a Group Handle.
4155067Srie  *
4165067Srie  * The capability of ld.so.1 to associate a group of objects, look for symbols
4175067Srie  * within that group, ensure that groups are isolated from one another (with
418*9577SRod.Evans@Sun.COM  * regard to relocations), and to unload a group, centers around a handle.
419*9577SRod.Evans@Sun.COM  *
420*9577SRod.Evans@Sun.COM  * Dependencies can be added to an existing handle as the dependencies are
421*9577SRod.Evans@Sun.COM  * lazily loaded.  The core dependencies on the handle are the ldd(1) list of
422*9577SRod.Evans@Sun.COM  * the referenced object.
423*9577SRod.Evans@Sun.COM  *
424*9577SRod.Evans@Sun.COM  * Handles can be created from:
4255067Srie  *
426*9577SRod.Evans@Sun.COM  *  -	a dlopen() request.  This associates a caller to a reference object,
427*9577SRod.Evans@Sun.COM  * 	and the referenced objects dependencies.  This group of objects can
428*9577SRod.Evans@Sun.COM  *	then be inspected for symbols (dlsym()).
429*9577SRod.Evans@Sun.COM  *  -	a filtering request.  This associates a filter (caller) to a referenced
430*9577SRod.Evans@Sun.COM  *	object (filtee).  The redirection of filter symbols to their filtee
431*9577SRod.Evans@Sun.COM  *	counterpart is essentially a dlsym() using the filtee's handle.
432*9577SRod.Evans@Sun.COM  *
433*9577SRod.Evans@Sun.COM  * The handle created for these events is referred to as a public handle.  This
434*9577SRod.Evans@Sun.COM  * handle tracks the referenced object, all of the dependencies of the
435*9577SRod.Evans@Sun.COM  * referenced object, and the caller (parent).
4365067Srie  *
4375067Srie  * Presently, an object may have two handles, one requested with RTLD_FIRST
4385067Srie  * and one without.
4395067Srie  *
440*9577SRod.Evans@Sun.COM  * A handle may be referenced by any number of callers (parents).  A reference
4415067Srie  * count tracks the number.  A dlclose() operation drops the reference count,
4425067Srie  * and when the count is zero, the handle is used to determine the family of
4435067Srie  * objects to unload.  As bindings may occur to objects on the handle from
444*9577SRod.Evans@Sun.COM  * other handles, it may not be possible to remove a complete family of objects
445*9577SRod.Evans@Sun.COM  * or the handle itself.  Handles in this state are moved to an orphan list.
446*9577SRod.Evans@Sun.COM  * A handle on the orphan list is taken off the orphan list if the associated
447*9577SRod.Evans@Sun.COM  * object is reopened.  Otherwise, the handle remains on the orphan list for
448*9577SRod.Evans@Sun.COM  * the duration of the process.  The orphan list is inspected any time objects
449*9577SRod.Evans@Sun.COM  * are unloaded, to determine if the orphaned objects can also be unloaded.
450*9577SRod.Evans@Sun.COM  *
451*9577SRod.Evans@Sun.COM  * Handles can also be created for internal uses:
452*9577SRod.Evans@Sun.COM  *
453*9577SRod.Evans@Sun.COM  *  -	to promote objects to RTLD_NOW.
454*9577SRod.Evans@Sun.COM  *  -	to establish families for symbol binding fallback, required when lazy
455*9577SRod.Evans@Sun.COM  *	loadable objects are still pending.
456*9577SRod.Evans@Sun.COM  *
457*9577SRod.Evans@Sun.COM  * The handle created for these events is referred to as a private handle.  This
458*9577SRod.Evans@Sun.COM  * handle does not need to track the caller (parent), and because of this, does
459*9577SRod.Evans@Sun.COM  * not need to be considered during dlclose() operations, as the handle can not
460*9577SRod.Evans@Sun.COM  * be referenced by callers outside of the referenced objects family.
461*9577SRod.Evans@Sun.COM  *
462*9577SRod.Evans@Sun.COM  * Note, a private handle is essentially a subset of a public handle.  Should
463*9577SRod.Evans@Sun.COM  * an internal operation require a private handle, and a public handle already
464*9577SRod.Evans@Sun.COM  * exist, the public handle can be used.  Should an external operation require
465*9577SRod.Evans@Sun.COM  * a public handle, and a private handle exist, the private handle is promoted
466*9577SRod.Evans@Sun.COM  * to a public handle.  Any handle that gets created will remain in existence
467*9577SRod.Evans@Sun.COM  * for the life time of the referenced object.
4685067Srie  *
4695067Srie  * Objects can be dlopened using RTLD_NOW.  This attribute requires that all
4705067Srie  * relocations of the object, and its dependencies are processed immediately,
4715067Srie  * before return to the caller.  Typically, an object is loaded without
4725067Srie  * RTLD_NOW, and procedure linkage relocations are satisfied when their
4735067Srie  * associated function is first called.  If an object is already loaded, and an
4745067Srie  * RTLD_NOW request is made, then the object, and its dependencies, most undergo
4755067Srie  * additional relocation processing.   This promotion from lazy binding to
4765067Srie  * immediate binding is carried out using handles, as the handle defines the
477*9577SRod.Evans@Sun.COM  * dependencies that must be processed.
478*9577SRod.Evans@Sun.COM  *
479*9577SRod.Evans@Sun.COM  * To ensure that objects within a lazy loadable environment can be relocated,
480*9577SRod.Evans@Sun.COM  * no matter whether the objects have their dependencies described completely,
481*9577SRod.Evans@Sun.COM  * a symbol lookup fallback is employed.  Any pending lazy loadable objects are
482*9577SRod.Evans@Sun.COM  * loaded, and a handle established to search the object and it's dependencies
483*9577SRod.Evans@Sun.COM  * for the required symbol.
484*9577SRod.Evans@Sun.COM  *
485*9577SRod.Evans@Sun.COM  * A group handle (and its associated group descriptors), is referenced from
486*9577SRod.Evans@Sun.COM  * a link-map's HANDLES and GROUPS lists.  Note, Aplist's are diagramed to
487*9577SRod.Evans@Sun.COM  * fully expose the allocations required to establish the data structure
488*9577SRod.Evans@Sun.COM  * relationships.
489*9577SRod.Evans@Sun.COM  *
490*9577SRod.Evans@Sun.COM  *                                  Grp_desc
491*9577SRod.Evans@Sun.COM  *                                   Alist
492*9577SRod.Evans@Sun.COM  *                                 -----------
493*9577SRod.Evans@Sun.COM  *                            --> |           |
494*9577SRod.Evans@Sun.COM  *                           |    |-----------|
495*9577SRod.Evans@Sun.COM  *                           |    | gd_depend | ---------
496*9577SRod.Evans@Sun.COM  *                           |    |           |          |
497*9577SRod.Evans@Sun.COM  *                           |    |-----------|          |
498*9577SRod.Evans@Sun.COM  *                   --------|--- | gd_depend |          |
499*9577SRod.Evans@Sun.COM  *                  |        |    | (parent)  |          |
500*9577SRod.Evans@Sun.COM  *                  |        |    |-----------|          |
501*9577SRod.Evans@Sun.COM  *                  |        |    | gd_depend |          |
502*9577SRod.Evans@Sun.COM  *                  |        |    |           |          |
503*9577SRod.Evans@Sun.COM  *                  |        |    |           |          |
504*9577SRod.Evans@Sun.COM  *                  |        |     -----------           |
505*9577SRod.Evans@Sun.COM  *                  |        |                           |
506*9577SRod.Evans@Sun.COM  *                  |        |      Grp_hdl              |
507*9577SRod.Evans@Sun.COM  *                  |        |    -----------            |
508*9577SRod.Evans@Sun.COM  *                  |         -- | gh_depends |          |
509*9577SRod.Evans@Sun.COM  *                  |  --------- | gh_ownlmp  |          |
510*9577SRod.Evans@Sun.COM  *                  | |          |            |          |
511*9577SRod.Evans@Sun.COM  *                  | |          |            |          |
512*9577SRod.Evans@Sun.COM  *                  | |          |            |          |
513*9577SRod.Evans@Sun.COM  *      Rt_map      | |           ------------           |       Rt_map
514*9577SRod.Evans@Sun.COM  *    ----------    | |               ^ ^                |     ----------
515*9577SRod.Evans@Sun.COM  *   |          | <-  |               | |                 --> |          |
516*9577SRod.Evans@Sun.COM  *   |          | <---   --------     | |                     |          |
517*9577SRod.Evans@Sun.COM  *   | HANDLES  | ----> |        |    | |     --------        |          |
518*9577SRod.Evans@Sun.COM  *   |          |       |        |    | |    |        | <---- |  GROUPS  |
519*9577SRod.Evans@Sun.COM  *   |          |       |        | ---  |    |        |       |          |
520*9577SRod.Evans@Sun.COM  *   |          |       |        |       --- |        |       |          |
521*9577SRod.Evans@Sun.COM  *   |          |        --------            |        |       |          |
522*9577SRod.Evans@Sun.COM  *    ----------          Aplist              --------         ----------
523*9577SRod.Evans@Sun.COM  *                                             Aplist
5240Sstevel@tonic-gate  */
5250Sstevel@tonic-gate typedef struct {
5261618Srie 	Alist		*gh_depends;	/* handle dependency list */
5271618Srie 	Rt_map		*gh_ownlmp;	/* handle owners link-map */
5281618Srie 	Lm_list		*gh_ownlml;	/* handle owners link-map list */
5290Sstevel@tonic-gate 	uint_t		gh_refcnt;	/* handle reference count */
5305067Srie 	uint_t		gh_flags;	/* handle flags (GPH_ values) */
5310Sstevel@tonic-gate } Grp_hdl;
5320Sstevel@tonic-gate 
533*9577SRod.Evans@Sun.COM /*
534*9577SRod.Evans@Sun.COM  * Define the two categories of handle.
535*9577SRod.Evans@Sun.COM  */
536*9577SRod.Evans@Sun.COM #define	GPH_PUBLIC	0x0001		/* handle returned to caller(s) */
537*9577SRod.Evans@Sun.COM #define	GPH_PRIVATE	0x0002		/* handle used internally */
538*9577SRod.Evans@Sun.COM 
539*9577SRod.Evans@Sun.COM /*
540*9577SRod.Evans@Sun.COM  * Define any flags that affects how the handle is used.
541*9577SRod.Evans@Sun.COM  */
542*9577SRod.Evans@Sun.COM #define	GPH_ZERO	0x0010		/* special handle for dlopen(0) */
543*9577SRod.Evans@Sun.COM #define	GPH_LDSO	0x0020		/* special handle for ld.so.1 */
544*9577SRod.Evans@Sun.COM #define	GPH_FIRST	0x0040		/* dlsym() can only use originating */
5450Sstevel@tonic-gate 					/*	dependency */
546*9577SRod.Evans@Sun.COM #define	GPH_FILTEE	0x0080		/* handle identifies a filtee, used */
547*9577SRod.Evans@Sun.COM 					/*	for diagnostics only */
548*9577SRod.Evans@Sun.COM /*
549*9577SRod.Evans@Sun.COM  * Define any state that is associated with the handle.
550*9577SRod.Evans@Sun.COM  */
551*9577SRod.Evans@Sun.COM #define	GPH_INITIAL	0x0100		/* handle is initialized */
552*9577SRod.Evans@Sun.COM #define	GPH_NOPENDLAZY	0x0200		/* no pending lazy dependencies */
5532850Srie 					/*	remain for this handle */
5540Sstevel@tonic-gate /*
5555067Srie  * Define a Group Descriptor.
5565067Srie  *
5575067Srie  * Each dependency associated with a group handle is maintained by a group
5585067Srie  * descriptor.  The descriptor defines the associated dependency together with
5595067Srie  * flags that indicate how the dependency can be used.
5600Sstevel@tonic-gate  */
5610Sstevel@tonic-gate typedef struct {
5628598SRod.Evans@Sun.COM 	Rt_map		*gd_depend;	/* dependency */
5635067Srie 	uint_t		gd_flags;	/* dependency flags (GPD_ values) */
5640Sstevel@tonic-gate } Grp_desc;
5650Sstevel@tonic-gate 
5664699Srie #define	GPD_DLSYM	0x0001		/* dependency available to dlsym() */
5674699Srie #define	GPD_RELOC	0x0002		/* dependency available to satisfy */
5684699Srie 					/*	relocation binding */
5694699Srie #define	GPD_ADDEPS	0x0004		/* dependencies of this dependency */
5700Sstevel@tonic-gate 					/*	should be added to handle */
5714699Srie #define	GPD_PARENT	0x0008		/* dependency is a parent */
5724699Srie #define	GPD_FILTER	0x0010		/* dependency is our filter */
573*9577SRod.Evans@Sun.COM #define	GPD_REMOVE	0x0100		/* descriptor is a candidate for */
5740Sstevel@tonic-gate 					/*	removal from the group */
575*9577SRod.Evans@Sun.COM #define	GPD_MODECHANGE	0x0200		/* dependency mode has changed, e.g. */
576*9577SRod.Evans@Sun.COM 					/*	promoted to RTLD_GOBAL */
5770Sstevel@tonic-gate 
5780Sstevel@tonic-gate /*
5790Sstevel@tonic-gate  * Define threading structures.  For compatibility with libthread (T1_VERSION 1
5800Sstevel@tonic-gate  * and TI_VERSION 2) our locking structure is sufficient to hold a mutex or a
5810Sstevel@tonic-gate  * readers/writers lock.
5820Sstevel@tonic-gate  */
5830Sstevel@tonic-gate typedef struct {
5840Sstevel@tonic-gate 	union {
5850Sstevel@tonic-gate 		mutex_t		l_mutex;
5860Sstevel@tonic-gate 		rwlock_t	l_rwlock;
5870Sstevel@tonic-gate 	} u;
5880Sstevel@tonic-gate } Rt_lock;
5890Sstevel@tonic-gate 
5900Sstevel@tonic-gate typedef	cond_t	Rt_cond;
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate /*
5930Sstevel@tonic-gate  * Define a dynamic section information descriptor.  This parallels the entries
5940Sstevel@tonic-gate  * in the .dynamic section and holds auxiliary information to implement lazy
5950Sstevel@tonic-gate  * loading and filtee processing.
5960Sstevel@tonic-gate  */
5970Sstevel@tonic-gate typedef struct {
5980Sstevel@tonic-gate 	uint_t	di_flags;
5990Sstevel@tonic-gate 	void	*di_info;
6000Sstevel@tonic-gate } Dyninfo;
6010Sstevel@tonic-gate 
6020Sstevel@tonic-gate #define	FLG_DI_STDFLTR	0x00001		/* .dynamic entry for DT_FILTER */
6030Sstevel@tonic-gate #define	FLG_DI_AUXFLTR	0x00002		/* .dynamic entry for DT_AUXILIARY */
6040Sstevel@tonic-gate #define	FLG_DI_SYMFLTR	0x00004		/* .dynamic entry for DT_SYMFILTER */
6050Sstevel@tonic-gate 					/*	and DT_SYMAUXILIARY */
6060Sstevel@tonic-gate #define	MSK_DI_FILTER	0x0000f		/* mask for all filter possibilities */
6070Sstevel@tonic-gate 
6085950Srie #define	FLG_DI_POSFLAG1	0x00010		/* .dynamic entry for DT_POSFLAG_1 */
6095950Srie #define	FLG_DI_NEEDED	0x00020		/* .dynamic entry for DT_NEEDED */
6105950Srie #define	FLG_DI_LAZY	0x00100		/* lazy needed entry - preceded by */
6115950Srie 					/*    DF_P1_LAZYLOAD (DT_POSFLAG_1) */
6125950Srie #define	FLG_DI_GROUP	0x00200		/* group needed entry - preceded by */
6135950Srie 					/*    DF_P1_GROUPPERM (DT_POSFLAG_1) */
6140Sstevel@tonic-gate 
6155950Srie #define	FLG_DI_LDD_DONE	0x01000		/* entry has been processed (ldd) */
6165950Srie #define	FLG_DI_LAZYFAIL	0x02000		/* the lazy loading of this entry */
6175950Srie 					/*    failed */
6180Sstevel@tonic-gate /*
6196387Srie  * Data structure to track AVL tree of pathnames.  This structure provides the
6206387Srie  * basis of both the "not-found" node tree, and the "full-path" node tree.  Both
6216387Srie  * of these trees persist for the life of a process, although the "not-found"
6226387Srie  * tree may be moved aside during a dlopen() or dlsym() fall back operation.
6230Sstevel@tonic-gate  */
6240Sstevel@tonic-gate typedef struct {
6256387Srie 	const char	*pn_name;	/* path name */
6266387Srie 	avl_node_t	pn_avl;		/* avl book-keeping (see SGSOFFSETOF) */
6276387Srie 	uint_t		pn_hash;	/* path name hash value */
6286387Srie } PathNode;
6296387Srie 
6306387Srie /*
6316387Srie  * Data structure to track AVL tree for full path names of objects that are
6326387Srie  * loaded into memory.
6336387Srie  */
6346387Srie typedef struct {
6356387Srie 	PathNode	fpn_node;	/* path node */
6360Sstevel@tonic-gate 	Rt_map		*fpn_lmp;	/* object link-map */
6376387Srie } FullPathNode;
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate /*
6405892Sab196087  * A given link-map can hold either a supplier or receiver copy
6415892Sab196087  * relocation list, but not both. This union is used to overlap
6425892Sab196087  * the space used for the two lists.
6435892Sab196087  */
6445892Sab196087 typedef union {
6455892Sab196087 	Alist	*rtc_r;		/* receiver list (Rel_copy) */
6465892Sab196087 	APlist	*rtc_s;		/* supplier list (Rt_map *) */
6475892Sab196087 } Rt_map_copy;
6485892Sab196087 
6495892Sab196087 
6505892Sab196087 /*
6510Sstevel@tonic-gate  * Link-map definition.
6520Sstevel@tonic-gate  */
6530Sstevel@tonic-gate struct rt_map {
6540Sstevel@tonic-gate 	/*
6550Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
6560Sstevel@tonic-gate 	 */
6570Sstevel@tonic-gate 	Link_map	rt_public;	/* public data */
6588598SRod.Evans@Sun.COM 	const char	*rt_pathname;	/* full pathname of loaded object */
6590Sstevel@tonic-gate 	ulong_t		rt_padstart;	/* start of image (including padding) */
6600Sstevel@tonic-gate 	ulong_t		rt_padimlen;	/* size of image (including padding */
6618598SRod.Evans@Sun.COM 	ulong_t		rt_msize;	/* total memory reservation range */
6620Sstevel@tonic-gate 	uint_t		rt_flags;	/* state flags, see FLG below */
6630Sstevel@tonic-gate 	uint_t		rt_flags1;	/* state flags1, see FL1 below */
6640Sstevel@tonic-gate 	ulong_t		rt_tlsmodid;	/* TLS module id */
6650Sstevel@tonic-gate 	/*
6660Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
6670Sstevel@tonic-gate 	 */
6685892Sab196087 	APlist		*rt_alias;	/* list of linked file names */
6695892Sab196087 	APlist		*rt_fpnode;	/* list of FullpathNode AVL nodes */
6700Sstevel@tonic-gate 	char		*rt_runpath;	/* LD_RUN_PATH and its equivalent */
6718598SRod.Evans@Sun.COM 	Alist		*rt_runlist;	/*	Pdesc structures */
6725892Sab196087 	APlist		*rt_depends;	/* list of dependencies */
6735892Sab196087 	APlist		*rt_callers;	/* list of callers */
6745892Sab196087 	APlist		*rt_handles;	/* dlopen handles */
6755892Sab196087 	APlist		*rt_groups;	/* groups we're a member of */
6760Sstevel@tonic-gate 	struct fct	*rt_fct;	/* file class table for this object */
6770Sstevel@tonic-gate 	void		*rt_priv;	/* private data, object type specific */
6780Sstevel@tonic-gate 	Lm_list		*rt_list;	/* link map list we belong to */
6790Sstevel@tonic-gate 	uint_t		rt_objfltrndx;	/* object filtees .dynamic index */
6800Sstevel@tonic-gate 	uint_t		rt_symsfltrcnt;	/* number of standard symbol filtees */
6810Sstevel@tonic-gate 	uint_t		rt_symafltrcnt;	/* number of auxiliary symbol filtees */
6820Sstevel@tonic-gate 	int		rt_mode;	/* usage mode, see RTLD mode flags */
683280Srie 	int		rt_sortval;	/* temporary buffer to traverse graph */
6840Sstevel@tonic-gate 	uint_t		rt_cycgroup;	/* cyclic group */
6850Sstevel@tonic-gate 	dev_t		rt_stdev;	/* device id and inode number for .so */
6868394SAli.Bahrami@Sun.COM 	rtld_ino_t	rt_stino;	/*	multiple inclusion checks */
6878598SRod.Evans@Sun.COM 	const char	*rt_origname;	/* original pathname of loaded object */
6880Sstevel@tonic-gate 	size_t		rt_dirsz;	/*	and its size */
6898598SRod.Evans@Sun.COM 	size_t		rt_lmsize;	/* size of the link-map allocation */
6905892Sab196087 	Rt_map_copy	rt_copy;	/* list of copy relocations */
6910Sstevel@tonic-gate 	Audit_desc	*rt_auditors;	/* audit descriptor array */
6920Sstevel@tonic-gate 	Audit_info	*rt_audinfo;	/* audit information descriptor */
6930Sstevel@tonic-gate 	Syminfo		*rt_syminfo;	/* elf .syminfo section - here */
6940Sstevel@tonic-gate 					/*	because it is checked in */
6950Sstevel@tonic-gate 					/*	common code */
6960Sstevel@tonic-gate 	Addr		*rt_initarray;	/* .initarray table */
6970Sstevel@tonic-gate 	Addr		*rt_finiarray;	/* .finiarray table */
6980Sstevel@tonic-gate 	Addr		*rt_preinitarray; /* .preinitarray table */
6998598SRod.Evans@Sun.COM 	mmapobj_result_t *rt_mmaps;	/* array of mapping information */
7000Sstevel@tonic-gate 	uint_t		rt_mmapcnt;	/*	and associated number */
7010Sstevel@tonic-gate 	uint_t		rt_initarraysz;	/* size of .initarray table */
7020Sstevel@tonic-gate 	uint_t		rt_finiarraysz;	/* size of .finiarray table */
7030Sstevel@tonic-gate 	uint_t		rt_preinitarraysz; /* size of .preinitarray table */
7040Sstevel@tonic-gate 	Dyninfo		*rt_dyninfo;	/* .dynamic information descriptors */
7050Sstevel@tonic-gate 	uint_t		rt_dyninfocnt;	/* count of dyninfo entries */
7060Sstevel@tonic-gate 	uint_t		rt_relacount;	/* no. of RELATIVE relocations */
7070Sstevel@tonic-gate 	uint_t		rt_idx;		/* hold index within linkmap list */
7080Sstevel@tonic-gate 	uint_t		rt_lazy;	/* lazy dependencies pending */
7090Sstevel@tonic-gate 	Xword		rt_hwcap;	/* hardware capabilities */
7100Sstevel@tonic-gate 	Xword		rt_sfcap;	/* software capabilities */
7110Sstevel@tonic-gate 	uint_t		rt_cntl;	/* link-map control list we belong to */
7128598SRod.Evans@Sun.COM 	uint_t		rt_aflags;	/* auditor flags, see LML_TFLG_AUD_ */
7138598SRod.Evans@Sun.COM 					/* address of _init */
7148598SRod.Evans@Sun.COM 	void		(*rt_init)(void);
7158598SRod.Evans@Sun.COM 					/* address of _fini */
7168598SRod.Evans@Sun.COM 	void		(*rt_fini)(void);
7178598SRod.Evans@Sun.COM 					/* link map symbol interpreter */
7188598SRod.Evans@Sun.COM 	Sym		*(*rt_symintp)(Slookup *, Rt_map **, uint_t *, int *);
7190Sstevel@tonic-gate };
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate #ifdef _SYSCALL32
7220Sstevel@tonic-gate /*
7230Sstevel@tonic-gate  * Structure to allow 64-bit rtld_db to read 32-bit processes out of procfs.
7240Sstevel@tonic-gate  */
7255892Sab196087 typedef union {
7265892Sab196087 	uint32_t	rtc_r;
7275892Sab196087 	uint32_t	rtc_s;
7285892Sab196087 } Rt_map_copy32;
7295892Sab196087 
7300Sstevel@tonic-gate typedef struct rt_map32 {
7310Sstevel@tonic-gate 	/*
7320Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
7330Sstevel@tonic-gate 	 */
7340Sstevel@tonic-gate 	Link_map32	rt_public;
7350Sstevel@tonic-gate 	uint32_t	rt_pathname;
7360Sstevel@tonic-gate 	uint32_t	rt_padstart;
7370Sstevel@tonic-gate 	uint32_t	rt_padimlen;
7380Sstevel@tonic-gate 	uint32_t	rt_msize;
7390Sstevel@tonic-gate 	uint32_t	rt_flags;
7400Sstevel@tonic-gate 	uint32_t	rt_flags1;
7410Sstevel@tonic-gate 	uint32_t	rt_tlsmodid;
7420Sstevel@tonic-gate 	/*
7430Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
7440Sstevel@tonic-gate 	 */
7450Sstevel@tonic-gate 	uint32_t	rt_alias;
7460Sstevel@tonic-gate 	uint32_t	rt_fpnode;
7470Sstevel@tonic-gate 	uint32_t	rt_runpath;
7480Sstevel@tonic-gate 	uint32_t	rt_runlist;
7490Sstevel@tonic-gate 	uint32_t	rt_depends;
7500Sstevel@tonic-gate 	uint32_t	rt_callers;
7510Sstevel@tonic-gate 	uint32_t	rt_handles;
7520Sstevel@tonic-gate 	uint32_t	rt_groups;
7530Sstevel@tonic-gate 	uint32_t	rt_fct;
7540Sstevel@tonic-gate 	uint32_t	rt_priv;
7550Sstevel@tonic-gate 	uint32_t 	rt_list;
7560Sstevel@tonic-gate 	uint32_t 	rt_objfltrndx;
7570Sstevel@tonic-gate 	uint32_t 	rt_symsfltrcnt;
7580Sstevel@tonic-gate 	uint32_t 	rt_symafltrcnt;
759280Srie 	int32_t		rt_mode;
760280Srie 	int32_t		rt_sortval;
7610Sstevel@tonic-gate 	uint32_t	rt_cycgroup;
7620Sstevel@tonic-gate 	uint32_t	rt_stdev;
7630Sstevel@tonic-gate 	uint32_t	rt_stino;
7640Sstevel@tonic-gate 	uint32_t	rt_origname;
7650Sstevel@tonic-gate 	uint32_t	rt_dirsz;
7665892Sab196087 	Rt_map_copy32	rt_copy;
7670Sstevel@tonic-gate 	uint32_t 	rt_auditors;
7680Sstevel@tonic-gate 	uint32_t 	rt_audinfo;
7690Sstevel@tonic-gate 	uint32_t	rt_syminfo;
7700Sstevel@tonic-gate 	uint32_t	rt_initarray;
7710Sstevel@tonic-gate 	uint32_t	rt_finiarray;
7720Sstevel@tonic-gate 	uint32_t	rt_preinitarray;
7730Sstevel@tonic-gate 	uint32_t	rt_mmaps;
7740Sstevel@tonic-gate 	uint32_t	rt_mmapcnt;
7750Sstevel@tonic-gate 	uint32_t	rt_initarraysz;
7760Sstevel@tonic-gate 	uint32_t	rt_finiarraysz;
7770Sstevel@tonic-gate 	uint32_t	rt_preinitarraysz;
7780Sstevel@tonic-gate 	uint32_t 	rt_dyninfo;
7790Sstevel@tonic-gate 	uint32_t 	rt_dyninfocnt;
7800Sstevel@tonic-gate 	uint32_t	rt_relacount;
7810Sstevel@tonic-gate 	uint32_t	rt_idx;
7820Sstevel@tonic-gate 	uint32_t	rt_lazy;
7830Sstevel@tonic-gate 	uint32_t	rt_hwcap;
7840Sstevel@tonic-gate 	uint32_t	rt_sfcap;
7850Sstevel@tonic-gate 	uint32_t	rt_cntl;
7868598SRod.Evans@Sun.COM 	uint32_t	rt_aflags;
7878598SRod.Evans@Sun.COM 	uint32_t 	rt_init;
7888598SRod.Evans@Sun.COM 	uint32_t	rt_fini;
7898598SRod.Evans@Sun.COM 	uint32_t	rt_symintp;
7900Sstevel@tonic-gate } Rt_map32;
7910Sstevel@tonic-gate 
7920Sstevel@tonic-gate #endif	/* _SYSCALL32 */
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate /*
7950Sstevel@tonic-gate  * Link map state flags.
7960Sstevel@tonic-gate  */
7970Sstevel@tonic-gate /*
7980Sstevel@tonic-gate  * BEGIN: Exposed to rtld_db - don't move, don't delete
7990Sstevel@tonic-gate  */
8000Sstevel@tonic-gate #define	FLG_RT_ISMAIN	0x00000001	/* object represents main executable */
8010Sstevel@tonic-gate #define	FLG_RT_IMGALLOC	0x00000002	/* image is allocated (not mmap'ed) */
8020Sstevel@tonic-gate 	/*
8038598SRod.Evans@Sun.COM 	 * Available for r_debug version >= R_RTLDDB_VERSION5
8040Sstevel@tonic-gate 	 */
8050Sstevel@tonic-gate #define	FLG_RT_RELOCED	0x00000004	/* object has been relocated */
8060Sstevel@tonic-gate /*
8070Sstevel@tonic-gate  * END: Exposed to rtld_db - don't move, don't delete
8080Sstevel@tonic-gate  */
8090Sstevel@tonic-gate #define	FLG_RT_SETGROUP	0x00000008	/* group establishment required */
8100Sstevel@tonic-gate #define	FLG_RT_HWCAP	0x00000010	/* process $HWCAP expansion */
8110Sstevel@tonic-gate #define	FLG_RT_OBJECT	0x00000020	/* object processing (ie. .o's) */
81264Srie #define	FLG_RT_NEWLOAD	0x00000040	/* object is newly loaded */
8130Sstevel@tonic-gate #define	FLG_RT_NODUMP	0x00000080	/* object can't be dldump(3x)'ed */
8140Sstevel@tonic-gate #define	FLG_RT_DELETE	0x00000100	/* object can be deleted */
8150Sstevel@tonic-gate #define	FLG_RT_ANALYZED	0x00000200	/* object has been analyzed */
8160Sstevel@tonic-gate #define	FLG_RT_INITDONE	0x00000400	/* objects .init has been completed */
8170Sstevel@tonic-gate #define	FLG_RT_TRANS	0x00000800	/* object is acting as a translator */
8180Sstevel@tonic-gate #define	FLG_RT_FIXED	0x00001000	/* image location is fixed */
8190Sstevel@tonic-gate #define	FLG_RT_PRELOAD	0x00002000	/* object was preloaded */
8200Sstevel@tonic-gate #define	FLG_RT_ALTER	0x00004000	/* alternative object used */
8210Sstevel@tonic-gate #define	FLG_RT_LOADFLTR	0x00008000	/* trigger filtee loading */
8220Sstevel@tonic-gate #define	FLG_RT_AUDIT	0x00010000	/* object is an auditor */
8230Sstevel@tonic-gate #define	FLG_RT_MODESET	0x00020000	/* MODE() has been initialized */
8240Sstevel@tonic-gate #define	FLG_RT_ANALZING	0x00040000	/* object is being analyzed */
8250Sstevel@tonic-gate #define	FLG_RT_INITFRST 0x00080000	/* execute .init first */
8260Sstevel@tonic-gate #define	FLG_RT_NOOPEN	0x00100000	/* dlopen() not allowed */
8270Sstevel@tonic-gate #define	FLG_RT_FINICLCT	0x00200000	/* fini has been collected (tsort) */
8280Sstevel@tonic-gate #define	FLG_RT_INITCALL	0x00400000	/* objects .init has been called */
8298159SAli.Bahrami@Sun.COM #define	FLG_RT_OBJINTPO	0x00800000	/* object is a global interposer */
8308159SAli.Bahrami@Sun.COM #define	FLG_RT_SYMINTPO	0x01000000	/* object contains symbol interposer */
8318159SAli.Bahrami@Sun.COM #define	MSK_RT_INTPOSE	0x01800000	/* mask for all interposer */
8323466Srie 					/*	possibilities */
8338159SAli.Bahrami@Sun.COM #define	FLG_RT_MOVE	0x02000000	/* object needs move operation */
834*9577SRod.Evans@Sun.COM #define	FLG_RT_RELOCING	0x04000000	/* object is being relocated */
8358159SAli.Bahrami@Sun.COM #define	FLG_RT_REGSYMS	0x08000000	/* object has DT_REGISTER entries */
8368159SAli.Bahrami@Sun.COM #define	FLG_RT_INITCLCT	0x10000000	/* init has been collected (tsort) */
837*9577SRod.Evans@Sun.COM #define	FLG_RT_PUBHDL	0x20000000	/* generate a handle for this object */
838*9577SRod.Evans@Sun.COM #define	FLG_RT_PRIHDL	0x40000000	/*	either public or private */
8390Sstevel@tonic-gate 
8400Sstevel@tonic-gate #define	FL1_RT_COPYTOOK	0x00000001	/* copy relocation taken */
8418598SRod.Evans@Sun.COM 
8420Sstevel@tonic-gate #define	FL1_RT_CONFSET	0x00000004	/* object was loaded by crle(1) */
8430Sstevel@tonic-gate #define	FL1_RT_NODEFLIB	0x00000008	/* ignore default library search */
8440Sstevel@tonic-gate #define	FL1_RT_ENDFILTE	0x00000010	/* filtee terminates filters search */
8450Sstevel@tonic-gate #define	FL1_RT_DISPREL	0x00000020	/* object has *disp* relocation */
8468598SRod.Evans@Sun.COM #define	FL1_RT_DTFLAGS	0x00000040	/* DT_FLAGS element exists */
8478598SRod.Evans@Sun.COM 
8480Sstevel@tonic-gate #define	FL1_RT_LDDSTUB	0x00000100	/* identify lddstub */
8490Sstevel@tonic-gate #define	FL1_RT_NOINIFIN	0x00000200	/* no .init or .fini exists */
8500Sstevel@tonic-gate #define	FL1_RT_USED	0x00000400	/* symbol referenced from this object */
8510Sstevel@tonic-gate #define	FL1_RT_SYMBOLIC	0x00000800	/* DF_SYMBOLIC was set - use */
8520Sstevel@tonic-gate 					/*	symbolic sym resolution */
8530Sstevel@tonic-gate #define	FL1_RT_OBJSFLTR	0x00001000	/* object is acting as a standard */
8540Sstevel@tonic-gate #define	FL1_RT_OBJAFLTR	0x00002000	/*	or auxiliary filter */
8550Sstevel@tonic-gate #define	FL1_RT_SYMSFLTR	0x00004000	/* symbol is acting as a standard */
8560Sstevel@tonic-gate #define	FL1_RT_SYMAFLTR	0x00008000	/*	or auxiliary filter */
8575067Srie #define	MSK_RT_FILTER	0x0000f000	/* mask for all filter possibilities */
8580Sstevel@tonic-gate 
8591824Srie #define	FL1_RT_TLSADD	0x00010000	/* objects TLS has been registered */
8602145Srie #define	FL1_RT_TLSSTAT	0x00020000	/* object requires static TLS */
8613466Srie #define	FL1_RT_DIRECT	0x00040000	/* object has DIRECT bindings enabled */
8624679Srie #define	FL1_RT_GLOBAUD	0x00080000	/* establish global auditing */
8631824Srie 
8640Sstevel@tonic-gate /*
8650Sstevel@tonic-gate  * Flags for the tls_modactivity() routine
8660Sstevel@tonic-gate  */
8670Sstevel@tonic-gate #define	TM_FLG_MODADD	0x01		/* call tls_modadd() interface */
8680Sstevel@tonic-gate #define	TM_FLG_MODREM	0x02		/* call tls_modrem() interface */
8690Sstevel@tonic-gate 
8700Sstevel@tonic-gate /*
8718598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION <= 2).
8720Sstevel@tonic-gate  */
8730Sstevel@tonic-gate #define	ADDR(X)		((X)->rt_public.l_addr)
8740Sstevel@tonic-gate #define	NAME(X)		((X)->rt_public.l_name)
8750Sstevel@tonic-gate #define	DYN(X)		((X)->rt_public.l_ld)
8760Sstevel@tonic-gate #define	NEXT(X)		((X)->rt_public.l_next)
8770Sstevel@tonic-gate #define	PREV(X)		((X)->rt_public.l_prev)
8780Sstevel@tonic-gate #define	REFNAME(X)	((X)->rt_public.l_refname)
8790Sstevel@tonic-gate 
8800Sstevel@tonic-gate /*
8818394SAli.Bahrami@Sun.COM  * An Rt_map starts with a Link_map, followed by other information.
8828394SAli.Bahrami@Sun.COM  * ld.so.1 allocates Rt_map structures, and then casts them to Link_map,
8838394SAli.Bahrami@Sun.COM  * and back, depending on context.
8848394SAli.Bahrami@Sun.COM  *
8858394SAli.Bahrami@Sun.COM  * On some platforms, Rt_map can have a higher alignment requirement
8868394SAli.Bahrami@Sun.COM  * than Link_map. On such platforms, the cast from Link_map to Rt_map will
8878394SAli.Bahrami@Sun.COM  * draw an E_BAD_PTR_CAST_ALIGN warning from lint. Since we allocate
8888394SAli.Bahrami@Sun.COM  * the memory as the higher alignment Rt_map, we know that this is a safe
8898394SAli.Bahrami@Sun.COM  * conversion. The LINKMAP_TO_RTMAP macro is used to handle the conversion
8908394SAli.Bahrami@Sun.COM  * in a manner that satisfies lint.
8918394SAli.Bahrami@Sun.COM  */
8928394SAli.Bahrami@Sun.COM #ifdef lint
8938394SAli.Bahrami@Sun.COM #define	LINKMAP_TO_RTMAP(X)	(Rt_map *)(void *)(X)
8948394SAli.Bahrami@Sun.COM #else
8958394SAli.Bahrami@Sun.COM #define	LINKMAP_TO_RTMAP(X)	(Rt_map *)(X)
8968394SAli.Bahrami@Sun.COM #endif
8978394SAli.Bahrami@Sun.COM 
8988394SAli.Bahrami@Sun.COM /*
8998394SAli.Bahrami@Sun.COM  * Convenience macros for the common case of using
9008394SAli.Bahrami@Sun.COM  * NEXT()/PREV() and casting the result to (Rt_map *)
9018394SAli.Bahrami@Sun.COM  */
9028394SAli.Bahrami@Sun.COM #define	NEXT_RT_MAP(X)	LINKMAP_TO_RTMAP(NEXT(X))
9038394SAli.Bahrami@Sun.COM #define	PREV_RT_MAP(X)	LINKMAP_TO_RTMAP(PREV(X))
9048394SAli.Bahrami@Sun.COM 
9058394SAli.Bahrami@Sun.COM /*
9068598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION3).
9070Sstevel@tonic-gate  */
9080Sstevel@tonic-gate #define	PATHNAME(X)	((X)->rt_pathname)
9090Sstevel@tonic-gate #define	PADSTART(X)	((X)->rt_padstart)
9100Sstevel@tonic-gate #define	PADIMLEN(X)	((X)->rt_padimlen)
9110Sstevel@tonic-gate #define	MSIZE(X)	((X)->rt_msize)
9120Sstevel@tonic-gate #define	FLAGS(X)	((X)->rt_flags)
9130Sstevel@tonic-gate #define	FLAGS1(X)	((X)->rt_flags1)
9148598SRod.Evans@Sun.COM 
9158598SRod.Evans@Sun.COM /*
9168598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION4).
9178598SRod.Evans@Sun.COM  */
9180Sstevel@tonic-gate #define	TLSMODID(X)	((X)->rt_tlsmodid)
9190Sstevel@tonic-gate 
9208598SRod.Evans@Sun.COM /*
9218598SRod.Evans@Sun.COM  * Macros for getting to unexposed, link-map data.
9228598SRod.Evans@Sun.COM  */
9238598SRod.Evans@Sun.COM #define	LMSIZE(X)	((X)->rt_lmsize)
9248598SRod.Evans@Sun.COM #define	AFLAGS(X)	((X)->rt_aflags)
9250Sstevel@tonic-gate #define	ALIAS(X)	((X)->rt_alias)
9260Sstevel@tonic-gate #define	FPNODE(X)	((X)->rt_fpnode)
9270Sstevel@tonic-gate #define	INIT(X)		((X)->rt_init)
9280Sstevel@tonic-gate #define	FINI(X)		((X)->rt_fini)
9290Sstevel@tonic-gate #define	RPATH(X)	((X)->rt_runpath)
9300Sstevel@tonic-gate #define	RLIST(X)	((X)->rt_runlist)
9310Sstevel@tonic-gate #define	DEPENDS(X)	((X)->rt_depends)
9320Sstevel@tonic-gate #define	CALLERS(X)	((X)->rt_callers)
9330Sstevel@tonic-gate #define	HANDLES(X)	((X)->rt_handles)
9340Sstevel@tonic-gate #define	GROUPS(X)	((X)->rt_groups)
9350Sstevel@tonic-gate #define	FCT(X)		((X)->rt_fct)
9360Sstevel@tonic-gate #define	SYMINTP(X)	((X)->rt_symintp)
9370Sstevel@tonic-gate #define	LIST(X)		((X)->rt_list)
9380Sstevel@tonic-gate #define	OBJFLTRNDX(X)	((X)->rt_objfltrndx)
9390Sstevel@tonic-gate #define	SYMSFLTRCNT(X)	((X)->rt_symsfltrcnt)
9400Sstevel@tonic-gate #define	SYMAFLTRCNT(X)	((X)->rt_symafltrcnt)
9410Sstevel@tonic-gate #define	MODE(X)		((X)->rt_mode)
9420Sstevel@tonic-gate #define	SORTVAL(X)	((X)->rt_sortval)
9430Sstevel@tonic-gate #define	CYCGROUP(X)	((X)->rt_cycgroup)
9440Sstevel@tonic-gate #define	STDEV(X)	((X)->rt_stdev)
9450Sstevel@tonic-gate #define	STINO(X)	((X)->rt_stino)
9460Sstevel@tonic-gate #define	ORIGNAME(X)	((X)->rt_origname)
9470Sstevel@tonic-gate #define	DIRSZ(X)	((X)->rt_dirsz)
9485892Sab196087 #define	COPY_R(X)	((X)->rt_copy.rtc_r)
9495892Sab196087 #define	COPY_S(X)	((X)->rt_copy.rtc_s)
9500Sstevel@tonic-gate #define	AUDITORS(X)	((X)->rt_auditors)
9510Sstevel@tonic-gate #define	AUDINFO(X)	((X)->rt_audinfo)
9520Sstevel@tonic-gate #define	SYMINFO(X)	((X)->rt_syminfo)
9530Sstevel@tonic-gate #define	INITARRAY(X)	((X)->rt_initarray)
9540Sstevel@tonic-gate #define	FINIARRAY(X)	((X)->rt_finiarray)
9550Sstevel@tonic-gate #define	PREINITARRAY(X)	((X)->rt_preinitarray)
9560Sstevel@tonic-gate #define	MMAPS(X)	((X)->rt_mmaps)
9570Sstevel@tonic-gate #define	MMAPCNT(X)	((X)->rt_mmapcnt)
9580Sstevel@tonic-gate #define	INITARRAYSZ(X)	((X)->rt_initarraysz)
9590Sstevel@tonic-gate #define	FINIARRAYSZ(X)	((X)->rt_finiarraysz)
9600Sstevel@tonic-gate #define	PREINITARRAYSZ(X) ((X)->rt_preinitarraysz)
9610Sstevel@tonic-gate #define	DYNINFO(X)	((X)->rt_dyninfo)
9620Sstevel@tonic-gate #define	DYNINFOCNT(X)	((X)->rt_dyninfocnt)
9630Sstevel@tonic-gate #define	RELACOUNT(X)	((X)->rt_relacount)
9640Sstevel@tonic-gate #define	IDX(X)		((X)->rt_idx)
9650Sstevel@tonic-gate #define	LAZY(X)		((X)->rt_lazy)
9660Sstevel@tonic-gate #define	CNTL(X)		((X)->rt_cntl)
9670Sstevel@tonic-gate #define	HWCAP(X)	((X)->rt_hwcap)
9680Sstevel@tonic-gate #define	SFCAP(X)	((X)->rt_sfcap)
9690Sstevel@tonic-gate 
970280Srie /*
971280Srie  * Flags for tsorting.
972280Srie  */
973280Srie #define	RT_SORT_FWD	0x01		/* topological sort (.fini) */
974280Srie #define	RT_SORT_REV	0x02		/* reverse topological sort (.init) */
9758598SRod.Evans@Sun.COM #define	RT_SORT_DELETE	0x10		/* process FLG_RT_DELETE objects */
976280Srie 					/*	only (called via dlclose()) */
9773817Srie #define	RT_SORT_INTPOSE	0x20		/* process interposer objects */
9783817Srie 
9790Sstevel@tonic-gate /*
9800Sstevel@tonic-gate  * Flags for lookup_sym (and hence find_sym) routines.
9810Sstevel@tonic-gate  */
9820Sstevel@tonic-gate #define	LKUP_DEFT	0x0000		/* simple lookup request */
9830Sstevel@tonic-gate #define	LKUP_SPEC	0x0001		/* special ELF lookup (allows address */
9840Sstevel@tonic-gate 					/*	resolutions to plt[] entries) */
9850Sstevel@tonic-gate #define	LKUP_LDOT	0x0002		/* indicates the original A_OUT */
9860Sstevel@tonic-gate 					/*	symbol had a leading `.' */
9870Sstevel@tonic-gate #define	LKUP_FIRST	0x0004		/* lookup symbol in first link map */
9880Sstevel@tonic-gate 					/*	only */
9890Sstevel@tonic-gate #define	LKUP_COPY	0x0008		/* lookup symbol for a COPY reloc, do */
9900Sstevel@tonic-gate 					/*	not bind to symbol at head */
9915220Srie #define	LKUP_STDRELOC	0x0010		/* lookup originates from a standard */
9925220Srie 					/*	relocation (elf_reloc()) */
9930Sstevel@tonic-gate #define	LKUP_SELF	0x0020		/* lookup symbol in ourself - undef */
9940Sstevel@tonic-gate 					/*	is valid */
9950Sstevel@tonic-gate #define	LKUP_WEAK	0x0040		/* relocation reference is weak */
9960Sstevel@tonic-gate #define	LKUP_NEXT	0x0080		/* request originates from RTLD_NEXT */
9970Sstevel@tonic-gate #define	LKUP_NODESCENT	0x0100		/* don't descend through dependencies */
9985950Srie #define	LKUP_NOFALLBACK	0x0200		/* don't fall back to loading */
9990Sstevel@tonic-gate 					/*	pending lazy dependencies */
10000Sstevel@tonic-gate #define	LKUP_DIRECT	0x0400		/* direct binding request */
1001502Srie #define	LKUP_SYMNDX	0x0800		/* establish symbol index */
10025220Srie #define	LKUP_SINGLETON	0x1000		/* search for a singleton symbol */
10035220Srie #define	LKUP_STANDARD	0x2000		/* standard lookup - originated from */
10045220Srie 					/* 	head link-map element */
10058388SRod.Evans@Sun.COM #define	LKUP_WORLD	0x4000		/* ensure world lookup */
10060Sstevel@tonic-gate 
10070Sstevel@tonic-gate /*
10085950Srie  * For the runtime linker to perform a symbol search, a number of data items
10095950Srie  * related to the search are required.  An Slookup data structure is used to
10105950Srie  * convey this data to lookup_sym(), and in special cases, to other core
10115950Srie  * routines that provide the implementation details for lookup_sym()
10125950Srie  *
10135950Srie  * The symbol name (sl_name), the caller (sl_cmap), and the link-map from which
10145950Srie  * to start the search (sl_imap) are fundamental to the symbol search.  The
10155950Srie  * initial search link-map might get modified by the core routines that provide
10165950Srie  * the implementation details for lookup_sym().  This modification accommodates
10175950Srie  * requirements such as processing a handle, direct binding and interposition.
10185950Srie  * The association between the caller and the potential destination also
10195950Srie  * determines whether the destination is a candidate to search.
10205950Srie  *
10215950Srie  * The lookup identifier (sl_id) is used to identify a runtime linker operation.
10225950Srie  * Within this operation, any lazy loads that fail are not re-examined.  This
10235950Srie  * technique keeps the overhead of processing a failed lazy load to a minimum.
10245950Srie  *
10255950Srie  * Symbol searches that originate from a relocation record are accompanied by
10265950Srie  * the relocation index (sl_rsymndx), the symbol reference (sl_rsym) and
10275950Srie  * possibly the relocation type (sl_rtype).  This data provides for determining
10285950Srie  * lazy loading, direct binding, and special symbol processing requirements
10295950Srie  * such as copy relocations and singleton lookup.
10305950Srie  *
10315950Srie  * The symbols hash value is computed by lookup_sym, and propagated throughout
10325950Srie  * the search engine.  Note, occasionally the Slookup data is passed to a core
10335950Srie  * routine that provides the implementation details for lookup_sym(), ie.
10345950Srie  * elf_find_sym(), in which case the caller must initialize the hash value.
10355950Srie  *
10365950Srie  * The symbols binding information is established by lookup_sym() when the
10375950Srie  * symbols relocation type is supplied.  Weak bindings allow relocations to
10385950Srie  * be set to zero should a symbol lookup fail.
10395950Srie  *
10405950Srie  * The flags allow the caller to control aspects of the search, including the
10415950Srie  * interpretation of copy relocations, etc.  Note, a number of flag settings
10425950Srie  * are established in lookup_sym() from attributes of the symbol reference.
10430Sstevel@tonic-gate  */
10448598SRod.Evans@Sun.COM struct slookup {
10450Sstevel@tonic-gate 	const char	*sl_name;	/* symbol name */
10460Sstevel@tonic-gate 	Rt_map		*sl_cmap;	/* callers link-map */
10470Sstevel@tonic-gate 	Rt_map		*sl_imap;	/* initial link-map to search */
10485950Srie 	ulong_t		sl_id;		/* identifier for this lookup */
10490Sstevel@tonic-gate 	ulong_t		sl_hash;	/* symbol hash value */
10500Sstevel@tonic-gate 	ulong_t		sl_rsymndx;	/* referencing reloc symndx */
10515220Srie 	Sym		*sl_rsym;	/* referencing symbol */
10525220Srie 	uchar_t		sl_rtype;	/* relocation type associate with */
10535220Srie 					/*    symbol */
10545220Srie 	uchar_t		sl_bind;	/* symbols binding (returned) */
10550Sstevel@tonic-gate 	uint_t		sl_flags;	/* lookup flags */
10568598SRod.Evans@Sun.COM };
10570Sstevel@tonic-gate 
10585950Srie #define	SLOOKUP_INIT(sl, name, cmap, imap, id, hash, rsymndx, rsym, rtype, \
10595950Srie     flags) \
10605950Srie 	(void) (sl.sl_name = (name), sl.sl_cmap = (cmap), sl.sl_imap = (imap), \
10615950Srie 	    sl.sl_id = (id), sl.sl_hash = (hash), sl.sl_rsymndx = (rsymndx), \
10625950Srie 	    sl.sl_rsym = (rsym), sl.sl_rtype = (rtype), sl.sl_bind = 0, \
10635950Srie 	    sl.sl_flags = (flags))
10640Sstevel@tonic-gate 
10655950Srie /*
10665950Srie  * Define a number of .plt lookup outcomes, for use in binding diagnostics.
10675950Srie  */
10680Sstevel@tonic-gate typedef	enum {
10690Sstevel@tonic-gate 	PLT_T_NONE = 0,
10700Sstevel@tonic-gate 	PLT_T_21D,
10710Sstevel@tonic-gate 	PLT_T_24D,
10720Sstevel@tonic-gate 	PLT_T_U32,
10730Sstevel@tonic-gate 	PLT_T_U44,
10740Sstevel@tonic-gate 	PLT_T_FULL,
10750Sstevel@tonic-gate 	PLT_T_FAR,
10760Sstevel@tonic-gate 	PLT_T_NUM			/* Must be last */
10770Sstevel@tonic-gate } Pltbindtype;
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate /*
10800Sstevel@tonic-gate  * Prototypes.
10810Sstevel@tonic-gate  */
10825950Srie extern ulong_t		ld_entry_cnt;	/* counter bumped on each entry to */
10835950Srie 					/*    ld.so.1. */
10840Sstevel@tonic-gate extern Lm_list		lml_main;	/* main's link map list */
10850Sstevel@tonic-gate extern Lm_list		lml_rtld;	/* rtld's link map list */
10860Sstevel@tonic-gate extern Lm_list		*lml_list[];
10870Sstevel@tonic-gate 
10880Sstevel@tonic-gate extern Pltbindtype	elf_plt_write(uintptr_t, uintptr_t, void *, uintptr_t,
10890Sstevel@tonic-gate 			    Xword);
10906387Srie extern Rt_map		*is_so_loaded(Lm_list *, const char *, int *);
10916387Srie extern Sym		*lookup_sym(Slookup *, Rt_map **, uint_t *, int *);
10920Sstevel@tonic-gate extern int		rt_dldump(Rt_map *, const char *, int, Addr);
10930Sstevel@tonic-gate 
10940Sstevel@tonic-gate #ifdef	__cplusplus
10950Sstevel@tonic-gate }
10960Sstevel@tonic-gate #endif
10970Sstevel@tonic-gate 
10980Sstevel@tonic-gate #endif /* _RTLD_H */
1099