xentools411: backport upstream commit to work around compilation issue

with GCC>=8 and _FORTIFY_SOURCE.

GCC refuses to inline functions with different target attributes.
SSP headers (upstream GCC and netbsd's) use always_inline.

If we reduce the target options ("no SSE") then it can't inline the
default options (yes SSE) ssp/string.h functions.

PR toolchain/54672
This commit is contained in:
maya 2019-11-03 10:07:16 +00:00
parent 67e3478b1c
commit 5ef0329dd2
2 changed files with 141 additions and 1 deletions

View file

@ -1,4 +1,4 @@
$NetBSD: distinfo,v 1.6 2019/08/30 13:16:27 bouyer Exp $
$NetBSD: distinfo,v 1.7 2019/11/03 10:07:16 maya Exp $
SHA1 (xen411/ipxe-git-356f6c1b64d7a97746d1816cef8ca22bdd8d0b5d.tar.gz) = 272b8c904dc0127690eca2c5c20c67479e40da34
RMD160 (xen411/ipxe-git-356f6c1b64d7a97746d1816cef8ca22bdd8d0b5d.tar.gz) = cfcb4a314c15da19b36132b27126f3bd9699d0e5
@ -12,6 +12,7 @@ SHA1 (patch-.._ipxe_src_core_settings.c) = 1eab2fbd8b22dde2b8aa830ae7701603486f7
SHA1 (patch-.._ipxe_src_net_fcels.c) = eda41b25c3d5f5bef33caa9a6af28c40cb91e66b
SHA1 (patch-Config.mk) = c41005a60de2f94a72b0206030eb021c137653d3
SHA1 (patch-Makefile) = 2f3a5eafc5039b149c98dd5e59c39a3197fd9264
SHA1 (patch-always_inline) = 23201b2b63072e040630525416a0b61280492f93
SHA1 (patch-docs_man_xl-disk-configuration.pod.5) = 03ff4c22dde1e1b60ab8750c8971ea057e479151
SHA1 (patch-docs_man_xl.cfg.pod.5.in) = 951915037a9975b76cc5c41a0e1abe0a202a3696
SHA1 (patch-docs_man_xl.conf.pod.5) = d77e3313750db315d540d7713c95cd54d6f02938

View file

@ -0,0 +1,139 @@
$NetBSD: patch-always_inline,v 1.1 2019/11/03 10:07:17 maya Exp $
Fix compilation issue with GCC>=8 and _FORTIFY_SOURCE.
From e8dfbc2962365ffa3d7ddcacaa5baaf4ed24b2af Mon Sep 17 00:00:00 2001
From: Christopher Clark <christopher.clark6@baesystems.com>
Date: Tue, 25 Sep 2018 16:30:32 +0200
Subject: [PATCH 1/1] 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
<stdio.h> and <string.h> 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 <stdlib.h> 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 <stdlib.h> or any of its dependencies, so the
pragma is therefore issued immediately after inclusion of <stdlib.h> with a
comment introduced to explain its location there.
Add compile-time checks for unwanted prior inclusion of <string.h> and
<stdio.h>, 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 <stdio.h> inclusion.
* Use "_STRING_H" (non-standardized guard macro) as best-effort
for detection of prior <string.h> inclusion. This is non-universally
viable but will provide error output on common GLIBC systems, so
provides some defensive coverage.
Adds conditional #include <stdio.h> to x86-emulate.h because fwrite, printf,
etc. are referenced when WRAP has been defined.
Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
tools/fuzz/x86_instruction_emulator/fuzz-emul.c | 10 +++++++--
tools/tests/x86_emulator/wrappers.c | 1 -
tools/tests/x86_emulator/x86-emulate.h | 28 +++++++++++++++++++++++--
3 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c
index 03a2473cdb..0ffd0fbfe1 100644
--- tools/fuzz/x86_instruction_emulator/fuzz-emul.c.orig
+++ tools/fuzz/x86_instruction_emulator/fuzz-emul.c
@@ -6,9 +6,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -16,6 +14,14 @@
#include <xen/xen.h>
#include "x86-emulate.h"
+/*
+ * include "x86-emulate.h" prior to <stdio.h> and <string.h>:
+ * x86-emulate.h disables use of SSE registers, while <stdio.h> and <string.h>
+ * declare functions that may be always_inline and use those registers
+ * unless they have been disabled earlier, which can fail to compile.
+ */
+#include <stdio.h>
+#include <string.h>
#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
--- tools/tests/x86_emulator/wrappers.c.orig
+++ tools/tests/x86_emulator/wrappers.c
@@ -1,5 +1,4 @@
#include <stdarg.h>
-#include <stdio.h>
#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
--- tools/tests/x86_emulator/x86-emulate.h.orig
+++ tools/tests/x86_emulator/x86-emulate.h
@@ -3,10 +3,34 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
+/*
+ * 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 <stdlib.h>
+ * 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 <string.h> before x86-emulate.h"
+#endif
#include <string.h>
-#if __GNUC__ >= 6
-#pragma GCC target("no-sse")
+/* EOF is a standard macro defined in <stdio.h> so use it for detection */
+#ifdef EOF
+# error "Must not include <stdio.h> before x86-emulate.h"
+#endif
+#ifdef WRAP
+# include <stdio.h>
#endif
#include <xen/xen.h>
--
2.11.0