4 int main(int argc
, char *argv
[])
12 if (!t_pathrel(buf
, sizeof buf
, argv
[0], "dlopen_dso.so")) {
13 t_error("failed to obtain relative path to dlopen_dso.so\n");
16 h
= dlopen(buf
, RTLD_LAZY
|RTLD_LOCAL
);
18 t_error("dlopen %s failed: %s\n", buf
, dlerror());
21 t_error("dlsym i failed: %s\n", dlerror());
23 t_error("initialization failed: want i=1 got i=%d\n", *i
);
24 f
= (void (*)(void))dlsym(h
, "f");
26 t_error("dlsym f failed: %s\n", dlerror());
29 t_error("f call failed: want i=2 got i=%d\n", *i
);
31 g
= dlopen(0, RTLD_LAZY
|RTLD_LOCAL
);
33 t_error("dlopen 0 failed: %s\n", dlerror());
37 t_error("dlsym i should have failed\n");
38 if (dlsym(g
, "main") != (void*)main
)
39 t_error("dlsym main failed: %s\n", dlerror());
41 /* close+open reinitializes the dso with glibc but not with musl */
42 h
= dlopen(buf
, RTLD_LAZY
|RTLD_GLOBAL
);
45 t_error("dlsym i failed: %s\n", dlerror());
47 t_error("reopened dso should have the same symbols, want %p, got %p\n", i
, i2
);
49 t_error("reopened dso should have the same symbols, want i2==2, got i2==%d\n", *i2
);
51 t_error("dlclose failed: %s\n", dlerror());
53 t_error("dlclose failed: %s\n", dlerror());