Subject: dlopen problems
To: NetBSD VAX Port <port-vax@netbsd.org>
From: Anders Hogrelius <ahs@hogrelius.nu>
List: port-vax
Date: 07/17/2001 00:43:18
I'm trying to port a linux program that uses dlopen/dlsym to access
functions in a shared object. Unfortunately it crashes with a segfault
when any of the functions in the so is called. I tried to compile a
example, and found out that it crashes too... :-(
Is there something that is missing in the documentation that is needed
to make the program work? It seems that the address of the function that
is returned by dlsym isn't correct, and that the wrong address is the
culprit. I'm running NetBSD 1.5 on this box. I have attached the code in
the example. On linux the program should be compiled with -ldl, but the
NetBSD manpage states that these functions automatically are included when
a program is dynamically linked.

Any ideas?

// foo.c begin

/* foo.c code for demo library
   compiled with:
   gcc -Wall -fPIC -o foo.o -c foo.c
   gcc -Wall -shared -Wl,--export-dynamic -o foo.so foo.o */

#include <stdio.h>

void foo(void)
{
  printf("Hello, world!\n");
}
// foo.c end

// dl.c begin

/* dl.c code to access function in demo library
   compiled with:
   gcc -Wall -Wl,--export-dynamic -o dl dl.c */

#include <stdlib.h>
#include <dlfcn.h>

int main(void)
{
  void (*foo)(void);
  void *handle;
  handle=dlopen("./foo.so", RTLD_NOW|RTLD_GLOBAL);
  foo = dlsym(handle, "foo");
  (*foo)();

  dlclose(handle);
  return (0);
}
// dl.c end

--
cheers,

/Anders


VAX is something we should do, VAX is something that's not Big Blue.
VAX is natural, VAX is good.
Not everyone's got Digital, but everybody should.
VAX is natural, VAX is fun.
VAX is best when it's ....  one on one, one on one.
******************************************-*******************************
* Anders Hogrelius       Phone : +46 21 381860
* Tessingatan 12         E-mail: anders@hogrelius.nu
* SE-72216 Vasteras      Web:    http://www.hogrelius.nu/~ahs/
* SWEDEN