soft-fp: Fix _FP_TO_INT latent bug in overflow handling.
[glibc.git] / nptl / tst-tls5.c
blobe3e61d88004006ee96230ee403f2a7755c8111dc
1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* Check alignment, overlapping and layout of TLS variables. */
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <pthread.h>
24 #include <pthreadP.h>
25 #include <sys/param.h>
27 #include "tst-tls5.h"
29 #ifdef TLS_REGISTER
31 struct tls_obj tls_registry[64];
33 static int
34 tls_addr_cmp (const void *a, const void *b)
36 if (((struct tls_obj *)a)->addr < ((struct tls_obj *)b)->addr)
37 return -1;
38 if (((struct tls_obj *)a)->addr > ((struct tls_obj *)b)->addr)
39 return 1;
40 return 0;
43 static int
44 do_test (void)
46 size_t cnt, i;
47 int res = 0;
48 uintptr_t min_addr = ~(uintptr_t) 0, max_addr = 0;
50 for (cnt = 0; tls_registry[cnt].name; ++cnt);
51 tls_registry[cnt].name = NULL;
52 tls_registry[cnt].addr = (uintptr_t) pthread_self ();
53 tls_registry[cnt].size = sizeof (struct pthread);
54 tls_registry[cnt++].align = __alignof__ (struct pthread);
56 qsort (tls_registry, cnt, sizeof (struct tls_obj), tls_addr_cmp);
58 for (i = 0; i < cnt; ++i)
60 printf ("%s%s = %p, size %zd, align %zd",
61 tls_registry[i].name ? "&" : "",
62 tls_registry[i].name ?: "pthread_self ()",
63 (void *) tls_registry[i].addr,
64 tls_registry[i].size, tls_registry[i].align);
65 if (tls_registry[i].addr & (tls_registry[i].align - 1))
67 fputs (", WRONG ALIGNMENT", stdout);
68 res = 1;
70 if (i > 0
71 && (tls_registry[i - 1].addr + tls_registry[i - 1].size
72 > tls_registry[i].addr))
74 fputs (", ADDRESS OVERLAP", stdout);
75 res = 1;
77 puts ("");
78 if (tls_registry[i].name)
80 min_addr = MIN (tls_registry[i].addr, min_addr);
81 max_addr = MAX (tls_registry[i].addr + tls_registry[i].size,
82 max_addr);
86 if (cnt > 1)
88 #if TLS_TCB_AT_TP
89 if (tls_registry[cnt - 1].name)
91 puts ("pthread_self () not larger than all TLS addresses");
92 res = 1;
94 else
95 max_addr = MAX (tls_registry[cnt - 1].addr, max_addr);
96 #elif TLS_DTV_AT_TP
97 if (tls_registry[0].name)
99 puts ("pthread_self () not smaller than all TLS addresses");
100 res = 1;
102 #else
103 abort ();
104 #endif
105 printf ("Initial TLS used block size %zd\n",
106 (size_t) (max_addr - min_addr));
108 return res;
111 #define TEST_FUNCTION do_test ()
113 #else
115 #define TEST_FUNCTION 0
117 #endif
119 #include "../test-skeleton.c"