summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@redhat.com>2009-10-19 12:11:48 +0200
committerAndreas Schwab <schwab@redhat.com>2009-10-19 12:11:48 +0200
commitfbfb328dd286def7988de5385d8a237100a73411 (patch)
tree9e8d0e5617dea6400089302d1be1d5f3ca231193
parente9721e1dec0888e02fc4b2bba7b487bec0d26ac8 (diff)
parenta0902db9fe8f4cfc6b0b0344558166f5b230b806 (diff)
downloadglibc-fbfb328dd286def7988de5385d8a237100a73411.tar.gz
glibc-fbfb328dd286def7988de5385d8a237100a73411.tar.xz
glibc-fbfb328dd286def7988de5385d8a237100a73411.zip
Merge remote branch 'origin/master' into fedora/master
-rw-r--r--ChangeLog10
-rw-r--r--csu/elf-init.c12
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S113
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc64/____longjmp_chk.S71
4 files changed, 201 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 7c87d37975..a14cabf7e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-10-14  David S. Miller  <davem@davemloft.net>
+
+	* sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S: New file.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/____longjmp_chk.S: New file.
+
+2009-10-13  Andreas Schwab  <schwab@redhat.com>
+
+	* csu/elf-init.c (__libc_csu_init): Run preinit array even if
+	!USE_MULTIARCH.
+
 2009-10-08  Ulrich Drepper  <drepper@redhat.com>
 
 	[BZ #10730]
diff --git a/csu/elf-init.c b/csu/elf-init.c
index 0ea23c6193..7481e69aa6 100644
--- a/csu/elf-init.c
+++ b/csu/elf-init.c
@@ -97,24 +97,26 @@ __libc_csu_init (int argc, char **argv, char **envp)
   /* For dynamically linked executables the preinit array is executed by
      the dynamic linker (before initializing any shared object.  */
 
-#if defined USE_MULTIARCH && !defined LIBC_NONSHARED
-# ifdef ELF_MACHINE_IRELA
+#ifndef LIBC_NONSHARED
+# ifdef USE_MULTIARCH
+#  ifdef ELF_MACHINE_IRELA
   {
     const size_t size = __rela_iplt_end - __rela_iplt_start;
     for (size_t i = 0; i < size; i++)
       elf_irela (&__rela_iplt_start [i]);
   }
-# endif
+#  endif
 
-# ifdef ELF_MACHINE_IREL
+#  ifdef ELF_MACHINE_IREL
   {
     const size_t size = __rel_iplt_end - __rel_iplt_start;
     for (size_t i = 0; i < size; i++)
       elf_irel (&__rel_iplt_start [i]);
   }
+#  endif
 # endif
 
-  /* For static executables, preinit happens rights before init.  */
+  /* For static executables, preinit happens right before init.  */
   {
     const size_t size = __preinit_array_end - __preinit_array_start;
     size_t i;
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S b/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
new file mode 100644
index 0000000000..0ecd7ddf83
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/____longjmp_chk.S
@@ -0,0 +1,113 @@
+/* Copyright (C) 2009 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <jmpbuf-offsets.h>
+
+#define ENV(base,reg) [%base + (reg * 4)]
+#define ST_FLUSH_WINDOWS 3
+#define RW_FP [%fp + 0x48]
+
+.section .rodata.str1.1,"aMS",@progbits,1
+	.type	longjmp_msg,@object
+longjmp_msg:
+	.string "longjmp causes uninitialized stack frame"
+	.size	longjmp_msg, .-longjmp_msg
+
+	.text
+ENTRY (____longjmp_chk)
+	ld	ENV(o0,JB_SP), %g5
+#ifdef PTR_DEMANGLE
+	PTR_DEMANGLE (%g5, %g5, %g4)
+#endif
+
+	cmp	%sp, %g5
+	bleu	.Lok_norestore
+	 nop
+
+	save	%sp, -80, %sp
+
+	clr	%o0
+	add	%sp, 64, %o1
+	set	__NR_sigaltstack, %g1
+	ta	0x10
+	bcs	.Lok
+	 ld	[%sp + 64 + 4], %o2
+	andcc	%o2, 0x1, %g0
+	be	.Lfail
+	 ld	[%sp + 64 + 0], %o0
+
+	ld	[%sp + 64 + 8], %o1
+	add	%o0, %o1, %o0
+	sub	%o0, %g3, %o0
+	cmp	%o1, %o0
+	bgeu	.Lok
+	 nop
+
+.Lfail:
+#ifdef PIC
+1:	call	2f
+	sethi	%hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7
+2:	or	%l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7
+	add	%l7, %o7, %l7
+#endif
+	sethi	%hi(longjmp_msg), %o0
+	or	%o0, %lo(longjmp_msg), %o0
+#ifdef PIC
+	ld	[%l7 + %o0], %o0
+#endif
+	call	HIDDEN_JUMPTARGET(__fortify_fail)
+	 nop
+
+.Lok:
+	restore
+
+.Lok_norestore:
+	ld	ENV(o0,JB_FP), %g3	/* Cache target FP in register %g3.  */
+#ifdef PTR_DEMANGLE
+	PTR_DEMANGLE2 (%g3, %g3, %g4)
+#endif
+
+	mov %o0, %g1		/* ENV in %g1 */
+	orcc %o1, %g0, %g2	/* VAL in %g2 */
+	be,a 0f			/* Branch if zero; else skip delay slot.  */
+	 mov 1, %g2		/* Delay slot only hit if zero: VAL = 1.  */
+0:
+
+	/*
+	 * Do a "flush register windows trap".  The trap handler in the
+	 * kernel writes all the register windows to their stack slots, and
+	 * marks them all as invalid (needing to be sucked up from the
+	 * stack when used).  This ensures that all information needed to
+	 * unwind to these callers is in memory, not in the register
+	 * windows.
+	 */
+	ta	ST_FLUSH_WINDOWS
+#ifdef PTR_DEMANGLE
+	ld	ENV(g1,JB_PC), %g1 /* Set return PC. */
+	PTR_DEMANGLE2 (%o7, %g1, %g4)
+#else
+	ld	ENV(g1,JB_PC), %o7 /* Set return PC. */
+#endif
+	mov	%g5, %fp
+	sub	%fp, 64, %sp	/* Allocate a register frame. */
+	st	%g3, RW_FP	/* Set saved FP on restore below. */
+	retl
+	 restore %g2, 0, %o0	/* Restore values from above register frame. */
+
+END(____longjmp_chk)
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/sparc/sparc64/____longjmp_chk.S
new file mode 100644
index 0000000000..9a4c8fe3b9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/____longjmp_chk.S
@@ -0,0 +1,71 @@
+/* Copyright (C) 2009 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* longjmp is implemented in terms of the setcontext trap on Linux/Sparc64.  */
+
+#include <sysdep.h>
+
+/* Offsets into the jmp_buf structure.  */
+
+#define O_mask_was_saved	512
+#define O_gregs			32
+#define O_g1			(O_gregs + 4*8)
+#define O_sp			(O_gregs + 17*8)
+
+.section .rodata.str1.1,"aMS",@progbits,1
+	.type	longjmp_msg,@object
+longjmp_msg:
+	.string "longjmp causes uninitialized stack frame"
+	.size	longjmp_msg, .-longjmp_msg
+
+	.text
+ENTRY (____longjmp_chk)
+	ldx	[%o0 + O_sp], %o2
+	cmp	%sp, %o2
+	bleu,pt	%xcc, .Lok
+	 nop
+
+	save	%sp, -128, %sp
+
+#ifdef PIC
+1:	call	2f
+	sethi	%hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7
+2:	or	%l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7
+	add	%l7, %o7, %l7
+#endif
+	sethi	%hi(longjmp_msg), %o0
+	or	%o0, %lo(longjmp_msg), %o0
+#ifdef PIC
+	ldx	[%l7 + %o0], %o0
+#endif
+	call	HIDDEN_JUMPTARGET(__fortify_fail)
+	 nop
+
+	restore
+
+.Lok:
+	/* Modify the context with the value we want to return.  */
+	movre	%o1, 1, %o1
+	stx	%o1, [%o0 + O_g1]
+
+	/* Let setcontext know if we want to modify the current sigmask. */
+	ld	[%o0 + O_mask_was_saved], %o1
+
+	/* And bamf back to where we belong!  */
+	ta	0x6f
+END(____longjmp_chk)