summaryrefslogtreecommitdiff
path: root/elf/tst-dlmopen1.c
blob: 5a05891846545f5a5c260f59ace132dba2562951 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <dlfcn.h>
#include <stdio.h>
#include <gnu/lib-names.h>

#define TEST_SO "$ORIGIN/tst-dlmopen1mod.so"

static int
do_test (void)
{
  void *h = dlopen (LIBC_SO, RTLD_LAZY|RTLD_NOLOAD);
  if (h == NULL)
    {
      printf ("cannot get handle for %s: %s\n", LIBC_SO, dlerror ());
      return 1;
    }

  Lmid_t ns = -10;
  if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
    {
      printf ("dlinfo for %s in %s failed: %s\n",
	      LIBC_SO, __func__, dlerror ());
      return 1;
    }

  if (ns != LM_ID_BASE)
    {
      printf ("namespace for %s not LM_ID_BASE\n", LIBC_SO);
      return 1;
    }

  if (dlclose (h) != 0)
    {
      printf ("dlclose for %s in %s failed: %s\n",
	      LIBC_SO, __func__, dlerror ());
      return 1;
    }

  h = dlmopen (LM_ID_NEWLM, TEST_SO, RTLD_LAZY);
  if (h == NULL)
    {
      printf ("cannot get handle for %s: %s\n",
	      "tst-dlmopen1mod.so", dlerror ());
      return 1;
    }

  ns = -10;
  if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
    {
      printf ("dlinfo for %s in %s failed: %s\n",
	      "tst-dlmopen1mod.so", __func__, dlerror ());
      return 1;
    }

  if (ns == LM_ID_BASE)
    {
      printf ("namespace for %s is LM_ID_BASE\n", TEST_SO);
      return 1;
    }

  int (*fct) (Lmid_t) = dlsym (h, "foo");
  if (fct == NULL)
    {
      printf ("could not find %s: %s\n", "foo", dlerror ());
      return 1;
    }

  if (fct (ns) != 0)
    return 1;

  if (dlclose (h) != 0)
    {
      printf ("dlclose for %s in %s failed: %s\n",
	      TEST_SO, __func__, dlerror ());
      return 1;
    }

  return 0;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"