1 /* Copyright (C) 2003-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@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 <https://www.gnu.org/licenses/>. */
24 #include <support/support.h>
25 #include <support/check.h>
26 #include <support/xthread.h>
30 __attribute__ ((aligned(0x20))) int a
;
31 __attribute__ ((aligned(0x200))) int b
;
36 /* Deliberately not static. */
37 __thread
struct test_s s
__attribute__ ((tls_model ("initial-exec"))) =
43 /* Use noinline in combination with not static to ensure that the
44 alignment check is really done. Otherwise it was optimized out! */
45 __attribute__ ((noinline
)) void
46 check_alignment (const char *thr_name
, const char *ptr_name
,
47 int *ptr
, int alignment
)
49 uintptr_t offset_aligment
= ((uintptr_t) ptr
) & (alignment
- 1);
52 FAIL_EXIT1 ("%s (%p) is not 0x%x-byte aligned in %s thread\n",
53 ptr_name
, ptr
, alignment
, thr_name
);
58 check_s (const char *thr_name
)
60 if (s
.a
!= INIT_A
|| s
.b
!= INIT_B
)
61 FAIL_EXIT1 ("initial value of s in %s thread wrong\n", thr_name
);
63 check_alignment (thr_name
, "s.a", &s
.a
, 0x20);
64 check_alignment (thr_name
, "s.b", &s
.b
, 0x200);
85 xpthread_attr_init (&a
);
87 #define STACK_SIZE (1 * 1024 * 1024)
88 xpthread_attr_setstacksize (&a
, STACK_SIZE
);
92 for (i
= 0; i
< N
; ++i
)
97 for (j
= 0; j
< M
; ++j
, ++s
.a
)
98 th
[j
] = xpthread_create (&a
, tf
, NULL
);
100 for (j
= 0; j
< M
; ++j
)
101 xpthread_join (th
[j
]);
104 /* Also check the alignment of the tls variables if a misaligned stack is
107 void *thr_stack
= NULL
;
108 thr_stack
= xposix_memalign (0x200, STACK_SIZE
+ 1);
109 xpthread_attr_setstack (&a
, thr_stack
+ 1, STACK_SIZE
);
110 th
= xpthread_create (&a
, tf
, NULL
);
114 xpthread_attr_destroy (&a
);
119 #include <support/test-driver.c>