xref: /onnv-gate/usr/src/cmd/sgs/include/rtld.h (revision 12877:69001e4756ae)
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 /*
2312449SRod.Evans@Sun.COM  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate #ifndef	_RTLD_H
260Sstevel@tonic-gate #define	_RTLD_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
291824Srie  * Global include file for the runtime linker.
300Sstevel@tonic-gate  */
318598SRod.Evans@Sun.COM #include <sys/mman.h>
320Sstevel@tonic-gate #include <time.h>
330Sstevel@tonic-gate #include <sgs.h>
340Sstevel@tonic-gate #include <thread.h>
350Sstevel@tonic-gate #include <synch.h>
366206Sab196087 #include <link.h>
370Sstevel@tonic-gate #include <sys/avl.h>
380Sstevel@tonic-gate #include <alist.h>
391824Srie #include <libc_int.h>
4011827SRod.Evans@Sun.COM #include <elfcap.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;
6211827SRod.Evans@Sun.COM typedef struct sresult	Sresult;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate  * A binding descriptor.  Establishes the binding relationship between two
661618Srie  * objects, the caller (originator) and the dependency (destination).
679577SRod.Evans@Sun.COM  *
689577SRod.Evans@Sun.COM  * Every relationship between two objects is tracked by a binding descriptor.
699577SRod.Evans@Sun.COM  * This descriptor is referenced from a link-map's DEPENDS and CALLERS lists.
709577SRod.Evans@Sun.COM  * Note, Aplist's are diagramed to fully expose the allocations required to
719577SRod.Evans@Sun.COM  * establish the data structure relationships.
729577SRod.Evans@Sun.COM  *
739577SRod.Evans@Sun.COM  *                                  Bnd_desc
749577SRod.Evans@Sun.COM  *                                 ----------
759577SRod.Evans@Sun.COM  *                    ------------| b_caller |
769577SRod.Evans@Sun.COM  *                   |            | b_depend | ----------
779577SRod.Evans@Sun.COM  *                   |            |          |           |
789577SRod.Evans@Sun.COM  *      Rt_map       |             ----------            |       Rt_map
799577SRod.Evans@Sun.COM  *    ----------     |                ^ ^                |     ----------
809577SRod.Evans@Sun.COM  *   |          | <--                 | |                 --> |          |
819577SRod.Evans@Sun.COM  *   |          |        --------     | |                     |          |
829577SRod.Evans@Sun.COM  *   | DEPENDS  | ----> |        |    | |     --------        |          |
839577SRod.Evans@Sun.COM  *   |          |       |        |    | |    |        | <---- | CALLERS  |
849577SRod.Evans@Sun.COM  *   |          |       |        | ---  |    |        |       |          |
859577SRod.Evans@Sun.COM  *   |          |       |        |       --- |        |       |          |
869577SRod.Evans@Sun.COM  *   |          |        --------            |        |       |          |
879577SRod.Evans@Sun.COM  *    ----------          Aplist              --------         ----------
889577SRod.Evans@Sun.COM  *                                             Aplist
890Sstevel@tonic-gate  */
900Sstevel@tonic-gate typedef struct {
910Sstevel@tonic-gate 	Rt_map		*b_caller;	/* caller (originator) of a binding */
920Sstevel@tonic-gate 	Rt_map		*b_depend;	/* dependency (destination) of a */
930Sstevel@tonic-gate 					/*	binding */
940Sstevel@tonic-gate 	uint_t		b_flags;	/* relationship of caller to the */
950Sstevel@tonic-gate 					/*	dependency */
960Sstevel@tonic-gate } Bnd_desc;
970Sstevel@tonic-gate 
980Sstevel@tonic-gate #define	BND_NEEDED	0x0001		/* caller NEEDED the dependency */
990Sstevel@tonic-gate #define	BND_REFER	0x0002		/* caller relocation references the */
1000Sstevel@tonic-gate 					/*	dependency */
1019577SRod.Evans@Sun.COM #define	BND_FILTER	0x0004		/* binding identifies filter, used */
1029577SRod.Evans@Sun.COM 					/*	for diagnostics only */
1030Sstevel@tonic-gate /*
1040Sstevel@tonic-gate  * Private structure for communication between rtld_db and rtld.
1050Sstevel@tonic-gate  *
1061824Srie  * We must bump the version number when ever an update in one of the
1071824Srie  * structures/fields that rtld_db reads is updated.  This hopefully permits
1081824Srie  * rtld_db implementations of the future to recognize core files produced on
1091824Srie  * older systems and deal with these core files accordingly.
1100Sstevel@tonic-gate  *
1118598SRod.Evans@Sun.COM  * As of version 'R_RTLDDB_VERSION <= 2' the following fields were valid for
1128598SRod.Evans@Sun.COM  * core file examination (basically the public Link_map):
1130Sstevel@tonic-gate  *
1140Sstevel@tonic-gate  *		ADDR()
1150Sstevel@tonic-gate  *		NAME()
1160Sstevel@tonic-gate  *		DYN()
1170Sstevel@tonic-gate  *		NEXT()
1180Sstevel@tonic-gate  *		PREV()
1190Sstevel@tonic-gate  *
1208598SRod.Evans@Sun.COM  * Valid fields for R_RTLDDB_VERSION3
1210Sstevel@tonic-gate  *
1220Sstevel@tonic-gate  *		PATHNAME()
1230Sstevel@tonic-gate  *		PADSTART()
1240Sstevel@tonic-gate  *		PADIMLEN()
1250Sstevel@tonic-gate  *		MSIZE()
1260Sstevel@tonic-gate  *		FLAGS()
1270Sstevel@tonic-gate  *		FLAGS1()
1280Sstevel@tonic-gate  *
1298598SRod.Evans@Sun.COM  * Valid fields for R_RTLDDB_VERSION4
1300Sstevel@tonic-gate  *
1310Sstevel@tonic-gate  *		TLSMODID()
1320Sstevel@tonic-gate  *
1338598SRod.Evans@Sun.COM  * Valid fields for R_RTLDDB_VERSION5
1340Sstevel@tonic-gate  *
1350Sstevel@tonic-gate  *		Added rtld_flags & FLG_RT_RELOCED to stable flags range
1360Sstevel@tonic-gate  *
13710167SRod.Evans@Sun.COM  * Valid fields for R_RTLDDB_VERSION6
13810167SRod.Evans@Sun.COM  *
13910167SRod.Evans@Sun.COM  *		rtd_dynlmlst converted from a List to APlist
1400Sstevel@tonic-gate  */
1410Sstevel@tonic-gate #define	R_RTLDDB_VERSION1	1	/* base version level - used for core */
1420Sstevel@tonic-gate 					/*	file examination */
1431824Srie #define	R_RTLDDB_VERSION2	2	/* minor revision - not relevant for */
1440Sstevel@tonic-gate 					/*	core files */
1450Sstevel@tonic-gate #define	R_RTLDDB_VERSION3	3
1460Sstevel@tonic-gate #define	R_RTLDDB_VERSION4	4
1470Sstevel@tonic-gate #define	R_RTLDDB_VERSION5	5
14810167SRod.Evans@Sun.COM #define	R_RTLDDB_VERSION6	6
14910167SRod.Evans@Sun.COM #define	R_RTLDDB_VERSION	R_RTLDDB_VERSION6	/* current version */
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate typedef struct rtld_db_priv {
1520Sstevel@tonic-gate 	struct r_debug	rtd_rdebug;	/* original r_debug structure */
1530Sstevel@tonic-gate 	Word		rtd_version;	/* version no. */
1540Sstevel@tonic-gate 	size_t		rtd_objpad;	/* padding around mmap()ed objects */
1559131SRod.Evans@Sun.COM 	APlist		**rtd_dynlmlst;	/* pointer to dynlm_list pointer */
1560Sstevel@tonic-gate } Rtld_db_priv;
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate #ifdef _SYSCALL32
1590Sstevel@tonic-gate typedef struct rtld_db_priv32 {
1600Sstevel@tonic-gate 	struct r_debug32 rtd_rdebug;	/* original r_debug structure */
1610Sstevel@tonic-gate 	Elf32_Word	rtd_version;	/* version no. */
1620Sstevel@tonic-gate 	Elf32_Word	rtd_objpad;	/* padding around mmap()ed objects */
1639131SRod.Evans@Sun.COM 	Elf32_Addr	rtd_dynlmlst;	/* pointer to dynlm_list */
1640Sstevel@tonic-gate } Rtld_db_priv32;
1650Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1660Sstevel@tonic-gate 
1671824Srie /*
1681824Srie  * External function definitions.  ld.so.1 must convey information to libc in
1691824Srie  * regards to threading.  libc also provides routines for atexit() and message
1701824Srie  * localization.  libc provides the necessary interfaces via its RTLDINFO
1711824Srie  * structure and/or later _ld_libc() calls.
1721824Srie  *
1731824Srie  * These external functions are maintained for each link-map list, and used
1741824Srie  * where appropriate.  The functions are associated with the object that
1751824Srie  * provided them, so that should the object be deleted (say, from an alternative
1761824Srie  * link-map), the functions can be removed.
1771824Srie  */
1781824Srie typedef struct {
1791824Srie 	Rt_map	*lc_lmp;			/* function provider */
1801824Srie 	union {
1811824Srie 		int		(*lc_func)();	/* external function pointer */
1821824Srie 		uintptr_t	lc_val;		/* external value */
1831824Srie 		char    	*lc_ptr;	/* external character pointer */
1841824Srie 	} lc_un;
1851824Srie } Lc_desc;
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate /*
1880Sstevel@tonic-gate  * Link map list definition.  Link-maps are used to describe each loaded object.
1890Sstevel@tonic-gate  * Lists of these link-maps describe the various namespaces within a process.
1900Sstevel@tonic-gate  * The process executable and its dependencies are maintained on the lml_main
1910Sstevel@tonic-gate  * list.  The runtime linker, and its dependencies are maintained on the
1920Sstevel@tonic-gate  * lml_rtld list.  Additional lists can be created (see dlmopen()) for such
1930Sstevel@tonic-gate  * things as auditors and their dependencies.
1940Sstevel@tonic-gate  *
1950Sstevel@tonic-gate  * Each link-map list maintains an Alist of one, or more, linked lists of
1960Sstevel@tonic-gate  * link-maps.  For backward compatibility, the lm_head/lm_tail elements are
1970Sstevel@tonic-gate  * initialized to the first linked-list of link-maps:
1980Sstevel@tonic-gate  *
1990Sstevel@tonic-gate  *      Lm_list
2000Sstevel@tonic-gate  *    ----------
2010Sstevel@tonic-gate  *   | lm_tail  | ------------------------------------
2020Sstevel@tonic-gate  *   | lm_head  | --------------------                |
2030Sstevel@tonic-gate  *   |          |                     |     Rt_map    |     Rt_map
2040Sstevel@tonic-gate  *   |          |                     |     ------    |     ------
2050Sstevel@tonic-gate  *   |          |          Alist       --> |      |   |--> |      |
2060Sstevel@tonic-gate  *   |          |        ---------    |    |      | --     |      |
2070Sstevel@tonic-gate  *   | lm_lists | ----> |         |   |    |      |    --> |      |
2080Sstevel@tonic-gate  *   |          |       |---------|   |    |      |   |    |      |
2090Sstevel@tonic-gate  *   |          |       | lc_head | --      ------    |     ------
2100Sstevel@tonic-gate  *   |          |       | lc_tail | ------------------
2110Sstevel@tonic-gate  *   |          |       |---------|
2129577SRod.Evans@Sun.COM  *    ----------        | lc_head |
2130Sstevel@tonic-gate  *                      | lc_tail |
2140Sstevel@tonic-gate  *                      |---------|
2150Sstevel@tonic-gate  *
2160Sstevel@tonic-gate  * Multiple link-map lists exist to support the addition of lazy loaded
2170Sstevel@tonic-gate  * families, filtee families, and dlopen() families.  The intent of these
2180Sstevel@tonic-gate  * lists is to insure that a family of objects that are to be loaded are
2190Sstevel@tonic-gate  * fully relocatable, and hence usable, before they become part of the main
2200Sstevel@tonic-gate  * (al_data[0]) link-map control list.  This main link-map control list is
2210Sstevel@tonic-gate  * the only list in existence when control is transferred to user code.
2220Sstevel@tonic-gate  *
2230Sstevel@tonic-gate  * During process initialization, the dynamic executable and its non-lazy
2240Sstevel@tonic-gate  * dependencies are maintained on al_data[0].  If a new object is loaded, then
2250Sstevel@tonic-gate  * this object is added to the next available control list [1], typically
2260Sstevel@tonic-gate  * al_data[1].  Any dependencies of this object that have not already been
2270Sstevel@tonic-gate  * loaded are added to the same control list.  Once all of the objects on the
2280Sstevel@tonic-gate  * new control list have been successfully relocated, the objects are moved from
2290Sstevel@tonic-gate  * the new control list to the highest control list to which objects of the new
2300Sstevel@tonic-gate  * control list bound to, typically al_data[1] to al_data[0].
2310Sstevel@tonic-gate  *
2320Sstevel@tonic-gate  * Each loading scenario can be broken down as follows:
2330Sstevel@tonic-gate  *
2340Sstevel@tonic-gate  *  setup() - only the initial link-map control list is used:
2350Sstevel@tonic-gate  *   i.	  create al_data[0]
2360Sstevel@tonic-gate  *   ii.  add new link-map for main on al_data[0]
2370Sstevel@tonic-gate  *   iii. analyze al_data[0] to add all non-lazy dependencies
2380Sstevel@tonic-gate  *   iv.  relocate al_data[0] dependencies.
2390Sstevel@tonic-gate  *
2400Sstevel@tonic-gate  *  dlopen() - the initiator can only be the initial link-map control list:
2410Sstevel@tonic-gate  *   i.   create al_data[1] from caller al_data[0]
2420Sstevel@tonic-gate  *   ii.  add new link-map for the dlopen'ed object on al_data[1]
2430Sstevel@tonic-gate  *   iii. analyze al_data[1] to add all non-lazy dependencies
2440Sstevel@tonic-gate  *   iv.  relocate al_data[1] dependencies, and move to al_data[0].
2450Sstevel@tonic-gate  *
2460Sstevel@tonic-gate  *  filtee and lazy loading processing - the initiator can be any link-map
2470Sstevel@tonic-gate  *  control list that is being relocated:
2480Sstevel@tonic-gate  *   i.   create al_data[y] from caller al_data[x]
2490Sstevel@tonic-gate  *   ii.  add new link-map for the new object on al_data[y]
2500Sstevel@tonic-gate  *   iii. analyze al_data[y] to add all non-lazy dependencies
2510Sstevel@tonic-gate  *   iv.  relocate al_data[y] dependencies, and move to al_data[x].
2520Sstevel@tonic-gate  *
2530Sstevel@tonic-gate  * This Alist therefore maintains a stack of link-map control lists.  The newest
2540Sstevel@tonic-gate  * link-map control list can locate symbols within any of the former lists,
2550Sstevel@tonic-gate  * however, control is not passed to a former list until the newest lists
2560Sstevel@tonic-gate  * processing is complete.  Thus, objects can't bind to new objects until they
2570Sstevel@tonic-gate  * have been fully analyzed and relocated.
2580Sstevel@tonic-gate  *
2590Sstevel@tonic-gate  * [1]  Note, additional link-map control list creation occurs after the head
2600Sstevel@tonic-gate  * link-map object (typically the dynamic executable) has been relocated.  This
2610Sstevel@tonic-gate  * staging is required to satisfy the binding requirements of copy relocations.
2620Sstevel@tonic-gate  * Copy relocations, effectively, transfer the bindings of the copied data
2630Sstevel@tonic-gate  * (say _iob in libc.so.1) to the copy location (_iob in the application).
2640Sstevel@tonic-gate  * Thus an object that might bind to the original copy data must be redirected
2650Sstevel@tonic-gate  * to the copy reference.  As the knowledge of a copy relocation having taken
2660Sstevel@tonic-gate  * place is only known after relocating the application, link-map control list
2670Sstevel@tonic-gate  * additions are suspended until after this relocation has completed.
2680Sstevel@tonic-gate  */
2690Sstevel@tonic-gate typedef struct {
2700Sstevel@tonic-gate 	Rt_map		*lc_head;
2710Sstevel@tonic-gate 	Rt_map		*lc_tail;
2725892Sab196087 	APlist		*lc_now;	/* pending promoted bind-now objects */
2730Sstevel@tonic-gate 	uint_t		lc_flags;
2740Sstevel@tonic-gate } Lm_cntl;
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate #define	LMC_FLG_ANALYZING	0x01	/* control list is being analyzed */
2770Sstevel@tonic-gate #define	LMC_FLG_RELOCATING	0x02	/* control list is being relocated */
2780Sstevel@tonic-gate #define	LMC_FLG_REANALYZE	0x04	/* repeat analysis (established when */
2790Sstevel@tonic-gate 					/*	interposers are added */
2800Sstevel@tonic-gate 
2811618Srie struct lm_list {
2820Sstevel@tonic-gate 	/*
2830Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
2840Sstevel@tonic-gate 	 */
2850Sstevel@tonic-gate 	Rt_map		*lm_head;	/* linked list pointers to active */
2860Sstevel@tonic-gate 	Rt_map		*lm_tail;	/*	link-map list */
2875892Sab196087 	APlist		*lm_handle;	/* not used by rtld_db - but spacing */
2880Sstevel@tonic-gate 					/*	is required for flags */
2890Sstevel@tonic-gate 	Word		lm_flags;
2900Sstevel@tonic-gate 	/*
2910Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
2920Sstevel@tonic-gate 	 */
2931824Srie 	Alist		*lm_rti;	/* list of RTLDINFO tables */
2945067Srie 	Audit_list	*lm_alp;	/* audit list descriptor */
2950Sstevel@tonic-gate 	avl_tree_t	*lm_fpavl;	/* avl tree of objects loaded */
2960Sstevel@tonic-gate 	Alist		*lm_lists;	/* active and pending link-map lists */
2976Srie 	char		***lm_environ;	/* pointer to environment array */
2980Sstevel@tonic-gate 	Word		lm_tflags;	/* transferable flags */
2991618Srie 	uint_t		lm_obj;		/* total number of objs on link-map */
3001618Srie 	uint_t		lm_init;	/* new obj since last init processing */
3019963SRod.Evans@Sun.COM 	uint_t		lm_lazy;	/* number of objects with pending */
3029963SRod.Evans@Sun.COM 					/*	lazy dependencies */
3031824Srie 	uint_t		lm_tls;		/* new obj that require TLS */
3041618Srie 	uint_t		lm_lmid;	/* unique link-map list identifier, */
3051618Srie 	char		*lm_lmidstr;	/* and associated diagnostic string */
306*12877SRod.Evans@Sun.COM 	Alist		*lm_aud_cookies; /* local auditor cookies */
3071824Srie 	Lc_desc		lm_lcs[CI_MAX];	/* external libc functions */
3081618Srie };
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate #ifdef	_SYSCALL32
3111618Srie struct lm_list32 {
3120Sstevel@tonic-gate 	/*
3130Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
3140Sstevel@tonic-gate 	 */
3150Sstevel@tonic-gate 	Elf32_Addr	lm_head;
3160Sstevel@tonic-gate 	Elf32_Addr	lm_tail;
3170Sstevel@tonic-gate 	Elf32_Addr	lm_handle;
3180Sstevel@tonic-gate 	Elf32_Word	lm_flags;
3190Sstevel@tonic-gate 	/*
3200Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
3210Sstevel@tonic-gate 	 */
3221824Srie 	Elf32_Addr	lm_rti;
3230Sstevel@tonic-gate 	Elf32_Addr	lm_fpavl;
3240Sstevel@tonic-gate 	Elf32_Addr	lm_lists;
3256Srie 	Elf32_Addr	lm_environ;
3260Sstevel@tonic-gate 	Elf32_Word	lm_tflags;
3271618Srie 	uint_t		lm_obj;
3281618Srie 	uint_t		lm_init;
3291618Srie 	uint_t		lm_lazy;
3301824Srie 	uint_t		lm_tls;
3311618Srie 	uint_t		lm_lmid;
3321618Srie 	Elf32_Addr	lm_lmidstr;
333*12877SRod.Evans@Sun.COM 	Elf32_Addr	lm_aud_cookies;
3341824Srie 	Elf32_Addr	lm_lcs[CI_MAX];
3351618Srie };
3360Sstevel@tonic-gate #endif /* _SYSCALL32 */
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate /*
3390Sstevel@tonic-gate  * Possible Link_map list flags (Lm_list.lm_flags)
3400Sstevel@tonic-gate  */
3410Sstevel@tonic-gate /*
3420Sstevel@tonic-gate  * BEGIN: Exposed to rtld_db - don't move, don't delete
3430Sstevel@tonic-gate  */
3440Sstevel@tonic-gate #define	LML_FLG_BASELM		0x00000001	/* primary link-map */
3450Sstevel@tonic-gate #define	LML_FLG_RTLDLM		0x00000002	/* rtld link-map */
3460Sstevel@tonic-gate /*
3470Sstevel@tonic-gate  * END: Exposed to rtld_db - don't move, don't delete
3480Sstevel@tonic-gate  */
349*12877SRod.Evans@Sun.COM #define	LML_FLG_ACTAUDIT	0x00000004	/* audit activity posted */
3500Sstevel@tonic-gate #define	LML_FLG_PLTREL		0x00000008	/* deferred plt relocation */
351*12877SRod.Evans@Sun.COM 						/*    initialization (ld.so.1 */
352*12877SRod.Evans@Sun.COM 						/*    only) */
3530Sstevel@tonic-gate #define	LML_FLG_HOLDLOCK	0x00000010	/* hold the rtld mutex lock */
3540Sstevel@tonic-gate #define	LML_FLG_ENVIRON		0x00000020	/* environ var initialized */
3550Sstevel@tonic-gate #define	LML_FLG_INTRPOSE	0x00000040	/* interposing objs on list */
3560Sstevel@tonic-gate #define	LML_FLG_LOCAUDIT	0x00000080	/* local auditors exists for */
357*12877SRod.Evans@Sun.COM 						/*    this link-map list */
3580Sstevel@tonic-gate #define	LML_FLG_LOADAVAIL	0x00000100	/* load anything available */
3590Sstevel@tonic-gate #define	LML_FLG_IGNRELERR	0x00000200	/* ignore relocation errors - */
360*12877SRod.Evans@Sun.COM 						/*    internal for crle(1) */
361*12877SRod.Evans@Sun.COM #define	LML_FLG_STARTREL	0x00000400	/* relocation started */
362*12877SRod.Evans@Sun.COM #define	LML_FLG_ATEXIT		0x00000800	/* atexit processing */
363*12877SRod.Evans@Sun.COM #define	LML_FLG_OBJADDED	0x00001000	/* object(s) added */
364*12877SRod.Evans@Sun.COM #define	LML_FLG_OBJDELETED	0x00002000	/* object(s) deleted */
365*12877SRod.Evans@Sun.COM #define	LML_FLG_OBJREEVAL	0x00004000	/* existing object(s) needs */
366*12877SRod.Evans@Sun.COM 						/*    tsort reevaluation */
367*12877SRod.Evans@Sun.COM #define	LML_FLG_INTRPOSETSORT	0x00008000	/* interpose tsorting done */
368*12877SRod.Evans@Sun.COM #define	LML_FLG_AUDITNOTIFY	0x00010000	/* audit consistent required */
369*12877SRod.Evans@Sun.COM #define	LML_FLG_GROUPSEXIST	0x00020000	/* local groups exist */
3702850Srie 
3710Sstevel@tonic-gate #define	LML_FLG_TRC_LDDSTUB	0x00100000	/* identify lddstub */
3720Sstevel@tonic-gate #define	LML_FLG_TRC_ENABLE	0x00200000	/* tracing enabled (ldd) */
3730Sstevel@tonic-gate #define	LML_FLG_TRC_WARN	0x00400000	/* print warnings for undefs */
3740Sstevel@tonic-gate #define	LML_FLG_TRC_VERBOSE	0x00800000	/* verbose (versioning) trace */
3750Sstevel@tonic-gate #define	LML_FLG_TRC_SEARCH	0x01000000	/* trace search paths */
3760Sstevel@tonic-gate #define	LML_FLG_TRC_UNREF	0x02000000	/* trace unreferenced */
377*12877SRod.Evans@Sun.COM 						/*    dependencies */
3780Sstevel@tonic-gate #define	LML_FLG_TRC_UNUSED	0x04000000	/* trace unused dependencies */
3790Sstevel@tonic-gate #define	LML_FLG_TRC_INIT	0x08000000	/* print .init order */
3804947Srie #define	LML_FLG_TRC_NOUNRESWEAK	0x10000000	/* unresolved weak references */
381*12877SRod.Evans@Sun.COM 						/*    are not allowed */
3826150Srie #define	LML_FLG_TRC_NOPAREXT	0x20000000	/* unresolved PARENT/EXTERN */
383*12877SRod.Evans@Sun.COM 						/*    references are not */
384*12877SRod.Evans@Sun.COM 						/*    allowed */
3850Sstevel@tonic-gate #define	LML_MSK_TRC		0xfff00000	/* tracing mask */
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate /*
3880Sstevel@tonic-gate  * Possible Link_map transferable flags (Lm_list.lm_tflags), i.e., link-map
3890Sstevel@tonic-gate  * list flags that can be propagated to any new link-map list created.
3900Sstevel@tonic-gate  */
3910Sstevel@tonic-gate #define	LML_TFLG_NOLAZYLD	0x00000001	/* lazy loading disabled */
3920Sstevel@tonic-gate #define	LML_TFLG_NODIRECT	0x00000002	/* direct bindings disabled */
393*12877SRod.Evans@Sun.COM #define	LML_TFLG_NOAUDIT	0x00000004	/* auditing disabled */
3940Sstevel@tonic-gate #define	LML_TFLG_LOADFLTR	0x00000008	/* trigger filtee loading */
3950Sstevel@tonic-gate 
3968598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PREINIT	0x00001000	/* preinit (audit) exists */
3978598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJSEARCH	0x00002000	/* objsearch (audit) exists */
3988598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJOPEN	0x00004000	/* objopen (audit) exists */
3998598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJFILTER	0x00008000	/* objfilter (audit) exists */
4008598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_OBJCLOSE	0x00010000	/* objclose (audit) exists */
4018598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_SYMBIND	0x00020000	/* symbind (audit) exists */
4028598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PLTENTER	0x00040000	/* pltenter (audit) exists */
4038598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_PLTEXIT	0x00080000	/* pltexit (audit) exists */
4048598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_ACTIVITY	0x00100000	/* activity (audit) exists */
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate /*
4078598SRod.Evans@Sun.COM  * NOTE: Each auditing module establishes a set of audit flags, AFLAGS(), that
4088598SRod.Evans@Sun.COM  * define the auditing interfaces the module offers.  These auditing flags are
4098598SRod.Evans@Sun.COM  * the LML_TFLG_AUD_ flags defined above.  Global auditors result in setting
4108598SRod.Evans@Sun.COM  * the lm_tflags too.  Local auditors only use the AFLAGS().  All tests for
4118598SRod.Evans@Sun.COM  * auditing inspect the lm_tflags and AFLAGS() for a specific auditing
4128598SRod.Evans@Sun.COM  * interface, and thus use the same flag to test for both types of auditors.
4130Sstevel@tonic-gate  */
4148598SRod.Evans@Sun.COM #define	LML_TFLG_AUD_MASK	0x0ffff000	/* audit interfaces mask */
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate /*
4175067Srie  * Define a Group Handle.
4185067Srie  *
4195067Srie  * The capability of ld.so.1 to associate a group of objects, look for symbols
4205067Srie  * within that group, ensure that groups are isolated from one another (with
4219577SRod.Evans@Sun.COM  * regard to relocations), and to unload a group, centers around a handle.
4229577SRod.Evans@Sun.COM  *
4239577SRod.Evans@Sun.COM  * Dependencies can be added to an existing handle as the dependencies are
4249577SRod.Evans@Sun.COM  * lazily loaded.  The core dependencies on the handle are the ldd(1) list of
4259577SRod.Evans@Sun.COM  * the referenced object.
4269577SRod.Evans@Sun.COM  *
4279577SRod.Evans@Sun.COM  * Handles can be created from:
4285067Srie  *
4299577SRod.Evans@Sun.COM  *  -	a dlopen() request.  This associates a caller to a reference object,
4309577SRod.Evans@Sun.COM  * 	and the referenced objects dependencies.  This group of objects can
4319577SRod.Evans@Sun.COM  *	then be inspected for symbols (dlsym()).
4329577SRod.Evans@Sun.COM  *  -	a filtering request.  This associates a filter (caller) to a referenced
4339577SRod.Evans@Sun.COM  *	object (filtee).  The redirection of filter symbols to their filtee
4349577SRod.Evans@Sun.COM  *	counterpart is essentially a dlsym() using the filtee's handle.
4359577SRod.Evans@Sun.COM  *
4369577SRod.Evans@Sun.COM  * The handle created for these events is referred to as a public handle.  This
4379577SRod.Evans@Sun.COM  * handle tracks the referenced object, all of the dependencies of the
4389577SRod.Evans@Sun.COM  * referenced object, and the caller (parent).
4395067Srie  *
4405067Srie  * Presently, an object may have two handles, one requested with RTLD_FIRST
4415067Srie  * and one without.
4425067Srie  *
4439577SRod.Evans@Sun.COM  * A handle may be referenced by any number of callers (parents).  A reference
4445067Srie  * count tracks the number.  A dlclose() operation drops the reference count,
4455067Srie  * and when the count is zero, the handle is used to determine the family of
4465067Srie  * objects to unload.  As bindings may occur to objects on the handle from
4479577SRod.Evans@Sun.COM  * other handles, it may not be possible to remove a complete family of objects
4489577SRod.Evans@Sun.COM  * or the handle itself.  Handles in this state are moved to an orphan list.
4499577SRod.Evans@Sun.COM  * A handle on the orphan list is taken off the orphan list if the associated
4509577SRod.Evans@Sun.COM  * object is reopened.  Otherwise, the handle remains on the orphan list for
4519577SRod.Evans@Sun.COM  * the duration of the process.  The orphan list is inspected any time objects
4529577SRod.Evans@Sun.COM  * are unloaded, to determine if the orphaned objects can also be unloaded.
4539577SRod.Evans@Sun.COM  *
4549577SRod.Evans@Sun.COM  * Handles can also be created for internal uses:
4559577SRod.Evans@Sun.COM  *
4569577SRod.Evans@Sun.COM  *  -	to promote objects to RTLD_NOW.
4579577SRod.Evans@Sun.COM  *  -	to establish families for symbol binding fallback, required when lazy
4589577SRod.Evans@Sun.COM  *	loadable objects are still pending.
4599577SRod.Evans@Sun.COM  *
4609577SRod.Evans@Sun.COM  * The handle created for these events is referred to as a private handle.  This
4619577SRod.Evans@Sun.COM  * handle does not need to track the caller (parent), and because of this, does
4629577SRod.Evans@Sun.COM  * not need to be considered during dlclose() operations, as the handle can not
4639577SRod.Evans@Sun.COM  * be referenced by callers outside of the referenced objects family.
4649577SRod.Evans@Sun.COM  *
4659577SRod.Evans@Sun.COM  * Note, a private handle is essentially a subset of a public handle.  Should
4669577SRod.Evans@Sun.COM  * an internal operation require a private handle, and a public handle already
4679577SRod.Evans@Sun.COM  * exist, the public handle can be used.  Should an external operation require
4689577SRod.Evans@Sun.COM  * a public handle, and a private handle exist, the private handle is promoted
4699577SRod.Evans@Sun.COM  * to a public handle.  Any handle that gets created will remain in existence
4709577SRod.Evans@Sun.COM  * for the life time of the referenced object.
4715067Srie  *
4725067Srie  * Objects can be dlopened using RTLD_NOW.  This attribute requires that all
4735067Srie  * relocations of the object, and its dependencies are processed immediately,
4745067Srie  * before return to the caller.  Typically, an object is loaded without
4755067Srie  * RTLD_NOW, and procedure linkage relocations are satisfied when their
4765067Srie  * associated function is first called.  If an object is already loaded, and an
4775067Srie  * RTLD_NOW request is made, then the object, and its dependencies, most undergo
4785067Srie  * additional relocation processing.   This promotion from lazy binding to
4795067Srie  * immediate binding is carried out using handles, as the handle defines the
4809577SRod.Evans@Sun.COM  * dependencies that must be processed.
4819577SRod.Evans@Sun.COM  *
4829577SRod.Evans@Sun.COM  * To ensure that objects within a lazy loadable environment can be relocated,
4839577SRod.Evans@Sun.COM  * no matter whether the objects have their dependencies described completely,
4849577SRod.Evans@Sun.COM  * a symbol lookup fallback is employed.  Any pending lazy loadable objects are
4859577SRod.Evans@Sun.COM  * loaded, and a handle established to search the object and it's dependencies
4869577SRod.Evans@Sun.COM  * for the required symbol.
4879577SRod.Evans@Sun.COM  *
4889577SRod.Evans@Sun.COM  * A group handle (and its associated group descriptors), is referenced from
4899577SRod.Evans@Sun.COM  * a link-map's HANDLES and GROUPS lists.  Note, Aplist's are diagramed to
4909577SRod.Evans@Sun.COM  * fully expose the allocations required to establish the data structure
4919577SRod.Evans@Sun.COM  * relationships.
4929577SRod.Evans@Sun.COM  *
4939577SRod.Evans@Sun.COM  *                                  Grp_desc
4949577SRod.Evans@Sun.COM  *                                   Alist
4959577SRod.Evans@Sun.COM  *                                 -----------
4969577SRod.Evans@Sun.COM  *                            --> |           |
4979577SRod.Evans@Sun.COM  *                           |    |-----------|
4989577SRod.Evans@Sun.COM  *                           |    | gd_depend | ---------
4999577SRod.Evans@Sun.COM  *                           |    |           |          |
5009577SRod.Evans@Sun.COM  *                           |    |-----------|          |
5019577SRod.Evans@Sun.COM  *                   --------|--- | gd_depend |          |
5029577SRod.Evans@Sun.COM  *                  |        |    | (parent)  |          |
5039577SRod.Evans@Sun.COM  *                  |        |    |-----------|          |
5049577SRod.Evans@Sun.COM  *                  |        |    | gd_depend |          |
5059577SRod.Evans@Sun.COM  *                  |        |    |           |          |
5069577SRod.Evans@Sun.COM  *                  |        |    |           |          |
5079577SRod.Evans@Sun.COM  *                  |        |     -----------           |
5089577SRod.Evans@Sun.COM  *                  |        |                           |
5099577SRod.Evans@Sun.COM  *                  |        |      Grp_hdl              |
5109577SRod.Evans@Sun.COM  *                  |        |    -----------            |
5119577SRod.Evans@Sun.COM  *                  |         -- | gh_depends |          |
5129577SRod.Evans@Sun.COM  *                  |  --------- | gh_ownlmp  |          |
5139577SRod.Evans@Sun.COM  *                  | |          |            |          |
5149577SRod.Evans@Sun.COM  *                  | |          |            |          |
5159577SRod.Evans@Sun.COM  *                  | |          |            |          |
5169577SRod.Evans@Sun.COM  *      Rt_map      | |           ------------           |       Rt_map
5179577SRod.Evans@Sun.COM  *    ----------    | |               ^ ^                |     ----------
5189577SRod.Evans@Sun.COM  *   |          | <-  |               | |                 --> |          |
5199577SRod.Evans@Sun.COM  *   |          | <---   --------     | |                     |          |
5209577SRod.Evans@Sun.COM  *   | HANDLES  | ----> |        |    | |     --------        |          |
5219577SRod.Evans@Sun.COM  *   |          |       |        |    | |    |        | <---- |  GROUPS  |
5229577SRod.Evans@Sun.COM  *   |          |       |        | ---  |    |        |       |          |
5239577SRod.Evans@Sun.COM  *   |          |       |        |       --- |        |       |          |
5249577SRod.Evans@Sun.COM  *   |          |        --------            |        |       |          |
5259577SRod.Evans@Sun.COM  *    ----------          Aplist              --------         ----------
5269577SRod.Evans@Sun.COM  *                                             Aplist
5270Sstevel@tonic-gate  */
5280Sstevel@tonic-gate typedef struct {
5291618Srie 	Alist		*gh_depends;	/* handle dependency list */
5301618Srie 	Rt_map		*gh_ownlmp;	/* handle owners link-map */
5311618Srie 	Lm_list		*gh_ownlml;	/* handle owners link-map list */
5320Sstevel@tonic-gate 	uint_t		gh_refcnt;	/* handle reference count */
5335067Srie 	uint_t		gh_flags;	/* handle flags (GPH_ values) */
5340Sstevel@tonic-gate } Grp_hdl;
5350Sstevel@tonic-gate 
5369577SRod.Evans@Sun.COM /*
5379577SRod.Evans@Sun.COM  * Define the two categories of handle.
5389577SRod.Evans@Sun.COM  */
5399577SRod.Evans@Sun.COM #define	GPH_PUBLIC	0x0001		/* handle returned to caller(s) */
5409577SRod.Evans@Sun.COM #define	GPH_PRIVATE	0x0002		/* handle used internally */
5419577SRod.Evans@Sun.COM 
5429577SRod.Evans@Sun.COM /*
5439577SRod.Evans@Sun.COM  * Define any flags that affects how the handle is used.
5449577SRod.Evans@Sun.COM  */
5459577SRod.Evans@Sun.COM #define	GPH_ZERO	0x0010		/* special handle for dlopen(0) */
5469577SRod.Evans@Sun.COM #define	GPH_LDSO	0x0020		/* special handle for ld.so.1 */
5479577SRod.Evans@Sun.COM #define	GPH_FIRST	0x0040		/* dlsym() can only use originating */
5480Sstevel@tonic-gate 					/*	dependency */
5499577SRod.Evans@Sun.COM #define	GPH_FILTEE	0x0080		/* handle identifies a filtee, used */
5509577SRod.Evans@Sun.COM 					/*	for diagnostics only */
5519577SRod.Evans@Sun.COM /*
5529577SRod.Evans@Sun.COM  * Define any state that is associated with the handle.
5539577SRod.Evans@Sun.COM  */
5549577SRod.Evans@Sun.COM #define	GPH_INITIAL	0x0100		/* handle is initialized */
5559963SRod.Evans@Sun.COM 
5560Sstevel@tonic-gate /*
5575067Srie  * Define a Group Descriptor.
5585067Srie  *
5595067Srie  * Each dependency associated with a group handle is maintained by a group
5605067Srie  * descriptor.  The descriptor defines the associated dependency together with
5615067Srie  * flags that indicate how the dependency can be used.
5620Sstevel@tonic-gate  */
5630Sstevel@tonic-gate typedef struct {
5648598SRod.Evans@Sun.COM 	Rt_map		*gd_depend;	/* dependency */
5655067Srie 	uint_t		gd_flags;	/* dependency flags (GPD_ values) */
5660Sstevel@tonic-gate } Grp_desc;
5670Sstevel@tonic-gate 
5684699Srie #define	GPD_DLSYM	0x0001		/* dependency available to dlsym() */
5694699Srie #define	GPD_RELOC	0x0002		/* dependency available to satisfy */
5704699Srie 					/*	relocation binding */
5714699Srie #define	GPD_ADDEPS	0x0004		/* dependencies of this dependency */
5720Sstevel@tonic-gate 					/*	should be added to handle */
5734699Srie #define	GPD_PARENT	0x0008		/* dependency is a parent */
5744699Srie #define	GPD_FILTER	0x0010		/* dependency is our filter */
5759577SRod.Evans@Sun.COM #define	GPD_REMOVE	0x0100		/* descriptor is a candidate for */
5760Sstevel@tonic-gate 					/*	removal from the group */
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 {
59812449SRod.Evans@Sun.COM 	uint_t		di_flags;
59912449SRod.Evans@Sun.COM 	void		*di_info;
60012449SRod.Evans@Sun.COM 	const char	*di_name;
6010Sstevel@tonic-gate } Dyninfo;
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate #define	FLG_DI_STDFLTR	0x00001		/* .dynamic entry for DT_FILTER */
6040Sstevel@tonic-gate #define	FLG_DI_AUXFLTR	0x00002		/* .dynamic entry for DT_AUXILIARY */
6050Sstevel@tonic-gate #define	FLG_DI_SYMFLTR	0x00004		/* .dynamic entry for DT_SYMFILTER */
6060Sstevel@tonic-gate 					/*	and DT_SYMAUXILIARY */
6070Sstevel@tonic-gate #define	MSK_DI_FILTER	0x0000f		/* mask for all filter possibilities */
6080Sstevel@tonic-gate 
6095950Srie #define	FLG_DI_POSFLAG1	0x00010		/* .dynamic entry for DT_POSFLAG_1 */
6105950Srie #define	FLG_DI_NEEDED	0x00020		/* .dynamic entry for DT_NEEDED */
61112449SRod.Evans@Sun.COM #define	FLG_DI_REGISTER	0x00040		/* .dynamic entry for DT_REGISTER */
61212449SRod.Evans@Sun.COM #define	FLG_DI_IGNORE	0x00080		/* .dynamic entry should be ignored */
61312449SRod.Evans@Sun.COM 
61412449SRod.Evans@Sun.COM #define	FLG_DI_LAZY	0x00100		/* lazy needed entry, preceded by */
6155950Srie 					/*    DF_P1_LAZYLOAD (DT_POSFLAG_1) */
61612449SRod.Evans@Sun.COM #define	FLG_DI_GROUP	0x00200		/* group needed entry, preceded by */
6175950Srie 					/*    DF_P1_GROUPPERM (DT_POSFLAG_1) */
61812449SRod.Evans@Sun.COM #define	FLG_DI_DEFERRED	0x00400		/* deferred needed entry, preceded by */
61912449SRod.Evans@Sun.COM 					/*    DF_P1_DEFERRED (DT_POSFLAG_1) */
6200Sstevel@tonic-gate 
62112449SRod.Evans@Sun.COM #define	FLG_DI_LAZYFAIL	0x01000		/* the lazy loading of this entry */
6225950Srie 					/*    failed */
62312449SRod.Evans@Sun.COM #define	FLG_DI_LDD_DONE	0x02000		/* entry has been processed (ldd) */
62412449SRod.Evans@Sun.COM #define	FLG_DI_DEF_DONE	0x04000		/* entry has been processed (dlinfo) */
62512449SRod.Evans@Sun.COM 
6260Sstevel@tonic-gate /*
6276387Srie  * Data structure to track AVL tree of pathnames.  This structure provides the
6286387Srie  * basis of both the "not-found" node tree, and the "full-path" node tree.  Both
6296387Srie  * of these trees persist for the life of a process, although the "not-found"
6306387Srie  * tree may be moved aside during a dlopen() or dlsym() fall back operation.
6310Sstevel@tonic-gate  */
6320Sstevel@tonic-gate typedef struct {
6336387Srie 	const char	*pn_name;	/* path name */
6346387Srie 	avl_node_t	pn_avl;		/* avl book-keeping (see SGSOFFSETOF) */
6356387Srie 	uint_t		pn_hash;	/* path name hash value */
6366387Srie } PathNode;
6376387Srie 
6386387Srie /*
6396387Srie  * Data structure to track AVL tree for full path names of objects that are
6406387Srie  * loaded into memory.
6416387Srie  */
6426387Srie typedef struct {
6436387Srie 	PathNode	fpn_node;	/* path node */
6440Sstevel@tonic-gate 	Rt_map		*fpn_lmp;	/* object link-map */
6456387Srie } FullPathNode;
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate /*
6485892Sab196087  * A given link-map can hold either a supplier or receiver copy
6495892Sab196087  * relocation list, but not both. This union is used to overlap
6505892Sab196087  * the space used for the two lists.
6515892Sab196087  */
6525892Sab196087 typedef union {
6535892Sab196087 	Alist	*rtc_r;		/* receiver list (Rel_copy) */
6545892Sab196087 	APlist	*rtc_s;		/* supplier list (Rt_map *) */
6555892Sab196087 } Rt_map_copy;
6565892Sab196087 
6575892Sab196087 
6585892Sab196087 /*
6590Sstevel@tonic-gate  * Link-map definition.
6600Sstevel@tonic-gate  */
6610Sstevel@tonic-gate struct rt_map {
6620Sstevel@tonic-gate 	/*
6630Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
6640Sstevel@tonic-gate 	 */
6650Sstevel@tonic-gate 	Link_map	rt_public;	/* public data */
6668598SRod.Evans@Sun.COM 	const char	*rt_pathname;	/* full pathname of loaded object */
6670Sstevel@tonic-gate 	ulong_t		rt_padstart;	/* start of image (including padding) */
6680Sstevel@tonic-gate 	ulong_t		rt_padimlen;	/* size of image (including padding */
6698598SRod.Evans@Sun.COM 	ulong_t		rt_msize;	/* total memory reservation range */
6700Sstevel@tonic-gate 	uint_t		rt_flags;	/* state flags, see FLG below */
6710Sstevel@tonic-gate 	uint_t		rt_flags1;	/* state flags1, see FL1 below */
6720Sstevel@tonic-gate 	ulong_t		rt_tlsmodid;	/* TLS module id */
6730Sstevel@tonic-gate 	/*
6740Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
6750Sstevel@tonic-gate 	 */
6765892Sab196087 	APlist		*rt_alias;	/* list of linked file names */
67711827SRod.Evans@Sun.COM 	APlist		*rt_fpnode;	/* list of FullPathNode AVL nodes */
6780Sstevel@tonic-gate 	char		*rt_runpath;	/* LD_RUN_PATH and its equivalent */
6798598SRod.Evans@Sun.COM 	Alist		*rt_runlist;	/*	Pdesc structures */
6805892Sab196087 	APlist		*rt_depends;	/* list of dependencies */
6815892Sab196087 	APlist		*rt_callers;	/* list of callers */
6825892Sab196087 	APlist		*rt_handles;	/* dlopen handles */
6835892Sab196087 	APlist		*rt_groups;	/* groups we're a member of */
6840Sstevel@tonic-gate 	struct fct	*rt_fct;	/* file class table for this object */
6850Sstevel@tonic-gate 	void		*rt_priv;	/* private data, object type specific */
6860Sstevel@tonic-gate 	Lm_list		*rt_list;	/* link map list we belong to */
6870Sstevel@tonic-gate 	uint_t		rt_objfltrndx;	/* object filtees .dynamic index */
6880Sstevel@tonic-gate 	uint_t		rt_symsfltrcnt;	/* number of standard symbol filtees */
6890Sstevel@tonic-gate 	uint_t		rt_symafltrcnt;	/* number of auxiliary symbol filtees */
6900Sstevel@tonic-gate 	int		rt_mode;	/* usage mode, see RTLD mode flags */
691280Srie 	int		rt_sortval;	/* temporary buffer to traverse graph */
6920Sstevel@tonic-gate 	uint_t		rt_cycgroup;	/* cyclic group */
6930Sstevel@tonic-gate 	dev_t		rt_stdev;	/* device id and inode number for .so */
6948394SAli.Bahrami@Sun.COM 	rtld_ino_t	rt_stino;	/*	multiple inclusion checks */
6958598SRod.Evans@Sun.COM 	const char	*rt_origname;	/* original pathname of loaded object */
6960Sstevel@tonic-gate 	size_t		rt_dirsz;	/*	and its size */
6978598SRod.Evans@Sun.COM 	size_t		rt_lmsize;	/* size of the link-map allocation */
6985892Sab196087 	Rt_map_copy	rt_copy;	/* list of copy relocations */
6990Sstevel@tonic-gate 	Audit_desc	*rt_auditors;	/* audit descriptor array */
7000Sstevel@tonic-gate 	Audit_info	*rt_audinfo;	/* audit information descriptor */
7010Sstevel@tonic-gate 	Syminfo		*rt_syminfo;	/* elf .syminfo section - here */
7020Sstevel@tonic-gate 					/*	because it is checked in */
7030Sstevel@tonic-gate 					/*	common code */
70412736SAli.Bahrami@Oracle.COM 	Addr		*rt_initarray;	/* .init_array table */
70512736SAli.Bahrami@Oracle.COM 	Addr		*rt_finiarray;	/* .fini_array table */
70612736SAli.Bahrami@Oracle.COM 	Addr		*rt_preinitarray; /* .preinit_array table */
7078598SRod.Evans@Sun.COM 	mmapobj_result_t *rt_mmaps;	/* array of mapping information */
7080Sstevel@tonic-gate 	uint_t		rt_mmapcnt;	/*	and associated number */
70912736SAli.Bahrami@Oracle.COM 	uint_t		rt_initarraysz;	/* size of .init_array table */
71012736SAli.Bahrami@Oracle.COM 	uint_t		rt_finiarraysz;	/* size of .fini_array table */
71112736SAli.Bahrami@Oracle.COM 	uint_t		rt_preinitarraysz; /* size of .preinit_array table */
7120Sstevel@tonic-gate 	Dyninfo		*rt_dyninfo;	/* .dynamic information descriptors */
7130Sstevel@tonic-gate 	uint_t		rt_dyninfocnt;	/* count of dyninfo entries */
7140Sstevel@tonic-gate 	uint_t		rt_relacount;	/* no. of RELATIVE relocations */
7150Sstevel@tonic-gate 	uint_t		rt_idx;		/* hold index within linkmap list */
7169963SRod.Evans@Sun.COM 	uint_t		rt_lazy;	/* number of lazy dependencies */
7179963SRod.Evans@Sun.COM 					/*	pending */
71811827SRod.Evans@Sun.COM 	Cap		*rt_cap;	/* capabilities data */
71911827SRod.Evans@Sun.COM 	Capchain	*rt_capchain;	/* capabilities chain data */
7200Sstevel@tonic-gate 	uint_t		rt_cntl;	/* link-map control list we belong to */
7218598SRod.Evans@Sun.COM 	uint_t		rt_aflags;	/* auditor flags, see LML_TFLG_AUD_ */
7228598SRod.Evans@Sun.COM 					/* address of _init */
7238598SRod.Evans@Sun.COM 	void		(*rt_init)(void);
7248598SRod.Evans@Sun.COM 					/* address of _fini */
7258598SRod.Evans@Sun.COM 	void		(*rt_fini)(void);
7268598SRod.Evans@Sun.COM 					/* link map symbol interpreter */
72711827SRod.Evans@Sun.COM 	int		(*rt_symintp)(Slookup *, Sresult *, uint_t *, int *);
7280Sstevel@tonic-gate };
7290Sstevel@tonic-gate 
7300Sstevel@tonic-gate #ifdef _SYSCALL32
7310Sstevel@tonic-gate /*
7320Sstevel@tonic-gate  * Structure to allow 64-bit rtld_db to read 32-bit processes out of procfs.
7330Sstevel@tonic-gate  */
7345892Sab196087 typedef union {
7355892Sab196087 	uint32_t	rtc_r;
7365892Sab196087 	uint32_t	rtc_s;
7375892Sab196087 } Rt_map_copy32;
7385892Sab196087 
7390Sstevel@tonic-gate typedef struct rt_map32 {
7400Sstevel@tonic-gate 	/*
7410Sstevel@tonic-gate 	 * BEGIN: Exposed to rtld_db - don't move, don't delete
7420Sstevel@tonic-gate 	 */
7430Sstevel@tonic-gate 	Link_map32	rt_public;
7440Sstevel@tonic-gate 	uint32_t	rt_pathname;
7450Sstevel@tonic-gate 	uint32_t	rt_padstart;
7460Sstevel@tonic-gate 	uint32_t	rt_padimlen;
7470Sstevel@tonic-gate 	uint32_t	rt_msize;
7480Sstevel@tonic-gate 	uint32_t	rt_flags;
7490Sstevel@tonic-gate 	uint32_t	rt_flags1;
7500Sstevel@tonic-gate 	uint32_t	rt_tlsmodid;
7510Sstevel@tonic-gate 	/*
7520Sstevel@tonic-gate 	 * END: Exposed to rtld_db - don't move, don't delete
7530Sstevel@tonic-gate 	 */
7540Sstevel@tonic-gate 	uint32_t	rt_alias;
7550Sstevel@tonic-gate 	uint32_t	rt_fpnode;
7560Sstevel@tonic-gate 	uint32_t	rt_runpath;
7570Sstevel@tonic-gate 	uint32_t	rt_runlist;
7580Sstevel@tonic-gate 	uint32_t	rt_depends;
7590Sstevel@tonic-gate 	uint32_t	rt_callers;
7600Sstevel@tonic-gate 	uint32_t	rt_handles;
7610Sstevel@tonic-gate 	uint32_t	rt_groups;
7620Sstevel@tonic-gate 	uint32_t	rt_fct;
7630Sstevel@tonic-gate 	uint32_t	rt_priv;
7640Sstevel@tonic-gate 	uint32_t 	rt_list;
7650Sstevel@tonic-gate 	uint32_t 	rt_objfltrndx;
7660Sstevel@tonic-gate 	uint32_t 	rt_symsfltrcnt;
7670Sstevel@tonic-gate 	uint32_t 	rt_symafltrcnt;
768280Srie 	int32_t		rt_mode;
769280Srie 	int32_t		rt_sortval;
7700Sstevel@tonic-gate 	uint32_t	rt_cycgroup;
7710Sstevel@tonic-gate 	uint32_t	rt_stdev;
7720Sstevel@tonic-gate 	uint32_t	rt_stino;
7730Sstevel@tonic-gate 	uint32_t	rt_origname;
7740Sstevel@tonic-gate 	uint32_t	rt_dirsz;
7755892Sab196087 	Rt_map_copy32	rt_copy;
7760Sstevel@tonic-gate 	uint32_t 	rt_auditors;
7770Sstevel@tonic-gate 	uint32_t 	rt_audinfo;
7780Sstevel@tonic-gate 	uint32_t	rt_syminfo;
7790Sstevel@tonic-gate 	uint32_t	rt_initarray;
7800Sstevel@tonic-gate 	uint32_t	rt_finiarray;
7810Sstevel@tonic-gate 	uint32_t	rt_preinitarray;
7820Sstevel@tonic-gate 	uint32_t	rt_mmaps;
7830Sstevel@tonic-gate 	uint32_t	rt_mmapcnt;
7840Sstevel@tonic-gate 	uint32_t	rt_initarraysz;
7850Sstevel@tonic-gate 	uint32_t	rt_finiarraysz;
7860Sstevel@tonic-gate 	uint32_t	rt_preinitarraysz;
7870Sstevel@tonic-gate 	uint32_t 	rt_dyninfo;
7880Sstevel@tonic-gate 	uint32_t 	rt_dyninfocnt;
7890Sstevel@tonic-gate 	uint32_t	rt_relacount;
7900Sstevel@tonic-gate 	uint32_t	rt_idx;
7910Sstevel@tonic-gate 	uint32_t	rt_lazy;
79211827SRod.Evans@Sun.COM 	uint32_t	rt_cap;
79311827SRod.Evans@Sun.COM 	uint32_t	rt_capchain;
7940Sstevel@tonic-gate 	uint32_t	rt_cntl;
7958598SRod.Evans@Sun.COM 	uint32_t	rt_aflags;
7968598SRod.Evans@Sun.COM 	uint32_t 	rt_init;
7978598SRod.Evans@Sun.COM 	uint32_t	rt_fini;
7988598SRod.Evans@Sun.COM 	uint32_t	rt_symintp;
7990Sstevel@tonic-gate } Rt_map32;
8000Sstevel@tonic-gate 
8010Sstevel@tonic-gate #endif	/* _SYSCALL32 */
8020Sstevel@tonic-gate 
8030Sstevel@tonic-gate /*
8040Sstevel@tonic-gate  * Link map state flags.
8050Sstevel@tonic-gate  */
8060Sstevel@tonic-gate /*
8070Sstevel@tonic-gate  * BEGIN: Exposed to rtld_db - don't move, don't delete
8080Sstevel@tonic-gate  */
8090Sstevel@tonic-gate #define	FLG_RT_ISMAIN	0x00000001	/* object represents main executable */
8100Sstevel@tonic-gate #define	FLG_RT_IMGALLOC	0x00000002	/* image is allocated (not mmap'ed) */
8110Sstevel@tonic-gate 	/*
8128598SRod.Evans@Sun.COM 	 * Available for r_debug version >= R_RTLDDB_VERSION5
8130Sstevel@tonic-gate 	 */
8140Sstevel@tonic-gate #define	FLG_RT_RELOCED	0x00000004	/* object has been relocated */
8150Sstevel@tonic-gate /*
8160Sstevel@tonic-gate  * END: Exposed to rtld_db - don't move, don't delete
8170Sstevel@tonic-gate  */
8180Sstevel@tonic-gate #define	FLG_RT_SETGROUP	0x00000008	/* group establishment required */
81911827SRod.Evans@Sun.COM #define	FLG_RT_CAP	0x00000010	/* process $CAPABILITY expansion */
8200Sstevel@tonic-gate #define	FLG_RT_OBJECT	0x00000020	/* object processing (ie. .o's) */
82164Srie #define	FLG_RT_NEWLOAD	0x00000040	/* object is newly loaded */
8220Sstevel@tonic-gate #define	FLG_RT_NODUMP	0x00000080	/* object can't be dldump(3x)'ed */
8230Sstevel@tonic-gate #define	FLG_RT_DELETE	0x00000100	/* object can be deleted */
8240Sstevel@tonic-gate #define	FLG_RT_ANALYZED	0x00000200	/* object has been analyzed */
8250Sstevel@tonic-gate #define	FLG_RT_INITDONE	0x00000400	/* objects .init has been completed */
8260Sstevel@tonic-gate #define	FLG_RT_TRANS	0x00000800	/* object is acting as a translator */
8270Sstevel@tonic-gate #define	FLG_RT_FIXED	0x00001000	/* image location is fixed */
8280Sstevel@tonic-gate #define	FLG_RT_PRELOAD	0x00002000	/* object was preloaded */
8290Sstevel@tonic-gate #define	FLG_RT_ALTER	0x00004000	/* alternative object used */
8300Sstevel@tonic-gate #define	FLG_RT_LOADFLTR	0x00008000	/* trigger filtee loading */
8310Sstevel@tonic-gate #define	FLG_RT_AUDIT	0x00010000	/* object is an auditor */
8320Sstevel@tonic-gate #define	FLG_RT_MODESET	0x00020000	/* MODE() has been initialized */
8330Sstevel@tonic-gate #define	FLG_RT_ANALZING	0x00040000	/* object is being analyzed */
8340Sstevel@tonic-gate #define	FLG_RT_INITFRST 0x00080000	/* execute .init first */
8350Sstevel@tonic-gate #define	FLG_RT_NOOPEN	0x00100000	/* dlopen() not allowed */
8360Sstevel@tonic-gate #define	FLG_RT_FINICLCT	0x00200000	/* fini has been collected (tsort) */
8370Sstevel@tonic-gate #define	FLG_RT_INITCALL	0x00400000	/* objects .init has been called */
8388159SAli.Bahrami@Sun.COM #define	FLG_RT_OBJINTPO	0x00800000	/* object is a global interposer */
8398159SAli.Bahrami@Sun.COM #define	FLG_RT_SYMINTPO	0x01000000	/* object contains symbol interposer */
8408159SAli.Bahrami@Sun.COM #define	MSK_RT_INTPOSE	0x01800000	/* mask for all interposer */
8413466Srie 					/*	possibilities */
8428159SAli.Bahrami@Sun.COM #define	FLG_RT_MOVE	0x02000000	/* object needs move operation */
8439577SRod.Evans@Sun.COM #define	FLG_RT_RELOCING	0x04000000	/* object is being relocated */
8448159SAli.Bahrami@Sun.COM #define	FLG_RT_REGSYMS	0x08000000	/* object has DT_REGISTER entries */
8458159SAli.Bahrami@Sun.COM #define	FLG_RT_INITCLCT	0x10000000	/* init has been collected (tsort) */
8469577SRod.Evans@Sun.COM #define	FLG_RT_PUBHDL	0x20000000	/* generate a handle for this object */
8479577SRod.Evans@Sun.COM #define	FLG_RT_PRIHDL	0x40000000	/*	either public or private */
8480Sstevel@tonic-gate 
8490Sstevel@tonic-gate #define	FL1_RT_COPYTOOK	0x00000001	/* copy relocation taken */
85011827SRod.Evans@Sun.COM #define	FL1_RT_ALTCHECK	0x00000002	/* alternative system capabilities */
85111827SRod.Evans@Sun.COM 					/*	checked */
85211827SRod.Evans@Sun.COM #define	FL1_RT_ALTCAP	0x00000004	/* alternative system capabilities */
85311827SRod.Evans@Sun.COM 					/*	should be used */
85411827SRod.Evans@Sun.COM #define	FL1_RT_CONFSET	0x00000008	/* object was loaded by crle(1) */
85511827SRod.Evans@Sun.COM #define	FL1_RT_NODEFLIB	0x00000010	/* ignore default library search */
85611827SRod.Evans@Sun.COM #define	FL1_RT_ENDFILTE	0x00000020	/* filtee terminates filters search */
85711827SRod.Evans@Sun.COM #define	FL1_RT_DISPREL	0x00000040	/* object has *disp* relocation */
85811827SRod.Evans@Sun.COM #define	FL1_RT_DTFLAGS	0x00000080	/* DT_FLAGS element exists */
8590Sstevel@tonic-gate #define	FL1_RT_LDDSTUB	0x00000100	/* identify lddstub */
8600Sstevel@tonic-gate #define	FL1_RT_NOINIFIN	0x00000200	/* no .init or .fini exists */
8610Sstevel@tonic-gate #define	FL1_RT_USED	0x00000400	/* symbol referenced from this object */
8620Sstevel@tonic-gate #define	FL1_RT_SYMBOLIC	0x00000800	/* DF_SYMBOLIC was set - use */
8630Sstevel@tonic-gate 					/*	symbolic sym resolution */
8640Sstevel@tonic-gate #define	FL1_RT_OBJSFLTR	0x00001000	/* object is acting as a standard */
8650Sstevel@tonic-gate #define	FL1_RT_OBJAFLTR	0x00002000	/*	or auxiliary filter */
8660Sstevel@tonic-gate #define	FL1_RT_SYMSFLTR	0x00004000	/* symbol is acting as a standard */
8670Sstevel@tonic-gate #define	FL1_RT_SYMAFLTR	0x00008000	/*	or auxiliary filter */
8685067Srie #define	MSK_RT_FILTER	0x0000f000	/* mask for all filter possibilities */
8690Sstevel@tonic-gate 
8701824Srie #define	FL1_RT_TLSADD	0x00010000	/* objects TLS has been registered */
8712145Srie #define	FL1_RT_TLSSTAT	0x00020000	/* object requires static TLS */
8723466Srie #define	FL1_RT_DIRECT	0x00040000	/* object has DIRECT bindings enabled */
8734679Srie #define	FL1_RT_GLOBAUD	0x00080000	/* establish global auditing */
8741824Srie 
8750Sstevel@tonic-gate /*
8760Sstevel@tonic-gate  * Flags for the tls_modactivity() routine
8770Sstevel@tonic-gate  */
8780Sstevel@tonic-gate #define	TM_FLG_MODADD	0x01		/* call tls_modadd() interface */
8790Sstevel@tonic-gate #define	TM_FLG_MODREM	0x02		/* call tls_modrem() interface */
8800Sstevel@tonic-gate 
8810Sstevel@tonic-gate /*
8828598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION <= 2).
8830Sstevel@tonic-gate  */
8840Sstevel@tonic-gate #define	ADDR(X)		((X)->rt_public.l_addr)
8850Sstevel@tonic-gate #define	NAME(X)		((X)->rt_public.l_name)
8860Sstevel@tonic-gate #define	DYN(X)		((X)->rt_public.l_ld)
8870Sstevel@tonic-gate #define	NEXT(X)		((X)->rt_public.l_next)
8880Sstevel@tonic-gate #define	PREV(X)		((X)->rt_public.l_prev)
8890Sstevel@tonic-gate #define	REFNAME(X)	((X)->rt_public.l_refname)
8900Sstevel@tonic-gate 
8910Sstevel@tonic-gate /*
8928394SAli.Bahrami@Sun.COM  * An Rt_map starts with a Link_map, followed by other information.
8938394SAli.Bahrami@Sun.COM  * ld.so.1 allocates Rt_map structures, and then casts them to Link_map,
8948394SAli.Bahrami@Sun.COM  * and back, depending on context.
8958394SAli.Bahrami@Sun.COM  *
8968394SAli.Bahrami@Sun.COM  * On some platforms, Rt_map can have a higher alignment requirement
8978394SAli.Bahrami@Sun.COM  * than Link_map. On such platforms, the cast from Link_map to Rt_map will
8988394SAli.Bahrami@Sun.COM  * draw an E_BAD_PTR_CAST_ALIGN warning from lint. Since we allocate
8998394SAli.Bahrami@Sun.COM  * the memory as the higher alignment Rt_map, we know that this is a safe
9008394SAli.Bahrami@Sun.COM  * conversion. The LINKMAP_TO_RTMAP macro is used to handle the conversion
9018394SAli.Bahrami@Sun.COM  * in a manner that satisfies lint.
9028394SAli.Bahrami@Sun.COM  */
9038394SAli.Bahrami@Sun.COM #ifdef lint
9048394SAli.Bahrami@Sun.COM #define	LINKMAP_TO_RTMAP(X)	(Rt_map *)(void *)(X)
9058394SAli.Bahrami@Sun.COM #else
9068394SAli.Bahrami@Sun.COM #define	LINKMAP_TO_RTMAP(X)	(Rt_map *)(X)
9078394SAli.Bahrami@Sun.COM #endif
9088394SAli.Bahrami@Sun.COM 
9098394SAli.Bahrami@Sun.COM /*
9108394SAli.Bahrami@Sun.COM  * Convenience macros for the common case of using
9118394SAli.Bahrami@Sun.COM  * NEXT()/PREV() and casting the result to (Rt_map *)
9128394SAli.Bahrami@Sun.COM  */
9138394SAli.Bahrami@Sun.COM #define	NEXT_RT_MAP(X)	LINKMAP_TO_RTMAP(NEXT(X))
9148394SAli.Bahrami@Sun.COM #define	PREV_RT_MAP(X)	LINKMAP_TO_RTMAP(PREV(X))
9158394SAli.Bahrami@Sun.COM 
9168394SAli.Bahrami@Sun.COM /*
9178598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION3).
9180Sstevel@tonic-gate  */
9190Sstevel@tonic-gate #define	PATHNAME(X)	((X)->rt_pathname)
9200Sstevel@tonic-gate #define	PADSTART(X)	((X)->rt_padstart)
9210Sstevel@tonic-gate #define	PADIMLEN(X)	((X)->rt_padimlen)
9220Sstevel@tonic-gate #define	MSIZE(X)	((X)->rt_msize)
9230Sstevel@tonic-gate #define	FLAGS(X)	((X)->rt_flags)
9240Sstevel@tonic-gate #define	FLAGS1(X)	((X)->rt_flags1)
9258598SRod.Evans@Sun.COM 
9268598SRod.Evans@Sun.COM /*
9278598SRod.Evans@Sun.COM  * Macros for getting to exposed, link_map data (R_RTLDDB_VERSION4).
9288598SRod.Evans@Sun.COM  */
9290Sstevel@tonic-gate #define	TLSMODID(X)	((X)->rt_tlsmodid)
9300Sstevel@tonic-gate 
9318598SRod.Evans@Sun.COM /*
9328598SRod.Evans@Sun.COM  * Macros for getting to unexposed, link-map data.
9338598SRod.Evans@Sun.COM  */
9348598SRod.Evans@Sun.COM #define	LMSIZE(X)	((X)->rt_lmsize)
9358598SRod.Evans@Sun.COM #define	AFLAGS(X)	((X)->rt_aflags)
9360Sstevel@tonic-gate #define	ALIAS(X)	((X)->rt_alias)
9370Sstevel@tonic-gate #define	FPNODE(X)	((X)->rt_fpnode)
9380Sstevel@tonic-gate #define	INIT(X)		((X)->rt_init)
9390Sstevel@tonic-gate #define	FINI(X)		((X)->rt_fini)
9400Sstevel@tonic-gate #define	RPATH(X)	((X)->rt_runpath)
9410Sstevel@tonic-gate #define	RLIST(X)	((X)->rt_runlist)
9420Sstevel@tonic-gate #define	DEPENDS(X)	((X)->rt_depends)
9430Sstevel@tonic-gate #define	CALLERS(X)	((X)->rt_callers)
9440Sstevel@tonic-gate #define	HANDLES(X)	((X)->rt_handles)
9450Sstevel@tonic-gate #define	GROUPS(X)	((X)->rt_groups)
9460Sstevel@tonic-gate #define	FCT(X)		((X)->rt_fct)
9470Sstevel@tonic-gate #define	SYMINTP(X)	((X)->rt_symintp)
9480Sstevel@tonic-gate #define	LIST(X)		((X)->rt_list)
9490Sstevel@tonic-gate #define	OBJFLTRNDX(X)	((X)->rt_objfltrndx)
9500Sstevel@tonic-gate #define	SYMSFLTRCNT(X)	((X)->rt_symsfltrcnt)
9510Sstevel@tonic-gate #define	SYMAFLTRCNT(X)	((X)->rt_symafltrcnt)
9520Sstevel@tonic-gate #define	MODE(X)		((X)->rt_mode)
9530Sstevel@tonic-gate #define	SORTVAL(X)	((X)->rt_sortval)
9540Sstevel@tonic-gate #define	CYCGROUP(X)	((X)->rt_cycgroup)
9550Sstevel@tonic-gate #define	STDEV(X)	((X)->rt_stdev)
9560Sstevel@tonic-gate #define	STINO(X)	((X)->rt_stino)
9570Sstevel@tonic-gate #define	ORIGNAME(X)	((X)->rt_origname)
9580Sstevel@tonic-gate #define	DIRSZ(X)	((X)->rt_dirsz)
9595892Sab196087 #define	COPY_R(X)	((X)->rt_copy.rtc_r)
9605892Sab196087 #define	COPY_S(X)	((X)->rt_copy.rtc_s)
9610Sstevel@tonic-gate #define	AUDITORS(X)	((X)->rt_auditors)
9620Sstevel@tonic-gate #define	AUDINFO(X)	((X)->rt_audinfo)
9630Sstevel@tonic-gate #define	SYMINFO(X)	((X)->rt_syminfo)
9640Sstevel@tonic-gate #define	INITARRAY(X)	((X)->rt_initarray)
9650Sstevel@tonic-gate #define	FINIARRAY(X)	((X)->rt_finiarray)
9660Sstevel@tonic-gate #define	PREINITARRAY(X)	((X)->rt_preinitarray)
9670Sstevel@tonic-gate #define	MMAPS(X)	((X)->rt_mmaps)
9680Sstevel@tonic-gate #define	MMAPCNT(X)	((X)->rt_mmapcnt)
9690Sstevel@tonic-gate #define	INITARRAYSZ(X)	((X)->rt_initarraysz)
9700Sstevel@tonic-gate #define	FINIARRAYSZ(X)	((X)->rt_finiarraysz)
9710Sstevel@tonic-gate #define	PREINITARRAYSZ(X) ((X)->rt_preinitarraysz)
9720Sstevel@tonic-gate #define	DYNINFO(X)	((X)->rt_dyninfo)
9730Sstevel@tonic-gate #define	DYNINFOCNT(X)	((X)->rt_dyninfocnt)
9740Sstevel@tonic-gate #define	RELACOUNT(X)	((X)->rt_relacount)
9750Sstevel@tonic-gate #define	IDX(X)		((X)->rt_idx)
9760Sstevel@tonic-gate #define	LAZY(X)		((X)->rt_lazy)
9770Sstevel@tonic-gate #define	CNTL(X)		((X)->rt_cntl)
97811827SRod.Evans@Sun.COM #define	CAP(X)		((X)->rt_cap)
97911827SRod.Evans@Sun.COM #define	CAPCHAIN(X)	((X)->rt_capchain)
9800Sstevel@tonic-gate 
981280Srie /*
982280Srie  * Flags for tsorting.
983280Srie  */
984280Srie #define	RT_SORT_FWD	0x01		/* topological sort (.fini) */
985280Srie #define	RT_SORT_REV	0x02		/* reverse topological sort (.init) */
9868598SRod.Evans@Sun.COM #define	RT_SORT_DELETE	0x10		/* process FLG_RT_DELETE objects */
987280Srie 					/*	only (called via dlclose()) */
9883817Srie #define	RT_SORT_INTPOSE	0x20		/* process interposer objects */
9893817Srie 
9900Sstevel@tonic-gate /*
9910Sstevel@tonic-gate  * Flags for lookup_sym (and hence find_sym) routines.
9920Sstevel@tonic-gate  */
9930Sstevel@tonic-gate #define	LKUP_DEFT	0x0000		/* simple lookup request */
9940Sstevel@tonic-gate #define	LKUP_SPEC	0x0001		/* special ELF lookup (allows address */
9950Sstevel@tonic-gate 					/*	resolutions to plt[] entries) */
9960Sstevel@tonic-gate #define	LKUP_LDOT	0x0002		/* indicates the original A_OUT */
9970Sstevel@tonic-gate 					/*	symbol had a leading `.' */
9980Sstevel@tonic-gate #define	LKUP_FIRST	0x0004		/* lookup symbol in first link map */
9990Sstevel@tonic-gate 					/*	only */
10000Sstevel@tonic-gate #define	LKUP_COPY	0x0008		/* lookup symbol for a COPY reloc, do */
10010Sstevel@tonic-gate 					/*	not bind to symbol at head */
10025220Srie #define	LKUP_STDRELOC	0x0010		/* lookup originates from a standard */
10035220Srie 					/*	relocation (elf_reloc()) */
10040Sstevel@tonic-gate #define	LKUP_SELF	0x0020		/* lookup symbol in ourself - undef */
10050Sstevel@tonic-gate 					/*	is valid */
10060Sstevel@tonic-gate #define	LKUP_WEAK	0x0040		/* relocation reference is weak */
10070Sstevel@tonic-gate #define	LKUP_NEXT	0x0080		/* request originates from RTLD_NEXT */
10080Sstevel@tonic-gate #define	LKUP_NODESCENT	0x0100		/* don't descend through dependencies */
10095950Srie #define	LKUP_NOFALLBACK	0x0200		/* don't fall back to loading */
10100Sstevel@tonic-gate 					/*	pending lazy dependencies */
10110Sstevel@tonic-gate #define	LKUP_DIRECT	0x0400		/* direct binding request */
1012502Srie #define	LKUP_SYMNDX	0x0800		/* establish symbol index */
10135220Srie #define	LKUP_SINGLETON	0x1000		/* search for a singleton symbol */
10145220Srie #define	LKUP_STANDARD	0x2000		/* standard lookup - originated from */
10155220Srie 					/* 	head link-map element */
10168388SRod.Evans@Sun.COM #define	LKUP_WORLD	0x4000		/* ensure world lookup */
101711827SRod.Evans@Sun.COM #define	LKUP_DLSYM	0x8000		/* lookup stems from dlsym() request */
10180Sstevel@tonic-gate 
10190Sstevel@tonic-gate /*
10205950Srie  * For the runtime linker to perform a symbol search, a number of data items
10215950Srie  * related to the search are required.  An Slookup data structure is used to
10225950Srie  * convey this data to lookup_sym(), and in special cases, to other core
10235950Srie  * routines that provide the implementation details for lookup_sym()
10245950Srie  *
10255950Srie  * The symbol name (sl_name), the caller (sl_cmap), and the link-map from which
10265950Srie  * to start the search (sl_imap) are fundamental to the symbol search.  The
10275950Srie  * initial search link-map might get modified by the core routines that provide
10285950Srie  * the implementation details for lookup_sym().  This modification accommodates
10295950Srie  * requirements such as processing a handle, direct binding and interposition.
10305950Srie  * The association between the caller and the potential destination also
10315950Srie  * determines whether the destination is a candidate to search.
10325950Srie  *
10335950Srie  * The lookup identifier (sl_id) is used to identify a runtime linker operation.
10345950Srie  * Within this operation, any lazy loads that fail are not re-examined.  This
10355950Srie  * technique keeps the overhead of processing a failed lazy load to a minimum.
10365950Srie  *
10375950Srie  * Symbol searches that originate from a relocation record are accompanied by
10385950Srie  * the relocation index (sl_rsymndx), the symbol reference (sl_rsym) and
10395950Srie  * possibly the relocation type (sl_rtype).  This data provides for determining
10405950Srie  * lazy loading, direct binding, and special symbol processing requirements
10415950Srie  * such as copy relocations and singleton lookup.
10425950Srie  *
10435950Srie  * The symbols hash value is computed by lookup_sym, and propagated throughout
10445950Srie  * the search engine.  Note, occasionally the Slookup data is passed to a core
10455950Srie  * routine that provides the implementation details for lookup_sym(), ie.
10465950Srie  * elf_find_sym(), in which case the caller must initialize the hash value.
10475950Srie  *
10485950Srie  * The symbols binding information is established by lookup_sym() when the
10495950Srie  * symbols relocation type is supplied.  Weak bindings allow relocations to
10505950Srie  * be set to zero should a symbol lookup fail.
10515950Srie  *
10525950Srie  * The flags allow the caller to control aspects of the search, including the
10535950Srie  * interpretation of copy relocations, etc.  Note, a number of flag settings
10545950Srie  * are established in lookup_sym() from attributes of the symbol reference.
10550Sstevel@tonic-gate  */
10568598SRod.Evans@Sun.COM struct slookup {
10570Sstevel@tonic-gate 	const char	*sl_name;	/* symbol name */
10580Sstevel@tonic-gate 	Rt_map		*sl_cmap;	/* callers link-map */
10590Sstevel@tonic-gate 	Rt_map		*sl_imap;	/* initial link-map to search */
10605950Srie 	ulong_t		sl_id;		/* identifier for this lookup */
10610Sstevel@tonic-gate 	ulong_t		sl_hash;	/* symbol hash value */
10620Sstevel@tonic-gate 	ulong_t		sl_rsymndx;	/* referencing reloc symndx */
10635220Srie 	Sym		*sl_rsym;	/* referencing symbol */
10645220Srie 	uchar_t		sl_rtype;	/* relocation type associate with */
10655220Srie 					/*    symbol */
10665220Srie 	uchar_t		sl_bind;	/* symbols binding (returned) */
10670Sstevel@tonic-gate 	uint_t		sl_flags;	/* lookup flags */
10688598SRod.Evans@Sun.COM };
10690Sstevel@tonic-gate 
10705950Srie #define	SLOOKUP_INIT(sl, name, cmap, imap, id, hash, rsymndx, rsym, rtype, \
10715950Srie     flags) \
10725950Srie 	(void) (sl.sl_name = (name), sl.sl_cmap = (cmap), sl.sl_imap = (imap), \
10735950Srie 	    sl.sl_id = (id), sl.sl_hash = (hash), sl.sl_rsymndx = (rsymndx), \
10745950Srie 	    sl.sl_rsym = (rsym), sl.sl_rtype = (rtype), sl.sl_bind = 0, \
10755950Srie 	    sl.sl_flags = (flags))
10760Sstevel@tonic-gate 
10775950Srie /*
107811827SRod.Evans@Sun.COM  * After a symbol lookup has been resolved, the runtime linker needs to retain
107911827SRod.Evans@Sun.COM  * information regarding the bound definition.  An Sresult data structure is
108011827SRod.Evans@Sun.COM  * used to provide this information.
108111827SRod.Evans@Sun.COM  *
108211827SRod.Evans@Sun.COM  * The symbol name (sr_name) may differ from the original referenced symbol if
108311827SRod.Evans@Sun.COM  * a symbol capabilities family member has resolved the binding.  The defining
108411827SRod.Evans@Sun.COM  * object (sr_dmap) indicates the object in which the definition has been found.
108511827SRod.Evans@Sun.COM  * The symbol table entry (sr_sym) defines the bound symbol definition.
108611827SRod.Evans@Sun.COM  *
108711827SRod.Evans@Sun.COM  * Note, a symbol lookup may start with one Sresult buffer, but underlying
108811827SRod.Evans@Sun.COM  * routines (for example, those that probe filters) might employ their own
108911827SRod.Evans@Sun.COM  * Sresult buffer.  If a binding is allowed, the latter buffer may get inherited
109011827SRod.Evans@Sun.COM  * by the former.  Along with this chain of requests, binding info (binfo) and
109111827SRod.Evans@Sun.COM  * not-found information (in_nfavl), may be passed between all the associated
109211827SRod.Evans@Sun.COM  * functions.  Hence, the binfo and in_nfavl data is not maintained as part of
109311827SRod.Evans@Sun.COM  * a Sresult structure.
109411827SRod.Evans@Sun.COM  */
109511827SRod.Evans@Sun.COM struct sresult {
109611827SRod.Evans@Sun.COM 	const char	*sr_name;	/* symbol definition name */
109711827SRod.Evans@Sun.COM 	Rt_map		*sr_dmap;	/* defining objects link-map */
109811827SRod.Evans@Sun.COM 	Sym		*sr_sym;	/* symbol table pointer */
109911827SRod.Evans@Sun.COM };
110011827SRod.Evans@Sun.COM 
110111827SRod.Evans@Sun.COM #define	SRESULT_INIT(sr, name) \
110211827SRod.Evans@Sun.COM 	(void) (sr.sr_name = (name), sr.sr_dmap = NULL, sr.sr_sym = NULL)
110311827SRod.Evans@Sun.COM 
110411827SRod.Evans@Sun.COM /*
110511827SRod.Evans@Sun.COM  * Define a system capabilities structure for maintaining the various
110611827SRod.Evans@Sun.COM  * capabilities of the system.  This structure follows the Objcapset definition
110711827SRod.Evans@Sun.COM  * from libld.h, however the system can only have one platform or machine
110811827SRod.Evans@Sun.COM  * hardware name, thus this structure is a little simpler.
110911827SRod.Evans@Sun.COM  */
111011827SRod.Evans@Sun.COM typedef	struct {
111111827SRod.Evans@Sun.COM 	elfcap_mask_t	sc_hw_1;	/* CA_SUNW_HW_1 capabilities */
111211827SRod.Evans@Sun.COM 	elfcap_mask_t	sc_sf_1;	/* CA_SUNW_SF_1 capabilities */
111311827SRod.Evans@Sun.COM 	elfcap_mask_t	sc_hw_2;	/* CA_SUNW_HW_2 capabilities */
111411827SRod.Evans@Sun.COM 	char		*sc_plat;	/* CA_SUNW_PLAT capability */
111511827SRod.Evans@Sun.COM 	size_t		sc_platsz;	/*	and size */
111611827SRod.Evans@Sun.COM 	char		*sc_mach;	/* CA_SUNW_MACH capability */
111711827SRod.Evans@Sun.COM 	size_t		sc_machsz;	/*	and size */
111811827SRod.Evans@Sun.COM } Syscapset;
111911827SRod.Evans@Sun.COM 
112011827SRod.Evans@Sun.COM /*
11215950Srie  * Define a number of .plt lookup outcomes, for use in binding diagnostics.
11225950Srie  */
11230Sstevel@tonic-gate typedef	enum {
11240Sstevel@tonic-gate 	PLT_T_NONE = 0,
11250Sstevel@tonic-gate 	PLT_T_21D,
11260Sstevel@tonic-gate 	PLT_T_24D,
11270Sstevel@tonic-gate 	PLT_T_U32,
11280Sstevel@tonic-gate 	PLT_T_U44,
11290Sstevel@tonic-gate 	PLT_T_FULL,
11300Sstevel@tonic-gate 	PLT_T_FAR,
11310Sstevel@tonic-gate 	PLT_T_NUM			/* Must be last */
11320Sstevel@tonic-gate } Pltbindtype;
11330Sstevel@tonic-gate 
11340Sstevel@tonic-gate /*
11350Sstevel@tonic-gate  * Prototypes.
11360Sstevel@tonic-gate  */
11375950Srie extern ulong_t		ld_entry_cnt;	/* counter bumped on each entry to */
11385950Srie 					/*    ld.so.1. */
11390Sstevel@tonic-gate extern Lm_list		lml_main;	/* main's link map list */
11400Sstevel@tonic-gate extern Lm_list		lml_rtld;	/* rtld's link map list */
11410Sstevel@tonic-gate extern Lm_list		*lml_list[];
11420Sstevel@tonic-gate 
11430Sstevel@tonic-gate extern Pltbindtype	elf_plt_write(uintptr_t, uintptr_t, void *, uintptr_t,
11440Sstevel@tonic-gate 			    Xword);
11456387Srie extern Rt_map		*is_so_loaded(Lm_list *, const char *, int *);
114611827SRod.Evans@Sun.COM extern int		lookup_sym(Slookup *, Sresult *, uint_t *, int *);
11470Sstevel@tonic-gate extern int		rt_dldump(Rt_map *, const char *, int, Addr);
11480Sstevel@tonic-gate 
11490Sstevel@tonic-gate #ifdef	__cplusplus
11500Sstevel@tonic-gate }
11510Sstevel@tonic-gate #endif
11520Sstevel@tonic-gate 
11530Sstevel@tonic-gate #endif /* _RTLD_H */
1154