|
Packit |
6c4009 |
/* Test if an executable can read from the TLS from an STT_GNU_IFUNC resolver.
|
|
Packit |
6c4009 |
Copyright (C) 2017-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <stdint.h>
|
|
Packit |
6c4009 |
#include <inttypes.h>
|
|
Packit |
6c4009 |
#include <libc-symbols.h>
|
|
Packit |
6c4009 |
#include <tls-macros.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__thread int bar;
|
|
Packit |
6c4009 |
static int *bar_ptr = NULL;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static uint32_t resolver_platform = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int foo (void);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int tcb_test (void);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Offsets copied from tcb-offsets.h. */
|
|
Packit |
6c4009 |
#ifdef __powerpc64__
|
|
Packit |
6c4009 |
# define __TPREG "r13"
|
|
Packit |
6c4009 |
# define __ATPLATOFF -28764
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
# define __TPREG "r2"
|
|
Packit |
6c4009 |
# define __ATPLATOFF -28724
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
uint32_t
|
|
Packit |
6c4009 |
get_platform (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
register unsigned long tp __asm__ (__TPREG);
|
|
Packit |
6c4009 |
uint32_t tmp;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__asm__ ("lwz %0,%1(%2)\n"
|
|
Packit |
6c4009 |
: "=r" (tmp)
|
|
Packit |
6c4009 |
: "i" (__ATPLATOFF), "b" (tp));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return tmp;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
init_foo (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
bar_ptr = TLS_GD (bar);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
my_foo (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("&bar = %p and bar_ptr = %p.\n", &bar, bar_ptr);
|
|
Packit |
6c4009 |
return bar_ptr != NULL;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__ifunc (foo, foo, my_foo, void, init_foo);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
init_tcb_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
resolver_platform = get_platform ();
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
my_tcb_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("resolver_platform = 0x%"PRIx32
|
|
Packit |
6c4009 |
" and current platform = 0x%"PRIx32".\n",
|
|
Packit |
6c4009 |
resolver_platform, get_platform ());
|
|
Packit |
6c4009 |
return resolver_platform != 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__ifunc (tcb_test, tcb_test, my_tcb_test, void, init_tcb_test);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int ret = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (foo ())
|
|
Packit |
6c4009 |
printf ("PASS: foo IFUNC resolver called once.\n");
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("FAIL: foo IFUNC resolver not called once.\n");
|
|
Packit |
6c4009 |
ret = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (&bar == bar_ptr)
|
|
Packit |
6c4009 |
printf ("PASS: bar address read from IFUNC resolver is correct.\n");
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("FAIL: bar address read from IFUNC resolver is incorrect.\n");
|
|
Packit |
6c4009 |
ret = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (tcb_test ())
|
|
Packit |
6c4009 |
printf ("PASS: tcb_test IFUNC resolver called once.\n");
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("FAIL: tcb_test IFUNC resolver not called once.\n");
|
|
Packit |
6c4009 |
ret = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (resolver_platform == get_platform ())
|
|
Packit |
6c4009 |
printf ("PASS: platform read from IFUNC resolver is correct.\n");
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("FAIL: platform read from IFUNC resolver is incorrect.\n");
|
|
Packit |
6c4009 |
ret = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return ret;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <support/test-driver.c>
|