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.
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.
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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 1988 AT&T
32 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
36 * SPARC specific setup routine - relocate ld.so's symbols, setup its
37 * environment, map in loadable sections of the executable.
39 * Takes base address ld.so was loaded at, address of ld.so's dynamic
40 * structure, address of process environment pointers, address of auxiliary
41 * vector and * argv[0] (process name).
42 * If errors occur, send process signal - otherwise
43 * return executable's entry point to the bootstrap routine.
49 #include <sys/types.h>
62 _setup(Boot
*ebp
, Dyn
*ld_dyn
)
64 ulong_t reladdr
, relacount
, ld_base
= 0;
66 ulong_t strtab
, soname
, interp_base
= 0;
67 char *_rt_name
, **_envp
, **_argv
;
68 int _syspagsz
= 0, fd
= -1;
70 uint_t hwcap
[2] = { 0, 0 };
75 uid_t uid
= (uid_t
)-1, euid
= (uid_t
)-1;
76 gid_t gid
= (gid_t
)-1, egid
= (gid_t
)-1;
77 char *_platform
= NULL
, *_execname
= NULL
, *_emulator
= NULL
;
84 * Scan the bootstrap structure to pick up the basics.
86 for (; ebp
->eb_tag
!= EB_NULL
; ebp
++)
87 switch (ebp
->eb_tag
) {
90 aoutdyn
= (Link_dynamic
*)ebp
->eb_un
.eb_val
;
94 ld_base
= (unsigned long)ebp
->eb_un
.eb_val
;
97 _argv
= (char **)ebp
->eb_un
.eb_ptr
;
100 _envp
= (char **)ebp
->eb_un
.eb_ptr
;
103 _auxv
= (auxv_t
*)ebp
->eb_un
.eb_ptr
;
106 _syspagsz
= (int)ebp
->eb_un
.eb_val
;
111 * Search the aux. vector for the information passed by exec.
113 for (auxv
= _auxv
; auxv
->a_type
!= AT_NULL
; auxv
++) {
114 switch (auxv
->a_type
) {
116 /* this is the old exec that passes a file descriptor */
117 fd
= (int)auxv
->a_un
.a_val
;
120 /* processor flags (MAU available, etc) */
121 _flags
= auxv
->a_un
.a_val
;
124 /* system page size */
125 _syspagsz
= (int)auxv
->a_un
.a_val
;
128 /* address of the segment table */
129 phdr
= (Phdr
*)auxv
->a_un
.a_ptr
;
132 /* interpreter base address */
134 ld_base
= auxv
->a_un
.a_val
;
135 interp_base
= auxv
->a_un
.a_val
;
138 /* effective user id for the executable */
139 euid
= (uid_t
)auxv
->a_un
.a_val
;
142 /* real user id for the executable */
143 uid
= (uid_t
)auxv
->a_un
.a_val
;
146 /* effective group id for the executable */
147 egid
= (gid_t
)auxv
->a_un
.a_val
;
150 /* real group id for the executable */
151 gid
= (gid_t
)auxv
->a_un
.a_val
;
153 case AT_SUN_PLATFORM
:
155 _platform
= auxv
->a_un
.a_ptr
;
157 case AT_SUN_EXECNAME
:
158 /* full pathname of execed object */
159 _execname
= auxv
->a_un
.a_ptr
;
161 case AT_SUN_AUXFLAGS
:
162 /* auxiliary flags */
163 auxflags
= (int)auxv
->a_un
.a_val
;
166 /* hardware capabilities */
167 hwcap
[0] = (uint_t
)auxv
->a_un
.a_val
;
170 /* hardware capabilities */
171 hwcap
[1] = (uint_t
)auxv
->a_un
.a_val
;
173 case AT_SUN_EMULATOR
:
174 /* name of emulation library, if any */
175 _emulator
= auxv
->a_un
.a_ptr
;
181 * Get needed info from ld.so's dynamic structure.
184 dyn_ptr
= (Dyn
*)((char *)ld_dyn
+ ld_base
);
185 for (ld_dyn
= dyn_ptr
; ld_dyn
->d_tag
!= DT_NULL
; ld_dyn
++) {
186 switch (ld_dyn
->d_tag
) {
188 reladdr
= ld_dyn
->d_un
.d_ptr
+ ld_base
;
191 relacount
= ld_dyn
->d_un
.d_val
;
194 relaent
= ld_dyn
->d_un
.d_val
;
197 strtab
= ld_dyn
->d_un
.d_ptr
+ ld_base
;
200 soname
= ld_dyn
->d_un
.d_val
;
204 _rt_name
= (char *)strtab
+ soname
;
207 * If we don't have a RELAENT, just assume the size.
210 relaent
= sizeof (Rela
);
213 * As all global symbol references within ld.so.1 are protected
214 * (symbolic), only RELATIVE and JMPSLOT relocations should be left
215 * to process at runtime. Process all relative relocations now.
217 for (; relacount
; relacount
--) {
220 roffset
= ((Rela
*)reladdr
)->r_offset
+ ld_base
;
221 *((ulong_t
*)roffset
) = ld_base
+
222 ((Rela
*)reladdr
)->r_addend
;
227 * If an emulation library is being used, use that as the linker's
228 * effective executable name. The real executable is not linked by this
231 if (_emulator
!= NULL
) {
232 _execname
= _emulator
;
233 rtld_flags2
|= RT_FL2_BRANDED
;
237 * Continue with generic startup processing.
240 if ((lmp
= setup((char **)_envp
, (auxv_t
*)_auxv
, _flags
, _platform
,
241 _syspagsz
, _rt_name
, ld_base
, interp_base
, fd
, phdr
,
242 _execname
, _argv
, uid
, euid
, gid
, egid
,
244 aoutdyn
, auxflags
, hwcap
)) == NULL
) {
247 NULL
, auxflags
, hwcap
)) == NULL
) {
249 rtldexit(&lml_main
, 1);
253 return (LM_ENTRY_PT(lmp
)());