From: Christopher Clark Date: Tue, 25 Sep 2018 14:30:32 +0000 (+0200) Subject: fuzz, test x86_emulator: disable sse before including always_inline fns X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~3234 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=e8dfbc2962365ffa3d7ddcacaa5baaf4ed24b2af;p=xen.git fuzz, test x86_emulator: disable sse before including always_inline fns Workaround for compiler rejection of SSE-using always_inlines defined before SSE is disabled. Compiling with _FORTIFY_SOURCE or higher levels of optimization enabled will always_inline several library fns (memset, memcpy, ...) (with gcc 8.2.0 and glibc 2.28). In fuzz and x86_emulator test, the compiler is instructed not to generate SSE instructions via: #pragma GCC target("no-sse") because those registers are needed for use by the workload. The combination above causes compilation failure as the inline functions use those instructions. This is resolved by reordering the inclusion of and to after the pragma disabling SSE generation. It would be preferable to locate the no-sse pragma within x86-emulate.h at the top of the file, prior to including any other headers; unfortunately doing so before causes compilation failure due to declaration of 'atof' with: "SSE register return with SSE disabled". Fortunately there is no (known) current dependency on any always_inline SSE-inclined function declared in or any of its dependencies, so the pragma is therefore issued immediately after inclusion of with a comment introduced to explain its location there. Add compile-time checks for unwanted prior inclusion of and , which are the two headers that provide the library functions that are handled with wrappers and listed within "x86-emulate.h" as ones "we think might access any of the FPU state". * Use standard-defined "EOF" macro to detect prior inclusion. * Use "_STRING_H" (non-standardized guard macro) as best-effort for detection of prior inclusion. This is non-universally viable but will provide error output on common GLIBC systems, so provides some defensive coverage. Adds conditional #include to x86-emulate.h because fwrite, printf, etc. are referenced when WRAP has been defined. Signed-off-by: Christopher Clark Reviewed-by: Jan Beulich --- diff --git a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c index 03a2473cdb..0ffd0fbfe1 100644 --- a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c +++ b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c @@ -6,9 +6,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -16,6 +14,14 @@ #include #include "x86-emulate.h" +/* + * include "x86-emulate.h" prior to and : + * x86-emulate.h disables use of SSE registers, while and + * declare functions that may be always_inline and use those registers + * unless they have been disabled earlier, which can fail to compile. + */ +#include +#include #include "fuzz-emul.h" #define MSR_INDEX_MAX 16 diff --git a/tools/tests/x86_emulator/wrappers.c b/tools/tests/x86_emulator/wrappers.c index d02013c4b1..eba7cc93c5 100644 --- a/tools/tests/x86_emulator/wrappers.c +++ b/tools/tests/x86_emulator/wrappers.c @@ -1,5 +1,4 @@ #include -#include #define WRAP(x) typeof(x) emul_##x #include "x86-emulate.h" diff --git a/tools/tests/x86_emulator/x86-emulate.h b/tools/tests/x86_emulator/x86-emulate.h index b249e4673c..08dead32fd 100644 --- a/tools/tests/x86_emulator/x86-emulate.h +++ b/tools/tests/x86_emulator/x86-emulate.h @@ -3,10 +3,34 @@ #include #include #include +/* + * Use of sse registers must be disabled prior to the definition of + * always_inline functions that would use them (memcpy, memset, etc), + * so do this as early as possible, aiming to be before any always_inline + * functions that are used are declared. + * Unfortunately, this cannot be done prior to inclusion of + * due to functions such as 'atof' that have SSE register return declared, + * so do so here, immediately after that. + */ +#if __GNUC__ >= 6 +# pragma GCC target("no-sse") +#endif + /* + * Attempt detection of unwanted prior inclusion of some headers known to use + * always_inline with SSE registers in some library / compiler / optimization + * combinations. + */ +#ifdef _STRING_H +# error "Must not include before x86-emulate.h" +#endif #include -#if __GNUC__ >= 6 -#pragma GCC target("no-sse") +/* EOF is a standard macro defined in so use it for detection */ +#ifdef EOF +# error "Must not include before x86-emulate.h" +#endif +#ifdef WRAP +# include #endif #include