Catch up with type changes. Also:

* Apply DT_PLTRELSZ to (one of) pltrel or pltrela *after* we've finished
  parsing the headers, so we know which one.
* Fix sparc64 bogons.  (It works now!)
This commit is contained in:
mycroft 2000-07-26 02:07:34 +00:00
parent 9af78695ed
commit 43cfeb27a9
6 changed files with 41 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mdreloc.c,v 1.2 2000/07/18 22:33:56 eeh Exp $ */
/* $NetBSD: mdreloc.c,v 1.3 2000/07/26 02:07:36 mycroft Exp $ */
/*-
* Copyright (c) 2000 Eduardo Horvath.
@ -192,7 +192,8 @@ _rtld_relocate_nonplt_object(obj, rela, dodebug)
bool dodebug;
{
Elf_Addr *where = (Elf_Addr *) (obj->relocbase + rela->r_offset);
Elf_Word type, value = 0, mask;
Elf_Word type;
Elf_Addr value = 0, mask;
const Elf_Sym *def = NULL;
const Obj_Entry *defobj = NULL;
@ -236,11 +237,11 @@ _rtld_relocate_nonplt_object(obj, rela, dodebug)
return (-1);
/* Add in the symbol's absolute address */
value += (Elf_Word)(defobj->relocbase + def->st_value);
value += (Elf_Addr)(defobj->relocbase + def->st_value);
}
if (RELOC_PC_RELATIVE(type)) {
value -= (Elf_Word)where;
value -= (Elf_Addr)where;
}
if (RELOC_BASE_RELATIVE(type)) {
@ -263,7 +264,7 @@ _rtld_relocate_nonplt_object(obj, rela, dodebug)
}
#endif
/* XXXX -- apparently we ignore the preexisting value */
value += (Elf_Word)(obj->relocbase);
value += (Elf_Addr)(obj->relocbase);
}
mask = RELOC_VALUE_BITMASK(type);
@ -272,7 +273,7 @@ _rtld_relocate_nonplt_object(obj, rela, dodebug)
if (RELOC_UNALIGNED(type)) {
/* Handle unaligned relocations. */
Elf_Word tmp = 0;
Elf_Addr tmp = 0;
char *ptr = (char *)where;
int i, size = RELOC_TARGET_SIZE(type)/8;
@ -287,14 +288,14 @@ _rtld_relocate_nonplt_object(obj, rela, dodebug)
for (i=0; i<size; i++)
ptr[i] = ((tmp >> (8*i)) & 0xff);
#ifdef RTLD_DEBUG_RELOC
value = (Elf_Word)tmp;
value = (Elf_Addr)tmp;
#endif
} else if (RELOC_TARGET_SIZE(type) > 32) {
*where &= ~mask;
*where |= value;
#ifdef RTLD_DEBUG_RELOC
value = (Elf_Word)*where;
value = (Elf_Addr)*where;
#endif
} else {
Elf32_Addr *where32 = (Elf32_Addr *)where;
@ -302,7 +303,7 @@ _rtld_relocate_nonplt_object(obj, rela, dodebug)
*where32 &= ~mask;
*where32 |= value;
#ifdef RTLD_DEBUG_RELOC
value = (Elf_Word)*where32;
value = (Elf_Addr)*where32;
#endif
}
@ -352,7 +353,7 @@ _rtld_relocate_plt_object(obj, rela, addrp, bind_now, dodebug)
{
const Elf_Sym *def;
const Obj_Entry *defobj;
Elf32_Word *where = (Elf32_Word *)((Elf_Addr)obj->pltgot + rela->r_offset);
Elf_Word *where = (Elf_Word *)((Elf_Addr)obj->relocbase + rela->r_offset);
Elf_Addr value, offset;
if (bind_now == 0 && obj->pltgot != NULL)
@ -590,11 +591,11 @@ _rtld_relocate_plt_object(obj, rela, addrp, bind_now, dodebug)
#define JMPL_l0_o0 0x93c42000
#define MOV_g1_o0 0x90100001
void _rtld_install_plt __P((Elf32_Word *pltgot, Elf_Addr proc));
void _rtld_install_plt __P((Elf_Word *pltgot, Elf_Addr proc));
void
_rtld_install_plt(pltgot, proc)
Elf32_Word *pltgot;
Elf_Word *pltgot;
Elf_Addr proc;
{
pltgot[0] = SAVE;

View File

@ -1,4 +1,4 @@
/* $NetBSD: headers.c,v 1.7 2000/07/18 22:33:55 eeh Exp $ */
/* $NetBSD: headers.c,v 1.8 2000/07/26 02:07:34 mycroft Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -64,8 +64,8 @@ _rtld_digest_dynamic(obj)
Needed_Entry **needed_tail = &obj->needed;
const Elf_Dyn *dyn_rpath = NULL;
Elf_Sword plttype = DT_REL;
Elf_Word relsz = 0, relasz = 0;
Elf_Word pltrelsz = 0, pltrelasz = 0;
Elf_Addr relsz = 0, relasz = 0;
Elf_Addr pltrelsz = 0;
for (dynp = obj->dynamic; dynp->d_tag != DT_NULL; ++dynp) {
switch (dynp->d_tag) {
@ -94,11 +94,7 @@ _rtld_digest_dynamic(obj)
break;
case DT_PLTRELSZ:
if (plttype == DT_REL) {
pltrelsz = dynp->d_un.d_val;
} else {
pltrelasz = dynp->d_un.d_val;
}
pltrelsz = dynp->d_un.d_val;
break;
case DT_RELA:
@ -118,7 +114,7 @@ _rtld_digest_dynamic(obj)
plttype = dynp->d_un.d_val;
assert(plttype == DT_REL ||
plttype == DT_RELA);
#if !defined(__sparc__) && !defined(__archv9__)
#if !defined(__sparc__) && !defined(__archv9__) && !defined(__sparc_v9__)
/*
* sparc v9 has both DT_PLTREL and DT_JMPREL.
* But they point to different things.
@ -127,8 +123,6 @@ _rtld_digest_dynamic(obj)
if (plttype == DT_RELA) {
obj->pltrela = (const Elf_RelA *) obj->pltrel;
obj->pltrel = NULL;
pltrelasz = pltrelsz;
pltrelsz = 0;
}
#endif
break;
@ -244,8 +238,13 @@ _rtld_digest_dynamic(obj)
obj->rellim = (const Elf_Rel *)((caddr_t)obj->rel + relsz);
obj->relalim = (const Elf_RelA *)((caddr_t)obj->rela + relasz);
obj->pltrellim = (const Elf_Rel *)((caddr_t)obj->pltrel + pltrelsz);
obj->pltrelalim = (const Elf_RelA *)((caddr_t)obj->pltrela + pltrelasz);
if (plttype == DT_REL) {
obj->pltrellim = (const Elf_Rel *)((caddr_t)obj->pltrel + pltrelsz);
obj->pltrelalim = 0;
} else {
obj->pltrellim = 0;
obj->pltrelalim = (const Elf_RelA *)((caddr_t)obj->pltrela + pltrelsz);
}
if (dyn_rpath != NULL) {
_rtld_add_paths(&obj->rpaths, obj->strtab +

View File

@ -1,4 +1,4 @@
/* $NetBSD: reloc.c,v 1.30 2000/07/18 22:33:55 eeh Exp $ */
/* $NetBSD: reloc.c,v 1.31 2000/07/26 02:07:34 mycroft Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -673,7 +673,7 @@ _rtld_relocate_objects(first, bind_now, dodebug)
_rtld_setup_powerpc_plt(obj);
#endif
#if defined(__sparc__)
#if defined(__arch64__)
#if defined(__arch64__) || defined(__sparc_v9__)
/*
* On sparc64 we got troubles.
*
@ -692,8 +692,8 @@ _rtld_relocate_objects(first, bind_now, dodebug)
* Oh, we need to fill out both PLT0 and PLT1.
*/
{
Elf32_Word *entry = (Elf32_Word *)obj->pltgot;
extern void _rtld_install_plt __P((Elf32_Word *,
Elf_Word *entry = (Elf_Word *)obj->pltgot;
extern void _rtld_install_plt __P((Elf_Word *,
Elf_Addr));
extern void _rtld_bind_start_0 __P((long,
long));

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtld.c,v 1.38 2000/07/19 15:01:16 thorpej Exp $ */
/* $NetBSD: rtld.c,v 1.39 2000/07/26 02:07:35 mycroft Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -73,7 +73,7 @@ typedef void (*funcptr) __P((void));
static void _rtld_init __P((caddr_t, int));
static void _rtld_exit __P((void));
Elf_Addr _rtld __P((Elf_Word *));
Elf_Addr _rtld __P((Elf_Addr *));
/*
@ -281,7 +281,7 @@ _rtld_exit()
*/
Elf_Addr
_rtld(sp)
Elf_Word *sp;
Elf_Addr *sp;
{
const AuxInfo *pAUX_base, *pAUX_entry, *pAUX_execfd, *pAUX_phdr,
*pAUX_phent, *pAUX_phnum;
@ -291,10 +291,11 @@ _rtld(sp)
char **env;
const AuxInfo *aux;
const AuxInfo *auxp;
Elf_Word *const osp = sp;
Elf_Addr *const osp = sp;
bool bind_now = 0;
const char *ld_bind_now;
const char **argv;
int argc;
Obj_Entry *obj;
const char **real___progname;
const Obj_Entry **real___mainprog_obj;
@ -322,7 +323,8 @@ _rtld(sp)
sp += 2; /* skip over return argument space */
argv = (const char **) &sp[1];
sp += ((int *)sp)[0] + 2; /* Skip over argc, arguments, and NULL
argc = *(int *)sp;
sp += 2 + argc; /* Skip over argc, arguments, and NULL
* terminator */
env = (char **) sp;
while (*sp++ != 0) { /* Skip over environment, and NULL terminator */

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtld.h,v 1.26 2000/07/06 03:16:51 christos Exp $ */
/* $NetBSD: rtld.h,v 1.27 2000/07/26 02:07:35 mycroft Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -278,7 +278,7 @@ char *_rtld_find_library __P((const char *, const Obj_Entry *));
unsigned long _rtld_elf_hash __P((const char *));
const Elf_Sym *_rtld_symlook_obj __P((const char *, unsigned long,
const Obj_Entry *, bool));
const Elf_Sym *_rtld_find_symdef __P((const Obj_Entry *, Elf_Word,
const Elf_Sym *_rtld_find_symdef __P((const Obj_Entry *, Elf_Addr,
const char *, Obj_Entry *, const Obj_Entry **, bool));
const Elf_Sym *_rtld_symlook_list(const char *, unsigned long,
Objlist *, const Obj_Entry **, bool in_plt);

View File

@ -1,4 +1,4 @@
/* $NetBSD: symbol.c,v 1.8 2000/07/03 03:33:52 matt Exp $ */
/* $NetBSD: symbol.c,v 1.9 2000/07/26 02:07:36 mycroft Exp $ */
/*
* Copyright 1996 John D. Polstra.
@ -156,13 +156,13 @@ _rtld_symlook_obj(name, hash, obj, in_plt)
const Elf_Sym *
_rtld_find_symdef(obj_list, r_info, name, refobj, defobj_out, in_plt)
const Obj_Entry *obj_list;
Elf_Word r_info;
Elf_Addr r_info;
const char *name;
Obj_Entry *refobj;
const Obj_Entry **defobj_out;
bool in_plt;
{
Elf_Word symnum = ELF_R_SYM(r_info);
Elf_Addr symnum = ELF_R_SYM(r_info);
const Elf_Sym *ref = NULL;
const Elf_Sym *def;
const Elf_Sym *symp;