Blame src/general/dlopen.c
|
nsz |
626789 |
#include <dlfcn.h>
|
|
nsz |
626789 |
#include "test.h"
|
|
nsz |
626789 |
|
|
nsz |
626789 |
int main()
|
|
nsz |
626789 |
{
|
|
nsz |
626789 |
void *h, *g;
|
|
nsz |
626789 |
int *i, *i2;
|
|
nsz |
626789 |
char *s;
|
|
nsz |
626789 |
void (*f)(void);
|
|
nsz |
626789 |
|
|
nsz |
626789 |
h = dlopen("./dlopen_dso.so", RTLD_LAZY|RTLD_LOCAL);
|
|
nsz |
626789 |
if (!h)
|
|
nsz |
626789 |
error("dlopen ./dlopen_dso.so failed: %s\n", dlerror());
|
|
nsz |
626789 |
i = dlsym(h, "i");
|
|
nsz |
626789 |
if (!i)
|
|
nsz |
626789 |
error("dlsym i failed: %s\n", dlerror());
|
|
nsz |
626789 |
if (*i != 1)
|
|
nsz |
626789 |
error("initialization failed: want i=1 got i=%d\n", *i);
|
|
nsz |
626789 |
f = (void (*)(void))dlsym(h, "f");
|
|
nsz |
626789 |
if (!f)
|
|
nsz |
626789 |
error("dlsym f failed: %s\n", dlerror());
|
|
nsz |
626789 |
f();
|
|
nsz |
626789 |
if (*i != 2)
|
|
nsz |
626789 |
error("f call failed: want i=2 got i=%d\n", *i);
|
|
nsz |
49b23c |
if (dlclose(h))
|
|
nsz |
49b23c |
error("dlclose failed: %s\n", dlerror());
|
|
nsz |
49b23c |
|
|
nsz |
626789 |
g = dlopen(0, RTLD_LAZY|RTLD_LOCAL);
|
|
nsz |
626789 |
if (!g)
|
|
nsz |
626789 |
error("dlopen 0 failed: %s\n", dlerror());
|
|
nsz |
626789 |
i2 = dlsym(g, "i");
|
|
nsz |
626789 |
s = dlerror();
|
|
nsz |
626789 |
if (i2 || s == 0)
|
|
nsz |
626789 |
error("dlsym i should have failed\n");
|
|
nsz |
49b23c |
if (dlsym(g, "main") == 0)
|
|
nsz |
49b23c |
error("dlsym main failed: %s\n", dlerror());
|
|
nsz |
49b23c |
|
|
nsz |
626789 |
h = dlopen("./dlopen_dso.so", RTLD_LAZY|RTLD_GLOBAL);
|
|
nsz |
626789 |
i2 = dlsym(g, "i");
|
|
nsz |
626789 |
if (!i2)
|
|
nsz |
626789 |
error("dlsym i failed: %s\n", dlerror());
|
|
nsz |
626789 |
if (*i2 != 2)
|
|
nsz |
626789 |
error("want i2=2, got i2=%d\n", *i2);
|
|
nsz |
49b23c |
if (dlclose(g))
|
|
nsz |
49b23c |
error("dlclose failed: %s\n", dlerror());
|
|
nsz |
626789 |
return test_status;
|
|
nsz |
626789 |
}
|