hurd: Avoid more libc.so PLTs
[glibc.git] / elf / tst-tlsalign-extern.c
blob30dffbb598799c2447672ca56077ce71b292843e
1 /* Test for large alignment in TLS blocks (extern case), BZ#18383.
2 Copyright (C) 2015-2018 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/>. */
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <stdlib.h>
23 /* This is the same as tst-tlsalign-static.c, except that it uses
24 TLS variables that are defined in a separate translation unit
25 (ts-tlsalign-vars.c). It turned out that the cause of BZ#18383
26 on ARM was actually an ARM assembler bug triggered by the ways of
27 using .tdata/.tbss sections and relocs referring to them that GCC
28 chooses when the variables are defined in the same translation
29 unit that contains the references. */
31 extern __thread int tdata1;
32 extern __thread int tdata2;
33 extern __thread int tdata3;
34 extern __thread int tbss1;
35 extern __thread int tbss2;
36 extern __thread int tbss3;
38 static int
39 test_one (const char *which, unsigned int alignment, int *var, int value)
41 uintptr_t addr = (uintptr_t) var;
42 unsigned int misalign = addr & (alignment - 1);
44 printf ("%s TLS address %p %% %u = %u\n",
45 which, (void *) var, alignment, misalign);
47 int got = *var;
48 if (got != value)
50 printf ("%s value %d should be %d\n", which, got, value);
51 return 1;
54 return misalign != 0;
57 static int
58 do_test (void)
60 int fail = 0;
62 fail |= test_one ("tdata1", 4, &tdata1, 1);
63 fail |= test_one ("tdata2", 0x10, &tdata2, 2);
64 fail |= test_one ("tdata3", 0x1000, &tdata3, 4);
66 fail |= test_one ("tbss1", 4, &tbss1, 0);
67 fail |= test_one ("tbss2", 0x10, &tbss2, 0);
68 fail |= test_one ("tbss3", 0x1000, &tbss3, 0);
70 return fail ? EXIT_FAILURE : EXIT_SUCCESS;
73 #include <support/test-driver.c>