summaryrefslogtreecommitdiff
blob: 5ff34da861b483c0f21d41791781bf0b85480bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
From: Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org>
Subject: [PATCH] Fix assemby textrels on rdrand_asm.S on PIC x86

This patch fixes the assembly in rdrand_asm.S so it won't generate textrels on PIC systems.
The main fixes are in the use of leal in SETPTR for such systems, the rest is the usual PIC
support stuff.

This should fix Gentoo bug #469962

This patch is released under the GPLv2 or a higher version license as is the original file
as long as reference to the author and the tester are included in the final code.

Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=469962
Upstream-status: Not sent yet
Signed-off-by: Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org>
Reported-by: cilly <cilly@cilly.mine.nu>
Tested-by: Anthony Basile <blueness@gentoo.org>

--- rng-tools/rdrand_asm.S
+++ rng-tools/rdrand_asm.S
@@ -49,6 +49,7 @@
 	ret
 ENDPROC(x86_rdrand_nlong)
 
+#define INIT_PIC()
 #define SETPTR(var,ptr)	leaq var(%rip),ptr
 #define PTR0	%rdi
 #define PTR1	%rsi
@@ -84,7 +85,16 @@
 	ret
 ENDPROC(x86_rdrand_nlong)
 
+#if defined(__PIC__)
+#undef __i686 /* gcc builtin define gets in our way */
+#define INIT_PIC() \
+	call __i686.get_pc_thunk.bx ; \
+	addl $_GLOBAL_OFFSET_TABLE_, %ebx
+#define SETPTR(var,ptr)	leal (var)@GOTOFF(%ebx),ptr
+#else
+#define INIT_PIC()
 #define SETPTR(var,ptr)	movl $(var),ptr
+#endif
 #define PTR0	%eax
 #define PTR1	%edx
 #define PTR2	%ecx
@@ -101,6 +111,7 @@
 	movl	8(%ebp), %eax
 	movl	12(%ebp), %edx
 #endif
+	INIT_PIC()
 
 	SETPTR(aes_round_keys, PTR2)
 
@@ -166,6 +177,17 @@
 #endif
 	ret
 ENDPROC(x86_aes_mangle)
+
+#if defined(__i386__) && defined(__PIC__)
+	.section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
+.globl __i686.get_pc_thunk.bx
+	.hidden  __i686.get_pc_thunk.bx
+	.type    __i686.get_pc_thunk.bx,@function
+__i686.get_pc_thunk.bx:
+	movl (%esp), %ebx
+	ret
+#endif
+
 	/*
 	 * AES round keys for an arbitrary key:
 	 * 00102030405060708090A0B0C0D0E0F0