[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [issues] dlopen(0, LD_DLGLOBAL|RTLD_LAZY) hangs forever in statically linked app



On 3/19/10 6:10 PM, Bernhard Rosenkraenzer wrote:
Hi,
with current eglibc trunk on x86_64 linux, the dlopen(0,
LD_DLGLOBAL|RTLD_LAZY) call [used by binutils' configure script to check
whether a statically linked application can dlopen itself] hangs forever,
eating up 100% CPU.

The attached sample program, when built with

gcc -static -o conftest conftest.c -ldl

shows the issue.

Bernhard,

This is long shot, but would you please try the attached patch by Maciej Rozycki.

Thank you,

--
Maxim Kuvyrkov
CodeSourcery
maxim@xxxxxxxxxxxxxxxx
(650) 331-3385 x724
Index: libc/elf/dl-open.c
===================================================================
--- libc/elf/dl-open.c	(revision 275057)
+++ libc/elf/dl-open.c	(revision 275058)
@@ -96,11 +96,22 @@
      anymore.  Instead the malloc() implementation of the libc is
      used.  But this means the block from the main map cannot be used
      in an realloc() call.  Therefore we allocate a completely new
-     array the first time we have to add something to the locale scope.  */
+     array the first time we have to add something to the locale scope.
 
+     Also the list may be missing altogether if we are called via
+     dlopen() from a statically linked executable as in this case ld.so
+     has not been called and no dynamic symbols have been pulled yet.
+     Start a new list in this case.  */
+
   struct link_namespaces *ns = &GL(dl_ns)[new->l_ns];
   if (ns->_ns_global_scope_alloc == 0)
     {
+      /* See if we've got a list at all.  */
+      if (ns->_ns_main_searchlist == NULL)
+	ns->_ns_main_searchlist = calloc (1, sizeof (struct r_scope_elem));
+      if (ns->_ns_main_searchlist == NULL)
+	goto nomem;
+
       /* This is the first dynamic object given global scope.  */
       ns->_ns_global_scope_alloc
 	= ns->_ns_main_searchlist->r_nlist + to_add + 8;