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 Use/require AT_PAGESZ on all platforms. (...



details:   https://anonhg.NetBSD.org/src/rev/0327951c5c50
branches:  trunk
changeset: 536902:0327951c5c50
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Tue Sep 24 01:24:44 2002 +0000

description:
Use/require AT_PAGESZ on all platforms.  (The kernel has exported it for ~3
years now.)  Use _rtld_pagesz instead of getpagesize() to determine the page
size in our local malloc().  Saves a system call.

Also, since we're now relocated early, we don't need to be careful to avoid
globals, so most of the VARPSZ hacks are eliminated.

diffstat:

 libexec/ld.elf_so/malloc.c |   8 +++--
 libexec/ld.elf_so/rtld.c   |  63 +++++----------------------------------------
 libexec/ld.elf_so/rtld.h   |   4 +-
 3 files changed, 15 insertions(+), 60 deletions(-)

diffs (189 lines):

diff -r 59396aab70bf -r 0327951c5c50 libexec/ld.elf_so/malloc.c
--- a/libexec/ld.elf_so/malloc.c        Tue Sep 24 00:53:58 2002 +0000
+++ b/libexec/ld.elf_so/malloc.c        Tue Sep 24 01:24:44 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: malloc.c,v 1.5 1999/06/17 21:13:14 thorpej Exp $       */
+/*     $NetBSD: malloc.c,v 1.6 2002/09/24 01:24:44 mycroft Exp $       */
 
 /*
  * Copyright (c) 1983 Regents of the University of California.
@@ -49,13 +49,15 @@
  */
 
 #include <sys/cdefs.h>
-#include "rtldenv.h"
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
+
+#include "rtld.h"
 
 /*
  * Pre-allocate mmap'ed pages
@@ -150,7 +152,7 @@
         * align break pointer so all data will be page aligned.
         */
        if (pagesz == 0) {
-               pagesz = n = getpagesize();
+               pagesz = n = _rtld_pagesz;
                if (morepages(NPOOLPAGES) == 0)
                        return NULL;
                op = (union overhead *)(pagepool_start);
diff -r 59396aab70bf -r 0327951c5c50 libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Tue Sep 24 00:53:58 2002 +0000
+++ b/libexec/ld.elf_so/rtld.c  Tue Sep 24 01:24:44 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.c,v 1.68 2002/09/24 00:33:39 mycroft Exp $         */
+/*     $NetBSD: rtld.c,v 1.69 2002/09/24 01:24:44 mycroft Exp $         */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -64,7 +64,7 @@
 /*
  * Function declarations.
  */
-static void     _rtld_init __P((caddr_t, caddr_t, int));
+static void     _rtld_init __P((caddr_t, caddr_t));
 static void     _rtld_exit __P((void));
 
 Elf_Addr        _rtld __P((Elf_Addr *, Elf_Addr));
@@ -83,9 +83,7 @@
 Obj_Entry       _rtld_objself; /* The dynamic linker shared object */
 char            _rtld_path[] = _PATH_RTLD;
 Elf_Sym         _rtld_sym_zero;        /* For resolving undefined weak refs. */
-#ifdef VARPSZ
 int            _rtld_pagesz;   /* Page size, as provided by kernel */
-#endif
 
 Objlist _rtld_list_main =      /* Objects loaded at program startup */
   SIMPLEQ_HEAD_INITIALIZER(_rtld_list_main);
@@ -142,9 +140,8 @@
  * this function is to relocate the dynamic linker.
  */
 static void
-_rtld_init(mapbase, relocbase, pagesz)
+_rtld_init(mapbase, relocbase)
        caddr_t mapbase, relocbase;
-       int pagesz;
 {
        Obj_Entry objself;/* The dynamic linker shared object */
        const Elf_Ehdr *hdr = (Elf_Ehdr *) mapbase;
@@ -160,21 +157,9 @@
        objself.phdr = (Elf_Phdr *) (mapbase + hdr->e_phoff);
        for (i = 0; i < hdr->e_phnum; i++) {
                if (objself.phdr[i].p_type == PT_LOAD) {
-#ifdef VARPSZ
-                       /* We can't touch _rtld_pagesz yet so we can't use 
-                          round_*() */
-#define        _rnd_down(x)    ((x) & ~((long)pagesz-1))
-#define        _rnd_up(x)      _rnd_down((x) + pagesz - 1)
-                       objself.textsize = _rnd_up(objself.phdr[i].p_vaddr + 
-                           objself.phdr[i].p_memsz) - 
-                           _rnd_down(objself.phdr[i].p_vaddr);
-#undef _rnd_down
-#undef _rnd_up
-#else
                        objself.textsize = round_up(objself.phdr[i].p_vaddr + 
                            objself.phdr[i].p_memsz) - 
                            round_down(objself.phdr[i].p_vaddr);
-#endif
                        break;
                }
        }
@@ -253,9 +238,7 @@
        const AuxInfo  *pAUX_base, *pAUX_entry, *pAUX_execfd, *pAUX_phdr,
                       *pAUX_phent, *pAUX_phnum, *pAUX_euid, *pAUX_egid,
                       *pAUX_ruid, *pAUX_rgid;
-#ifdef VARPSZ
        const AuxInfo  *pAUX_pagesz;
-#endif
        char          **env;
        const AuxInfo  *aux;
        const AuxInfo  *auxp;
@@ -305,39 +288,9 @@
        pAUX_base = pAUX_entry = pAUX_execfd = NULL;
        pAUX_phdr = pAUX_phent = pAUX_phnum = NULL;
        pAUX_euid = pAUX_ruid = pAUX_egid = pAUX_rgid = NULL;
-#ifdef VARPSZ
        pAUX_pagesz = NULL;
-#endif
-       /*
-        * First pass through the the auxiliary vector, avoiding the use
-        * of a `switch() {}' statement at this stage. A `switch()' may
-        * be translated into code utilizing a jump table approach which
-        * references the equivalent of a global variable. This must be
-        * avoided until _rtld_init() has done its job.
-        * 
-        * _rtld_init() only needs `pAUX_base' and possibly `pAUX_pagesz',
-        * so we look for just those in this pass.
-        */
-       for (auxp = aux; auxp->a_type != AT_NULL; ++auxp) {
-               if (auxp->a_type == AT_BASE)
-                       pAUX_base = auxp;
-#ifdef VARPSZ
-               if (auxp->a_type == AT_PAGESZ)
-                       pAUX_pagesz = auxp;
-#endif
-       }
 
-       /* Initialize and relocate ourselves. */
-       assert(pAUX_base != NULL);
-#ifdef VARPSZ
-       assert(pAUX_pagesz != NULL);
-       _rtld_init((caddr_t)pAUX_base->a_v, (caddr_t)relocbase,
-           (int)pAUX_pagesz->a_v);
-#else
-       _rtld_init((caddr_t)pAUX_base->a_v, (caddr_t)relocbase, 0);
-#endif
-
-       /* Digest the auxiliary vector (full pass now that we can afford it). */
+       /* Digest the auxiliary vector. */
        for (auxp = aux; auxp->a_type != AT_NULL; ++auxp) {
                switch (auxp->a_type) {
                case AT_BASE:
@@ -372,17 +325,17 @@
                        pAUX_rgid = auxp;
                        break;
 #endif
-#ifdef VARPSZ
                case AT_PAGESZ:
                        pAUX_pagesz = auxp;
                        break;
-#endif
                }
        }
 
-#ifdef VARPSZ
+       /* Initialize and relocate ourselves. */
+       assert(pAUX_base != NULL);
+       assert(pAUX_pagesz != NULL);
        _rtld_pagesz = (int)pAUX_pagesz->a_v;
-#endif
+       _rtld_init((caddr_t)pAUX_base->a_v, (caddr_t)relocbase);
 
 #ifdef RTLD_DEBUG
        dbg(("_ctype_ is %p\n", _ctype_));
diff -r 59396aab70bf -r 0327951c5c50 libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h  Tue Sep 24 00:53:58 2002 +0000
+++ b/libexec/ld.elf_so/rtld.h  Tue Sep 24 01:24:44 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.h,v 1.53 2002/09/23 23:56:49 mycroft Exp $         */
+/*     $NetBSD: rtld.h,v 1.54 2002/09/24 01:24:44 mycroft Exp $         */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -57,9 +57,9 @@
 #define LIBDIRLEN      (sizeof LIBDIR - 1)
 #define SVR4_LIBDIRLEN (sizeof SVR4_LIBDIR - 1)
 
+extern int _rtld_pagesz;
 #ifndef        PAGESIZE
 # ifdef VARPSZ
-extern int _rtld_pagesz;
 #  ifdef RTLD_DEBUG
 #   define PAGESIZE    (assert(_rtld_pagesz), _rtld_pagesz)
 #  else



Home | Main Index | Thread Index | Old Index