1#include <dlfcn.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5extern int bar (void);
6extern int baz (void);
7extern int foo (void);
8extern void __attribute__ ((__constructor__)) init (void);
9
10void *h;
11
12int
13foo (void)
14{
15 return 42 + bar ();
16}
17
18int
19baz (void)
20{
21 return -21;
22}
23
24
25void
26__attribute__ ((__constructor__))
27init (void)
28{
29 h = dlopen (file: "constload3.so", RTLD_GLOBAL | RTLD_LAZY);
30 if (h == NULL)
31 {
32 puts (s: "failed to load constload3");
33 exit (status: 1);
34 }
35 else
36 puts (s: "succeeded loading constload3");
37}
38
39static void
40__attribute__ ((__destructor__))
41fini (void)
42{
43 if (dlclose (handle: h) != 0)
44 {
45 puts (s: "failed to unload constload3");
46 exit (status: 1);
47 }
48 else
49 puts (s: "succeeded unloading constload3");
50}
51

source code of glibc/elf/constload2.c