summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/rng-tools/rng-tools/rng-tools-5-fix-textrels-on-PIC-x86.patch
blob: 614adab27f530611c66a15bfb2c6264b205aeb6d (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From d8b1bb8edd99b2898720b4f10d292a67d532db48 Mon Sep 17 00:00:00 2001
From: "Francisco Blas Izquierdo Riera (klondike)" <klondike@gentoo.org>
Date: Mon, 22 Oct 2018 15:29:36 +0800
Subject: [PATCH 4/4] Fix assemby textrels on rdrand_asm.S on PIC x86
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch updates the fixes in the assembly in rdrand_asm.S in
sys-apps/rng-tools-5 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 and help fix #518210

This patch is released under the GPLv2 or a higher version license as is the
original file as long as the author and the tester are credited.

Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=469962
Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=518210
Signed-off-by: Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org>
Reported-by: cilly <cilly@cilly.mine.nu>
Reported-by: Manuel Rüger <mrueg@gentoo.org>
Tested-by: Anthony Basile <blueness@gentoo.org>

Upstream-Status: Pending
---
 rdrand_asm.S | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/rdrand_asm.S b/rdrand_asm.S
index b5d260a..7811cf2 100644
--- a/rdrand_asm.S
+++ b/rdrand_asm.S
@@ -2,6 +2,7 @@
  * Copyright (c) 2011-2014, Intel Corporation
  * Authors: Fenghua Yu <fenghua.yu@intel.com>,
  *          H. Peter Anvin <hpa@linux.intel.com>
+ * PIC code by: Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -172,7 +173,19 @@ ENTRY(x86_rdseed_or_rdrand_bytes)
 	jmp	4b
 ENDPROC(x86_rdseed_or_rdrand_bytes)
 
+#if defined(__PIC__)
+#define INIT_PIC() \
+	pushl	%ebx ; \
+	call    __x86.get_pc_thunk.bx ; \
+	addl    $_GLOBAL_OFFSET_TABLE_, %ebx
+#define END_PIC() \
+	popl	%ebx
+#define SETPTR(var,ptr) leal (var)@GOTOFF(%ebx),ptr
+#else
+#define INIT_PIC()
+#define END_PIC()
 #define SETPTR(var,ptr)	movl $(var),ptr
+#endif
 #define PTR0	%eax
 #define PTR1	%edx
 #define PTR2	%ecx
@@ -188,6 +201,7 @@ ENTRY(x86_aes_mangle)
 	movl	8(%ebp), %eax
 	movl	12(%ebp), %edx
 	push	%esi
+	INIT_PIC()
 #endif
 	movl	$512, CTR3	/* Number of rounds */
 	
@@ -278,6 +292,7 @@ offset = offset + 16
 	movdqa	%xmm7, (7*16)(PTR1)
 
 #ifdef __i386__
+	END_PIC()
 	pop	%esi
 	pop	%ebp
 #endif
@@ -292,6 +307,7 @@ ENTRY(x86_aes_expand_key)
 	push	%ebp
 	mov	%esp, %ebp
 	movl	8(%ebp), %eax
+	INIT_PIC()
 #endif
 
 	SETPTR(aes_round_keys, PTR1)
@@ -321,6 +337,7 @@ ENTRY(x86_aes_expand_key)
 	call	1f
 
 #ifdef __i386__
+	END_PIC()
 	pop	%ebp
 #endif
 	ret
@@ -341,6 +358,16 @@ ENTRY(x86_aes_expand_key)
 
 ENDPROC(x86_aes_expand_key)
 
+#if defined(__i386__) && defined(__PIC__)
+	.section	.text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat
+	.globl	__x86.get_pc_thunk.bx
+	.hidden	__x86.get_pc_thunk.bx
+	.type	__x86.get_pc_thunk.bx, @function
+__x86.get_pc_thunk.bx:
+	movl	(%esp), %ebx
+	ret
+#endif
+
 	.bss
 	.balign 64
 aes_round_keys:
-- 
2.7.4