diff options
author | Christopher Clark <christopher.w.clark@gmail.com> | 2018-09-25 10:40:59 -0700 |
---|---|---|
committer | Bruce Ashfield <bruce.ashfield@windriver.com> | 2018-09-25 17:38:10 -0400 |
commit | 55590b65f2de925cdf093210d9a17f3fc745c389 (patch) | |
tree | 4811740f2fcfd3ed7caed558acea2b536a46834d | |
parent | 6f2de77556960d6953aa56fb8e8d876f58fdd583 (diff) | |
download | meta-virtualization-55590b65f2de925cdf093210d9a17f3fc745c389.tar.gz |
xen: fix build with _FORTIFY_SOURCE, gcc 8.2 and glibc 2.28
Apply upstream-reviewed patch to fix compilation.
Patch reorders header includes to issue a pragma to disable SSE before
including any potentially always_inline functions that would use SSE.
Also modify the recipe to supply compiler flags via the tools variables where
they will get used, necessary as _FORTIFY_SOURCE requires optimization flags to
be supplied.
Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
-rw-r--r-- | recipes-extended/xen/files/xen-disable-sse-before-inlines.patch | 140 | ||||
-rw-r--r-- | recipes-extended/xen/xen.inc | 6 | ||||
-rw-r--r-- | recipes-extended/xen/xen_4.11.0.bb | 1 | ||||
-rw-r--r-- | recipes-extended/xen/xen_git.bb | 1 |
4 files changed, 148 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 | |||
diff --git a/recipes-extended/xen/xen.inc b/recipes-extended/xen/xen.inc index bf4b3c28..365f71d9 100644 --- a/recipes-extended/xen/xen.inc +++ b/recipes-extended/xen/xen.inc | |||
@@ -842,6 +842,12 @@ export LDFLAGS="" | |||
842 | # patching the build to be ok with this | 842 | # patching the build to be ok with this |
843 | TUNE_CCARGS := "${@oe.utils.str_filter_out('-mfpmath=sse', '${TUNE_CCARGS}', d)}" | 843 | TUNE_CCARGS := "${@oe.utils.str_filter_out('-mfpmath=sse', '${TUNE_CCARGS}', d)}" |
844 | 844 | ||
845 | # Supply the full set of compiler flags via the tool variables | ||
846 | # Yocto supplys _FORTIFY_SOURCE via CC/CPP/CXX but optimization -O via C*FLAGS | ||
847 | CC_append = " ${CFLAGS}" | ||
848 | CPP_append = " ${CPPFLAGS}" | ||
849 | CXX_append = " ${CXXFLAGS}" | ||
850 | |||
845 | EXTRA_OECONF += " \ | 851 | EXTRA_OECONF += " \ |
846 | --exec-prefix=/usr \ | 852 | --exec-prefix=/usr \ |
847 | --prefix=/usr \ | 853 | --prefix=/usr \ |
diff --git a/recipes-extended/xen/xen_4.11.0.bb b/recipes-extended/xen/xen_4.11.0.bb index 40e73405..b2750667 100644 --- a/recipes-extended/xen/xen_4.11.0.bb +++ b/recipes-extended/xen/xen_4.11.0.bb | |||
@@ -6,6 +6,7 @@ SRC_URI = " \ | |||
6 | file://tools-xentop-vwprintw.patch \ | 6 | file://tools-xentop-vwprintw.patch \ |
7 | file://xen-4.11-arm-acpi-fix-string-lengths.patch \ | 7 | file://xen-4.11-arm-acpi-fix-string-lengths.patch \ |
8 | file://xen-tools-xenpmd-snprintf.patch \ | 8 | file://xen-tools-xenpmd-snprintf.patch \ |
9 | file://xen-disable-sse-before-inlines.patch \ | ||
9 | " | 10 | " |
10 | 11 | ||
11 | SRC_URI[md5sum] = "cbec0600284921744bc14119f4ed3fff" | 12 | SRC_URI[md5sum] = "cbec0600284921744bc14119f4ed3fff" |
diff --git a/recipes-extended/xen/xen_git.bb b/recipes-extended/xen/xen_git.bb index da1eea60..81ee1002 100644 --- a/recipes-extended/xen/xen_git.bb +++ b/recipes-extended/xen/xen_git.bb | |||
@@ -12,6 +12,7 @@ S = "${WORKDIR}/git" | |||
12 | 12 | ||
13 | SRC_URI = " \ | 13 | SRC_URI = " \ |
14 | git://xenbits.xen.org/xen.git;branch=${XEN_BRANCH} \ | 14 | git://xenbits.xen.org/xen.git;branch=${XEN_BRANCH} \ |
15 | file://xen-disable-sse-before-inlines.patch \ | ||
15 | " | 16 | " |
16 | 17 | ||
17 | DEFAULT_PREFERENCE = "-1" | 18 | DEFAULT_PREFERENCE = "-1" |