This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: problem w/plugin libraries and incorrect memory addresses
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Mantra Wind River Thrum <mwgthrum at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Wed, 21 Jan 2009 21:52:50 -0800
- Subject: Re: problem w/plugin libraries and incorrect memory addresses
- References: <456a106a0901211951o3d3d169eh695ae3861039662b@mail.gmail.com>
On Wed, Jan 21, 2009 at 7:51 PM, Mantra Wind River Thrum
<mwgthrum@gmail.com> wrote:
> Dear binutils experts,
>
> I'd be forever grateful for the solution to the following problem:
>
> I have a program which links to many libraries (Qt, lapack, atlas, and
> many more) and also loads plugin libraries via dlopen().
>
>
> The plugin consists of only these functions:
>
> void controller()
> {
> cout << "got here" << endl;
> }
>
> void init(Object* x)
> {
> void (**fn)() = &x->fn;
> *fn = controller;
> // these two statements equivalent to x->fn = controller and are
> used to illustrate the problem
> }
>
>
> The program that loads the plugin (highly simplified and modified for
> brevity):
>
> int main()
> {
> Object o;
> typedef void (*init_t)();
>
> // load init function
> void* handle = dlopen("plugin.so", DTLD_NOW);
> assert(handle);
> init_t init = (init_t) dlsym(handle, "init");
> const char *dlsym_error = dlerror();
> assert(!dlsym_error);
> (*init)(&o);
>
> // run controller
> if (o.controller)
> (*o.controller)();
> else
> cout << "no controller!" << endl;
> }
>
> Running this program yields the output "no controller!"
>
> Debugging with gdb reveals that the statement void (**fn) = &x->fn
> uses the wrong memory address for x->fn (it is off by 0x70 bytes
> according to gdb): the program is writing to the wrong location (I've
> verified this by examining the memory at that location).
>
> I wouldn't mind including the source for my program, but it depends on
> many libraries, at least one of which I can guarantee you don't have
> installed.
>
>
If you can provide all necessary libraries for me to reproduce it
on Fedora/9, Fedora/10 or RHEL 5, I will look into it.
--
H.J.