about summary refs log tree commit diff
path: root/elf/dl-open.c
diff options
context:
space:
mode:
Diffstat (limited to 'elf/dl-open.c')
-rw-r--r--elf/dl-open.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 9dda31e761..40b5224725 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -22,6 +22,11 @@ Cambridge, MA 02139, USA.  */
 #include <stdlib.h>
 #include <errno.h>
 
+
+extern void _dl_start (void); weak_extern (_dl_start)
+
+extern int __libc_multiple_libcs;	/* Defined in init-first.c.  */
+
 size_t _dl_global_scope_alloc;
 
 struct link_map *
@@ -30,7 +35,9 @@ _dl_open (const char *file, int mode)
   struct link_map *new, *l;
   ElfW(Addr) init;
   struct r_debug *r;
-
+  /* To decide whether we are the static libc or not.  We must use
+     this variable since gcc would otherwise optimize the test away.  */
+  void (*dl_start_ptr) (void) = &_dl_start;
 
   /* Load the named object.  */
   new = _dl_map_object (NULL, file, lt_loaded);
@@ -131,5 +138,11 @@ _dl_open (const char *file, int mode)
   while (init = _dl_init_next (new))
     (*(void (*) (void)) init) ();
 
+  if (dl_start_ptr == NULL)
+    /* We must be the static _dl_open in libc.a because ld.so.1 is not
+       in scope.  A static program that has loaded a dynamic object
+       now has competition.  */
+    __libc_multiple_libcs = 1;
+
   return new;
 }