| 1 | /* PLT trampolines. x86-64 version. |
| 2 | Copyright (C) 2004-2017 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <config.h> |
| 20 | #include <sysdep.h> |
| 21 | #include <cpu-features.h> |
| 22 | #include <link-defines.h> |
| 23 | |
| 24 | #ifndef DL_STACK_ALIGNMENT |
| 25 | /* Due to GCC bug: |
| 26 | |
| 27 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066 |
| 28 | |
| 29 | __tls_get_addr may be called with 8-byte stack alignment. Although |
| 30 | this bug has been fixed in GCC 4.9.4, 5.3 and 6, we can't assume |
| 31 | that stack will be always aligned at 16 bytes. We use unaligned |
| 32 | 16-byte move to load and store SSE registers, which has no penalty |
| 33 | on modern processors if stack is 16-byte aligned. */ |
| 34 | # define DL_STACK_ALIGNMENT 8 |
| 35 | #endif |
| 36 | |
| 37 | #ifndef DL_RUNTIME_UNALIGNED_VEC_SIZE |
| 38 | /* The maximum size in bytes of unaligned vector load and store in the |
| 39 | dynamic linker. Since SSE optimized memory/string functions with |
| 40 | aligned SSE register load and store are used in the dynamic linker, |
| 41 | we must set this to 8 so that _dl_runtime_resolve_sse will align the |
| 42 | stack before calling _dl_fixup. */ |
| 43 | # define DL_RUNTIME_UNALIGNED_VEC_SIZE 8 |
| 44 | #endif |
| 45 | |
| 46 | /* True if _dl_runtime_resolve should align stack to VEC_SIZE bytes. */ |
| 47 | #define DL_RUNTIME_RESOLVE_REALIGN_STACK \ |
| 48 | (VEC_SIZE > DL_STACK_ALIGNMENT \ |
| 49 | && VEC_SIZE > DL_RUNTIME_UNALIGNED_VEC_SIZE) |
| 50 | |
| 51 | /* Align vector register save area to 16 bytes. */ |
| 52 | #define REGISTER_SAVE_VEC_OFF 0 |
| 53 | |
| 54 | /* Area on stack to save and restore registers used for parameter |
| 55 | passing when calling _dl_fixup. */ |
| 56 | #ifdef __ILP32__ |
| 57 | # define REGISTER_SAVE_RAX (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 8) |
| 58 | # define PRESERVE_BND_REGS_PREFIX |
| 59 | #else |
| 60 | /* Align bound register save area to 16 bytes. */ |
| 61 | # define REGISTER_SAVE_BND0 (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 8) |
| 62 | # define REGISTER_SAVE_BND1 (REGISTER_SAVE_BND0 + 16) |
| 63 | # define REGISTER_SAVE_BND2 (REGISTER_SAVE_BND1 + 16) |
| 64 | # define REGISTER_SAVE_BND3 (REGISTER_SAVE_BND2 + 16) |
| 65 | # define REGISTER_SAVE_RAX (REGISTER_SAVE_BND3 + 16) |
| 66 | # ifdef HAVE_MPX_SUPPORT |
| 67 | # define PRESERVE_BND_REGS_PREFIX bnd |
| 68 | # else |
| 69 | # define PRESERVE_BND_REGS_PREFIX .byte 0xf2 |
| 70 | # endif |
| 71 | #endif |
| 72 | #define REGISTER_SAVE_RCX (REGISTER_SAVE_RAX + 8) |
| 73 | #define REGISTER_SAVE_RDX (REGISTER_SAVE_RCX + 8) |
| 74 | #define REGISTER_SAVE_RSI (REGISTER_SAVE_RDX + 8) |
| 75 | #define REGISTER_SAVE_RDI (REGISTER_SAVE_RSI + 8) |
| 76 | #define REGISTER_SAVE_R8 (REGISTER_SAVE_RDI + 8) |
| 77 | #define REGISTER_SAVE_R9 (REGISTER_SAVE_R8 + 8) |
| 78 | |
| 79 | #define RESTORE_AVX |
| 80 | |
| 81 | #define VEC_SIZE 64 |
| 82 | #define VMOVA vmovdqa64 |
| 83 | #if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
| 84 | # define VMOV vmovdqa64 |
| 85 | #else |
| 86 | # define VMOV vmovdqu64 |
| 87 | #endif |
| 88 | #define VEC(i) zmm##i |
| 89 | #define _dl_runtime_resolve _dl_runtime_resolve_avx512 |
| 90 | #define _dl_runtime_resolve_opt _dl_runtime_resolve_avx512_opt |
| 91 | #define _dl_runtime_profile _dl_runtime_profile_avx512 |
| 92 | #include "dl-trampoline.h" |
| 93 | #undef _dl_runtime_resolve |
| 94 | #undef _dl_runtime_resolve_opt |
| 95 | #undef _dl_runtime_profile |
| 96 | #undef VEC |
| 97 | #undef VMOV |
| 98 | #undef VMOVA |
| 99 | #undef VEC_SIZE |
| 100 | |
| 101 | #define VEC_SIZE 32 |
| 102 | #define VMOVA vmovdqa |
| 103 | #if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
| 104 | # define VMOV vmovdqa |
| 105 | #else |
| 106 | # define VMOV vmovdqu |
| 107 | #endif |
| 108 | #define VEC(i) ymm##i |
| 109 | #define _dl_runtime_resolve _dl_runtime_resolve_avx |
| 110 | #define _dl_runtime_resolve_opt _dl_runtime_resolve_avx_opt |
| 111 | #define _dl_runtime_profile _dl_runtime_profile_avx |
| 112 | #include "dl-trampoline.h" |
| 113 | #undef _dl_runtime_resolve |
| 114 | #undef _dl_runtime_resolve_opt |
| 115 | #undef _dl_runtime_profile |
| 116 | #undef VEC |
| 117 | #undef VMOV |
| 118 | #undef VMOVA |
| 119 | #undef VEC_SIZE |
| 120 | |
| 121 | /* movaps/movups is 1-byte shorter. */ |
| 122 | #define VEC_SIZE 16 |
| 123 | #define VMOVA movaps |
| 124 | #if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
| 125 | # define VMOV movaps |
| 126 | #else |
| 127 | # define VMOV movups |
| 128 | #endif |
| 129 | #define VEC(i) xmm##i |
| 130 | #define _dl_runtime_resolve _dl_runtime_resolve_sse |
| 131 | #define _dl_runtime_profile _dl_runtime_profile_sse |
| 132 | #undef RESTORE_AVX |
| 133 | #include "dl-trampoline.h" |
| 134 | #undef _dl_runtime_resolve |
| 135 | #undef _dl_runtime_profile |
| 136 | #undef VMOV |
| 137 | #undef VMOVA |
| 138 | |
| 139 | /* Used by _dl_runtime_resolve_avx_opt/_dl_runtime_resolve_avx512_opt |
| 140 | to preserve the full vector registers with zero upper bits. */ |
| 141 | #define VMOVA vmovdqa |
| 142 | #if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
| 143 | # define VMOV vmovdqa |
| 144 | #else |
| 145 | # define VMOV vmovdqu |
| 146 | #endif |
| 147 | #define _dl_runtime_resolve _dl_runtime_resolve_sse_vex |
| 148 | #include "dl-trampoline.h" |
| 149 | |