summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf/i386
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>1999-06-25 02:53:59 +0000
committerjdp <jdp@FreeBSD.org>1999-06-25 02:53:59 +0000
commit2be78ea16b1b57cbbbb05a25df4da4e456886b1e (patch)
tree83d8009aa5e1c5ab9099cc0f005d362f28775078 /libexec/rtld-elf/i386
parent5ebdb91f86b4fa1cd4c6463fe611646aaccb77e3 (diff)
downloadFreeBSD-src-2be78ea16b1b57cbbbb05a25df4da4e456886b1e.zip
FreeBSD-src-2be78ea16b1b57cbbbb05a25df4da4e456886b1e.tar.gz
Fix a serious performance bug for large programs on the Alpha,
discovered by Hidetoshi Shimokawa. Large programs need multiple GOTs. The lazy binding stub in the PLT can be reached from any of these GOTs, but the dynamic linker only has enough information to fix up the first GOT entry. Thus calls through the other GOTs went through the time-consuming lazy binding process on every call. This fix rewrites the PLT entries themselves to bypass the lazy binding. Tested by Hidetoshi Shimokawa and Steve Price. Reviewed by: Doug Rabson <dfr@freebsd.org>
Diffstat (limited to 'libexec/rtld-elf/i386')
-rw-r--r--libexec/rtld-elf/i386/reloc.c46
-rw-r--r--libexec/rtld-elf/i386/rtld_machdep.h10
2 files changed, 30 insertions, 26 deletions
diff --git a/libexec/rtld-elf/i386/reloc.c b/libexec/rtld-elf/i386/reloc.c
index 82c0e8e..bdae921 100644
--- a/libexec/rtld-elf/i386/reloc.c
+++ b/libexec/rtld-elf/i386/reloc.c
@@ -1,5 +1,5 @@
/*-
- * Copyright 1996-1998 John D. Polstra.
+ * Copyright 1996, 1997, 1998, 1999 John D. Polstra.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -22,7 +22,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: reloc.c,v 1.1 1998/09/04 19:03:57 dfr Exp $
+ * $Id: reloc.c,v 1.2 1999/04/09 00:28:43 jdp Exp $
*/
/*
@@ -214,33 +214,29 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
int
reloc_plt(Obj_Entry *obj, bool bind_now)
{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
+ const Elf_Rel *rellim;
+ const Elf_Rel *rel;
- /* Process the PLT relocations. */
- rellim = (const Elf_Rel *) ((caddr_t) obj->pltrel + obj->pltrelsize);
- if (bind_now) {
- /* Fully resolve procedure addresses now */
- for (rel = obj->pltrel; rel < rellim; rel++) {
- Elf_Addr *where = (Elf_Addr *)
- (obj->relocbase + rel->r_offset);
- const Elf_Sym *def;
- const Obj_Entry *defobj;
+ rellim = (const Elf_Rel *)((char *)obj->pltrel + obj->pltrelsize);
+ for (rel = obj->pltrel; rel < rellim; rel++) {
+ Elf_Addr *where;
- assert(ELF_R_TYPE(rel->r_info) == R_386_JMP_SLOT);
+ assert(ELF_R_TYPE(rel->r_info) == R_386_JMP_SLOT);
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true);
- if (def == NULL)
- return -1;
+ /* Relocate the GOT slot pointing into the PLT. */
+ where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
+ *where += (Elf_Addr)obj->relocbase;
- *where = (Elf_Addr) (defobj->relocbase + def->st_value);
- }
- } else { /* Just relocate the GOT slots pointing into the PLT */
- for (rel = obj->pltrel; rel < rellim; rel++) {
- Elf_Addr *where = (Elf_Addr *)
- (obj->relocbase + rel->r_offset);
- *where += (Elf_Addr) obj->relocbase;
- }
+ if (bind_now) { /* Fully resolve the procedure address. */
+ const Elf_Sym *def;
+ const Obj_Entry *defobj;
+
+ def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true);
+ if (def == NULL)
+ return -1;
+ reloc_jmpslot(where,
+ (Elf_Addr)(defobj->relocbase + def->st_value));
}
+ }
return 0;
}
diff --git a/libexec/rtld-elf/i386/rtld_machdep.h b/libexec/rtld-elf/i386/rtld_machdep.h
index 89a9322..fe39d43 100644
--- a/libexec/rtld-elf/i386/rtld_machdep.h
+++ b/libexec/rtld-elf/i386/rtld_machdep.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: rtld_machdep.h,v 1.1 1999/04/09 00:28:43 jdp Exp $
*/
#ifndef RTLD_MACHDEP_H
@@ -33,4 +33,12 @@
#define rtld_dynamic(obj) \
((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
+/* Fixup the jump slot at "where" to transfer control to "target". */
+#define reloc_jmpslot(where, target) \
+ do { \
+ dbg("reloc_jmpslot: *%p = %p", (void *)(where), \
+ (void *)(target)); \
+ (*(Elf_Addr *)(where) = (Elf_Addr)(target)); \
+ } while (0)
+
#endif
OpenPOWER on IntegriCloud