Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QEMU] try updating #4506

Merged
merged 15 commits into from
Feb 28, 2022
74 changes: 59 additions & 15 deletions Q/Qemu/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
using BinaryBuilder

name = "Qemu"
version = v"4.1.0"
version = v"6.2.0"

# Collection of sources required to build libffi
sources = [
GitSource("https://gitlab.com/virtio-fs/qemu.git",
"bf5775237ee563b4baa1c7f3c1a65b7c93b93fca"),
ArchiveSource("https://download.qemu.org/qemu-6.2.0.tar.xz",
"68e15d8e45ac56326e0b9a4afa8b49a3dfe8aba3488221d098c84698bca65b45"),
DirectorySource("./bundled"),
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/qemu
cd $WORKSPACE/srcdir/qemu-*

# Patch out usage of MADV_NOHUGEPAGE which does not exist in glibc 2.12.X
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_madv_nohugepage.patch"

# Patch in adapter for `clock_gettime()` on macOS 10.12-
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_clock_gettime.patch"
# Patch to include `falloc` header in `strace.c`
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_falloc.patch"

# Patch to fix pointer mismatch between `size_t` and `uint64_t`
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_size_uint64.patch"
if [[ "${target}" == *-*-musl ]]; then
# Patch to fix messy header situation on musl
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_syscall.patch"
fi

# Patch to disable tests
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_disable_tests.patch"

# Patch to properly link to rt
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_link_rt.patch"

## Patch in adapter for `clock_gettime()` on macOS 10.12-
#atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_clock_gettime.patch"
#
## Patch to fix pointer mismatch between `size_t` and `uint64_t`
#atomic_patch -p1 "${WORKSPACE}/srcdir/patches/qemu_size_uint64.patch"

# Configure, ignoring some warnings that we don't need, etc...
./configure --host-cc="${HOSTCC}" --extra-cflags="-I${prefix}/include -Wno-unused-result" --disable-cocoa --prefix=$prefix
Expand All @@ -30,31 +44,61 @@ echo '#!/bin/true ' > /usr/bin/Rez
echo '#!/bin/true ' > /usr/bin/SetFile
chmod +x /usr/bin/Rez
chmod +x /usr/bin/SetFile
make -j${nproc}
make -j${nproc} || true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the build process tries to delete a non-existent file in cleanup, which should be harmless. I tried patching the Makefile, but it didn't work and I thought it probably isn't worth the trouble over just ignoring the return code

make install
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = [
Platform("x86_64", "linux"; libc="glibc"),
Platform("x86_64", "macos"),
Platform("i686", "linux"; libc="glibc"),
Platform("x86_64", "linux"; libc="musl"),
]
platforms = expand_cxxstring_abis(platforms)

# The products that we will ensure are always built
products = [
ExecutableProduct("qemu-system-x86_64", :qemu_system_x86_64),
ExecutableProduct("qemu-system-xtensaeb" , :qemu_system_xtensaeb ),
ExecutableProduct("qemu-system-xtensa" , :qemu_system_xtensa ),
ExecutableProduct("qemu-system-tricore" , :qemu_system_tricore ),
ExecutableProduct("qemu-system-sparc64" , :qemu_system_sparc64 ),
ExecutableProduct("qemu-system-sparc" , :qemu_system_sparc ),
ExecutableProduct("qemu-system-x86_64" , :qemu_system_x86_64 ),
ExecutableProduct("qemu-system-sh4eb" , :qemu_system_sh4eb ),
ExecutableProduct("qemu-system-s390x" , :qemu_system_s390x ),
ExecutableProduct("qemu-system-sh4" , :qemu_system_sh4 ),
ExecutableProduct("qemu-system-rx" , :qemu_system_rx ),
ExecutableProduct("qemu-system-riscv32" , :qemu_system_riscv32 ),
ExecutableProduct("qemu-system-riscv64" , :qemu_system_riscv64 ),
ExecutableProduct("qemu-system-ppc64" , :qemu_system_ppc64 ),
ExecutableProduct("qemu-system-ppc" , :qemu_system_ppc ),
ExecutableProduct("qemu-system-or1k" , :qemu_system_or1k ),
ExecutableProduct("qemu-system-nios2" , :qemu_system_nios2 ),
ExecutableProduct("qemu-system-microblazeel", :qemu_system_microblazeel),
ExecutableProduct("qemu-system-microblaze" , :qemu_system_microblaze ),
ExecutableProduct("qemu-system-m68k" , :qemu_system_m68k ),
ExecutableProduct("qemu-system-i386" , :qemu_system_i386 ),
ExecutableProduct("qemu-system-cris" , :qemu_system_cris ),
ExecutableProduct("qemu-system-hppa" , :qemu_system_hppa ),
ExecutableProduct("qemu-system-avr" , :qemu_system_avr ),
ExecutableProduct("qemu-system-arm" , :qemu_system_arm ),
ExecutableProduct("qemu-system-alpha" , :qemu_system_alpha ),
ExecutableProduct("qemu-system-aarch64" , :qemu_system_aarch64 ),
ExecutableProduct("qemu-system-mips" , :qemu_system_mips ),
ExecutableProduct("qemu-system-mipsel" , :qemu_system_mipsel ),
ExecutableProduct("qemu-system-mips64el" , :qemu_system_mips64el ),
ExecutableProduct("qemu-system-mips64" , :qemu_system_mips64 ),
]

# Dependencies that must be installed before this package can be built
dependencies = [
Dependency("Pixman_jll"),
Dependency("Glib_jll", v"2.59.0"; compat="2.59.0"),
Dependency("Glib_jll"; compat="2.68.1"),
Dependency("PCRE_jll"),
# TOOD: verify Gettext is actually needed at runtime
Dependency("Gettext_jll", v"0.20.1"; compat="=0.20.1"),
BuildDependency("Gettext_jll"),
Dependency("libcap_jll"),
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies)
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; preferred_gcc_version=v"8", julia_compat="1.6")
22 changes: 22 additions & 0 deletions Q/Qemu/bundled/patches/qemu_disable_tests.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/meson.build
+++ b/meson.build
@@ -2620,8 +2620,8 @@
specific_ss.add_all(when: 'CONFIG_LINUX_USER', if_true: linux_user_ss)

# needed for fuzzing binaries
-subdir('tests/qtest/libqos')
-subdir('tests/qtest/fuzz')
+#subdir('tests/qtest/libqos')
+#subdir('tests/qtest/fuzz')

# accel modules
tcg_real_module_ss = ss.source_set()
@@ -3107,7 +3107,7 @@
subdir('tools')
subdir('pc-bios')
subdir('docs')
-subdir('tests')
+#subdir('tests')
if gtk.found()
subdir('po')
endif
13 changes: 13 additions & 0 deletions Q/Qemu/bundled/patches/qemu_falloc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -18,6 +18,10 @@
#include "user-internals.h"
#include "strace.h"

+#if defined(CONFIG_FALLOCATE_PUNCH_HOLE) || defined(CONFIG_FALLOCATE_ZERO_RANGE)
+#include <linux/falloc.h>
+#endif
+
struct syscallname {
int nr;
const char *name;
13 changes: 13 additions & 0 deletions Q/Qemu/bundled/patches/qemu_link_rt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/meson.build b/meson.build
index 96de1a6ef9..36b315971e 100644
--- a/meson.build
+++ b/meson.build
@@ -2527,7 +2527,7 @@ util_ss.add_all(trace_ss)
util_ss = util_ss.apply(config_all, strict: false)
libqemuutil = static_library('qemuutil',
sources: util_ss.sources() + stub_ss.sources() + genh,
- dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman])
+ dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman, rt])
qemuutil = declare_dependency(link_with: libqemuutil,
sources: genh + version_res)

29 changes: 21 additions & 8 deletions Q/Qemu/bundled/patches/qemu_madv_nohugepage.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c
index 8af8c84dec..d86395f31a 100644
--- a/contrib/libvhost-user/libvhost-user.c
+++ b/contrib/libvhost-user/libvhost-user.c
@@ -646,7 +646,7 @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg)
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -80,6 +80,14 @@
} \
} while (0)

+/* copied from include/qemu/osdep.h */
+#define QEMU_MADV_INVALID -1
+#ifdef MADV_NOHUGEPAGE
+#define QEMU_MADV_NOHUGEPAGE MADV_NOHUGEPAGE
+#else
+#define QEMU_MADV_NOHUGEPAGE QEMU_MADV_INVALID
+#endif
+
static inline
bool has_feature(uint64_t features, unsigned int fbit)
{
@@ -634,7 +642,7 @@
*/
ret = madvise((void *)dev_region->mmap_addr,
ret = madvise((void *)(uintptr_t)dev_region->mmap_addr,
dev_region->size + dev_region->mmap_offset,
- MADV_NOHUGEPAGE);
+ QEMU_MADV_NOHUGEPAGE);
if (ret) {
/* Note: This can happen legally on kernels that are configured
* without madvise'able hugepages
/*
* Note: This can happen legally on kernels that are configured
61 changes: 61 additions & 0 deletions Q/Qemu/bundled/patches/qemu_syscall.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f1cfcc810..52cfe29d6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -49,6 +49,7 @@
#include <sys/statfs.h>
#include <utime.h>
#include <sys/sysinfo.h>
+#define _LINUX_SYSINFO_H
#include <sys/signalfd.h>
//#include <sys/user.h>
#include <netinet/in.h>
@@ -7281,12 +7282,47 @@ static inline abi_long host_to_target_timex64(abi_long target_addr,
#endif

#ifndef HAVE_SIGEV_NOTIFY_THREAD_ID
+typedef union _sigval {
+ int sival_int;
+ void *sival_ptr;
+} sigval_t;
+
+/*
+ * This works because the alignment is ok on all current architectures
+ * but we leave open this being overridden in the future
+ */
+#ifndef __ARCH_SIGEV_PREAMBLE_SIZE
+#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(int) * 2 + sizeof(sigval_t))
+#endif
+
+#define SIGEV_MAX_SIZE 64
+#define SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE - __ARCH_SIGEV_PREAMBLE_SIZE) \
+ / sizeof(int))
+
+typedef struct _sigevent {
+ sigval_t sigev_value;
+ int sigev_signo;
+ int sigev_notify;
+ union {
+ int _pad[SIGEV_PAD_SIZE];
+ int _tid;
+
+ struct {
+ void (*_function)(sigval_t);
+ void *_attribute; /* really pthread_attr_t */
+ } _sigev_thread;
+ } _sigev_un;
+} sigevent_t;
+
Comment on lines +17 to +48
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied from the asm-generic/siginfo.h headers. No idea if this is actually kosher...

#define sigev_notify_thread_id _sigev_un._tid
+#else
+#define _sigevent sigevent
#endif

-static inline abi_long target_to_host_sigevent(struct sigevent *host_sevp,
+static inline abi_long target_to_host_sigevent(struct sigevent *_host_sevp,
abi_ulong target_addr)
{
+ struct _sigevent *host_sevp = (struct _sigevent*)_host_sevp;
struct target_sigevent *target_sevp;

if (!lock_user_struct(VERIFY_READ, target_sevp, target_addr, 1)) {