Blame elf/tst-tls5.c

Packit 6c4009
#include <dlfcn.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  static const char modname[] = "tst-tlsmod2.so";
Packit 6c4009
  int result = 0;
Packit 6c4009
  int *foop;
Packit 6c4009
  int *foop2;
Packit 6c4009
  int (*fp) (int, int *);
Packit 6c4009
  void *h;
Packit 6c4009
Packit 6c4009
  h = dlopen (modname, RTLD_LAZY);
Packit 6c4009
  if (h == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("cannot open '%s': %s\n", modname, dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  foop = dlsym (h, "foo");
Packit 6c4009
  if (foop == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("cannot get symbol 'foo': %s\n", dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  *foop = 42;
Packit 6c4009
Packit 6c4009
  fp = dlsym (h, "in_dso");
Packit 6c4009
  if (fp == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("cannot get symbol 'in_dso': %s\n", dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  result |= fp (42, foop);
Packit 6c4009
Packit 6c4009
  foop2 = dlsym (h, "foo");
Packit 6c4009
  if (foop2 == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("cannot get symbol 'foo' the second time: %s\n", dlerror ());
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (foop != foop2)
Packit 6c4009
    {
Packit 6c4009
      puts ("address of 'foo' different the second time");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else if (*foop != 16)
Packit 6c4009
    {
Packit 6c4009
      puts ("foo != 16");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  dlclose (h);
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
#include <support/test-driver.c>