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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/regset.h>
40 psaddr_t rlid_pltaddr
;
41 psaddr_t rlid_gotaddr
;
46 * Iterator function for rd_loadobj_iter - we are scaning
47 * each object loaded to try and find the object defining
48 * the current PLT being traversed - when found we return
49 * the GOT pointer for that object.
52 rli_func(const rd_loadobj_t
*rl
, void *data
)
66 rli_data
= (Rli_data
*)data
;
67 pltaddr
= rli_data
->rlid_pltaddr
;
68 rap
= rli_data
->rlid_rap
;
70 if (ps_pread(rap
->rd_psp
, rl
->rl_base
, (char *)&ehdr
,
71 sizeof (Ehdr
)) != PS_OK
) {
72 rli_data
->rlid_ret
= RD_ERR
;
73 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_X86_1
),
74 EC_ADDR(rl
->rl_base
)));
77 if (ehdr
.e_type
== ET_EXEC
)
80 baseaddr
= rl
->rl_base
;
82 off
= rl
->rl_base
+ ehdr
.e_phoff
;
83 for (i
= 0; i
< ehdr
.e_phnum
; i
++) {
84 if (ps_pread(rap
->rd_psp
, off
, (char *)&phdr
,
85 sizeof (Phdr
)) != PS_OK
) {
86 rli_data
->rlid_ret
= RD_ERR
;
87 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_X86_1
),
88 EC_ADDR(rl
->rl_base
)));
91 if (phdr
.p_type
== PT_LOAD
) {
92 if ((pltaddr
>= (phdr
.p_vaddr
+ baseaddr
)) &&
93 (pltaddr
< (phdr
.p_vaddr
+ baseaddr
+
97 } else if (phdr
.p_type
== PT_DYNAMIC
) {
98 dynbase
= phdr
.p_vaddr
+ baseaddr
;
100 off
+= ehdr
.e_phentsize
;
102 if (found_obj
& dynbase
)
110 LOG(ps_plog(MSG_ORIG(MSG_DB_NODYN_X86
)));
111 rli_data
->rlid_ret
= RD_ERR
;
114 if ((rc
= find_dynamic_ent32(rap
, dynbase
, DT_PLTGOT
,
115 &dynent
)) != RD_OK
) {
116 rli_data
->rlid_ret
= rc
;
120 * We've found our gotpntr. Return (0) to stop
123 rli_data
->rlid_gotaddr
= dynent
.d_un
.d_val
+ baseaddr
;
132 * On x86, basically, a PLT entry looks like this:
133 * 8048738: ff 25 c8 45 05 08 jmp *0x80545c8 < OFFSET_INTO_GOT>
134 * 804873e: 68 20 00 00 00 pushl $0x20
135 * 8048743: e9 70 ff ff ff jmp 0xffffff70 <80486b8> < &.plt >
137 * The first time around OFFSET_INTO_GOT contains address of pushl; this forces
138 * first time resolution to go thru PLT's first entry (which is a call)
139 * The nth time around, the OFFSET_INTO_GOT actually contains the resolved
140 * address of the symbol(name), so the jmp is direct [VT]
141 * The only complication is when going from a .so to an a.out or to another
142 * .so, we must resolve where the GOT table is for the given object.
146 plt32_resolution(rd_agent_t
*rap
, psaddr_t pc
, lwpid_t lwpid
,
147 psaddr_t pltbase
, rd_plt_info_t
*rpi
)
151 psaddr_t pltoff
, pltaddr
;
154 if (rtld_db_version
>= RD_VERSION3
) {
159 pltoff
= pc
- pltbase
;
161 ((pltoff
/ M_PLT_ENTSIZE
) * M_PLT_ENTSIZE
);
163 * This is the target of the jmp instruction
165 if (ps_pread(rap
->rd_psp
, pltaddr
+ 2, (char *)&addr
,
166 sizeof (unsigned)) != PS_OK
) {
167 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2
), EC_ADDR(pltaddr
+ 2)));
172 * Is this branch %ebx relative
174 if (ps_pread(rap
->rd_psp
, pltaddr
+ 1, (char *)&ebx
,
175 sizeof (unsigned)) != PS_OK
) {
176 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2
), EC_ADDR(pltaddr
+ 1)));
181 * If this .plt call is made via a GOT table (pic code), then
182 * in order to resolve the PLT we must determine where the
183 * GOT table is for the object making the call.
185 * We do this by using the rd_loadobj_iter() logic to scan
186 * all of the objects currently loaded into memory, when we
187 * find one which contains the .PLT table in question - we
188 * find the GOT address for that object.
190 if ((ebx
& 0xff) == 0xa3) {
194 rli_data
.rlid_ret
= RD_OK
;
195 rli_data
.rlid_pltaddr
= pltaddr
;
196 rli_data
.rlid_rap
= rap
;
197 rli_data
.rlid_gotaddr
= 0;
198 if ((rderr
= _rd_loadobj_iter32(rap
, rli_func
, &rli_data
))
203 if (rli_data
.rlid_ret
!= RD_OK
) {
204 return (rli_data
.rlid_ret
);
207 if (rli_data
.rlid_gotaddr
== 0) {
208 LOG(ps_plog(MSG_ORIG(MSG_DB_NOGOT_X86
)));
211 addr
+= rli_data
.rlid_gotaddr
;
215 * Find out what's pointed to by @OFFSET_INTO_GOT
217 if (ps_pread(rap
->rd_psp
, addr
, (char *)&addr
,
218 sizeof (unsigned)) != PS_OK
) {
219 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2
), EC_ADDR(addr
)));
222 if (addr
== (pltaddr
+ 6)) {
225 * If GOT[ind] points to PLT+6 then this is the first
226 * time through this PLT.
228 if ((rerr
= rd_binder_exit_addr(rap
, MSG_ORIG(MSG_SYM_RTBIND
),
229 &(rpi
->pi_target
))) != RD_OK
) {
232 rpi
->pi_skip_method
= RD_RESOLVE_TARGET_STEP
;
236 * This is the n'th time through and GOT[ind] points
237 * to the final destination.
239 rpi
->pi_skip_method
= RD_RESOLVE_STEP
;
242 if (rtld_db_version
>= RD_VERSION3
) {
243 rpi
->pi_flags
|= RD_FLG_PI_PLTBOUND
;
244 rpi
->pi_baddr
= addr
;