Blame elf/tst-tls16.c

Packit 6c4009
#include <dlfcn.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  void *h = dlopen ("tst-tlsmod16a.so", RTLD_LAZY | RTLD_GLOBAL);
Packit 6c4009
  if (h == NULL)
Packit 6c4009
    {
Packit 6c4009
      puts ("unexpectedly failed to open tst-tlsmod16a.so");
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  void *p = dlsym (h, "tlsvar");
Packit 6c4009
Packit 6c4009
  /* This dlopen should indeed fail, because tlsvar was assigned to
Packit 6c4009
     dynamic TLS, and the new module requests it to be in static TLS.
Packit 6c4009
     However, there's a possibility that dlopen succeeds if the
Packit 6c4009
     variable is, for whatever reason, assigned to static TLS, or if
Packit 6c4009
     the module fails to require static TLS, or even if TLS is not
Packit 6c4009
     supported.  */
Packit 6c4009
  h = dlopen ("tst-tlsmod16b.so", RTLD_NOW | RTLD_GLOBAL);
Packit 6c4009
  if (h == NULL)
Packit 6c4009
    {
Packit 6c4009
      return 0;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  puts ("unexpectedly succeeded to open tst-tlsmod16b.so");
Packit 6c4009
Packit 6c4009
Packit 6c4009
  void *(*fp) (void) = (void *(*) (void)) dlsym (h, "in_dso");
Packit 6c4009
  if (fp == NULL)
Packit 6c4009
    {
Packit 6c4009
      puts ("cannot find in_dso");
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* If the dlopen passes, at least make sure the address returned by
Packit 6c4009
     dlsym is the same as that returned by the initial-exec access.
Packit 6c4009
     If the variable was assigned to dynamic TLS during dlsym, this
Packit 6c4009
     portion will fail.  */
Packit 6c4009
  if (fp () != p)
Packit 6c4009
    {
Packit 6c4009
      puts ("returned values do not match");
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#include <support/test-driver.c>