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 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
37 * On amd64, basically, a PLT entry looks like this:
39 * 0x00 ff 25 00 00 00 00 jmpq *func@got(%rip) ; jmp GOT[N]
40 * 0x06 68 01 00 00 00 pushq $0x1 ; push index
41 * 0x0b e9 00 00 00 00 jmpq .plt0 ; jmp plt[0]
44 * The first time around GOT[N] contains address of pushq; this forces
45 * first time resolution to go thru PLT's first entry (which is a call)
46 * The nth time around, the GOT[N] actually contains the resolved
47 * address of the symbol(name), so the jmp is direct
51 plt64_resolution(rd_agent_t
*rap
, psaddr_t pc
, lwpid_t lwpid
,
52 psaddr_t pltbase
, rd_plt_info_t
*rpi
)
56 psaddr_t pltoff
, pltaddr
;
59 if (rtld_db_version
>= RD_VERSION3
) {
64 pltoff
= pc
- pltbase
;
66 ((pltoff
/ M_PLT_ENTSIZE
) * M_PLT_ENTSIZE
);
68 * This is the target of the jmp instruction
70 if (ps_pread(rap
->rd_psp
, pltaddr
+ 2, (char *)&pcrel
,
71 sizeof (pcrel
)) != PS_OK
) {
72 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2
), EC_ADDR(pltaddr
+ 2)));
77 * the offset to the GOT table entry is
80 destaddr
= pcrel
+ pltaddr
+ 6;
83 * Find out what's pointed to by @OFFSET_INTO_GOT
85 if (ps_pread(rap
->rd_psp
, destaddr
, (char *)&destaddr
,
86 sizeof (destaddr
)) != PS_OK
) {
87 LOG(ps_plog(MSG_ORIG(MSG_DB_READFAIL_2
), EC_ADDR(destaddr
)));
90 if (destaddr
== (pltaddr
+ 6)) {
93 * If GOT[ind] points to PLT+6 then this is the first
94 * time through this PLT.
96 if ((rerr
= rd_binder_exit_addr(rap
, MSG_ORIG(MSG_SYM_RTBIND
),
97 &(rpi
->pi_target
))) != RD_OK
) {
100 rpi
->pi_skip_method
= RD_RESOLVE_TARGET_STEP
;
104 * This is the n'th time through and GOT[ind] points
105 * to the final destination.
107 rpi
->pi_skip_method
= RD_RESOLVE_STEP
;
110 if (rtld_db_version
>= RD_VERSION3
) {
111 rpi
->pi_flags
|= RD_FLG_PI_PLTBOUND
;
112 rpi
->pi_baddr
= destaddr
;