diff options
Diffstat (limited to 'recipes-extended/xen/files/xen-disable-sse-before-inlines.patch')
-rw-r--r-- | recipes-extended/xen/files/xen-disable-sse-before-inlines.patch | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/recipes-extended/xen/files/xen-disable-sse-before-inlines.patch b/recipes-extended/xen/files/xen-disable-sse-before-inlines.patch new file mode 100644 index 00000000..54a28ee4 --- /dev/null +++ b/recipes-extended/xen/files/xen-disable-sse-before-inlines.patch | |||
@@ -0,0 +1,140 @@ | |||
1 | From 6d50ae155c0f736aa6239eabf1bc8c8e3704742d Mon Sep 17 00:00:00 2001 | ||
2 | From: Christopher Clark <christopher.w.clark@gmail.com> | ||
3 | Date: Fri, 21 Sep 2018 08:28:02 -0700 | ||
4 | Subject: [PATCH v2] fuzz, test x86_emulator: disable sse before including | ||
5 | always_inline fns | ||
6 | To: xen-devel@lists.xenproject.org, | ||
7 | jbeulich@suse.com | ||
8 | Cc: ian.jackson@eu.citrix.com, | ||
9 | wei.liu2@citrix.com, | ||
10 | andrew.cooper3@citrix.com | ||
11 | |||
12 | Workaround for compiler rejection of SSE-using always_inlines defined before | ||
13 | SSE is disabled. | ||
14 | |||
15 | Compiling with _FORTIFY_SOURCE or higher levels of optimization enabled | ||
16 | will always_inline several library fns (memset, memcpy, ...) | ||
17 | (with gcc 8.2.0 and glibc 2.28). | ||
18 | |||
19 | In fuzz and x86_emulator test, the compiler is instructed not | ||
20 | to generate SSE instructions via: #pragma GCC target("no-sse") | ||
21 | because those registers are needed for use by the workload. | ||
22 | |||
23 | The combination above causes compilation failure as the inline functions | ||
24 | use those instructions. This is resolved by reordering the inclusion of | ||
25 | <stdio.h> and <string.h> to after the pragma disabling SSE generation. | ||
26 | |||
27 | It would be preferable to locate the no-sse pragma within x86-emulate.h at the | ||
28 | top of the file, prior to including any other headers; unfortunately doing so | ||
29 | before <stdlib.h> causes compilation failure due to declaration of 'atof' with: | ||
30 | "SSE register return with SSE disabled". | ||
31 | Fortunately there is no (known) current dependency on any always_inline | ||
32 | SSE-inclined function declared in <stdlib.h> or any of its dependencies, so the | ||
33 | pragma is therefore issued immediately after inclusion of <stdlib.h> with a | ||
34 | comment introduced to explain its location there. | ||
35 | |||
36 | Add compile-time checks for unwanted prior inclusion of <string.h> and | ||
37 | <stdio.h>, which are the two headers that provide the library functions that | ||
38 | are handled with wrappers and listed within "x86-emulate.h" as ones "we think | ||
39 | might access any of the FPU state". | ||
40 | * Use standard-defined "EOF" macro to detect prior <stdio.h> inclusion. | ||
41 | * Use "_STRING_H" (non-standardized guard macro) as best-effort | ||
42 | for detection of prior <string.h> inclusion. This is non-universally | ||
43 | viable but will provide error output on common GLIBC systems, so | ||
44 | provides some defensive coverage. | ||
45 | |||
46 | Adds conditional #include <stdio.h> to x86-emulate.h because fwrite, printf, | ||
47 | etc. are referenced when WRAP has been defined. | ||
48 | |||
49 | Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com> | ||
50 | Reviewed-by: Jan Beulich <jbeulich@suse.com> | ||
51 | --- | ||
52 | tools/fuzz/x86_instruction_emulator/fuzz-emul.c | 10 +++++++-- | ||
53 | tools/tests/x86_emulator/wrappers.c | 1 - | ||
54 | tools/tests/x86_emulator/x86-emulate.h | 28 +++++++++++++++++++++++-- | ||
55 | 3 files changed, 34 insertions(+), 5 deletions(-) | ||
56 | |||
57 | diff --git a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c | ||
58 | index 03a2473..0ffd0fb 100644 | ||
59 | --- a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c | ||
60 | +++ b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c | ||
61 | @@ -6,9 +6,7 @@ | ||
62 | #include <stdbool.h> | ||
63 | #include <stddef.h> | ||
64 | #include <stdint.h> | ||
65 | -#include <stdio.h> | ||
66 | #include <stdlib.h> | ||
67 | -#include <string.h> | ||
68 | #include <sys/types.h> | ||
69 | #include <sys/stat.h> | ||
70 | #include <sys/mman.h> | ||
71 | @@ -16,6 +14,14 @@ | ||
72 | #include <xen/xen.h> | ||
73 | |||
74 | #include "x86-emulate.h" | ||
75 | +/* | ||
76 | + * include "x86-emulate.h" prior to <stdio.h> and <string.h>: | ||
77 | + * x86-emulate.h disables use of SSE registers, while <stdio.h> and <string.h> | ||
78 | + * declare functions that may be always_inline and use those registers | ||
79 | + * unless they have been disabled earlier, which can fail to compile. | ||
80 | + */ | ||
81 | +#include <stdio.h> | ||
82 | +#include <string.h> | ||
83 | #include "fuzz-emul.h" | ||
84 | |||
85 | #define MSR_INDEX_MAX 16 | ||
86 | diff --git a/tools/tests/x86_emulator/wrappers.c b/tools/tests/x86_emulator/wrappers.c | ||
87 | index d02013c..eba7cc9 100644 | ||
88 | --- a/tools/tests/x86_emulator/wrappers.c | ||
89 | +++ b/tools/tests/x86_emulator/wrappers.c | ||
90 | @@ -1,5 +1,4 @@ | ||
91 | #include <stdarg.h> | ||
92 | -#include <stdio.h> | ||
93 | |||
94 | #define WRAP(x) typeof(x) emul_##x | ||
95 | #include "x86-emulate.h" | ||
96 | diff --git a/tools/tests/x86_emulator/x86-emulate.h b/tools/tests/x86_emulator/x86-emulate.h | ||
97 | index b249e46..07ea1e8 100644 | ||
98 | --- a/tools/tests/x86_emulator/x86-emulate.h | ||
99 | +++ b/tools/tests/x86_emulator/x86-emulate.h | ||
100 | @@ -3,11 +3,35 @@ | ||
101 | #include <stddef.h> | ||
102 | #include <stdint.h> | ||
103 | #include <stdlib.h> | ||
104 | -#include <string.h> | ||
105 | - | ||
106 | +/* | ||
107 | + * Use of sse registers must be disabled prior to the definition of | ||
108 | + * always_inline functions that would use them (memcpy, memset, etc), | ||
109 | + * so do this as early as possible, aiming to be before any always_inline | ||
110 | + * functions that are used are declared. | ||
111 | + * Unfortunately, this cannot be done prior to inclusion of <stdlib.h> | ||
112 | + * due to functions such as 'atof' that have SSE register return declared, | ||
113 | + * so do so here, immediately after that. | ||
114 | + */ | ||
115 | #if __GNUC__ >= 6 | ||
116 | #pragma GCC target("no-sse") | ||
117 | #endif | ||
118 | + /* | ||
119 | + * Attempt detection of unwanted prior inclusion of some headers known to use | ||
120 | + * always_inline with SSE registers in some library / compiler / optimization | ||
121 | + * combinations. | ||
122 | + */ | ||
123 | +#ifdef _STRING_H | ||
124 | +#error "Must not include <string.h> before x86-emulate.h" | ||
125 | +#endif | ||
126 | +#include <string.h> | ||
127 | + | ||
128 | +/* EOF is a standard macro defined in <stdio.h> so use it for detection */ | ||
129 | +#ifdef EOF | ||
130 | +#error "Must not include <stdio.h> before x86-emulate.h" | ||
131 | +#endif | ||
132 | +#ifdef WRAP | ||
133 | +#include <stdio.h> | ||
134 | +#endif | ||
135 | |||
136 | #include <xen/xen.h> | ||
137 | |||
138 | -- | ||
139 | 2.1.4 | ||
140 | |||