Back to index

glibc  2.9
tst-tls3.c
Go to the documentation of this file.
00001 /* glibc test for TLS in ld.so.  */
00002 #include <stdio.h>
00003 
00004 #include <tls.h>
00005 
00006 #include "tls-macros.h"
00007 
00008 
00009 /* One define int variable, two externs.  */
00010 COMMON_INT_DECL(foo);
00011 VAR_INT_DECL(bar);
00012 VAR_INT_DEF(baz);
00013 
00014 
00015 extern int in_dso (void);
00016 
00017 
00018 #define TEST_FUNCTION do_test ()
00019 static int
00020 do_test (void)
00021 {
00022   int result = 0;
00023   int *ap, *bp, *cp;
00024 
00025 
00026   /* Set the variable using the local exec model.  */
00027   puts ("set baz to 3 (LE)");
00028   ap = TLS_LE (baz);
00029   *ap = 3;
00030 
00031 
00032   /* Get variables using initial exec model.  */
00033   puts ("set variables foo and bar (IE)");
00034   ap = TLS_IE (foo);
00035   *ap = 1;
00036   bp = TLS_IE (bar);
00037   *bp = 2;
00038 
00039 
00040   /* Get variables using local dynamic model.  */
00041   fputs ("get sum of foo, bar (GD) and baz (LD)", stdout);
00042   ap = TLS_GD (foo);
00043   bp = TLS_GD (bar);
00044   cp = TLS_LD (baz);
00045   printf (" = %d\n", *ap + *bp + *cp);
00046   result |= *ap + *bp + *cp != 6;
00047   if (*ap != 1)
00048     {
00049       printf ("foo = %d\n", *ap);
00050       result = 1;
00051     }
00052   if (*bp != 2)
00053     {
00054       printf ("bar = %d\n", *bp);
00055       result = 1;
00056     }
00057   if (*cp != 3)
00058     {
00059       printf ("baz = %d\n", *cp);
00060       result = 1;
00061     }
00062 
00063 
00064   result |= in_dso ();
00065 
00066   return result;
00067 }
00068 
00069 
00070 #include "../test-skeleton.c"