x86: Move abilist files out of nptl/ subdirectories.
[glibc.git] / elf / multiload.c
blobe85cc96589064c31d3df926914fac06d58e29e63
1 #include <dlfcn.h>
2 #include <errno.h>
3 #include <mcheck.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
9 int
10 main (void)
12 void *a;
13 void *b;
14 void *c;
15 void *d;
16 char *wd;
17 char *base;
18 char *buf;
20 mtrace ();
22 /* Change to the binary directory. */
23 if (chdir (OBJDIR) != 0)
25 printf ("cannot change to `%s': %m", OBJDIR);
26 exit (EXIT_FAILURE);
29 wd = getcwd (NULL, 0);
30 base = basename (wd);
31 buf = alloca (strlen (wd) + strlen (base) + 5 + sizeof "testobj1.so");
33 printf ("loading `%s'\n", "./testobj1.so");
34 a = dlopen ("./testobj1.so", RTLD_NOW);
35 if (a == NULL)
37 printf ("cannot load `./testobj1.so': %s\n", dlerror ());
38 exit (EXIT_FAILURE);
41 stpcpy (stpcpy (stpcpy (buf, "../"), base), "/testobj1.so");
42 printf ("loading `%s'\n", buf);
43 b = dlopen (buf, RTLD_NOW);
44 if (b == NULL)
46 printf ("cannot load `%s': %s\n", buf, dlerror ());
47 exit (EXIT_FAILURE);
50 stpcpy (stpcpy (buf, wd), "/testobj1.so");
51 printf ("loading `%s'\n", buf);
52 c = dlopen (buf, RTLD_NOW);
53 if (c == NULL)
55 printf ("cannot load `%s': %s\n", buf, dlerror ());
56 exit (EXIT_FAILURE);
59 stpcpy (stpcpy (stpcpy (stpcpy (buf, wd), "/../"), base), "/testobj1.so");
60 printf ("loading `%s'\n", buf);
61 d = dlopen (buf, RTLD_NOW);
62 if (d == NULL)
64 printf ("cannot load `%s': %s\n", buf, dlerror ());
65 exit (EXIT_FAILURE);
68 if (a != b || b != c || c != d)
70 puts ("shared object loaded more than once");
71 exit (EXIT_FAILURE);
74 if (dlclose (a) != 0)
76 puts ("closing `a' failed");
77 exit (EXIT_FAILURE);
79 if (dlclose (b) != 0)
81 puts ("closing `a' failed");
82 exit (EXIT_FAILURE);
84 if (dlclose (c) != 0)
86 puts ("closing `a' failed");
87 exit (EXIT_FAILURE);
89 if (dlclose (d) != 0)
91 puts ("closing `a' failed");
92 exit (EXIT_FAILURE);
95 free (wd);
97 return 0;
100 extern int foo (int a);
102 foo (int a)
104 return a;