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"
29 #include <proc_service.h>
36 * A un-initialized SPARCV9 PLT look like so:
39 * sethi (. - .PLT0), %g1
48 * To test to see if this is an uninitialized PLT we check
49 * the second instruction and confirm that it's a branch.
53 plt64_resolution(rd_agent_t
*rap
, psaddr_t pc
, lwpid_t lwpid
,
54 psaddr_t pltbase
, rd_plt_info_t
*rpi
)
58 psaddr_t destaddr
= 0;
62 if (rtld_db_version
>= RD_VERSION3
) {
67 pltoff
= pc
- pltbase
;
69 if (pltoff
>= (M64_PLT_NEARPLTS
* M64_PLT_ENTSIZE
)) {
70 psaddr_t pltptr
, pltptrval
;
81 * 3 ldx [%o7 + (.PLTP# - .PLT#+4)], %g1
82 * 4 jmpl %o7 + %g1, %g1
86 pltblockoff
= pltoff
- (M64_PLT_NEARPLTS
* M64_PLT_ENTSIZE
);
88 ((pltblockoff
/ M64_PLT_FBLOCKSZ
) * M64_PLT_FBLOCKSZ
) +
89 (((pltblockoff
% M64_PLT_FBLOCKSZ
) / M64_PLT_FENTSIZE
) *
93 pltaddr
= pltbase
+ (M64_PLT_NEARPLTS
* M64_PLT_ENTSIZE
) +
96 if (ps_pread(rap
->rd_psp
, pltaddr
, (char *)instr
,
97 M64_PLT_FENTSIZE
) != PS_OK
) {
98 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2
),
104 if (instr
[0] != M_MOVO7TOG5
) {
105 LOG(ps_plog(MSG_ORIG(MSG_DB_BADFPLT
),
106 EC_ADDR(pltaddr
), EC_ADDR(instr
[0])));
111 * the offset is a positive displacement from the
112 * ldx [%o7 + #], %g1 instruction. So - we don't
113 * need to worry about the sign bit :)
115 pltptr
= instr
[3] & S_MASK(12);
116 pltptr
+= pltaddr
+ 4;
118 * Load the pltptr to determine whether it is
119 * pointing to .PLT0 or to the final
122 if (ps_pread(rap
->rd_psp
, pltptr
, &pltptrval
,
123 sizeof (long long)) != PS_OK
) {
124 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2
),
128 pltptrval
+= pltaddr
+ 4;
129 if (pltptrval
== pltbase
) {
130 if ((rerr
= rd_binder_exit_addr(rap
,
131 MSG_ORIG(MSG_SYM_RTBIND
),
132 &(rpi
->pi_target
))) != RD_OK
) {
135 rpi
->pi_skip_method
= RD_RESOLVE_TARGET_STEP
;
138 rpi
->pi_skip_method
= RD_RESOLVE_STEP
;
141 if (rtld_db_version
>= RD_VERSION3
) {
142 destaddr
= pltptrval
;
150 ((pltoff
/ M64_PLT_ENTSIZE
) * M64_PLT_ENTSIZE
);
152 if (ps_pread(rap
->rd_psp
, pltaddr
, (char *)instr
,
153 M64_PLT_ENTSIZE
) != PS_OK
) {
154 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2
),
162 if ((instr
[0] != M_NOP
) &&
163 ((instr
[1] & (~(S_MASK(19)))) == M_BA_A_XCC
)) {
167 if ((rerr
= rd_binder_exit_addr(rap
,
168 MSG_ORIG(MSG_SYM_RTBIND
),
169 &(rpi
->pi_target
))) != RD_OK
) {
172 rpi
->pi_skip_method
= RD_RESOLVE_TARGET_STEP
;
174 } else if ((instr
[0] == M_NOP
) &&
175 ((instr
[1] & (~(S_MASK(22)))) == M_BA_A
)) {
177 * Resolved 64-bit PLT entry format (b+-8mb):
188 rpi
->pi_skip_method
= RD_RESOLVE_STEP
;
191 if (rtld_db_version
>= RD_VERSION3
) {
193 d22
= instr
[1] & S_MASK(22);
195 destaddr
= ((long)pltaddr
+ 4) +
197 (((int)d22
<< 10) >> 8);
200 } else if ((instr
[0] == M_NOP
) &&
201 ((instr
[1] & (~(S_MASK(19)))) == M_BA_A_PT
)) {
203 * Resolved 64-bit PLT entry format (b+-2mb):
206 * 1 ba,a,pt %icc, <dest>
214 rpi
->pi_skip_method
= RD_RESOLVE_STEP
;
217 if (rtld_db_version
>= RD_VERSION3
) {
219 d19
= instr
[1] & S_MASK(22);
221 destaddr
= ((long)pltaddr
+ 4) +
223 (((int)d19
<< 13) >> 11);
226 } else if ((instr
[6] & (~(S_MASK(13)))) == M_JMPL_G5G0
) {
228 * Resolved 64-bit PLT entry format (abs-64):
231 * 1 sethi %hh(dest), %g1
232 * 2 sethi %lm(dest), %g5
233 * 3 or %g1, %hm(dest), %g1
234 * 4 sllx %g1, 32, %g1
236 * 6 jmpl %g5 + %lo(dest), %g0
239 rpi
->pi_skip_method
= RD_RESOLVE_STEP
;
242 if (rtld_db_version
>= RD_VERSION3
) {
247 hh_bits
= instr
[1] & S_MASK(22); /* 63..42 */
248 hm_bits
= instr
[3] & S_MASK(10); /* 41..32 */
249 lm_bits
= instr
[2] & S_MASK(22); /* 31..10 */
250 lo_bits
= instr
[6] & S_MASK(10); /* 09..00 */
251 destaddr
= (hh_bits
<< 42) | (hm_bits
<< 32) |
252 (lm_bits
<< 10) | lo_bits
;
255 } else if (instr
[3] == M_JMPL
) {
257 * Resolved 64-bit PLT entry format (top-32):
261 * 1 sethi %hi(~dest), %g5
262 * 2 xnor %g5, %lo(~dest), %g1
269 rpi
->pi_skip_method
= RD_RESOLVE_STEP
;
272 if (rtld_db_version
>= RD_VERSION3
) {
275 hi_bits
= (instr
[1] & S_MASK(22)) << 10;
276 lo_bits
= (instr
[2] & S_MASK(10));
277 destaddr
= hi_bits
^ ~lo_bits
;
280 } else if ((instr
[2] & (~(S_MASK(13)))) == M_XNOR_G5G1
) {
282 * Resolved 64-bit PLT entry format (top-44):
286 * 1 sethi %h44(~dest), %g5
287 * 2 xnor %g5, %m44(~dest), %g1
288 * 3 slxx %g1, 12, %g1
289 * 4 jmpl %g1 + %l44(dest), %g0
294 rpi
->pi_skip_method
= RD_RESOLVE_STEP
;
297 if (rtld_db_version
>= RD_VERSION3
) {
301 h44_bits
= (((long)instr
[1] & S_MASK(22))
303 m44_bits
= (((long)instr
[2] & S_MASK(13))
305 l44_bits
= (((long)instr
[4] & S_MASK(13))
307 destaddr
= (~(h44_bits
^ m44_bits
) << 12)
312 rpi
->pi_skip_method
= RD_RESOLVE_NONE
;
315 if ((rtld_db_version
>= RD_VERSION3
) && pltbound
) {
316 rpi
->pi_flags
|= RD_FLG_PI_PLTBOUND
;
317 rpi
->pi_baddr
= destaddr
;