xref: /titanic_51/usr/src/cmd/sgs/rtld/common/globals.c (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  *
27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include	<sys/types.h>
33 #include	<sys/mman.h>
34 #include	<signal.h>
35 #include	<dlfcn.h>
36 #include	<synch.h>
37 #include	"_rtld.h"
38 
39 /*
40  * Declarations of global variables used in ld.so.
41  */
42 Rt_lock		rtldlock;
43 
44 /*
45  * Major link-map lists.
46  */
47 Lm_list		lml_main =	{ 0 };		/* the `main's link map list */
48 Lm_list		lml_rtld =	{ 0 };		/* rtld's link map list */
49 
50 /*
51  * BEGIN: Exposed to rtld_db, don't change without a coordinated handshake with
52  * librtld_db (remembering that librtld_db must be able to read old as well as
53  * current core files).
54  */
55 List		dynlm_list =	{ 0, 0 };	/* dynamic list of link-maps */
56 /*
57  * END: Exposed to rtld_db
58  */
59 
60 Reglist *	reglist = 0;			/* list of register symbols */
61 
62 void		(*thrinit)() = 0;		/* thread initialization */
63 
64 ulong_t		hwcap = 0;			/* hardware capabilities */
65 ulong_t		sfcap = 0;			/* software capabilities */
66 
67 /*
68  * Initialized fmap structure.
69  */
70 static Fmap	_fmap = { 0, 0, 0, 0, 0 };
71 Fmap *		fmap = &_fmap;			/* initial file mapping info */
72 
73 /*
74  * Set of integers to track how many of what type of
75  * PLT's have been bound.  This is only really interesting
76  * for SPARC since ia32 basically just has the one PLT.
77  */
78 uint32_t	pltcnt21d = 0;
79 uint32_t	pltcnt24d = 0;
80 uint32_t	pltcntu32 = 0;
81 uint32_t	pltcntu44 = 0;
82 uint32_t	pltcntfull = 0;
83 uint32_t	pltcntfar = 0;
84 
85 /*
86  * Enable technology (via status flags for RTLD) dependent upon whether we're
87  * in a patch or major release build environment.
88  */
89 uint_t		rtld_flags =
90 #ifdef	EXPAND_RELATIVE
91 			RT_FL_RELATIVE |
92 #endif
93 #ifdef	SIEBEL_DISABLE
94 			RT_FL_DISFIX_1 |
95 #endif
96 			RT_FL_NOCONCUR;
97 uint_t		rtld_flags2 = 0;
98 
99 /*
100  * Various other global data.
101  */
102 const char	*procname = (const char *)0;
103 const char	*rtldname = MSG_ORIG(MSG_FIL_RTLD);
104 
105 char		*lasterr = (char *)0;	/* string describing last error */
106 					/*	cleared by each dlerror() */
107 Interp		*interp = 0;		/* ELF interpreter info */
108 List		hdl_list[HDLIST_SZ+2];	/* dlopen() handle list */
109 size_t		syspagsz = 0;		/* system page size */
110 unsigned long	at_flags = 0;		/* machine specific file flags */
111 char		*platform = 0;		/* platform name from AT_SUN_PLATFORM */
112 size_t		platform_sz = 0;	/* platform string length */
113 Uts_desc	*uts;			/* utsname descriptor */
114 Isa_desc	*isa;			/* isalist descriptor */
115 
116 uint_t		audit_argcnt = 64;	/* no. of stack args to copy (default */
117 					/*	is all) */
118 Audit_desc	*auditors = 0;		/* global auditors (LD_AUDIT) */
119 
120 const char	*locale = 0;		/* locale environment definition */
121 
122 const char	*rpl_audit = 0;		/* replaceable LD_AUDIT string */
123 const char	*rpl_debug = 0;		/* replaceable LD_DEBUG string */
124 const char	*rpl_ldflags = 0;	/* replaceable LD_FLAGS string */
125 const char	*rpl_libpath = 0;	/* replaceable LD_LIBRARY_PATH string */
126 Pnode		*rpl_libdirs = 0;	/*	and associated Pnode list */
127 const char	*rpl_preload = 0;	/* replaceable LD_PRELOAD string */
128 
129 const char	*prm_audit = 0;		/* permanent LD_AUDIT string */
130 const char	*prm_debug = 0;		/* permanent LD_DEBUG string */
131 const char	*prm_ldflags = 0;	/* permanent LD_FLAGS string */
132 const char	*prm_libpath = 0;	/* permanent LD_LIBRARY_PATH string */
133 Pnode		*prm_libdirs = 0;	/*	and associated Pnode list */
134 const char	*prm_preload = 0;	/* permanent LD_PRELOAD string */
135 
136 uint_t		env_info = 0;		/* information regarding environment */
137 					/*	variables */
138 int		killsig = SIGKILL;	/* signal sent on fatal exit */
139 uint_t		dbg_mask;		/* debugging classes */
140 const char	*dbg_file = 0;		/* debugging directed to file */
141 
142 #pragma weak	environ = _environ	/* environ for PLT tracing - we */
143 char		**_environ = 0;		/* supply the pair to satisfy any */
144 					/* libc requirements (hwmuldiv) */
145 
146 const char	*profile_name;		/* object being profiled */
147 const char	*profile_out;		/* profile output file */
148 const char	*profile_lib;		/* audit library to perform profile */
149 
150 unsigned char	search_rules[] = {	/* dependency search rules */
151 		RPLENV,			/*	replaceable LD_LIBRARY_PATH */
152 		PRMENV,			/*	permanent LD_LIBRARY_PATH */
153 		RUNPATH,		/*	callers runpath */
154 		DEFAULT,		/*	default library path */
155 		0
156 };
157 
158 Dl_argsinfo	argsinfo = { 0 };	/* process argument, environment and */
159 					/*	auxv information. */
160 
161 /*
162  * Frequently used messages are cached here to reduce _dgettext() overhead and
163  * also provide for resetting should the locale change (see _ld_libc()).
164  */
165 const char	*err_strs[ERR_NUM] = { 0 };
166 const char	*nosym_str = 0;
167 
168 
169 /*
170  * Rejection error message tables.
171  */
172 const Msg
173 ldd_reject[] = {
174 		MSG_STR_EMPTY,
175 		MSG_LDD_REJ_MACH,	/* MSG_INTL(MSG_LDD_REJ_MACH) */
176 		MSG_LDD_REJ_CLASS,	/* MSG_INTL(MSG_LDD_REJ_CLASS) */
177 		MSG_LDD_REJ_DATA,	/* MSG_INTL(MSG_LDD_REJ_DATA) */
178 		MSG_LDD_REJ_TYPE,	/* MSG_INTL(MSG_LDD_REJ_TYPE) */
179 		MSG_LDD_REJ_BADFLAG,	/* MSG_INTL(MSG_LDD_REJ_BADFLAG) */
180 		MSG_LDD_REJ_MISFLAG,	/* MSG_INTL(MSG_LDD_REJ_MISFLAG) */
181 		MSG_LDD_REJ_VERSION,	/* MSG_INTL(MSG_LDD_REJ_VERSION) */
182 		MSG_LDD_REJ_HAL,	/* MSG_INTL(MSG_LDD_REJ_HAL) */
183 		MSG_LDD_REJ_US3,	/* MSG_INTL(MSG_LDD_REJ_US3) */
184 		MSG_LDD_REJ_STR,	/* MSG_INTL(MSG_LDD_REJ_STR) */
185 		MSG_LDD_REJ_UNKFILE,	/* MSG_INTL(MSG_LDD_REJ_UNKFILE) */
186 		MSG_LDD_REJ_HWCAP_1,	/* MSG_INTL(MSG_LDD_REJ_HWCAP_1) */
187 	};
188 
189 
190 const Msg
191 err_reject[] = {
192 		MSG_STR_EMPTY,
193 		MSG_ERR_REJ_MACH,	/* MSG_INTL(MSG_ERR_REJ_MACH) */
194 		MSG_ERR_REJ_CLASS,	/* MSG_INTL(MSG_ERR_REJ_CLASS) */
195 		MSG_ERR_REJ_DATA,	/* MSG_INTL(MSG_ERR_REJ_DATA) */
196 		MSG_ERR_REJ_TYPE,	/* MSG_INTL(MSG_ERR_REJ_TYPE) */
197 		MSG_ERR_REJ_BADFLAG,	/* MSG_INTL(MSG_ERR_REJ_BADFLAG) */
198 		MSG_ERR_REJ_MISFLAG,	/* MSG_INTL(MSG_ERR_REJ_MISFLAG) */
199 		MSG_ERR_REJ_VERSION,	/* MSG_INTL(MSG_ERR_REJ_VERSION) */
200 		MSG_ERR_REJ_HAL,	/* MSG_INTL(MSG_ERR_REJ_HAL) */
201 		MSG_ERR_REJ_US3,	/* MSG_INTL(MSG_ERR_REJ_US3) */
202 		MSG_ERR_REJ_STR,	/* MSG_INTL(MSG_ERR_REJ_STR) */
203 		MSG_ERR_REJ_UNKFILE,	/* MSG_INTL(MSG_ERR_REJ_UNKFILE) */
204 		MSG_ERR_REJ_HWCAP_1,	/* MSG_INTL(MSG_ERR_REJ_HWCAP_1) */
205 	};
206