2002-02-10 15:44:36 +08:00
|
|
|
/* glibc test for TLS in ld.so. */
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
2021-08-17 00:59:30 +08:00
|
|
|
__thread int foo, bar __attribute__ ((tls_model("local-exec")));
|
|
|
|
extern __thread int foo_gd asm ("foo") __attribute__ ((tls_model("global-dynamic")));
|
|
|
|
extern __thread int foo_ld asm ("foo") __attribute__ ((tls_model("local-dynamic")));
|
|
|
|
extern __thread int foo_ie asm ("foo") __attribute__ ((tls_model("initial-exec")));
|
|
|
|
extern __thread int bar_gd asm ("bar") __attribute__ ((tls_model("global-dynamic")));
|
|
|
|
extern __thread int bar_ld asm ("bar") __attribute__ ((tls_model("local-dynamic")));
|
|
|
|
extern __thread int bar_ie asm ("bar") __attribute__ ((tls_model("initial-exec")));
|
2002-02-10 15:44:36 +08:00
|
|
|
|
2002-02-13 16:03:56 +08:00
|
|
|
static int
|
|
|
|
do_test (void)
|
2002-02-10 15:44:36 +08:00
|
|
|
{
|
|
|
|
int result = 0;
|
2002-02-10 17:15:59 +08:00
|
|
|
int *ap, *bp;
|
2002-02-10 15:44:36 +08:00
|
|
|
|
|
|
|
|
2002-02-10 17:15:59 +08:00
|
|
|
/* Set the variable using the local exec model. */
|
|
|
|
puts ("set bar to 1 (LE)");
|
2021-08-17 00:59:30 +08:00
|
|
|
bar = 1;
|
2002-02-10 17:15:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Get variables using initial exec model. */
|
|
|
|
fputs ("get sum of foo and bar (IE)", stdout);
|
2021-08-17 00:59:30 +08:00
|
|
|
ap = &foo_ie;
|
|
|
|
bp = &bar_ie;
|
2002-02-10 17:15:59 +08:00
|
|
|
printf (" = %d\n", *ap + *bp);
|
|
|
|
result |= *ap + *bp != 1;
|
2021-08-17 00:59:30 +08:00
|
|
|
if (*ap != 0 || *bp != 1)
|
2002-02-10 17:15:59 +08:00
|
|
|
{
|
2021-08-17 00:59:30 +08:00
|
|
|
printf ("foo = %d\nbar = %d\n", *ap, *bp);
|
2002-02-10 17:15:59 +08:00
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-17 00:59:30 +08:00
|
|
|
/* Get variables using local dynamic model or TLSDESC. */
|
|
|
|
fputs ("get sum of foo and bar (LD or TLSDESC)", stdout);
|
|
|
|
ap = &foo_ld;
|
|
|
|
bp = &bar_ld;
|
2002-02-10 17:15:59 +08:00
|
|
|
printf (" = %d\n", *ap + *bp);
|
|
|
|
result |= *ap + *bp != 1;
|
2021-08-17 00:59:30 +08:00
|
|
|
if (*ap != 0 || *bp != 1)
|
2002-02-10 17:15:59 +08:00
|
|
|
{
|
2021-08-17 00:59:30 +08:00
|
|
|
printf ("foo = %d\nbar = %d\n", *ap, *bp);
|
2002-02-10 17:15:59 +08:00
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-17 00:59:30 +08:00
|
|
|
/* Get variables using general dynamic model or TLSDESC. */
|
|
|
|
fputs ("get sum of foo and bar (GD or TLSDESC)", stdout);
|
|
|
|
ap = &foo_gd;
|
|
|
|
bp = &bar_gd;
|
2002-02-10 17:15:59 +08:00
|
|
|
printf (" = %d\n", *ap + *bp);
|
|
|
|
result |= *ap + *bp != 1;
|
2021-08-17 00:59:30 +08:00
|
|
|
if (*ap != 0 || *bp != 1)
|
2002-02-10 17:15:59 +08:00
|
|
|
{
|
2021-08-17 00:59:30 +08:00
|
|
|
printf ("foo = %d\nbar = %d\n", *ap, *bp);
|
2002-02-10 17:15:59 +08:00
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
|
2021-08-17 00:59:30 +08:00
|
|
|
|
2002-02-10 15:44:36 +08:00
|
|
|
return result;
|
|
|
|
}
|
2002-02-13 16:03:56 +08:00
|
|
|
|
|
|
|
|
2017-04-05 21:34:39 +08:00
|
|
|
#include <support/test-driver.c>
|