S390: Test that lazy binding does not clobber R0
authorIlya Leoshkevich <iii@linux.ibm.com>
Fri, 10 Aug 2018 07:07:43 +0000 (09:07 +0200)
committerStefan Liebler <stli@linux.ibm.com>
Fri, 10 Aug 2018 07:07:43 +0000 (09:07 +0200)
The following combinations need to be tested:
* 32- (g5, esa and zarch) and 64-bit
  * linux32 glibc/configure CC='gcc -m31 -march=g5'
  * linux32 glibc/configure CC='gcc -m31'
  * linux32 glibc/configure CC='gcc -m31 -mzarch'
* With and without VX:
  * glibc/configure libc_cv_asm_s390_vx=no
* With and without profiling (using LD_PROFILE)
* With and without pltexit (using LD_AUDIT)

ChangeLog:

* sysdeps/s390/Makefile: Register the new tests.
* sysdeps/s390/tst-dl-runtime-mod.S: New file.
* sysdeps/s390/tst-dl-runtime-profile-audit.c: New file.
* sysdeps/s390/tst-dl-runtime-profile-noaudit.c: New file.
* sysdeps/s390/tst-dl-runtime-resolve-audit.c: New file.
* sysdeps/s390/tst-dl-runtime-resolve-noaudit.c: New file.
* sysdeps/s390/tst-dl-runtime.c: New file.

ChangeLog
sysdeps/s390/Makefile
sysdeps/s390/tst-dl-runtime-mod.S [new file with mode: 0644]
sysdeps/s390/tst-dl-runtime-profile-audit.c [new file with mode: 0644]
sysdeps/s390/tst-dl-runtime-profile-noaudit.c [new file with mode: 0644]
sysdeps/s390/tst-dl-runtime-resolve-audit.c [new file with mode: 0644]
sysdeps/s390/tst-dl-runtime-resolve-noaudit.c [new file with mode: 0644]
sysdeps/s390/tst-dl-runtime.c [new file with mode: 0644]

index 87e328871267700bfef2e7c188d80bf3e6658ae5..ae2868ffe0fd8cb2e628cbdf3cfb563fc5a482c1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-08-10  Ilya Leoshkevich  <iii@linux.ibm.com>
+
+       * sysdeps/s390/Makefile: Register the new tests.
+       * sysdeps/s390/tst-dl-runtime-mod.S: New file.
+       * sysdeps/s390/tst-dl-runtime-profile-audit.c: New file.
+       * sysdeps/s390/tst-dl-runtime-profile-noaudit.c: New file.
+       * sysdeps/s390/tst-dl-runtime-resolve-audit.c: New file.
+       * sysdeps/s390/tst-dl-runtime-resolve-noaudit.c: New file.
+       * sysdeps/s390/tst-dl-runtime.c: New file.
+
 2018-08-10  Ilya Leoshkevich  <iii@linux.ibm.com>
 
        * sysdeps/s390/s390-64/dl-trampoline.h (_dl_runtime_profile):
index 8a54f88cd7ac880ed8d998f718ff6cec76086493..496ab51973522164f4811a76de271cceca6440f8 100644 (file)
@@ -29,3 +29,26 @@ $(inst_gconvdir)/%.so: $(objpfx)%.so $(+force)
 
 sysdeps-gconv-modules = ../sysdeps/s390/gconv-modules
 endif
+
+ifeq ($(subdir),elf)
+ifeq ($(build-shared),yes)
+tests += tst-dl-runtime-resolve-noaudit tst-dl-runtime-resolve-audit \
+       tst-dl-runtime-profile-noaudit
+# FIXME: When both LD_PROFILE and LD_AUDIT are set, a segfault occurs.
+#tests += tst-dl-runtime-profile-audit
+modules-names += tst-dl-runtime-mod
+$(objpfx)tst-dl-runtime-resolve-noaudit: $(objpfx)tst-dl-runtime-mod.so
+$(objpfx)tst-dl-runtime-resolve-audit: $(objpfx)tst-dl-runtime-mod.so
+$(objpfx)tst-dl-runtime-profile-noaudit: $(objpfx)tst-dl-runtime-mod.so
+$(objpfx)tst-dl-runtime-profile-audit: $(objpfx)tst-dl-runtime-mod.so
+$(objpfx)tst-dl-runtime-resolve-audit.out: $(objpfx)tst-auditmod1.so
+$(objpfx)tst-dl-runtime-profile-audit.out: $(objpfx)tst-auditmod1.so
+# The profiling output goes to $LD_PROFILE_OUTPUT/$LD_PROFILE.profile
+env-profile = LD_PROFILE=$(objpfx)tst-dl-runtime-mod.so \
+       LD_PROFILE_OUTPUT=/
+env-audit = LD_AUDIT=$(objpfx)tst-auditmod1.so
+tst-dl-runtime-resolve-audit-ENV = $(env-audit)
+tst-dl-runtime-profile-noaudit-ENV = $(env-profile)
+tst-dl-runtime-profile-audit-ENV = $(env-profile) $(env-audit)
+endif
+endif
diff --git a/sysdeps/s390/tst-dl-runtime-mod.S b/sysdeps/s390/tst-dl-runtime-mod.S
new file mode 100644 (file)
index 0000000..5568524
--- /dev/null
@@ -0,0 +1,30 @@
+/* Shared library for the lazy binding tests.
+   Copyright (C) 2018 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/>.  */
+
+       .globl  r0x2
+       .type   r0x2, @function
+r0x2:
+       .cfi_startproc
+#if defined (__s390x__)
+       agr %r0,%r0
+#else
+       ar %r0,%r0
+#endif
+       br %r14
+       .cfi_endproc
+       .size   r0x2, .-r0x2
diff --git a/sysdeps/s390/tst-dl-runtime-profile-audit.c b/sysdeps/s390/tst-dl-runtime-profile-audit.c
new file mode 100644 (file)
index 0000000..a797e72
--- /dev/null
@@ -0,0 +1,19 @@
+/* Lazy binding test with profiling and auditing.
+   Copyright (C) 2018 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 "tst-dl-runtime.c"
diff --git a/sysdeps/s390/tst-dl-runtime-profile-noaudit.c b/sysdeps/s390/tst-dl-runtime-profile-noaudit.c
new file mode 100644 (file)
index 0000000..fedae9d
--- /dev/null
@@ -0,0 +1,19 @@
+/* Lazy binding test with profiling.
+   Copyright (C) 2018 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 "tst-dl-runtime.c"
diff --git a/sysdeps/s390/tst-dl-runtime-resolve-audit.c b/sysdeps/s390/tst-dl-runtime-resolve-audit.c
new file mode 100644 (file)
index 0000000..a4fb189
--- /dev/null
@@ -0,0 +1,19 @@
+/* Lazy binding test with auditing.
+   Copyright (C) 2018 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 "tst-dl-runtime.c"
diff --git a/sysdeps/s390/tst-dl-runtime-resolve-noaudit.c b/sysdeps/s390/tst-dl-runtime-resolve-noaudit.c
new file mode 100644 (file)
index 0000000..472724c
--- /dev/null
@@ -0,0 +1,19 @@
+/* Lazy binding test.
+   Copyright (C) 2018 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 "tst-dl-runtime.c"
diff --git a/sysdeps/s390/tst-dl-runtime.c b/sysdeps/s390/tst-dl-runtime.c
new file mode 100644 (file)
index 0000000..7ab3c07
--- /dev/null
@@ -0,0 +1,91 @@
+/* Test that lazy binding does not clobber r0.
+   Copyright (C) 2018 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 <assert.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#if defined (__s390x__)
+static const unsigned long magic_value = 0x0011223344556677UL;
+#else
+static const unsigned long magic_value = 0x00112233;
+#endif
+
+unsigned long r0x2_trampoline (unsigned long);
+
+/* Invoke r0x2, which doubles the value in r0.  If we get
+   value * 2 back, this means nothing clobbers r0, particularly,
+   _dl_runtime_resolve and _dl_runtime_profile.  */
+asm ("    .type r0x2_trampoline, @function\n"
+     "r0x2_trampoline:\n"
+#if defined (__s390x__)
+     "    lgr %r0,%r2\n"
+     "    stg %r14,112(%r15)\n"
+     "    aghi %r15,-160\n"
+     "    brasl %r14,r0x2@plt\n"
+     "    aghi %r15,160\n"
+     "    lg %r14,112(%r15)\n"
+     "    lgr %r2,%r0\n"
+     "    br %r14\n"
+#elif defined (__zarch__)
+     "    lr %r0,%r2\n"
+     "    st %r14,56(%r15)\n"
+     "    ahi %r15,-96\n"
+     "    brasl %r14,r0x2@plt\n"
+     "    ahi %r15,96\n"
+     "    l %r14,56(%r15)\n"
+     "    lr %r2,%r0\n"
+     "    br %r14\n"
+#else
+     "    lr %r0,%r2\n"
+     "    st %r14,56(%r15)\n"
+     "    ahi %r15,-96\n"
+     "    balr %r14,0\n"
+     "    l %r14,1f-.(%r14)\n"
+     "    basr %r14,%r14\n"
+     "    ahi %r15,96\n"
+     "    l %r14,56(%r15)\n"
+     "    lr %r2,%r0\n"
+     "    br %r14\n"
+     "1: .long r0x2\n"
+#endif
+     );
+
+static int
+do_test (void)
+{
+  int i;
+  unsigned long r0;
+  const char *run;
+
+  for (i = 0; i < 2; i++)
+    {
+      run = (i == 0) ? "lazy" : "non-lazy";
+      r0 = magic_value;
+      printf ("-> %s r0 = 0x%lx\n", run, r0);
+      r0 = r0x2_trampoline (r0);
+      printf ("<- %s r0 * 2 = 0x%lx\n", run, r0);
+      if (r0 != magic_value * 2)
+       return EXIT_FAILURE;
+    }
+  return EXIT_SUCCESS;
+}
+
+#include <support/test-driver.c>