Module Name: src
Committed By: skrll
Date: Fri Jan 6 10:38:57 UTC 2012
Modified Files:
src/libexec/ld.elf_so: reloc.c
src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c rtld_start.S
Log Message:
Implement lazy binding on hppa. rump_server needs it!?!?!
Mostly from OpenBSD.
To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.41 -r1.42 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
cvs rdiff -u -r1.11 -r1.12 src/libexec/ld.elf_so/arch/hppa/rtld_start.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.105 src/libexec/ld.elf_so/reloc.c:1.106
--- src/libexec/ld.elf_so/reloc.c:1.105 Fri Dec 2 09:06:49 2011
+++ src/libexec/ld.elf_so/reloc.c Fri Jan 6 10:38:56 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: reloc.c,v 1.105 2011/12/02 09:06:49 skrll Exp $ */
+/* $NetBSD: reloc.c,v 1.106 2012/01/06 10:38:56 skrll Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.105 2011/12/02 09:06:49 skrll Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.106 2012/01/06 10:38:56 skrll Exp $");
#endif /* not lint */
#include <err.h>
@@ -195,9 +195,6 @@ _rtld_relocate_objects(Obj_Entry *first,
dbg(("doing lazy PLT binding"));
if (_rtld_relocate_plt_lazy(obj) < 0)
ok = 0;
-#if defined(__hppa__)
- bind_now = 1;
-#endif
if (obj->z_now || bind_now) {
dbg(("doing immediate PLT binding"));
if (_rtld_relocate_plt_objects(obj) < 0)
Index: src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
diff -u src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.41 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.42
--- src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.41 Sun Dec 4 16:53:08 2011
+++ src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c Fri Jan 6 10:38:57 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: hppa_reloc.c,v 1.41 2011/12/04 16:53:08 skrll Exp $ */
+/* $NetBSD: hppa_reloc.c,v 1.42 2012/01/06 10:38:57 skrll Exp $ */
/*-
* Copyright (c) 2002, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hppa_reloc.c,v 1.41 2011/12/04 16:53:08 skrll Exp $");
+__RCSID("$NetBSD: hppa_reloc.c,v 1.42 2012/01/06 10:38:57 skrll Exp $");
#endif /* not lint */
#include <stdlib.h>
@@ -82,6 +82,30 @@ store_ptr(void *where, Elf_Addr val)
(void)memcpy(where, &val, sizeof(val));
}
+static __inline void
+fdc(void *addr)
+{
+ __asm volatile("fdc %%r0(%%sr0, %0)" : : "r" (addr));
+}
+
+static __inline void
+fic(void *addr)
+{
+ __asm volatile("fic %%r0(%%sr0,%0)" : : "r" (addr));
+}
+
+static __inline void
+sync(void)
+{
+ __asm volatile("sync" : : : "memory");
+}
+
+#define PLT_STUB_MAGIC1 0x00c0ffee
+#define PLT_STUB_MAGIC2 0xdeadbeef
+
+#define PLT_STUB_INSN1 0x0e801081 /* ldw 0(%r20), %r1 */
+#define PLT_STUB_INSN2 0xe820c000 /* bv %r0(%r1) */
+
/*
* In the runtime architecture (ABI), PLABEL function pointers are
* distinguished from normal function pointers by having the next-least-
@@ -355,7 +379,34 @@ _rtld_function_descriptor_function(const
void
_rtld_setup_pltgot(const Obj_Entry *obj)
{
- __rtld_setup_hppa_pltgot(obj, obj->pltgot);
+ Elf_Word *got = obj->pltgot;
+
+ assert(got[-2] == PLT_STUB_MAGIC1);
+ assert(got[-1] == PLT_STUB_MAGIC2);
+
+ __rtld_setup_hppa_pltgot(obj, got);
+
+ fdc(&got[-2]);
+ fdc(&got[-1]);
+ fdc(&got[1]);
+ sync();
+ fic(&got[-2]);
+ fic(&got[-1]);
+ fic(&got[1]);
+ sync();
+
+ /*
+ * libc makes use of %t1 (%r22) to pass errno values to __cerror. Fixup
+ * the PLT stub to not use %r22.
+ */
+ got[-7] = PLT_STUB_INSN1;
+ got[-6] = PLT_STUB_INSN2;
+ fdc(&got[-7]);
+ fdc(&got[-6]);
+ sync();
+ fic(&got[-7]);
+ fic(&got[-6]);
+ sync();
}
int
Index: src/libexec/ld.elf_so/arch/hppa/rtld_start.S
diff -u src/libexec/ld.elf_so/arch/hppa/rtld_start.S:1.11 src/libexec/ld.elf_so/arch/hppa/rtld_start.S:1.12
--- src/libexec/ld.elf_so/arch/hppa/rtld_start.S:1.11 Fri Sep 30 03:05:43 2011
+++ src/libexec/ld.elf_so/arch/hppa/rtld_start.S Fri Jan 6 10:38:57 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: rtld_start.S,v 1.11 2011/09/30 03:05:43 mrg Exp $ */
+/* $NetBSD: rtld_start.S,v 1.12 2012/01/06 10:38:57 skrll Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -181,6 +181,7 @@ ENTRY(_rtld_bind_start,HPPA_FRAME_SIZE)
/* 0(%r3) is filled with the saved %r3 above */
stw %ret0, 4(%r3)
stw %ret1, 8(%r3)
+ stw %t1, 12(%r3) /* %r22 */
/*
* The linker PLT stub loads %r20 with (GOT - 8) for the object that
@@ -220,6 +221,7 @@ ENTRY(_rtld_bind_start,HPPA_FRAME_SIZE)
ldw HPPA_FRAME_ARG(3)(%r3), %arg3
ldw 4(%r3), %ret0
ldw 8(%r3), %ret1
+ ldw 12(%r3), %t1 /* %r22 */
/* End stack calling convention. */
ldo HPPA_FRAME_SIZE(%r3), %sp