Optimize x86-64 pthread_cond_wait.
[glibc.git] / elf / ifuncmain3.c
blob5d067cced96f49c3f5aa4499f8cffded9901417e
1 /* Test STT_GNU_IFUNC symbols with dlopen:
3 1. Direct function call.
4 2. Function pointer.
5 3. Visibility with override.
6 */
8 #include <dlfcn.h>
9 #include <stdlib.h>
10 #include <stdio.h>
12 typedef int (*foo_p) (void);
14 int
15 __attribute__ ((noinline))
16 foo (void)
18 return -30;
21 int
22 __attribute__ ((noinline))
23 foo_hidden (void)
25 return -20;
28 int
29 __attribute__ ((noinline))
30 foo_protected (void)
32 return -40;
35 int
36 main (void)
38 foo_p p;
39 foo_p (*f) (void);
40 int *ret;
42 void *h = dlopen ("ifuncmod3.so", RTLD_LAZY);
43 if (h == NULL)
45 printf ("cannot load: %s\n", dlerror ());
46 return 1;
49 f = dlsym (h, "get_foo_p");
50 if (f == NULL)
52 printf ("symbol not found: %s\n", dlerror ());
53 return 1;
56 ret = dlsym (h, "ret_foo");
57 if (ret == NULL)
59 printf ("symbol not found: %s\n", dlerror ());
60 return 1;
63 p = (*f) ();
64 if (p != foo)
65 abort ();
66 if (foo () != -30)
67 abort ();
68 if (*ret != -30 || (*p) () != *ret)
69 abort ();
71 f = dlsym (h, "get_foo_hidden_p");
72 if (f == NULL)
74 printf ("symbol not found: %s\n", dlerror ());
75 return 1;
78 ret = dlsym (h, "ret_foo_hidden");
79 if (ret == NULL)
81 printf ("symbol not found: %s\n", dlerror ());
82 return 1;
85 p = (*f) ();
86 if (foo_hidden () != -20)
87 abort ();
88 if (*ret != 1 || (*p) () != *ret)
89 abort ();
91 f = dlsym (h, "get_foo_protected_p");
92 if (f == NULL)
94 printf ("symbol not found: %s\n", dlerror ());
95 return 1;
98 ret = dlsym (h, "ret_foo_protected");
99 if (ret == NULL)
101 printf ("symbol not found: %s\n", dlerror ());
102 return 1;
105 p = (*f) ();
106 if (p == foo_protected)
107 abort ();
108 if (foo_protected () != -40)
109 abort ();
110 if (*ret != 0 || (*p) () != *ret)
111 abort ();
113 if (dlclose (h) != 0)
115 printf ("cannot close: %s\n", dlerror ());
116 return 1;
119 return 0;