bug-libtool
[Top][All Lists]
Advanced

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

Re: lt_dlopenadvise stops on encountering a non-library


From: Anton Ertl
Subject: Re: lt_dlopenadvise stops on encountering a non-library
Date: Sat, 3 May 2008 11:04:21 +0200 (CEST)

Gary V. Vaughan wrote:
> Thanks for chasing this.  Again, I'm not sure why you would need to
> dlopen libc, since it is already loaded by the linker when an  
> application
> comes up, but anyway...

1) I need a handle for lt_dlsym.

2) If this problem exists for libc, maybe it exists for other
libraries, too.  On my platform (Linux-AMD64) I see:

[c8:/usr/lib:15833] file *.so|grep ASCII
libc.so:                                   ASCII C program text
libfl.so:                                  ASCII C program text
libpthread.so:                             ASCII C program text

Inspecting these files reveals that they are all linker scripts.

> > BTW, if the ...ext() feature only works for ".la" files, that's very
> > little functionality.  I guess that an ...ext() feature that's
> > unreliable for non-.la files can still be useful for some
> > applications.
> 
> lt_dlopenext is supposed to first try the name as passed in the search
> path, and then try both .la and the host suffix (".so" in your case).   
> It
> certainly isn't tied to .la files... unless you have uncovered a bug  
> here.

Here's what I see with the program below (which uses
lt_dladvise_ext()):

[c8:~/tmp:15843] strace -e trace=file a.out /lib/libc.so.6
execve("./a.out", ["a.out", "/lib/libc.so.6"], [/* 31 vars */]) = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libltdl.so.7", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libdl.so.2", O_RDONLY)       = 3
open("/lib/libc.so.6.la", O_RDONLY)     = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6.so", O_RDONLY)     = -1 ENOENT (No such file or directory)
my_dlopenext: file not found
Process 4701 detached

So it indeed opens the right file first (I missed that the last time I
looked), but then tries the other variants and eventually fails.

After commenting out the lt_dladvise_ext(), I get:

[c8:~/tmp:15848] strace -e trace=file a.out /lib/libc.so.6
execve("./a.out", ["a.out", "/lib/libc.so.6"], [/* 31 vars */]) = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libltdl.so.7", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libdl.so.2", O_RDONLY)       = 3
0x501250
Process 4733 detached

So here it succeeds.  Strange.

> > For (the main usage in) my application I found a completely different
> > solution: I build some files with wrapper functions for calling these
> > libraries anyway.  Now, instead of dlopening the libraries explicitly,
> > I just make them dependent libraries of my wrapper libraries by
> > passing "-l<lib>" parts to the "libtool -mode=link" invocations that
> > build the wrapper libraries.  I hope that that's portable.
> 
> 
> It's certainly a lot more portable than dlopen("/lib/libc.so.6")! :-)

Good.  Still, are there any caveats?

- anton

Just for completeness, here's the program again:

#include <ltdl.h>
#include <stdio.h>

lt_dlhandle
my_dlopenext (const char *filename)
{
  lt_dlhandle handle = 0;
  lt_dladvise advise;

  if (lt_dladvise_init (&advise)) {
    fprintf(stderr,"lt_dladvise_init: %s\n",lt_dlerror());
    exit(1);
  }

  if (lt_dladvise_ext (&advise)) {
     fprintf(stderr,"lt_dladvise_ext: %s\n",lt_dlerror());
    exit(1);
  }

  handle = lt_dlopenadvise (filename, advise);

  lt_dladvise_destroy (&advise);

  return handle;
}

int main(int argc, char *argv[])
{
  if (lt_dlinit()!=0) {
    fprintf(stderr,"lt_dlinit: %s\n",lt_dlerror());
    exit(1);
  }
  lt_dlhandle x = my_dlopenext(argv[1]);
  if (x == NULL) {
    fprintf(stderr,"my_dlopenext: %s\n",lt_dlerror());
    exit(1);
  }
  printf("%p\n",x);
  return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]