This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Re: problem w/plugin libraries and incorrect memory addresses


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.


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