This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

dlopen/dlclose problems


Hello,

I have a dlopen/dlclose problem with the attached programs. The first line is a command line for building the test-library and
the test-program.

The problem description:
When having a static variable in a template function it seems to be impossible to dlclose the library again (tested with
glibc-2.12.1). Can anyone else confirm this behaviour?

How to reproduce:
Build the test library with 'g++ -shared -fPIC -O0 -o libtest.so libtest.cpp' (I think for 32-bit you do not need -fPIC)
Build the test program with 'g++ -ldl -o test_dlopen test_dlopen.cpp'
Run the test program (as argument the library path which should be dlopened can be given). Watch which libraries are mappend for
the process before dlopen, after dlopen and after dlclose. I expect that after dlclose the library is not loaded anymore, however
it still is.

Is this a bug or intended behaviour (if it is intended can you tell me why?)

Regards
Andreas
// g++ -shared -fPIC -O0 -o libtest.so libtest.cpp

template<class T>
void test()
{
  static const int N[1] = {0};
  int i=N[0];
}

void blubbels()
{
  test<short>();
}
// g++ -ldl -o test_dlopen test_dlopen.cpp && ./test_dlopen /path/to/libtest.so

#include <dlfcn.h>
#include <iostream>
#include <link.h>

int cb(struct dl_phdr_info* info, size_t size, void* data)
{
  std::cout << info->dlpi_name << std::endl;
  return 0;
}


int main(int argc, char** argv)
{
  const char* default_path = "./libtest.so";
  const char* path = default_path;
  if (argc >= 2) {
    path = argv[1];
  }

  std::cout << "Loaded libraries before dynamic loading:" << std::endl;
  dl_iterate_phdr(cb, 0);
  
  void* h = dlopen(path, RTLD_NOW);
  std::cout << "Handle: " << h << std::endl;
  std::cout << "Loaded libraries after dynamic loading:" << std::endl;
  dl_iterate_phdr(cb, 0);
  
  std::cout << "dlclose return: " << dlclose(h) << std::endl;
  std::cout << "Loaded libraries after closing handle:" << std::endl;
  dl_iterate_phdr(cb, 0);

  return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]