a83cc2
From 40e5138fb1e615c927a21d0b3f2e24eca885ede4 Mon Sep 17 00:00:00 2001
a83cc2
From: Thomas Huth <thuth@redhat.com>
a83cc2
Date: Thu, 15 Jul 2021 10:39:28 +0200
a83cc2
Subject: [PATCH 36/39] configure: Fix endianess test with LTO
a83cc2
a83cc2
RH-Author: Jon Maloy <jmaloy@redhat.com>
a83cc2
RH-MergeRequest: 24: v7:  Add support for building qemu-kvm with clang and safe-stack
a83cc2
RH-Commit: [9/11] c4be415076356fe74efab6f74d7b347064bbdb40 (jmaloy/qemu-kvm-centos-jon)
a83cc2
RH-Bugzilla: 1939509 1940132
a83cc2
RH-Acked-by: Danilo Cesar Lemes de Paula <ddepaula@redhat.com>
a83cc2
RH-Acked-by: Thomas Huth <thuth@redhat.com>
a83cc2
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
a83cc2
a83cc2
If a user is trying to compile QEMU with link-time optimization
a83cc2
enabled by running the configure script like this:
a83cc2
a83cc2
 .../configure --extra-cflags="-flto"
a83cc2
a83cc2
then the endianess test is failing since the magic values do not
a83cc2
show up in the intermediate object files there. If the host is
a83cc2
a big endian machine (like s390x), the QEMU binary is then unusable
a83cc2
since the corresponding variable "bigendian" is pre-initialized
a83cc2
with "no".
a83cc2
a83cc2
To fix this issue, we should rather create a full binary and look
a83cc2
for the magic strings there instead.
a83cc2
And we really should not continue the build if the endianess check
a83cc2
failed, to make it clear right from the start that something went
a83cc2
wrong here, thus let's also add some "exit 1" statements here
a83cc2
after emitting the error message.
a83cc2
a83cc2
Message-Id: <20210715083928.933806-1-thuth@redhat.com>
a83cc2
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
a83cc2
Signed-off-by: Thomas Huth <thuth@redhat.com>
a83cc2
(cherry picked from commit 659eb157a55666bf379f5362238a86d855e262e2)
a83cc2
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
a83cc2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
---
a83cc2
 configure | 15 +++++++++------
a83cc2
 1 file changed, 9 insertions(+), 6 deletions(-)
a83cc2
a83cc2
diff --git a/configure b/configure
a83cc2
index 83d8af7fe4..dcd9520bed 100755
a83cc2
--- a/configure
a83cc2
+++ b/configure
a83cc2
@@ -2323,24 +2323,27 @@ feature_not_found() {
a83cc2
 # ---
a83cc2
 # big/little endian test
a83cc2
 cat > $TMPC << EOF
a83cc2
+#include <stdio.h>
a83cc2
 short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
a83cc2
 short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, };
a83cc2
-extern int foo(short *, short *);
a83cc2
-int main(int argc, char *argv[]) {
a83cc2
-    return foo(big_endian, little_endian);
a83cc2
+int main(int argc, char *argv[])
a83cc2
+{
a83cc2
+    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
a83cc2
 }
a83cc2
 EOF
a83cc2
 
a83cc2
-if compile_object ; then
a83cc2
-    if strings -a $TMPO | grep -q BiGeNdIaN ; then
a83cc2
+if compile_prog ; then
a83cc2
+    if strings -a $TMPE | grep -q BiGeNdIaN ; then
a83cc2
         bigendian="yes"
a83cc2
-    elif strings -a $TMPO | grep -q LiTtLeEnDiAn ; then
a83cc2
+    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
a83cc2
         bigendian="no"
a83cc2
     else
a83cc2
         echo big/little test failed
a83cc2
+        exit 1
a83cc2
     fi
a83cc2
 else
a83cc2
     echo big/little test failed
a83cc2
+    exit 1
a83cc2
 fi
a83cc2
 
a83cc2
 ##########################################
a83cc2
-- 
a83cc2
2.27.0
a83cc2