proj/portage:master commit in: lib/portage/package/ebuild/_config/, bin/

"Sam James" <[email protected]>
Newsgroups gmane.linux.gentoo.cvs
Message-ID <1786673566.7d73f9873e3130ce92f54299a7c64dc007b566b6.sam@gentoo>
commit:     7d73f9873e3130ce92f54299a7c64dc007b566b6
Author:     Pepper Gray <hello <AT> peppergray <DOT> xyz>
AuthorDate: Sat Jul  4 12:09:31 2026 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug 14 02:12:46 2026 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=7d73f987

special_env_vars.py: preserve QEMU_* for qemu-static

When running emerge in a cross architecture chroot via qemu-static
with extensions that are not enabled by default it fails with error:
```
Sandboxed process killed by signal: Illegal instruction
 * The ebuild phase 'unpack' has been killed by signal 4.
```
This is caused by qemu-static being invoked without the QEMU_* vars.
They have already been stripped by environ, but not yet being added
back in _grab_pkg_env. Thus qemu-static falls back to its  default
settings for the target architecture and doesn't load the
needed cpu extensions.

Therefore `sandbox` (environ) and `bash` (__filter_readonly_variables)
fail, when execting in a cross arch chroot.

For qemu-static to work properly:
- allow QEMU_* vars through the environ filter
- add QEMU_* vars to the readonly vars filter environment

Closes: https://bugs.gentoo.org/978685
Signed-off-by: Pepper Gray <hello <AT> peppergray.xyz>
Part-of: https://github.com/gentoo/portage/pull/1622
Closes: https://github.com/gentoo/portage/pull/1622
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/phase-functions.sh                                 | 11 ++++++++---
 lib/portage/package/ebuild/_config/special_env_vars.py |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index b383ec08f..ebad8b8eb 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -86,14 +86,19 @@ portage_mutable_filtered_vars=( AA HOSTNAME )
 # is to preserve various variables as they were at the time that the binary
 # package was built while protecting against the application of package renames.
 __filter_readonly_variables() {
-	local -a filtered_vars bash_vars
-	local IFS
+	local -a filtered_vars bash_vars qemu_env
+	local IFS x
+
+	# preserve QEMU vars for qemu-static
+	for x in ${!QEMU_@}; do
+		qemu_env+=( "${x}=${!x}" )
+	done
 
 	# Collect an initial list of special bash variables by instructing a
 	# hygienic instance of bash(1) to report them.
 	mapfile -t bash_vars < <(
 		# Like compgen -A variable but doesn't require readline support.
-		env -i -- "${BASH}" -c "printf %s\\\n $(printf '${!%s*} ' {A..Z} {a..z} _)" \
+		env -i -- "${qemu_env[@]}" "${BASH}" -c "printf %s\\\n $(printf '${!%s*} ' {A..Z} {a..z} _)" \
 		| grep -vx -e PATH -e SHELL
 	)
 	# Incorporate other variables that are known to either be set by or be

diff --git a/lib/portage/package/ebuild/_config/special_env_vars.py b/lib/portage/package/ebuild/_config/special_env_vars.py
index 76fef9e2c..056f3a112 100644
--- a/lib/portage/package/ebuild/_config/special_env_vars.py
+++ b/lib/portage/package/ebuild/_config/special_env_vars.py
@@ -247,7 +247,7 @@ environ_whitelist = frozenset(
     )
 )
 
-environ_whitelist_re = re.compile(r"^(CCACHE_|DISTCC_).*")
+environ_whitelist_re = re.compile(r"^(CCACHE_|DISTCC_|QEMU_).*")
 
 # Filter selected variables in the config.environ() method so that
 # they don't needlessly propagate down into the ebuild environment.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.