[Gmp-commit] /home/hgfiles/gmp: 4 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Mon Nov 29 22:07:51 CET 2010


details:   /home/hgfiles/gmp/rev/f6ad7c54bb00
changeset: 13694:f6ad7c54bb00
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Nov 29 16:48:22 2010 +0100
description:
Rewrite x86 calling conventions checking code for code size and to support PIC.

details:   /home/hgfiles/gmp/rev/6fbe7a75ee28
changeset: 13695:6fbe7a75ee28
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Nov 29 21:59:04 2010 +0100
description:
(LEA): Support non-PIC code.

details:   /home/hgfiles/gmp/rev/dc39ce381cbc
changeset: 13696:dc39ce381cbc
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Nov 29 22:06:00 2010 +0100
description:
Rewrite amd64 calling conventions checking code to match calls and returns.

details:   /home/hgfiles/gmp/rev/92083b7f4185
changeset: 13697:92083b7f4185
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Nov 29 22:06:47 2010 +0100
description:
Misc and comment changes.

diffstat:

 ChangeLog           |   12 +++++
 mpn/x86/darwin.m4   |   11 +++-
 mpn/x86/x86-defs.m4 |   15 +++--
 tests/amd64call.asm |  119 +++++++++++++++++++++++++------------------------
 tests/x86call.asm   |  123 +++++++++++++++++++++++++++++++++------------------
 tests/x86check.c    |   54 ++++++++++++++--------
 6 files changed, 204 insertions(+), 130 deletions(-)

diffs (truncated from 527 to 300 lines):

diff -r 3de121797ffd -r 92083b7f4185 ChangeLog
--- a/ChangeLog	Mon Nov 22 22:26:05 2010 +0100
+++ b/ChangeLog	Mon Nov 29 22:06:47 2010 +0100
@@ -1,3 +1,15 @@
+2010-11-29  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpn/x86/x86-defs.m4 (LEA): Support non-PIC code.
+	* mpn/x86/darwin.m4 (LEA): Likewise.
+
+	* tests/amd64call.asm: Rewrite for code size, and to match calls and
+	returns.
+
+	* tests/x86call.asm: Rewrite for code size, to support PIC, and to
+	match calls and returns.
+	* tests/x86check.c: Rewrite.
+
 2010-11-22  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpz/get_str.c: Make all bases either work or return an error.
diff -r 3de121797ffd -r 92083b7f4185 mpn/x86/darwin.m4
--- a/mpn/x86/darwin.m4	Mon Nov 22 22:26:05 2010 +0100
+++ b/mpn/x86/darwin.m4	Mon Nov 29 22:06:47 2010 +0100
@@ -23,9 +23,12 @@
 dnl  FIXME: Only handles one symbol per assembly file because of the
 dnl  way EPILOGUE_cpu is handled.
 
-define(`LEA',`
+define(`LEA',
+m4_assert_numargs(2)
+`ifdef(`PIC',`
 define(`EPILOGUE_cpu',
-`	L(movl_eip_`'substr($2,1)):
+`
+L(movl_eip_`'substr($2,1)):
 	movl	(%esp), $2
 	ret_internal
 	.section __IMPORT,__pointers,non_lazy_symbol_pointers
@@ -35,6 +38,8 @@
 ')
 	call	L(movl_eip_`'substr($2,1))
 	movl	L($1`'$non_lazy_ptr)-.($2), $2
-')
+',`
+	movl	`$'$1, $2
+')')
 
 divert`'dnl
diff -r 3de121797ffd -r 92083b7f4185 mpn/x86/x86-defs.m4
--- a/mpn/x86/x86-defs.m4	Mon Nov 22 22:26:05 2010 +0100
+++ b/mpn/x86/x86-defs.m4	Mon Nov 29 22:06:47 2010 +0100
@@ -928,7 +928,9 @@
 
 dnl  Usage LEA(symbol,reg)
 
-define(`LEA',`
+define(`LEA',
+m4_assert_numargs(2)
+`ifdef(`PIC',`
 define(`EPILOGUE_cpu',
 `
 L(movl_eip_`'substr($2,1)):
@@ -936,11 +938,12 @@
 	ret_internal
 	SIZE($'`1, .-$'`1)')
 
-        call    L(movl_eip_`'substr($2,1))
-        addl    $_GLOBAL_OFFSET_TABLE_, $2
-        movl    $1 at GOT($2), $2
-')
-
+	call	L(movl_eip_`'substr($2,1))
+	addl	$_GLOBAL_OFFSET_TABLE_, $2
+	movl	$1 at GOT($2), $2
+',`
+	movl	`$'$1, $2
+')')
 
 define(`DEF_OBJECT',
 m4_assert_numargs_range(1,2)
diff -r 3de121797ffd -r 92083b7f4185 tests/amd64call.asm
--- a/tests/amd64call.asm	Mon Nov 22 22:26:05 2010 +0100
+++ b/tests/amd64call.asm	Mon Nov 29 22:06:47 2010 +0100
@@ -1,6 +1,6 @@
 dnl  AMD64 calling conventions checking.
 
-dnl  Copyright 2000, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
+dnl  Copyright 2000, 2003, 2004, 2006, 2007, 2010 Free Software Foundation, Inc.
 dnl
 dnl  This file is part of the GNU MP Library.
 dnl
@@ -18,6 +18,9 @@
 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
 
 
+dnl  The current version of the code attempts to keep the call/return
+dnl  prediction stack valid, but matching calls and returns.
+
 include(`../config.m4')
 
 
@@ -37,17 +40,17 @@
 C Execute an fstcw, returning the current x87 control word.
 
 PROLOGUE(x86_fstcw)
-        movq	$0, -8(%rsp)
-        fstcw	-8(%rsp)
-        movq	-8(%rsp), %rax
+	movq	$0, -8(%rsp)
+	fstcw	-8(%rsp)
+	movq	-8(%rsp), %rax
 	ret
 EPILOGUE()
 
 
-dnl  Instrumented profiling won't come out quite right below, since we don't
-dnl  do an actual "ret".  There's only a few instructions here, so there's
-dnl  no great need to get them separately accounted, just let them get
-dnl  attributed to the caller.
+dnl  Instrumented profiling won't come out quite right below, since we don't do
+dnl  an actual "ret".  There's only a few instructions here, so there's no
+dnl  great need to get them separately accounted, just let them get attributed
+dnl  to the caller.  FIXME this comment might no longer be true.
 
 ifelse(WANT_PROFILING,instrument,
 `define(`WANT_PROFILING',no)')
@@ -97,69 +100,67 @@
 	TEXT
 	ALIGN(32)
 PROLOGUE(calling_conventions)
-	push	%rdi
-	movq	G(calling_conventions_values)@GOTPCREL(%rip), %rdi
+	movq	G(calling_conventions_values)@GOTPCREL(%rip), %rax
+	popq	RETADDR(%rax)
 
-	movq	8(%rsp), %rax
-	movq	%rax, RETADDR(%rdi)
+	movq	%rbx, SAVE_RBX(%rax)
+	movq	%rbp, SAVE_RBP(%rax)
+	movq	%r12, SAVE_R12(%rax)
+	movq	%r13, SAVE_R13(%rax)
+	movq	%r14, SAVE_R14(%rax)
+	movq	%r15, SAVE_R15(%rax)
 
-	leaq	L(return)(%rip), %rax
-	movq	%rax, 8(%rsp)
+	C Values we expect to see unchanged, as per amd64check.c
+	movq	WANT_RBX(%rax), %rbx
+	movq	WANT_RBP(%rax), %rbp
+	movq	WANT_R12(%rax), %r12
+	movq	WANT_R13(%rax), %r13
+	movq	WANT_R14(%rax), %r14
+	movq	WANT_R15(%rax), %r15
 
-	movq	%rbx, SAVE_RBX(%rdi)
-	movq	%rbp, SAVE_RBP(%rdi)
-	movq	%r12, SAVE_R12(%rdi)
-	movq	%r13, SAVE_R13(%rdi)
-	movq	%r14, SAVE_R14(%rdi)
-	movq	%r15, SAVE_R15(%rdi)
-
-	C values we expect to see unchanged, as per amd64check.c
-	movq	WANT_RBX(%rdi), %rbx
-	movq	WANT_RBP(%rdi), %rbp
-	movq	WANT_R12(%rdi), %r12
-	movq	WANT_R13(%rdi), %r13
-	movq	WANT_R14(%rdi), %r14
-	movq	WANT_R15(%rdi), %r15
-
-	C Try to provoke a problem by starting with junk in the registers,
-	C especially %rax which will be the return value.
-	C
-	C ENHANCE-ME: If we knew how many of the parameter registers were
-	C actually being used we could put junk in the rest.  Maybe we could
-	C get try.c to communicate this to us.
-C	movq	JUNK_RAX(%rdi), %rax		C overwritten below anyway
-	movq	JUNK_R10(%rdi), %r10
-	movq	JUNK_R11(%rdi), %r11
+	C Try to provoke a problem by starting with junk in the caller-saves
+	C registers, especially %rax which will be the return value.
+C	movq	JUNK_RAX(%rax), %rax		C overwritten below anyway
+	movq	JUNK_R10(%rax), %r10
+	movq	JUNK_R11(%rax), %r11
 
 	movq	G(calling_conventions_function)@GOTPCREL(%rip), %rax
-	pop	%rdi
-	jmp	*(%rax)
+	call	*(%rax)
 
-L(return):
-	movq	G(calling_conventions_values)@GOTPCREL(%rip), %rdi
+	movq	G(calling_conventions_values)@GOTPCREL(%rip), %rcx
 
-	movq	%rbx, RBX(%rdi)
-	movq	%rbp, RBP(%rdi)
-	movq	%r12, R12(%rdi)
-	movq	%r13, R13(%rdi)
-	movq	%r14, R14(%rdi)
-	movq	%r15, R15(%rdi)
+	movq	%rbx, RBX(%rcx)
+	movq	%rbp, RBP(%rcx)
+	movq	%r12, R12(%rcx)
+	movq	%r13, R13(%rcx)
+	movq	%r14, R14(%rcx)
+	movq	%r15, R15(%rcx)
 
 	pushfq
 	popq	%rbx
-	movq	%rbx, RFLAGS(%rdi)
+	movq	%rbx, RFLAGS(%rcx)
 
-	movq	G(calling_conventions_fenv)@GOTPCREL(%rip), %rbx
-	fstenv	(%rbx)
+	movq	SAVE_RBX(%rcx), %rbx
+	movq	SAVE_RBP(%rcx), %rbp
+	movq	SAVE_R12(%rcx), %r12
+	movq	SAVE_R13(%rcx), %r13
+	movq	SAVE_R14(%rcx), %r14
+	movq	SAVE_R15(%rcx), %r15
+
+	C Overwrite parameter registers
+C	mov	JUNK_R9(%rcx), %r9
+C	mov	JUNK_R8(%rcx), %r8
+C	mov	JUNK_RCX(%rcx), %rcx
+C	mov	JUNK_RDX(%rcx), %rdx
+C	mov	JUNK_RSI(%rcx), %rsi
+C	mov	JUNK_RDI(%rcx), %rdi
+
+	pushq	RETADDR(%rcx)
+
+	movq	G(calling_conventions_fenv)@GOTPCREL(%rip), %rcx
+	fstenv	(%rcx)
 	finit
 
-	movq	SAVE_RBX(%rdi), %rbx
-	movq	SAVE_RBP(%rdi), %rbp
-	movq	SAVE_R12(%rdi), %r12
-	movq	SAVE_R13(%rdi), %r13
-	movq	SAVE_R14(%rdi), %r14
-	movq	SAVE_R15(%rdi), %r15
-
-	jmp	*RETADDR(%rdi)
+	ret
 
 EPILOGUE()
diff -r 3de121797ffd -r 92083b7f4185 tests/x86call.asm
--- a/tests/x86call.asm	Mon Nov 22 22:26:05 2010 +0100
+++ b/tests/x86call.asm	Mon Nov 29 22:06:47 2010 +0100
@@ -1,6 +1,6 @@
 dnl  x86 calling conventions checking.
 
-dnl  Copyright 2000, 2003 Free Software Foundation, Inc.
+dnl  Copyright 2000, 2003, 2010 Free Software Foundation, Inc.
 dnl
 dnl  This file is part of the GNU MP Library.
 dnl
@@ -18,6 +18,9 @@
 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
 
 
+dnl  The current version of the code attempts to keep the call/return
+dnl  prediction stack valid, but matching calls and returns.
+
 include(`../config.m4')
 
 
@@ -26,8 +29,8 @@
 C Execute an fldcw, setting the x87 control word to cw.
 
 PROLOGUE(x86_fldcw)
-        fldcw   4(%esp)
-        ret
+	fldcw	4(%esp)
+	ret
 EPILOGUE()
 
 
@@ -36,18 +39,18 @@
 C Execute an fstcw, returning the current x87 control word.
 
 PROLOGUE(x86_fstcw)
-        xorl    %eax, %eax
-        pushl   %eax
-        fstcw   (%esp)
-        popl    %eax
-        ret
+	xorl	%eax, %eax
+	pushl	%eax
+	fstcw	(%esp)
+	popl	%eax
+	ret
 EPILOGUE()
 
 
-dnl  Instrumented profiling doesn't come out quite right below, since we
-dnl  don't do an actual "ret".  There's only a few instructions here, so
-dnl  there's no great need to get them separately accounted, just let them
-dnl  get attributed to the caller.
+dnl  Instrumented profiling doesn't come out quite right below, since we don't
+dnl  do an actual "ret".  There's only a few instructions here, so there's no
+dnl  great need to get them separately accounted, just let them get attributed


More information about the gmp-commit mailing list