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 * i386 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>
59 _setup(Boot
*ebp
, Dyn
*ld_dyn
)
61 ulong_t reladdr
, relcount
, ld_base
= 0;
63 ulong_t strtab
, soname
, interp_base
= 0;
64 char *_rt_name
, **_envp
, **_argv
;
65 int _syspagsz
= 0, fd
= -1;
67 uint_t hwcap
[2] = { 0, 0 };
72 uid_t uid
= (uid_t
)-1, euid
= (uid_t
)-1;
73 gid_t gid
= (gid_t
)-1, egid
= (gid_t
)-1;
74 char *_platform
= NULL
, *_execname
= NULL
, *_emulator
= NULL
;
78 * Scan the bootstrap structure to pick up the basics.
80 for (; ebp
->eb_tag
!= EB_NULL
; ebp
++)
81 switch (ebp
->eb_tag
) {
83 ld_base
= (unsigned long)ebp
->eb_un
.eb_val
;
86 _argv
= (char **)ebp
->eb_un
.eb_ptr
;
89 _envp
= (char **)ebp
->eb_un
.eb_ptr
;
92 _auxv
= (auxv_t
*)ebp
->eb_un
.eb_ptr
;
95 _syspagsz
= (int)ebp
->eb_un
.eb_val
;
100 * Search the aux. vector for the information passed by exec.
102 for (auxv
= _auxv
; auxv
->a_type
!= AT_NULL
; auxv
++) {
103 switch (auxv
->a_type
) {
105 /* this is the old exec that passes a file descriptor */
106 fd
= (int)auxv
->a_un
.a_val
;
109 /* processor flags (MAU available, etc) */
110 _flags
= auxv
->a_un
.a_val
;
113 /* system page size */
114 _syspagsz
= (int)auxv
->a_un
.a_val
;
117 /* address of the segment table */
118 phdr
= (Phdr
*)auxv
->a_un
.a_ptr
;
121 /* interpreter base address */
123 ld_base
= auxv
->a_un
.a_val
;
124 interp_base
= auxv
->a_un
.a_val
;
127 /* effective user id for the executable */
128 euid
= (uid_t
)auxv
->a_un
.a_val
;
131 /* real user id for the executable */
132 uid
= (uid_t
)auxv
->a_un
.a_val
;
135 /* effective group id for the executable */
136 egid
= (gid_t
)auxv
->a_un
.a_val
;
139 /* real group id for the executable */
140 gid
= (gid_t
)auxv
->a_un
.a_val
;
142 case AT_SUN_PLATFORM
:
144 _platform
= auxv
->a_un
.a_ptr
;
146 case AT_SUN_EXECNAME
:
147 /* full pathname of execed object */
148 _execname
= auxv
->a_un
.a_ptr
;
150 case AT_SUN_AUXFLAGS
:
151 /* auxiliary flags */
152 auxflags
= (int)auxv
->a_un
.a_val
;
155 /* hardware capabilities */
156 hwcap
[0] = (uint_t
)auxv
->a_un
.a_val
;
159 /* hardware capabilities */
160 hwcap
[1] = (uint_t
)auxv
->a_un
.a_val
;
162 case AT_SUN_EMULATOR
:
163 /* name of emulation library, if any */
164 _emulator
= auxv
->a_un
.a_ptr
;
170 * Get needed info from ld.so's dynamic structure.
173 dyn_ptr
= (Dyn
*)((char *)ld_dyn
+ ld_base
);
174 for (ld_dyn
= dyn_ptr
; ld_dyn
->d_tag
!= DT_NULL
; ld_dyn
++) {
175 switch (ld_dyn
->d_tag
) {
177 reladdr
= ld_dyn
->d_un
.d_ptr
+ ld_base
;
180 relcount
= ld_dyn
->d_un
.d_val
;
183 relent
= ld_dyn
->d_un
.d_val
;
186 strtab
= ld_dyn
->d_un
.d_ptr
+ ld_base
;
189 soname
= ld_dyn
->d_un
.d_val
;
193 _rt_name
= (char *)strtab
+ soname
;
196 * If we don't have a RELENT, just assume the size.
199 relent
= sizeof (Rel
);
202 * As all global symbol references within ld.so.1 are protected
203 * (symbolic), only RELATIVE and JMPSLOT relocations should be left
204 * to process at runtime. Process all relative relocations now.
206 for (; relcount
; relcount
--) {
209 roffset
= ((Rel
*)reladdr
)->r_offset
+ ld_base
;
210 *((ulong_t
*)roffset
) += ld_base
;
215 * If an emulation library is being used, use that as the linker's
216 * effective executable name. The real executable is not linked by this
219 if (_emulator
!= NULL
) {
220 _execname
= _emulator
;
221 rtld_flags2
|= RT_FL2_BRANDED
;
225 * Initialize the dyn_plt_ent_size field. It currently contains the
226 * size of the dyn_plt_template. It still needs to be aligned and have
227 * space for the 'dyn_data' area added.
229 dyn_plt_ent_size
= ROUND(dyn_plt_ent_size
, M_WORD_ALIGN
) +
230 sizeof (uintptr_t) + sizeof (uintptr_t) + sizeof (ulong_t
) +
231 sizeof (ulong_t
) + sizeof (Sym
);
234 * Continue with generic startup processing.
236 if ((lmp
= setup((char **)_envp
, (auxv_t
*)_auxv
, _flags
, _platform
,
237 _syspagsz
, _rt_name
, ld_base
, interp_base
, fd
, phdr
,
238 _execname
, _argv
, uid
, euid
, gid
, egid
, NULL
, auxflags
,
240 rtldexit(&lml_main
, 1);
243 return (LM_ENTRY_PT(lmp
)());