Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ld.elf_so Like Sparc, PowerPC can use IRELATIVE relo...



details:   https://anonhg.NetBSD.org/src/rev/03d9a90369fa
branches:  trunk
changeset: 321299:03d9a90369fa
user:      joerg <joerg%NetBSD.org@localhost>
date:      Fri Mar 09 20:19:11 2018 +0000

description:
Like Sparc, PowerPC can use IRELATIVE relocations in non-PLT sections.

diffstat:

 libexec/ld.elf_so/arch/powerpc/ppc_reloc.c |  30 +++++++++++++++++++++++++-----
 libexec/ld.elf_so/rtld.c                   |   6 +++---
 libexec/ld.elf_so/rtld.h                   |   4 ++--
 3 files changed, 30 insertions(+), 10 deletions(-)

diffs (111 lines):

diff -r 7c0f71b6431a -r 03d9a90369fa libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
--- a/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c        Fri Mar 09 20:16:54 2018 +0000
+++ b/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c        Fri Mar 09 20:19:11 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ppc_reloc.c,v 1.55 2017/08/10 19:03:26 joerg Exp $     */
+/*     $NetBSD: ppc_reloc.c,v 1.56 2018/03/09 20:19:11 joerg Exp $     */
 
 /*-
  * Copyright (C) 1998  Tsubai Masanari
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ppc_reloc.c,v 1.55 2017/08/10 19:03:26 joerg Exp $");
+__RCSID("$NetBSD: ppc_reloc.c,v 1.56 2018/03/09 20:19:11 joerg Exp $");
 #endif /* not lint */
 
 #include <stdarg.h>
@@ -285,6 +285,14 @@
                            obj->path, (void *)*where, defobj->path));
                        break;
 
+               case R_TYPE(IRELATIVE):
+                       /* IFUNC relocations are handled in _rtld_call_ifunc */
+                       if (obj->ifunc_remaining_nonplt == 0) {
+                               obj->ifunc_remaining_nonplt =
+                                   rela - obj->rela + 1;
+                       }
+                       break;
+
                default:
                        rdbg(("sym = %lu, type = %lu, offset = %p, "
                            "addend = %p, contents = %p, symbol = %s",
@@ -314,10 +322,9 @@
 #else
        Elf_Addr * const pltresolve = obj->pltgot + 8;
        const Elf_Rela *rela;
-       int reloff;
 
-       rela = obj->pltrelalim;
-       for (reloff = rela - obj->pltrela; rela-- > obj->pltrela; --reloff) {
+       for (rela = obj->pltrelalim; rela-- > obj->pltrela;) {
+               size_t reloff = rela - obj->pltrela;
                Elf_Word *where = (Elf_Word *)(obj->relocbase + rela->r_offset);
 
                assert(ELF_R_TYPE(rela->r_info) == R_TYPE(JUMP_SLOT) ||
@@ -383,6 +390,19 @@
                                *where = target;
                }
        }
+
+       while (obj->ifunc_remaining_nonplt > 0 && _rtld_objgen == cur_objgen) {
+               rela = obj->relalim - --obj->ifunc_remaining_nonplt;
+               if (ELF_R_TYPE(rela->r_info) != R_TYPE(IRELATIVE))
+                       continue;
+               where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
+               target = (Elf_Addr)(obj->relocbase + rela->r_addend);
+               _rtld_exclusive_exit(mask);
+               target = _rtld_resolve_ifunc2(obj, target);
+               _rtld_exclusive_enter(mask);
+               if (*where != target)
+                       *where = target;
+       }
 }
 
 static int
diff -r 7c0f71b6431a -r 03d9a90369fa libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Fri Mar 09 20:16:54 2018 +0000
+++ b/libexec/ld.elf_so/rtld.c  Fri Mar 09 20:19:11 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.c,v 1.190 2018/02/11 18:58:44 jakllsch Exp $       */
+/*     $NetBSD: rtld.c,v 1.191 2018/03/09 20:19:11 joerg Exp $  */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.190 2018/02/11 18:58:44 jakllsch Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.191 2018/03/09 20:19:11 joerg Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -263,7 +263,7 @@
 _rtld_call_ifunc_functions(sigset_t *mask, Obj_Entry *obj, u_int cur_objgen)
 {
        if (obj->ifunc_remaining
-#ifdef __sparc__
+#if defined(__sparc__) || defined(__powerpc__)
            || obj->ifunc_remaining_nonplt
 #endif
        ) {
diff -r 7c0f71b6431a -r 03d9a90369fa libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h  Fri Mar 09 20:16:54 2018 +0000
+++ b/libexec/ld.elf_so/rtld.h  Fri Mar 09 20:19:11 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.h,v 1.131 2017/08/12 09:03:27 joerg Exp $  */
+/*     $NetBSD: rtld.h,v 1.132 2018/03/09 20:19:11 joerg Exp $  */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -300,7 +300,7 @@
        size_t          fini_arraysz;   /* # of entries in it */
        /* IRELATIVE relocations */
        size_t          ifunc_remaining;
-#ifdef __sparc__
+#if defined(__sparc__) || defined(__powerpc__)
        /* On SPARC, the PLT variant is called JMP_IREL and counted above. */
        size_t          ifunc_remaining_nonplt;
 #endif



Home | Main Index | Thread Index | Old Index