about summary refs log tree commit diff
path: root/sysdeps/powerpc/tst-tlsifunc.c
diff options
context:
space:
mode:
authorTulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>2017-07-17 17:48:59 -0300
committerTulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>2017-07-17 17:49:26 -0300
commit91ac3a7d8474480685632cd25f844d3154c69fdf (patch)
treee83a0146b14a08bafb9b9d5a25d83f7c715b266c /sysdeps/powerpc/tst-tlsifunc.c
parentae5c498d93d049d9574d3f8f18e62cac64cbdf5c (diff)
downloadglibc-91ac3a7d8474480685632cd25f844d3154c69fdf.tar.gz
glibc-91ac3a7d8474480685632cd25f844d3154c69fdf.tar.xz
glibc-91ac3a7d8474480685632cd25f844d3154c69fdf.zip
powerpc: Fix float128 IFUNC relocations [BZ #21707]
The patch proposed by Peter Bergner [1] to libgcc in order to fix
[BZ #21707] adds a dependency on a symbol provided by the loader,
forcing the loader to be linked to tests after libgcc was linked.

It also requires to read the thread pointer during IRELA relocations.

Tested on powerpc, powerpc64, powerpc64le, s390x and x86_64.

[1] https://sourceware.org/ml/libc-alpha/2017-06/msg01383.html

	[BZ #21707]
	* csu/libc-start.c (LIBC_START_MAIN): Perform IREL{,A}
	relocations before or after initializing the TCB on statically
	linked executables.  That's a per-architecture definition.
	* elf/rtld.c (dl_main): Add a comment about thread-local
	variables initialization.
	* sysdeps/generic/libc-start.h: New file.  Define
	ARCH_APPLY_IREL and ARCH_SETUP_IREL.
	* sysdeps/powerpc/Makefile:
	[$(subdir) = elf && $(multi-arch) != no] (tests-static-internal): Add tst-tlsifunc-static.
	[$(subdir) = elf && $(multi-arch) != no && $(build-shared) == yes]
	(tests-internal): Add tst-tlsifunc.
	* sysdeps/powerpc/tst-tlsifunc.c: New file.
	* sysdeps/powerpc/tst-tlsifunc-static.c: Likewise.
	* sysdeps/powerpc/powerpc64le/Makefile (f128-loader-link): New
	variable.
	[$(subdir) = math] (test-float128% test-ifloat128%): Force
	linking to the loader after linking to libgcc.
	[$(subdir) = wcsmbs || $(subdir) = stdlib] (bug-strtod bug-strtod2)
	(bug-strtod2 tst-strtod-round tst-wcstod-round tst-strtod6 tst-strrom)
	(tst-strfrom-locale strfrom-skeleton): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/libc-start.h: New file.  Define
	ARCH_APPLY_IREL and ARCH_SETUP_IREL.
Diffstat (limited to 'sysdeps/powerpc/tst-tlsifunc.c')
-rw-r--r--sysdeps/powerpc/tst-tlsifunc.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/sysdeps/powerpc/tst-tlsifunc.c b/sysdeps/powerpc/tst-tlsifunc.c
new file mode 100644
index 0000000000..0a8bdbf0c4
--- /dev/null
+++ b/sysdeps/powerpc/tst-tlsifunc.c
@@ -0,0 +1,129 @@
+/* Test if an executable can read from the TLS from an STT_GNU_IFUNC resolver.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <libc-symbols.h>
+#include <tls-macros.h>
+
+__thread int bar;
+static int *bar_ptr = NULL;
+
+static uint32_t resolver_platform = 0;
+
+int foo (void);
+
+int tcb_test (void);
+
+/* Offsets copied from tcb-offsets.h.  */
+#ifdef __powerpc64__
+# define __TPREG     "r13"
+# define __ATPLATOFF -28764
+#else
+# define __TPREG     "r2"
+# define __ATPLATOFF -28724
+#endif
+
+uint32_t
+get_platform (void)
+{
+  register unsigned long tp __asm__ (__TPREG);
+  uint32_t tmp;
+
+  __asm__  ("lwz %0,%1(%2)\n"
+	    : "=r" (tmp)
+	    : "i" (__ATPLATOFF), "b" (tp));
+
+  return tmp;
+}
+
+void
+init_foo (void)
+{
+  bar_ptr = TLS_GD (bar);
+}
+
+int
+my_foo (void)
+{
+  printf ("&bar = %p and bar_ptr = %p.\n", &bar, bar_ptr);
+  return bar_ptr != NULL;
+}
+
+__ifunc (foo, foo, my_foo, void, init_foo);
+
+void
+init_tcb_test (void)
+{
+  resolver_platform = get_platform ();
+}
+
+int
+my_tcb_test (void)
+{
+  printf ("resolver_platform = 0x%"PRIx32
+	  " and current platform = 0x%"PRIx32".\n",
+	  resolver_platform, get_platform ());
+  return resolver_platform != 0;
+}
+
+__ifunc (tcb_test, tcb_test, my_tcb_test, void, init_tcb_test);
+
+static int
+do_test (void)
+{
+  int ret = 0;
+
+  if (foo ())
+    printf ("PASS: foo IFUNC resolver called once.\n");
+  else
+    {
+      printf ("FAIL: foo IFUNC resolver not called once.\n");
+      ret = 1;
+    }
+
+  if (&bar == bar_ptr)
+    printf ("PASS: bar address read from IFUNC resolver is correct.\n");
+  else
+    {
+      printf ("FAIL: bar address read from IFUNC resolver is incorrect.\n");
+      ret = 1;
+    }
+
+  if (tcb_test ())
+    printf ("PASS: tcb_test IFUNC resolver called once.\n");
+  else
+    {
+      printf ("FAIL: tcb_test IFUNC resolver not called once.\n");
+      ret = 1;
+    }
+
+  if (resolver_platform == get_platform ())
+    printf ("PASS: platform read from IFUNC resolver is correct.\n");
+  else
+    {
+      printf ("FAIL: platform read from IFUNC resolver is incorrect.\n");
+      ret = 1;
+    }
+
+  return ret;
+}
+
+#include <support/test-driver.c>