about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-load.c2
-rw-r--r--elf/dlsym.c18
2 files changed, 16 insertions, 4 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index f01bdad525..c19ebe722e 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -70,7 +70,7 @@ struct link_map *
 _dl_map_object_from_fd (const char *name, int fd, char *realname,
 			struct link_map *loader, int l_type)
 {
-  struct link_map *l;
+  struct link_map *l = NULL;
   void *file_mapping = NULL;
   size_t mapping_size = 0;
 
diff --git a/elf/dlsym.c b/elf/dlsym.c
index 7677f2741f..256eba800e 100644
--- a/elf/dlsym.c
+++ b/elf/dlsym.c
@@ -26,13 +26,25 @@ Cambridge, MA 02139, USA.  */
 void *
 dlsym (void *handle, const char *name)
 {
-  struct link_map *map = handle;
   ElfW(Addr) loadbase;
   const ElfW(Sym) *ref = NULL;
   void doit (void)
     {
-      struct link_map *scope[2] = { map, NULL };
-      loadbase = _dl_lookup_symbol (name, &ref, scope, map->l_name, 0, 0);
+      struct link_map *map = handle, **scope, *mapscope[2] = { map, NULL };
+      const char *owner;
+
+      if (map)
+	{
+	  /* Search the scope of the given object.  */
+	  scope = mapscope;
+	  owner = map->l_name;
+	}
+      else
+	{
+	  scope = &(_dl_global_scope ?: _dl_default_scope)[2];
+	  owner = NULL;
+	}
+      loadbase = _dl_lookup_symbol (name, &ref, scope, owner, 0, 0);
     }
 
   return _dlerror_run (doit) ? NULL : (void *) (loadbase + ref->st_value);