libtool
[Top][All Lists]
Advanced

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

Re: dlopening the C runtime library


From: Sam Varshavchik
Subject: Re: dlopening the C runtime library
Date: Sun, 06 Dec 2009 10:03:24 -0500

Ralf Wildenhues writes:

* Sam Varshavchik wrote on Sun, Dec 06, 2009 at 02:52:52PM CET:

My use case is intercepting a main application's calls to library
functions. I set LD_PRELOAD to preload my own shared library which
provides replacement symbols for socket(), connect(), etc…

What level of portability do you need?  GNU/Linux only?  ELF?

Additional portability is always a plus. ELF portability would certainly be nice.

My wrapper needs to find the real socket() and connect(). I haven't
checked this yet, but I suspect that since my shared library was
loaded ahead of libc, after lt_dlopen(NULL), using lt_dlsym() will
simply return a pointer to my own symbols, rather than libc's.

Yes, that sounds like it, although I must admit that I haven't fully
understood the above description.  Uses of -Bsymbolic may give you
trouble.

You want to intercept an application's calls to a selected set of the standard library's function, such as open() and close(). The classical way is to put together a shared library, and use LD_PRELOAD to force the application to resolve its external references to your own replacements, instead of the standard library's. But then, you still need to invoke the default open() and close(), from the standard library.

With a platform-specific solution, you know the exact name of the standard library, which you can dlopen yourself and invoke the real open() and close(), as part of intercepting the application's function calls. I'm trying to figure out something that would have some portability to it.

As I said, I can have a prepared list of library names where standard library functions may be found, such as "libc", "c", "libnsl", and just dlopen each one until I find the real open() and close(). Or, I can probe these names in my configure script, and find the exact library name.

The problem is that on ELF, linking against "libc" grabs the SONAME from the ELF object, and that's what you end up loading at runtime. So, even though on a development server dlopen of "libc" works, it won't work on a runtime-only server.


Attachment: pgpPdCLOsN9Jg.pgp
Description: PGP signature


reply via email to

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