about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-06-20 15:59:03 +0000
committerJakub Jelinek <jakub@redhat.com>2005-06-20 15:59:03 +0000
commit27424b29289a49958e62450203f33a57dc1465e2 (patch)
tree7045409bd7d383127ecac0f78325a2a035b3f754 /elf
parent841d8c3466e6472c9cd16ee5bff701ba0380998a (diff)
downloadglibc-27424b29289a49958e62450203f33a57dc1465e2.tar.gz
glibc-27424b29289a49958e62450203f33a57dc1465e2.tar.xz
glibc-27424b29289a49958e62450203f33a57dc1465e2.zip
Updated to fedora-glibc-20050620T1530
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-deps.c31
-rw-r--r--elf/dl-error.c30
-rw-r--r--elf/dl-libc.c11
-rw-r--r--elf/dl-open.c15
-rw-r--r--elf/elf.h12
-rw-r--r--elf/rtld.c73
-rw-r--r--elf/tls-macros.h51
7 files changed, 159 insertions, 64 deletions
diff --git a/elf/dl-deps.c b/elf/dl-deps.c
index 50d7a0e71c..a73e21db7b 100644
--- a/elf/dl-deps.c
+++ b/elf/dl-deps.c
@@ -235,16 +235,22 @@ _dl_map_object_deps (struct link_map *map,
 	      {
 		/* Map in the needed object.  */
 		struct link_map *dep;
-		int err;
 
 		/* Recognize DSTs.  */
 		name = expand_dst (l, strtab + d->d_un.d_val, 0);
 		/* Store the tag in the argument structure.  */
 		args.name = name;
 
-		err = _dl_catch_error (&objname, &errstring, openaux, &args);
+		bool malloced;
+		int err = _dl_catch_error (&objname, &errstring, &malloced,
+					   openaux, &args);
 		if (__builtin_expect (errstring != NULL, 0))
 		  {
+		    char *new_errstring = strdupa (errstring);
+		    if (malloced)
+		      free ((char *) errstring);
+		    errstring = new_errstring;
+
 		    if (err)
 		      errno_reason = err;
 		    else
@@ -288,8 +294,6 @@ _dl_map_object_deps (struct link_map *map,
 
 		if (d->d_tag == DT_AUXILIARY)
 		  {
-		    int err;
-
 		    /* Say that we are about to load an auxiliary library.  */
 		    if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_LIBS,
 					  0))
@@ -301,13 +305,14 @@ _dl_map_object_deps (struct link_map *map,
 
 		    /* We must be prepared that the addressed shared
 		       object is not available.  */
-		    err = _dl_catch_error (&objname, &errstring, openaux,
-					   &args);
+		    bool malloced;
+		    (void) _dl_catch_error (&objname, &errstring, &malloced,
+					    openaux, &args);
 		    if (__builtin_expect (errstring != NULL, 0))
 		      {
 			/* We are not interested in the error message.  */
 			assert (errstring != NULL);
-			if (errstring != _dl_out_of_memory)
+			if (malloced)
 			  free ((char *) errstring);
 
 			/* Simply ignore this error and continue the work.  */
@@ -316,8 +321,6 @@ _dl_map_object_deps (struct link_map *map,
 		  }
 		else
 		  {
-		    int err;
-
 		    /* Say that we are about to load an auxiliary library.  */
 		    if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_LIBS,
 					  0))
@@ -328,10 +331,16 @@ _dl_map_object_deps (struct link_map *map,
 					? l->l_name : rtld_progname);
 
 		    /* For filter objects the dependency must be available.  */
-		    err = _dl_catch_error (&objname, &errstring, openaux,
-					   &args);
+		    bool malloced;
+		    int err = _dl_catch_error (&objname, &errstring, &malloced,
+					       openaux, &args);
 		    if (__builtin_expect (errstring != NULL, 0))
 		      {
+			char *new_errstring = strdupa (errstring);
+			if (malloced)
+			  free ((char *) errstring);
+			errstring = new_errstring;
+
 			if (err)
 			  errno_reason = err;
 			else
diff --git a/elf/dl-error.c b/elf/dl-error.c
index 993b7c29ab..a63d801411 100644
--- a/elf/dl-error.c
+++ b/elf/dl-error.c
@@ -19,6 +19,7 @@
 
 #include <libintl.h>
 #include <setjmp.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -30,6 +31,8 @@ struct catch
   {
     const char *objname;	/* Object/File name.  */
     const char *errstring;	/* Error detail filled in here.  */
+    bool malloced;		/* Nonzero if the string is malloced
+				   by the libc malloc.  */
     jmp_buf env;		/* longjmp here on error.  */
   };
 
@@ -44,8 +47,7 @@ struct catch
 /* This message we return as a last resort.  We define the string in a
    variable since we have to avoid freeing it and so have to enable
    a pointer comparison.  See below and in dlfcn/dlerror.c.  */
-const char _dl_out_of_memory[] = "out of memory";
-rtld_hidden_data_def (_dl_out_of_memory)
+static const char _dl_out_of_memory[] = "out of memory";
 
 
 /* This points to a function which is called when an continuable error is
@@ -87,15 +89,27 @@ _dl_signal_error (int errcode, const char *objname, const char *occation,
 
       lcatch->errstring = (char *) malloc (len_objname + len_errstring);
       if (lcatch->errstring != NULL)
-	/* Make a copy of the object file name and the error string.  */
-	lcatch->objname = memcpy (__mempcpy ((char *) lcatch->errstring,
-					     errstring, len_errstring),
-				  objname, len_objname);
+	{
+	  /* Make a copy of the object file name and the error string.  */
+	  lcatch->objname = memcpy (__mempcpy ((char *) lcatch->errstring,
+					       errstring, len_errstring),
+				    objname, len_objname);
+
+	  /* If the main executable is relocated it means the libc's malloc
+	     is used.  */
+#ifdef SHARED
+	  lcatch->malloced = (GL(dl_ns)[LM_ID_BASE]._ns_loaded->l_relocated
+			      != 0);
+#else
+	  lcatch->malloced = true;
+#endif
+	}
       else
 	{
 	  /* This is better than nothing.  */
 	  lcatch->objname = "";
 	  lcatch->errstring = _dl_out_of_memory;
+	  lcatch->malloced = false;
 	}
       longjmp (lcatch->env, errcode ?: -1);
     }
@@ -140,7 +154,7 @@ _dl_signal_cerror (int errcode, const char *objname, const char *occation,
 int
 internal_function
 _dl_catch_error (const char **objname, const char **errstring,
-		 void (*operate) (void *), void *args)
+		 bool *mallocedp, void (*operate) (void *), void *args)
 {
   int errcode;
   struct catch *volatile old;
@@ -162,6 +176,7 @@ _dl_catch_error (const char **objname, const char **errstring,
       *catchp = old;
       *objname = NULL;
       *errstring = NULL;
+      *mallocedp = false;
       return 0;
     }
 
@@ -169,6 +184,7 @@ _dl_catch_error (const char **objname, const char **errstring,
   *catchp = old;
   *objname = c.objname;
   *errstring = c.errstring;
+  *mallocedp = c.malloced;
   return errcode == -1 ? 0 : errcode;
 }
 
diff --git a/elf/dl-libc.c b/elf/dl-libc.c
index 5e76069139..1b995eda92 100644
--- a/elf/dl-libc.c
+++ b/elf/dl-libc.c
@@ -1,5 +1,5 @@
 /* Handle loading and unloading shared objects for internal libc purposes.
-   Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1999,2000,2001,2002,2004,2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Zack Weinberg <zack@rabi.columbia.edu>, 1999.
 
@@ -42,12 +42,13 @@ dlerror_run (void (*operate) (void *), void *args)
 {
   const char *objname;
   const char *last_errstring = NULL;
-  int result;
+  bool malloced;
 
-  (void) GLRO(dl_catch_error) (&objname, &last_errstring, operate, args);
+  (void) GLRO(dl_catch_error) (&objname, &last_errstring, &malloced,
+			       operate, args);
 
-  result = last_errstring != NULL;
-  if (result && last_errstring != _dl_out_of_memory)
+  int result = last_errstring != NULL;
+  if (result && malloced)
     free ((char *) last_errstring);
 
   return result;
diff --git a/elf/dl-open.c b/elf/dl-open.c
index a65690e5a3..984f4a4ec6 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -504,11 +504,6 @@ void *
 _dl_open (const char *file, int mode, const void *caller_dlopen, Lmid_t nsid,
 	  int argc, char *argv[], char *env[])
 {
-  struct dl_open_args args;
-  const char *objname;
-  const char *errstring;
-  int errcode;
-
   if ((mode & RTLD_BINDING_MASK) == 0)
     /* One of the flags must be set.  */
     _dl_signal_error (EINVAL, file, NULL, N_("invalid mode for dlopen()"));
@@ -543,6 +538,7 @@ no more namespaces available for dlmopen()"));
     _dl_signal_error (EINVAL, file, NULL,
 		      N_("invalid target namespace in dlmopen()"));
 
+  struct dl_open_args args;
   args.file = file;
   args.mode = mode;
   args.caller_dlopen = caller_dlopen;
@@ -552,7 +548,12 @@ no more namespaces available for dlmopen()"));
   args.argc = argc;
   args.argv = argv;
   args.env = env;
-  errcode = _dl_catch_error (&objname, &errstring, dl_open_worker, &args);
+
+  const char *objname;
+  const char *errstring;
+  bool malloced;
+  int errcode = _dl_catch_error (&objname, &errstring, &malloced,
+				 dl_open_worker, &args);
 
 #ifndef MAP_COPY
   /* We must munmap() the cache file.  */
@@ -603,7 +604,7 @@ no more namespaces available for dlmopen()"));
 	  memcpy (local_errstring, errstring, len_errstring);
 	}
 
-      if (errstring != _dl_out_of_memory)
+      if (malloced)
 	free ((char *) errstring);
 
       assert (_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT);
diff --git a/elf/elf.h b/elf/elf.h
index e246519fab..a09d279dbf 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -1866,6 +1866,9 @@ typedef Elf32_Addr Elf32_Conflict;
 #define LITUSE_ALPHA_TLS_GD	4
 #define LITUSE_ALPHA_TLS_LDM	5
 
+/* Legal values for d_tag of Elf64_Dyn.  */
+#define DT_ALPHA_PLTRO		0x70000000
+#define DT_ALPHA_NUM		1
 
 /* PowerPC specific declarations */
 
@@ -1976,10 +1979,19 @@ typedef Elf32_Addr Elf32_Conflict;
 #define R_PPC_DIAB_RELSDA_HI	184	/* like EMB_RELSDA, but high 16 bit */
 #define R_PPC_DIAB_RELSDA_HA	185	/* like EMB_RELSDA, adjusted high 16 */
 
+/* GNU relocs used in PIC code sequences.  */
+#define R_PPC_REL16		249	/* word32   (sym-.) */
+#define R_PPC_REL16_LO		250	/* half16   (sym-.)@l */
+#define R_PPC_REL16_HI		251	/* half16   (sym-.)@h */
+#define R_PPC_REL16_HA		252	/* half16   (sym-.)@ha */
+
 /* This is a phony reloc to handle any old fashioned TOC16 references
    that may still be in object files.  */
 #define R_PPC_TOC16		255
 
+/* PowerPC specific values for the Dyn d_tag field.  */
+#define DT_PPC_GOT		(DT_LOPROC + 0)
+#define DT_PPC_NUM		1
 
 /* PowerPC64 relocations defined by the ABIs */
 #define R_PPC64_NONE		R_PPC_NONE
diff --git a/elf/rtld.c b/elf/rtld.c
index b7f16f7b37..a3dbb867f3 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -61,6 +61,9 @@ static void print_missing_version (int errcode, const char *objname,
 /* Print the various times we collected.  */
 static void print_statistics (hp_timing_t *total_timep);
 
+/* Add audit objects.  */
+static void process_dl_audit (char *str);
+
 /* This is a list of all the modes the dynamic loader can be in.  */
 enum mode { normal, list, verify, trace };
 
@@ -771,6 +774,7 @@ do_preload (char *fname, struct link_map *main_map, const char *where)
   const char *objname;
   const char *err_str = NULL;
   struct map_args args;
+  bool malloced;
 
   args.str = fname;
   args.loader = main_map;
@@ -779,7 +783,7 @@ do_preload (char *fname, struct link_map *main_map, const char *where)
 
   unsigned int old_nloaded = GL(dl_ns)[LM_ID_BASE]._ns_nloaded;
 
-  (void) _dl_catch_error (&objname, &err_str, map_doit, &args);
+  (void) _dl_catch_error (&objname, &err_str, &malloced, map_doit, &args);
   if (__builtin_expect (err_str != NULL, 0))
     {
       _dl_error_printf ("\
@@ -927,6 +931,14 @@ dl_main (const ElfW(Phdr) *phdr,
 	    _dl_argc -= 2;
 	    INTUSE(_dl_argv) += 2;
 	  }
+	else if (! strcmp (INTUSE(_dl_argv)[1], "--audit") && _dl_argc > 2)
+	  {
+	    process_dl_audit (INTUSE(_dl_argv)[2]);
+
+	    _dl_skip_args += 2;
+	    _dl_argc -= 2;
+	    INTUSE(_dl_argv) += 2;
+	  }
 	else
 	  break;
 
@@ -983,12 +995,14 @@ of this helper program; chances are you did not intend to run this program.\n\
 	  const char *objname;
 	  const char *err_str = NULL;
 	  struct map_args args;
+	  bool malloced;
 
 	  args.str = rtld_progname;
 	  args.loader = NULL;
 	  args.is_preloaded = 0;
 	  args.mode = __RTLD_OPENEXEC;
-	  (void) _dl_catch_error (&objname, &err_str, map_doit, &args);
+	  (void) _dl_catch_error (&objname, &err_str, &malloced, map_doit,
+				  &args);
 	  if (__builtin_expect (err_str != NULL, 0))
 	    /* We don't free the returned string, the programs stops
 	       anyway.  */
@@ -1451,14 +1465,17 @@ ld.so does not support TLS, but program uses it!\n");
 
 	  const char *objname;
 	  const char *err_str = NULL;
-	  (void) _dl_catch_error (&objname, &err_str, dlmopen_doit, &dlmargs);
+	  bool malloced;
+	  (void) _dl_catch_error (&objname, &err_str, &malloced, dlmopen_doit,
+				  &dlmargs);
 	  if (__builtin_expect (err_str != NULL, 0))
 	    {
 	    not_loaded:
 	      _dl_error_printf ("\
 ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 				al->name, err_str);
-	      free ((char *) err_str);
+	      if (malloced)
+		free ((char *) err_str);
 	    }
 	  else
 	    {
@@ -1467,7 +1484,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 	      largs.map = dlmargs.map;
 
 	      /* Check whether the interface version matches.  */
-	      (void) _dl_catch_error (&objname, &err_str, lookup_doit, &largs);
+	      (void) _dl_catch_error (&objname, &err_str, &malloced,
+				      lookup_doit, &largs);
 
 	      unsigned int (*laversion) (unsigned int);
 	      unsigned int lav;
@@ -1508,8 +1526,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 		  do
 		    {
 		      largs.name = cp;
-		      (void) _dl_catch_error (&objname, &err_str, lookup_doit,
-					      &largs);
+		      (void) _dl_catch_error (&objname, &err_str, &malloced,
+					      lookup_doit, &largs);
 
 		      /* Store the pointer.  */
 		      if (err_str == NULL && largs.result != NULL)
@@ -1593,6 +1611,23 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
 	}
     }
 
+  /* Set up debugging before the debugger is notified for the first time.  */
+#ifdef ELF_MACHINE_DEBUG_SETUP
+  /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */
+  ELF_MACHINE_DEBUG_SETUP (main_map, r);
+  ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r);
+#else
+  if (main_map->l_info[DT_DEBUG] != NULL)
+    /* There is a DT_DEBUG entry in the dynamic section.  Fill it in
+       with the run-time address of the r_debug structure  */
+    main_map->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
+
+  /* Fill in the pointer in the dynamic linker's own dynamic section, in
+     case you run gdb on the dynamic linker directly.  */
+  if (GL(dl_rtld_map).l_info[DT_DEBUG] != NULL)
+    GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
+#endif
+
   /* We start adding objects.  */
   r->r_state = RT_ADD;
   _dl_debug_state ();
@@ -2162,30 +2197,6 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
     }
 
 
-  {
-    struct link_map *l = main_map;
-
-#ifdef ELF_MACHINE_DEBUG_SETUP
-
-    /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */
-
-    ELF_MACHINE_DEBUG_SETUP (l, r);
-    ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r);
-
-#else
-
-    if (l->l_info[DT_DEBUG] != NULL)
-      /* There is a DT_DEBUG entry in the dynamic section.  Fill it in
-	 with the run-time address of the r_debug structure  */
-      l->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
-
-    /* Fill in the pointer in the dynamic linker's own dynamic section, in
-       case you run gdb on the dynamic linker directly.  */
-    if (GL(dl_rtld_map).l_info[DT_DEBUG] != NULL)
-      GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
-#endif
-  }
-
   /* Now set up the variable which helps the assembler startup code.  */
   GL(dl_ns)[LM_ID_BASE]._ns_main_searchlist = &main_map->l_searchlist;
   GL(dl_ns)[LM_ID_BASE]._ns_global_scope[0] = &main_map->l_searchlist;
diff --git a/elf/tls-macros.h b/elf/tls-macros.h
index 0ae9e65dc0..37cbe7514f 100644
--- a/elf/tls-macros.h
+++ b/elf/tls-macros.h
@@ -703,6 +703,8 @@ register void *__gp __asm__("$29");
 
 #elif defined __powerpc__ && !defined __powerpc64__
 
+#include "config.h"
+
 # define __TLS_CALL_CLOBBERS						\
 	"0", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",	\
 	"lr", "ctr", "cr0", "cr1", "cr5", "cr6", "cr7"
@@ -715,7 +717,20 @@ register void *__gp __asm__("$29");
      __result; })
 
 /* PowerPC32 Initial Exec TLS access.  */
-# define TLS_IE(x)					\
+# ifdef HAVE_ASM_PPC_REL16
+#  define TLS_IE(x)					\
+  ({ int *__result;					\
+     asm ("bcl 20,31,1f\n1:\t"				\
+	  "mflr %0\n\t"					\
+	  "addis %0,%0,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t"	\
+	  "addi %0,%0,_GLOBAL_OFFSET_TABLE_-1b@l\n\t"	\
+	  "lwz %0," #x "@got@tprel(%0)\n\t"		\
+	  "add %0,%0," #x "@tls"			\
+	  : "=b" (__result) :				\
+	  : "lr");					\
+     __result; })
+# else
+#  define TLS_IE(x)					\
   ({ int *__result;					\
      asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t"	\
 	  "mflr %0\n\t"					\
@@ -724,9 +739,24 @@ register void *__gp __asm__("$29");
 	  : "=b" (__result) :				\
 	  : "lr");					\
      __result; })
+# endif
 
 /* PowerPC32 Local Dynamic TLS access.  */
-# define TLS_LD(x)					\
+# ifdef HAVE_ASM_PPC_REL16
+#  define TLS_LD(x)					\
+  ({ int *__result;					\
+     asm ("bcl 20,31,1f\n1:\t"				\
+	  "mflr 3\n\t"					\
+	  "addis 3,3,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t"	\
+	  "addi 3,3,_GLOBAL_OFFSET_TABLE_-1b@l\n\t"	\
+	  "addi 3,3," #x "@got@tlsld\n\t"		\
+	  "bl __tls_get_addr@plt\n\t"			\
+	  "addi %0,3," #x "@dtprel"			\
+	  : "=r" (__result) :				\
+	  : __TLS_CALL_CLOBBERS);			\
+     __result; })
+# else
+#  define TLS_LD(x)					\
   ({ int *__result;					\
      asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t"	\
 	  "mflr 3\n\t"					\
@@ -736,9 +766,23 @@ register void *__gp __asm__("$29");
 	  : "=r" (__result) :				\
 	  : __TLS_CALL_CLOBBERS);			\
      __result; })
+# endif
 
 /* PowerPC32 General Dynamic TLS access.  */
-# define TLS_GD(x)					\
+# ifdef HAVE_ASM_PPC_REL16
+#  define TLS_GD(x)					\
+  ({ register int *__result __asm__ ("r3");		\
+     asm ("bcl 20,31,1f\n1:\t"				\
+	  "mflr 3\n\t"					\
+	  "addis 3,3,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t"	\
+	  "addi 3,3,_GLOBAL_OFFSET_TABLE_-1b@l\n\t"	\
+	  "addi 3,3," #x "@got@tlsgd\n\t"		\
+	  "bl __tls_get_addr@plt"			\
+	  : :						\
+	  : __TLS_CALL_CLOBBERS);			\
+     __result; })
+# else
+#  define TLS_GD(x)					\
   ({ register int *__result __asm__ ("r3");		\
      asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t"	\
 	  "mflr 3\n\t"					\
@@ -747,6 +791,7 @@ register void *__gp __asm__("$29");
 	  : :						\
 	  : __TLS_CALL_CLOBBERS);			\
      __result; })
+# endif
 
 #elif defined __powerpc__ && defined __powerpc64__