xref: /titanic_52/usr/src/cmd/sgs/rtld/common/globals.c (revision 0eb822a1c0c2bea495647510b75f77f0e57633eb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  *	Copyright (c) 1988 AT&T
23  *	  All Rights Reserved
24  *
25  *
26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include	<sys/types.h>
32 #include	<sys/mman.h>
33 #include	<signal.h>
34 #include	<dlfcn.h>
35 #include	<synch.h>
36 #include	<debug.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 ulong_t		hwcap = 0;			/* hardware capabilities */
63 ulong_t		sfcap = 0;			/* software capabilities */
64 
65 /*
66  * Initialized fmap structure.
67  */
68 static Fmap	_fmap = { 0, 0, 0, 0, 0 };
69 Fmap *		fmap = &_fmap;			/* initial file mapping info */
70 
71 /*
72  * Set of integers to track how many of what type of
73  * PLT's have been bound.  This is only really interesting
74  * for SPARC since ia32 basically just has the one PLT.
75  */
76 uint32_t	pltcnt21d = 0;
77 uint32_t	pltcnt24d = 0;
78 uint32_t	pltcntu32 = 0;
79 uint32_t	pltcntu44 = 0;
80 uint32_t	pltcntfull = 0;
81 uint32_t	pltcntfar = 0;
82 
83 /*
84  * Enable technology (via status flags for RTLD) dependent upon whether we're
85  * in a patch or major release build environment.
86  */
87 uint_t		rtld_flags =
88 #ifdef	EXPAND_RELATIVE
89 			RT_FL_RELATIVE |
90 #endif
91 #ifdef	SIEBEL_DISABLE
92 			RT_FL_DISFIX_1 |
93 #endif
94 			RT_FL_NOCONCUR;
95 uint_t		rtld_flags2 = 0;
96 
97 /*
98  * Various other global data.
99  */
100 Lc_desc		glcs[CI_MAX];		/* global external interfaces */
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	*rpl_audit = 0;		/* replaceable LD_AUDIT string */
121 const char	*rpl_debug = 0;		/* replaceable LD_DEBUG string */
122 const char	*rpl_ldflags = 0;	/* replaceable LD_FLAGS string */
123 const char	*rpl_libpath = 0;	/* replaceable LD_LIBRARY_PATH string */
124 Pnode		*rpl_libdirs = 0;	/*	and associated Pnode list */
125 const char	*rpl_preload = 0;	/* replaceable LD_PRELOAD string */
126 
127 const char	*prm_audit = 0;		/* permanent LD_AUDIT string */
128 const char	*prm_debug = 0;		/* permanent LD_DEBUG string */
129 const char	*prm_ldflags = 0;	/* permanent LD_FLAGS string */
130 const char	*prm_libpath = 0;	/* permanent LD_LIBRARY_PATH string */
131 Pnode		*prm_libdirs = 0;	/*	and associated Pnode list */
132 const char	*prm_preload = 0;	/* permanent LD_PRELOAD string */
133 
134 uint_t		env_info = 0;		/* information regarding environment */
135 					/*	variables */
136 int		killsig = SIGKILL;	/* signal sent on fatal exit */
137 
138 /*
139  * Note, the debugging descriptor interposes on the default definition provided
140  * by liblddbg.  This is required as ld.so.1 must only have outstanding relative
141  * relocations.
142  */
143 static Dbg_desc	_dbg_desc = {0, 0, 0};
144 Dbg_desc	*dbg_desc = &_dbg_desc;	/* debugging descriptor */
145 const char	*dbg_file = 0;		/* debugging directed to file */
146 
147 #pragma weak	environ = _environ	/* environ for PLT tracing - we */
148 char		**_environ = 0;		/* supply the pair to satisfy any */
149 					/* libc requirements (hwmuldiv) */
150 
151 const char	*profile_name;		/* object being profiled */
152 const char	*profile_out;		/* profile output file */
153 const char	*profile_lib;		/* audit library to perform profile */
154 
155 unsigned char	search_rules[] = {	/* dependency search rules */
156 		RPLENV,			/*	replaceable LD_LIBRARY_PATH */
157 		PRMENV,			/*	permanent LD_LIBRARY_PATH */
158 		RUNPATH,		/*	callers runpath */
159 		DEFAULT,		/*	default library path */
160 		0
161 };
162 
163 Dl_argsinfo	argsinfo = { 0 };	/* process argument, environment and */
164 					/*	auxv information. */
165 
166 /*
167  * Frequently used messages are cached here to reduce _dgettext() overhead and
168  * also provide for resetting should the locale change (see _ld_libc()).
169  */
170 const char	*err_strs[ERR_NUM] = { 0 };
171 const char	*nosym_str = 0;
172 
173 
174 /*
175  * Rejection error message tables.
176  */
177 const Msg
178 ldd_reject[] = {
179 		MSG_STR_EMPTY,
180 		MSG_LDD_REJ_MACH,	/* MSG_INTL(MSG_LDD_REJ_MACH) */
181 		MSG_LDD_REJ_CLASS,	/* MSG_INTL(MSG_LDD_REJ_CLASS) */
182 		MSG_LDD_REJ_DATA,	/* MSG_INTL(MSG_LDD_REJ_DATA) */
183 		MSG_LDD_REJ_TYPE,	/* MSG_INTL(MSG_LDD_REJ_TYPE) */
184 		MSG_LDD_REJ_BADFLAG,	/* MSG_INTL(MSG_LDD_REJ_BADFLAG) */
185 		MSG_LDD_REJ_MISFLAG,	/* MSG_INTL(MSG_LDD_REJ_MISFLAG) */
186 		MSG_LDD_REJ_VERSION,	/* MSG_INTL(MSG_LDD_REJ_VERSION) */
187 		MSG_LDD_REJ_HAL,	/* MSG_INTL(MSG_LDD_REJ_HAL) */
188 		MSG_LDD_REJ_US3,	/* MSG_INTL(MSG_LDD_REJ_US3) */
189 		MSG_LDD_REJ_STR,	/* MSG_INTL(MSG_LDD_REJ_STR) */
190 		MSG_LDD_REJ_UNKFILE,	/* MSG_INTL(MSG_LDD_REJ_UNKFILE) */
191 		MSG_LDD_REJ_HWCAP_1,	/* MSG_INTL(MSG_LDD_REJ_HWCAP_1) */
192 	};
193 
194 
195 const Msg
196 err_reject[] = {
197 		MSG_STR_EMPTY,
198 		MSG_ERR_REJ_MACH,	/* MSG_INTL(MSG_ERR_REJ_MACH) */
199 		MSG_ERR_REJ_CLASS,	/* MSG_INTL(MSG_ERR_REJ_CLASS) */
200 		MSG_ERR_REJ_DATA,	/* MSG_INTL(MSG_ERR_REJ_DATA) */
201 		MSG_ERR_REJ_TYPE,	/* MSG_INTL(MSG_ERR_REJ_TYPE) */
202 		MSG_ERR_REJ_BADFLAG,	/* MSG_INTL(MSG_ERR_REJ_BADFLAG) */
203 		MSG_ERR_REJ_MISFLAG,	/* MSG_INTL(MSG_ERR_REJ_MISFLAG) */
204 		MSG_ERR_REJ_VERSION,	/* MSG_INTL(MSG_ERR_REJ_VERSION) */
205 		MSG_ERR_REJ_HAL,	/* MSG_INTL(MSG_ERR_REJ_HAL) */
206 		MSG_ERR_REJ_US3,	/* MSG_INTL(MSG_ERR_REJ_US3) */
207 		MSG_ERR_REJ_STR,	/* MSG_INTL(MSG_ERR_REJ_STR) */
208 		MSG_ERR_REJ_UNKFILE,	/* MSG_INTL(MSG_ERR_REJ_UNKFILE) */
209 		MSG_ERR_REJ_HWCAP_1,	/* MSG_INTL(MSG_ERR_REJ_HWCAP_1) */
210 	};
211