public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Move __fortify_fail call out of line in x86 ____longjmp_chk
@ 2011-04-08 12:25 Andreas Schwab
  2011-04-08 12:48 ` Ulrich Drepper
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2011-04-08 12:25 UTC (permalink / raw)
  To: libc-hacker

2011-04-08  Andreas Schwab  <schwab@redhat.com>

	* sysdeps/unix/sysv/linux/i386/____longjmp_chk.S: Move call to
	__fortify_fail out of line.
	* sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S: Likewise.
---
 sysdeps/unix/sysv/linux/i386/____longjmp_chk.S   |   45 +++++++++-----------
 sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S |   48 ++++++++-------------
 2 files changed, 39 insertions(+), 54 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
index a07e6c8..4dc828e 100644
--- a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001,2004,2005,2006,2009 Free Software Foundation, Inc.
+/* Copyright (C) 2001,2004,2005,2006,2009,2011 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
@@ -20,26 +20,6 @@
 #include <jmpbuf-offsets.h>
 #include <asm-syntax.h>
 
-
-	.section .rodata.str1.1,"aMS",@progbits,1
-	.type	longjmp_msg,@object
-longjmp_msg:
-	.string "longjmp causes uninitialized stack frame"
-	.size	longjmp_msg, .-longjmp_msg
-
-
-#ifdef PIC
-# define CALL_FAIL	movl	%ebx, %ecx;				      \
-			cfi_register(%ebx,%ecx);			      \
-			LOAD_PIC_REG (bx);				      \
-			leal	longjmp_msg@GOTOFF(%ebx), %eax;		      \
-			call	__GI___fortify_fail@PLT
-#else
-# define CALL_FAIL	movl	$longjmp_msg, %eax;			      \
-			call	__fortify_fail
-#endif
-
-
 	.text
 ENTRY (____longjmp_chk)
 	movl	4(%esp), %ecx	/* User's jmp_buf in %ecx.  */
@@ -71,11 +51,10 @@ ENTRY (____longjmp_chk)
 	addl	8(%esp), %eax
 	subl	%edi, %eax
 	cmpl	8(%esp), %eax
-	jae	.Lok2
-
-.Lfail:	CALL_FAIL
+	jb	.Lfail
 
 .Lok2:	addl	$12, %esp
+	cfi_remember_state
 	cfi_adjust_cfa_offset(-12)
 	movl	4(%esp), %ecx
 
@@ -103,4 +82,22 @@ ENTRY (____longjmp_chk)
 
 	/* Jump to saved PC.  */
 	jmp	*%edx
+
+	.section .rodata.str1.1,"aMS",@progbits,1
+.Llongjmp_msg:
+	.string "longjmp causes uninitialized stack frame"
+
+	.text
+.Lfail:	cfi_restore_state
+
+#ifdef PIC
+	movl	%ebx, %ecx
+	cfi_register (%ebx, %ecx)
+	LOAD_PIC_REG (bx)
+	leal	.Llongjmp_msg@GOTOFF(%ebx), %eax
+#else
+	movl	$.Llongjmp_msg, %eax
+#endif
+	call	HIDDEN_JUMPTARGET(__fortify_fail)
+
 END (____longjmp_chk)
diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
index 3881082..63ff282 100644
--- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
@@ -20,33 +20,6 @@
 #include <jmpbuf-offsets.h>
 #include <asm-syntax.h>
 
-	.section .rodata.str1.1,"aMS",@progbits,1
-	.type	longjmp_msg,@object
-longjmp_msg:
-	.string "longjmp causes uninitialized stack frame"
-	.size	longjmp_msg, .-longjmp_msg
-
-
-//#define __longjmp ____longjmp_chk
-
-#ifdef PIC
-# define CALL_FAIL	subq	$8, %rsp;				      \
-			cfi_remember_state;				      \
-			cfi_def_cfa_offset(16);				      \
-			leaq	longjmp_msg(%rip), %rdi;		      \
-			call	__GI___fortify_fail;			      \
-			nop;						      \
-			cfi_restore_state
-#else
-# define CALL_FAIL	subq	$8, %rsp;				      \
-			cfi_remember_state;				      \
-			cfi_def_cfa_offset(16);				      \
-			movq	$longjmp_msg, %rdi;			      \
-			call	__fortify_fail;				      \
-			nop;						      \
-			cfi_restore_state
-#endif
-
 /* Jump to the position specified by ENV, causing the
    setjmp call there to return VAL, or 1 if VAL is 0.
    void __longjmp (__jmp_buf env, int val).  */
@@ -85,11 +58,10 @@ ENTRY(____longjmp_chk)
 	addq	-8(%rsp), %rax
 	subq	%r8, %rax
 	cmpq	-8(%rsp), %rax
-	jae	.Lok2
-
-.Lfail:	CALL_FAIL
+	jb	.Lfail
 
 .Lok2:	movq	%r10, %rdi
+	cfi_remember_state
 	cfi_restore (%rdi)
 	movl	%ebx, %esi
 	cfi_restore (%rsi)
@@ -114,4 +86,20 @@ ENTRY(____longjmp_chk)
 	movq	%r8,%rsp
 	movq	%r9,%rbp
 	jmpq	*%rdx
+
+	.section .rodata.str1.1,"aMS",@progbits,1
+.Llongjmp_msg:
+	.string "longjmp causes uninitialized stack frame"
+
+	.text
+.Lfail:	cfi_restore_state
+	subq	$8, %rsp
+	cfi_def_cfa_offset (16)
+#ifdef PIC
+	leaq	.Llongjmp_msg(%rip), %rdi
+#else
+	movq	$.Llongjmp_msg, %rdi
+#endif
+	call	HIDDEN_JUMPTARGET(__fortify_fail)
+
 END (____longjmp_chk)
-- 
1.7.4.2


-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

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

end of thread, other threads:[~2011-04-08 13:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-08 12:25 [PATCH] Move __fortify_fail call out of line in x86 ____longjmp_chk Andreas Schwab
2011-04-08 12:48 ` Ulrich Drepper
2011-04-08 12:57   ` Andreas Schwab
2011-04-08 13:04     ` 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).