Skip to content

Commit

Permalink
Test dlopen()
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 18, 2009
1 parent d0c37ed commit bb6416c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/hello-dlopen.c
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <dlfcn.h>
#include <errno.h>

typedef int (*hellofn)(void);

int main(void)
{
int retval = 1;
void *lib = dlopen("./hello.so", RTLD_NOW | RTLD_GLOBAL);
if (lib == NULL)
perror("dlopen");
else
{
hellofn phello = (hellofn) dlsym(lib, "hello");
if (phello == NULL)
perror("dlsym");
else
{
retval = phello();
dlclose(lib);
}
}

return retval;
}

/* end of hello-dlopen.c ... */

8 changes: 8 additions & 0 deletions test/test.sh
Expand Up @@ -11,25 +11,33 @@ make -j2

gcc -o hello.so ../hello-lib.c -shared -fPIC -m32
gcc -o hello-x86 ../hello.c hello.so -m32 -Wl,-rpath,.
gcc -o hello-dlopen-x86 ../hello-dlopen.c -ldl -m32
mv hello.so hello-x86.so

gcc -o hello.so ../hello-lib.c -shared -fPIC -m64
gcc -o hello-amd64 ../hello.c hello.so -m64 -Wl,-rpath,.
gcc -o hello-dlopen-amd64 ../hello-dlopen.c -ldl -m64
mv hello.so hello-amd64.so

./fatelf-glue hello hello-x86 hello-amd64
./fatelf-glue hello.so hello-amd64.so hello-x86.so
./fatelf-glue hello-dlopen hello-dlopen-amd64 hello-dlopen-x86

file ./hello
./fatelf-info ./hello

file ./hello.so
./fatelf-info ./hello.so

file ./hello-dlopen
./fatelf-info ./hello-dlopen

ldd ./hello
ldd ./hello.so
ldd ./hello-dlopen

./hello
./hello-dlopen

# end of test.sh ...

Expand Down

0 comments on commit bb6416c

Please sign in to comment.