1 | /* PLT trampolines. x86-64 version. |
2 | Copyright (C) 2004-2016 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 <link-defines.h> |
22 | |
23 | #ifndef DL_STACK_ALIGNMENT |
24 | /* Due to GCC bug: |
25 | |
26 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066 |
27 | |
28 | __tls_get_addr may be called with 8-byte stack alignment. Although |
29 | this bug has been fixed in GCC 4.9.4, 5.3 and 6, we can't assume |
30 | that stack will be always aligned at 16 bytes. We use unaligned |
31 | 16-byte move to load and store SSE registers, which has no penalty |
32 | on modern processors if stack is 16-byte aligned. */ |
33 | # define DL_STACK_ALIGNMENT 8 |
34 | #endif |
35 | |
36 | #ifndef DL_RUNTIME_UNALIGNED_VEC_SIZE |
37 | /* The maximum size in bytes of unaligned vector load and store in the |
38 | dynamic linker. Since SSE optimized memory/string functions with |
39 | aligned SSE register load and store are used in the dynamic linker, |
40 | we must set this to 8 so that _dl_runtime_resolve_sse will align the |
41 | stack before calling _dl_fixup. */ |
42 | # define DL_RUNTIME_UNALIGNED_VEC_SIZE 8 |
43 | #endif |
44 | |
45 | /* True if _dl_runtime_resolve should align stack to VEC_SIZE bytes. */ |
46 | #define DL_RUNTIME_RESOLVE_REALIGN_STACK \ |
47 | (VEC_SIZE > DL_STACK_ALIGNMENT \ |
48 | && VEC_SIZE > DL_RUNTIME_UNALIGNED_VEC_SIZE) |
49 | |
50 | /* Align vector register save area to 16 bytes. */ |
51 | #define REGISTER_SAVE_VEC_OFF 0 |
52 | |
53 | /* Area on stack to save and restore registers used for parameter |
54 | passing when calling _dl_fixup. */ |
55 | #ifdef __ILP32__ |
56 | # define REGISTER_SAVE_RAX (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 8) |
57 | # define PRESERVE_BND_REGS_PREFIX |
58 | #else |
59 | /* Align bound register save area to 16 bytes. */ |
60 | # define REGISTER_SAVE_BND0 (REGISTER_SAVE_VEC_OFF + VEC_SIZE * 8) |
61 | # define REGISTER_SAVE_BND1 (REGISTER_SAVE_BND0 + 16) |
62 | # define REGISTER_SAVE_BND2 (REGISTER_SAVE_BND1 + 16) |
63 | # define REGISTER_SAVE_BND3 (REGISTER_SAVE_BND2 + 16) |
64 | # define REGISTER_SAVE_RAX (REGISTER_SAVE_BND3 + 16) |
65 | # ifdef HAVE_MPX_SUPPORT |
66 | # define PRESERVE_BND_REGS_PREFIX bnd |
67 | # else |
68 | # define PRESERVE_BND_REGS_PREFIX .byte 0xf2 |
69 | # endif |
70 | #endif |
71 | #define REGISTER_SAVE_RCX (REGISTER_SAVE_RAX + 8) |
72 | #define REGISTER_SAVE_RDX (REGISTER_SAVE_RCX + 8) |
73 | #define REGISTER_SAVE_RSI (REGISTER_SAVE_RDX + 8) |
74 | #define REGISTER_SAVE_RDI (REGISTER_SAVE_RSI + 8) |
75 | #define REGISTER_SAVE_R8 (REGISTER_SAVE_RDI + 8) |
76 | #define REGISTER_SAVE_R9 (REGISTER_SAVE_R8 + 8) |
77 | |
78 | #define RESTORE_AVX |
79 | |
80 | #define VEC_SIZE 64 |
81 | #define VMOVA vmovdqa64 |
82 | #if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
83 | # define VMOV vmovdqa64 |
84 | #else |
85 | # define VMOV vmovdqu64 |
86 | #endif |
87 | #define VEC(i) zmm##i |
88 | #define _dl_runtime_resolve _dl_runtime_resolve_avx512 |
89 | #define _dl_runtime_profile _dl_runtime_profile_avx512 |
90 | #include "dl-trampoline.h" |
91 | #undef _dl_runtime_resolve |
92 | #undef _dl_runtime_profile |
93 | #undef VEC |
94 | #undef VMOV |
95 | #undef VMOVA |
96 | #undef VEC_SIZE |
97 | |
98 | #define VEC_SIZE 32 |
99 | #define VMOVA vmovdqa |
100 | #if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
101 | # define VMOV vmovdqa |
102 | #else |
103 | # define VMOV vmovdqu |
104 | #endif |
105 | #define VEC(i) ymm##i |
106 | #define _dl_runtime_resolve _dl_runtime_resolve_avx |
107 | #define _dl_runtime_profile _dl_runtime_profile_avx |
108 | #include "dl-trampoline.h" |
109 | #undef _dl_runtime_resolve |
110 | #undef _dl_runtime_profile |
111 | #undef VEC |
112 | #undef VMOV |
113 | #undef VMOVA |
114 | #undef VEC_SIZE |
115 | |
116 | /* movaps/movups is 1-byte shorter. */ |
117 | #define VEC_SIZE 16 |
118 | #define VMOVA movaps |
119 | #if DL_RUNTIME_RESOLVE_REALIGN_STACK || VEC_SIZE <= DL_STACK_ALIGNMENT |
120 | # define VMOV movaps |
121 | #else |
122 | # define VMOV movups |
123 | #endif |
124 | #define VEC(i) xmm##i |
125 | #define _dl_runtime_resolve _dl_runtime_resolve_sse |
126 | #define _dl_runtime_profile _dl_runtime_profile_sse |
127 | #undef RESTORE_AVX |
128 | #include "dl-trampoline.h" |
129 | |