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 Avoid the use of a `switch(){}' statement ...



details:   https://anonhg.NetBSD.org/src/rev/bb56f3567ead
branches:  trunk
changeset: 503237:bb56f3567ead
user:      pk <pk%NetBSD.org@localhost>
date:      Sat Feb 03 13:25:00 2001 +0000

description:
Avoid the use of a `switch(){}' statement before _rtld_init() is called.
`switch()' code may be translated using a jump table approach which causes
it to reference the equivalent of a global variable, something that must
be avoided before _rtld_init() has run.

diffstat:

 libexec/ld.elf_so/rtld.c |  41 ++++++++++++++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 11 deletions(-)

diffs (67 lines):

diff -r 55ae569ee495 -r bb56f3567ead libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Sat Feb 03 13:02:20 2001 +0000
+++ b/libexec/ld.elf_so/rtld.c  Sat Feb 03 13:25:00 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.c,v 1.43 2000/11/10 23:53:04 mycroft Exp $         */
+/*     $NetBSD: rtld.c,v 1.44 2001/02/03 13:25:00 pk Exp $      */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -334,12 +334,40 @@
        }
        aux = (const AuxInfo *) sp;
 
-       /* Digest the auxiliary vector. */
        pAUX_base = pAUX_entry = pAUX_execfd = NULL;
        pAUX_phdr = pAUX_phent = pAUX_phnum = 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, (int)pAUX_pagesz->a_v);
+#else
+       _rtld_init((caddr_t) pAUX_base->a_v, 0);
+#endif
+
+       /* Digest the auxiliary vector (full pass now that we can afford it). */
        for (auxp = aux; auxp->a_type != AT_NULL; ++auxp) {
                switch (auxp->a_type) {
                case AT_BASE:
@@ -368,15 +396,6 @@
                }
        }
 
-       /* Initialize and relocate ourselves. */
-       assert(pAUX_base != NULL);
-#ifdef VARPSZ
-       assert(pAUX_pagesz != NULL);
-       _rtld_init((caddr_t) pAUX_base->a_v, (int)pAUX_pagesz->a_v);
-#else
-       _rtld_init((caddr_t) pAUX_base->a_v, 0);
-#endif
-
 #ifdef VARPSZ
        _rtld_pagesz = (int)pAUX_pagesz->a_v;
 #endif



Home | Main Index | Thread Index | Old Index