xref: /onnv-gate/usr/src/cmd/sgs/include/rtld.h (revision 9963:d23f520cfd07)
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).
669577SRod.Evans@Sun.COM  *
679577SRod.Evans@Sun.COM  * Every relationship between two objects is tracked by a binding descriptor.
689577SRod.Evans@Sun.COM  * This descriptor is referenced from a link-map's DEPENDS and CALLERS lists.
699577SRod.Evans@Sun.COM  * Note, Aplist's are diagramed to fully expose the allocations required to
709577SRod.Evans@Sun.COM  * establish the data structure relationships.
719577SRod.Evans@Sun.COM  *
729577SRod.Evans@Sun.COM  *                                  Bnd_desc
739577SRod.Evans@Sun.COM  *                                 ----------
749577SRod.Evans@Sun.COM  *                    ------------| b_caller |
759577SRod.Evans@Sun.COM  *                   |            | b_depend | ----------
769577SRod.Evans@Sun.COM  *                   |            |          |           |
779577SRod.Evans@Sun.COM  *      Rt_map       |             ----------            |       Rt_map
789577SRod.Evans@Sun.COM  *    ----------     |                ^ ^                |     ----------
799577SRod.Evans@Sun.COM  *   |          | <--                 | |                 --> |          |
809577SRod.Evans@Sun.COM  *   |          |        --------     | |                     |          |
819577SRod.Evans@Sun.COM  *   | DEPENDS  | ----> |        |    | |     --------        |          |
829577SRod.Evans@Sun.COM  *   |          |       |        |    | |    |        | <---- | CALLERS  |
839577SRod.Evans@Sun.COM  *   |          |       |        | ---  |    |        |       |          |
849577SRod.Evans@Sun.COM  *   |          |       |        |       --- |        |       |          |
859577SRod.Evans@Sun.COM  *   |          |        --------            |        |       |          |
869577SRod.Evans@Sun.COM  *    ----------          Aplist              --------         ----------
879577SRod.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 */
1009577SRod.Evans@Sun.COM #define	BND_FILTER	0x0004		/* binding identifies filter, used */
1019577SRod.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  *   |          |       |---------|
2079577SRod.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 */
296*9963SRod.Evans@Sun.COM 	uint_t		lm_lazy;	/* number of objects with pending */
297*9963SRod.Evans@Sun.COM 					/*	lazy dependencies */
2981824Srie 	uint_t		lm_tls;		/* new obj that require TLS */
2991618Srie 	uint_t		lm_lmid;	/* unique link-map list identifier, */
3001618Srie 	char		*lm_lmidstr;	/* and associated diagnostic string */
3015892Sab196087 	APlist		*lm_actaudit;	/* list of pending audit activity */
3021824Srie 	Lc_desc		lm_lcs[CI_MAX];	/* external libc functions */
3031618Srie };
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate #ifdef	_SYSCALL32
3061618Srie struct lm_list32 {
3070Sstevel@tonic-gate 	/*
3080Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
3090Sstevel@tonic-gate 	 */
3100Sstevel@tonic-gate 	Elf32_Addr	lm_head;
3110Sstevel@tonic-gate 	Elf32_Addr	lm_tail;
3120Sstevel@tonic-gate 	Elf32_Addr	lm_handle;
3130Sstevel@tonic-gate 	Elf32_Word	lm_flags;
3140Sstevel@tonic-gate 	/*
3150Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
3160Sstevel@tonic-gate 	 */
3171824Srie 	Elf32_Addr	lm_rti;
3180Sstevel@tonic-gate 	Elf32_Addr	lm_fpavl;
3190Sstevel@tonic-gate 	Elf32_Addr	lm_lists;
3206Srie 	Elf32_Addr	lm_environ;
3210Sstevel@tonic-gate 	Elf32_Word	lm_tflags;
3221618Srie 	uint_t		lm_obj;
3231618Srie 	uint_t		lm_init;
3241618Srie 	uint_t		lm_lazy;
3251824Srie 	uint_t		lm_tls;
3261618Srie 	uint_t		lm_lmid;
3271618Srie 	Elf32_Addr	lm_lmidstr;
3284679Srie 	Elf32_Addr	lm_actaudit;
3291824Srie 	Elf32_Addr	lm_lcs[CI_MAX];
3301618Srie };
3310Sstevel@tonic-gate #endif /* _SYSCALL32 */
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate /*
3340Sstevel@tonic-gate  * Possible Link_map list flags (Lm_list.lm_flags)
3350Sstevel@tonic-gate  */
3360Sstevel@tonic-gate /*
3370Sstevel@tonic-gate  * BEGIN: Exposed to rtld_db - don't move, don't delete
3380Sstevel@tonic-gate  */
3390Sstevel@tonic-gate #define	LML_FLG_BASELM		0x00000001	/* primary link-map */
3400Sstevel@tonic-gate #define	LML_FLG_RTLDLM		0x00000002	/* rtld link-map */
3410Sstevel@tonic-gate /*
3420Sstevel@tonic-gate  * END: Exposed to rtld_db - don't move, don't delete
3430Sstevel@tonic-gate  */
3440Sstevel@tonic-gate #define	LML_FLG_NOAUDIT		0x00000004	/* symbol auditing disabled */
3450Sstevel@tonic-gate #define	LML_FLG_PLTREL		0x00000008	/* deferred plt relocation */
3460Sstevel@tonic-gate 						/* 	initialization */
3470Sstevel@tonic-gate 						/*	(ld.so.1 only) */
3480Sstevel@tonic-gate #define	LML_FLG_HOLDLOCK	0x00000010	/* hold the rtld mutex lock */
3490Sstevel@tonic-gate #define	LML_FLG_ENVIRON		0x00000020	/* environ var initialized */
3500Sstevel@tonic-gate #define	LML_FLG_INTRPOSE	0x00000040	/* interposing objs on list */
3510Sstevel@tonic-gate #define	LML_FLG_LOCAUDIT	0x00000080	/* local auditors exists for */
3520Sstevel@tonic-gate 						/*	this link-map list */
3530Sstevel@tonic-gate #define	LML_FLG_LOADAVAIL	0x00000100	/* load anything available */
3540Sstevel@tonic-gate #define	LML_FLG_IGNRELERR	0x00000200	/* ignore relocation errors - */
3550Sstevel@tonic-gate 						/*	internal for crle(1) */
3560Sstevel@tonic-gate #define	LML_FLG_DBNOTIF		0x00000400	/* binding activity going on */
357280Srie #define	LML_FLG_STARTREL	0x00000800	/* relocation started */
358280Srie #define	LML_FLG_ATEXIT		0x00001000	/* atexit processing */
359280Srie #define	LML_FLG_OBJADDED	0x00002000	/* object(s) added */
360280Srie #define	LML_FLG_OBJDELETED	0x00004000	/* object(s) deleted */
361280Srie #define	LML_FLG_OBJREEVAL	0x00008000	/* existing object(s) needs */
362280Srie 						/*	tsort reevaluation */
3633817Srie #define	LML_FLG_INTRPOSETSORT	0x00020000	/* interpose tsorting done */
3644679Srie #define	LML_FLG_AUDITNOTIFY	0x00040000	/* audit consistent required */
3655220Srie #define	LML_FLG_GROUPSEXIST	0x00080000	/* local groups exist */
3662850Srie 
3670Sstevel@tonic-gate #define	LML_FLG_TRC_LDDSTUB	0x00100000	/* identify lddstub */
3680Sstevel@tonic-gate #define	LML_FLG_TRC_ENABLE	0x00200000	/* tracing enabled (ldd) */
3690Sstevel@tonic-gate #define	LML_FLG_TRC_WARN	0x00400000	/* print warnings for undefs */
3700Sstevel@tonic-gate #define	LML_FLG_TRC_VERBOSE	0x00800000	/* verbose (versioning) trace */
3710Sstevel@tonic-gate #define	LML_FLG_TRC_SEARCH	0x01000000	/* trace search paths */
3720Sstevel@tonic-gate #define	LML_FLG_TRC_UNREF	0x02000000	/* trace unreferenced */
3730Sstevel@tonic-gate 						/*	dependencies */
3740Sstevel@tonic-gate #define	LML_FLG_TRC_UNUSED	0x04000000	/* trace unused dependencies */
3750Sstevel@tonic-gate #define	LML_FLG_TRC_INIT	0x08000000	/* print .init order */
3764947Srie #define	LML_FLG_TRC_NOUNRESWEAK	0x10000000	/* unresolved weak references */
3774947Srie 						/*	are not allowed */
3786150Srie #define	LML_FLG_TRC_NOPAREXT	0x20000000	/* unresolved PARENT/EXTERN */
3796150Srie 						/*	references are not */
3806150Srie 						/*	allowed */
3810Sstevel@tonic-gate #define	LML_MSK_TRC		0xfff00000	/* tracing mask */
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate /*
3840Sstevel@tonic-gate  * Possible Link_map transferable flags (Lm_list.lm_tflags), i.e., link-map
3850Sstevel@tonic-gate  * list flags that can be propagated to any new link-map list created.
3860Sstevel@tonic-gate  */
3870Sstevel@tonic-gate #define	LML_TFLG_NOLAZYLD	0x00000001	/* lazy loading disabled */
3880Sstevel@tonic-gate #define	LML_TFLG_NODIRECT	0x00000002	/* direct bindings disabled */
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate #define	LML_TFLG_LOADFLTR	0x00000008	/* trigger filtee loading */
3910Sstevel@tonic-gate 
3928598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PREINIT	0x00001000	/* preinit (audit) exists */
3938598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJSEARCH	0x00002000	/* objsearch (audit) exists */
3948598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJOPEN	0x00004000	/* objopen (audit) exists */
3958598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJFILTER	0x00008000	/* objfilter (audit) exists */
3968598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJCLOSE	0x00010000	/* objclose (audit) exists */
3978598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_SYMBIND	0x00020000	/* symbind (audit) exists */
3988598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PLTENTER	0x00040000	/* pltenter (audit) exists */
3998598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PLTEXIT	0x00080000	/* pltexit (audit) exists */
4008598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_ACTIVITY	0x00100000	/* activity (audit) exists */
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate /*
4038598SRod.Evans@Sun.COM  * NOTE: Each auditing module establishes a set of audit flags, AFLAGS(), that
4048598SRod.Evans@Sun.COM  * define the auditing interfaces the module offers.  These auditing flags are
4058598SRod.Evans@Sun.COM  * the LML_TFLG_AUD_ flags defined above.  Global auditors result in setting
4068598SRod.Evans@Sun.COM  * the lm_tflags too.  Local auditors only use the AFLAGS().  All tests for
4078598SRod.Evans@Sun.COM  * auditing inspect the lm_tflags and AFLAGS() for a specific auditing
4088598SRod.Evans@Sun.COM  * interface, and thus use the same flag to test for both types of auditors.
4090Sstevel@tonic-gate  */
4108598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_MASK	0x0ffff000	/* audit interfaces mask */
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate /*
4135067Srie  * Define a Group Handle.
4145067Srie  *
4155067Srie  * The capability of ld.so.1 to associate a group of objects, look for symbols
4165067Srie  * within that group, ensure that groups are isolated from one another (with
4179577SRod.Evans@Sun.COM  * regard to relocations), and to unload a group, centers around a handle.
4189577SRod.Evans@Sun.COM  *
4199577SRod.Evans@Sun.COM  * Dependencies can be added to an existing handle as the dependencies are
4209577SRod.Evans@Sun.COM  * lazily loaded.  The core dependencies on the handle are the ldd(1) list of
4219577SRod.Evans@Sun.COM  * the referenced object.
4229577SRod.Evans@Sun.COM  *
4239577SRod.Evans@Sun.COM  * Handles can be created from:
4245067Srie  *
4259577SRod.Evans@Sun.COM  *  -	a dlopen() request.  This associates a caller to a reference object,
4269577SRod.Evans@Sun.COM  * 	and the referenced objects dependencies.  This group of objects can
4279577SRod.Evans@Sun.COM  *	then be inspected for symbols (dlsym()).
4289577SRod.Evans@Sun.COM  *  -	a filtering request.  This associates a filter (caller) to a referenced
4299577SRod.Evans@Sun.COM  *	object (filtee).  The redirection of filter symbols to their filtee
4309577SRod.Evans@Sun.COM  *	counterpart is essentially a dlsym() using the filtee's handle.
4319577SRod.Evans@Sun.COM  *
4329577SRod.Evans@Sun.COM  * The handle created for these events is referred to as a public handle.  This
4339577SRod.Evans@Sun.COM  * handle tracks the referenced object, all of the dependencies of the
4349577SRod.Evans@Sun.COM  * referenced object, and the caller (parent).
4355067Srie  *
4365067Srie  * Presently, an object may have two handles, one requested with RTLD_FIRST
4375067Srie  * and one without.
4385067Srie  *
4399577SRod.Evans@Sun.COM  * A handle may be referenced by any number of callers (parents).  A reference
4405067Srie  * count tracks the number.  A dlclose() operation drops the reference count,
4415067Srie  * and when the count is zero, the handle is used to determine the family of
4425067Srie  * objects to unload.  As bindings may occur to objects on the handle from
4439577SRod.Evans@Sun.COM  * other handles, it may not be possible to remove a complete family of objects
4449577SRod.Evans@Sun.COM  * or the handle itself.  Handles in this state are moved to an orphan list.
4459577SRod.Evans@Sun.COM  * A handle on the orphan list is taken off the orphan list if the associated
4469577SRod.Evans@Sun.COM  * object is reopened.  Otherwise, the handle remains on the orphan list for
4479577SRod.Evans@Sun.COM  * the duration of the process.  The orphan list is inspected any time objects
4489577SRod.Evans@Sun.COM  * are unloaded, to determine if the orphaned objects can also be unloaded.
4499577SRod.Evans@Sun.COM  *
4509577SRod.Evans@Sun.COM  * Handles can also be created for internal uses:
4519577SRod.Evans@Sun.COM  *
4529577SRod.Evans@Sun.COM  *  -	to promote objects to RTLD_NOW.
4539577SRod.Evans@Sun.COM  *  -	to establish families for symbol binding fallback, required when lazy
4549577SRod.Evans@Sun.COM  *	loadable objects are still pending.
4559577SRod.Evans@Sun.COM  *
4569577SRod.Evans@Sun.COM  * The handle created for these events is referred to as a private handle.  This
4579577SRod.Evans@Sun.COM  * handle does not need to track the caller (parent), and because of this, does
4589577SRod.Evans@Sun.COM  * not need to be considered during dlclose() operations, as the handle can not
4599577SRod.Evans@Sun.COM  * be referenced by callers outside of the referenced objects family.
4609577SRod.Evans@Sun.COM  *
4619577SRod.Evans@Sun.COM  * Note, a private handle is essentially a subset of a public handle.  Should
4629577SRod.Evans@Sun.COM  * an internal operation require a private handle, and a public handle already
4639577SRod.Evans@Sun.COM  * exist, the public handle can be used.  Should an external operation require
4649577SRod.Evans@Sun.COM  * a public handle, and a private handle exist, the private handle is promoted
4659577SRod.Evans@Sun.COM  * to a public handle.  Any handle that gets created will remain in existence
4669577SRod.Evans@Sun.COM  * for the life time of the referenced object.
4675067Srie  *
4685067Srie  * Objects can be dlopened using RTLD_NOW.  This attribute requires that all
4695067Srie  * relocations of the object, and its dependencies are processed immediately,
4705067Srie  * before return to the caller.  Typically, an object is loaded without
4715067Srie  * RTLD_NOW, and procedure linkage relocations are satisfied when their
4725067Srie  * associated function is first called.  If an object is already loaded, and an
4735067Srie  * RTLD_NOW request is made, then the object, and its dependencies, most undergo
4745067Srie  * additional relocation processing.   This promotion from lazy binding to
4755067Srie  * immediate binding is carried out using handles, as the handle defines the
4769577SRod.Evans@Sun.COM  * dependencies that must be processed.
4779577SRod.Evans@Sun.COM  *
4789577SRod.Evans@Sun.COM  * To ensure that objects within a lazy loadable environment can be relocated,
4799577SRod.Evans@Sun.COM  * no matter whether the objects have their dependencies described completely,
4809577SRod.Evans@Sun.COM  * a symbol lookup fallback is employed.  Any pending lazy loadable objects are
4819577SRod.Evans@Sun.COM  * loaded, and a handle established to search the object and it's dependencies
4829577SRod.Evans@Sun.COM  * for the required symbol.
4839577SRod.Evans@Sun.COM  *
4849577SRod.Evans@Sun.COM  * A group handle (and its associated group descriptors), is referenced from
4859577SRod.Evans@Sun.COM  * a link-map's HANDLES and GROUPS lists.  Note, Aplist's are diagramed to
4869577SRod.Evans@Sun.COM  * fully expose the allocations required to establish the data structure
4879577SRod.Evans@Sun.COM  * relationships.
4889577SRod.Evans@Sun.COM  *
4899577SRod.Evans@Sun.COM  *                                  Grp_desc
4909577SRod.Evans@Sun.COM  *                                   Alist
4919577SRod.Evans@Sun.COM  *                                 -----------
4929577SRod.Evans@Sun.COM  *                            --> |           |
4939577SRod.Evans@Sun.COM  *                           |    |-----------|
4949577SRod.Evans@Sun.COM  *                           |    | gd_depend | ---------
4959577SRod.Evans@Sun.COM  *                           |    |           |          |
4969577SRod.Evans@Sun.COM  *                           |    |-----------|          |
4979577SRod.Evans@Sun.COM  *                   --------|--- | gd_depend |          |
4989577SRod.Evans@Sun.COM  *                  |        |    | (parent)  |          |
4999577SRod.Evans@Sun.COM  *                  |        |    |-----------|          |
5009577SRod.Evans@Sun.COM  *                  |        |    | gd_depend |          |
5019577SRod.Evans@Sun.COM  *                  |        |    |           |          |
5029577SRod.Evans@Sun.COM  *                  |        |    |           |          |
5039577SRod.Evans@Sun.COM  *                  |        |     -----------           |
5049577SRod.Evans@Sun.COM  *                  |        |                           |
5059577SRod.Evans@Sun.COM  *                  |        |      Grp_hdl              |
5069577SRod.Evans@Sun.COM  *                  |        |    -----------            |
5079577SRod.Evans@Sun.COM  *                  |         -- | gh_depends |          |
5089577SRod.Evans@Sun.COM  *                  |  --------- | gh_ownlmp  |          |
5099577SRod.Evans@Sun.COM  *                  | |          |            |          |
5109577SRod.Evans@Sun.COM  *                  | |          |            |          |
5119577SRod.Evans@Sun.COM  *                  | |          |            |          |
5129577SRod.Evans@Sun.COM  *      Rt_map      | |           ------------           |       Rt_map
5139577SRod.Evans@Sun.COM  *    ----------    | |               ^ ^                |     ----------
5149577SRod.Evans@Sun.COM  *   |          | <-  |               | |                 --> |          |
5159577SRod.Evans@Sun.COM  *   |          | <---   --------     | |                     |          |
5169577SRod.Evans@Sun.COM  *   | HANDLES  | ----> |        |    | |     --------        |          |
5179577SRod.Evans@Sun.COM  *   |          |       |        |    | |    |        | <---- |  GROUPS  |
5189577SRod.Evans@Sun.COM  *   |          |       |        | ---  |    |        |       |          |
5199577SRod.Evans@Sun.COM  *   |          |       |        |       --- |        |       |          |
5209577SRod.Evans@Sun.COM  *   |          |        --------            |        |       |          |
5219577SRod.Evans@Sun.COM  *    ----------          Aplist              --------         ----------
5229577SRod.Evans@Sun.COM  *                                             Aplist
5230Sstevel@tonic-gate  */
5240Sstevel@tonic-gate typedef struct {
5251618Srie 	Alist		*gh_depends;	/* handle dependency list */
5261618Srie 	Rt_map		*gh_ownlmp;	/* handle owners link-map */
5271618Srie 	Lm_list		*gh_ownlml;	/* handle owners link-map list */
5280Sstevel@tonic-gate 	uint_t		gh_refcnt;	/* handle reference count */
5295067Srie 	uint_t		gh_flags;	/* handle flags (GPH_ values) */
5300Sstevel@tonic-gate } Grp_hdl;
5310Sstevel@tonic-gate 
5329577SRod.Evans@Sun.COM /*
5339577SRod.Evans@Sun.COM  * Define the two categories of handle.
5349577SRod.Evans@Sun.COM  */
5359577SRod.Evans@Sun.COM #define	GPH_PUBLIC	0x0001		/* handle returned to caller(s) */
5369577SRod.Evans@Sun.COM #define	GPH_PRIVATE	0x0002		/* handle used internally */
5379577SRod.Evans@Sun.COM 
5389577SRod.Evans@Sun.COM /*
5399577SRod.Evans@Sun.COM  * Define any flags that affects how the handle is used.
5409577SRod.Evans@Sun.COM  */
5419577SRod.Evans@Sun.COM #define	GPH_ZERO	0x0010		/* special handle for dlopen(0) */
5429577SRod.Evans@Sun.COM #define	GPH_LDSO	0x0020		/* special handle for ld.so.1 */
5439577SRod.Evans@Sun.COM #define	GPH_FIRST	0x0040		/* dlsym() can only use originating */
5440Sstevel@tonic-gate 					/*	dependency */
5459577SRod.Evans@Sun.COM #define	GPH_FILTEE	0x0080		/* handle identifies a filtee, used */
5469577SRod.Evans@Sun.COM 					/*	for diagnostics only */
5479577SRod.Evans@Sun.COM /*
5489577SRod.Evans@Sun.COM  * Define any state that is associated with the handle.
5499577SRod.Evans@Sun.COM  */
5509577SRod.Evans@Sun.COM #define	GPH_INITIAL	0x0100		/* handle is initialized */
551*9963SRod.Evans@Sun.COM 
5520Sstevel@tonic-gate /*
5535067Srie  * Define a Group Descriptor.
5545067Srie  *
5555067Srie  * Each dependency associated with a group handle is maintained by a group
5565067Srie  * descriptor.  The descriptor defines the associated dependency together with
5575067Srie  * flags that indicate how the dependency can be used.
5580Sstevel@tonic-gate  */
5590Sstevel@tonic-gate typedef struct {
5608598SRod.Evans@Sun.COM 	Rt_map		*gd_depend;	/* dependency */
5615067Srie 	uint_t		gd_flags;	/* dependency flags (GPD_ values) */
5620Sstevel@tonic-gate } Grp_desc;
5630Sstevel@tonic-gate 
5644699Srie #define	GPD_DLSYM	0x0001		/* dependency available to dlsym() */
5654699Srie #define	GPD_RELOC	0x0002		/* dependency available to satisfy */
5664699Srie 					/*	relocation binding */
5674699Srie #define	GPD_ADDEPS	0x0004		/* dependencies of this dependency */
5680Sstevel@tonic-gate 					/*	should be added to handle */
5694699Srie #define	GPD_PARENT	0x0008		/* dependency is a parent */
5704699Srie #define	GPD_FILTER	0x0010		/* dependency is our filter */
5719577SRod.Evans@Sun.COM #define	GPD_REMOVE	0x0100		/* descriptor is a candidate for */
5720Sstevel@tonic-gate 					/*	removal from the group */
5730Sstevel@tonic-gate 
5740Sstevel@tonic-gate /*
5750Sstevel@tonic-gate  * Define threading structures.  For compatibility with libthread (T1_VERSION 1
5760Sstevel@tonic-gate  * and TI_VERSION 2) our locking structure is sufficient to hold a mutex or a
5770Sstevel@tonic-gate  * readers/writers lock.
5780Sstevel@tonic-gate  */
5790Sstevel@tonic-gate typedef struct {
5800Sstevel@tonic-gate 	union {
5810Sstevel@tonic-gate 		mutex_t		l_mutex;
5820Sstevel@tonic-gate 		rwlock_t	l_rwlock;
5830Sstevel@tonic-gate 	} u;
5840Sstevel@tonic-gate } Rt_lock;
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate typedef	cond_t	Rt_cond;
5870Sstevel@tonic-gate 
5880Sstevel@tonic-gate /*
5890Sstevel@tonic-gate  * Define a dynamic section information descriptor.  This parallels the entries
5900Sstevel@tonic-gate  * in the .dynamic section and holds auxiliary information to implement lazy
5910Sstevel@tonic-gate  * loading and filtee processing.
5920Sstevel@tonic-gate  */
5930Sstevel@tonic-gate typedef struct {
5940Sstevel@tonic-gate 	uint_t	di_flags;
5950Sstevel@tonic-gate 	void	*di_info;
5960Sstevel@tonic-gate } Dyninfo;
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate #define	FLG_DI_STDFLTR	0x00001		/* .dynamic entry for DT_FILTER */
5990Sstevel@tonic-gate #define	FLG_DI_AUXFLTR	0x00002		/* .dynamic entry for DT_AUXILIARY */
6000Sstevel@tonic-gate #define	FLG_DI_SYMFLTR	0x00004		/* .dynamic entry for DT_SYMFILTER */
6010Sstevel@tonic-gate 					/*	and DT_SYMAUXILIARY */
6020Sstevel@tonic-gate #define	MSK_DI_FILTER	0x0000f		/* mask for all filter possibilities */
6030Sstevel@tonic-gate 
6045950Srie #define	FLG_DI_POSFLAG1	0x00010		/* .dynamic entry for DT_POSFLAG_1 */
6055950Srie #define	FLG_DI_NEEDED	0x00020		/* .dynamic entry for DT_NEEDED */
6065950Srie #define	FLG_DI_LAZY	0x00100		/* lazy needed entry - preceded by */
6075950Srie 					/*    DF_P1_LAZYLOAD (DT_POSFLAG_1) */
6085950Srie #define	FLG_DI_GROUP	0x00200		/* group needed entry - preceded by */
6095950Srie 					/*    DF_P1_GROUPPERM (DT_POSFLAG_1) */
6100Sstevel@tonic-gate 
6115950Srie #define	FLG_DI_LDD_DONE	0x01000		/* entry has been processed (ldd) */
6125950Srie #define	FLG_DI_LAZYFAIL	0x02000		/* the lazy loading of this entry */
6135950Srie 					/*    failed */
6140Sstevel@tonic-gate /*
6156387Srie  * Data structure to track AVL tree of pathnames.  This structure provides the
6166387Srie  * basis of both the "not-found" node tree, and the "full-path" node tree.  Both
6176387Srie  * of these trees persist for the life of a process, although the "not-found"
6186387Srie  * tree may be moved aside during a dlopen() or dlsym() fall back operation.
6190Sstevel@tonic-gate  */
6200Sstevel@tonic-gate typedef struct {
6216387Srie 	const char	*pn_name;	/* path name */
6226387Srie 	avl_node_t	pn_avl;		/* avl book-keeping (see SGSOFFSETOF) */
6236387Srie 	uint_t		pn_hash;	/* path name hash value */
6246387Srie } PathNode;
6256387Srie 
6266387Srie /*
6276387Srie  * Data structure to track AVL tree for full path names of objects that are
6286387Srie  * loaded into memory.
6296387Srie  */
6306387Srie typedef struct {
6316387Srie 	PathNode	fpn_node;	/* path node */
6320Sstevel@tonic-gate 	Rt_map		*fpn_lmp;	/* object link-map */
6336387Srie } FullPathNode;
6340Sstevel@tonic-gate 
6350Sstevel@tonic-gate /*
6365892Sab196087  * A given link-map can hold either a supplier or receiver copy
6375892Sab196087  * relocation list, but not both. This union is used to overlap
6385892Sab196087  * the space used for the two lists.
6395892Sab196087  */
6405892Sab196087 typedef union {
6415892Sab196087 	Alist	*rtc_r;		/* receiver list (Rel_copy) */
6425892Sab196087 	APlist	*rtc_s;		/* supplier list (Rt_map *) */
6435892Sab196087 } Rt_map_copy;
6445892Sab196087 
6455892Sab196087 
6465892Sab196087 /*
6470Sstevel@tonic-gate  * Link-map definition.
6480Sstevel@tonic-gate  */
6490Sstevel@tonic-gate struct rt_map {
6500Sstevel@tonic-gate 	/*
6510Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
6520Sstevel@tonic-gate 	 */
6530Sstevel@tonic-gate 	Link_map	rt_public;	/* public data */
6548598SRod.Evans@Sun.COM 	const char	*rt_pathname;	/* full pathname of loaded object */
6550Sstevel@tonic-gate 	ulong_t		rt_padstart;	/* start of image (including padding) */
6560Sstevel@tonic-gate 	ulong_t		rt_padimlen;	/* size of image (including padding */
6578598SRod.Evans@Sun.COM 	ulong_t		rt_msize;	/* total memory reservation range */
6580Sstevel@tonic-gate 	uint_t		rt_flags;	/* state flags, see FLG below */
6590Sstevel@tonic-gate 	uint_t		rt_flags1;	/* state flags1, see FL1 below */
6600Sstevel@tonic-gate 	ulong_t		rt_tlsmodid;	/* TLS module id */
6610Sstevel@tonic-gate 	/*
6620Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
6630Sstevel@tonic-gate 	 */
6645892Sab196087 	APlist		*rt_alias;	/* list of linked file names */
6655892Sab196087 	APlist		*rt_fpnode;	/* list of FullpathNode AVL nodes */
6660Sstevel@tonic-gate 	char		*rt_runpath;	/* LD_RUN_PATH and its equivalent */
6678598SRod.Evans@Sun.COM 	Alist		*rt_runlist;	/*	Pdesc structures */
6685892Sab196087 	APlist		*rt_depends;	/* list of dependencies */
6695892Sab196087 	APlist		*rt_callers;	/* list of callers */
6705892Sab196087 	APlist		*rt_handles;	/* dlopen handles */
6715892Sab196087 	APlist		*rt_groups;	/* groups we're a member of */
6720Sstevel@tonic-gate 	struct fct	*rt_fct;	/* file class table for this object */
6730Sstevel@tonic-gate 	void		*rt_priv;	/* private data, object type specific */
6740Sstevel@tonic-gate 	Lm_list		*rt_list;	/* link map list we belong to */
6750Sstevel@tonic-gate 	uint_t		rt_objfltrndx;	/* object filtees .dynamic index */
6760Sstevel@tonic-gate 	uint_t		rt_symsfltrcnt;	/* number of standard symbol filtees */
6770Sstevel@tonic-gate 	uint_t		rt_symafltrcnt;	/* number of auxiliary symbol filtees */
6780Sstevel@tonic-gate 	int		rt_mode;	/* usage mode, see RTLD mode flags */
679280Srie 	int		rt_sortval;	/* temporary buffer to traverse graph */
6800Sstevel@tonic-gate 	uint_t		rt_cycgroup;	/* cyclic group */
6810Sstevel@tonic-gate 	dev_t		rt_stdev;	/* device id and inode number for .so */
6828394SAli.Bahrami@Sun.COM 	rtld_ino_t	rt_stino;	/*	multiple inclusion checks */
6838598SRod.Evans@Sun.COM 	const char	*rt_origname;	/* original pathname of loaded object */
6840Sstevel@tonic-gate 	size_t		rt_dirsz;	/*	and its size */
6858598SRod.Evans@Sun.COM 	size_t		rt_lmsize;	/* size of the link-map allocation */
6865892Sab196087 	Rt_map_copy	rt_copy;	/* list of copy relocations */
6870Sstevel@tonic-gate 	Audit_desc	*rt_auditors;	/* audit descriptor array */
6880Sstevel@tonic-gate 	Audit_info	*rt_audinfo;	/* audit information descriptor */
6890Sstevel@tonic-gate 	Syminfo		*rt_syminfo;	/* elf .syminfo section - here */
6900Sstevel@tonic-gate 					/*	because it is checked in */
6910Sstevel@tonic-gate 					/*	common code */
6920Sstevel@tonic-gate 	Addr		*rt_initarray;	/* .initarray table */
6930Sstevel@tonic-gate 	Addr		*rt_finiarray;	/* .finiarray table */
6940Sstevel@tonic-gate 	Addr		*rt_preinitarray; /* .preinitarray table */
6958598SRod.Evans@Sun.COM 	mmapobj_result_t *rt_mmaps;	/* array of mapping information */
6960Sstevel@tonic-gate 	uint_t		rt_mmapcnt;	/*	and associated number */
6970Sstevel@tonic-gate 	uint_t		rt_initarraysz;	/* size of .initarray table */
6980Sstevel@tonic-gate 	uint_t		rt_finiarraysz;	/* size of .finiarray table */
6990Sstevel@tonic-gate 	uint_t		rt_preinitarraysz; /* size of .preinitarray table */
7000Sstevel@tonic-gate 	Dyninfo		*rt_dyninfo;	/* .dynamic information descriptors */
7010Sstevel@tonic-gate 	uint_t		rt_dyninfocnt;	/* count of dyninfo entries */
7020Sstevel@tonic-gate 	uint_t		rt_relacount;	/* no. of RELATIVE relocations */
7030Sstevel@tonic-gate 	uint_t		rt_idx;		/* hold index within linkmap list */
704*9963SRod.Evans@Sun.COM 	uint_t		rt_lazy;	/* number of lazy dependencies */
705*9963SRod.Evans@Sun.COM 					/*	pending */
7060Sstevel@tonic-gate 	Xword		rt_hwcap;	/* hardware capabilities */
7070Sstevel@tonic-gate 	Xword		rt_sfcap;	/* software capabilities */
7080Sstevel@tonic-gate 	uint_t		rt_cntl;	/* link-map control list we belong to */
7098598SRod.Evans@Sun.COM 	uint_t		rt_aflags;	/* auditor flags, see LML_TFLG_AUD_ */
7108598SRod.Evans@Sun.COM 					/* address of _init */
7118598SRod.Evans@Sun.COM 	void		(*rt_init)(void);
7128598SRod.Evans@Sun.COM 					/* address of _fini */
7138598SRod.Evans@Sun.COM 	void		(*rt_fini)(void);
7148598SRod.Evans@Sun.COM 					/* link map symbol interpreter */
7158598SRod.Evans@Sun.COM 	Sym		*(*rt_symintp)(Slookup *, Rt_map **, uint_t *, int *);
7160Sstevel@tonic-gate };
7170Sstevel@tonic-gate 
7180Sstevel@tonic-gate #ifdef _SYSCALL32
7190Sstevel@tonic-gate /*
7200Sstevel@tonic-gate  * Structure to allow 64-bit rtld_db to read 32-bit processes out of procfs.
7210Sstevel@tonic-gate  */
7225892Sab196087 typedef union {
7235892Sab196087 	uint32_t	rtc_r;
7245892Sab196087 	uint32_t	rtc_s;
7255892Sab196087 } Rt_map_copy32;
7265892Sab196087 
7270Sstevel@tonic-gate typedef struct rt_map32 {
7280Sstevel@tonic-gate 	/*
7290Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
7300Sstevel@tonic-gate 	 */
7310Sstevel@tonic-gate 	Link_map32	rt_public;
7320Sstevel@tonic-gate 	uint32_t	rt_pathname;
7330Sstevel@tonic-gate 	uint32_t	rt_padstart;
7340Sstevel@tonic-gate 	uint32_t	rt_padimlen;
7350Sstevel@tonic-gate 	uint32_t	rt_msize;
7360Sstevel@tonic-gate 	uint32_t	rt_flags;
7370Sstevel@tonic-gate 	uint32_t	rt_flags1;
7380Sstevel@tonic-gate 	uint32_t	rt_tlsmodid;
7390Sstevel@tonic-gate 	/*
7400Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
7410Sstevel@tonic-gate 	 */
7420Sstevel@tonic-gate 	uint32_t	rt_alias;
7430Sstevel@tonic-gate 	uint32_t	rt_fpnode;
7440Sstevel@tonic-gate 	uint32_t	rt_runpath;
7450Sstevel@tonic-gate 	uint32_t	rt_runlist;
7460Sstevel@tonic-gate 	uint32_t	rt_depends;
7470Sstevel@tonic-gate 	uint32_t	rt_callers;
7480Sstevel@tonic-gate 	uint32_t	rt_handles;
7490Sstevel@tonic-gate 	uint32_t	rt_groups;
7500Sstevel@tonic-gate 	uint32_t	rt_fct;
7510Sstevel@tonic-gate 	uint32_t	rt_priv;
7520Sstevel@tonic-gate 	uint32_t 	rt_list;
7530Sstevel@tonic-gate 	uint32_t 	rt_objfltrndx;
7540Sstevel@tonic-gate 	uint32_t 	rt_symsfltrcnt;
7550Sstevel@tonic-gate 	uint32_t 	rt_symafltrcnt;
756280Srie 	int32_t		rt_mode;
757280Srie 	int32_t		rt_sortval;
7580Sstevel@tonic-gate 	uint32_t	rt_cycgroup;
7590Sstevel@tonic-gate 	uint32_t	rt_stdev;
7600Sstevel@tonic-gate 	uint32_t	rt_stino;
7610Sstevel@tonic-gate 	uint32_t	rt_origname;
7620Sstevel@tonic-gate 	uint32_t	rt_dirsz;
7635892Sab196087 	Rt_map_copy32	rt_copy;
7640Sstevel@tonic-gate 	uint32_t 	rt_auditors;
7650Sstevel@tonic-gate 	uint32_t 	rt_audinfo;
7660Sstevel@tonic-gate 	uint32_t	rt_syminfo;
7670Sstevel@tonic-gate 	uint32_t	rt_initarray;
7680Sstevel@tonic-gate 	uint32_t	rt_finiarray;
7690Sstevel@tonic-gate 	uint32_t	rt_preinitarray;
7700Sstevel@tonic-gate 	uint32_t	rt_mmaps;
7710Sstevel@tonic-gate 	uint32_t	rt_mmapcnt;
7720Sstevel@tonic-gate 	uint32_t	rt_initarraysz;
7730Sstevel@tonic-gate 	uint32_t	rt_finiarraysz;
7740Sstevel@tonic-gate 	uint32_t	rt_preinitarraysz;
7750Sstevel@tonic-gate 	uint32_t 	rt_dyninfo;
7760Sstevel@tonic-gate 	uint32_t 	rt_dyninfocnt;
7770Sstevel@tonic-gate 	uint32_t	rt_relacount;
7780Sstevel@tonic-gate 	uint32_t	rt_idx;
7790Sstevel@tonic-gate 	uint32_t	rt_lazy;
7800Sstevel@tonic-gate 	uint32_t	rt_hwcap;
7810Sstevel@tonic-gate 	uint32_t	rt_sfcap;
7820Sstevel@tonic-gate 	uint32_t	rt_cntl;
7838598SRod.Evans@Sun.COM 	uint32_t	rt_aflags;
7848598SRod.Evans@Sun.COM 	uint32_t 	rt_init;
7858598SRod.Evans@Sun.COM 	uint32_t	rt_fini;
7868598SRod.Evans@Sun.COM 	uint32_t	rt_symintp;
7870Sstevel@tonic-gate } Rt_map32;
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate #endif	/* _SYSCALL32 */
7900Sstevel@tonic-gate 
7910Sstevel@tonic-gate /*
7920Sstevel@tonic-gate  * Link map state flags.
7930Sstevel@tonic-gate  */
7940Sstevel@tonic-gate /*
7950Sstevel@tonic-gate  * BEGIN: Exposed to rtld_db - don't move, don't delete
7960Sstevel@tonic-gate  */
7970Sstevel@tonic-gate #define	FLG_RT_ISMAIN	0x00000001	/* object represents main executable */
7980Sstevel@tonic-gate #define	FLG_RT_IMGALLOC	0x00000002	/* image is allocated (not mmap'ed) */
7990Sstevel@tonic-gate 	/*
8008598SRod.Evans@Sun.COM 	 * Available for r_debug version >= R_RTLDDB_VERSION5
8010Sstevel@tonic-gate 	 */
8020Sstevel@tonic-gate #define	FLG_RT_RELOCED	0x00000004	/* object has been relocated */
8030Sstevel@tonic-gate /*
8040Sstevel@tonic-gate  * END: Exposed to rtld_db - don't move, don't delete
8050Sstevel@tonic-gate  */
8060Sstevel@tonic-gate #define	FLG_RT_SETGROUP	0x00000008	/* group establishment required */
8070Sstevel@tonic-gate #define	FLG_RT_HWCAP	0x00000010	/* process $HWCAP expansion */
8080Sstevel@tonic-gate #define	FLG_RT_OBJECT	0x00000020	/* object processing (ie. .o's) */
80964Srie #define	FLG_RT_NEWLOAD	0x00000040	/* object is newly loaded */
8100Sstevel@tonic-gate #define	FLG_RT_NODUMP	0x00000080	/* object can't be dldump(3x)'ed */
8110Sstevel@tonic-gate #define	FLG_RT_DELETE	0x00000100	/* object can be deleted */
8120Sstevel@tonic-gate #define	FLG_RT_ANALYZED	0x00000200	/* object has been analyzed */
8130Sstevel@tonic-gate #define	FLG_RT_INITDONE	0x00000400	/* objects .init has been completed */
8140Sstevel@tonic-gate #define	FLG_RT_TRANS	0x00000800	/* object is acting as a translator */
8150Sstevel@tonic-gate #define	FLG_RT_FIXED	0x00001000	/* image location is fixed */
8160Sstevel@tonic-gate #define	FLG_RT_PRELOAD	0x00002000	/* object was preloaded */
8170Sstevel@tonic-gate #define	FLG_RT_ALTER	0x00004000	/* alternative object used */
8180Sstevel@tonic-gate #define	FLG_RT_LOADFLTR	0x00008000	/* trigger filtee loading */
8190Sstevel@tonic-gate #define	FLG_RT_AUDIT	0x00010000	/* object is an auditor */
8200Sstevel@tonic-gate #define	FLG_RT_MODESET	0x00020000	/* MODE() has been initialized */
8210Sstevel@tonic-gate #define	FLG_RT_ANALZING	0x00040000	/* object is being analyzed */
8220Sstevel@tonic-gate #define	FLG_RT_INITFRST 0x00080000	/* execute .init first */
8230Sstevel@tonic-gate #define	FLG_RT_NOOPEN	0x00100000	/* dlopen() not allowed */
8240Sstevel@tonic-gate #define	FLG_RT_FINICLCT	0x00200000	/* fini has been collected (tsort) */
8250Sstevel@tonic-gate #define	FLG_RT_INITCALL	0x00400000	/* objects .init has been called */
8268159SAli.Bahrami@Sun.COM #define	FLG_RT_OBJINTPO	0x00800000	/* object is a global interposer */
8278159SAli.Bahrami@Sun.COM #define	FLG_RT_SYMINTPO	0x01000000	/* object contains symbol interposer */
8288159SAli.Bahrami@Sun.COM #define	MSK_RT_INTPOSE	0x01800000	/* mask for all interposer */
8293466Srie 					/*	possibilities */
8308159SAli.Bahrami@Sun.COM #define	FLG_RT_MOVE	0x02000000	/* object needs move operation */
8319577SRod.Evans@Sun.COM #define	FLG_RT_RELOCING	0x04000000	/* object is being relocated */
8328159SAli.Bahrami@Sun.COM #define	FLG_RT_REGSYMS	0x08000000	/* object has DT_REGISTER entries */
8338159SAli.Bahrami@Sun.COM #define	FLG_RT_INITCLCT	0x10000000	/* init has been collected (tsort) */
8349577SRod.Evans@Sun.COM #define	FLG_RT_PUBHDL	0x20000000	/* generate a handle for this object */
8359577SRod.Evans@Sun.COM #define	FLG_RT_PRIHDL	0x40000000	/*	either public or private */
8360Sstevel@tonic-gate 
8370Sstevel@tonic-gate #define	FL1_RT_COPYTOOK	0x00000001	/* copy relocation taken */
8388598SRod.Evans@Sun.COM 
8390Sstevel@tonic-gate #define	FL1_RT_CONFSET	0x00000004	/* object was loaded by crle(1) */
8400Sstevel@tonic-gate #define	FL1_RT_NODEFLIB	0x00000008	/* ignore default library search */
8410Sstevel@tonic-gate #define	FL1_RT_ENDFILTE	0x00000010	/* filtee terminates filters search */
8420Sstevel@tonic-gate #define	FL1_RT_DISPREL	0x00000020	/* object has *disp* relocation */
8438598SRod.Evans@Sun.COM #define	FL1_RT_DTFLAGS	0x00000040	/* DT_FLAGS element exists */
8448598SRod.Evans@Sun.COM 
8450Sstevel@tonic-gate #define	FL1_RT_LDDSTUB	0x00000100	/* identify lddstub */
8460Sstevel@tonic-gate #define	FL1_RT_NOINIFIN	0x00000200	/* no .init or .fini exists */
8470Sstevel@tonic-gate #define	FL1_RT_USED	0x00000400	/* symbol referenced from this object */
8480Sstevel@tonic-gate #define	FL1_RT_SYMBOLIC	0x00000800	/* DF_SYMBOLIC was set - use */
8490Sstevel@tonic-gate 					/*	symbolic sym resolution */
8500Sstevel@tonic-gate #define	FL1_RT_OBJSFLTR	0x00001000	/* object is acting as a standard */
8510Sstevel@tonic-gate #define	FL1_RT_OBJAFLTR	0x00002000	/*	or auxiliary filter */
8520Sstevel@tonic-gate #define	FL1_RT_SYMSFLTR	0x00004000	/* symbol is acting as a standard */
8530Sstevel@tonic-gate #define	FL1_RT_SYMAFLTR	0x00008000	/*	or auxiliary filter */
8545067Srie #define	MSK_RT_FILTER	0x0000f000	/* mask for all filter possibilities */
8550Sstevel@tonic-gate 
8561824Srie #define	FL1_RT_TLSADD	0x00010000	/* objects TLS has been registered */
8572145Srie #define	FL1_RT_TLSSTAT	0x00020000	/* object requires static TLS */
8583466Srie #define	FL1_RT_DIRECT	0x00040000	/* object has DIRECT bindings enabled */
8594679Srie #define	FL1_RT_GLOBAUD	0x00080000	/* establish global auditing */
8601824Srie 
8610Sstevel@tonic-gate /*
8620Sstevel@tonic-gate  * Flags for the tls_modactivity() routine
8630Sstevel@tonic-gate  */
8640Sstevel@tonic-gate #define	TM_FLG_MODADD	0x01		/* call tls_modadd() interface */
8650Sstevel@tonic-gate #define	TM_FLG_MODREM	0x02		/* call tls_modrem() interface */
8660Sstevel@tonic-gate 
8670Sstevel@tonic-gate /*
8688598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION <= 2).
8690Sstevel@tonic-gate  */
8700Sstevel@tonic-gate #define	ADDR(X)		((X)->rt_public.l_addr)
8710Sstevel@tonic-gate #define	NAME(X)		((X)->rt_public.l_name)
8720Sstevel@tonic-gate #define	DYN(X)		((X)->rt_public.l_ld)
8730Sstevel@tonic-gate #define	NEXT(X)		((X)->rt_public.l_next)
8740Sstevel@tonic-gate #define	PREV(X)		((X)->rt_public.l_prev)
8750Sstevel@tonic-gate #define	REFNAME(X)	((X)->rt_public.l_refname)
8760Sstevel@tonic-gate 
8770Sstevel@tonic-gate /*
8788394SAli.Bahrami@Sun.COM  * An Rt_map starts with a Link_map, followed by other information.
8798394SAli.Bahrami@Sun.COM  * ld.so.1 allocates Rt_map structures, and then casts them to Link_map,
8808394SAli.Bahrami@Sun.COM  * and back, depending on context.
8818394SAli.Bahrami@Sun.COM  *
8828394SAli.Bahrami@Sun.COM  * On some platforms, Rt_map can have a higher alignment requirement
8838394SAli.Bahrami@Sun.COM  * than Link_map. On such platforms, the cast from Link_map to Rt_map will
8848394SAli.Bahrami@Sun.COM  * draw an E_BAD_PTR_CAST_ALIGN warning from lint. Since we allocate
8858394SAli.Bahrami@Sun.COM  * the memory as the higher alignment Rt_map, we know that this is a safe
8868394SAli.Bahrami@Sun.COM  * conversion. The LINKMAP_TO_RTMAP macro is used to handle the conversion
8878394SAli.Bahrami@Sun.COM  * in a manner that satisfies lint.
8888394SAli.Bahrami@Sun.COM  */
8898394SAli.Bahrami@Sun.COM #ifdef lint
8908394SAli.Bahrami@Sun.COM #define	LINKMAP_TO_RTMAP(X)	(Rt_map *)(void *)(X)
8918394SAli.Bahrami@Sun.COM #else
8928394SAli.Bahrami@Sun.COM #define	LINKMAP_TO_RTMAP(X)	(Rt_map *)(X)
8938394SAli.Bahrami@Sun.COM #endif
8948394SAli.Bahrami@Sun.COM 
8958394SAli.Bahrami@Sun.COM /*
8968394SAli.Bahrami@Sun.COM  * Convenience macros for the common case of using
8978394SAli.Bahrami@Sun.COM  * NEXT()/PREV() and casting the result to (Rt_map *)
8988394SAli.Bahrami@Sun.COM  */
8998394SAli.Bahrami@Sun.COM #define	NEXT_RT_MAP(X)	LINKMAP_TO_RTMAP(NEXT(X))
9008394SAli.Bahrami@Sun.COM #define	PREV_RT_MAP(X)	LINKMAP_TO_RTMAP(PREV(X))
9018394SAli.Bahrami@Sun.COM 
9028394SAli.Bahrami@Sun.COM /*
9038598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION3).
9040Sstevel@tonic-gate  */
9050Sstevel@tonic-gate #define	PATHNAME(X)	((X)->rt_pathname)
9060Sstevel@tonic-gate #define	PADSTART(X)	((X)->rt_padstart)
9070Sstevel@tonic-gate #define	PADIMLEN(X)	((X)->rt_padimlen)
9080Sstevel@tonic-gate #define	MSIZE(X)	((X)->rt_msize)
9090Sstevel@tonic-gate #define	FLAGS(X)	((X)->rt_flags)
9100Sstevel@tonic-gate #define	FLAGS1(X)	((X)->rt_flags1)
9118598SRod.Evans@Sun.COM 
9128598SRod.Evans@Sun.COM /*
9138598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION4).
9148598SRod.Evans@Sun.COM  */
9150Sstevel@tonic-gate #define	TLSMODID(X)	((X)->rt_tlsmodid)
9160Sstevel@tonic-gate 
9178598SRod.Evans@Sun.COM /*
9188598SRod.Evans@Sun.COM  * Macros for getting to unexposed, link-map data.
9198598SRod.Evans@Sun.COM  */
9208598SRod.Evans@Sun.COM #define	LMSIZE(X)	((X)->rt_lmsize)
9218598SRod.Evans@Sun.COM #define	AFLAGS(X)	((X)->rt_aflags)
9220Sstevel@tonic-gate #define	ALIAS(X)	((X)->rt_alias)
9230Sstevel@tonic-gate #define	FPNODE(X)	((X)->rt_fpnode)
9240Sstevel@tonic-gate #define	INIT(X)		((X)->rt_init)
9250Sstevel@tonic-gate #define	FINI(X)		((X)->rt_fini)
9260Sstevel@tonic-gate #define	RPATH(X)	((X)->rt_runpath)
9270Sstevel@tonic-gate #define	RLIST(X)	((X)->rt_runlist)
9280Sstevel@tonic-gate #define	DEPENDS(X)	((X)->rt_depends)
9290Sstevel@tonic-gate #define	CALLERS(X)	((X)->rt_callers)
9300Sstevel@tonic-gate #define	HANDLES(X)	((X)->rt_handles)
9310Sstevel@tonic-gate #define	GROUPS(X)	((X)->rt_groups)
9320Sstevel@tonic-gate #define	FCT(X)		((X)->rt_fct)
9330Sstevel@tonic-gate #define	SYMINTP(X)	((X)->rt_symintp)
9340Sstevel@tonic-gate #define	LIST(X)		((X)->rt_list)
9350Sstevel@tonic-gate #define	OBJFLTRNDX(X)	((X)->rt_objfltrndx)
9360Sstevel@tonic-gate #define	SYMSFLTRCNT(X)	((X)->rt_symsfltrcnt)
9370Sstevel@tonic-gate #define	SYMAFLTRCNT(X)	((X)->rt_symafltrcnt)
9380Sstevel@tonic-gate #define	MODE(X)		((X)->rt_mode)
9390Sstevel@tonic-gate #define	SORTVAL(X)	((X)->rt_sortval)
9400Sstevel@tonic-gate #define	CYCGROUP(X)	((X)->rt_cycgroup)
9410Sstevel@tonic-gate #define	STDEV(X)	((X)->rt_stdev)
9420Sstevel@tonic-gate #define	STINO(X)	((X)->rt_stino)
9430Sstevel@tonic-gate #define	ORIGNAME(X)	((X)->rt_origname)
9440Sstevel@tonic-gate #define	DIRSZ(X)	((X)->rt_dirsz)
9455892Sab196087 #define	COPY_R(X)	((X)->rt_copy.rtc_r)
9465892Sab196087 #define	COPY_S(X)	((X)->rt_copy.rtc_s)
9470Sstevel@tonic-gate #define	AUDITORS(X)	((X)->rt_auditors)
9480Sstevel@tonic-gate #define	AUDINFO(X)	((X)->rt_audinfo)
9490Sstevel@tonic-gate #define	SYMINFO(X)	((X)->rt_syminfo)
9500Sstevel@tonic-gate #define	INITARRAY(X)	((X)->rt_initarray)
9510Sstevel@tonic-gate #define	FINIARRAY(X)	((X)->rt_finiarray)
9520Sstevel@tonic-gate #define	PREINITARRAY(X)	((X)->rt_preinitarray)
9530Sstevel@tonic-gate #define	MMAPS(X)	((X)->rt_mmaps)
9540Sstevel@tonic-gate #define	MMAPCNT(X)	((X)->rt_mmapcnt)
9550Sstevel@tonic-gate #define	INITARRAYSZ(X)	((X)->rt_initarraysz)
9560Sstevel@tonic-gate #define	FINIARRAYSZ(X)	((X)->rt_finiarraysz)
9570Sstevel@tonic-gate #define	PREINITARRAYSZ(X) ((X)->rt_preinitarraysz)
9580Sstevel@tonic-gate #define	DYNINFO(X)	((X)->rt_dyninfo)
9590Sstevel@tonic-gate #define	DYNINFOCNT(X)	((X)->rt_dyninfocnt)
9600Sstevel@tonic-gate #define	RELACOUNT(X)	((X)->rt_relacount)
9610Sstevel@tonic-gate #define	IDX(X)		((X)->rt_idx)
9620Sstevel@tonic-gate #define	LAZY(X)		((X)->rt_lazy)
9630Sstevel@tonic-gate #define	CNTL(X)		((X)->rt_cntl)
9640Sstevel@tonic-gate #define	HWCAP(X)	((X)->rt_hwcap)
9650Sstevel@tonic-gate #define	SFCAP(X)	((X)->rt_sfcap)
9660Sstevel@tonic-gate 
967280Srie /*
968280Srie  * Flags for tsorting.
969280Srie  */
970280Srie #define	RT_SORT_FWD	0x01		/* topological sort (.fini) */
971280Srie #define	RT_SORT_REV	0x02		/* reverse topological sort (.init) */
9728598SRod.Evans@Sun.COM #define	RT_SORT_DELETE	0x10		/* process FLG_RT_DELETE objects */
973280Srie 					/*	only (called via dlclose()) */
9743817Srie #define	RT_SORT_INTPOSE	0x20		/* process interposer objects */
9753817Srie 
9760Sstevel@tonic-gate /*
9770Sstevel@tonic-gate  * Flags for lookup_sym (and hence find_sym) routines.
9780Sstevel@tonic-gate  */
9790Sstevel@tonic-gate #define	LKUP_DEFT	0x0000		/* simple lookup request */
9800Sstevel@tonic-gate #define	LKUP_SPEC	0x0001		/* special ELF lookup (allows address */
9810Sstevel@tonic-gate 					/*	resolutions to plt[] entries) */
9820Sstevel@tonic-gate #define	LKUP_LDOT	0x0002		/* indicates the original A_OUT */
9830Sstevel@tonic-gate 					/*	symbol had a leading `.' */
9840Sstevel@tonic-gate #define	LKUP_FIRST	0x0004		/* lookup symbol in first link map */
9850Sstevel@tonic-gate 					/*	only */
9860Sstevel@tonic-gate #define	LKUP_COPY	0x0008		/* lookup symbol for a COPY reloc, do */
9870Sstevel@tonic-gate 					/*	not bind to symbol at head */
9885220Srie #define	LKUP_STDRELOC	0x0010		/* lookup originates from a standard */
9895220Srie 					/*	relocation (elf_reloc()) */
9900Sstevel@tonic-gate #define	LKUP_SELF	0x0020		/* lookup symbol in ourself - undef */
9910Sstevel@tonic-gate 					/*	is valid */
9920Sstevel@tonic-gate #define	LKUP_WEAK	0x0040		/* relocation reference is weak */
9930Sstevel@tonic-gate #define	LKUP_NEXT	0x0080		/* request originates from RTLD_NEXT */
9940Sstevel@tonic-gate #define	LKUP_NODESCENT	0x0100		/* don't descend through dependencies */
9955950Srie #define	LKUP_NOFALLBACK	0x0200		/* don't fall back to loading */
9960Sstevel@tonic-gate 					/*	pending lazy dependencies */
9970Sstevel@tonic-gate #define	LKUP_DIRECT	0x0400		/* direct binding request */
998502Srie #define	LKUP_SYMNDX	0x0800		/* establish symbol index */
9995220Srie #define	LKUP_SINGLETON	0x1000		/* search for a singleton symbol */
10005220Srie #define	LKUP_STANDARD	0x2000		/* standard lookup - originated from */
10015220Srie 					/* 	head link-map element */
10028388SRod.Evans@Sun.COM #define	LKUP_WORLD	0x4000		/* ensure world lookup */
10030Sstevel@tonic-gate 
10040Sstevel@tonic-gate /*
10055950Srie  * For the runtime linker to perform a symbol search, a number of data items
10065950Srie  * related to the search are required.  An Slookup data structure is used to
10075950Srie  * convey this data to lookup_sym(), and in special cases, to other core
10085950Srie  * routines that provide the implementation details for lookup_sym()
10095950Srie  *
10105950Srie  * The symbol name (sl_name), the caller (sl_cmap), and the link-map from which
10115950Srie  * to start the search (sl_imap) are fundamental to the symbol search.  The
10125950Srie  * initial search link-map might get modified by the core routines that provide
10135950Srie  * the implementation details for lookup_sym().  This modification accommodates
10145950Srie  * requirements such as processing a handle, direct binding and interposition.
10155950Srie  * The association between the caller and the potential destination also
10165950Srie  * determines whether the destination is a candidate to search.
10175950Srie  *
10185950Srie  * The lookup identifier (sl_id) is used to identify a runtime linker operation.
10195950Srie  * Within this operation, any lazy loads that fail are not re-examined.  This
10205950Srie  * technique keeps the overhead of processing a failed lazy load to a minimum.
10215950Srie  *
10225950Srie  * Symbol searches that originate from a relocation record are accompanied by
10235950Srie  * the relocation index (sl_rsymndx), the symbol reference (sl_rsym) and
10245950Srie  * possibly the relocation type (sl_rtype).  This data provides for determining
10255950Srie  * lazy loading, direct binding, and special symbol processing requirements
10265950Srie  * such as copy relocations and singleton lookup.
10275950Srie  *
10285950Srie  * The symbols hash value is computed by lookup_sym, and propagated throughout
10295950Srie  * the search engine.  Note, occasionally the Slookup data is passed to a core
10305950Srie  * routine that provides the implementation details for lookup_sym(), ie.
10315950Srie  * elf_find_sym(), in which case the caller must initialize the hash value.
10325950Srie  *
10335950Srie  * The symbols binding information is established by lookup_sym() when the
10345950Srie  * symbols relocation type is supplied.  Weak bindings allow relocations to
10355950Srie  * be set to zero should a symbol lookup fail.
10365950Srie  *
10375950Srie  * The flags allow the caller to control aspects of the search, including the
10385950Srie  * interpretation of copy relocations, etc.  Note, a number of flag settings
10395950Srie  * are established in lookup_sym() from attributes of the symbol reference.
10400Sstevel@tonic-gate  */
10418598SRod.Evans@Sun.COM struct slookup {
10420Sstevel@tonic-gate 	const char	*sl_name;	/* symbol name */
10430Sstevel@tonic-gate 	Rt_map		*sl_cmap;	/* callers link-map */
10440Sstevel@tonic-gate 	Rt_map		*sl_imap;	/* initial link-map to search */
10455950Srie 	ulong_t		sl_id;		/* identifier for this lookup */
10460Sstevel@tonic-gate 	ulong_t		sl_hash;	/* symbol hash value */
10470Sstevel@tonic-gate 	ulong_t		sl_rsymndx;	/* referencing reloc symndx */
10485220Srie 	Sym		*sl_rsym;	/* referencing symbol */
10495220Srie 	uchar_t		sl_rtype;	/* relocation type associate with */
10505220Srie 					/*    symbol */
10515220Srie 	uchar_t		sl_bind;	/* symbols binding (returned) */
10520Sstevel@tonic-gate 	uint_t		sl_flags;	/* lookup flags */
10538598SRod.Evans@Sun.COM };
10540Sstevel@tonic-gate 
10555950Srie #define	SLOOKUP_INIT(sl, name, cmap, imap, id, hash, rsymndx, rsym, rtype, \
10565950Srie     flags) \
10575950Srie 	(void) (sl.sl_name = (name), sl.sl_cmap = (cmap), sl.sl_imap = (imap), \
10585950Srie 	    sl.sl_id = (id), sl.sl_hash = (hash), sl.sl_rsymndx = (rsymndx), \
10595950Srie 	    sl.sl_rsym = (rsym), sl.sl_rtype = (rtype), sl.sl_bind = 0, \
10605950Srie 	    sl.sl_flags = (flags))
10610Sstevel@tonic-gate 
10625950Srie /*
10635950Srie  * Define a number of .plt lookup outcomes, for use in binding diagnostics.
10645950Srie  */
10650Sstevel@tonic-gate typedef	enum {
10660Sstevel@tonic-gate 	PLT_T_NONE = 0,
10670Sstevel@tonic-gate 	PLT_T_21D,
10680Sstevel@tonic-gate 	PLT_T_24D,
10690Sstevel@tonic-gate 	PLT_T_U32,
10700Sstevel@tonic-gate 	PLT_T_U44,
10710Sstevel@tonic-gate 	PLT_T_FULL,
10720Sstevel@tonic-gate 	PLT_T_FAR,
10730Sstevel@tonic-gate 	PLT_T_NUM			/* Must be last */
10740Sstevel@tonic-gate } Pltbindtype;
10750Sstevel@tonic-gate 
10760Sstevel@tonic-gate /*
10770Sstevel@tonic-gate  * Prototypes.
10780Sstevel@tonic-gate  */
10795950Srie extern ulong_t		ld_entry_cnt;	/* counter bumped on each entry to */
10805950Srie 					/*    ld.so.1. */
10810Sstevel@tonic-gate extern Lm_list		lml_main;	/* main's link map list */
10820Sstevel@tonic-gate extern Lm_list		lml_rtld;	/* rtld's link map list */
10830Sstevel@tonic-gate extern Lm_list		*lml_list[];
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate extern Pltbindtype	elf_plt_write(uintptr_t, uintptr_t, void *, uintptr_t,
10860Sstevel@tonic-gate 			    Xword);
10876387Srie extern Rt_map		*is_so_loaded(Lm_list *, const char *, int *);
10886387Srie extern Sym		*lookup_sym(Slookup *, Rt_map **, uint_t *, int *);
10890Sstevel@tonic-gate extern int		rt_dldump(Rt_map *, const char *, int, Addr);
10900Sstevel@tonic-gate 
10910Sstevel@tonic-gate #ifdef	__cplusplus
10920Sstevel@tonic-gate }
10930Sstevel@tonic-gate #endif
10940Sstevel@tonic-gate 
10950Sstevel@tonic-gate #endif /* _RTLD_H */
1096