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