globals.c revision 6515:10dab2b883e0
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 2008 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 */
42Rt_lock		rtldlock;
43int		thr_flg_nolock = 0;
44int		thr_flg_reenter = 0;
45
46/*
47 * Major link-map lists.
48 */
49Lm_list		lml_main =	{ 0 };		/* the `main's link map list */
50Lm_list		lml_rtld =	{ 0 };		/* rtld's link map list */
51
52/*
53 * Entrance count.  Each time ld.so.1 is entered following initial process
54 * setup, this count is bumped.  This value serves to identify the present
55 * ld.so.1 operation.
56 *
57 * An ld.so.1 operation can result in many symbol lookup requests (i.e., loading
58 * objects and relocating all symbolic bindings).  This count is used to protect
59 * against attempting to re-load a failed lazy load within a single call to
60 * ld.so.1, while allowing such attempts across calls.  Should a lazy load fail,
61 * the present operation identifier is saved in the current symbol lookup data
62 * block (Slookup).  Should a lazy load fall back operation be triggered, the
63 * identifier in the symbol lookup block is compared to the current ld.so.1
64 * entry count, and if the two are equal the fall back is skipped.
65 *
66 * With this count, there is a danger of wrap-around, although as an unsigned
67 * 32-bit value, it is highly unlikely that any application could usefully make
68 * 4.3 giga-calls into ld.so.1.  The worst that can occur is that a fall back
69 * lazy load isn't triggered.  However, most lazy loads that fail typically
70 * continue to fail unless the user takes corrective action (adds the necessary
71 * (fixed) dependencies to the system).
72 */
73ulong_t		ld_entry_cnt = 1;
74
75/*
76 * BEGIN: Exposed to rtld_db, don't change without a coordinated handshake with
77 * librtld_db (remembering that librtld_db must be able to read old as well as
78 * current core files).
79 */
80List		dynlm_list =	{ 0, 0 };	/* dynamic list of link-maps */
81/*
82 * END: Exposed to rtld_db
83 */
84
85Reglist *	reglist = 0;			/* list of register symbols */
86
87ulong_t		hwcap = 0;			/* hardware capabilities */
88ulong_t		sfcap = 0;			/* software capabilities */
89
90/*
91 * Initialized fmap structure.
92 */
93static Fmap	_fmap = { 0, 0, 0, 0, 0 };
94Fmap *		fmap = &_fmap;			/* initial file mapping info */
95
96/*
97 * Set of integers to track how many of what type of PLT's have been bound.
98 * This is only really interesting for SPARC since ia32 has only one PLT.
99 */
100uint32_t	pltcnt21d = 0;
101uint32_t	pltcnt24d = 0;
102uint32_t	pltcntu32 = 0;
103uint32_t	pltcntu44 = 0;
104uint32_t	pltcntfull = 0;
105uint32_t	pltcntfar = 0;
106
107/*
108 * Provide for recording not-found path names.
109 */
110avl_tree_t	*nfavl = NULL;
111
112/*
113 * Enable technology (via status flags for RTLD) dependent upon whether we're
114 * in a patch or major release build environment.
115 */
116uint_t		rtld_flags =
117#ifdef	EXPAND_RELATIVE
118			RT_FL_RELATIVE |
119#endif
120#ifdef	SIEBEL_DISABLE
121			RT_FL_DISFIX_1 |
122#endif
123			RT_FL_NOCONCUR;
124uint_t		rtld_flags2 = 0;
125
126/*
127 * Various other global data.
128 */
129Lc_desc		glcs[CI_MAX];		/* global external interfaces */
130
131const char	*procname = (const char *)0;
132const char	*rtldname = MSG_ORIG(MSG_FIL_RTLD);
133
134char		*lasterr = (char *)0;	/* string describing last error */
135					/*	cleared by each dlerror() */
136Interp		*interp = 0;		/* ELF interpreter info */
137List		hdl_list[HDLIST_SZ+2];	/* dlopen() handle list */
138size_t		syspagsz = 0;		/* system page size */
139unsigned long	at_flags = 0;		/* machine specific file flags */
140char		*platform = 0;		/* platform name from AT_SUN_PLATFORM */
141size_t		platform_sz = 0;	/* platform string length */
142Uts_desc	*uts;			/* utsname descriptor */
143Isa_desc	*isa;			/* isalist descriptor */
144
145uint_t		audit_argcnt = 64;	/* no. of stack args to copy (default */
146					/*	is all) */
147Audit_desc	*auditors = 0;		/* global auditors (LD_AUDIT) */
148
149const char	*rpl_audit = 0;		/* replaceable LD_AUDIT string */
150const char	*rpl_debug = 0;		/* replaceable LD_DEBUG string */
151const char	*rpl_ldflags = 0;	/* replaceable LD_FLAGS string */
152const char	*rpl_libpath = 0;	/* replaceable LD_LIBRARY_PATH string */
153Pnode		*rpl_libdirs = 0;	/*	and associated Pnode list */
154const char	*rpl_preload = 0;	/* replaceable LD_PRELOAD string */
155
156const char	*prm_audit = 0;		/* permanent LD_AUDIT string */
157const char	*prm_debug = 0;		/* permanent LD_DEBUG string */
158const char	*prm_ldflags = 0;	/* permanent LD_FLAGS string */
159const char	*prm_libpath = 0;	/* permanent LD_LIBRARY_PATH string */
160Pnode		*prm_libdirs = 0;	/*	and associated Pnode list */
161const char	*prm_preload = 0;	/* permanent LD_PRELOAD string */
162
163uint_t		env_info = 0;		/* information regarding environment */
164					/*	variables */
165int		killsig = SIGKILL;	/* signal sent on fatal exit */
166
167/*
168 * Note, the debugging descriptor interposes on the default definition provided
169 * by liblddbg.  This is required as ld.so.1 must only have outstanding relative
170 * relocations.
171 */
172static Dbg_desc	_dbg_desc = {0, 0, 0};
173Dbg_desc	*dbg_desc = &_dbg_desc;	/* debugging descriptor */
174const char	*dbg_file = 0;		/* debugging directed to file */
175
176#pragma weak	environ = _environ	/* environ for PLT tracing - we */
177char		**_environ = 0;		/* supply the pair to satisfy any */
178					/* libc requirements (hwmuldiv) */
179
180const char	*profile_name;		/* object being profiled */
181const char	*profile_out;		/* profile output file */
182const char	*profile_lib;		/* audit library to perform profile */
183
184unsigned char	search_rules[] = {	/* dependency search rules */
185		RPLENV,			/*	replaceable LD_LIBRARY_PATH */
186		PRMENV,			/*	permanent LD_LIBRARY_PATH */
187		RUNPATH,		/*	callers runpath */
188		DEFAULT,		/*	default library path */
189		0
190};
191
192Dl_argsinfo	argsinfo = { 0 };	/* process argument, environment and */
193					/*	auxv information. */
194
195/*
196 * Frequently used messages are cached here to reduce _dgettext() overhead and
197 * also provide for resetting should the locale change (see _ld_libc()).
198 */
199const char	*err_strs[ERR_NUM] = { 0 };
200const char	*nosym_str = 0;
201
202
203/*
204 * Rejection error message tables.
205 */
206const Msg
207ldd_reject[] = {
208		MSG_STR_EMPTY,
209		MSG_LDD_REJ_MACH,	/* MSG_INTL(MSG_LDD_REJ_MACH) */
210		MSG_LDD_REJ_CLASS,	/* MSG_INTL(MSG_LDD_REJ_CLASS) */
211		MSG_LDD_REJ_DATA,	/* MSG_INTL(MSG_LDD_REJ_DATA) */
212		MSG_LDD_REJ_TYPE,	/* MSG_INTL(MSG_LDD_REJ_TYPE) */
213		MSG_LDD_REJ_BADFLAG,	/* MSG_INTL(MSG_LDD_REJ_BADFLAG) */
214		MSG_LDD_REJ_MISFLAG,	/* MSG_INTL(MSG_LDD_REJ_MISFLAG) */
215		MSG_LDD_REJ_VERSION,	/* MSG_INTL(MSG_LDD_REJ_VERSION) */
216		MSG_LDD_REJ_HAL,	/* MSG_INTL(MSG_LDD_REJ_HAL) */
217		MSG_LDD_REJ_US3,	/* MSG_INTL(MSG_LDD_REJ_US3) */
218		MSG_LDD_REJ_STR,	/* MSG_INTL(MSG_LDD_REJ_STR) */
219		MSG_LDD_REJ_UNKFILE,	/* MSG_INTL(MSG_LDD_REJ_UNKFILE) */
220		MSG_LDD_REJ_HWCAP_1,	/* MSG_INTL(MSG_LDD_REJ_HWCAP_1) */
221	};
222
223
224const Msg
225err_reject[] = {
226		MSG_STR_EMPTY,
227		MSG_ERR_REJ_MACH,	/* MSG_INTL(MSG_ERR_REJ_MACH) */
228		MSG_ERR_REJ_CLASS,	/* MSG_INTL(MSG_ERR_REJ_CLASS) */
229		MSG_ERR_REJ_DATA,	/* MSG_INTL(MSG_ERR_REJ_DATA) */
230		MSG_ERR_REJ_TYPE,	/* MSG_INTL(MSG_ERR_REJ_TYPE) */
231		MSG_ERR_REJ_BADFLAG,	/* MSG_INTL(MSG_ERR_REJ_BADFLAG) */
232		MSG_ERR_REJ_MISFLAG,	/* MSG_INTL(MSG_ERR_REJ_MISFLAG) */
233		MSG_ERR_REJ_VERSION,	/* MSG_INTL(MSG_ERR_REJ_VERSION) */
234		MSG_ERR_REJ_HAL,	/* MSG_INTL(MSG_ERR_REJ_HAL) */
235		MSG_ERR_REJ_US3,	/* MSG_INTL(MSG_ERR_REJ_US3) */
236		MSG_ERR_REJ_STR,	/* MSG_INTL(MSG_ERR_REJ_STR) */
237		MSG_ERR_REJ_UNKFILE,	/* MSG_INTL(MSG_ERR_REJ_UNKFILE) */
238		MSG_ERR_REJ_HWCAP_1,	/* MSG_INTL(MSG_ERR_REJ_HWCAP_1) */
239	};
240