plt32_resolution.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <libelf.h>
#include <rtld_db.h>
#include <_rtld_db.h>
#include <msg.h>
#include <stdio.h>
typedef struct {
} Rli_data;
/*
* Iterator function for rd_loadobj_iter - we are scaning
* each object loaded to try and find the object defining
* the current PLT being traversed - when found we return
* the GOT pointer for that object.
*/
static int
{
uint_t i;
return (0);
}
baseaddr = 0;
else
return (0);
}
found_obj = 1;
}
}
break;
}
if (found_obj) {
if (dynbase == 0) {
return (0);
}
return (0);
}
/*
* We've found our gotpntr. Return (0) to stop
* the 'iteration'.
*/
return (0);
}
return (1);
}
/*
* On x86, basically, a PLT entry looks like this:
* 8048738: ff 25 c8 45 05 08 jmp *0x80545c8 < OFFSET_INTO_GOT>
* 804873e: 68 20 00 00 00 pushl $0x20
* 8048743: e9 70 ff ff ff jmp 0xffffff70 <80486b8> < &.plt >
*
* The first time around OFFSET_INTO_GOT contains address of pushl; this forces
* first time resolution to go thru PLT's first entry (which is a call)
* The nth time around, the OFFSET_INTO_GOT actually contains the resolved
* address of the symbol(name), so the jmp is direct [VT]
* The only complication is when going from a .so to an a.out or to another
* .so, we must resolve where the GOT table is for the given object.
*/
/* ARGSUSED 3 */
{
unsigned addr;
unsigned ebx;
if (rtld_db_version >= RD_VERSION3) {
}
/*
* This is the target of the jmp instruction
*/
sizeof (unsigned)) != PS_OK) {
return (RD_ERR);
}
/*
* Is this branch %ebx relative
*/
sizeof (unsigned)) != PS_OK) {
return (RD_ERR);
}
/*
* If this .plt call is made via a GOT table (pic code), then
* in order to resolve the PLT we must determine where the
* GOT table is for the object making the call.
*
* We do this by using the rd_loadobj_iter() logic to scan
* all of the objects currently loaded into memory, when we
* find one which contains the .PLT table in question - we
* find the GOT address for that object.
*/
rli_data.rlid_gotaddr = 0;
!= RD_OK) {
return (rderr);
}
}
if (rli_data.rlid_gotaddr == 0) {
return (RD_ERR);
}
}
/*
* Find out what's pointed to by @OFFSET_INTO_GOT
*/
sizeof (unsigned)) != PS_OK) {
return (RD_ERR);
}
/*
* If GOT[ind] points to PLT+6 then this is the first
* time through this PLT.
*/
return (rerr);
}
} else {
/*
* This is the n'th time through and GOT[ind] points
* to the final destination.
*/
if (rtld_db_version >= RD_VERSION3) {
}
}
return (RD_OK);
}