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

dlopen(0, LD_DLGLOBAL|RTLD_LAZY) hangs forever in statically linked app



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.

ttyl
bero
#include <dlfcn.h>

#include <stdio.h>

#ifdef RTLD_GLOBAL
#  define LT_DLGLOBAL		RTLD_GLOBAL
#else
#  ifdef DL_GLOBAL
#    define LT_DLGLOBAL		DL_GLOBAL
#  else
#    define LT_DLGLOBAL		0
#  endif
#endif

/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
   find out it does not work in some platform. */
#ifndef LT_DLLAZY_OR_NOW
#  ifdef RTLD_LAZY
#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
#  else
#    ifdef DL_LAZY
#      define LT_DLLAZY_OR_NOW		DL_LAZY
#    else
#      ifdef RTLD_NOW
#        define LT_DLLAZY_OR_NOW	RTLD_NOW
#      else
#        ifdef DL_NOW
#          define LT_DLLAZY_OR_NOW	DL_NOW
#        else
#          define LT_DLLAZY_OR_NOW	0
#        endif
#      endif
#    endif
#  endif
#endif

/* When -fvisbility=hidden is used, assume the code has been annotated
   correspondingly for the symbols needed.  */
#if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
void fnord () __attribute__((visibility("default")));
#endif

void fnord () { int i=42; }
int main ()
{
  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
  int status = 0;

  if (self)
    {
      if (dlsym (self,"fnord"))       status = 1;
      else
        {
	  if (dlsym( self,"_fnord"))  status = 2;
          else puts (dlerror ());
	}
      /* dlclose (self); */
    }
  else
    puts (dlerror ());

  return status;
}