[Gmp-commit] /var/hg/gmp: Properly support PIC code in x86_64 code with jump ...
mercurial at gmplib.org
mercurial at gmplib.org
Wed Dec 12 22:54:01 CET 2012
details: /var/hg/gmp/rev/82cac642c646
changeset: 15177:82cac642c646
user: Torbjorn Granlund <tege at gmplib.org>
date: Wed Dec 12 22:53:54 2012 +0100
description:
Properly support PIC code in x86_64 code with jump tables.
diffstat:
ChangeLog | 13 +++++++++++--
mpn/x86_64/darwin.m4 | 7 ++++++-
mpn/x86_64/dos64.m4 | 4 ++++
mpn/x86_64/mod_34lsub1.asm | 29 ++++++++++++++++-------------
mpn/x86_64/mullo_basecase.asm | 33 +++++++++++++++++++--------------
mpn/x86_64/sqr_basecase.asm | 26 ++++++++++++++++----------
mpn/x86_64/x86_64-defs.m4 | 4 ++++
7 files changed, 76 insertions(+), 40 deletions(-)
diffs (197 lines):
diff -r c5001c11c266 -r 82cac642c646 ChangeLog
--- a/ChangeLog Tue Dec 11 13:29:22 2012 +0100
+++ b/ChangeLog Wed Dec 12 22:53:54 2012 +0100
@@ -1,7 +1,16 @@
+2012-12-12 Torbjorn Granlund <tege at gmplib.org>
+
+ * Version 5.1.0 released.
+
+ * mpn/x86_64/x86_64-defs.m4 (JMPENT): New macro.
+ * mpn/x86_64/dos64.m4: Likewise.
+ * mpn/x86_64/darwin.m4: Likewise.
+ * mpn/x86_64/mod_34lsub1.asm: Use JMPENT to properly support PIC.
+ * mpn/x86_64/mullo_basecase.asm: Likewise.
+ * mpn/x86_64/sqr_basecase.asm: Likewise.
+
2012-12-11 Torbjorn Granlund <tege at gmplib.org>
- * Version 5.1.0 released.
-
* mpn/x86_64/mod_34lsub1.asm: Try different jump table for the benefit
of broken Apple linkers.
diff -r c5001c11c266 -r 82cac642c646 mpn/x86_64/darwin.m4
--- a/mpn/x86_64/darwin.m4 Tue Dec 11 13:29:22 2012 +0100
+++ b/mpn/x86_64/darwin.m4 Wed Dec 12 22:53:54 2012 +0100
@@ -32,8 +32,13 @@
define(`CALL',`call GSYM_PREFIX`'$1')
-define(`JUMPTABSECT', `DATA')
+define(`JUMPTABSECT', `RODATA')
+ifdef(`PIC',
+ `define(`JMPENT',
+ `.set $1_tmp, $1-$2
+ .long $1_tmp')',
+ `define(`JMPENT', `.quad $1')')
dnl Target ABI macros. For Darwin we override IFELF (and leave default for
dnl IFDOS and IFSTD).
diff -r c5001c11c266 -r 82cac642c646 mpn/x86_64/dos64.m4
--- a/mpn/x86_64/dos64.m4 Tue Dec 11 13:29:22 2012 +0100
+++ b/mpn/x86_64/dos64.m4 Wed Dec 12 22:53:54 2012 +0100
@@ -24,6 +24,10 @@
define(`JUMPTABSECT', `RODATA')
+ifdef(`PIC',
+ `define(`JMPENT', `.long $1-$2')',
+ `define(`JMPENT', `.quad $1')')
+
dnl Usage: FUNC_ENTRY(nregparmas)
dnl Usage: FUNC_EXIT()
diff -r c5001c11c266 -r 82cac642c646 mpn/x86_64/mod_34lsub1.asm
--- a/mpn/x86_64/mod_34lsub1.asm Tue Dec 11 13:29:22 2012 +0100
+++ b/mpn/x86_64/mod_34lsub1.asm Wed Dec 12 22:53:54 2012 +0100
@@ -103,24 +103,27 @@
jnc L(top)
L(end):
-C Handle 0-8 remaining limbs. The switch code here is zany in an attempt to
-C fit the tiny envelope of code that triggers no Apple bugs
lea L(tab)(%rip), %r8
+ifdef(`PIC',
+` movslq 36(%r8,%rsi,4), %r10
+ add %r10, %r8
+ jmp *%r8
+',`
jmp *72(%r8,%rsi,8)
-
+')
JUMPTABSECT
ALIGN(8)
-L(tab): .quad L(0)
- .quad L(1)
- .quad L(2)
- .quad L(3)
- .quad L(4)
- .quad L(5)
- .quad L(6)
- .quad L(7)
- .quad L(8)
+L(tab): JMPENT( L(0), L(tab))
+ JMPENT( L(1), L(tab))
+ JMPENT( L(2), L(tab))
+ JMPENT( L(3), L(tab))
+ JMPENT( L(4), L(tab))
+ JMPENT( L(5), L(tab))
+ JMPENT( L(6), L(tab))
+ JMPENT( L(7), L(tab))
+ JMPENT( L(8), L(tab))
+ TEXT
- TEXT
L(6): add (ap), %rax
adc 8(ap), %rcx
adc 16(ap), %rdx
diff -r c5001c11c266 -r 82cac642c646 mpn/x86_64/mullo_basecase.asm
--- a/mpn/x86_64/mullo_basecase.asm Tue Dec 11 13:29:22 2012 +0100
+++ b/mpn/x86_64/mullo_basecase.asm Wed Dec 12 22:53:54 2012 +0100
@@ -64,23 +64,28 @@
mov (up), %rax C u0
mov (vp_param), %r8 C v0
- lea L(jmptab)(%rip), %r9
+ lea L(tab)(%rip), %r9
+ifdef(`PIC',
+` movslq (%r9,%rcx,4), %r10
+ add %r10, %r9
+ jmp *%r9
+',`
jmp *(%r9,n,8)
+')
JUMPTABSECT
ALIGN(8)
-L(jmptab):
- .quad 0 C not allowed
- .quad L(1) C 1
- .quad L(2) C 2
- .quad L(3) C 3
-C .quad L(0m4) C 4
-C .quad L(1m4) C 5
-C .quad L(2m4) C 6
-C .quad L(3m4) C 7
-C .quad L(0m4) C 8
-C .quad L(1m4) C 9
-C .quad L(2m4) C 10
-C .quad L(3m4) C 11
+L(tab): JMPENT( L(tab), L(tab)) C not allowed
+ JMPENT( L(1), L(tab)) C 1
+ JMPENT( L(2), L(tab)) C 2
+ JMPENT( L(3), L(tab)) C 3
+dnl JMPENT( L(0m4), L(tab)) C 4
+dnl JMPENT( L(1m4), L(tab)) C 5
+dnl JMPENT( L(2m4), L(tab)) C 6
+dnl JMPENT( L(3m4), L(tab)) C 7
+dnl JMPENT( L(0m4), L(tab)) C 8
+dnl JMPENT( L(1m4), L(tab)) C 9
+dnl JMPENT( L(2m4), L(tab)) C 10
+dnl JMPENT( L(3m4), L(tab)) C 11
TEXT
L(1): imul %r8, %rax
diff -r c5001c11c266 -r 82cac642c646 mpn/x86_64/sqr_basecase.asm
--- a/mpn/x86_64/sqr_basecase.asm Tue Dec 11 13:29:22 2012 +0100
+++ b/mpn/x86_64/sqr_basecase.asm Wed Dec 12 22:53:54 2012 +0100
@@ -99,19 +99,25 @@
mov %r14, (%rsp)
cmovg %r8, %rcx
- lea L(jmptab)(%rip), %rax
+
+ lea L(tab)(%rip), %rax
+ifdef(`PIC',
+` movslq (%rax,%rcx,4), %r10
+ add %r10, %rax
+ jmp *%rax
+',`
jmp *(%rax,%rcx,8)
+')
JUMPTABSECT
ALIGN(8)
-L(jmptab):
- .quad L(4)
- .quad L(1)
- .quad L(2)
- .quad L(3)
- .quad L(0m4)
- .quad L(1m4)
- .quad L(2m4)
- .quad L(3m4)
+L(tab): JMPENT( L(4), L(tab))
+ JMPENT( L(1), L(tab))
+ JMPENT( L(2), L(tab))
+ JMPENT( L(3), L(tab))
+ JMPENT( L(0m4), L(tab))
+ JMPENT( L(1m4), L(tab))
+ JMPENT( L(2m4), L(tab))
+ JMPENT( L(3m4), L(tab))
TEXT
L(1): mov (up), %rax
diff -r c5001c11c266 -r 82cac642c646 mpn/x86_64/x86_64-defs.m4
--- a/mpn/x86_64/x86_64-defs.m4 Tue Dec 11 13:29:22 2012 +0100
+++ b/mpn/x86_64/x86_64-defs.m4 Wed Dec 12 22:53:54 2012 +0100
@@ -187,6 +187,10 @@
define(`JUMPTABSECT', `.section .data.rel.ro.local,"aw", at progbits')
+ifdef(`PIC',
+ `define(`JMPENT', `.long $1-$2')',
+ `define(`JMPENT', `.quad $1')')
+
dnl These macros are defined just for DOS64, where they provide calling
dnl sequence glue code.
More information about the gmp-commit
mailing list