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 Cause ld.elf_so to find the symbols for __...



details:   https://anonhg.NetBSD.org/src/rev/0996254e5b7c
branches:  trunk
changeset: 484935:0996254e5b7c
user:      erh <erh%NetBSD.org@localhost>
date:      Sat Apr 15 05:41:46 2000 +0000

description:
Cause ld.elf_so to find the symbols for __progname and environ and set them.  If we wait until crt0 gets around to doing it it's too late for any library init functions.

diffstat:

 libexec/ld.elf_so/rtld.c |  41 ++++++++++++++++++++++++++++++++++++++++-
 libexec/ld.elf_so/rtld.h |   3 ++-
 2 files changed, 42 insertions(+), 2 deletions(-)

diffs (86 lines):

diff -r e0bd33736532 -r 0996254e5b7c libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Sat Apr 15 05:27:49 2000 +0000
+++ b/libexec/ld.elf_so/rtld.c  Sat Apr 15 05:41:46 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.c,v 1.30 2000/04/15 05:27:49 christos Exp $        */
+/*     $NetBSD: rtld.c,v 1.31 2000/04/15 05:41:46 erh Exp $     */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -277,6 +277,8 @@
        const char     *ld_bind_now;
        const char    **argv;
        Obj_Entry       *obj;
+       const char **real___progname;
+       char ***real_environ;
 #if defined(RTLD_DEBUG) && !defined(RTLD_RELOCATE_SELF)
        int             i = 0;
 #endif
@@ -457,6 +459,21 @@
        if (_rtld_do_copy_relocations(_rtld_objmain, true) == -1)
                _rtld_die();
 
+       /*
+        * Set the __progname and environ before calling
+        * anything that might use them.
+        */
+       real___progname = _rtld_objmain_sym("__progname");
+       if (real___progname) {
+               if ((*real___progname = strrchr(argv[0], '/')) == NULL)
+                       (*real___progname) = argv[0];
+               else
+                       (*real___progname)++;
+       }
+       real_environ = _rtld_objmain_sym("environ");
+       if (real_environ)
+               *real_environ = environ;
+
        dbg(("calling _init functions"));
        _rtld_call_init_functions(_rtld_objmain->next);
 
@@ -660,6 +677,28 @@
        return obj;
 }
 
+/*
+ * Find a symbol in the main program.
+ */
+void *
+_rtld_objmain_sym(name)
+       const char *name;
+{
+       unsigned long hash;
+       const Elf_Sym *def;
+       const Obj_Entry *obj;
+
+       hash = _rtld_elf_hash(name);
+       obj = _rtld_objmain;
+
+       _rtld_curmark++;
+       def = _rtld_symlook_list(name, hash, &_rtld_list_main, &obj, true);
+
+       if (def != NULL)
+               return obj->relocbase + def->st_value;
+       return(NULL);
+}
+
 void *
 _rtld_dlsym(handle, name)
        void *handle;
diff -r e0bd33736532 -r 0996254e5b7c libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h  Sat Apr 15 05:27:49 2000 +0000
+++ b/libexec/ld.elf_so/rtld.h  Sat Apr 15 05:41:46 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.h,v 1.24 2000/02/08 16:23:00 scottb Exp $  */
+/*     $NetBSD: rtld.h,v 1.25 2000/04/15 05:41:46 erh Exp $     */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -240,6 +240,7 @@
 void _rtld_die __P((void));
 char *_rtld_dlerror __P((void));
 void *_rtld_dlopen __P((const char *, int));
+void *_rtld_objmain_sym __P((const char *));
 void *_rtld_dlsym __P((void *, const char *));
 int _rtld_dlclose __P((void *));
 int _rtld_dladdr __P((const void *, Dl_info *));



Home | Main Index | Thread Index | Old Index