Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] binfmt handling improvements, qemu: update to 9.0.1
@ 2024-06-15 19:00 classabbyamp
  2024-06-16  7:50 ` [PR PATCH] [Updated] " classabbyamp
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: classabbyamp @ 2024-06-15 19:00 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]

There is a new pull request by classabbyamp against master on the void-packages repository

https://github.com/classabbyamp/void-packages qemu-binfmt
https://github.com/void-linux/void-packages/pull/50838

binfmt handling improvements, qemu: update to 9.0.1
This cleans up a lot of the binfmt handling in triggers and especially qemu-user-static.

- `update-binfmts --import` is a lot cleaner than `update-binfmts --install`
- moves the important data out of the install script and into the package itself (`/usr/share/binfmts`)
- allows the `binfmts` trigger to be detected automatically
- old behaviour kept around for compatibility, with signficant cleanups to the code
- qemu provides a script to generate binfmt definitions in the format `update-binfmts --import` understands, removing a bunch of junk from the template
- these definition files are simple enough that we can generate it for wine during build

<!-- Uncomment relevant sections and delete options which are not applicable -->

#### Testing the changes
- I tested the changes in this PR: **YES**



A patch file from https://github.com/void-linux/void-packages/pull/50838.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-qemu-binfmt-50838.patch --]
[-- Type: text/x-diff, Size: 18543 bytes --]

From fb328dde91dc14090afdae6b1256552c773a49ae Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:12:09 -0400
Subject: [PATCH 1/7] xbps-triggers: support importing/unimporting binfmt files

removes the need to manually list all the binfmt magics and masks in
qemu-user-static.

keeps the legacy behaviour around for compatibility
---
 srcpkgs/xbps-triggers/files/binfmts | 63 ++++++++++++++++++++++-------
 srcpkgs/xbps-triggers/template      |  2 +-
 2 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/binfmts b/srcpkgs/xbps-triggers/files/binfmts
index 16919833a80b0d..4212afd1e0d60b 100755
--- a/srcpkgs/xbps-triggers/files/binfmts
+++ b/srcpkgs/xbps-triggers/files/binfmts
@@ -19,32 +19,65 @@ UPDATE="$5"
 
 export PATH="usr/bin:usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin"
 
+# {install,remove}_binfmts: legacy installation style
+install_binfmts() {
+	echo "$binfmts" | while read -r line; do
+		set -- $line
+		_bin="$1"; shift
+		_bname="${_bin##*/}"
+		update-binfmts --package "${PKGNAME}" --install "${_bname}" "${_bin}" "$@"
+	done
+}
+
+remove_binfmts() {
+	echo "$binfmts" | while read -r line; do
+		set -- $line
+		_bin="$1"; shift
+		_bname="${_bin##*/}"
+		if [ -f "var/lib/binfmts/${_bname}" ]; then
+			update-binfmts --package "${PKGNAME}" --remove "${_bname}" "${_bin}"
+		fi
+	done
+}
+
+# {,un}import_binfmts: new installation style
+import_binfmts() {
+	for _fmt in $import_binfmts; do
+		update-binfmts --import "$_fmt"
+	done
+}
+
+unimport_binfmts() {
+	for _fmt in $import_binfmts; do
+		if [ -f "var/lib/binfmts/${_fmt}" ]; then
+			update-binfmts --unimport "$_fmt"
+		fi
+	done
+}
+
 case "$ACTION" in
 targets)
 	echo "post-install pre-remove"
 	;;
 run)
 	[ -x /usr/bin/update-binfmts ] || exit 0
-	[ -z "${binfmts}" ] && exit 0
 
 	case "$TARGET" in
 	post-install)
-		echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do
-			line=$(echo $line | tr '&' '\' 2> /dev/null)
-			set -- ${line}
-			_bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})"
-			update-binfmts --package ${PKGNAME} --install ${_bname} ${_bin} ${_args}
-		done
+		if [ -n "${binfmts}" ]; then
+			install_binfmts
+		fi
+		if [ -n "${import_binfmts}" ]; then
+			import_binfmts
+		fi
 		;;
 	pre-remove)
-		echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do
-			line=$(echo $line | tr '&' '\' 2> /dev/null)
-			set -- ${line}
-			_bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})"
-			if [ -f /var/lib/binfmts/${_bname} ]; then
-				update-binfmts --package ${PKGNAME} --remove ${_bname} ${_bin}
-			fi
-		done
+		if [ -n "${binfmts}" ]; then
+			remove_binfmts
+		fi
+		if [ -n "${import_binfmts}" ]; then
+			unimport_binfmts
+		fi
 		;;
 	*)
 		exit 1
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index 66936411a42588..7745a9aa4f12d2 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.127
+version=0.128
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

From b7f8dd265f685e19fd8a74a66603e5a84da38092 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:15:34 -0400
Subject: [PATCH 2/7] common/hooks/post-install: support new binfmts hook style

---
 .../hooks/post-install/04-create-xbps-metadata-scripts.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/hooks/post-install/04-create-xbps-metadata-scripts.sh b/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
index f21017f8361e6d..70152bad55f4fc 100644
--- a/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
+++ b/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
@@ -119,10 +119,16 @@ _EOF
 	#
 	# Handle binfmts trigger
 	#
-	if [ -n "${binfmts}" ]; then
+	if [ -n "${binfmts}" ] || [ -d "${PKGDESTDIR}/usr/share/binfmts" ]; then
 		_add_trigger binfmts
+	fi
+	if [ -n "${binfmts}" ]; then
 		echo "export binfmts=\"${binfmts}\"" >> $tmpf
 	fi
+	if [ -d "${PKGDESTDIR}/usr/share/binfmts" ]; then
+		_import_binfmts="$(find "${PKGDESTDIR}/usr/share/binfmts" -type f -printf '%f\n')"
+		echo "export import_binfmts=\"${_import_binfmts}\"" >> $tmpf
+	fi
 	#
 	# Handle GNU Info files.
 	#

From 750c66838f136cb85009c0ec64e0c73fa14fc876 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:11:12 -0400
Subject: [PATCH 3/7] Manual.md: document new binfmts trigger behaviour

---
 Manual.md | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Manual.md b/Manual.md
index f323739ffed362..96b6a3fcacaadb 100644
--- a/Manual.md
+++ b/Manual.md
@@ -1804,8 +1804,19 @@ executable binary formats, know as binfmts.
 During installation/removal it uses `update-binfmts` from the `binfmt-support` package
 to register/remove entries from the arbitrary executable binary formats database.
 
-To include the trigger use the `binfmts` variable, as the trigger won't do anything unless
-it is defined.
+It is automatically added to packages that contain files in `usr/share/binfmts`.
+These files should be `update-binfmts` format files and will be imported with
+`update-binfmts --import`.
+
+While it is not preferred, the trigger can also be added by using the `binfmts` variable,
+which should contain lines defining binfmts to register:
+
+```
+/path/to/interpreter [update-binfmts binary format specification arguments ...]
+...
+```
+
+See [`update-binfmts(8)`](https://man.voidlinux.org/man8/update-binfmts.8) for more details.
 
 <a id="triggers_dkms"></a>
 #### dkms

From be449aa305e8ae59cbbd1eb78c4f4fd2bc787ace Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:15:07 -0400
Subject: [PATCH 4/7] binfmt-support: depend on xbps-triggers

---
 srcpkgs/binfmt-support/template | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/srcpkgs/binfmt-support/template b/srcpkgs/binfmt-support/template
index aefbc2a026b3b5..634109b979de5c 100644
--- a/srcpkgs/binfmt-support/template
+++ b/srcpkgs/binfmt-support/template
@@ -1,10 +1,11 @@
 # Template file for 'binfmt-support'
 pkgname=binfmt-support
 version=2.2.2
-revision=1
+revision=2
 build_style=gnu-configure
 hostmakedepends="pkg-config"
 makedepends="libpipeline-devel"
+depends="xbps-triggers>=0.128_1"
 short_desc="Register interpreters for various binary formats"
 maintainer="Andrea Brancaleoni <abc@pompel.me>"
 license="GPL-2.0-or-later"

From 33f87fac92947c476496d756dae0afe50d2980c8 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:16:31 -0400
Subject: [PATCH 5/7] wine: provide binfmt file

this matches the one debian provides
---
 srcpkgs/wine/template | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/srcpkgs/wine/template b/srcpkgs/wine/template
index f9245e742f8367..c4e8216ae823ba 100644
--- a/srcpkgs/wine/template
+++ b/srcpkgs/wine/template
@@ -1,7 +1,7 @@
 # Template file for 'wine'
 pkgname=wine
 version=9.10
-revision=1
+revision=2
 _pkgver=${version/r/-r}
 create_wrksrc=yes
 build_wrksrc=wine-${_pkgver}
@@ -141,7 +141,6 @@ wine-devel_package() {
 
 wine-common_package() {
 	short_desc+=" - common files"
-	binfmts="/usr/bin/wine --magic MZ"
 	pkg_install() {
 		vmove usr/share
 		vmove etc/fonts
@@ -149,6 +148,12 @@ wine-common_package() {
 		do
 			vmove usr/bin/${file}
 		done
+		vmkdir usr/share/binfmts
+		cat <<- EOF >> "${PKGDESTDIR}"/usr/share/binfmts/wine
+		package wine
+		interpreter /usr/bin/wine
+		magic MZ
+		EOF
 	}
 }
 

From 897da274b2b9598db66db6260501bfb345efa644 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:16:54 -0400
Subject: [PATCH 6/7] qemu-user-static: update to 9.0.1, clean up binfmt
 generation

qemu provides a script to generate this in a format update-binfmts
understands
---
 srcpkgs/qemu-user-static/template | 113 ++++++------------------------
 1 file changed, 22 insertions(+), 91 deletions(-)

diff --git a/srcpkgs/qemu-user-static/template b/srcpkgs/qemu-user-static/template
index c29ed1dadf247d..7d5a65e54f8388 100644
--- a/srcpkgs/qemu-user-static/template
+++ b/srcpkgs/qemu-user-static/template
@@ -1,8 +1,8 @@
 # Template file for 'qemu-user-static'
 # This package should be updated together with qemu
 pkgname=qemu-user-static
-version=9.0.0
-revision=2
+version=9.0.1
+revision=1
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec
  --disable-kvm --disable-png --disable-virtfs --disable-fdt --disable-seccomp
@@ -14,103 +14,20 @@ maintainer="Orphaned <orphan@voidlinux.org>"
 license="GPL-2.0-only, LGPL-2.1-only"
 homepage="https://www.qemu.org"
 distfiles="https://wiki.qemu.org/download/qemu-${version}.tar.bz2"
-checksum=f816255215ed495d164311210e05aec867c4cb22576b41b2d723209de579ed61
-
-_fmts="aarch64 aarch64_be alpha arm armeb cris hppa i386 m68k microblaze
- microblazeel mips mipsel mips64 mips64el mipsn32 mipsn32el or1k
- ppc ppcle ppc64 ppc64le riscv32 riscv64 s390x sh4 sh4eb
- sparc sparc32plus sparc64 x86_64 xtensa xtensaeb"
-
-_aarch64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
-_aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_aarch64_be_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
-_aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_alpha_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90'
-_alpha_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_arm_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
-_arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_armeb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28'
-_armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_cris_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x4c\x00'
-_cris_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f'
-_hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_i386_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
-_i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_m68k_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04'
-_m68k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_microblaze_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xba\xab'
-_microblaze_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_microblazeel_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xab\xba'
-_microblazeel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mips_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mipsel_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mips64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mips64el_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mipsn32_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mipsn32el_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_or1k_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5c'
-_or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppc_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14'
-_ppc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppcle_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14\x00'
-_ppcle_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00'
-_ppc64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15'
-_ppc64_mask='\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppc64le_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00'
-_ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00'
-_riscv32_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'
-_riscv32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_riscv64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'
-_riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_s390x_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16'
-_s390x_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sh4_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00'
-_sh4_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_sh4eb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a'
-_sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'
-_sparc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc32plus_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12'
-_sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b'
-_sparc64_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_x86_64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00'
-_x86_64_mask='\xff\xff\xff\xff\xff\xfe\xfe\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_xtensa_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e\x00'
-_xtensa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_xtensaeb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e'
-_xtensaeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+checksum=c79bd301abd9f2501bdf0a543c6f6f7474424178dcfde2be271150988cadc0a7
 
 if [ "$CROSS_BUILD" ]; then
 	configure_args+=" --cross-prefix=${XBPS_CROSS_TRIPLET}-"
 fi
 
+_omit=("${XBPS_TARGET_MACHINE%-*}")
 case "$XBPS_TARGET_MACHINE" in
-	x86_64*) _omit="i386|x86_64" ;;
-	aarch64*) _omit="aarch64" ;;
-	armv*) _omit="arm" ;;
-	ppc64le*) _omit="ppc64le|ppcle" ;;
-	ppc64*) _omit="ppc64|ppc" ;;
-	*) _omit="${XBPS_TARGET_MACHINE%-*}" ;;
+	x86_64*) _omit+=(i386) ;;
+	armv*) _omit+=(arm) ;;
+	ppc64le*) _omit+=(ppcle) ;;
+	ppc64*) _omit+=(ppc) ;;
 esac
 
-for _fmt in $_fmts; do
-	eval "case $_fmt in $_omit) magic= ;; *) magic=\"\$_${_fmt}_magic\" mask=\"\$_${_fmt}_mask\" ;; esac"
-	if [ "$magic" ]; then
-		binfmts+="/usr/bin/qemu-$_fmt-static --magic $magic --mask $mask --offset 0 --credentials yes --fix-binary yes
-"
-	fi
-done
-
-binfmts="${binfmts%?}"
-
 post_install() {
 	# Remove unneeded stuff.
 	rm -rf ${DESTDIR}/etc ${DESTDIR}/usr/share ${DESTDIR}/usr/libexec
@@ -120,4 +37,18 @@ post_install() {
 	for f in ${DESTDIR}/usr/bin/*; do
 		mv ${f} ${f}-static
 	done
+
+	vmkdir usr/share/binfmts
+	scripts/qemu-binfmt-conf.sh --debian ALL --exportdir "${DESTDIR}"/usr/share/binfmts \
+		--qemu-path /usr/bin --preserve-argv0 yes --persistent yes --credential yes
+	for bf in "${DESTDIR}"/usr/share/binfmts/*; do
+		for ar in "${_omit[@]}"; do
+			if [[ "$bf" = *"$ar" ]]; then
+				rm "$bf"
+				continue 2
+			fi
+		done
+		vsed -i -e "s/${bf##*/}/&-static/g" "$bf"
+		mv "$bf" "${bf}-static"
+	done
 }

From 5b2e2fd27d8b672a2c4d8cec9604b2e2be9278bd Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:17:35 -0400
Subject: [PATCH 7/7] qemu: update to 9.0.1.

---
 srcpkgs/qemu/template | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/srcpkgs/qemu/template b/srcpkgs/qemu/template
index 623f197ff9b7cf..e05d7ce5620265 100644
--- a/srcpkgs/qemu/template
+++ b/srcpkgs/qemu/template
@@ -1,8 +1,8 @@
 # Template file for 'qemu'
 # This package should be updated together with qemu-user-static
 pkgname=qemu
-version=9.0.0
-revision=2
+version=9.0.1
+revision=1
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec --localstatedir=/var
  --disable-glusterfs --disable-xen --enable-docs --enable-kvm --enable-libusb --enable-pie
@@ -28,7 +28,7 @@ maintainer="Orphaned <orphan@voidlinux.org>"
 license="GPL-2.0-only, LGPL-2.1-only"
 homepage="https://www.qemu.org"
 distfiles="https://wiki.qemu.org/download/qemu-${version}.tar.bz2"
-checksum=f816255215ed495d164311210e05aec867c4cb22576b41b2d723209de579ed61
+checksum=c79bd301abd9f2501bdf0a543c6f6f7474424178dcfde2be271150988cadc0a7
 ignore_elf_dirs="/usr/share/qemu"
 nostrip_files="hppa-firmware.img hppa-firmware64.img openbios-ppc
  openbios-sparc32 openbios-sparc64 palcode-clipper s390-ccw.img

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PR PATCH] [Updated] binfmt handling improvements, qemu: update to 9.0.1
  2024-06-15 19:00 [PR PATCH] binfmt handling improvements, qemu: update to 9.0.1 classabbyamp
@ 2024-06-16  7:50 ` classabbyamp
  2024-06-16 18:38 ` classabbyamp
  2024-06-17 20:13 ` [PR PATCH] [Merged]: " classabbyamp
  2 siblings, 0 replies; 4+ messages in thread
From: classabbyamp @ 2024-06-16  7:50 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]

There is an updated pull request by classabbyamp against master on the void-packages repository

https://github.com/classabbyamp/void-packages qemu-binfmt
https://github.com/void-linux/void-packages/pull/50838

binfmt handling improvements, qemu: update to 9.0.1
This cleans up a lot of the binfmt handling in triggers and especially qemu-user-static.

- `update-binfmts --import` is a lot cleaner than `update-binfmts --install`
- moves the important data out of the install script and into the package itself (`/usr/share/binfmts`)
- allows the `binfmts` trigger to be detected automatically
- old behaviour kept around for compatibility, with signficant cleanups to the code
- qemu provides a script to generate binfmt definitions in the format `update-binfmts --import` understands, removing a bunch of junk from the template
- these definition files are simple enough that we can generate it for wine during build

<!-- Uncomment relevant sections and delete options which are not applicable -->

#### Testing the changes
- I tested the changes in this PR: **YES**



A patch file from https://github.com/void-linux/void-packages/pull/50838.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-qemu-binfmt-50838.patch --]
[-- Type: text/x-diff, Size: 18549 bytes --]

From 564c44595faff51575d9bcd40132cb22832513fc Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:12:09 -0400
Subject: [PATCH 1/7] xbps-triggers: support importing/unimporting binfmt files

removes the need to manually list all the binfmt magics and masks in
qemu-user-static.

keeps the legacy behaviour around for compatibility
---
 srcpkgs/xbps-triggers/files/binfmts | 63 ++++++++++++++++++++++-------
 srcpkgs/xbps-triggers/template      |  2 +-
 2 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/binfmts b/srcpkgs/xbps-triggers/files/binfmts
index 16919833a80b0d..4212afd1e0d60b 100755
--- a/srcpkgs/xbps-triggers/files/binfmts
+++ b/srcpkgs/xbps-triggers/files/binfmts
@@ -19,32 +19,65 @@ UPDATE="$5"
 
 export PATH="usr/bin:usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin"
 
+# {install,remove}_binfmts: legacy installation style
+install_binfmts() {
+	echo "$binfmts" | while read -r line; do
+		set -- $line
+		_bin="$1"; shift
+		_bname="${_bin##*/}"
+		update-binfmts --package "${PKGNAME}" --install "${_bname}" "${_bin}" "$@"
+	done
+}
+
+remove_binfmts() {
+	echo "$binfmts" | while read -r line; do
+		set -- $line
+		_bin="$1"; shift
+		_bname="${_bin##*/}"
+		if [ -f "var/lib/binfmts/${_bname}" ]; then
+			update-binfmts --package "${PKGNAME}" --remove "${_bname}" "${_bin}"
+		fi
+	done
+}
+
+# {,un}import_binfmts: new installation style
+import_binfmts() {
+	for _fmt in $import_binfmts; do
+		update-binfmts --import "$_fmt"
+	done
+}
+
+unimport_binfmts() {
+	for _fmt in $import_binfmts; do
+		if [ -f "var/lib/binfmts/${_fmt}" ]; then
+			update-binfmts --unimport "$_fmt"
+		fi
+	done
+}
+
 case "$ACTION" in
 targets)
 	echo "post-install pre-remove"
 	;;
 run)
 	[ -x /usr/bin/update-binfmts ] || exit 0
-	[ -z "${binfmts}" ] && exit 0
 
 	case "$TARGET" in
 	post-install)
-		echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do
-			line=$(echo $line | tr '&' '\' 2> /dev/null)
-			set -- ${line}
-			_bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})"
-			update-binfmts --package ${PKGNAME} --install ${_bname} ${_bin} ${_args}
-		done
+		if [ -n "${binfmts}" ]; then
+			install_binfmts
+		fi
+		if [ -n "${import_binfmts}" ]; then
+			import_binfmts
+		fi
 		;;
 	pre-remove)
-		echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do
-			line=$(echo $line | tr '&' '\' 2> /dev/null)
-			set -- ${line}
-			_bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})"
-			if [ -f /var/lib/binfmts/${_bname} ]; then
-				update-binfmts --package ${PKGNAME} --remove ${_bname} ${_bin}
-			fi
-		done
+		if [ -n "${binfmts}" ]; then
+			remove_binfmts
+		fi
+		if [ -n "${import_binfmts}" ]; then
+			unimport_binfmts
+		fi
 		;;
 	*)
 		exit 1
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index 66936411a42588..7745a9aa4f12d2 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.127
+version=0.128
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

From 44939cb6294ff83366b04b161cae7650d9d0ac32 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:15:34 -0400
Subject: [PATCH 2/7] common/hooks/post-install: support new binfmts hook style

---
 .../hooks/post-install/04-create-xbps-metadata-scripts.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/hooks/post-install/04-create-xbps-metadata-scripts.sh b/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
index f21017f8361e6d..70152bad55f4fc 100644
--- a/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
+++ b/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
@@ -119,10 +119,16 @@ _EOF
 	#
 	# Handle binfmts trigger
 	#
-	if [ -n "${binfmts}" ]; then
+	if [ -n "${binfmts}" ] || [ -d "${PKGDESTDIR}/usr/share/binfmts" ]; then
 		_add_trigger binfmts
+	fi
+	if [ -n "${binfmts}" ]; then
 		echo "export binfmts=\"${binfmts}\"" >> $tmpf
 	fi
+	if [ -d "${PKGDESTDIR}/usr/share/binfmts" ]; then
+		_import_binfmts="$(find "${PKGDESTDIR}/usr/share/binfmts" -type f -printf '%f\n')"
+		echo "export import_binfmts=\"${_import_binfmts}\"" >> $tmpf
+	fi
 	#
 	# Handle GNU Info files.
 	#

From 27e168dec11ba23b5683f3560d100ef96daf6663 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:11:12 -0400
Subject: [PATCH 3/7] Manual.md: document new binfmts trigger behaviour

---
 Manual.md | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Manual.md b/Manual.md
index f323739ffed362..96b6a3fcacaadb 100644
--- a/Manual.md
+++ b/Manual.md
@@ -1804,8 +1804,19 @@ executable binary formats, know as binfmts.
 During installation/removal it uses `update-binfmts` from the `binfmt-support` package
 to register/remove entries from the arbitrary executable binary formats database.
 
-To include the trigger use the `binfmts` variable, as the trigger won't do anything unless
-it is defined.
+It is automatically added to packages that contain files in `usr/share/binfmts`.
+These files should be `update-binfmts` format files and will be imported with
+`update-binfmts --import`.
+
+While it is not preferred, the trigger can also be added by using the `binfmts` variable,
+which should contain lines defining binfmts to register:
+
+```
+/path/to/interpreter [update-binfmts binary format specification arguments ...]
+...
+```
+
+See [`update-binfmts(8)`](https://man.voidlinux.org/man8/update-binfmts.8) for more details.
 
 <a id="triggers_dkms"></a>
 #### dkms

From 428ca69286632b6b293325f25c48c63632d2cf9e Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:15:07 -0400
Subject: [PATCH 4/7] binfmt-support: depend on xbps-triggers

---
 srcpkgs/binfmt-support/template | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/srcpkgs/binfmt-support/template b/srcpkgs/binfmt-support/template
index aefbc2a026b3b5..634109b979de5c 100644
--- a/srcpkgs/binfmt-support/template
+++ b/srcpkgs/binfmt-support/template
@@ -1,10 +1,11 @@
 # Template file for 'binfmt-support'
 pkgname=binfmt-support
 version=2.2.2
-revision=1
+revision=2
 build_style=gnu-configure
 hostmakedepends="pkg-config"
 makedepends="libpipeline-devel"
+depends="xbps-triggers>=0.128_1"
 short_desc="Register interpreters for various binary formats"
 maintainer="Andrea Brancaleoni <abc@pompel.me>"
 license="GPL-2.0-or-later"

From efa52720ff73d8544dfcf361317574346df8150a Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:16:31 -0400
Subject: [PATCH 5/7] wine: provide binfmt file

this matches the one debian provides
---
 srcpkgs/wine/template | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/srcpkgs/wine/template b/srcpkgs/wine/template
index f9245e742f8367..c4e8216ae823ba 100644
--- a/srcpkgs/wine/template
+++ b/srcpkgs/wine/template
@@ -1,7 +1,7 @@
 # Template file for 'wine'
 pkgname=wine
 version=9.10
-revision=1
+revision=2
 _pkgver=${version/r/-r}
 create_wrksrc=yes
 build_wrksrc=wine-${_pkgver}
@@ -141,7 +141,6 @@ wine-devel_package() {
 
 wine-common_package() {
 	short_desc+=" - common files"
-	binfmts="/usr/bin/wine --magic MZ"
 	pkg_install() {
 		vmove usr/share
 		vmove etc/fonts
@@ -149,6 +148,12 @@ wine-common_package() {
 		do
 			vmove usr/bin/${file}
 		done
+		vmkdir usr/share/binfmts
+		cat <<- EOF >> "${PKGDESTDIR}"/usr/share/binfmts/wine
+		package wine
+		interpreter /usr/bin/wine
+		magic MZ
+		EOF
 	}
 }
 

From 6c09a383241e2fa31739f5c4f098a32e40ee3d79 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:16:54 -0400
Subject: [PATCH 6/7] qemu-user-static: update to 9.0.1, clean up binfmt
 generation

qemu provides a script to generate this in a format update-binfmts
understands
---
 srcpkgs/qemu-user-static/template | 113 ++++++------------------------
 1 file changed, 22 insertions(+), 91 deletions(-)

diff --git a/srcpkgs/qemu-user-static/template b/srcpkgs/qemu-user-static/template
index c29ed1dadf247d..858f035de38b05 100644
--- a/srcpkgs/qemu-user-static/template
+++ b/srcpkgs/qemu-user-static/template
@@ -1,8 +1,8 @@
 # Template file for 'qemu-user-static'
 # This package should be updated together with qemu
 pkgname=qemu-user-static
-version=9.0.0
-revision=2
+version=9.0.1
+revision=1
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec
  --disable-kvm --disable-png --disable-virtfs --disable-fdt --disable-seccomp
@@ -14,103 +14,20 @@ maintainer="Orphaned <orphan@voidlinux.org>"
 license="GPL-2.0-only, LGPL-2.1-only"
 homepage="https://www.qemu.org"
 distfiles="https://wiki.qemu.org/download/qemu-${version}.tar.bz2"
-checksum=f816255215ed495d164311210e05aec867c4cb22576b41b2d723209de579ed61
-
-_fmts="aarch64 aarch64_be alpha arm armeb cris hppa i386 m68k microblaze
- microblazeel mips mipsel mips64 mips64el mipsn32 mipsn32el or1k
- ppc ppcle ppc64 ppc64le riscv32 riscv64 s390x sh4 sh4eb
- sparc sparc32plus sparc64 x86_64 xtensa xtensaeb"
-
-_aarch64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
-_aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_aarch64_be_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
-_aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_alpha_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90'
-_alpha_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_arm_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
-_arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_armeb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28'
-_armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_cris_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x4c\x00'
-_cris_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f'
-_hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_i386_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
-_i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_m68k_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04'
-_m68k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_microblaze_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xba\xab'
-_microblaze_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_microblazeel_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xab\xba'
-_microblazeel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mips_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mipsel_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mips64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mips64el_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mipsn32_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mipsn32el_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_or1k_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5c'
-_or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppc_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14'
-_ppc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppcle_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14\x00'
-_ppcle_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00'
-_ppc64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15'
-_ppc64_mask='\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppc64le_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00'
-_ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00'
-_riscv32_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'
-_riscv32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_riscv64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'
-_riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_s390x_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16'
-_s390x_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sh4_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00'
-_sh4_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_sh4eb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a'
-_sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'
-_sparc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc32plus_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12'
-_sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b'
-_sparc64_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_x86_64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00'
-_x86_64_mask='\xff\xff\xff\xff\xff\xfe\xfe\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_xtensa_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e\x00'
-_xtensa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_xtensaeb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e'
-_xtensaeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+checksum=c79bd301abd9f2501bdf0a543c6f6f7474424178dcfde2be271150988cadc0a7
 
 if [ "$CROSS_BUILD" ]; then
 	configure_args+=" --cross-prefix=${XBPS_CROSS_TRIPLET}-"
 fi
 
+_omit=("${XBPS_TARGET_MACHINE%-*}")
 case "$XBPS_TARGET_MACHINE" in
-	x86_64*) _omit="i386|x86_64" ;;
-	aarch64*) _omit="aarch64" ;;
-	armv*) _omit="arm" ;;
-	ppc64le*) _omit="ppc64le|ppcle" ;;
-	ppc64*) _omit="ppc64|ppc" ;;
-	*) _omit="${XBPS_TARGET_MACHINE%-*}" ;;
+	x86_64*) _omit+=(i386) ;;
+	armv*) _omit+=(arm) ;;
+	ppc64le*) _omit+=(ppcle) ;;
+	ppc64*) _omit+=(ppc) ;;
 esac
 
-for _fmt in $_fmts; do
-	eval "case $_fmt in $_omit) magic= ;; *) magic=\"\$_${_fmt}_magic\" mask=\"\$_${_fmt}_mask\" ;; esac"
-	if [ "$magic" ]; then
-		binfmts+="/usr/bin/qemu-$_fmt-static --magic $magic --mask $mask --offset 0 --credentials yes --fix-binary yes
-"
-	fi
-done
-
-binfmts="${binfmts%?}"
-
 post_install() {
 	# Remove unneeded stuff.
 	rm -rf ${DESTDIR}/etc ${DESTDIR}/usr/share ${DESTDIR}/usr/libexec
@@ -120,4 +37,18 @@ post_install() {
 	for f in ${DESTDIR}/usr/bin/*; do
 		mv ${f} ${f}-static
 	done
+
+	vmkdir usr/share/binfmts
+	scripts/qemu-binfmt-conf.sh --debian ALL --exportdir "${DESTDIR}"/usr/share/binfmts \
+		--qemu-path /usr/bin --preserve-argv0 yes --persistent yes --credential yes
+	for bf in "${DESTDIR}"/usr/share/binfmts/*; do
+		for ar in "${_omit[@]}"; do
+			if [[ "$bf" = */qemu-"$ar" ]]; then
+				rm "$bf"
+				continue 2
+			fi
+		done
+		vsed -i -e "s/${bf##*/}/&-static/g" "$bf"
+		mv "$bf" "${bf}-static"
+	done
 }

From fc831943c3f7ab3873fe7551a10f853e6bae3f4d Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:17:35 -0400
Subject: [PATCH 7/7] qemu: update to 9.0.1.

---
 srcpkgs/qemu/template | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/srcpkgs/qemu/template b/srcpkgs/qemu/template
index 623f197ff9b7cf..e05d7ce5620265 100644
--- a/srcpkgs/qemu/template
+++ b/srcpkgs/qemu/template
@@ -1,8 +1,8 @@
 # Template file for 'qemu'
 # This package should be updated together with qemu-user-static
 pkgname=qemu
-version=9.0.0
-revision=2
+version=9.0.1
+revision=1
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec --localstatedir=/var
  --disable-glusterfs --disable-xen --enable-docs --enable-kvm --enable-libusb --enable-pie
@@ -28,7 +28,7 @@ maintainer="Orphaned <orphan@voidlinux.org>"
 license="GPL-2.0-only, LGPL-2.1-only"
 homepage="https://www.qemu.org"
 distfiles="https://wiki.qemu.org/download/qemu-${version}.tar.bz2"
-checksum=f816255215ed495d164311210e05aec867c4cb22576b41b2d723209de579ed61
+checksum=c79bd301abd9f2501bdf0a543c6f6f7474424178dcfde2be271150988cadc0a7
 ignore_elf_dirs="/usr/share/qemu"
 nostrip_files="hppa-firmware.img hppa-firmware64.img openbios-ppc
  openbios-sparc32 openbios-sparc64 palcode-clipper s390-ccw.img

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PR PATCH] [Updated] binfmt handling improvements, qemu: update to 9.0.1
  2024-06-15 19:00 [PR PATCH] binfmt handling improvements, qemu: update to 9.0.1 classabbyamp
  2024-06-16  7:50 ` [PR PATCH] [Updated] " classabbyamp
@ 2024-06-16 18:38 ` classabbyamp
  2024-06-17 20:13 ` [PR PATCH] [Merged]: " classabbyamp
  2 siblings, 0 replies; 4+ messages in thread
From: classabbyamp @ 2024-06-16 18:38 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]

There is an updated pull request by classabbyamp against master on the void-packages repository

https://github.com/classabbyamp/void-packages qemu-binfmt
https://github.com/void-linux/void-packages/pull/50838

binfmt handling improvements, qemu: update to 9.0.1
This cleans up a lot of the binfmt handling in triggers and especially qemu-user-static.

- `update-binfmts --import` is a lot cleaner than `update-binfmts --install`
- moves the important data out of the install script and into the package itself (`/usr/share/binfmts`)
- allows the `binfmts` trigger to be detected automatically
- old behaviour kept around for compatibility, with signficant cleanups to the code
- qemu provides a script to generate binfmt definitions in the format `update-binfmts --import` understands, removing a bunch of junk from the template
- these definition files are simple enough that we can generate it for wine during build

<!-- Uncomment relevant sections and delete options which are not applicable -->

#### Testing the changes
- I tested the changes in this PR: **YES**



A patch file from https://github.com/void-linux/void-packages/pull/50838.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-qemu-binfmt-50838.patch --]
[-- Type: text/x-diff, Size: 18549 bytes --]

From 374b6c7beaef9da2e7143b308751c8d57b18d3c3 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:12:09 -0400
Subject: [PATCH 1/7] xbps-triggers: support importing/unimporting binfmt files

removes the need to manually list all the binfmt magics and masks in
qemu-user-static.

keeps the legacy behaviour around for compatibility
---
 srcpkgs/xbps-triggers/files/binfmts | 63 ++++++++++++++++++++++-------
 srcpkgs/xbps-triggers/template      |  2 +-
 2 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/binfmts b/srcpkgs/xbps-triggers/files/binfmts
index 16919833a80b0d..4212afd1e0d60b 100755
--- a/srcpkgs/xbps-triggers/files/binfmts
+++ b/srcpkgs/xbps-triggers/files/binfmts
@@ -19,32 +19,65 @@ UPDATE="$5"
 
 export PATH="usr/bin:usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin"
 
+# {install,remove}_binfmts: legacy installation style
+install_binfmts() {
+	echo "$binfmts" | while read -r line; do
+		set -- $line
+		_bin="$1"; shift
+		_bname="${_bin##*/}"
+		update-binfmts --package "${PKGNAME}" --install "${_bname}" "${_bin}" "$@"
+	done
+}
+
+remove_binfmts() {
+	echo "$binfmts" | while read -r line; do
+		set -- $line
+		_bin="$1"; shift
+		_bname="${_bin##*/}"
+		if [ -f "var/lib/binfmts/${_bname}" ]; then
+			update-binfmts --package "${PKGNAME}" --remove "${_bname}" "${_bin}"
+		fi
+	done
+}
+
+# {,un}import_binfmts: new installation style
+import_binfmts() {
+	for _fmt in $import_binfmts; do
+		update-binfmts --import "$_fmt"
+	done
+}
+
+unimport_binfmts() {
+	for _fmt in $import_binfmts; do
+		if [ -f "var/lib/binfmts/${_fmt}" ]; then
+			update-binfmts --unimport "$_fmt"
+		fi
+	done
+}
+
 case "$ACTION" in
 targets)
 	echo "post-install pre-remove"
 	;;
 run)
 	[ -x /usr/bin/update-binfmts ] || exit 0
-	[ -z "${binfmts}" ] && exit 0
 
 	case "$TARGET" in
 	post-install)
-		echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do
-			line=$(echo $line | tr '&' '\' 2> /dev/null)
-			set -- ${line}
-			_bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})"
-			update-binfmts --package ${PKGNAME} --install ${_bname} ${_bin} ${_args}
-		done
+		if [ -n "${binfmts}" ]; then
+			install_binfmts
+		fi
+		if [ -n "${import_binfmts}" ]; then
+			import_binfmts
+		fi
 		;;
 	pre-remove)
-		echo "$binfmts" | tr '\' '&' 2> /dev/null | while read line; do
-			line=$(echo $line | tr '&' '\' 2> /dev/null)
-			set -- ${line}
-			_bin="$1"; shift; _args="$@"; _bname="$(basename ${_bin})"
-			if [ -f /var/lib/binfmts/${_bname} ]; then
-				update-binfmts --package ${PKGNAME} --remove ${_bname} ${_bin}
-			fi
-		done
+		if [ -n "${binfmts}" ]; then
+			remove_binfmts
+		fi
+		if [ -n "${import_binfmts}" ]; then
+			unimport_binfmts
+		fi
 		;;
 	*)
 		exit 1
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index 66936411a42588..7745a9aa4f12d2 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.127
+version=0.128
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

From 08d1f154f34e4af6f2848972efc6795c9a60e0b0 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:15:34 -0400
Subject: [PATCH 2/7] common/hooks/post-install: support new binfmts hook style

---
 .../hooks/post-install/04-create-xbps-metadata-scripts.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/hooks/post-install/04-create-xbps-metadata-scripts.sh b/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
index f21017f8361e6d..70152bad55f4fc 100644
--- a/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
+++ b/common/hooks/post-install/04-create-xbps-metadata-scripts.sh
@@ -119,10 +119,16 @@ _EOF
 	#
 	# Handle binfmts trigger
 	#
-	if [ -n "${binfmts}" ]; then
+	if [ -n "${binfmts}" ] || [ -d "${PKGDESTDIR}/usr/share/binfmts" ]; then
 		_add_trigger binfmts
+	fi
+	if [ -n "${binfmts}" ]; then
 		echo "export binfmts=\"${binfmts}\"" >> $tmpf
 	fi
+	if [ -d "${PKGDESTDIR}/usr/share/binfmts" ]; then
+		_import_binfmts="$(find "${PKGDESTDIR}/usr/share/binfmts" -type f -printf '%f\n')"
+		echo "export import_binfmts=\"${_import_binfmts}\"" >> $tmpf
+	fi
 	#
 	# Handle GNU Info files.
 	#

From 4cda4a60126721f9ef8b55fbbaf51b4fdb845ea2 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:11:12 -0400
Subject: [PATCH 3/7] Manual.md: document new binfmts trigger behaviour

---
 Manual.md | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Manual.md b/Manual.md
index f323739ffed362..96b6a3fcacaadb 100644
--- a/Manual.md
+++ b/Manual.md
@@ -1804,8 +1804,19 @@ executable binary formats, know as binfmts.
 During installation/removal it uses `update-binfmts` from the `binfmt-support` package
 to register/remove entries from the arbitrary executable binary formats database.
 
-To include the trigger use the `binfmts` variable, as the trigger won't do anything unless
-it is defined.
+It is automatically added to packages that contain files in `usr/share/binfmts`.
+These files should be `update-binfmts` format files and will be imported with
+`update-binfmts --import`.
+
+While it is not preferred, the trigger can also be added by using the `binfmts` variable,
+which should contain lines defining binfmts to register:
+
+```
+/path/to/interpreter [update-binfmts binary format specification arguments ...]
+...
+```
+
+See [`update-binfmts(8)`](https://man.voidlinux.org/man8/update-binfmts.8) for more details.
 
 <a id="triggers_dkms"></a>
 #### dkms

From a33498ccff09c0e8eebab83f0eb65923169d68d1 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:15:07 -0400
Subject: [PATCH 4/7] binfmt-support: depend on xbps-triggers

---
 srcpkgs/binfmt-support/template | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/srcpkgs/binfmt-support/template b/srcpkgs/binfmt-support/template
index aefbc2a026b3b5..634109b979de5c 100644
--- a/srcpkgs/binfmt-support/template
+++ b/srcpkgs/binfmt-support/template
@@ -1,10 +1,11 @@
 # Template file for 'binfmt-support'
 pkgname=binfmt-support
 version=2.2.2
-revision=1
+revision=2
 build_style=gnu-configure
 hostmakedepends="pkg-config"
 makedepends="libpipeline-devel"
+depends="xbps-triggers>=0.128_1"
 short_desc="Register interpreters for various binary formats"
 maintainer="Andrea Brancaleoni <abc@pompel.me>"
 license="GPL-2.0-or-later"

From 844780bcce9d0a62eb276536ddf686807287f7ce Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:16:31 -0400
Subject: [PATCH 5/7] wine: provide binfmt file

this matches the one debian provides
---
 srcpkgs/wine/template | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/srcpkgs/wine/template b/srcpkgs/wine/template
index 072ac5bfef314e..b6be758459b4b5 100644
--- a/srcpkgs/wine/template
+++ b/srcpkgs/wine/template
@@ -1,7 +1,7 @@
 # Template file for 'wine'
 pkgname=wine
 version=9.11
-revision=1
+revision=2
 _pkgver=${version/r/-r}
 create_wrksrc=yes
 build_wrksrc=wine-${_pkgver}
@@ -141,7 +141,6 @@ wine-devel_package() {
 
 wine-common_package() {
 	short_desc+=" - common files"
-	binfmts="/usr/bin/wine --magic MZ"
 	pkg_install() {
 		vmove usr/share
 		vmove etc/fonts
@@ -149,6 +148,12 @@ wine-common_package() {
 		do
 			vmove usr/bin/${file}
 		done
+		vmkdir usr/share/binfmts
+		cat <<- EOF >> "${PKGDESTDIR}"/usr/share/binfmts/wine
+		package wine
+		interpreter /usr/bin/wine
+		magic MZ
+		EOF
 	}
 }
 

From c3c42a7128a1a5e4cc4dadd81320ba85387f96fa Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:16:54 -0400
Subject: [PATCH 6/7] qemu-user-static: update to 9.0.1, clean up binfmt
 generation

qemu provides a script to generate this in a format update-binfmts
understands
---
 srcpkgs/qemu-user-static/template | 113 ++++++------------------------
 1 file changed, 22 insertions(+), 91 deletions(-)

diff --git a/srcpkgs/qemu-user-static/template b/srcpkgs/qemu-user-static/template
index c29ed1dadf247d..858f035de38b05 100644
--- a/srcpkgs/qemu-user-static/template
+++ b/srcpkgs/qemu-user-static/template
@@ -1,8 +1,8 @@
 # Template file for 'qemu-user-static'
 # This package should be updated together with qemu
 pkgname=qemu-user-static
-version=9.0.0
-revision=2
+version=9.0.1
+revision=1
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec
  --disable-kvm --disable-png --disable-virtfs --disable-fdt --disable-seccomp
@@ -14,103 +14,20 @@ maintainer="Orphaned <orphan@voidlinux.org>"
 license="GPL-2.0-only, LGPL-2.1-only"
 homepage="https://www.qemu.org"
 distfiles="https://wiki.qemu.org/download/qemu-${version}.tar.bz2"
-checksum=f816255215ed495d164311210e05aec867c4cb22576b41b2d723209de579ed61
-
-_fmts="aarch64 aarch64_be alpha arm armeb cris hppa i386 m68k microblaze
- microblazeel mips mipsel mips64 mips64el mipsn32 mipsn32el or1k
- ppc ppcle ppc64 ppc64le riscv32 riscv64 s390x sh4 sh4eb
- sparc sparc32plus sparc64 x86_64 xtensa xtensaeb"
-
-_aarch64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
-_aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_aarch64_be_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'
-_aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_alpha_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90'
-_alpha_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_arm_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
-_arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_armeb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28'
-_armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_cris_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x4c\x00'
-_cris_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f'
-_hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_i386_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
-_i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_m68k_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04'
-_m68k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_microblaze_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xba\xab'
-_microblaze_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_microblazeel_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xab\xba'
-_microblazeel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mips_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mipsel_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mips64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mips64el_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_mipsn32_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'
-_mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_mipsn32el_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'
-_mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_or1k_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5c'
-_or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppc_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14'
-_ppc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppcle_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14\x00'
-_ppcle_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00'
-_ppc64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15'
-_ppc64_mask='\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_ppc64le_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00'
-_ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00'
-_riscv32_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'
-_riscv32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_riscv64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'
-_riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_s390x_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16'
-_s390x_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sh4_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00'
-_sh4_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_sh4eb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a'
-_sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'
-_sparc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc32plus_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12'
-_sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_sparc64_magic='\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b'
-_sparc64_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
-_x86_64_magic='\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00'
-_x86_64_mask='\xff\xff\xff\xff\xff\xfe\xfe\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_xtensa_magic='\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e\x00'
-_xtensa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
-_xtensaeb_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e'
-_xtensaeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
+checksum=c79bd301abd9f2501bdf0a543c6f6f7474424178dcfde2be271150988cadc0a7
 
 if [ "$CROSS_BUILD" ]; then
 	configure_args+=" --cross-prefix=${XBPS_CROSS_TRIPLET}-"
 fi
 
+_omit=("${XBPS_TARGET_MACHINE%-*}")
 case "$XBPS_TARGET_MACHINE" in
-	x86_64*) _omit="i386|x86_64" ;;
-	aarch64*) _omit="aarch64" ;;
-	armv*) _omit="arm" ;;
-	ppc64le*) _omit="ppc64le|ppcle" ;;
-	ppc64*) _omit="ppc64|ppc" ;;
-	*) _omit="${XBPS_TARGET_MACHINE%-*}" ;;
+	x86_64*) _omit+=(i386) ;;
+	armv*) _omit+=(arm) ;;
+	ppc64le*) _omit+=(ppcle) ;;
+	ppc64*) _omit+=(ppc) ;;
 esac
 
-for _fmt in $_fmts; do
-	eval "case $_fmt in $_omit) magic= ;; *) magic=\"\$_${_fmt}_magic\" mask=\"\$_${_fmt}_mask\" ;; esac"
-	if [ "$magic" ]; then
-		binfmts+="/usr/bin/qemu-$_fmt-static --magic $magic --mask $mask --offset 0 --credentials yes --fix-binary yes
-"
-	fi
-done
-
-binfmts="${binfmts%?}"
-
 post_install() {
 	# Remove unneeded stuff.
 	rm -rf ${DESTDIR}/etc ${DESTDIR}/usr/share ${DESTDIR}/usr/libexec
@@ -120,4 +37,18 @@ post_install() {
 	for f in ${DESTDIR}/usr/bin/*; do
 		mv ${f} ${f}-static
 	done
+
+	vmkdir usr/share/binfmts
+	scripts/qemu-binfmt-conf.sh --debian ALL --exportdir "${DESTDIR}"/usr/share/binfmts \
+		--qemu-path /usr/bin --preserve-argv0 yes --persistent yes --credential yes
+	for bf in "${DESTDIR}"/usr/share/binfmts/*; do
+		for ar in "${_omit[@]}"; do
+			if [[ "$bf" = */qemu-"$ar" ]]; then
+				rm "$bf"
+				continue 2
+			fi
+		done
+		vsed -i -e "s/${bf##*/}/&-static/g" "$bf"
+		mv "$bf" "${bf}-static"
+	done
 }

From 69b2da25217b88ab91c65d6bdfa0376dc1749263 Mon Sep 17 00:00:00 2001
From: classabbyamp <void@placeviolette.net>
Date: Sat, 15 Jun 2024 12:17:35 -0400
Subject: [PATCH 7/7] qemu: update to 9.0.1.

---
 srcpkgs/qemu/template | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/srcpkgs/qemu/template b/srcpkgs/qemu/template
index 623f197ff9b7cf..e05d7ce5620265 100644
--- a/srcpkgs/qemu/template
+++ b/srcpkgs/qemu/template
@@ -1,8 +1,8 @@
 # Template file for 'qemu'
 # This package should be updated together with qemu-user-static
 pkgname=qemu
-version=9.0.0
-revision=2
+version=9.0.1
+revision=1
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec --localstatedir=/var
  --disable-glusterfs --disable-xen --enable-docs --enable-kvm --enable-libusb --enable-pie
@@ -28,7 +28,7 @@ maintainer="Orphaned <orphan@voidlinux.org>"
 license="GPL-2.0-only, LGPL-2.1-only"
 homepage="https://www.qemu.org"
 distfiles="https://wiki.qemu.org/download/qemu-${version}.tar.bz2"
-checksum=f816255215ed495d164311210e05aec867c4cb22576b41b2d723209de579ed61
+checksum=c79bd301abd9f2501bdf0a543c6f6f7474424178dcfde2be271150988cadc0a7
 ignore_elf_dirs="/usr/share/qemu"
 nostrip_files="hppa-firmware.img hppa-firmware64.img openbios-ppc
  openbios-sparc32 openbios-sparc64 palcode-clipper s390-ccw.img

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PR PATCH] [Merged]: binfmt handling improvements, qemu: update to 9.0.1
  2024-06-15 19:00 [PR PATCH] binfmt handling improvements, qemu: update to 9.0.1 classabbyamp
  2024-06-16  7:50 ` [PR PATCH] [Updated] " classabbyamp
  2024-06-16 18:38 ` classabbyamp
@ 2024-06-17 20:13 ` classabbyamp
  2 siblings, 0 replies; 4+ messages in thread
From: classabbyamp @ 2024-06-17 20:13 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]

There's a merged pull request on the void-packages repository

binfmt handling improvements, qemu: update to 9.0.1
https://github.com/void-linux/void-packages/pull/50838

Description:
This cleans up a lot of the binfmt handling in triggers and especially qemu-user-static.

- `update-binfmts --import` is a lot cleaner than `update-binfmts --install`
- moves the important data out of the install script and into the package itself (`/usr/share/binfmts`)
- allows the `binfmts` trigger to be detected automatically
- old behaviour kept around for compatibility, with signficant cleanups to the code
- qemu provides a script to generate binfmt definitions in the format `update-binfmts --import` understands, removing a bunch of junk from the template
- these definition files are simple enough that we can generate it for wine during build

<!-- Uncomment relevant sections and delete options which are not applicable -->

#### Testing the changes
- I tested the changes in this PR: **YES**



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-17 20:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-15 19:00 [PR PATCH] binfmt handling improvements, qemu: update to 9.0.1 classabbyamp
2024-06-16  7:50 ` [PR PATCH] [Updated] " classabbyamp
2024-06-16 18:38 ` classabbyamp
2024-06-17 20:13 ` [PR PATCH] [Merged]: " classabbyamp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).