1 /* Test for large alignment in TLS blocks, BZ#18383.
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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/>. */
23 static __thread
int tdata1
= 1;
24 static __thread
int tdata2
__attribute__ ((aligned (0x10))) = 2;
25 static __thread
int tdata3
__attribute__ ((aligned (0x1000))) = 4;
26 static __thread
int tbss1
;
27 static __thread
int tbss2
__attribute__ ((aligned (0x10)));
28 static __thread
int tbss3
__attribute__ ((aligned (0x1000)));
31 extern __thread
int mod_tdata1
;
32 extern __thread
int mod_tdata2
;
33 extern __thread
int mod_tdata3
;
34 extern __thread
int mod_tbss1
;
35 extern __thread
int mod_tbss2
;
36 extern __thread
int mod_tbss3
;
40 test_one (const char *which
, unsigned int alignment
, int *var
, int value
)
42 uintptr_t addr
= (uintptr_t) var
;
43 unsigned int misalign
= addr
& (alignment
- 1);
45 printf ("%s TLS address %p %% %u = %u\n",
46 which
, (void *) var
, alignment
, misalign
);
51 printf ("%s value %d should be %d\n", which
, got
, value
);
63 fail
|= test_one ("tdata1", 4, &tdata1
, 1);
64 fail
|= test_one ("tdata2", 0x10, &tdata2
, 2);
65 fail
|= test_one ("tdata3", 0x1000, &tdata3
, 4);
67 fail
|= test_one ("tbss1", 4, &tbss1
, 0);
68 fail
|= test_one ("tbss2", 0x10, &tbss2
, 0);
69 fail
|= test_one ("tbss3", 0x1000, &tbss3
, 0);
72 fail
|= test_one ("mod_tdata1", 4, &mod_tdata1
, 1);
73 fail
|= test_one ("mod_tdata2", 0x10, &mod_tdata2
, 2);
74 fail
|= test_one ("mod_tdata3", 0x1000, &mod_tdata3
, 4);
76 fail
|= test_one ("mod_tbss1", 4, &mod_tbss1
, 0);
77 fail
|= test_one ("mod_tbss2", 0x10, &mod_tbss2
, 0);
78 fail
|= test_one ("mod_tbss3", 0x1000, &mod_tbss3
, 0);
81 return fail
? EXIT_FAILURE
: EXIT_SUCCESS
;
84 #define TEST_FUNCTION do_test ()
85 #include "../test-skeleton.c"