blob: 6bacb599dddbd10b5b42d3b9a4fdf4e25781ffe4 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Check alignment of TLS variable. */
2#include <dlfcn.h>
3#include <stdint.h>
4#include <stdio.h>
5#include <stdlib.h>
6
7#define AL 4096
8struct foo
9{
10 int i;
11} __attribute ((aligned (AL)));
12
13static __thread struct foo f;
14static struct foo g;
15
16
17extern int in_dso1 (void);
18
19
20static int
21do_test (void)
22{
23 int result = 0;
24
25 int fail = (((uintptr_t) &f) & (AL - 1)) != 0;
26 printf ("&f = %p %s\n", &f, fail ? "FAIL" : "OK");
27 result |= fail;
28
29 fail = (((uintptr_t) &g) & (AL - 1)) != 0;
30 printf ("&g = %p %s\n", &g, fail ? "FAIL" : "OK");
31 result |= fail;
32
33 result |= in_dso1 ();
34
35 void *h = dlopen ("tst-tlsmod14b.so", RTLD_LAZY);
36 if (h == NULL)
37 {
38 printf ("cannot open tst-tlsmod14b.so: %m\n");
39 exit (1);
40 }
41
42 int (*fp) (void) = (int (*) (void)) dlsym (h, "in_dso2");
43 if (fp == NULL)
44 {
45 puts ("cannot find in_dso2");
46 exit (1);
47 }
48
49 result |= fp ();
50
51 return result;
52}
53
54#define TEST_FUNCTION do_test ()
55#include "../test-skeleton.c"