dlopen + dlsym
From: William Ahern (william_at_wilbur.25thandClement.com)
Date: 07/30/04
- Previous message: Materialised: "Re: GTK Audible Alert"
- Next in thread: Ulrich Eckhardt: "Re: dlopen + dlsym"
- Reply: Ulrich Eckhardt: "Re: dlopen + dlsym"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Jul 2004 15:34:49 -0700
Problem:
Load a library using dlopen(3) which provides an alternative malloc(3) (and
eventually connect(2) and other calls).
Solution:
At first I thought that after loading the library w/ dlopen(3) everything
would just magically work; libdl would sequentially interpose each and every
malloc() symbol found.
Not so.
So, I accepted that I would have to provide my own malloc(3) *within* the
main binary, which itself would call dlsym(RTLD_NEXT,"malloc"). I had hoped
not, because I didn't want to have to predetermine all the library calls a
loadable module could interpose, but w'ever.
However, this doesn't work, either! The only way I can get such libary
iterposition to work is to 1) LD_PRELOAD the modules or 2) manually pull out
the symbol using dlsym(my_module_handle,"malloc").
The problem w/ LD_PRELOAD is that I want to load modules according to
directives in a configuration file. The problem w/ manually pulling out the
symbols from each dlopen handle using dlsym is that I don't know what the
interposition ordering is, so that when the module uses
dlsym(RTLD_NEXT,"malloc") itself if may or may not get a symbol to the
malloc definition in the next module, or from libc itself.
Any ideas on what I'm doing wrong, or if this is possible at all?
I'm using a recent glibc (trying this on Mandrake 9.1 and Debian/Testing).
TIA,
Bill
- Previous message: Materialised: "Re: GTK Audible Alert"
- Next in thread: Ulrich Eckhardt: "Re: dlopen + dlsym"
- Reply: Ulrich Eckhardt: "Re: dlopen + dlsym"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]