Blame sysdeps/powerpc/mod-tlsopt-powerpc.c

Packit 6c4009
/* shared library to test for __tls_get_addr optimization.  */
Packit 6c4009
#include <stdio.h>
Packit 6c4009
Packit 6c4009
#include "../../elf/tls-macros.h"
Packit 6c4009
#include "dl-tls.h"
Packit 6c4009
Packit 6c4009
/* common 'int' variable in TLS.  */
Packit 6c4009
COMMON_INT_DEF(foo);
Packit 6c4009
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
tls_get_addr_opt_test (void)
Packit 6c4009
{
Packit 6c4009
  int result = 0;
Packit 6c4009
Packit 6c4009
  /* Get variable using general dynamic model.  */
Packit 6c4009
  int *ap = TLS_GD (foo);
Packit 6c4009
  if (*ap != 0)
Packit 6c4009
    {
Packit 6c4009
      printf ("foo = %d\n", *ap);
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  tls_index *tls_arg;
Packit 6c4009
#ifdef __powerpc64__
Packit 6c4009
  register unsigned long thread_pointer __asm__ ("r13");
Packit 6c4009
  asm ("addi %0,2,foo@got@tlsgd" : "=r" (tls_arg));
Packit 6c4009
#else
Packit 6c4009
  register unsigned long thread_pointer __asm__ ("r2");
Packit 6c4009
  asm ("bcl 20,31,1f\n1:\t"
Packit 6c4009
       "mflr %0\n\t"
Packit 6c4009
       "addis %0,%0,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t"
Packit 6c4009
       "addi %0,%0,_GLOBAL_OFFSET_TABLE_-1b@l\n\t"
Packit 6c4009
       "addi %0,%0,foo@got@tlsgd" : "=b" (tls_arg));
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  if (tls_arg->ti_module != 0)
Packit 6c4009
    {
Packit 6c4009
      printf ("tls_index not optimized, binutils too old?\n");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
  else if (tls_arg->ti_offset + thread_pointer != (unsigned long) ap)
Packit 6c4009
    {
Packit 6c4009
      printf ("tls_index->ti_offset wrong value\n");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}