blob: 614adab27f530611c66a15bfb2c6264b205aeb6d [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From d8b1bb8edd99b2898720b4f10d292a67d532db48 Mon Sep 17 00:00:00 2001
2From: "Francisco Blas Izquierdo Riera (klondike)" <klondike@gentoo.org>
3Date: Mon, 22 Oct 2018 15:29:36 +0800
4Subject: [PATCH 4/4] Fix assemby textrels on rdrand_asm.S on PIC x86
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008
9This patch updates the fixes in the assembly in rdrand_asm.S in
10sys-apps/rng-tools-5 so it won't generate textrels on PIC systems.
11The main fixes are in the use of leal in SETPTR for such systems, the rest is
12the usual PIC support stuff.
13
14This should fix Gentoo bug #469962 and help fix #518210
15
16This patch is released under the GPLv2 or a higher version license as is the
17original file as long as the author and the tester are credited.
18
19Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=469962
20Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=518210
21Signed-off-by: Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org>
22Reported-by: cilly <cilly@cilly.mine.nu>
23Reported-by: Manuel RĂ¼ger <mrueg@gentoo.org>
24Tested-by: Anthony Basile <blueness@gentoo.org>
25
26Upstream-Status: Pending
Brad Bishop19323692019-04-05 15:28:33 -040027---
28 rdrand_asm.S | 27 +++++++++++++++++++++++++++
29 1 file changed, 27 insertions(+)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030
Brad Bishop19323692019-04-05 15:28:33 -040031diff --git a/rdrand_asm.S b/rdrand_asm.S
32index b5d260a..7811cf2 100644
33--- a/rdrand_asm.S
34+++ b/rdrand_asm.S
Brad Bishopd7bf8c12018-02-25 22:55:05 -050035@@ -2,6 +2,7 @@
36 * Copyright (c) 2011-2014, Intel Corporation
37 * Authors: Fenghua Yu <fenghua.yu@intel.com>,
38 * H. Peter Anvin <hpa@linux.intel.com>
39+ * PIC code by: Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org>
40 *
41 * This program is free software; you can redistribute it and/or modify it
42 * under the terms and conditions of the GNU General Public License,
Brad Bishop19323692019-04-05 15:28:33 -040043@@ -172,7 +173,19 @@ ENTRY(x86_rdseed_or_rdrand_bytes)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050044 jmp 4b
45 ENDPROC(x86_rdseed_or_rdrand_bytes)
46
47+#if defined(__PIC__)
48+#define INIT_PIC() \
49+ pushl %ebx ; \
50+ call __x86.get_pc_thunk.bx ; \
51+ addl $_GLOBAL_OFFSET_TABLE_, %ebx
52+#define END_PIC() \
53+ popl %ebx
54+#define SETPTR(var,ptr) leal (var)@GOTOFF(%ebx),ptr
55+#else
56+#define INIT_PIC()
57+#define END_PIC()
58 #define SETPTR(var,ptr) movl $(var),ptr
59+#endif
60 #define PTR0 %eax
61 #define PTR1 %edx
62 #define PTR2 %ecx
Brad Bishop19323692019-04-05 15:28:33 -040063@@ -188,6 +201,7 @@ ENTRY(x86_aes_mangle)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050064 movl 8(%ebp), %eax
65 movl 12(%ebp), %edx
66 push %esi
67+ INIT_PIC()
68 #endif
69 movl $512, CTR3 /* Number of rounds */
70
Brad Bishop19323692019-04-05 15:28:33 -040071@@ -278,6 +292,7 @@ offset = offset + 16
Brad Bishopd7bf8c12018-02-25 22:55:05 -050072 movdqa %xmm7, (7*16)(PTR1)
73
74 #ifdef __i386__
75+ END_PIC()
76 pop %esi
77 pop %ebp
78 #endif
Brad Bishop19323692019-04-05 15:28:33 -040079@@ -292,6 +307,7 @@ ENTRY(x86_aes_expand_key)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050080 push %ebp
81 mov %esp, %ebp
82 movl 8(%ebp), %eax
83+ INIT_PIC()
84 #endif
85
86 SETPTR(aes_round_keys, PTR1)
Brad Bishop19323692019-04-05 15:28:33 -040087@@ -321,6 +337,7 @@ ENTRY(x86_aes_expand_key)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050088 call 1f
89
90 #ifdef __i386__
91+ END_PIC()
92 pop %ebp
93 #endif
94 ret
Brad Bishop19323692019-04-05 15:28:33 -040095@@ -341,6 +358,16 @@ ENTRY(x86_aes_expand_key)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050096
97 ENDPROC(x86_aes_expand_key)
98
99+#if defined(__i386__) && defined(__PIC__)
100+ .section .text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat
101+ .globl __x86.get_pc_thunk.bx
102+ .hidden __x86.get_pc_thunk.bx
103+ .type __x86.get_pc_thunk.bx, @function
104+__x86.get_pc_thunk.bx:
105+ movl (%esp), %ebx
106+ ret
107+#endif
108+
109 .bss
110 .balign 64
111 aes_round_keys:
Brad Bishop19323692019-04-05 15:28:33 -0400112--
1132.7.4
114