summaryrefslogtreecommitdiff
path: root/test/ldso/dltest2.c
blob: 91bafa40e1d0117fdac47b6eb9f5c0cb89c03889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include "thread_db.h"

extern void _dlinfo();

int main(int argc, char **argv) {
	void *handle;
	td_err_e (*td_init_p) (void);

	fprintf(stderr, "Attempting to dlopen() libpthread.so with RTLD_NOW\n");
	handle = dlopen ("libpthread.so", RTLD_NOW);
	if (!handle) {
		fputs (dlerror(), stderr);
		exit(1);
	}

	td_init_p = dlsym (handle, "__pthread_initialize");
	if (td_init_p == NULL) {
	    fprintf(stderr, "yipe!  __pthread_initialize() failed!\n");
	    return EXIT_FAILURE;
	}
#if 0 //def __UCLIBC__
	_dlinfo();   /* not supported by ld.so.2 */
#endif
	dlclose(handle);


	fprintf(stderr, "Attempting to dlopen() libpthread.so with RTLD_LAZY\n");
	handle = dlopen ("libpthread.so", RTLD_LAZY);
	if (!handle) {
		fputs (dlerror(), stderr);
		exit(1);
	}

	td_init_p = dlsym (handle, "__pthread_initialize");
	if (td_init_p == NULL) {
	    fprintf(stderr, "yipe!  __pthread_initialize() failed!");
	    return EXIT_FAILURE;
	}
#if 0 //def __UCLIBC__
	_dlinfo();   /* not supported by ld.so.2 */
#endif
	dlclose(handle);

	fprintf(stderr, "Everything worked as expected.\n");
	return EXIT_SUCCESS;
}