commit:     69629171b283b4e0d29eb0d18d812b469af49ca1
Author:     Michal Privoznik <michal.privoznik <AT> gmail <DOT> com>
AuthorDate: Wed Oct 19 07:43:54 2022 +0000
Commit:     John Helmert III <ajak <AT> gentoo <DOT> org>
CommitDate: Wed Oct 19 14:14:43 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=69629171

app-emulation/qemu-guest-agent: Avoid using strings binary

The qemu's configure script (from which qemu-guest-agent is
built) calls strings binary directly. This does not fly with
cross compilation and was fixed upstream. Backport the fix.

Bug: https://bugs.gentoo.org/876933
Signed-off-by: Michal Privoznik <michal.privoznik <AT> gmail.com>
Signed-off-by: John Helmert III <ajak <AT> gentoo.org>

 ....1.0-configure-Avoid-using-strings-binary.patch | 85 ++++++++++++++++++++++
 .../qemu-guest-agent/qemu-guest-agent-7.1.0.ebuild |  4 +
 2 files changed, 89 insertions(+)

diff --git 
a/app-emulation/qemu-guest-agent/files/qemu-guest-agent-7.1.0-configure-Avoid-using-strings-binary.patch
 
b/app-emulation/qemu-guest-agent/files/qemu-guest-agent-7.1.0-configure-Avoid-using-strings-binary.patch
new file mode 100644
index 000000000000..dff62304a5c7
--- /dev/null
+++ 
b/app-emulation/qemu-guest-agent/files/qemu-guest-agent-7.1.0-configure-Avoid-using-strings-binary.patch
@@ -0,0 +1,85 @@
+From 33ab5f24913db8d5590fe4155829bd38e7902506 Mon Sep 17 00:00:00 2001
+Message-Id: 
<33ab5f24913db8d5590fe4155829bd38e7902506.1666164897.git.mpriv...@redhat.com>
+From: Michal Privoznik <[email protected]>
+Date: Fri, 14 Oct 2022 09:30:15 +0200
+Subject: [PATCH] configure: Avoid using strings binary
+
+When determining the endiandness of the target architecture we're
+building for a small program is compiled, which in an obfuscated
+way declares two strings. Then, we look which string is in
+correct order (using strings binary) and deduct the endiandness.
+But using the strings binary is problematic, because it's part of
+toolchain (strings is just a symlink to
+x86_64-pc-linux-gnu-strings or llvm-strings). And when
+(cross-)compiling, it requires users to set the symlink to the
+correct toolchain.
+
+Fortunately, we have a better alternative anyways. We can mimic
+what compiler.h is already doing: comparing __BYTE_ORDER__
+against values for little/big endiandness.
+
+Bug: https://bugs.gentoo.org/876933
+Signed-off-by: Michal Privoznik <[email protected]>
+Message-Id: 
<d6d9c7043cfe6d976d96694f2b4ecf85cf3206f1.1665732504.git.mpriv...@redhat.com>
+Cc: [email protected]
+Signed-off-by: Paolo Bonzini <[email protected]>
+---
+ configure | 35 ++++++++++++++++++-----------------
+ 1 file changed, 18 insertions(+), 17 deletions(-)
+
+diff --git a/configure b/configure
+index f9ec050bf8..81561be7c1 100755
+--- a/configure
++++ b/configure
+@@ -1423,30 +1423,31 @@ if test "$tcg" = "enabled"; then
+     git_submodules="$git_submodules tests/fp/berkeley-softfloat-3"
+ fi
+ 
+-# ---
++##########################################
+ # big/little endian test
+ cat > $TMPC << EOF
+-#include <stdio.h>
+-short big_endian[] = { 0x4269, 0x4765, 0x4e64, 0x4961, 0x4e00, 0, };
+-short little_endian[] = { 0x694c, 0x7454, 0x654c, 0x6e45, 0x6944, 0x6e41, 0, 
};
+-int main(int argc, char *argv[])
+-{
+-    return printf("%s %s\n", (char *)big_endian, (char *)little_endian);
+-}
++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
++# error LITTLE
++#endif
++int main(void) { return 0; }
+ EOF
+ 
+-if compile_prog ; then
+-    if strings -a $TMPE | grep -q BiGeNdIaN ; then
+-        bigendian="yes"
+-    elif strings -a $TMPE | grep -q LiTtLeEnDiAn ; then
+-        bigendian="no"
+-    else
+-        echo big/little test failed
+-        exit 1
+-    fi
++if ! compile_prog ; then
++  bigendian="no"
+ else
++  cat > $TMPC << EOF
++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
++# error BIG
++#endif
++int main(void) { return 0; }
++EOF
++
++  if ! compile_prog ; then
++    bigendian="yes"
++  else
+     echo big/little test failed
+     exit 1
++  fi
+ fi
+ 
+ ##########################################
+-- 
+2.37.3
+

diff --git a/app-emulation/qemu-guest-agent/qemu-guest-agent-7.1.0.ebuild 
b/app-emulation/qemu-guest-agent/qemu-guest-agent-7.1.0.ebuild
index 0f2019bc9f7e..87c4dbf69d23 100644
--- a/app-emulation/qemu-guest-agent/qemu-guest-agent-7.1.0.ebuild
+++ b/app-emulation/qemu-guest-agent/qemu-guest-agent-7.1.0.ebuild
@@ -24,6 +24,10 @@ BDEPEND="${PYTHON_DEPS}"
 
 S="${WORKDIR}/${MY_P}"
 
+PATCHES=(
+       "${FILESDIR}"/${PN}-7.1.0-configure-Avoid-using-strings-binary.patch
+)
+
 src_configure() {
        tc-export AR LD OBJCOPY RANLIB
 

Reply via email to