1#include <dlfcn.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5extern int call_me (void);
6
7int
8call_me (void)
9{
10 void *h;
11 int (*fp) (void);
12 int res;
13
14 h = dlopen (file: "reldepmod1.so", RTLD_LAZY);
15 if (h == NULL)
16 {
17 printf (format: "cannot open reldepmod1.so in %s: %s\n", __FILE__, dlerror ());
18 exit (status: 1);
19 }
20
21 fp = dlsym (handle: h, name: "foo");
22 if (fp == NULL)
23 {
24 printf (format: "cannot get address of foo in global scope: %s\n", dlerror ());
25 exit (status: 1);
26 }
27
28 res = fp () - 42;
29
30 if (dlclose (handle: h) != 0)
31 {
32 printf (format: "failure when closing h in %s: %s\n", __FILE__, dlerror ());
33 exit (status: 1);
34 }
35
36 return res;
37}
38

source code of glibc/elf/reldepmod4.c