Back to index

glibc  2.9
tst-tls14.c
Go to the documentation of this file.
00001 /* Check alignment of TLS variable.  */
00002 #include <dlfcn.h>
00003 #include <stdint.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 
00007 #include <tls.h>
00008 
00009 #if HAVE___THREAD
00010 
00011 # define AL 4096
00012 struct foo
00013 {
00014   int i;
00015 } __attribute ((aligned (AL)));
00016 
00017 static __thread struct foo f;
00018 static struct foo g;
00019 
00020 
00021 extern int in_dso1 (void);
00022 
00023 
00024 static int
00025 do_test (void)
00026 {
00027   int result = 0;
00028 
00029   int fail = (((uintptr_t) &f) & (AL - 1)) != 0;
00030   printf ("&f = %p %s\n", &f, fail ? "FAIL" : "OK");
00031   result |= fail;
00032 
00033   fail = (((uintptr_t) &g) & (AL - 1)) != 0;
00034   printf ("&g = %p %s\n", &g, fail ? "FAIL" : "OK");
00035   result |= fail;
00036 
00037   result |= in_dso1 ();
00038 
00039   void *h = dlopen ("tst-tlsmod14b.so", RTLD_LAZY);
00040   if (h == NULL)
00041     {
00042       printf ("cannot open tst-tlsmod14b.so: %m\n");
00043       exit (1);
00044     }
00045 
00046   int (*fp) (void) = (int (*) (void)) dlsym (h, "in_dso2");
00047   if (fp == NULL)
00048     {
00049       puts ("cannot find in_dso2");
00050       exit (1);
00051     }
00052 
00053   result |= fp ();
00054 
00055   return result;
00056 }
00057 
00058 # define TEST_FUNCTION do_test ()
00059 
00060 #else
00061 
00062 # define TEST_FUNCTION 0
00063 
00064 #endif
00065 
00066 #include "../test-skeleton.c"