Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | From d8b1bb8edd99b2898720b4f10d292a67d532db48 Mon Sep 17 00:00:00 2001 |
| 2 | From: "Francisco Blas Izquierdo Riera (klondike)" <klondike@gentoo.org> |
| 3 | Date: Mon, 22 Oct 2018 15:29:36 +0800 |
| 4 | Subject: [PATCH 4/4] Fix assemby textrels on rdrand_asm.S on PIC x86 |
| 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | |
| 9 | This patch updates the fixes in the assembly in rdrand_asm.S in |
| 10 | sys-apps/rng-tools-5 so it won't generate textrels on PIC systems. |
| 11 | The main fixes are in the use of leal in SETPTR for such systems, the rest is |
| 12 | the usual PIC support stuff. |
| 13 | |
| 14 | This should fix Gentoo bug #469962 and help fix #518210 |
| 15 | |
| 16 | This patch is released under the GPLv2 or a higher version license as is the |
| 17 | original file as long as the author and the tester are credited. |
| 18 | |
| 19 | Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=469962 |
| 20 | Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=518210 |
| 21 | Signed-off-by: Francisco Blas Izquierdo Riera (klondike) <klondike@gentoo.org> |
| 22 | Reported-by: cilly <cilly@cilly.mine.nu> |
| 23 | Reported-by: Manuel RĂ¼ger <mrueg@gentoo.org> |
| 24 | Tested-by: Anthony Basile <blueness@gentoo.org> |
| 25 | |
| 26 | Upstream-Status: Pending |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 27 | --- |
| 28 | rdrand_asm.S | 27 +++++++++++++++++++++++++++ |
| 29 | 1 file changed, 27 insertions(+) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 30 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 31 | diff --git a/rdrand_asm.S b/rdrand_asm.S |
| 32 | index b5d260a..7811cf2 100644 |
| 33 | --- a/rdrand_asm.S |
| 34 | +++ b/rdrand_asm.S |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 35 | @@ -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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 43 | @@ -172,7 +173,19 @@ ENTRY(x86_rdseed_or_rdrand_bytes) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 63 | @@ -188,6 +201,7 @@ ENTRY(x86_aes_mangle) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 71 | @@ -278,6 +292,7 @@ offset = offset + 16 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 72 | movdqa %xmm7, (7*16)(PTR1) |
| 73 | |
| 74 | #ifdef __i386__ |
| 75 | + END_PIC() |
| 76 | pop %esi |
| 77 | pop %ebp |
| 78 | #endif |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 79 | @@ -292,6 +307,7 @@ ENTRY(x86_aes_expand_key) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 80 | push %ebp |
| 81 | mov %esp, %ebp |
| 82 | movl 8(%ebp), %eax |
| 83 | + INIT_PIC() |
| 84 | #endif |
| 85 | |
| 86 | SETPTR(aes_round_keys, PTR1) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 87 | @@ -321,6 +337,7 @@ ENTRY(x86_aes_expand_key) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 88 | call 1f |
| 89 | |
| 90 | #ifdef __i386__ |
| 91 | + END_PIC() |
| 92 | pop %ebp |
| 93 | #endif |
| 94 | ret |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 95 | @@ -341,6 +358,16 @@ ENTRY(x86_aes_expand_key) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 96 | |
| 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 112 | -- |
| 113 | 2.7.4 |
| 114 | |