1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <proc_service.h>
31*0Sstevel@tonic-gate #include <link.h>
32*0Sstevel@tonic-gate #include <rtld_db.h>
33*0Sstevel@tonic-gate #include <_rtld_db.h>
34*0Sstevel@tonic-gate #include <msg.h>
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate /*
38*0Sstevel@tonic-gate * A un-initialized PLT look like so:
39*0Sstevel@tonic-gate *
40*0Sstevel@tonic-gate * .PLT
41*0Sstevel@tonic-gate * sethi (.-.PLT0), %g1
42*0Sstevel@tonic-gate * ba,a .PLT0
43*0Sstevel@tonic-gate * nop
44*0Sstevel@tonic-gate *
45*0Sstevel@tonic-gate * To test to see if this is an uninitialized PLT we check
46*0Sstevel@tonic-gate * the second instruction and confirm that it's a branch.
47*0Sstevel@tonic-gate */
48*0Sstevel@tonic-gate /* ARGSUSED 2 */
49*0Sstevel@tonic-gate rd_err_e
plt32_resolution(rd_agent_t * rap,psaddr_t pc,lwpid_t lwpid,psaddr_t pltbase,rd_plt_info_t * rpi)50*0Sstevel@tonic-gate plt32_resolution(rd_agent_t *rap, psaddr_t pc, lwpid_t lwpid,
51*0Sstevel@tonic-gate psaddr_t pltbase, rd_plt_info_t *rpi)
52*0Sstevel@tonic-gate {
53*0Sstevel@tonic-gate unsigned int instr[4];
54*0Sstevel@tonic-gate rd_err_e rerr;
55*0Sstevel@tonic-gate psaddr_t destaddr = 0;
56*0Sstevel@tonic-gate psaddr_t pltoff, pltaddr;
57*0Sstevel@tonic-gate int pltbound = 0;
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate pltoff = pc - pltbase;
60*0Sstevel@tonic-gate pltaddr = pltbase +
61*0Sstevel@tonic-gate ((pltoff / M32_PLT_ENTSIZE) * M32_PLT_ENTSIZE);
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate if (ps_pread(rap->rd_psp, pltaddr, (char *)instr,
64*0Sstevel@tonic-gate M32_PLT_ENTSIZE) != PS_OK) {
65*0Sstevel@tonic-gate LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2), EC_ADDR(pltaddr)));
66*0Sstevel@tonic-gate return (RD_ERR);
67*0Sstevel@tonic-gate }
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate if (rtld_db_version >= RD_VERSION3) {
70*0Sstevel@tonic-gate rpi->pi_flags = 0;
71*0Sstevel@tonic-gate rpi->pi_baddr = 0;
72*0Sstevel@tonic-gate }
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate if ((instr[0] != M_NOP) &&
75*0Sstevel@tonic-gate ((instr[1] & (~(S_MASK(22)))) == M_BA_A)) {
76*0Sstevel@tonic-gate /*
77*0Sstevel@tonic-gate * Unbound PLT
78*0Sstevel@tonic-gate */
79*0Sstevel@tonic-gate if ((rerr = rd_binder_exit_addr(rap, MSG_ORIG(MSG_SYM_RTBIND),
80*0Sstevel@tonic-gate &(rpi->pi_target))) != RD_OK) {
81*0Sstevel@tonic-gate return (rerr);
82*0Sstevel@tonic-gate }
83*0Sstevel@tonic-gate rpi->pi_skip_method = RD_RESOLVE_TARGET_STEP;
84*0Sstevel@tonic-gate rpi->pi_nstep = 1;
85*0Sstevel@tonic-gate } else if ((instr[2] & (~(S_MASK(13)))) == M_JMPL) {
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate * Resolved 32-bit PLT entry format (full-32):
88*0Sstevel@tonic-gate *
89*0Sstevel@tonic-gate * .PLT:
90*0Sstevel@tonic-gate * 0 sethi (.-PLT0), %g1
91*0Sstevel@tonic-gate * 1 sethi %hi(dest), %g1
92*0Sstevel@tonic-gate * 2 jmpl %g1 + lo(dest), %g0
93*0Sstevel@tonic-gate * 3 nop
94*0Sstevel@tonic-gate */
95*0Sstevel@tonic-gate rpi->pi_skip_method = RD_RESOLVE_STEP;
96*0Sstevel@tonic-gate rpi->pi_nstep = 4;
97*0Sstevel@tonic-gate rpi->pi_target = 0;
98*0Sstevel@tonic-gate if (rtld_db_version >= RD_VERSION3) {
99*0Sstevel@tonic-gate uint_t hi_bits;
100*0Sstevel@tonic-gate uint_t lo_bits;
101*0Sstevel@tonic-gate hi_bits = instr[1] & S_MASK(22); /* 31..10 */
102*0Sstevel@tonic-gate lo_bits = instr[2] & S_MASK(10); /* 09..00 */
103*0Sstevel@tonic-gate destaddr = (hi_bits << 10) | lo_bits;
104*0Sstevel@tonic-gate pltbound++;
105*0Sstevel@tonic-gate }
106*0Sstevel@tonic-gate } else if ((instr[0] == M_NOP) &&
107*0Sstevel@tonic-gate ((instr[1] & (~(S_MASK(22)))) == M_BA_A)) {
108*0Sstevel@tonic-gate /*
109*0Sstevel@tonic-gate * Resolved 32-bit PLT entry format (b+-8mb):
110*0Sstevel@tonic-gate * .PLT
111*0Sstevel@tonic-gate * 0 nop
112*0Sstevel@tonic-gate * 1 ba,a <dest>
113*0Sstevel@tonic-gate * 2 nop
114*0Sstevel@tonic-gate * 3 nop
115*0Sstevel@tonic-gate */
116*0Sstevel@tonic-gate rpi->pi_skip_method = RD_RESOLVE_STEP;
117*0Sstevel@tonic-gate rpi->pi_nstep = 2;
118*0Sstevel@tonic-gate rpi->pi_target = 0;
119*0Sstevel@tonic-gate if (rtld_db_version >= RD_VERSION3) {
120*0Sstevel@tonic-gate uint_t d22;
121*0Sstevel@tonic-gate d22 = instr[1] & S_MASK(22);
122*0Sstevel@tonic-gate destaddr = ((int)pltaddr + 4) +
123*0Sstevel@tonic-gate (((int)d22 << 10) >> 8);
124*0Sstevel@tonic-gate pltbound++;
125*0Sstevel@tonic-gate }
126*0Sstevel@tonic-gate } else if ((instr[0] == M_NOP) &&
127*0Sstevel@tonic-gate ((instr[1] & (~(S_MASK(19)))) == M_BA_A_PT)) {
128*0Sstevel@tonic-gate /*
129*0Sstevel@tonic-gate * Resolved 32-bit PLT entry format (b+-2mb):
130*0Sstevel@tonic-gate * .PLT
131*0Sstevel@tonic-gate * 0 nop
132*0Sstevel@tonic-gate * 1 ba,a,pt %icc, <dest>
133*0Sstevel@tonic-gate * 2 nop
134*0Sstevel@tonic-gate * 3 nop
135*0Sstevel@tonic-gate */
136*0Sstevel@tonic-gate rpi->pi_skip_method = RD_RESOLVE_STEP;
137*0Sstevel@tonic-gate rpi->pi_nstep = 2;
138*0Sstevel@tonic-gate rpi->pi_target = 0;
139*0Sstevel@tonic-gate if (rtld_db_version >= RD_VERSION3) {
140*0Sstevel@tonic-gate uint_t d19;
141*0Sstevel@tonic-gate d19 = instr[1] & S_MASK(22);
142*0Sstevel@tonic-gate destaddr = ((int)pltaddr + 4) +
143*0Sstevel@tonic-gate (((int)d19 << 13) >> 11);
144*0Sstevel@tonic-gate pltbound++;
145*0Sstevel@tonic-gate }
146*0Sstevel@tonic-gate } else
147*0Sstevel@tonic-gate rpi->pi_skip_method = RD_RESOLVE_NONE;
148*0Sstevel@tonic-gate
149*0Sstevel@tonic-gate if ((rtld_db_version >= RD_VERSION3) && pltbound) {
150*0Sstevel@tonic-gate rpi->pi_flags |= RD_FLG_PI_PLTBOUND;
151*0Sstevel@tonic-gate rpi->pi_baddr = destaddr;
152*0Sstevel@tonic-gate }
153*0Sstevel@tonic-gate return (RD_OK);
154*0Sstevel@tonic-gate }
155