summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-01-31 03:41:25 +0000
committerUlrich Drepper <drepper@redhat.com>2002-01-31 03:41:25 +0000
commitd6b5d570a3255d8dc80e07c3674594574cd98fe7 (patch)
tree36e05b0d065614559820d2a4f43bb1076ea5cfa1 /elf
parent1b4575aefaaa43adfed4658f7d66de587f12120e (diff)
downloadglibc-d6b5d570a3255d8dc80e07c3674594574cd98fe7.tar.gz
glibc-d6b5d570a3255d8dc80e07c3674594574cd98fe7.tar.xz
glibc-d6b5d570a3255d8dc80e07c3674594574cd98fe7.zip
Update.
2002-01-30  Ulrich Drepper  <drepper@redhat.com>

	* Versions.def [ld]: Add GLIBC_2.3.
	* elf/dl-addr.c: Move global variables for SHARED code in struct
	_rtld_global.  Export this struct, remove all exports for the
	signal variables.
	* elf/dl-close.c: Likewise.
	* elf/dl-conflict.c: Likewise.
	* elf/dl-debug.c: Likewise.
	* elf/dl-deps.c: Likewise.
	* elf/dl-dst.h: Likewise.
	* elf/dl-error.c: Likewise.
	* elf/dl-fini.c: Likewise.
	* elf/dl-init.c: Likewise.
	* elf/dl-iteratephdr.c: Likewise.
	* elf/dl-libc.c: Likewise.
	* elf/dl-load.c: Likewise.
	* elf/dl-lookup.c: Likewise.
	* elf/dl-minimal.c: Likewise.
	* elf/dl-object.c: Likewise.
	* elf/dl-open.c: Likewise.
	* elf/dl-profile.c: Likewise.
	* elf/dl-profstub.c: Likewise.
	* elf/dl-reloc.c: Likewise.
	* elf/dl-runtime.c: Likewise.
	* elf/dl-support.c: Likewise.
	* elf/dl-sym.c: Likewise.
	* elf/dl-version.c: Likewise.
	* elf/do-lookup.h: Likewise.
	* elf/do-rel.h: Likewise.
	* elf/dynamic-link.h: Likewise.
	* elf/rtld.c: Likewise.
	* sysdeps/generic/dl-cache.c: Likewise.
	* sysdeps/generic/dl-sysdep.c: Likewise.
	* sysdeps/generic/ldsodefs.h: Likewise.
	* sysdeps/generic/libc-start.c: Likewise.
	* sysdeps/i386/dl-machine.h: Likewise.
	* sysdeps/ia64/dl-fptr.c: Likewise.
	* sysdeps/ia64/dl-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/dl-librecon.h: Likewise.
	* sysdeps/unix/sysv/linux/dl-origin.c: Likewise.
	* sysdeps/unix/sysv/linux/dl-osinfo.h: Likewise.
	* sysdeps/unix/sysv/linux/getclktck.c: Likewise.
	* sysdeps/unix/sysv/linux/getpagesize.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/dl-librecon.h: Likewise.
	* sysdeps/unix/sysv/linux/ia64/dl-static.c: Likewise.
	* sysdeps/unix/sysv/linux/ia64/getpagesize.c: Likewise.

	* malloc/thread-m.h: Spinlock definitions for x86/x86_64.
Diffstat (limited to 'elf')
-rw-r--r--elf/Versions27
-rw-r--r--elf/dl-addr.c4
-rw-r--r--elf/dl-close.c32
-rw-r--r--elf/dl-conflict.c27
-rw-r--r--elf/dl-debug.c4
-rw-r--r--elf/dl-deps.c20
-rw-r--r--elf/dl-dst.h4
-rw-r--r--elf/dl-error.c2
-rw-r--r--elf/dl-fini.c20
-rw-r--r--elf/dl-init.c15
-rw-r--r--elf/dl-iteratephdr.c4
-rw-r--r--elf/dl-libc.c8
-rw-r--r--elf/dl-load.c98
-rw-r--r--elf/dl-lookup.c33
-rw-r--r--elf/dl-minimal.c9
-rw-r--r--elf/dl-object.c12
-rw-r--r--elf/dl-open.c52
-rw-r--r--elf/dl-profile.c23
-rw-r--r--elf/dl-profstub.c6
-rw-r--r--elf/dl-reloc.c18
-rw-r--r--elf/dl-runtime.c6
-rw-r--r--elf/dl-support.c29
-rw-r--r--elf/dl-sym.c26
-rw-r--r--elf/dl-version.c17
-rw-r--r--elf/do-lookup.h4
-rw-r--r--elf/do-rel.h8
-rw-r--r--elf/dynamic-link.h7
-rw-r--r--elf/rtld.c320
28 files changed, 397 insertions, 438 deletions
diff --git a/elf/Versions b/elf/Versions
index 0c3480450f..5c8da22843 100644
--- a/elf/Versions
+++ b/elf/Versions
@@ -35,12 +35,12 @@ ld {
 
     # Those are in the dynamic linker, but used by libc.so.
     __libc_enable_secure; _dl_catch_error; _dl_check_all_versions;
-    _dl_debug_initialize; _dl_debug_state; _dl_default_scope;
-    _dl_global_scope_end; _dl_lookup_symbol;
+    _dl_debug_initialize; _dl_debug_state;
+    _dl_lookup_symbol;
     _dl_map_object; _dl_map_object_deps; _dl_object_relocation_scope;
     _dl_relocate_object; _dl_signal_error; _dl_starting_up;
     _dl_sysdep_start; _r_debug;
-    _dl_global_scope; _dl_lookup_symbol_skip;
+    _dl_lookup_symbol_skip;
     _dl_lookup_versioned_symbol; _dl_lookup_versioned_symbol_skip;
 
     # Function from libc.so which must be shared with libc.
@@ -48,31 +48,28 @@ ld {
   }
   GLIBC_2.1 {
     # global variables
-    _dl_profile; _dl_profile_map; _dl_profile_output; _dl_start_profile;
-    _dl_loaded; _dl_main_searchlist; _dl_fpu_control; _dl_initial_searchlist;
-    _dl_global_scope_alloc; __libc_stack_end;
+    _dl_fpu_control; __libc_stack_end;
 
     # functions used in other libraries
-    _dl_mcount; _dl_unload_cache;
+    _dl_start_profile; _dl_mcount; _dl_unload_cache;
   }
   GLIBC_2.1.1 {
     # global variables
-    _dl_lazy; _dl_origin_path; _dl_platformlen;
+    _dl_lazy;
 
     # functions used in other libraries
     _dl_dst_count; _dl_dst_substitute;
   }
   GLIBC_2.2 {
-    _dl_init; _dl_load_lock; _dl_argv; _dl_nloaded; _dl_check_map_versions;
-
-    # this is defined in ld.so and overridden by libc
-    _dl_init_first;
+    _dl_init; _dl_load_lock; _dl_argv; _dl_check_map_versions;
 
     # variables used elsewhere
-    _dl_out_of_memory; _dl_all_dirs; _dl_init_all_dirs;
-    _dl_clktck; _dl_pagesize;
+    _dl_out_of_memory;
   }
   GLIBC_2.2.3 {
-    _dl_debug_mask; _dl_debug_printf;
+    _dl_debug_printf;
+  }
+  GLIBC_2.3 {
+    _rtld_global;
   }
 }
diff --git a/elf/dl-addr.c b/elf/dl-addr.c
index ebb62858e6..59f1a430b5 100644
--- a/elf/dl-addr.c
+++ b/elf/dl-addr.c
@@ -1,5 +1,5 @@
 /* Locate the shared object symbol nearest a given address.
-   Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1996-2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -34,7 +34,7 @@ _dl_addr (const void *address, Dl_info *info)
 
   /* Find the highest-addressed object that ADDRESS is not below.  */
   match = NULL;
-  for (l = _dl_loaded; l; l = l->l_next)
+  for (l = GL(dl_loaded); l; l = l->l_next)
     if (addr >= l->l_map_start && addr < l->l_map_end)
       {
 	/* We know ADDRESS lies within L if in any shared object.
diff --git a/elf/dl-close.c b/elf/dl-close.c
index de4b91ac03..cece96b7fb 100644
--- a/elf/dl-close.c
+++ b/elf/dl-close.c
@@ -1,5 +1,5 @@
 /* Close a shared object opened by `_dl_open'.
-   Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -63,7 +63,7 @@ _dl_close (void *_map)
   if (map->l_opencount > 1 || map->l_type != lt_loaded)
     {
       /* There are still references to this object.  Do nothing more.  */
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_FILES, 0))
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_FILES, 0))
 	_dl_debug_printf ("\nclosing file=%s; opencount == %u\n",
 			  map->l_name, map->l_opencount);
 
@@ -125,7 +125,7 @@ _dl_close (void *_map)
 	  && imap->l_init_called)
 	{
 	  /* When debugging print a message first.  */
-	  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_IMPCALLS, 0))
+	  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_IMPCALLS, 0))
 	    _dl_debug_printf ("\ncalling fini: %s\n\n", imap->l_name);
 
 	  /* Call its termination function.  */
@@ -192,18 +192,18 @@ _dl_close (void *_map)
 	  if (__builtin_expect (imap->l_global, 0))
 	    {
 	      /* This object is in the global scope list.  Remove it.  */
-	      unsigned int cnt = _dl_main_searchlist->r_nlist;
+	      unsigned int cnt = GL(dl_main_searchlist)->r_nlist;
 
 	      do
 		--cnt;
-	      while (_dl_main_searchlist->r_list[cnt] != imap);
+	      while (GL(dl_main_searchlist)->r_list[cnt] != imap);
 
 	      /* The object was already correctly registered.  */
-	      while (++cnt < _dl_main_searchlist->r_nlist)
-		_dl_main_searchlist->r_list[cnt - 1]
-		  = _dl_main_searchlist->r_list[cnt];
+	      while (++cnt < GL(dl_main_searchlist)->r_nlist)
+		GL(dl_main_searchlist)->r_list[cnt - 1]
+		  = GL(dl_main_searchlist)->r_list[cnt];
 
-	      --_dl_main_searchlist->r_nlist;
+	      --GL(dl_main_searchlist)->r_nlist;
 	    }
 
 	  /* We can unmap all the maps at once.  We determined the
@@ -221,9 +221,9 @@ _dl_close (void *_map)
 	  if (imap->l_prev != NULL)
 	    imap->l_prev->l_next = imap->l_next;
 	  else
-	    _dl_loaded = imap->l_next;
+	    GL(dl_loaded) = imap->l_next;
 #endif
-	  --_dl_nloaded;
+	  --GL(dl_nloaded);
 	  if (imap->l_next)
 	    imap->l_next->l_prev = imap->l_prev;
 
@@ -305,17 +305,17 @@ _dl_close (void *_map)
 static void
 free_mem (void)
 {
-  if (__builtin_expect (_dl_global_scope_alloc, 0) != 0
-      && _dl_main_searchlist->r_nlist == _dl_initial_searchlist.r_nlist)
+  if (__builtin_expect (GL(dl_global_scope_alloc), 0) != 0
+      && GL(dl_main_searchlist)->r_nlist == GL(dl_initial_searchlist).r_nlist)
     {
       /* All object dynamically loaded by the program are unloaded.  Free
 	 the memory allocated for the global scope variable.  */
-      struct link_map **old = _dl_main_searchlist->r_list;
+      struct link_map **old = GL(dl_main_searchlist)->r_list;
 
       /* Put the old map in.  */
-      _dl_main_searchlist->r_list = _dl_initial_searchlist.r_list;
+      GL(dl_main_searchlist)->r_list = GL(dl_initial_searchlist).r_list;
       /* Signal that the original map is used.  */
-      _dl_global_scope_alloc = 0;
+      GL(dl_global_scope_alloc) = 0;
 
       /* Now free the old map.  */
       free (old);
diff --git a/elf/dl-conflict.c b/elf/dl-conflict.c
index 0f863ac893..3e88e54021 100644
--- a/elf/dl-conflict.c
+++ b/elf/dl-conflict.c
@@ -1,5 +1,5 @@
 /* Resolve conflicts against already prelinked libraries.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@redhat.com>, 2001.
 
@@ -28,13 +28,12 @@
 #include <sys/types.h>
 #include "dynamic-link.h"
 
-extern unsigned long int _dl_num_cache_relocations;	/* in dl-lookup.c */
 
 void
 _dl_resolve_conflicts (struct link_map *l, ElfW(Rela) *conflict,
 		       ElfW(Rela) *conflictend)
 {
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_RELOC, 0))
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_RELOC, 0))
     _dl_printf ("\nconflict processing: %s\n",
 		l->l_name[0] ? l->l_name : _dl_argv[0]);
 
@@ -45,25 +44,21 @@ _dl_resolve_conflicts (struct link_map *l, ElfW(Rela) *conflict,
     /* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code.  */
 #define RESOLVE_MAP(ref, version, flags) (*ref = NULL, 0)
 #define RESOLVE(ref, version, flags) (*ref = NULL, 0)
-#define RESOLVE_CONFLICT_FIND_MAP(map, r_offset)		\
-do								\
-  {								\
-    while ((resolve_conflict_map->l_map_end			\
-	    < (ElfW(Addr))(r_offset))				\
-	   || (resolve_conflict_map->l_map_start		\
-	       > (ElfW(Addr))(r_offset)))			\
-      resolve_conflict_map					\
-	= resolve_conflict_map->l_next;				\
-    (map) = resolve_conflict_map;				\
+#define RESOLVE_CONFLICT_FIND_MAP(map, r_offset) \
+  do {									      \
+    while ((resolve_conflict_map->l_map_end < (ElfW(Addr)) (r_offset))	      \
+	   || (resolve_conflict_map->l_map_start > (ElfW(Addr)) (r_offset)))  \
+      resolve_conflict_map = resolve_conflict_map->l_next;		      \
+									      \
+    (map) = resolve_conflict_map;					      \
   } while (0)
 
     struct link_map *resolve_conflict_map __attribute__ ((__unused__))
-      = _dl_loaded;
-    
+      = GL(dl_loaded);
 
 #include "dynamic-link.h"
 
-    _dl_num_cache_relocations += conflictend - conflict;
+    GL(dl_num_cache_relocations) += conflictend - conflict;
 
     for (; conflict < conflictend; ++conflict)
       elf_machine_rela (l, conflict, NULL, NULL, (void *) conflict->r_offset);
diff --git a/elf/dl-debug.c b/elf/dl-debug.c
index 5a51b53357..4e8197227e 100644
--- a/elf/dl-debug.c
+++ b/elf/dl-debug.c
@@ -1,5 +1,5 @@
 /* Communicate dynamic linker state to the debugger at runtime.
-   Copyright (C) 1996, 1998, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1998, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -39,7 +39,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase)
       /* Tell the debugger where to find the map of loaded objects.  */
       _r_debug.r_version = 1	/* R_DEBUG_VERSION XXX */;
       _r_debug.r_ldbase = ldbase;
-      _r_debug.r_map = _dl_loaded;
+      _r_debug.r_map = GL(dl_loaded);
       _r_debug.r_brk = (ElfW(Addr)) &_dl_debug_state;
     }
 
diff --git a/elf/dl-deps.c b/elf/dl-deps.c
index af39de1023..368ad2d557 100644
--- a/elf/dl-deps.c
+++ b/elf/dl-deps.c
@@ -1,5 +1,5 @@
 /* Load the dependencies of a mapped object.
-   Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -39,12 +39,6 @@
 #define FILTERTAG (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
 		   + DT_EXTRATAGIDX (DT_FILTER))
 
-/* This is zero at program start to signal that the global scope map is
-   allocated by rtld.  Later it keeps the size of the map.  It might be
-   reset if in _dl_close if the last global object is removed.  */
-size_t _dl_global_scope_alloc;
-
-extern size_t _dl_platformlen;
 
 /* When loading auxiliary objects we must ignore errors.  It's ok if
    an object is missing.  */
@@ -131,7 +125,7 @@ empty dynamics string token substitution"));				      \
 	    else							      \
 	      {								      \
 		/* This is for DT_AUXILIARY.  */			      \
-		if (__builtin_expect (_dl_debug_mask & DL_DEBUG_LIBS, 0))     \
+		if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS, 0))  \
 		  _dl_debug_printf ("cannot load auxiliary `%s' because of"   \
 				    "empty dynamic string token "	      \
 				    "substitution\n", __str);		      \
@@ -294,7 +288,8 @@ _dl_map_object_deps (struct link_map *map,
 		    int err;
 
 		    /* Say that we are about to load an auxiliary library.  */
-		    if (__builtin_expect (_dl_debug_mask & DL_DEBUG_LIBS, 0))
+		    if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS,
+					  0))
 		      _dl_debug_printf ("load auxiliary object=%s"
 					" requested by file=%s\n", name,
 					l->l_name[0]
@@ -320,7 +315,8 @@ _dl_map_object_deps (struct link_map *map,
 		    int err;
 
 		    /* Say that we are about to load an auxiliary library.  */
-		    if (__builtin_expect (_dl_debug_mask & DL_DEBUG_LIBS, 0))
+		    if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS,
+					  0))
 		      _dl_debug_printf ("load filtered object=%s"
 					" requested by file=%s\n", name,
 					l->l_name[0]
@@ -507,8 +503,8 @@ _dl_map_object_deps (struct link_map *map,
       runp->map->l_reserved = 0;
     }
 
-  if (__builtin_expect(_dl_debug_mask & DL_DEBUG_PRELINK, 0) != 0
-      && map == _dl_loaded)
+  if (__builtin_expect(GL(dl_debug_mask) & DL_DEBUG_PRELINK, 0) != 0
+      && map == GL(dl_loaded))
     {
       /* If we are to compute conflicts, we have to build local scope
 	 for each library, not just the ultimate loader.  */
diff --git a/elf/dl-dst.h b/elf/dl-dst.h
index 2ebd4d9636..af4a94a3b3 100644
--- a/elf/dl-dst.h
+++ b/elf/dl-dst.h
@@ -1,5 +1,5 @@
 /* Handling of dynamic sring tokens.
-   Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -57,7 +57,7 @@ extern size_t _dl_dst_count (const char *name, int is_path);
     else								      \
       origin_len = (l)->l_origin == (char *) -1 ? 0 : strlen ((l)->l_origin); \
 									      \
-    __len + cnt * (MAX (origin_len, _dl_platformlen) - 7); })
+    __len + cnt * (MAX (origin_len, GL(dl_platformlen)) - 7); })
 
 /* Find origin of the executable.  */
 extern const char *_dl_get_origin (void);
diff --git a/elf/dl-error.c b/elf/dl-error.c
index be9a84361c..922de5caeb 100644
--- a/elf/dl-error.c
+++ b/elf/dl-error.c
@@ -1,5 +1,5 @@
 /* Error handling for runtime dynamic linker.
-   Copyright (C) 1995,96,97,98,99,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
diff --git a/elf/dl-fini.c b/elf/dl-fini.c
index fc4f4b68a6..e8533a471c 100644
--- a/elf/dl-fini.c
+++ b/elf/dl-fini.c
@@ -1,5 +1,5 @@
 /* Call the termination functions of loaded shared objects.
-   Copyright (C) 1995,96,98,99,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,98,99,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -47,15 +47,15 @@ _dl_fini (void)
   struct link_map **maps;
 
   /* XXX Could it be (in static binaries) that there is no object loaded?  */
-  assert (_dl_nloaded > 0);
+  assert (GL(dl_nloaded) > 0);
 
   /* Now we can allocate an array to hold all the pointers and copy
      the pointers in.  */
-  maps = (struct link_map **) alloca (_dl_nloaded
+  maps = (struct link_map **) alloca (GL(dl_nloaded)
 				      * sizeof (struct link_map *));
-  for (l = _dl_loaded, i = 0; l != NULL; l = l->l_next)
+  for (l = GL(dl_loaded), i = 0; l != NULL; l = l->l_next)
     {
-      assert (i < _dl_nloaded);
+      assert (i < GL(dl_nloaded));
 
       maps[i++] = l;
 
@@ -63,10 +63,10 @@ _dl_fini (void)
 	 from underneath us.  */
       ++l->l_opencount;
     }
-  assert (i == _dl_nloaded);
+  assert (i == GL(dl_nloaded));
 
   /* Now we have to do the sorting.  */
-  for (l = _dl_loaded->l_next; l != NULL; l = l->l_next)
+  for (l = GL(dl_loaded)->l_next; l != NULL; l = l->l_next)
     {
       unsigned int j;
       unsigned int k;
@@ -77,7 +77,7 @@ _dl_fini (void)
 
       /* Find all object for which the current one is a dependency and
 	 move the found object (if necessary) in front.  */
-      for (k = j + 1; k < _dl_nloaded; ++k)
+      for (k = j + 1; k < GL(dl_nloaded); ++k)
 	{
 	  struct link_map **runp;
 
@@ -128,7 +128,7 @@ _dl_fini (void)
 
   /* `maps' now contains the objects in the right order.  Now call the
      destructors.  We have to process this array from the front.  */
-  for (i = 0; i < _dl_nloaded; ++i)
+  for (i = 0; i < GL(dl_nloaded); ++i)
     {
       l = maps[i];
 
@@ -146,7 +146,7 @@ _dl_fini (void)
 	    continue;
 
 	  /* When debugging print a message first.  */
-	  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_IMPCALLS, 0))
+	  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_IMPCALLS, 0))
 	    _dl_debug_printf ("\ncalling fini: %s\n\n",
 			      l->l_name[0] ? l->l_name : _dl_argv[0]);
 
diff --git a/elf/dl-init.c b/elf/dl-init.c
index 5448b03c33..700efc58e5 100644
--- a/elf/dl-init.c
+++ b/elf/dl-init.c
@@ -1,5 +1,5 @@
 /* Return the next shared object initializer function not yet run.
-   Copyright (C) 1995,1996,1998,1999,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1998-2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -27,9 +27,6 @@ typedef void (*init_t) (int, char **, char **);
 /* Flag, nonzero during startup phase.  */
 extern int _dl_starting_up;
 
-/* The object to be initialized first.  */
-extern struct link_map *_dl_initfirst;
-
 
 static void
 call_init (struct link_map *l, int argc, char **argv, char **env)
@@ -53,7 +50,7 @@ call_init (struct link_map *l, int argc, char **argv, char **env)
     return;
 
   /* Print a debug message if wanted.  */
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_IMPCALLS, 0))
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_IMPCALLS, 0))
     _dl_debug_printf ("\ncalling init: %s\n\n",
 		      l->l_name[0] ? l->l_name : _dl_argv[0]);
 
@@ -95,10 +92,10 @@ _dl_init (struct link_map *main_map, int argc, char **argv, char **env)
   struct r_debug *r;
   unsigned int i;
 
-  if (__builtin_expect (_dl_initfirst != NULL, 0))
+  if (__builtin_expect (GL(dl_initfirst) != NULL, 0))
     {
-      call_init (_dl_initfirst, argc, argv, env);
-      _dl_initfirst = NULL;
+      call_init (GL(dl_initfirst), argc, argv, env);
+      GL(dl_initfirst) = NULL;
     }
 
   /* Don't do anything if there is no preinit array.  */
@@ -108,7 +105,7 @@ _dl_init (struct link_map *main_map, int argc, char **argv, char **env)
       ElfW(Addr) *addrs;
       unsigned int cnt;
 
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_IMPCALLS, 0))
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_IMPCALLS, 0))
 	_dl_debug_printf ("\ncalling preinit: %s\n\n",
 			  main_map->l_name[0]
 			  ? main_map->l_name : _dl_argv[0]);
diff --git a/elf/dl-iteratephdr.c b/elf/dl-iteratephdr.c
index ff11ce5bff..e2a5d2a753 100644
--- a/elf/dl-iteratephdr.c
+++ b/elf/dl-iteratephdr.c
@@ -1,5 +1,5 @@
 /* Get loaded objects program headers.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@redhat.com>, 2001.
 
@@ -34,7 +34,7 @@ __dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
   /* Make sure we are alone.  */
   __libc_lock_lock_recursive (_dl_load_lock);
 
-  for (l = _dl_loaded; l != NULL; l = l->l_next)
+  for (l = GL(dl_loaded); l != NULL; l = l->l_next)
     {
       /* Skip the dynamic linker.  */
       if (l->l_phdr == NULL)
diff --git a/elf/dl-libc.c b/elf/dl-libc.c
index c83448df77..bb32f697e1 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 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Zack Weinberg <zack@rabi.columbia.edu>, 1999.
 
@@ -129,8 +129,8 @@ free_mem (void)
   struct r_search_path_elem *d;
 
   /* Remove all search directories.  */
-  d = _dl_all_dirs;
-  while (d != _dl_init_all_dirs)
+  d = GL(dl_all_dirs);
+  while (d != GL(dl_init_all_dirs))
     {
       struct r_search_path_elem *old = d;
       d = d->next;
@@ -138,7 +138,7 @@ free_mem (void)
     }
 
   /* Remove all additional names added to the objects.  */
-  for (l = _dl_loaded; l != NULL; l = l->l_next)
+  for (l = GL(dl_loaded); l != NULL; l = l->l_next)
     {
       struct libname_list *lnp = l->l_libname->next;
 
diff --git a/elf/dl-load.c b/elf/dl-load.c
index b66e7fee1d..cd568d2261 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -111,18 +111,6 @@ struct filebuf
   char buf[1024];
 };
 
-size_t _dl_pagesize;
-
-unsigned int _dl_osversion;
-
-int _dl_clktck;
-
-extern const char *_dl_platform;
-extern size_t _dl_platformlen;
-
-/* The object to be initialized first.  */
-struct link_map *_dl_initfirst;
-
 /* This is the decomposed LD_LIBRARY_PATH search path.  */
 static struct r_search_path_struct env_path_list;
 
@@ -240,7 +228,7 @@ _dl_dst_substitute (struct link_map *l, const char *name, char *result,
 	    repl = l->l_origin;
 	  else if ((len = is_dst (start, name + 1, "{PLATFORM}", 10, is_path,
 				  0)) != 0)
-	    repl = _dl_platform;
+	    repl = GL(dl_platform);
 
 	  if (repl != NULL && repl != (const char *) -1)
 	    {
@@ -344,12 +332,6 @@ add_name_to_object (struct link_map *l, const char *name)
   lastp->next = newname;
 }
 
-/* All known directories in sorted order.  */
-struct r_search_path_elem *_dl_all_dirs;
-
-/* All directories after startup.  */
-struct r_search_path_elem *_dl_init_all_dirs;
-
 /* Standard search directories.  */
 static struct r_search_path_struct rtld_search_dirs;
 
@@ -413,7 +395,7 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
 	}
 
       /* See if this directory is already known.  */
-      for (dirp = _dl_all_dirs; dirp != NULL; dirp = dirp->next)
+      for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
 	if (dirp->dirnamelen == len && memcmp (cp, dirp->dirname, len) == 0)
 	  break;
 
@@ -460,13 +442,13 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
 	  dirp->what = what;
 	  if (__builtin_expect (where != NULL, 1))
 	    dirp->where = memcpy ((char *) dirp + sizeof (*dirp) + len + 1
-				  + ncapstr * sizeof (enum r_dir_status),
+				  + (ncapstr * sizeof (enum r_dir_status)),
 				  where, where_len);
 	  else
 	    dirp->where = NULL;
 
-	  dirp->next = _dl_all_dirs;
-	  _dl_all_dirs = dirp;
+	  dirp->next = GL(dl_all_dirs);
+	  GL(dl_all_dirs) = dirp;
 
 	  /* Put it in the result array.  */
 	  result[nelems++] = dirp;
@@ -496,13 +478,14 @@ decompose_rpath (struct r_search_path_struct *sps,
 
   /* First see whether we must forget the RUNPATH and RPATH from this
      object.  */
-  if (__builtin_expect (_dl_inhibit_rpath != NULL, 0) && !__libc_enable_secure)
+  if (__builtin_expect (GL(dl_inhibit_rpath) != NULL, 0)
+      && !__libc_enable_secure)
     {
-      const char *found = strstr (_dl_inhibit_rpath, where);
+      const char *found = strstr (GL(dl_inhibit_rpath), where);
       if (found != NULL)
 	{
 	  size_t len = strlen (where);
-	  if ((found == _dl_inhibit_rpath || found[-1] == ':')
+	  if ((found == GL(dl_inhibit_rpath) || found[-1] == ':')
 	      && (found[len] == '\0' || found[len] == ':'))
 	    {
 	      /* This object is on the list of objects for which the
@@ -579,7 +562,7 @@ _dl_init_paths (const char *llp)
      directories addressed by the LD_LIBRARY_PATH environment variable.  */
 
   /* Get the capabilities.  */
-  capstr = _dl_important_hwcaps (_dl_platform, _dl_platformlen,
+  capstr = _dl_important_hwcaps (GL(dl_platform), GL(dl_platformlen),
 				 &ncapstr, &max_capstrlen);
 
   /* First set up the rest of the default search directory entries.  */
@@ -606,7 +589,7 @@ _dl_init_paths (const char *llp)
     }
 
   rtld_search_dirs.malloced = 0;
-  pelem = _dl_all_dirs = rtld_search_dirs.dirs[0];
+  pelem = GL(dl_all_dirs) = rtld_search_dirs.dirs[0];
   strp = system_dirs;
   idx = 0;
 
@@ -639,7 +622,7 @@ _dl_init_paths (const char *llp)
 
 #ifdef SHARED
   /* This points to the map of the main object.  */
-  l = _dl_loaded;
+  l = GL(dl_loaded);
   if (l != NULL)
     {
       assert (l->l_type != lt_loaded);
@@ -715,7 +698,7 @@ _dl_init_paths (const char *llp)
     env_path_list.dirs = (void *) -1;
 
   /* Remember the last search directory added at startup.  */
-  _dl_init_all_dirs = _dl_all_dirs;
+  GL(dl_init_all_dirs) = GL(dl_all_dirs);
 }
 
 
@@ -746,11 +729,11 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l,
 #ifndef SHARED
       if (l->l_prev == NULL)
 	/* No other module loaded.  */
-	_dl_loaded = NULL;
+	GL(dl_loaded) = NULL;
       else
 #endif
 	l->l_prev->l_next = NULL;
-      --_dl_nloaded;
+      --GL(dl_nloaded);
       free (l);
     }
   free (realname);
@@ -791,7 +774,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
     }
 
   /* Look again to see if the real name matched another already loaded.  */
-  for (l = _dl_loaded; l; l = l->l_next)
+  for (l = GL(dl_loaded); l; l = l->l_next)
     if (l->l_ino == st.st_ino && l->l_dev == st.st_dev)
       {
 	/* The object is already loaded.
@@ -812,7 +795,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
     return NULL;
 
   /* Print debugging message.  */
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_FILES, 0))
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_FILES, 0))
     _dl_debug_printf ("file=%s;  generating link map\n", name);
 
   /* This is the ELF header.  We read it in `open_verify'.  */
@@ -892,7 +875,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 	case PT_LOAD:
 	  /* A load command tells us to map in part of the file.
 	     We record the load commands and process them all later.  */
-	  if ((ph->p_align & (_dl_pagesize - 1)) != 0)
+	  if ((ph->p_align & (GL(dl_pagesize) - 1)) != 0)
 	    {
 	      errstring = N_("ELF load command alignment not page-aligned");
 	      goto call_lose;
@@ -907,8 +890,8 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 	  {
 	    struct loadcmd *c = &loadcmds[nloadcmds++];
 	    c->mapstart = ph->p_vaddr & ~(ph->p_align - 1);
-	    c->mapend = ((ph->p_vaddr + ph->p_filesz + _dl_pagesize - 1)
-			 & ~(_dl_pagesize - 1));
+	    c->mapend = ((ph->p_vaddr + ph->p_filesz + GL(dl_pagesize) - 1)
+			 & ~(GL(dl_pagesize) - 1));
 	    c->dataend = ph->p_vaddr + ph->p_filesz;
 	    c->allocend = ph->p_vaddr + ph->p_memsz;
 	    c->mapoff = ph->p_offset & ~(ph->p_align - 1);
@@ -1023,7 +1006,8 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 
 	    zero = l->l_addr + c->dataend;
 	    zeroend = l->l_addr + c->allocend;
-	    zeropage = (zero + _dl_pagesize - 1) & ~(_dl_pagesize - 1);
+	    zeropage = ((zero + GL(dl_pagesize) - 1)
+			& ~(GL(dl_pagesize) - 1));
 
 	    if (zeroend < zeropage)
 	      /* All the extra data is in the last page of the segment.
@@ -1036,8 +1020,8 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 		if ((c->prot & PROT_WRITE) == 0)
 		  {
 		    /* Dag nab it.  */
-		    if (__mprotect ((caddr_t) (zero & ~(_dl_pagesize - 1)),
-				    _dl_pagesize, c->prot|PROT_WRITE) < 0)
+		    if (__mprotect ((caddr_t) (zero & ~(GL(dl_pagesize) - 1)),
+				    GL(dl_pagesize), c->prot|PROT_WRITE) < 0)
 		      {
 			errstring = N_("cannot change memory protections");
 			goto call_lose_errno;
@@ -1045,8 +1029,8 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 		  }
 		memset ((void *) zero, '\0', zeropage - zero);
 		if ((c->prot & PROT_WRITE) == 0)
-		  __mprotect ((caddr_t) (zero & ~(_dl_pagesize - 1)),
-			      _dl_pagesize, c->prot);
+		  __mprotect ((caddr_t) (zero & ~(GL(dl_pagesize) - 1)),
+			      GL(dl_pagesize), c->prot);
 	      }
 
 	    if (zeroend > zeropage)
@@ -1110,7 +1094,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 
   l->l_entry += l->l_addr;
 
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_FILES, 0))
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_FILES, 0))
     _dl_debug_printf ("  dynamic: 0x%0*lx  base: 0x%0*lx   size: 0x%0*Zx\n"
 		      "    entry: 0x%0*lx  phdr: 0x%0*lx  phnum:   %*u\n\n",
 		      (int) sizeof (void *) * 2, (unsigned long int) l->l_ld,
@@ -1176,7 +1160,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 
   /* Remember whether this object must be initialized first.  */
   if (l->l_flags_1 & DF_1_INITFIRST)
-    _dl_initfirst = l;
+    GL(dl_initfirst) = l;
 
   /* Finally the file information.  */
   l->l_dev = st.st_dev;
@@ -1397,7 +1381,7 @@ open_verify (const char *name, struct filebuf *fbp)
 			+ (abi_note[6] & 0xff) * 256
 			+ (abi_note[7] & 0xff);
 	    if (abi_note[4] != __ABI_TAG_OS
-		|| (_dl_osversion && _dl_osversion < osversion))
+		|| (GL(dl_osversion) && GL(dl_osversion) < osversion))
 	      {
 	      close_and_out:
 		__close (fd);
@@ -1442,7 +1426,7 @@ open_path (const char *name, size_t namelen, int preloaded,
 
       /* If we are debugging the search for libraries print the path
 	 now if it hasn't happened now.  */
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_LIBS, 0)
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS, 0)
 	  && current_what != this_dir->what)
 	{
 	  current_what = this_dir->what;
@@ -1457,13 +1441,13 @@ open_path (const char *name, size_t namelen, int preloaded,
 	    continue;
 
 	  buflen =
-	    ((char *) __mempcpy (__mempcpy (edp,
-					    capstr[cnt].str, capstr[cnt].len),
+	    ((char *) __mempcpy (__mempcpy (edp, capstr[cnt].str,
+					    capstr[cnt].len),
 				 name, namelen)
 	     - buf);
 
 	  /* Print name we try if this is wanted.  */
-	  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_LIBS, 0))
+	  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS, 0))
 	    _dl_debug_printf ("  trying file=%s\n", buf);
 
 	  fd = open_verify (buf, fbp);
@@ -1566,7 +1550,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
   struct filebuf fb;
 
   /* Look for this name among those already loaded.  */
-  for (l = _dl_loaded; l; l = l->l_next)
+  for (l = GL(dl_loaded); l; l = l->l_next)
     {
       /* If the requested name matches the soname of a loaded object,
 	 use that object.  Elide this check for names that have not
@@ -1596,7 +1580,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
     }
 
   /* Display information if we are debugging.  */
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_FILES, 0) && loader != NULL)
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_FILES, 0) && loader != NULL)
     _dl_debug_printf ("\nfile=%s;  needed by %s\n", name,
 		      loader->l_name[0] ? loader->l_name : _dl_argv[0]);
 
@@ -1606,7 +1590,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
 
       size_t namelen = strlen (name) + 1;
 
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_LIBS, 0))
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS, 0))
 	_dl_debug_printf ("find library=%s; searching\n", name);
 
       fd = -1;
@@ -1644,7 +1628,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
 
 	  /* If dynamically linked, try the DT_RPATH of the executable
              itself.  */
-	  l = _dl_loaded;
+	  l = GL(dl_loaded);
 	  if (fd == -1 && l && l->l_type != lt_loaded && l != loader
 	      && l->l_rpath_dirs.dirs != (void *) -1)
 	    fd = open_path (name, namelen, preloaded, &l->l_rpath_dirs,
@@ -1698,7 +1682,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
 	  if (cached != NULL)
 	    {
 #ifdef SHARED
-	      l = loader ?: _dl_loaded;
+	      l = loader ?: GL(dl_loaded);
 #else
 	      l = loader;
 #endif
@@ -1748,14 +1732,14 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
 
       /* Finally, try the default path.  */
       if (fd == -1
-	  && ((l = loader ?: _dl_loaded) == NULL
+	  && ((l = loader ?: GL(dl_loaded)) == NULL
 	      || __builtin_expect (!(l->l_flags_1 & DF_1_NODEFLIB), 1))
 	  && rtld_search_dirs.dirs != (void *) -1)
 	fd = open_path (name, namelen, preloaded, &rtld_search_dirs,
 			&realname, &fb);
 
       /* Add another newline when we a tracing the library loading.  */
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_LIBS, 0))
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS, 0))
         _dl_debug_printf ("\n");
     }
   else
@@ -1777,7 +1761,7 @@ _dl_map_object (struct link_map *loader, const char *name, int preloaded,
   if (__builtin_expect (fd, 0) == -1)
     {
       if (trace_mode
-	  && __builtin_expect (_dl_debug_mask & DL_DEBUG_PRELINK, 0) == 0)
+	  && __builtin_expect (GL(dl_debug_mask) & DL_DEBUG_PRELINK, 0) == 0)
 	{
 	  /* We haven't found an appropriate library.  But since we
 	     are only interested in the list of libraries this isn't
diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
index ae8df270e9..f10ff4739d 100644
--- a/elf/dl-lookup.c
+++ b/elf/dl-lookup.c
@@ -59,12 +59,11 @@ struct sym_val
     result;								      \
   })
 
-#ifdef SHARED
 /* Statistics function.  */
-unsigned long int _dl_num_relocations;
-# define bump_num_relocation() ++_dl_num_relocations
+#ifdef SHARED
+# define bump_num_relocations() ++GL(dl_num_relocations)
 #else
-# define bump_num_relocation() ((void) 0)
+# define bump_num_relocations() ((void) 0)
 #endif
 
 
@@ -122,7 +121,7 @@ add_dependency (struct link_map *undef_map, struct link_map *map)
      reference is still available.  There is a brief period in
      which the object could have been removed since we found the
      definition.  */
-  runp = _dl_loaded;
+  runp = GL(dl_loaded);
   while (runp != NULL && runp != map)
     runp = runp->l_next;
 
@@ -168,7 +167,7 @@ add_dependency (struct link_map *undef_map, struct link_map *map)
 	  ++(*list)->l_opencount;
 
       /* Display information if we are debugging.  */
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_FILES, 0))
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_FILES, 0))
 	_dl_debug_printf ("\
 \nfile=%s;  needed by %s (relocation dependency)\n\n",
 			  map->l_name[0] ? map->l_name : _dl_argv[0],
@@ -281,7 +280,7 @@ _dl_lookup_symbol (const char *undef_name, struct link_map *undef_map,
 	}
     }
 
-  if (__builtin_expect (_dl_debug_mask
+  if (__builtin_expect (GL(dl_debug_mask)
 			& (DL_DEBUG_BINDINGS|DL_DEBUG_PRELINK), 0))
     _dl_debug_bindings (undef_name, undef_map, ref, symbol_scope,
 			&current_value, NULL, type_class, protected);
@@ -352,7 +351,7 @@ _dl_lookup_symbol_skip (const char *undef_name,
 	}
     }
 
-  if (__builtin_expect (_dl_debug_mask
+  if (__builtin_expect (GL(dl_debug_mask)
 			& (DL_DEBUG_BINDINGS|DL_DEBUG_PRELINK), 0))
     _dl_debug_bindings (undef_name, undef_map, ref, symbol_scope,
 			&current_value, NULL, 0, protected);
@@ -471,7 +470,7 @@ _dl_lookup_versioned_symbol (const char *undef_name,
 	}
     }
 
-  if (__builtin_expect (_dl_debug_mask
+  if (__builtin_expect (GL(dl_debug_mask)
 			& (DL_DEBUG_BINDINGS|DL_DEBUG_PRELINK), 0))
     _dl_debug_bindings (undef_name, undef_map, ref, symbol_scope,
 			&current_value, version, type_class, protected);
@@ -557,7 +556,7 @@ _dl_lookup_versioned_symbol_skip (const char *undef_name,
 	}
     }
 
-  if (__builtin_expect (_dl_debug_mask
+  if (__builtin_expect (GL(dl_debug_mask)
 			& (DL_DEBUG_BINDINGS|DL_DEBUG_PRELINK), 0))
     _dl_debug_bindings (undef_name, undef_map, ref, symbol_scope,
 			&current_value, version, 0, protected);
@@ -596,7 +595,7 @@ _dl_debug_bindings (const char *undef_name, struct link_map *undef_map,
 {
   const char *reference_name = undef_map->l_name;
 
-  if (_dl_debug_mask & DL_DEBUG_BINDINGS)
+  if (GL(dl_debug_mask) & DL_DEBUG_BINDINGS)
     {
       _dl_debug_printf ("binding file %s to %s: %s symbol `%s'",
 			(reference_name[0]
@@ -610,14 +609,14 @@ _dl_debug_bindings (const char *undef_name, struct link_map *undef_map,
 	_dl_debug_printf_c ("\n");
     }
 #ifdef SHARED
-  if (_dl_debug_mask & DL_DEBUG_PRELINK)
+  if (GL(dl_debug_mask) & DL_DEBUG_PRELINK)
     {
       int conflict = 0;
       struct sym_val val = { NULL, NULL };
 
-      if ((_dl_trace_prelink_map == NULL
-	   || _dl_trace_prelink_map == _dl_loaded)
-	  && undef_map != _dl_loaded)
+      if ((GL(dl_trace_prelink_map) == NULL
+	   || GL(dl_trace_prelink_map) == GL(dl_loaded))
+	  && undef_map != GL(dl_loaded))
 	{
 	  const unsigned long int hash = _dl_elf_hash (undef_name);
 
@@ -634,8 +633,8 @@ _dl_debug_bindings (const char *undef_name, struct link_map *undef_map,
 	}
 
       if (conflict
-	  || _dl_trace_prelink_map == undef_map
-	  || _dl_trace_prelink_map == NULL)
+	  || GL(dl_trace_prelink_map) == undef_map
+	  || GL(dl_trace_prelink_map) == NULL)
 	{
 	  _dl_printf ("%s 0x%0*Zx 0x%0*Zx -> 0x%0*Zx 0x%0*Zx ",
 		      conflict ? "conflict" : "lookup",
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
index b72faa0aa7..12e9d69ff7 100644
--- a/elf/dl-minimal.c
+++ b/elf/dl-minimal.c
@@ -1,5 +1,5 @@
 /* Minimal replacements for basic facilities used in the dynamic linker.
-   Copyright (C) 1995,96,97,98,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,98,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -60,8 +60,9 @@ malloc (size_t n)
       /* Consume any unused space in the last page of our data segment.  */
       extern int _end;
       alloc_ptr = &_end;
-      alloc_end = (void *) 0 + (((alloc_ptr - (void *) 0) + _dl_pagesize - 1)
-				& ~(_dl_pagesize - 1));
+      alloc_end = (void *) 0 + (((alloc_ptr - (void *) 0)
+				 + GL(dl_pagesize) - 1)
+				& ~(GL(dl_pagesize) - 1));
     }
 
   /* Make sure the allocation pointer is ideally aligned.  */
@@ -72,7 +73,7 @@ malloc (size_t n)
     {
       /* Insufficient space left; allocate another page.  */
       caddr_t page;
-      size_t nup = (n + _dl_pagesize - 1) & ~(_dl_pagesize - 1);
+      size_t nup = (n + GL(dl_pagesize) - 1) & ~(GL(dl_pagesize) - 1);
       page = __mmap (0, nup, PROT_READ|PROT_WRITE,
 		     MAP_ANON|MAP_PRIVATE, _dl_zerofd, 0);
       assert (page != MAP_FAILED);
diff --git a/elf/dl-object.c b/elf/dl-object.c
index eee9deb3d2..0488e3230c 100644
--- a/elf/dl-object.c
+++ b/elf/dl-object.c
@@ -1,5 +1,5 @@
 /* Storage management for the chain of loaded shared objects.
-   Copyright (C) 1995,96,97,98,99,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -64,9 +64,9 @@ _dl_new_object (char *realname, const char *libname, int type,
   /* Counter for the scopes we have to handle.  */
   idx = 0;
 
-  if (_dl_loaded != NULL)
+  if (GL(dl_loaded) != NULL)
     {
-      l = _dl_loaded;
+      l = GL(dl_loaded);
       while (l->l_next != NULL)
 	l = l->l_next;
       new->l_prev = l;
@@ -74,11 +74,11 @@ _dl_new_object (char *realname, const char *libname, int type,
       l->l_next = new;
 
       /* Add the global scope.  */
-      new->l_scope[idx++] = &_dl_loaded->l_searchlist;
+      new->l_scope[idx++] = &GL(dl_loaded)->l_searchlist;
     }
   else
-    _dl_loaded = new;
-  ++_dl_nloaded;
+    GL(dl_loaded) = new;
+  ++GL(dl_nloaded);
 
   /* If we have no loader the new object acts as it.  */
   if (loader == NULL)
diff --git a/elf/dl-open.c b/elf/dl-open.c
index c061cdeb0e..2f82e4cf40 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -1,5 +1,5 @@
 /* Load a shared object at runtime, relocate it, and run its initializer.
-   Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -50,16 +50,12 @@ extern char **__libc_argv;
 
 extern char **__environ;
 
-extern int _dl_lazy;			/* Do we do lazy relocations?  */
-
 /* Undefine the following for debugging.  */
 /* #define SCOPE_DEBUG 1 */
 #ifdef SCOPE_DEBUG
 static void show_scope (struct link_map *new);
 #endif
 
-extern size_t _dl_platformlen;
-
 /* We must be carefull not to leave us in an inconsistent state.  Thus we
    catch any error and re-raise it after cleaning up.  */
 
@@ -98,15 +94,15 @@ add_to_global (struct link_map *new)
      in an realloc() call.  Therefore we allocate a completely new
      array the first time we have to add something to the locale scope.  */
 
-  if (_dl_global_scope_alloc == 0)
+  if (GL(dl_global_scope_alloc) == 0)
     {
       /* This is the first dynamic object given global scope.  */
-      _dl_global_scope_alloc = _dl_main_searchlist->r_nlist + to_add + 8;
+      GL(dl_global_scope_alloc) = GL(dl_main_searchlist)->r_nlist + to_add + 8;
       new_global = (struct link_map **)
-	malloc (_dl_global_scope_alloc * sizeof (struct link_map *));
+	malloc (GL(dl_global_scope_alloc) * sizeof (struct link_map *));
       if (new_global == NULL)
 	{
-	  _dl_global_scope_alloc = 0;
+	  GL(dl_global_scope_alloc) = 0;
 	nomem:
 	  _dl_signal_error (ENOMEM, new->l_libname->name, NULL,
 			    N_("cannot extend global scope"));
@@ -114,24 +110,25 @@ add_to_global (struct link_map *new)
 	}
 
       /* Copy over the old entries.  */
-      memcpy (new_global, _dl_main_searchlist->r_list,
-	      (_dl_main_searchlist->r_nlist * sizeof (struct link_map *)));
+      memcpy (new_global, GL(dl_main_searchlist)->r_list,
+	      (GL(dl_main_searchlist)->r_nlist * sizeof (struct link_map *)));
 
-      _dl_main_searchlist->r_list = new_global;
+      GL(dl_main_searchlist)->r_list = new_global;
     }
-  else if (_dl_main_searchlist->r_nlist + to_add > _dl_global_scope_alloc)
+  else if (GL(dl_main_searchlist)->r_nlist + to_add
+	   > GL(dl_global_scope_alloc))
     {
       /* We have to extend the existing array of link maps in the
 	 main map.  */
       new_global = (struct link_map **)
-	realloc (_dl_main_searchlist->r_list,
-		 ((_dl_global_scope_alloc + to_add + 8)
+	realloc (GL(dl_main_searchlist)->r_list,
+		 ((GL(dl_global_scope_alloc) + to_add + 8)
 		  * sizeof (struct link_map *)));
       if (new_global == NULL)
 	goto nomem;
 
-      _dl_global_scope_alloc += to_add + 8;
-      _dl_main_searchlist->r_list = new_global;
+      GL(dl_global_scope_alloc) += to_add + 8;
+      GL(dl_main_searchlist)->r_list = new_global;
     }
 
   /* Now add the new entries.  */
@@ -142,8 +139,9 @@ add_to_global (struct link_map *new)
       if (map->l_global == 0)
 	{
 	  map->l_global = 1;
-	  _dl_main_searchlist->r_list[_dl_main_searchlist->r_nlist] = map;
-	  ++_dl_main_searchlist->r_nlist;
+	  GL(dl_main_searchlist)->r_list[GL(dl_main_searchlist)->r_nlist]
+	    = map;
+	  ++GL(dl_main_searchlist)->r_nlist;
 	}
     }
 
@@ -180,7 +178,7 @@ dl_open_worker (void *a)
 
       /* We have to find out from which object the caller is calling.  */
       call_map = NULL;
-      for (l = _dl_loaded; l; l = l->l_next)
+      for (l = GL(dl_loaded); l; l = l->l_next)
 	if (caller >= (const void *) l->l_map_start
 	    && caller < (const void *) l->l_map_end)
 	  {
@@ -192,7 +190,7 @@ dl_open_worker (void *a)
 
       if (call_map == NULL)
 	/* In this case we assume this is the main application.  */
-	call_map = _dl_loaded;
+	call_map = GL(dl_loaded);
 
       /* Determine how much space we need.  We have to allocate the
 	 memory locally.  */
@@ -233,7 +231,7 @@ dl_open_worker (void *a)
   if (new->l_searchlist.r_list != NULL)
     {
       /* Let the user know about the opencount.  */
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_FILES, 0))
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_FILES, 0))
 	_dl_debug_printf ("opening file=%s; opencount == %u\n\n",
 			  new->l_name, new->l_opencount);
 
@@ -274,20 +272,20 @@ dl_open_worker (void *a)
       if (! l->l_relocated)
 	{
 #ifdef SHARED
-	  if (_dl_profile != NULL)
+	  if (GL(dl_profile) != NULL)
 	    {
 	      /* If this here is the shared object which we want to profile
 		 make sure the profile is started.  We can find out whether
 	         this is necessary or not by observing the `_dl_profile_map'
 	         variable.  If was NULL but is not NULL afterwars we must
 		 start the profiling.  */
-	      struct link_map *old_profile_map = _dl_profile_map;
+	      struct link_map *old_profile_map = GL(dl_profile_map);
 
 	      _dl_relocate_object (l, l->l_scope, 1, 1);
 
-	      if (old_profile_map == NULL && _dl_profile_map != NULL)
+	      if (old_profile_map == NULL && GL(dl_profile_map) != NULL)
 		/* We must prepare the profiling.  */
-		_dl_start_profile (_dl_profile_map, _dl_profile_output);
+		_dl_start_profile (GL(dl_profile_map), GL(dl_profile_output));
 	    }
 	  else
 #endif
@@ -382,7 +380,7 @@ dl_open_worker (void *a)
     __libc_multiple_libcs = 1;
 
   /* Let the user know about the opencount.  */
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_FILES, 0))
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_FILES, 0))
     _dl_debug_printf ("opening file=%s; opencount == %u\n\n",
 		      new->l_name, new->l_opencount);
 }
diff --git a/elf/dl-profile.c b/elf/dl-profile.c
index 9f16a9359e..6abdb1b76d 100644
--- a/elf/dl-profile.c
+++ b/elf/dl-profile.c
@@ -1,5 +1,5 @@
 /* Profiling of shared libraries.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
    Based on the BSD mcount implementation.
@@ -196,9 +196,9 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
   for (ph = map->l_phdr; ph < &map->l_phdr[map->l_phnum]; ++ph)
     if (ph->p_type == PT_LOAD && (ph->p_flags & PF_X))
       {
-	ElfW(Addr) start = (ph->p_vaddr & ~(_dl_pagesize - 1));
-	ElfW(Addr) end = ((ph->p_vaddr + ph->p_memsz + _dl_pagesize - 1)
-			  & ~(_dl_pagesize - 1));
+	ElfW(Addr) start = (ph->p_vaddr & ~(GL(dl_pagesize) - 1));
+	ElfW(Addr) end = ((ph->p_vaddr + ph->p_memsz + GL(dl_pagesize) - 1)
+			  & ~(GL(dl_pagesize) - 1));
 
 	if (start < mapstart)
 	  mapstart = start;
@@ -250,11 +250,11 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
   /* First determine the output name.  We write in the directory
      OUTPUT_DIR and the name is composed from the shared objects
      soname (or the file name) and the ending ".profile".  */
-  filename = (char *) alloca (strlen (output_dir) + 1 + strlen (_dl_profile)
+  filename = (char *) alloca (strlen (output_dir) + 1 + strlen (GL(dl_profile))
 			      + sizeof ".profile");
   cp = __stpcpy (filename, output_dir);
   *cp++ = '/';
-  __stpcpy (__stpcpy (cp, _dl_profile), ".profile");
+  __stpcpy (__stpcpy (cp, GL(dl_profile)), ".profile");
 
 #ifdef O_NOFOLLOW
 # define EXTRA_FLAGS | O_NOFOLLOW
@@ -287,11 +287,11 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
   if (st.st_size == 0)
     {
       /* We have to create the file.  */
-      char buf[_dl_pagesize];
+      char buf[GL(dl_pagesize)];
 
-      memset (buf, '\0', _dl_pagesize);
+      memset (buf, '\0', GL(dl_pagesize));
 
-      if (__lseek (fd, expected_size & ~(_dl_pagesize - 1), SEEK_SET) == -1)
+      if (__lseek (fd, expected_size & ~(GL(dl_pagesize) - 1), SEEK_SET) == -1)
 	{
 	  char buf[400];
 	  int errnum;
@@ -304,7 +304,8 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
 	}
 
       if (TEMP_FAILURE_RETRY (__libc_write (fd, buf, (expected_size
-						      & (_dl_pagesize - 1))))
+						      & (GL(dl_pagesize)
+							 - 1))))
 	  < 0)
 	goto cannot_create;
     }
@@ -317,7 +318,7 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
 	__munmap ((void *) addr, expected_size);
 
       _dl_error_printf ("%s: file is no correct profile data file for `%s'\n",
-			filename, _dl_profile);
+			filename, GL(dl_profile));
       return;
     }
 
diff --git a/elf/dl-profstub.c b/elf/dl-profstub.c
index 4ca39b5b80..45fb4e987c 100644
--- a/elf/dl-profstub.c
+++ b/elf/dl-profstub.c
@@ -1,5 +1,5 @@
 /* Helper definitions for profiling of shared libraries.
-   Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -24,7 +24,7 @@
 
 /* This is the map for the shared object we profile.  It is defined here
    only because we test for this value being NULL or not.  */
-extern struct link_map *_dl_profile_map;
+//Xextern struct link_map *_dl_profile_map;
 
 
 void
@@ -37,6 +37,6 @@ _dl_mcount_wrapper (void *selfpc)
 void
 _dl_mcount_wrapper_check (void *selfpc)
 {
-  if (_dl_profile_map != NULL)
+  if (GL(dl_profile_map) != NULL)
     _dl_mcount ((ElfW(Addr)) RETURN_ADDRESS (0), (ElfW(Addr)) selfpc);
 }
diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c
index bfab6a2bda..a3ee153b84 100644
--- a/elf/dl-reloc.c
+++ b/elf/dl-reloc.c
@@ -27,10 +27,9 @@
 #include <sys/types.h>
 #include "dynamic-link.h"
 
-#ifdef SHARED
 /* Statistics function.  */
-unsigned long int _dl_num_cache_relocations;
-# define bump_num_cache_relocations() ++_dl_num_cache_relocations
+#ifdef SHARED
+# define bump_num_cache_relocations() ++GL(dl_num_cache_relocations)
 #else
 # define bump_num_cache_relocations() ((void) 0)
 #endif
@@ -59,9 +58,10 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
       && __builtin_expect (l->l_info[DT_BIND_NOW] != NULL, 0))
     lazy = 0;
 
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_RELOC, 0))
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_RELOC, 0))
     _dl_printf ("\nrelocation processing: %s%s\n",
-		l->l_name[0] ? l->l_name : _dl_argv[0], lazy ? " (lazy)" : "");
+		l->l_name[0] ? l->l_name : _dl_argv[0],
+		lazy ? " (lazy)" : "");
 
   /* DT_TEXTREL is now in level 2 and might phase out at some time.
      But we rewrite the DT_FLAGS entry to a DT_TEXTREL entry to make
@@ -77,10 +77,10 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
 	    struct textrels *newp;
 
 	    newp = (struct textrels *) alloca (sizeof (*newp));
-	    newp->len = (((ph->p_vaddr + ph->p_memsz + _dl_pagesize - 1)
-			  & ~(_dl_pagesize - 1))
-			 - (ph->p_vaddr & ~(_dl_pagesize - 1)));
-	    newp->start = ((ph->p_vaddr & ~(_dl_pagesize - 1))
+	    newp->len = (((ph->p_vaddr + ph->p_memsz + GL(dl_pagesize) - 1)
+			  & ~(GL(dl_pagesize) - 1))
+			 - (ph->p_vaddr & ~(GL(dl_pagesize) - 1)));
+	    newp->start = ((ph->p_vaddr & ~(GL(dl_pagesize) - 1))
 			   + (caddr_t) l->l_addr);
 
 	    if (__mprotect (newp->start, newp->len, PROT_READ|PROT_WRITE) < 0)
diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
index 27d99fcc66..44af537ab7 100644
--- a/elf/dl-runtime.c
+++ b/elf/dl-runtime.c
@@ -1,5 +1,5 @@
 /* On-demand PLT fixup for shared objects.
-   Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -118,7 +118,7 @@ fixup (
   value = elf_machine_plt_value (l, reloc, value);
 
   /* Finally, fix up the plt itself.  */
-  if (__builtin_expect (_dl_bind_not, 0))
+  if (__builtin_expect (GL(dl_bind_not), 0))
     return value;
 
   return elf_machine_fixup_plt (l, result, reloc, rel_addr, value);
@@ -210,7 +210,7 @@ profile_fixup (
       value = elf_machine_plt_value (l, reloc, value);
 
       /* Store the result for later runs.  */
-      if (__builtin_expect (! _dl_bind_not, 1))
+      if (__builtin_expect (! GL(dl_bind_not), 1))
 	*resultp = value;
     }
 
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 1332e8a89f..0efbcc4cb6 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -1,5 +1,5 @@
 /* Support for dynamic linking code in static libc.
-   Copyright (C) 1996, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -52,9 +52,6 @@ int _dl_dynamic_weak = 1;
 /* If nonzero print warnings about problematic situations.  */
 int _dl_verbose;
 
-/* Structure to store information about search paths.  */
-struct r_search_path *_dl_search_paths;
-
 /* We never do profiling.  */
 const char *_dl_profile;
 
@@ -104,6 +101,24 @@ int _dl_starting_up = 1;
 hp_timing_t _dl_cpuclock_offset;
 #endif
 
+/* This is zero at program start to signal that the global scope map is
+   allocated by rtld.  Later it keeps the size of the map.  It might be
+   reset if in _dl_close if the last global object is removed.  */
+size_t _dl_global_scope_alloc;
+
+size_t _dl_pagesize;
+
+unsigned int _dl_osversion;
+
+/* All known directories in sorted order.  */
+struct r_search_path_elem *_dl_all_dirs;
+
+/* All directories after startup.  */
+struct r_search_path_elem *_dl_init_all_dirs;
+
+/* The object to be initialized first.  */
+struct link_map *_dl_initfirst;
+
 /* During the program run we must not modify the global data of
    loaded shared object simultanously in two threads.  Therefore we
    protect `_dl_open' and `_dl_close' in dl-close.c.
@@ -115,7 +130,7 @@ __libc_lock_define_initialized_recursive (, _dl_load_lock)
 
 
 #ifdef HAVE_AUX_VECTOR
-extern int _dl_clktck;
+int _dl_clktck;
 
 void
 internal_function
@@ -125,10 +140,10 @@ _dl_aux_init (ElfW(auxv_t) *av)
     switch (av->a_type)
       {
       case AT_PAGESZ:
-	_dl_pagesize = av->a_un.a_val;
+	GL(dl_pagesize) = av->a_un.a_val;
 	break;
       case AT_CLKTCK:
-	_dl_clktck = av->a_un.a_val;
+	GL(dl_clktck) = av->a_un.a_val;
 	break;
       }
 }
diff --git a/elf/dl-sym.c b/elf/dl-sym.c
index 85d084f7f7..b0db159aa6 100644
--- a/elf/dl-sym.c
+++ b/elf/dl-sym.c
@@ -1,5 +1,5 @@
 /* Look up a symbol in a shared object loaded by `dlopen'.
-   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -37,10 +37,10 @@ _dl_sym (void *handle, const char *name, void *who)
 
   /* If the address is not recognized the call comes from the main
      program (we hope).  */
-  match = _dl_loaded;
+  match = GL(dl_loaded);
 
   /* Find the highest-addressed object that CALLER is not below.  */
-  for (l = _dl_loaded; l != NULL; l = l->l_next)
+  for (l = GL(dl_loaded); l != NULL; l = l->l_next)
     if (caller >= l->l_map_start && caller < l->l_map_end)
       {
 	/* There must be exactly one DSO for the range of the virtual
@@ -64,11 +64,11 @@ _dl_sym (void *handle, const char *name, void *who)
 	}
       else
 	{
-	  if (__builtin_expect (match == _dl_loaded, 0))
+	  if (__builtin_expect (match == GL(dl_loaded), 0))
 	    {
-	      if (! _dl_loaded
-		  || caller < _dl_loaded->l_map_start
-		  || caller >= _dl_loaded->l_map_end)
+	      if (! GL(dl_loaded)
+		  || caller < GL(dl_loaded)->l_map_start
+		  || caller >= GL(dl_loaded)->l_map_end)
 	        _dl_signal_error (0, NULL, NULL, N_("\
 RTLD_NEXT used in code not dynamically loaded"));
 	    }
@@ -108,10 +108,10 @@ _dl_vsym (void *handle, const char *name, const char *version, void *who)
 
   /* If the address is not recognized the call comes from the main
      program (we hope).  */
-  match = _dl_loaded;
+  match = GL(dl_loaded);
 
   /* Find the highest-addressed object that CALLER is not below.  */
-  for (l = _dl_loaded; l != NULL; l = l->l_next)
+  for (l = GL(dl_loaded); l != NULL; l = l->l_next)
     if (caller >= l->l_map_start && caller < l->l_map_end)
       {
 	/* There must be exactly one DSO for the range of the virtual
@@ -126,11 +126,11 @@ _dl_vsym (void *handle, const char *name, const char *version, void *who)
 					  &vers, 0, 0);
   else if (handle == RTLD_NEXT)
     {
-      if (__builtin_expect (match == _dl_loaded, 0))
+      if (__builtin_expect (match == GL(dl_loaded), 0))
 	{
-	  if (! _dl_loaded
-	      || caller < _dl_loaded->l_map_start
-	      || caller >= _dl_loaded->l_map_end)
+	  if (! GL(dl_loaded)
+	      || caller < GL(dl_loaded)->l_map_start
+	      || caller >= GL(dl_loaded)->l_map_end)
 	    _dl_signal_error (0, NULL, NULL, N_("\
 RTLD_NEXT used in code not dynamically loaded"));
 	}
diff --git a/elf/dl-version.c b/elf/dl-version.c
index 6715bc1547..7edb8ec359 100644
--- a/elf/dl-version.c
+++ b/elf/dl-version.c
@@ -1,5 +1,5 @@
 /* Handle symbol and library versioning.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -58,7 +58,7 @@ find_needed (const char *name, struct link_map *map)
   struct link_map *tmap;
   unsigned int n;
 
-  for (tmap = _dl_loaded; tmap != NULL; tmap = tmap->l_next)
+  for (tmap = GL(dl_loaded); tmap != NULL; tmap = tmap->l_next)
     if (_dl_name_match_p (name, tmap))
       return tmap;
 
@@ -86,11 +86,11 @@ match_symbol (const char *name, ElfW(Word) hash, const char *string,
   int result = 0;
 
   /* Display information about what we are doing while debugging.  */
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_VERSIONS, 0))
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_VERSIONS, 0))
     _dl_debug_printf ("\
 checking for version `%s' in file %s required by file %s\n",
-		      string, map->l_name[0] ? map->l_name : _dl_argv[0],
-		      name);
+		      string, map->l_name[0]
+		      ? map->l_name : _dl_argv[0], name);
 
   if (__builtin_expect (map->l_info[VERSYMIDX (DT_VERDEF)] == NULL, 0))
     {
@@ -166,8 +166,8 @@ no version information available (required by ", name, ")");
 			   name, ")");
   result = 1;
  call_cerror:
-  _dl_signal_cerror (0, map->l_name[0] ? map->l_name : _dl_argv[0], NULL,
-		     errstring);
+  _dl_signal_cerror (0, map->l_name[0] ? map->l_name : _dl_argv[0],
+		     NULL, errstring);
   return result;
 }
 
@@ -214,7 +214,8 @@ _dl_check_map_versions (struct link_map *map, int verbose, int trace_mode)
 					       &buf[sizeof (buf) - 1], 10, 0),
 				   " of Verneed record\n");
 	call_error:
-	  _dl_signal_error (errval, (*map->l_name ? map->l_name : _dl_argv[0]),
+	  _dl_signal_error (errval, (*map->l_name
+				     ? map->l_name : _dl_argv[0]),
 			    NULL, errstring);
 	}
 
diff --git a/elf/do-lookup.h b/elf/do-lookup.h
index b9364b95d1..65f7b02a20 100644
--- a/elf/do-lookup.h
+++ b/elf/do-lookup.h
@@ -1,5 +1,5 @@
 /* Look up a symbol in the loaded objects.
-   Copyright (C) 1995,96,97,98,99,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -60,7 +60,7 @@ FCT (const char *undef_name, unsigned long int hash, const ElfW(Sym) *ref,
 	continue;
 
       /* Print some debugging info if wanted.  */
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_SYMBOLS, 0))
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_SYMBOLS, 0))
 	_dl_debug_printf ("symbol=%s;  lookup in file=%s\n", undef_name,
 			  map->l_name[0] ? map->l_name : _dl_argv[0]);
 
diff --git a/elf/do-rel.h b/elf/do-rel.h
index d08f655815..3968937093 100644
--- a/elf/do-rel.h
+++ b/elf/do-rel.h
@@ -1,5 +1,5 @@
 /* Do relocations for ELF dynamic linking.
-   Copyright (C) 1995,96,97,98,99,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -79,8 +79,10 @@ elf_dynamic_do_rel (struct link_map *map,
 	 RTLD_BOOTSTRAP) because rtld.c contains the common defn for
 	 _dl_rtld_map, which is incompatible with a weak decl in the same
 	 file.  */
-      weak_extern (_dl_rtld_map);
-      if (map != &_dl_rtld_map) /* Already done in rtld itself.  */
+# ifndef SHARED
+      weak_extern (GL(dl_rtld_map));
+# endif
+      if (map != &GL(dl_rtld_map)) /* Already done in rtld itself.  */
 # ifndef DO_RELA
 	/* Rela platforms get the offset from r_addend and this must
 	   be copied in the relocation address.  Therefore we can skip
diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
index bbfd301231..8792b8e4b6 100644
--- a/elf/dynamic-link.h
+++ b/elf/dynamic-link.h
@@ -1,5 +1,5 @@
 /* Inline functions for dynamic linking.
-   Copyright (C) 1995,96,97,98,99,2000,2001 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -26,11 +26,6 @@
 #endif
 
 
-/* Global read-only variable defined in rtld.c which is nonzero if we
-   shall give more warning messages.  */
-extern int _dl_verbose __attribute__ ((unused));
-
-
 /* Read the dynamic section at DYN and fill in INFO with indices DT_*.  */
 
 static inline void __attribute__ ((unused))
diff --git a/elf/rtld.c b/elf/rtld.c
index 45b15fd8f2..050d7fae8a 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -58,17 +58,7 @@ static void process_envvars (enum mode *modep);
 int _dl_argc;
 char **_dl_argv;
 unsigned int _dl_skip_args;	/* Nonzero if we were run directly.  */
-int _dl_verbose;
-const char *_dl_platform;
-size_t _dl_platformlen;
-unsigned long _dl_hwcap;
 fpu_control_t _dl_fpu_control = _FPU_DEFAULT;
-struct r_search_path *_dl_search_paths;
-const char *_dl_profile;
-const char *_dl_profile_output;
-struct link_map *_dl_profile_map;
-const char *_dl_trace_prelink;
-struct link_map *_dl_trace_prelink_map;
 int _dl_lazy = 1;
 /* XXX I know about at least one case where we depend on the old weak
    behavior (it has to do with librt).  Until we get DSO groups implemented
@@ -78,23 +68,6 @@ int _dl_dynamic_weak;
 #else
 int _dl_dynamic_weak = 1;
 #endif
-int _dl_debug_mask;
-const char *_dl_inhibit_rpath;		/* RPATH values which should be
-					   ignored.  */
-const char *_dl_origin_path;
-int _dl_bind_not;
-
-/* This is a pointer to the map for the main object and through it to
-   all loaded objects.  */
-struct link_map *_dl_loaded;
-/* Number of object in the _dl_loaded list.  */
-unsigned int _dl_nloaded;
-/* Pointer to the l_searchlist element of the link map of the main object.  */
-struct r_scope_elem *_dl_main_searchlist;
-/* Copy of the content of `_dl_main_searchlist'.  */
-struct r_scope_elem _dl_initial_searchlist;
-/* Array which is used when looking up in the global scope.  */
-struct r_scope_elem *_dl_global_scope[2];
 
 /* During the program run we must not modify the global data of
    loaded shared object simultanously in two threads.  Therefore we
@@ -114,14 +87,17 @@ __libc_lock_define_initialized_recursive (, _dl_load_lock)
    never be called.  */
 int _dl_starting_up;
 
+/* This is the structure which defines all variables global to ld.so
+   (except those which cannot be added for some reason).  */
+struct rtld_global _rtld_global;
+
 
 static void dl_main (const ElfW(Phdr) *phdr,
 		     ElfW(Word) phnum,
 		     ElfW(Addr) *user_entry);
 
-struct link_map _dl_rtld_map;
-struct libname_list _dl_rtld_libname;
-struct libname_list _dl_rtld_libname2;
+static struct libname_list _dl_rtld_libname;
+static struct libname_list _dl_rtld_libname2;
 
 /* We expect less than a second for relocation.  */
 #ifdef HP_SMALL_TIMING_AVAIL
@@ -135,8 +111,6 @@ static hp_timing_t rtld_total_time;
 static hp_timing_t relocate_time;
 static hp_timing_t load_time;
 #endif
-extern unsigned long int _dl_num_relocations;		/* in dl-lookup.c */
-extern unsigned long int _dl_num_cache_relocations;	/* in dl-reloc.c */
 
 static ElfW(Addr) _dl_start_final (void *arg, struct link_map *bootstrap_map_p,
 				   hp_timing_t start_time);
@@ -217,7 +191,7 @@ _dl_start (void *arg)
 # define ELF_MACHINE_START_ADDRESS(map, start) (start)
 #endif
 
-    return ELF_MACHINE_START_ADDRESS (_dl_loaded, entry);
+    return ELF_MACHINE_START_ADDRESS (GL(dl_loaded), entry);
   }
 }
 
@@ -253,15 +227,15 @@ _dl_start_final (void *arg, struct link_map *bootstrap_map_p,
     }
 
   /* Transfer data about ourselves to the permanent link_map structure.  */
-  _dl_rtld_map.l_addr = bootstrap_map_p->l_addr;
-  _dl_rtld_map.l_ld = bootstrap_map_p->l_ld;
-  _dl_rtld_map.l_opencount = 1;
-  memcpy (_dl_rtld_map.l_info, bootstrap_map_p->l_info,
-	  sizeof _dl_rtld_map.l_info);
-  _dl_setup_hash (&_dl_rtld_map);
-  _dl_rtld_map.l_mach = bootstrap_map_p->l_mach;
-  _dl_rtld_map.l_map_start = (ElfW(Addr)) _begin;
-  _dl_rtld_map.l_map_end = (ElfW(Addr)) _end;
+  GL(dl_rtld_map).l_addr = bootstrap_map_p->l_addr;
+  GL(dl_rtld_map).l_ld = bootstrap_map_p->l_ld;
+  GL(dl_rtld_map).l_opencount = 1;
+  memcpy (GL(dl_rtld_map).l_info, bootstrap_map_p->l_info,
+	  sizeof GL(dl_rtld_map).l_info);
+  _dl_setup_hash (&GL(dl_rtld_map));
+  GL(dl_rtld_map).l_mach = bootstrap_map_p->l_mach;
+  GL(dl_rtld_map).l_map_start = (ElfW(Addr)) _begin;
+  GL(dl_rtld_map).l_map_end = (ElfW(Addr)) _end;
 
   /* Call the OS-dependent function to set up life so we can do things like
      file access.  It will call `dl_main' (below) to do all the real work
@@ -281,7 +255,7 @@ _dl_start_final (void *arg, struct link_map *bootstrap_map_p,
     }
 #endif
 
-  if (__builtin_expect (_dl_debug_mask & DL_DEBUG_STATISTICS, 0))
+  if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_STATISTICS, 0))
     print_statistics ();
 
   return *start_addr;
@@ -334,7 +308,7 @@ static void
 version_check_doit (void *a)
 {
   struct version_check_args *args = (struct version_check_args *) a;
-  if (_dl_check_all_versions (_dl_loaded, 1, args->dotrace) && args->doexit)
+  if (_dl_check_all_versions (GL(dl_loaded), 1, args->dotrace) && args->doexit)
     /* We cannot start the application.  Abort now.  */
     _exit (1);
 }
@@ -343,11 +317,11 @@ version_check_doit (void *a)
 static inline struct link_map *
 find_needed (const char *name)
 {
-  unsigned int n = _dl_loaded->l_searchlist.r_nlist;
+  unsigned int n = GL(dl_loaded)->l_searchlist.r_nlist;
 
   while (n-- > 0)
-    if (_dl_name_match_p (name, _dl_loaded->l_searchlist.r_list[n]))
-      return _dl_loaded->l_searchlist.r_list[n];
+    if (_dl_name_match_p (name, GL(dl_loaded)->l_searchlist.r_list[n]))
+      return GL(dl_loaded)->l_searchlist.r_list[n];
 
   /* Should never happen.  */
   return NULL;
@@ -438,7 +412,7 @@ dl_main (const ElfW(Phdr) *phdr,
       rtld_is_main = 1;
 
       /* Note the place where the dynamic linker actually came from.  */
-      _dl_rtld_map.l_name = _dl_argv[0];
+      GL(dl_rtld_map).l_name = _dl_argv[0];
 
       while (_dl_argc > 1)
 	if (! strcmp (_dl_argv[1], "--list"))
@@ -468,7 +442,7 @@ dl_main (const ElfW(Phdr) *phdr,
 	  }
 	else if (! strcmp (_dl_argv[1], "--inhibit-rpath") && _dl_argc > 2)
 	  {
-	    _dl_inhibit_rpath = _dl_argv[2];
+	    GL(dl_inhibit_rpath) = _dl_argv[2];
 
 	    _dl_skip_args += 2;
 	    _dl_argc -= 2;
@@ -534,25 +508,25 @@ of this helper program; chances are you did not intend to run this program.\n\
 	  HP_TIMING_DIFF (load_time, start, stop);
 	}
 
-      phdr = _dl_loaded->l_phdr;
-      phnum = _dl_loaded->l_phnum;
+      phdr = GL(dl_loaded)->l_phdr;
+      phnum = GL(dl_loaded)->l_phnum;
       /* We overwrite here a pointer to a malloc()ed string.  But since
 	 the malloc() implementation used at this point is the dummy
 	 implementations which has no real free() function it does not
 	 makes sense to free the old string first.  */
-      _dl_loaded->l_name = (char *) "";
-      *user_entry = _dl_loaded->l_entry;
+      GL(dl_loaded)->l_name = (char *) "";
+      *user_entry = GL(dl_loaded)->l_entry;
     }
   else
     {
       /* Create a link_map for the executable itself.
 	 This will be what dlopen on "" returns.  */
       _dl_new_object ((char *) "", "", lt_executable, NULL);
-      if (_dl_loaded == NULL)
+      if (GL(dl_loaded) == NULL)
 	_dl_fatal_printf ("cannot allocate memory for link map\n");
-      _dl_loaded->l_phdr = phdr;
-      _dl_loaded->l_phnum = phnum;
-      _dl_loaded->l_entry = *user_entry;
+      GL(dl_loaded)->l_phdr = phdr;
+      GL(dl_loaded)->l_phnum = phnum;
+      GL(dl_loaded)->l_entry = *user_entry;
 
       /* At this point we are in a bit of trouble.  We would have to
 	 fill in the values for l_dev and l_ino.  But in general we
@@ -573,11 +547,11 @@ of this helper program; chances are you did not intend to run this program.\n\
 	 information for the program.  */
     }
 
-  _dl_loaded->l_map_end = 0;
+  GL(dl_loaded)->l_map_end = 0;
   /* Perhaps the executable has no PT_LOAD header entries at all.  */
-  _dl_loaded->l_map_start = ~0;
+  GL(dl_loaded)->l_map_start = ~0;
   /* We opened the file, account for it.  */
-  ++_dl_loaded->l_opencount;
+  ++GL(dl_loaded)->l_opencount;
 
   /* Scan the program header table for the dynamic section.  */
   for (ph = phdr; ph < &phdr[phnum]; ++ph)
@@ -585,12 +559,12 @@ of this helper program; chances are you did not intend to run this program.\n\
       {
       case PT_PHDR:
 	/* Find out the load address.  */
-	_dl_loaded->l_addr = (ElfW(Addr)) phdr - ph->p_vaddr;
+	GL(dl_loaded)->l_addr = (ElfW(Addr)) phdr - ph->p_vaddr;
 	break;
       case PT_DYNAMIC:
 	/* This tells us where to find the dynamic section,
 	   which tells us everything we need to do.  */
-	_dl_loaded->l_ld = (void *) _dl_loaded->l_addr + ph->p_vaddr;
+	GL(dl_loaded)->l_ld = (void *) GL(dl_loaded)->l_addr + ph->p_vaddr;
 	break;
       case PT_INTERP:
 	/* This "interpreter segment" was used by the program loader to
@@ -599,17 +573,17 @@ of this helper program; chances are you did not intend to run this program.\n\
 	   dlopen call or DT_NEEDED entry, for something that wants to link
 	   against the dynamic linker as a shared library, will know that
 	   the shared object is already loaded.  */
-	_dl_rtld_libname.name = ((const char *) _dl_loaded->l_addr
+	_dl_rtld_libname.name = ((const char *) GL(dl_loaded)->l_addr
 				 + ph->p_vaddr);
 	/* _dl_rtld_libname.next = NULL;	Already zero.  */
-	_dl_rtld_map.l_libname = &_dl_rtld_libname;
+	GL(dl_rtld_map).l_libname = &_dl_rtld_libname;
 
 	/* Ordinarilly, we would get additional names for the loader from
 	   our DT_SONAME.  This can't happen if we were actually linked as
 	   a static executable (detect this case when we have no DYNAMIC).
 	   If so, assume the filename component of the interpreter path to
 	   be our SONAME, and add it to our name list.  */
-	if (_dl_rtld_map.l_ld == NULL)
+	if (GL(dl_rtld_map).l_ld == NULL)
 	  {
 	    char *p = strrchr (_dl_rtld_libname.name, '/');
 	    if (p)
@@ -628,37 +602,38 @@ of this helper program; chances are you did not intend to run this program.\n\
 	  ElfW(Addr) allocend;
 
 	  /* Remember where the main program starts in memory.  */
-	  mapstart = _dl_loaded->l_addr + (ph->p_vaddr & ~(ph->p_align - 1));
-	  if (_dl_loaded->l_map_start > mapstart)
-	    _dl_loaded->l_map_start = mapstart;
+	  mapstart = (GL(dl_loaded)->l_addr
+		      + (ph->p_vaddr & ~(ph->p_align - 1)));
+	  if (GL(dl_loaded)->l_map_start > mapstart)
+	    GL(dl_loaded)->l_map_start = mapstart;
 
 	  /* Also where it ends.  */
-	  allocend = _dl_loaded->l_addr + ph->p_vaddr + ph->p_memsz;
-	  if (_dl_loaded->l_map_end < allocend)
-	    _dl_loaded->l_map_end = allocend;
+	  allocend = GL(dl_loaded)->l_addr + ph->p_vaddr + ph->p_memsz;
+	  if (GL(dl_loaded)->l_map_end < allocend)
+	    GL(dl_loaded)->l_map_end = allocend;
 	}
 	break;
       }
-  if (! _dl_loaded->l_map_end)
-    _dl_loaded->l_map_end = ~0;
-  if (! _dl_rtld_map.l_libname && _dl_rtld_map.l_name)
+  if (! GL(dl_loaded)->l_map_end)
+    GL(dl_loaded)->l_map_end = ~0;
+  if (! GL(dl_rtld_map).l_libname && GL(dl_rtld_map).l_name)
     {
       /* We were invoked directly, so the program might not have a
 	 PT_INTERP.  */
-      _dl_rtld_libname.name = _dl_rtld_map.l_name;
+      _dl_rtld_libname.name = GL(dl_rtld_map).l_name;
       /* _dl_rtld_libname.next = NULL; 	Alread zero.  */
-      _dl_rtld_map.l_libname =  &_dl_rtld_libname;
+      GL(dl_rtld_map).l_libname =  &_dl_rtld_libname;
     }
   else
-    assert (_dl_rtld_map.l_libname); /* How else did we get here?  */
+    assert (GL(dl_rtld_map).l_libname); /* How else did we get here?  */
 
   if (! rtld_is_main)
     {
       /* Extract the contents of the dynamic section for easy access.  */
-      elf_get_dynamic_info (_dl_loaded);
-      if (_dl_loaded->l_info[DT_HASH])
+      elf_get_dynamic_info (GL(dl_loaded));
+      if (GL(dl_loaded)->l_info[DT_HASH])
 	/* Set up our cache of pointers into the hash table.  */
-	_dl_setup_hash (_dl_loaded);
+	_dl_setup_hash (GL(dl_loaded));
     }
 
   if (__builtin_expect (mode, normal) == verify)
@@ -667,7 +642,7 @@ of this helper program; chances are you did not intend to run this program.\n\
 	 executable using us as the program interpreter.  Exit with an
 	 error if we were not able to load the binary or no interpreter
 	 is specified (i.e., this is no dynamically linked binary.  */
-      if (_dl_loaded->l_ld == NULL)
+      if (GL(dl_loaded)->l_ld == NULL)
 	_exit (1);
 
       /* We allow here some platform specific code.  */
@@ -684,15 +659,15 @@ of this helper program; chances are you did not intend to run this program.\n\
 
   /* Put the link_map for ourselves on the chain so it can be found by
      name.  Note that at this point the global chain of link maps contains
-     exactly one element, which is pointed to by _dl_loaded.  */
-  if (! _dl_rtld_map.l_name)
+     exactly one element, which is pointed to by dl_loaded.  */
+  if (! GL(dl_rtld_map).l_name)
     /* If not invoked directly, the dynamic linker shared object file was
        found by the PT_INTERP name.  */
-    _dl_rtld_map.l_name = (char *) _dl_rtld_map.l_libname->name;
-  _dl_rtld_map.l_type = lt_library;
-  _dl_loaded->l_next = &_dl_rtld_map;
-  _dl_rtld_map.l_prev = _dl_loaded;
-  ++_dl_nloaded;
+    GL(dl_rtld_map).l_name = (char *) GL(dl_rtld_map).l_libname->name;
+  GL(dl_rtld_map).l_type = lt_library;
+  GL(dl_loaded)->l_next = &GL(dl_rtld_map);
+  GL(dl_rtld_map).l_prev = GL(dl_loaded);
+  ++GL(dl_nloaded);
 
   /* We have two ways to specify objects to preload: via environment
      variable and via the file /etc/ld.so.preload.  The latter can also
@@ -717,7 +692,7 @@ of this helper program; chances are you did not intend to run this program.\n\
 	    && (__builtin_expect (! __libc_enable_secure, 1)
 		|| strchr (p, '/') == NULL))
 	  {
-	    struct link_map *new_map = _dl_map_object (_dl_loaded, p, 1,
+	    struct link_map *new_map = _dl_map_object (GL(dl_loaded), p, 1,
 						       lt_library, 0, 0);
 	    if (++new_map->l_opencount == 1)
 	      /* It is no duplicate.  */
@@ -785,7 +760,7 @@ of this helper program; chances are you did not intend to run this program.\n\
 	  while ((p = strsep (&runp, ": \t\n")) != NULL)
 	    if (p[0] != '\0')
 	      {
-		struct link_map *new_map = _dl_map_object (_dl_loaded, p, 1,
+		struct link_map *new_map = _dl_map_object (GL(dl_loaded), p, 1,
 							   lt_library, 0, 0);
 		if (++new_map->l_opencount == 1)
 		  /* It is no duplicate.  */
@@ -796,7 +771,7 @@ of this helper program; chances are you did not intend to run this program.\n\
       if (problem != NULL)
 	{
 	  char *p = strndupa (problem, file_size - (problem - file));
-	  struct link_map *new_map = _dl_map_object (_dl_loaded, p, 1,
+	  struct link_map *new_map = _dl_map_object (GL(dl_loaded), p, 1,
 						     lt_library, 0, 0);
 	  if (++new_map->l_opencount == 1)
 	    /* It is no duplicate.  */
@@ -816,7 +791,7 @@ of this helper program; chances are you did not intend to run this program.\n\
       /* Set up PRELOADS with a vector of the preloaded libraries.  */
       struct link_map *l;
       preloads = __alloca (npreloads * sizeof preloads[0]);
-      l = _dl_rtld_map.l_next; /* End of the chain before preloads.  */
+      l = GL(dl_rtld_map).l_next; /* End of the chain before preloads.  */
       i = 0;
       do
 	{
@@ -830,18 +805,18 @@ of this helper program; chances are you did not intend to run this program.\n\
      specified some libraries to load, these are inserted before the actual
      dependencies in the executable's searchlist for symbol resolution.  */
   HP_TIMING_NOW (start);
-  _dl_map_object_deps (_dl_loaded, preloads, npreloads, mode == trace);
+  _dl_map_object_deps (GL(dl_loaded), preloads, npreloads, mode == trace);
   HP_TIMING_NOW (stop);
   HP_TIMING_DIFF (diff, start, stop);
   HP_TIMING_ACCUM_NT (load_time, diff);
 
   /* Mark all objects as being in the global scope and set the open
      counter.  */
-  for (i = _dl_loaded->l_searchlist.r_nlist; i > 0; )
+  for (i = GL(dl_loaded)->l_searchlist.r_nlist; i > 0; )
     {
       --i;
-      _dl_loaded->l_searchlist.r_list[i]->l_global = 1;
-      ++_dl_loaded->l_searchlist.r_list[i]->l_opencount;
+      GL(dl_loaded)->l_searchlist.r_list[i]->l_global = 1;
+      ++GL(dl_loaded)->l_searchlist.r_list[i]->l_opencount;
     }
 
 #ifndef MAP_ANON
@@ -851,38 +826,38 @@ of this helper program; chances are you did not intend to run this program.\n\
 #endif
 
   /* Remove _dl_rtld_map from the chain.  */
-  _dl_rtld_map.l_prev->l_next = _dl_rtld_map.l_next;
-  if (_dl_rtld_map.l_next)
-    _dl_rtld_map.l_next->l_prev = _dl_rtld_map.l_prev;
+  GL(dl_rtld_map).l_prev->l_next = GL(dl_rtld_map).l_next;
+  if (GL(dl_rtld_map).l_next)
+    GL(dl_rtld_map).l_next->l_prev = GL(dl_rtld_map).l_prev;
 
-  if (__builtin_expect (_dl_rtld_map.l_opencount > 1, 1))
+  if (__builtin_expect (GL(dl_rtld_map).l_opencount > 1, 1))
     {
       /* Some DT_NEEDED entry referred to the interpreter object itself, so
 	 put it back in the list of visible objects.  We insert it into the
 	 chain in symbol search order because gdb uses the chain's order as
 	 its symbol search order.  */
       i = 1;
-      while (_dl_loaded->l_searchlist.r_list[i] != &_dl_rtld_map)
+      while (GL(dl_loaded)->l_searchlist.r_list[i] != &GL(dl_rtld_map))
 	++i;
-      _dl_rtld_map.l_prev = _dl_loaded->l_searchlist.r_list[i - 1];
+      GL(dl_rtld_map).l_prev = GL(dl_loaded)->l_searchlist.r_list[i - 1];
       if (__builtin_expect (mode, normal) == normal)
-	_dl_rtld_map.l_next = (i + 1 < _dl_loaded->l_searchlist.r_nlist
-			       ? _dl_loaded->l_searchlist.r_list[i + 1]
-			       : NULL);
+	GL(dl_rtld_map).l_next = (i + 1 < GL(dl_loaded)->l_searchlist.r_nlist
+				  ? GL(dl_loaded)->l_searchlist.r_list[i + 1]
+				  : NULL);
       else
 	/* In trace mode there might be an invisible object (which we
 	   could not find) after the previous one in the search list.
 	   In this case it doesn't matter much where we put the
 	   interpreter object, so we just initialize the list pointer so
 	   that the assertion below holds.  */
-	_dl_rtld_map.l_next = _dl_rtld_map.l_prev->l_next;
+	GL(dl_rtld_map).l_next = GL(dl_rtld_map).l_prev->l_next;
 
-      assert (_dl_rtld_map.l_prev->l_next == _dl_rtld_map.l_next);
-      _dl_rtld_map.l_prev->l_next = &_dl_rtld_map;
-      if (_dl_rtld_map.l_next)
+      assert (GL(dl_rtld_map).l_prev->l_next == GL(dl_rtld_map).l_next);
+      GL(dl_rtld_map).l_prev->l_next = &GL(dl_rtld_map);
+      if (GL(dl_rtld_map).l_next)
 	{
-	  assert (_dl_rtld_map.l_next->l_prev == _dl_rtld_map.l_prev);
-	  _dl_rtld_map.l_next->l_prev = &_dl_rtld_map;
+	  assert (GL(dl_rtld_map).l_next->l_prev == GL(dl_rtld_map).l_prev);
+	  GL(dl_rtld_map).l_next->l_prev = &GL(dl_rtld_map);
 	}
     }
 
@@ -901,15 +876,15 @@ of this helper program; chances are you did not intend to run this program.\n\
 	 important that we do this before real relocation, because the
 	 functions we call below for output may no longer work properly
 	 after relocation.  */
-      if (! _dl_loaded->l_info[DT_NEEDED])
+      if (! GL(dl_loaded)->l_info[DT_NEEDED])
 	_dl_printf ("\tstatically linked\n");
       else
 	{
 	  struct link_map *l;
 
-	  if (_dl_debug_mask & DL_DEBUG_PRELINK)
+	  if (GL(dl_debug_mask) & DL_DEBUG_PRELINK)
 	    {
-	      struct r_scope_elem *scope = &_dl_loaded->l_searchlist;
+	      struct r_scope_elem *scope = &GL(dl_loaded)->l_searchlist;
 
 	      for (i = 0; i < scope->r_nlist; i++)
 		{
@@ -919,8 +894,8 @@ of this helper program; chances are you did not intend to run this program.\n\
 		      _dl_printf ("\t%s => not found\n", l->l_libname->name);
 		      continue;
 		    }
-		  if (_dl_name_match_p (_dl_trace_prelink, l))
-		    _dl_trace_prelink_map = l;
+		  if (_dl_name_match_p (GL(dl_trace_prelink), l))
+		    GL(dl_trace_prelink_map) = l;
 		  _dl_printf ("\t%s => %s (0x%0*Zx, 0x%0*Zx)\n",
 			      l->l_libname->name[0] ? l->l_libname->name
 			      : _dl_argv[0] ?: "<main program>",
@@ -934,7 +909,7 @@ of this helper program; chances are you did not intend to run this program.\n\
 	    }
 	  else
 	    {
-	      for (l = _dl_loaded->l_next; l; l = l->l_next)
+	      for (l = GL(dl_loaded)->l_next; l; l = l->l_next)
 		if (l->l_faked)
 		  /* The library was not found.  */
 		  _dl_printf ("\t%s => not found\n", l->l_libname->name);
@@ -952,8 +927,8 @@ of this helper program; chances are you did not intend to run this program.\n\
 	    ElfW(Addr) loadbase;
 	    lookup_t result;
 
-	    result = _dl_lookup_symbol (_dl_argv[i], _dl_loaded,
-					&ref, _dl_loaded->l_scope,
+	    result = _dl_lookup_symbol (_dl_argv[i], GL(dl_loaded),
+					&ref, GL(dl_loaded)->l_scope,
 					ELF_RTYPE_CLASS_PLT, 1);
 
 	    loadbase = LOOKUP_VALUE_ADDRESS (result);
@@ -966,7 +941,7 @@ of this helper program; chances are you did not intend to run this program.\n\
       else
 	{
 	  /* If LD_WARN is set warn about undefined symbols.  */
-	  if (_dl_lazy >= 0 && _dl_verbose)
+	  if (_dl_lazy >= 0 && GL(dl_verbose))
 	    {
 	      /* We have to do symbol dependency testing.  */
 	      struct relocate_args args;
@@ -974,12 +949,12 @@ of this helper program; chances are you did not intend to run this program.\n\
 
 	      args.lazy = _dl_lazy;
 
-	      l = _dl_loaded;
+	      l = GL(dl_loaded);
 	      while (l->l_next)
 		l = l->l_next;
 	      do
 		{
-		  if (l != &_dl_rtld_map && ! l->l_faked)
+		  if (l != &GL(dl_rtld_map) && ! l->l_faked)
 		    {
 		      args.l = l;
 		      _dl_receive_error (print_unresolved, relocate_doit,
@@ -988,9 +963,10 @@ of this helper program; chances are you did not intend to run this program.\n\
 		  l = l->l_prev;
 		} while (l);
 
-	      if ((_dl_debug_mask & DL_DEBUG_PRELINK)
-		  && _dl_rtld_map.l_opencount > 1)
-		_dl_relocate_object (&_dl_rtld_map, _dl_loaded->l_scope, 0, 0);
+	      if ((GL(dl_debug_mask) & DL_DEBUG_PRELINK)
+		  && GL(dl_rtld_map).l_opencount > 1)
+		_dl_relocate_object (&GL(dl_rtld_map), GL(dl_loaded)->l_scope,
+				     0, 0);
 	    }
 
 #define VERNEEDTAG (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (DT_VERNEED))
@@ -999,9 +975,9 @@ of this helper program; chances are you did not intend to run this program.\n\
 	      /* Print more information.  This means here, print information
 		 about the versions needed.  */
 	      int first = 1;
-	      struct link_map *map = _dl_loaded;
+	      struct link_map *map = GL(dl_loaded);
 
-	      for (map = _dl_loaded; map != NULL; map = map->l_next)
+	      for (map = GL(dl_loaded); map != NULL; map = map->l_next)
 		{
 		  const char *strtab;
 		  ElfW(Dyn) *dyn = map->l_info[VERNEEDTAG];
@@ -1069,28 +1045,28 @@ of this helper program; chances are you did not intend to run this program.\n\
       _exit (0);
     }
 
-  if (_dl_loaded->l_info [ADDRIDX (DT_GNU_LIBLIST)]
-      && ! __builtin_expect (_dl_profile != NULL, 0))
+  if (GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_LIBLIST)]
+      && ! __builtin_expect (GL(dl_profile) != NULL, 0))
     {
       ElfW(Lib) *liblist, *liblistend;
       struct link_map **r_list, **r_listend, *l;
       const char *strtab = (const void *)
-			   D_PTR (_dl_loaded, l_info[DT_STRTAB]);
+			   D_PTR (GL(dl_loaded), l_info[DT_STRTAB]);
 
-      assert (_dl_loaded->l_info [VALIDX (DT_GNU_LIBLISTSZ)] != NULL);
+      assert (GL(dl_loaded)->l_info [VALIDX (DT_GNU_LIBLISTSZ)] != NULL);
       liblist = (ElfW(Lib) *)
-		_dl_loaded->l_info [ADDRIDX (DT_GNU_LIBLIST)]->d_un.d_ptr;
+		GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_LIBLIST)]->d_un.d_ptr;
       liblistend = (ElfW(Lib) *)
 		   ((char *) liblist
-		    + _dl_loaded->l_info [VALIDX (DT_GNU_LIBLISTSZ)]->d_un.d_val);
-      r_list = _dl_loaded->l_searchlist.r_list;
-      r_listend = r_list + _dl_loaded->l_searchlist.r_nlist;
+		    + GL(dl_loaded)->l_info [VALIDX (DT_GNU_LIBLISTSZ)]->d_un.d_val);
+      r_list = GL(dl_loaded)->l_searchlist.r_list;
+      r_listend = r_list + GL(dl_loaded)->l_searchlist.r_nlist;
 
       for (; r_list < r_listend && liblist < liblistend; r_list++)
 	{
 	  l = *r_list;
 
-	  if (l == _dl_loaded)
+	  if (l == GL(dl_loaded))
 	    continue;
 
 	  /* If the library is not mapped where it should, fail.  */
@@ -1118,13 +1094,13 @@ of this helper program; chances are you did not intend to run this program.\n\
       if (r_list == r_listend && liblist == liblistend)
 	prelinked = 1;
 
-      if (__builtin_expect (_dl_debug_mask & DL_DEBUG_LIBS, 0))
+      if (__builtin_expect (GL(dl_debug_mask) & DL_DEBUG_LIBS, 0))
 	_dl_printf ("\nprelink checking: %s\n", prelinked ? "ok" : "failed");
     }
 
   if (prelinked)
     {
-      if (_dl_loaded->l_info [ADDRIDX (DT_GNU_CONFLICT)] != NULL)
+      if (GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_CONFLICT)] != NULL)
 	{
 	  ElfW(Rela) *conflict, *conflictend;
 #ifndef HP_TIMING_NONAVAIL
@@ -1133,13 +1109,13 @@ of this helper program; chances are you did not intend to run this program.\n\
 #endif
 
 	  HP_TIMING_NOW (start);
-	  assert (_dl_loaded->l_info [VALIDX (DT_GNU_CONFLICTSZ)] != NULL);
+	  assert (GL(dl_loaded)->l_info [VALIDX (DT_GNU_CONFLICTSZ)] != NULL);
 	  conflict = (ElfW(Rela) *)
-		     _dl_loaded->l_info [ADDRIDX (DT_GNU_CONFLICT)]->d_un.d_ptr;
+		     GL(dl_loaded)->l_info [ADDRIDX (DT_GNU_CONFLICT)]->d_un.d_ptr;
 	  conflictend = (ElfW(Rela) *)
 			((char *) conflict
-			 + _dl_loaded->l_info [VALIDX (DT_GNU_CONFLICTSZ)]->d_un.d_val);
-	  _dl_resolve_conflicts (_dl_loaded, conflict, conflictend);
+			 + GL(dl_loaded)->l_info [VALIDX (DT_GNU_CONFLICTSZ)]->d_un.d_val);
+	  _dl_resolve_conflicts (GL(dl_loaded), conflict, conflictend);
 	  HP_TIMING_NOW (stop);
 	  HP_TIMING_DIFF (relocate_time, start, stop);
 	}
@@ -1158,7 +1134,7 @@ of this helper program; chances are you did not intend to run this program.\n\
        know that because it is self-contained).  */
 
     struct link_map *l;
-    int consider_profiling = _dl_profile != NULL;
+    int consider_profiling = GL(dl_profile) != NULL;
 #ifndef HP_TIMING_NONAVAIL
     hp_timing_t start;
     hp_timing_t stop;
@@ -1168,7 +1144,7 @@ of this helper program; chances are you did not intend to run this program.\n\
     /* If we are profiling we also must do lazy reloaction.  */
     _dl_lazy |= consider_profiling;
 
-    l = _dl_loaded;
+    l = GL(dl_loaded);
     while (l->l_next)
       l = l->l_next;
 
@@ -1186,7 +1162,7 @@ of this helper program; chances are you did not intend to run this program.\n\
 	    lnp = lnp->next;
 	  }
 
-	if (l != &_dl_rtld_map)
+	if (l != &GL(dl_rtld_map))
 	  _dl_relocate_object (l, l->l_scope, _dl_lazy, consider_profiling);
 
 	l = l->l_prev;
@@ -1207,16 +1183,16 @@ of this helper program; chances are you did not intend to run this program.\n\
        this has to go here because the calls it makes should use the
        rtld versions of the functions (particularly calloc()), but it
        needs to have _dl_profile_map set up by the relocator.  */
-    if (__builtin_expect (_dl_profile_map != NULL, 0))
+    if (__builtin_expect (GL(dl_profile_map) != NULL, 0))
       /* We must prepare the profiling.  */
-      _dl_start_profile (_dl_profile_map, _dl_profile_output);
+      _dl_start_profile (GL(dl_profile_map), GL(dl_profile_output));
 
-    if (_dl_rtld_map.l_opencount > 1)
+    if (GL(dl_rtld_map).l_opencount > 1)
       {
 	/* There was an explicit ref to the dynamic linker as a shared lib.
 	   Re-relocate ourselves with user-controlled symbol definitions.  */
 	HP_TIMING_NOW (start);
-	_dl_relocate_object (&_dl_rtld_map, _dl_loaded->l_scope, 0, 0);
+	_dl_relocate_object (&GL(dl_rtld_map), GL(dl_loaded)->l_scope, 0, 0);
 	HP_TIMING_NOW (stop);
 	HP_TIMING_DIFF (add, start, stop);
 	HP_TIMING_ACCUM_NT (relocate_time, add);
@@ -1224,26 +1200,26 @@ of this helper program; chances are you did not intend to run this program.\n\
   }
 
   /* Now set up the variable which helps the assembler startup code.  */
-  _dl_main_searchlist = &_dl_loaded->l_searchlist;
-  _dl_global_scope[0] = &_dl_loaded->l_searchlist;
+  GL(dl_main_searchlist) = &GL(dl_loaded)->l_searchlist;
+  GL(dl_global_scope)[0] = &GL(dl_loaded)->l_searchlist;
 
   /* Save the information about the original global scope list since
      we need it in the memory handling later.  */
-  _dl_initial_searchlist = *_dl_main_searchlist;
+  GL(dl_initial_searchlist) = *GL(dl_main_searchlist);
 
   {
     /* Initialize _r_debug.  */
-    struct r_debug *r = _dl_debug_initialize (_dl_rtld_map.l_addr);
+    struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr);
     struct link_map *l;
 
-    l = _dl_loaded;
+    l = GL(dl_loaded);
 
 #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 (&_dl_rtld_map, r);
+    ELF_MACHINE_DEBUG_SETUP (&GL(dl_rtld_map), r);
 
 #else
 
@@ -1254,8 +1230,8 @@ of this helper program; chances are you did not intend to run this program.\n\
 
     /* Fill in the pointer in the dynamic linker's own dynamic section, in
        case you run gdb on the dynamic linker directly.  */
-    if (_dl_rtld_map.l_info[DT_DEBUG])
-      _dl_rtld_map.l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
+    if (GL(dl_rtld_map).l_info[DT_DEBUG])
+      GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
 
 #endif
 
@@ -1350,7 +1326,7 @@ process_dl_debug (const char *dl_debug)
 	    if (strncmp (dl_debug, debopts[cnt].name, len) == 0
 		&& debopts[cnt].name[len] == '\0')
 	      {
-		_dl_debug_mask |= debopts[cnt].mask;
+		GL(dl_debug_mask) |= debopts[cnt].mask;
 		break;
 	      }
 
@@ -1367,7 +1343,7 @@ warning: debug option `%s' unknown; try LD_DEBUG=help\n", copy);
     }
   while (*(dl_debug += len) != '\0');
 
-  if (_dl_debug_mask & DL_DEBUG_HELP)
+  if (GL(dl_debug_mask) & DL_DEBUG_HELP)
     {
       size_t cnt;
 
@@ -1391,6 +1367,7 @@ a filename can be specified using the LD_DEBUG_OUTPUT environment variable.\n");
    all the entries.  */
 extern char **_environ;
 
+
 static void
 process_envvars (enum mode *modep)
 {
@@ -1400,7 +1377,8 @@ process_envvars (enum mode *modep)
   char *debug_output = NULL;
 
   /* This is the default place for profiling data file.  */
-  _dl_profile_output = &"/var/tmp\0/var/profile"[__libc_enable_secure ? 9 : 0];
+  GL(dl_profile_output) = &"/var/tmp\0/var/profile"[__libc_enable_secure
+						    ? 9 : 0];
 
   while ((envline = _dl_next_ld_env_entry (&runp)) != NULL)
     {
@@ -1417,7 +1395,7 @@ process_envvars (enum mode *modep)
 	case 4:
 	  /* Warning level, verbose or not.  */
 	  if (memcmp (envline, "WARN", 4) == 0)
-	    _dl_verbose = envline[5] != '\0';
+	    GL(dl_verbose) = envline[5] != '\0';
 	  break;
 
 	case 5:
@@ -1443,7 +1421,7 @@ process_envvars (enum mode *modep)
 
 	  /* Which shared object shall be profiled.  */
 	  if (memcmp (envline, "PROFILE", 7) == 0 && envline[8] != '\0')
-	    _dl_profile = &envline[8];
+	    GL(dl_profile) = &envline[8];
 	  break;
 
 	case 8:
@@ -1454,7 +1432,7 @@ process_envvars (enum mode *modep)
 	      break;
 	    }
 	  if (memcmp (envline, "BIND_NOT", 8) == 0)
-	    _dl_bind_not = envline[9] != '\0';
+	    GL(dl_bind_not) = envline[9] != '\0';
 	  break;
 
 	case 9:
@@ -1467,14 +1445,14 @@ process_envvars (enum mode *modep)
 	case 10:
 	  /* Mask for the important hardware capabilities.  */
 	  if (memcmp (envline, "HWCAP_MASK", 10) == 0)
-	    _dl_hwcap_mask = __strtoul_internal (&envline[11], NULL, 0, 0);
+	    GL(dl_hwcap_mask) = __strtoul_internal (&envline[11], NULL, 0, 0);
 	  break;
 
 	case 11:
 	  /* Path where the binary is found.  */
 	  if (!__libc_enable_secure
 	      && memcmp (envline, "ORIGIN_PATH", 11) == 0)
-	    _dl_origin_path = &envline[12];
+	    GL(dl_origin_path) = &envline[12];
 	  break;
 
 	case 12:
@@ -1501,7 +1479,7 @@ process_envvars (enum mode *modep)
 	  if (!__libc_enable_secure
 	      && memcmp (envline, "PROFILE_OUTPUT", 14) == 0
 	      && envline[15] != '\0')
-	    _dl_profile_output = &envline[15];
+	    GL(dl_profile_output) = &envline[15];
 	  break;
 
 	case 16:
@@ -1509,9 +1487,9 @@ process_envvars (enum mode *modep)
 	  if (memcmp (envline, "TRACE_PRELINKING", 16) == 0)
 	    {
 	      mode = trace;
-	      _dl_verbose = 1;
-	      _dl_debug_mask |= DL_DEBUG_PRELINK;
-	      _dl_trace_prelink = &envline[17];
+	      GL(dl_verbose) = 1;
+	      GL(dl_debug_mask) |= DL_DEBUG_PRELINK;
+	      GL(dl_trace_prelink) = &envline[17];
 	    }
 	  break;
 
@@ -1624,9 +1602,9 @@ print_statistics (void)
     }
 #endif
   _dl_debug_printf ("                 number of relocations: %lu\n",
-		    _dl_num_relocations);
+		    GL(dl_num_relocations));
   _dl_debug_printf ("      number of relocations from cache: %lu\n",
-		    _dl_num_cache_relocations);
+		    GL(dl_num_cache_relocations));
 
 #ifndef HP_TIMING_NONAVAIL
   /* Time spend while loading the object and the dependencies.  */