File: lateglobal.c

package info (click to toggle)
glibc 2.42-13
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 312,844 kB
  • sloc: ansic: 1,061,027; asm: 238,416; makefile: 20,970; python: 13,509; sh: 11,828; cpp: 5,188; awk: 1,794; perl: 317; yacc: 292; pascal: 182; sed: 19
file content (47 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (18)
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
#include <dlfcn.h>
#include <mcheck.h>
#include <stdio.h>
#include <stdlib.h>

int
main (void)
{
  void *h[2];
  int fail;
  int (*fp) (void);

  mtrace ();

  h[0] = dlopen ("ltglobmod1.so", RTLD_LAZY);
  if (h[0] == NULL)
    {
      printf ("%s: cannot open %s: %s\n",
	      __FUNCTION__, "ltglobmod1.so", dlerror ());
      exit (EXIT_FAILURE);
    }
  h[1] = dlopen ("ltglobmod2.so", RTLD_LAZY);
  if (h[1] == NULL)
    {
      printf ("%s: cannot open %s: %s\n",
	      __FUNCTION__, "ltglobmod2.so", dlerror ());
      exit (EXIT_FAILURE);
    }

  puts ("loaded \"ltglobmod1.so\" without RTLD_GLOBAL");

  fp = dlsym (h[1], "foo");
  if (fp == NULL)
    {
      printf ("cannot get address of `foo': %s\n", dlerror ());
      exit (EXIT_FAILURE);
    }

  fail = fp ();

  puts ("back in main");

  dlclose (h[1]);
  dlclose (h[0]);

  return fail;
}