From 125d6a43ac0ca241f07fb9093fcaaa30ecaa7cc7 Mon Sep 17 00:00:00 2001 From: skrll Date: Sat, 4 Mar 2006 08:58:46 +0000 Subject: [PATCH] Add LD_BIND_NOW support for mips. This is the last arch to be done so remove the large ugly #if defined() stuff in reloc.c. --- libexec/ld.elf_so/arch/mips/mips_reloc.c | 58 +++++++++++++++++++----- libexec/ld.elf_so/reloc.c | 9 +--- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/libexec/ld.elf_so/arch/mips/mips_reloc.c b/libexec/ld.elf_so/arch/mips/mips_reloc.c index cdd5b0a7e07e..89f1fe403ee1 100644 --- a/libexec/ld.elf_so/arch/mips/mips_reloc.c +++ b/libexec/ld.elf_so/arch/mips/mips_reloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mips_reloc.c,v 1.49 2005/12/24 20:59:30 perry Exp $ */ +/* $NetBSD: mips_reloc.c,v 1.50 2006/03/04 08:58:46 skrll Exp $ */ /* * Copyright 1997 Michael L. Hitch @@ -30,7 +30,7 @@ #include #ifndef lint -__RCSID("$NetBSD: mips_reloc.c,v 1.49 2005/12/24 20:59:30 perry Exp $"); +__RCSID("$NetBSD: mips_reloc.c,v 1.50 2006/03/04 08:58:46 skrll Exp $"); #endif /* not lint */ #include @@ -338,22 +338,58 @@ _rtld_relocate_plt_lazy(const Obj_Entry *obj) return 0; } +static inline int +_rtld_relocate_plt_object(const Obj_Entry *obj, Elf_Word sym, Elf_Addr *tp) +{ + Elf_Addr *got = obj->pltgot; + const Elf_Sym *def; + const Obj_Entry *defobj; + Elf_Addr new_value; + + def = _rtld_find_symdef(sym, obj, &defobj, true); + if (def == NULL) + return -1; + + new_value = (Elf_Addr)(defobj->relocbase + def->st_value); + rdbg(("bind now/fixup in %s --> new=%p", + defobj->strtab + def->st_name, (void *)new_value)); + got[obj->local_gotno + sym - obj->gotsym] = new_value; + + if (tp) + *tp = new_value; + return 0; +} + + + + + caddr_t _rtld_bind(Elf_Word a0, Elf_Addr a1, Elf_Addr a2, Elf_Addr a3) { Elf_Addr *got = (Elf_Addr *)(a2 - 0x7ff0); const Obj_Entry *obj = (Obj_Entry *)(got[1] & 0x7fffffff); - const Elf_Sym *def; - const Obj_Entry *defobj; Elf_Addr new_value; + int err; - def = _rtld_find_symdef(a0, obj, &defobj, true); - if (def == NULL) + err = _rtld_relocate_plt_object(obj, a0, &new_value); + if (err) _rtld_die(); - new_value = (Elf_Addr)(defobj->relocbase + def->st_value); - rdbg(("bind now/fixup in %s --> new=%p", - defobj->strtab + def->st_name, (void *)new_value)); - got[obj->local_gotno + a0 - obj->gotsym] = new_value; - return ((caddr_t)new_value); + return (caddr_t)new_value; +} + +int +_rtld_relocate_plt_objects(const Obj_Entry *obj) +{ + const Elf_Sym *sym = obj->symtab + obj->gotsym; + int i; + + for (i = obj->gotsym; i < obj->symtabno; i++, sym++) { + if (ELF_ST_TYPE(sym->st_info) == STT_FUNC) + if (_rtld_relocate_plt_object(obj, i, NULL) < 0) + return -1; + } + + return 0; } diff --git a/libexec/ld.elf_so/reloc.c b/libexec/ld.elf_so/reloc.c index 3e759eb61f0c..9ad9a814bb3a 100644 --- a/libexec/ld.elf_so/reloc.c +++ b/libexec/ld.elf_so/reloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: reloc.c,v 1.94 2005/07/28 12:35:21 skrll Exp $ */ +/* $NetBSD: reloc.c,v 1.95 2006/03/04 08:58:46 skrll Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: reloc.c,v 1.94 2005/07/28 12:35:21 skrll Exp $"); +__RCSID("$NetBSD: reloc.c,v 1.95 2006/03/04 08:58:46 skrll Exp $"); #endif /* not lint */ #include @@ -190,16 +190,11 @@ _rtld_relocate_objects(Obj_Entry *first, bool bind_now) #if defined(__hppa__) bind_now = 1; #endif -#if defined(__i386__) || defined(__arm__) || defined(__hppa__) \ - || defined(__sparc64__) || defined(__sparc__) || defined(__alpha__) \ - || defined(__sh__) || defined(__x86_64__) || defined(__vax__) \ - || defined(__m68k__) || defined(__powerpc__) if (bind_now) { dbg(("doing immediate PLT binding")); if (_rtld_relocate_plt_objects(obj) < 0) ok = 0; } -#endif if (!ok) return -1;