File: reldep7.c

package info (click to toggle)
glibc 2.41-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300,376 kB
  • sloc: ansic: 1,050,583; asm: 238,243; makefile: 20,379; python: 13,537; sh: 11,827; cpp: 5,197; awk: 1,795; perl: 317; yacc: 292; pascal: 182; sed: 19
file content (58 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download | duplicates (41)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

int
main (void)
{
  void *h1;
  void *h2;
  void *mod1_bar, *mod2_bar;

  h1 = dlopen ("reldep7mod1.so", RTLD_GLOBAL | RTLD_LAZY);
  if (h1 == NULL)
    {
      printf ("cannot open reldep7mod1.so: %s\n", dlerror ());
      exit (1);
    }

  h2 = dlopen ("reldep7mod2.so", RTLD_GLOBAL | RTLD_LAZY);
  if (h2 == NULL)
    {
      printf ("cannot open reldep7mod1.so: %s\n", dlerror ());
      exit (1);
    }

  mod1_bar = dlsym (h1, "mod1_bar");
  if (mod1_bar == NULL)
    {
      printf ("cannot get address of \"mod1_bar\": %s\n", dlerror ());
      exit (1);
    }

  mod2_bar = dlsym (h2, "mod2_bar");
  if (mod2_bar == NULL)
    {
      printf ("cannot get address of \"mod2_bar\": %s\n", dlerror ());
      exit (1);
    }

  printf ("%d\n", ((int (*) (void)) mod1_bar) ());
  printf ("%d\n", ((int (*) (void)) mod2_bar) ());

  if (dlclose (h1) != 0)
    {
      printf ("closing h1 failed: %s\n", dlerror ());
      exit (1);
    }

  printf ("%d\n", ((int (*) (void)) mod2_bar) ());

  if (dlclose (h2) != 0)
    {
      printf ("closing h2 failed: %s\n", dlerror ());
      exit (1);
    }

  return 0;
}