about summary refs log tree commit diff
path: root/elf/rtld.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-03-05 14:03:24 +0000
committerUlrich Drepper <drepper@redhat.com>1998-03-05 14:03:24 +0000
commitea278354429c511389edab51dcb588343652601d (patch)
treea78e3c472ce68aa2d1b1e5b415edd5f68e8969ec /elf/rtld.c
parent2eb45444a74df5f8d47ba14e318aff2e78a915db (diff)
downloadglibc-ea278354429c511389edab51dcb588343652601d.tar.gz
glibc-ea278354429c511389edab51dcb588343652601d.tar.xz
glibc-ea278354429c511389edab51dcb588343652601d.zip
Update.
1998-03-05  Ulrich Drepper  <drepper@cygnus.com>

	* elf/rtld.c: Speed up processing of environment variables.  Do
	only one run on the environment by avoiding to call getenv.
	* sysdeps/generic/dl-sysdep.c (_dl_next_ld_env_entry): New
	function.  Used by patch above.

1998-03-05 10:25  Ulrich Drepper  <drepper@cygnus.com>

	* nss/getXXbyYY_r.c: Don't try to contact nscd every time when it
	failed.  Only do this every NSS_NSCD_RETRY times.
	* nss/nsswitch.c: Define __nss_nscd_not_available, used by above
	change.
	* nscd/nscd_getgr_r.c (__nscd_getgr_r): Return 2 if contacting the
	daemon failed.
	* nscd/nscd_getpw_r.c (__nscd_getpw_r): Likewise.

1998-03-05  Ulrich Drepper  <drepper@cygnus.com>

	* nss/nsswitch.c (nss_lookup_function): Don't modify errno if NSS
	module cannot be found.  Reported by Andreas Jaeger.

1998-03-05 11:40  Franz Sirl <Franz.Sirl-kernel@lauterbach.com>

	* nscd/nscd_getgr_r.c: Change char to int to avoid compiler warning
	on platforms which default to unsigned chars.
	* nscd/nscd_getpw_r.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sysdep.h: Undefine L before
	defining it.

1998-03-05  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* elf/Makefile (install-bin): Change = to += for sprof to install
	ldd also.
Diffstat (limited to 'elf/rtld.c')
-rw-r--r--elf/rtld.c141
1 files changed, 104 insertions, 37 deletions
diff --git a/elf/rtld.c b/elf/rtld.c
index 95830c54c2..2707da60df 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -53,6 +53,15 @@ static void print_unresolved (int errcode, const char *objname,
 static void print_missing_version (int errcode, const char *objname,
 				   const char *errsting);
 
+
+/* This is a list of all the modes the dynamic loader can be in.  */
+enum mode { normal, list, verify, trace };
+
+/* Process all environments variables the dynamic linker must recognize.
+   Since all of them start with `LD_' we are a bit smarter while finding
+   all the entries.  */
+static void process_envvars (enum mode *modep, int *lazyp);
+
 int _dl_argc;
 char **_dl_argv;
 const char *_dl_rpath;
@@ -147,7 +156,6 @@ _dl_start (void *arg)
   return _dl_sysdep_start (arg, &dl_main);
 }
 
-
 /* Now life is peachy; we can do all normal operations.
    On to the real work.  */
 
@@ -260,7 +268,7 @@ dl_main (const ElfW(Phdr) *phdr,
   const ElfW(Phdr) *ph;
   struct link_map *main_map;
   int lazy;
-  enum { normal, list, verify, trace } mode;
+  enum mode mode;
   struct link_map **preloads;
   unsigned int npreloads;
   const char *preloadlist;
@@ -268,41 +276,8 @@ dl_main (const ElfW(Phdr) *phdr,
   char *file;
   int has_interp = 0;
 
-  /* Test whether we want to see the content of the auxiliary array passed
-     up from the kernel.  */
-  if (getenv ("LD_SHOW_AUXV") != NULL)
-    _dl_show_auxv ();
-
-  mode = getenv ("LD_TRACE_LOADED_OBJECTS") != NULL ? trace : normal;
-  _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
-
-  /* LAZY is determined by the environment variable LD_WARN and
-     LD_BIND_NOW if we trace the binary.  */
-  if (mode == trace)
-    lazy = (_dl_verbose
-	    ? (*(getenv ("LD_BIND_NOW") ?: "") == '\0' ? 1 : 0) : -1);
-  else
-    lazy = !__libc_enable_secure && *(getenv ("LD_BIND_NOW") ?: "") == '\0';
-
-  /* See whether we want to use profiling.  */
-  _dl_profile = getenv ("LD_PROFILE");
-  if (_dl_profile != NULL)
-    if (_dl_profile[0] == '\0')
-      /* An empty string is of not much help.  Disable profiling.  */
-      _dl_profile = NULL;
-    else
-      {
-	/* OK, we have the name of a shared object we want to
-	   profile.  It's up to the user to provide a good name, it
-	   must match the file name or soname of one of the loaded
-	   objects.  Now let's see where we are supposed to place the
-	   result.  */
-	_dl_profile_output = getenv ("LD_PROFILE_OUTPUT");
-
-	if (_dl_profile_output == NULL || _dl_profile_output[0] == '\0')
-	  /* This is the default place.  */
-	  _dl_profile_output = "/var/tmp";
-      }
+  /* Process the environment variable which control the behaviour.  */
+  process_envvars (&mode, &lazy);
 
   /* Set up a flag which tells we are just starting.  */
   _dl_starting_up = 1;
@@ -930,3 +905,95 @@ print_missing_version (int errcode __attribute__ ((unused)),
   _dl_sysdep_error (_dl_argv[0] ?: "<program name unknown>", ": ",
 		    objname, ": ", errstring, "\n", NULL);
 }
+
+/* Process all environments variables the dynamic linker must recognize.
+   Since all of them start with `LD_' we are a bit smarter while finding
+   all the entries.  */
+static void
+process_envvars (enum mode *modep, int *lazyp)
+{
+  char **runp = NULL;
+  char *envline;
+  enum mode mode = normal;
+  int bind_now = 0;
+
+  /* This is the default place for profiling data file.  */
+  _dl_profile_output = "/var/tmp";
+
+  while ((envline = _dl_next_ld_env_entry (&runp)) != NULL)
+    {
+      int result;
+
+      /* Do we bind early?  */
+      result = strncmp (&envline[3], "BIND_NOW=", 9);
+      if (result == 0)
+	{
+	  bind_now = 1;
+	  continue;
+	}
+      if (result < 0)
+	continue;
+
+      /* Which shared object shall be profiled.  */
+      result = strncmp (&envline[3], "PROFILE=", 8);
+      if (result == 0)
+	{
+	  _dl_profile = &envline[11];
+	  if (*_dl_profile == '\0')
+	    _dl_profile = NULL;
+	  continue;
+	}
+      if (result < 0)
+	continue;
+
+      /* Where to place the profiling data file.  */
+      result = strncmp (&envline[3], "PROFILE_OUTPUT=", 15);
+      if (result == 0)
+	{
+	  _dl_profile_output = &envline[18];
+	  if (*_dl_profile_output == '\0')
+	    _dl_profile_output = "/var/tmp";
+	  continue;
+	}
+      if (result < 0)
+	continue;
+
+      /* Test whether we want to see the content of the auxiliary
+	 array passed up from the kernel.  */
+      result = strncmp (&envline[3], "SHOW_AUXV=", 10);
+      if (result == 0)
+	{
+	  _dl_show_auxv ();
+	  continue;
+	}
+      if (result < 0)
+	continue;
+
+      /* The mode of the dynamic linker can be set.  */
+      result = strncmp (&envline[3], "TRACE_LOADED_OBJECTS=", 21);
+      if (result == 0)
+	{
+	  mode = trace;
+	  continue;
+	}
+      if (result < 0)
+	continue;
+
+      /* Warning level, verbose or not.  */
+      result = strncmp (&envline[3], "WARN=", 5);
+      if (result == 0)
+	{
+	  _dl_verbose = envline[8] != '\0';
+	  continue;
+	}
+    }
+
+  /* LAZY is determined by the environment variable LD_WARN and
+     LD_BIND_NOW if we trace the binary.  */
+  if (mode == trace)
+    *lazyp = _dl_verbose ? !bind_now : -1;
+  else
+    *lazyp = !__libc_enable_secure && !bind_now;
+
+  *modep = mode;
+}