public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix s390{,x} build
@ 2009-05-29 17:11 Jakub Jelinek
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Jelinek @ 2009-05-29 17:11 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

This patch makes s390{,x} glibc compile again by defining ____longjmp_chk.
Tested on s390{,x}-linux.

2009-05-29  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/s390/s390-32/__longjmp.c (__longjmp): If CHECK_SP is
	defined, use it.
	* sysdeps/s390/s390-64/__longjmp.c (__longjmp): Likewise.
	* sysdeps/s390/s390-32/____longjmp_chk.c: New file.
	* sysdeps/s390/s390-64/____longjmp_chk.c: New file.

--- libc/sysdeps/s390/s390-32/__longjmp.c.jj	2009-05-16 13:23:42.000000000 -0400
+++ libc/sysdeps/s390/s390-32/__longjmp.c	2009-05-29 10:37:56.000000000 -0400
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2001, 2005, 2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
 
@@ -33,6 +33,11 @@ __longjmp (__jmp_buf env, int val)
 #ifdef PTR_DEMANGLE
   register uintptr_t r3 __asm ("%r3") = THREAD_GET_POINTER_GUARD ();
   register void *r1 __asm ("%r1") = (void *) env;
+# ifdef CHECK_SP
+  CHECK_SP (env, r3);
+# endif
+#elif defined CHECK_SP
+  CHECK_SP (env, 0);
 #endif
   /* Restore registers and jump back.  */
   asm volatile ("ld   %%f6,48(%1)\n\t"
--- libc/sysdeps/s390/s390-32/____longjmp_chk.c.jj	2009-05-29 10:16:59.000000000 -0400
+++ libc/sysdeps/s390/s390-32/____longjmp_chk.c	2009-05-29 10:39:08.000000000 -0400
@@ -0,0 +1,41 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <sysdep.h>
+#include <setjmp.h>
+#include <bits/setjmp.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#define __longjmp ____longjmp_chk
+
+#define CHECK_SP(env, guard) \
+  do									\
+    {									\
+      uintptr_t cur_sp;							\
+      uintptr_t new_sp = env->__gregs[9];				\
+      __asm ("lr %0, %%r15" : "=r" (cur_sp));				\
+      new_sp ^= guard;							\
+      if (new_sp < cur_sp)						\
+	__fortify_fail ("longjmp causes uninitialized stack frame");	\
+    } while (0)
+
+#include "__longjmp.c"
--- libc/sysdeps/s390/s390-64/__longjmp.c.jj	2009-05-16 13:23:42.000000000 -0400
+++ libc/sysdeps/s390/s390-64/__longjmp.c	2009-05-29 10:38:08.000000000 -0400
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2005, 2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
 
@@ -33,6 +33,11 @@ __longjmp (__jmp_buf env, int val)
 #ifdef PTR_DEMANGLE
   register uintptr_t r3 __asm ("%r3") = THREAD_GET_POINTER_GUARD ();
   register void *r1 __asm ("%r1") = (void *) env;
+# ifdef CHECK_SP
+  CHECK_SP (env, r3);
+# endif
+#elif defined CHECK_SP
+  CHECK_SP (env, 0);
 #endif
   /* Restore registers and jump back.  */
   asm volatile ("ld   %%f7,104(%1)\n\t"
--- libc/sysdeps/s390/s390-64/____longjmp_chk.c.jj	2009-05-29 10:16:59.000000000 -0400
+++ libc/sysdeps/s390/s390-64/____longjmp_chk.c	2009-05-29 10:38:52.000000000 -0400
@@ -0,0 +1,41 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <errno.h>
+#include <sysdep.h>
+#include <setjmp.h>
+#include <bits/setjmp.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#define __longjmp ____longjmp_chk
+
+#define CHECK_SP(env, guard) \
+  do									\
+    {									\
+      uintptr_t cur_sp;							\
+      uintptr_t new_sp = env->__gregs[9];				\
+      __asm ("lgr %0, %%r15" : "=r" (cur_sp));				\
+      new_sp ^= guard;							\
+      if (new_sp < cur_sp)						\
+	__fortify_fail ("longjmp causes uninitialized stack frame");	\
+    } while (0)
+
+#include "__longjmp.c"

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Fix s390{,x} build
@ 2004-10-05 15:31 Jakub Jelinek
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Jelinek @ 2004-10-05 15:31 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

Without this s390{,x} ld.so doesn't link.

2004-10-05  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h: Include dl-sysdep.h.
	* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h: Likewise.

--- libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h	4 Oct 2004 20:59:35 -0000	1.14
+++ libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h	5 Oct 2004 11:23:18 -0000	1.12.2.3
@@ -22,6 +22,7 @@
 
 #include <sysdeps/s390/s390-32/sysdep.h>
 #include <sysdeps/unix/sysdep.h>
+#include <dl-sysdep.h>	/* For RTLD_PRIVATE_ERRNO.  */
 
 /* For Linux we can use the system call table in the header file
 	/usr/include/asm/unistd.h
--- libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h	4 Oct 2004 20:59:34 -0000	1.16
+++ libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h	5 Oct 2004 11:23:19 -0000	1.14.2.3
@@ -23,6 +23,7 @@
 
 #include <sysdeps/s390/s390-64/sysdep.h>
 #include <sysdeps/unix/sysdep.h>
+#include <dl-sysdep.h>	/* For RTLD_PRIVATE_ERRNO.  */
 
 /* For Linux we can use the system call table in the header file
 	/usr/include/asm/unistd.h

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix s390{,x} build
@ 2004-03-11  9:40 Martin Schwidefsky
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Schwidefsky @ 2004-03-11  9:40 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers





Hi Jakub,
> The recent dl-tls.c -> dl-sym.c reshuffling broke s390*.
> Here is a fix, verified so far with doing dlsym on a STT_TLS symbol
> in a shared library.

I was just trying to get this fixed myself. Jakub was (again) faster and
his solution is better than mine. My solution exports __tls_get_addr as
second interface which isn't nice. The __tls_get_offset should be the
only interface because __tls_get_addr doesn't return the address to the
variable but the offset of the variable to the thread pointer. This can
be very confusing.

blue skies,
   Martin

Linux/390 Design & Development, IBM Deutschland Entwicklung GmbH
Schönaicherstr. 220, D-71032 Böblingen, Telefon: 49 - (0)7031 - 16-2247
E-Mail: schwidefsky@de.ibm.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix s390{,x} build
  2004-03-11  9:17 Jakub Jelinek
@ 2004-03-11  9:39 ` Ulrich Drepper
  0 siblings, 0 replies; 5+ messages in thread
From: Ulrich Drepper @ 2004-03-11  9:39 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

Applied.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Fix s390{,x} build
@ 2004-03-11  9:17 Jakub Jelinek
  2004-03-11  9:39 ` Ulrich Drepper
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2004-03-11  9:17 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

The recent dl-tls.c -> dl-sym.c reshuffling broke s390*.
Here is a fix, verified so far with doing dlsym on a STT_TLS symbol
in a shared library.

2004-03-11  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/s390/dl-tls.h: Only add __tls_get_offset assembly if
	IS_IN_rtld.
	(__TLS_GET_ADDR): Use __tls_get_offset, not __tls_get_addr.

--- libc/sysdeps/s390/dl-tls.h.jj	2003-01-28 11:34:02.000000000 +0100
+++ libc/sysdeps/s390/dl-tls.h	2004-03-11 09:47:56.536933703 +0100
@@ -1,5 +1,5 @@
 /* Thread-local storage handling in the ELF dynamic linker.  s390 version.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004 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
@@ -31,6 +31,7 @@ typedef struct
 extern void *__tls_get_addr (tls_index *ti) attribute_hidden;
 extern unsigned long __tls_get_offset (unsigned long got_offset);
 
+# ifdef IS_IN_rtld
 /* The special thing about the s390 TLS ABI is that we do not have the
    standard __tls_get_addr function but the __tls_get_offset function
    which differs in two important aspects:
@@ -39,7 +40,7 @@ extern unsigned long __tls_get_offset (u
    2) __tls_get_offset returns the offset of the requested variable to
       the thread descriptor instead of a pointer to the variable.
  */
-#if defined __s390x__
+#  if defined __s390x__
 asm("\n\
 	.text\n\
 	.globl __tls_get_offset\n\
@@ -49,7 +50,7 @@ __tls_get_offset:\n\
 	la	%r2,0(%r2,%r12)\n\
 	jg	__tls_get_addr\n\
 ");
-#elif defined __s390__
+#  elif defined __s390__
 asm("\n\
 	.text\n\
 	.globl __tls_get_offset\n\
@@ -62,12 +63,15 @@ __tls_get_offset:\n\
 	b	0(%r4,%r3)\n\
 1:	.long	__tls_get_addr - 0b\n\
 ");
-#endif
+#  endif
+# endif
 
-#define GET_ADDR_OFFSET \
+# define GET_ADDR_OFFSET \
   (ti->ti_offset - (unsigned long) __builtin_thread_pointer ())
 
-#define __TLS_GET_ADDR(__ti) \
-  (__tls_get_addr(__ti) + (unsigned long) __builtin_thread_pointer ())
+# define __TLS_GET_ADDR(__ti) \
+  ({ extern char _GLOBAL_OFFSET_TABLE_[] attribute_hidden;		  \
+     (void *) __tls_get_offset ((char *) (__ti) - _GLOBAL_OFFSET_TABLE_)  \
+     + (unsigned long) __builtin_thread_pointer (); }) 
 
 #endif

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-05-29 17:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-29 17:11 [PATCH] Fix s390{,x} build Jakub Jelinek
  -- strict thread matches above, loose matches on Subject: below --
2004-10-05 15:31 Jakub Jelinek
2004-03-11  9:40 Martin Schwidefsky
2004-03-11  9:17 Jakub Jelinek
2004-03-11  9:39 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).