1#include <dlfcn.h>
2#include <error.h>
3#include <mcheck.h>
4#include <stdio.h>
5#include <stdlib.h>
6
7int
8main (void)
9{
10 void *su[5];
11 void *h;
12 int n;
13
14 mtrace ();
15
16 if ((su[0] = dlopen (file: "testobj1.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
17 || (su[1] = dlopen (file: "testobj2.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
18 || (su[2] = dlopen (file: "testobj3.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
19 || (su[3] = dlopen (file: "testobj4.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
20 || (su[4] = dlopen (file: "testobj5.so", RTLD_GLOBAL | RTLD_NOW)) == NULL)
21 error (EXIT_FAILURE, errnum: 0, format: "failed to load shared object: %s", dlerror ());
22
23 h = dlopen (file: "failobj.so", RTLD_GLOBAL | RTLD_NOW);
24
25 printf (format: "h = %p, %s\n", h, h == NULL ? "ok" : "fail");
26
27 for (n = 0; n < 5; ++n)
28 if (dlclose (handle: su[n]) != 0)
29 {
30 printf (format: "failed to unload su[%d]: %s\n", n, dlerror ());
31 exit (EXIT_FAILURE);
32 }
33
34 return h != NULL;
35}
36
37extern int foo (int a);
38int
39foo (int a)
40{
41 return 10;
42}
43

source code of glibc/elf/loadfail.c