Source-Changes-HG archive

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

[src/trunk]: src Add IRELATIVE support for ARM, X86 and PowerPC.



details:   https://anonhg.NetBSD.org/src/rev/b3cc66c4f7c4
branches:  trunk
changeset: 826008:b3cc66c4f7c4
user:      joerg <joerg%NetBSD.org@localhost>
date:      Thu Aug 10 19:03:25 2017 +0000

description:
Add IRELATIVE support for ARM, X86 and PowerPC.

diffstat:

 libexec/ld.elf_so/arch/aarch64/mdreloc.c                  |   6 +-
 libexec/ld.elf_so/arch/alpha/alpha_reloc.c                |   6 +-
 libexec/ld.elf_so/arch/arm/mdreloc.c                      |  34 +++++++-
 libexec/ld.elf_so/arch/hppa/hppa_reloc.c                  |   6 +-
 libexec/ld.elf_so/arch/i386/mdreloc.c                     |  37 ++++++++-
 libexec/ld.elf_so/arch/m68k/mdreloc.c                     |   6 +-
 libexec/ld.elf_so/arch/mips/mips_reloc.c                  |   6 +-
 libexec/ld.elf_so/arch/or1k/mdreloc.c                     |   6 +-
 libexec/ld.elf_so/arch/powerpc/ppc_reloc.c                |  42 +++++++++-
 libexec/ld.elf_so/arch/riscv/mdreloc.c                    |   6 +-
 libexec/ld.elf_so/arch/sh3/mdreloc.c                      |   6 +-
 libexec/ld.elf_so/arch/sparc/mdreloc.c                    |   6 +-
 libexec/ld.elf_so/arch/sparc64/mdreloc.c                  |   6 +-
 libexec/ld.elf_so/arch/vax/mdreloc.c                      |   6 +-
 libexec/ld.elf_so/arch/x86_64/mdreloc.c                   |  38 ++++++++-
 libexec/ld.elf_so/reloc.c                                 |  15 +++-
 libexec/ld.elf_so/rtld.c                                  |  21 ++++-
 libexec/ld.elf_so/rtld.h                                  |  10 ++-
 sys/arch/arm/include/elf_machdep.h                        |   4 +-
 sys/arch/powerpc/include/elf_machdep.h                    |   5 +-
 sys/sys/cdefs_elf.h                                       |  12 ++-
 tests/libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c |  16 ++++
 tests/libexec/ld.elf_so/t_ifunc.c                         |  57 ++++++++++++++-
 23 files changed, 289 insertions(+), 68 deletions(-)

diffs (truncated from 891 to 300 lines):

diff -r 734ce255df9e -r b3cc66c4f7c4 libexec/ld.elf_so/arch/aarch64/mdreloc.c
--- a/libexec/ld.elf_so/arch/aarch64/mdreloc.c  Thu Aug 10 18:45:20 2017 +0000
+++ b/libexec/ld.elf_so/arch/aarch64/mdreloc.c  Thu Aug 10 19:03:25 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mdreloc.c,v 1.3 2017/06/19 11:57:01 joerg Exp $ */
+/* $NetBSD: mdreloc.c,v 1.4 2017/08/10 19:03:25 joerg Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.3 2017/06/19 11:57:01 joerg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.4 2017/08/10 19:03:25 joerg Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -190,7 +190,7 @@
 }
 
 int
-_rtld_relocate_plt_lazy(const Obj_Entry *obj)
+_rtld_relocate_plt_lazy(Obj_Entry *obj)
 {
 
        if (!obj->relocbase)
diff -r 734ce255df9e -r b3cc66c4f7c4 libexec/ld.elf_so/arch/alpha/alpha_reloc.c
--- a/libexec/ld.elf_so/arch/alpha/alpha_reloc.c        Thu Aug 10 18:45:20 2017 +0000
+++ b/libexec/ld.elf_so/arch/alpha/alpha_reloc.c        Thu Aug 10 19:03:25 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: alpha_reloc.c,v 1.42 2017/06/19 11:57:01 joerg Exp $   */
+/*     $NetBSD: alpha_reloc.c,v 1.43 2017/08/10 19:03:26 joerg Exp $   */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -62,7 +62,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: alpha_reloc.c,v 1.42 2017/06/19 11:57:01 joerg Exp $");
+__RCSID("$NetBSD: alpha_reloc.c,v 1.43 2017/08/10 19:03:26 joerg Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -343,7 +343,7 @@
 }
 
 int
-_rtld_relocate_plt_lazy(const Obj_Entry *obj)
+_rtld_relocate_plt_lazy(Obj_Entry *obj)
 {
        const Elf_Rela *rela;
 
diff -r 734ce255df9e -r b3cc66c4f7c4 libexec/ld.elf_so/arch/arm/mdreloc.c
--- a/libexec/ld.elf_so/arch/arm/mdreloc.c      Thu Aug 10 18:45:20 2017 +0000
+++ b/libexec/ld.elf_so/arch/arm/mdreloc.c      Thu Aug 10 19:03:25 2017 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: mdreloc.c,v 1.41 2017/06/20 12:41:49 joerg Exp $       */
+/*     $NetBSD: mdreloc.c,v 1.42 2017/08/10 19:03:26 joerg Exp $       */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.41 2017/06/20 12:41:49 joerg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.42 2017/08/10 19:03:26 joerg Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -253,17 +253,21 @@
 }
 
 int
-_rtld_relocate_plt_lazy(const Obj_Entry *obj)
+_rtld_relocate_plt_lazy(Obj_Entry *obj)
 {
        const Elf_Rel *rel;
 
        if (!obj->relocbase)
                return 0;
 
-       for (rel = obj->pltrel; rel < obj->pltrellim; rel++) {
+       for (rel = obj->pltrellim; rel-- > obj->pltrel; ) {
                Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
 
-               assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JUMP_SLOT));
+               assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JUMP_SLOT) ||
+                      ELF_R_TYPE(rel->r_info) == R_TYPE(IRELATIVE));
+
+               if (ELF_R_TYPE(rel->r_info) == R_TYPE(IRELATIVE))
+                       obj->ifunc_remaining = obj->pltrellim - rel;
 
                /* Just relocate the GOT slots pointing into the PLT */
                *where += (Elf_Addr)obj->relocbase;
@@ -273,6 +277,26 @@
        return 0;
 }
 
+void
+_rtld_call_ifunc(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen)
+{
+       const Elf_Rel *rel;
+       Elf_Addr *where, target;
+
+       while (obj->ifunc_remaining > 0 && _rtld_objgen == cur_objgen) {
+               rel = obj->pltrellim - obj->ifunc_remaining;
+               --obj->ifunc_remaining;
+               if (ELF_R_TYPE(rel->r_info) == R_TYPE(IRELATIVE)) {
+                       where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
+                       _rtld_exclusive_exit(mask);
+                       target = _rtld_resolve_ifunc2(obj, *where);
+                       _rtld_exclusive_enter(mask);
+                       if (*where != target)
+                               *where = target;
+               }
+       }
+}
+
 static int
 _rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rel *rel,
        Elf_Addr *tp)
diff -r 734ce255df9e -r b3cc66c4f7c4 libexec/ld.elf_so/arch/hppa/hppa_reloc.c
--- a/libexec/ld.elf_so/arch/hppa/hppa_reloc.c  Thu Aug 10 18:45:20 2017 +0000
+++ b/libexec/ld.elf_so/arch/hppa/hppa_reloc.c  Thu Aug 10 19:03:25 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hppa_reloc.c,v 1.44 2017/06/19 11:57:01 joerg Exp $    */
+/*     $NetBSD: hppa_reloc.c,v 1.45 2017/08/10 19:03:26 joerg 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.44 2017/06/19 11:57:01 joerg Exp $");
+__RCSID("$NetBSD: hppa_reloc.c,v 1.45 2017/08/10 19:03:26 joerg Exp $");
 #endif /* not lint */
 
 #include <stdlib.h>
@@ -589,7 +589,7 @@
 }
 
 int
-_rtld_relocate_plt_lazy(const Obj_Entry *obj)
+_rtld_relocate_plt_lazy(Obj_Entry *obj)
 {
        const Elf_Rela *rela;
 
diff -r 734ce255df9e -r b3cc66c4f7c4 libexec/ld.elf_so/arch/i386/mdreloc.c
--- a/libexec/ld.elf_so/arch/i386/mdreloc.c     Thu Aug 10 18:45:20 2017 +0000
+++ b/libexec/ld.elf_so/arch/i386/mdreloc.c     Thu Aug 10 19:03:25 2017 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: mdreloc.c,v 1.38 2017/06/19 11:57:01 joerg Exp $       */
+/*     $NetBSD: mdreloc.c,v 1.39 2017/08/10 19:03:26 joerg Exp $       */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.38 2017/06/19 11:57:01 joerg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.39 2017/08/10 19:03:26 joerg Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -194,17 +194,21 @@
 }
 
 int
-_rtld_relocate_plt_lazy(const Obj_Entry *obj)
+_rtld_relocate_plt_lazy(Obj_Entry *obj)
 {
        const Elf_Rel *rel;
 
        if (!obj->relocbase)
                return 0;
 
-       for (rel = obj->pltrel; rel < obj->pltrellim; rel++) {
+       for (rel = obj->pltrellim; rel-- > obj->pltrel; ) {
                Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
 
-               assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JMP_SLOT));
+               assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JMP_SLOT) ||
+                      ELF_R_TYPE(rel->r_info) == R_TYPE(IRELATIVE));
+
+               if (ELF_R_TYPE(rel->r_info) == R_TYPE(IRELATIVE))
+                       obj->ifunc_remaining = obj->pltrellim - rel;
 
                /* Just relocate the GOT slots pointing into the PLT */
                *where += (Elf_Addr)obj->relocbase;
@@ -214,6 +218,26 @@
        return 0;
 }
 
+void
+_rtld_call_ifunc(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen)
+{
+       const Elf_Rel *rel;
+       Elf_Addr *where, target;
+
+       while (obj->ifunc_remaining > 0 && _rtld_objgen == cur_objgen) {
+               rel = obj->pltrellim - obj->ifunc_remaining;
+               --obj->ifunc_remaining;
+               if (ELF_R_TYPE(rel->r_info) == R_TYPE(IRELATIVE)) {
+                       where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
+                       _rtld_exclusive_exit(mask);
+                       target = _rtld_resolve_ifunc2(obj, *where);
+                       _rtld_exclusive_enter(mask);
+                       if (*where != target)
+                               *where = target;
+               }
+       }
+}
+
 static inline int
 _rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rel *rel,
        Elf_Addr *tp)
@@ -224,6 +248,9 @@
        const Obj_Entry *defobj;
        unsigned long info = rel->r_info;
 
+       if (ELF_R_TYPE(info) == R_TYPE(IRELATIVE))
+               return 0;
+
        assert(ELF_R_TYPE(info) == R_TYPE(JMP_SLOT));
 
        def = _rtld_find_plt_symdef(ELF_R_SYM(info), obj, &defobj, tp != NULL);
diff -r 734ce255df9e -r b3cc66c4f7c4 libexec/ld.elf_so/arch/m68k/mdreloc.c
--- a/libexec/ld.elf_so/arch/m68k/mdreloc.c     Thu Aug 10 18:45:20 2017 +0000
+++ b/libexec/ld.elf_so/arch/m68k/mdreloc.c     Thu Aug 10 19:03:25 2017 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: mdreloc.c,v 1.32 2017/06/19 11:57:01 joerg Exp $       */
+/*     $NetBSD: mdreloc.c,v 1.33 2017/08/10 19:03:26 joerg Exp $       */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.32 2017/06/19 11:57:01 joerg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.33 2017/08/10 19:03:26 joerg Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -181,7 +181,7 @@
 }
 
 int
-_rtld_relocate_plt_lazy(const Obj_Entry *obj)
+_rtld_relocate_plt_lazy(Obj_Entry *obj)
 {
        const Elf_Rela *rela;
 
diff -r 734ce255df9e -r b3cc66c4f7c4 libexec/ld.elf_so/arch/mips/mips_reloc.c
--- a/libexec/ld.elf_so/arch/mips/mips_reloc.c  Thu Aug 10 18:45:20 2017 +0000
+++ b/libexec/ld.elf_so/arch/mips/mips_reloc.c  Thu Aug 10 19:03:25 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mips_reloc.c,v 1.68 2017/06/21 12:34:01 joerg Exp $    */
+/*     $NetBSD: mips_reloc.c,v 1.69 2017/08/10 19:03:26 joerg Exp $    */
 
 /*
  * Copyright 1997 Michael L. Hitch <mhitch%montana.edu@localhost>
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mips_reloc.c,v 1.68 2017/06/21 12:34:01 joerg Exp $");
+__RCSID("$NetBSD: mips_reloc.c,v 1.69 2017/08/10 19:03:26 joerg Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -480,7 +480,7 @@
 }
 
 int
-_rtld_relocate_plt_lazy(const Obj_Entry *obj)
+_rtld_relocate_plt_lazy(Obj_Entry *obj)
 {
        /* PLT fixups were done above in the GOT relocation. */
        return 0;
diff -r 734ce255df9e -r b3cc66c4f7c4 libexec/ld.elf_so/arch/or1k/mdreloc.c
--- a/libexec/ld.elf_so/arch/or1k/mdreloc.c     Thu Aug 10 18:45:20 2017 +0000
+++ b/libexec/ld.elf_so/arch/or1k/mdreloc.c     Thu Aug 10 19:03:25 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mdreloc.c,v 1.2 2017/06/19 11:57:02 joerg Exp $        */
+/*     $NetBSD: mdreloc.c,v 1.3 2017/08/10 19:03:26 joerg Exp $        */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.2 2017/06/19 11:57:02 joerg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.3 2017/08/10 19:03:26 joerg Exp $");
 #endif /* not lint */
 
 #include <stdarg.h>
@@ -210,7 +210,7 @@
 }
 
 int
-_rtld_relocate_plt_lazy(const Obj_Entry *obj)
+_rtld_relocate_plt_lazy(Obj_Entry *obj)
 {
        const Elf_Rela *rela;
        int reloff;



Home | Main Index | Thread Index | Old Index