Gentoo Archives: gentoo-commits

From: Matthias Maier <tamiko@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-emulation/qemu/, app-emulation/qemu/files/
Date: Fri, 01 Sep 2017 01:32:41
Message-Id: 1504229474.ecbdc929ac2d3b34812aa3b3ac07054198a0547c.tamiko@gentoo
1 commit: ecbdc929ac2d3b34812aa3b3ac07054198a0547c
2 Author: Matthias Maier <tamiko <AT> gentoo <DOT> org>
3 AuthorDate: Fri Sep 1 01:31:14 2017 +0000
4 Commit: Matthias Maier <tamiko <AT> gentoo <DOT> org>
5 CommitDate: Fri Sep 1 01:31:14 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ecbdc929
7
8 app-emulation/qemu: version bump to 2.10.0, bug #629350
9
10 This version bump also addresses a number of security issues
11 CVE-2017-12809, bug #628498
12 CVE-2017-13673, bug #629316
13 CVE-2017-13711, bug #629350
14
15 Package-Manager: Portage-2.3.6, Repoman-2.3.3
16
17 app-emulation/qemu/Manifest | 1 +
18 .../qemu/files/qemu-2.10.0-CVE-2017-13711.patch | 80 +++
19 app-emulation/qemu/qemu-2.10.0.ebuild | 781 +++++++++++++++++++++
20 3 files changed, 862 insertions(+)
21
22 diff --git a/app-emulation/qemu/Manifest b/app-emulation/qemu/Manifest
23 index fb4bf044093..0c8db490a09 100644
24 --- a/app-emulation/qemu/Manifest
25 +++ b/app-emulation/qemu/Manifest
26 @@ -1 +1,2 @@
27 +DIST qemu-2.10.0.tar.bz2 30955656 SHA256 7e9f39e1306e6dcc595494e91c1464d4b03f55ddd2053183e0e1b69f7f776d48 SHA512 ea21c014030f8a902df159641e6ccb45f0850ac5cb1cb8ab6845124c44ea5def54845e7bc66a6e80d624c78069f9baa913ee5119704076ae4ff47ab018ace9f9 WHIRLPOOL 58f846788fdf2b0c90e6d17ce921a1fe02556968d38ffc11be7e32b81ebc723dfeaa790f22d8085d4f388eb01fe0daa3ddbc00630c5ecba083df33cc9709fb39
28 DIST qemu-2.9.0.tar.bz2 28720490 SHA256 00bfb217b1bb03c7a6c3261b819cfccbfb5a58e3e2ceff546327d271773c6c14 SHA512 4b28966eec0ca44681e35fcfb64a4eaef7c280b8d65c91d03f2efa37f76278fd8c1680e5798c7a30dbfcc8f3c05f4a803f48b8a2dfec3a4181bac079b2a5e422 WHIRLPOOL d79fe89eb271a56aee0cbd328e5f96999176b711afb5683d164b7b99d91e6dd2bfaf6e2ff4cd820a941c94f28116765cb07ffd5809d75c2f9654a67d56bfc0c1
29
30 diff --git a/app-emulation/qemu/files/qemu-2.10.0-CVE-2017-13711.patch b/app-emulation/qemu/files/qemu-2.10.0-CVE-2017-13711.patch
31 new file mode 100644
32 index 00000000000..9d026568492
33 --- /dev/null
34 +++ b/app-emulation/qemu/files/qemu-2.10.0-CVE-2017-13711.patch
35 @@ -0,0 +1,80 @@
36 +From 1201d308519f1e915866d7583d5136d03cc1d384 Mon Sep 17 00:00:00 2001
37 +From: Samuel Thibault <samuel.thibault@××××××××.org>
38 +Date: Fri, 25 Aug 2017 01:35:53 +0200
39 +Subject: [PATCH] slirp: fix clearing ifq_so from pending packets
40 +MIME-Version: 1.0
41 +Content-Type: text/plain; charset=UTF-8
42 +Content-Transfer-Encoding: 8bit
43 +
44 +The if_fastq and if_batchq contain not only packets, but queues of packets
45 +for the same socket. When sofree frees a socket, it thus has to clear ifq_so
46 +from all the packets from the queues, not only the first.
47 +
48 +Signed-off-by: Samuel Thibault <samuel.thibault@××××××××.org>
49 +Reviewed-by: Philippe Mathieu-Daudé <f4bug@×××××.org>
50 +Cc: qemu-stable@××××××.org
51 +Signed-off-by: Peter Maydell <peter.maydell@××××××.org>
52 +---
53 + slirp/socket.c | 39 +++++++++++++++++++++++----------------
54 + 1 file changed, 23 insertions(+), 16 deletions(-)
55 +
56 +diff --git a/slirp/socket.c b/slirp/socket.c
57 +index ecec0295a9..cb7b5b608d 100644
58 +--- a/slirp/socket.c
59 ++++ b/slirp/socket.c
60 +@@ -60,29 +60,36 @@ socreate(Slirp *slirp)
61 + }
62 +
63 + /*
64 ++ * Remove references to so from the given message queue.
65 ++ */
66 ++static void
67 ++soqfree(struct socket *so, struct quehead *qh)
68 ++{
69 ++ struct mbuf *ifq;
70 ++
71 ++ for (ifq = (struct mbuf *) qh->qh_link;
72 ++ (struct quehead *) ifq != qh;
73 ++ ifq = ifq->ifq_next) {
74 ++ if (ifq->ifq_so == so) {
75 ++ struct mbuf *ifm;
76 ++ ifq->ifq_so = NULL;
77 ++ for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) {
78 ++ ifm->ifq_so = NULL;
79 ++ }
80 ++ }
81 ++ }
82 ++}
83 ++
84 ++/*
85 + * remque and free a socket, clobber cache
86 + */
87 + void
88 + sofree(struct socket *so)
89 + {
90 + Slirp *slirp = so->slirp;
91 +- struct mbuf *ifm;
92 +
93 +- for (ifm = (struct mbuf *) slirp->if_fastq.qh_link;
94 +- (struct quehead *) ifm != &slirp->if_fastq;
95 +- ifm = ifm->ifq_next) {
96 +- if (ifm->ifq_so == so) {
97 +- ifm->ifq_so = NULL;
98 +- }
99 +- }
100 +-
101 +- for (ifm = (struct mbuf *) slirp->if_batchq.qh_link;
102 +- (struct quehead *) ifm != &slirp->if_batchq;
103 +- ifm = ifm->ifq_next) {
104 +- if (ifm->ifq_so == so) {
105 +- ifm->ifq_so = NULL;
106 +- }
107 +- }
108 ++ soqfree(so, &slirp->if_fastq);
109 ++ soqfree(so, &slirp->if_batchq);
110 +
111 + if (so->so_emu==EMU_RSH && so->extra) {
112 + sofree(so->extra);
113 +--
114 +2.13.5
115 +
116
117 diff --git a/app-emulation/qemu/qemu-2.10.0.ebuild b/app-emulation/qemu/qemu-2.10.0.ebuild
118 new file mode 100644
119 index 00000000000..e9342fbc380
120 --- /dev/null
121 +++ b/app-emulation/qemu/qemu-2.10.0.ebuild
122 @@ -0,0 +1,781 @@
123 +# Copyright 1999-2017 Gentoo Foundation
124 +# Distributed under the terms of the GNU General Public License v2
125 +
126 +EAPI="6"
127 +
128 +PYTHON_COMPAT=( python2_7 )
129 +PYTHON_REQ_USE="ncurses,readline"
130 +
131 +PLOCALES="bg de_DE fr_FR hu it tr zh_CN"
132 +
133 +FIRMWARE_ABI_VERSION="2.9.0-r52"
134 +
135 +inherit eutils flag-o-matic linux-info toolchain-funcs multilib python-r1 \
136 + user udev fcaps readme.gentoo-r1 pax-utils l10n
137 +
138 +if [[ ${PV} = *9999* ]]; then
139 + EGIT_REPO_URI="git://git.qemu.org/qemu.git"
140 + inherit git-r3
141 + SRC_URI=""
142 +else
143 + SRC_URI="http://wiki.qemu-project.org/download/${P}.tar.bz2"
144 + KEYWORDS="~amd64 ~arm64 ~ppc ~ppc64 ~x86 ~x86-fbsd"
145 +fi
146 +
147 +DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
148 +HOMEPAGE="http://www.qemu.org http://www.linux-kvm.org"
149 +
150 +LICENSE="GPL-2 LGPL-2 BSD-2"
151 +SLOT="0"
152 +IUSE="accessibility +aio alsa bluetooth bzip2 +caps +curl debug +fdt
153 + glusterfs gnutls gtk gtk2 infiniband iscsi +jpeg kernel_linux
154 + kernel_FreeBSD lzo ncurses nfs nls numa opengl +pin-upstream-blobs +png
155 + pulseaudio python rbd sasl +seccomp sdl sdl2 selinux smartcard snappy
156 + spice ssh static static-user systemtap tci test usb usbredir vde
157 + +vhost-net virgl virtfs +vnc vte xattr xen xfs"
158 +
159 +COMMON_TARGETS="aarch64 alpha arm cris i386 m68k microblaze microblazeel
160 + mips mips64 mips64el mipsel nios2 or1k ppc ppc64 s390x sh4 sh4eb sparc
161 + sparc64 x86_64"
162 +IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS}
163 + lm32 moxie ppcemb tricore unicore32 xtensa xtensaeb"
164 +IUSE_USER_TARGETS="${COMMON_TARGETS}
165 + armeb hppa mipsn32 mipsn32el ppc64abi32 ppc64le sparc32plus tilegx"
166 +
167 +use_softmmu_targets=$(printf ' qemu_softmmu_targets_%s' ${IUSE_SOFTMMU_TARGETS})
168 +use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
169 +IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
170 +
171 +# Allow no targets to be built so that people can get a tools-only build.
172 +# Block USE flag configurations known to not work.
173 +REQUIRED_USE="${PYTHON_REQUIRED_USE}
174 + gtk2? ( gtk )
175 + qemu_softmmu_targets_arm? ( fdt )
176 + qemu_softmmu_targets_microblaze? ( fdt )
177 + qemu_softmmu_targets_mips64el? ( fdt )
178 + qemu_softmmu_targets_ppc? ( fdt )
179 + qemu_softmmu_targets_ppc64? ( fdt )
180 + sdl2? ( sdl )
181 + static? ( static-user !alsa !bluetooth !gtk !gtk2 !opengl !pulseaudio )
182 + virtfs? ( xattr )
183 + vte? ( gtk )"
184 +
185 +# Dependencies required for qemu tools (qemu-nbd, qemu-img, qemu-io, ...)
186 +# and user/softmmu targets (qemu-*, qemu-system-*).
187 +#
188 +# Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
189 +#
190 +# The attr lib isn't always linked in (although the USE flag is always
191 +# respected). This is because qemu supports using the C library's API
192 +# when available rather than always using the extranl library.
193 +ALL_DEPEND="
194 + >=dev-libs/glib-2.0[static-libs(+)]
195 + sys-libs/zlib[static-libs(+)]
196 + python? ( ${PYTHON_DEPS} )
197 + systemtap? ( dev-util/systemtap )
198 + xattr? ( sys-apps/attr[static-libs(+)] )"
199 +
200 +# Dependencies required for qemu tools (qemu-nbd, qemu-img, qemu-io, ...)
201 +# softmmu targets (qemu-system-*).
202 +SOFTMMU_TOOLS_DEPEND="
203 + >=x11-libs/pixman-0.28.0[static-libs(+)]
204 + accessibility? (
205 + app-accessibility/brltty[api]
206 + app-accessibility/brltty[static-libs(+)]
207 + )
208 + aio? ( dev-libs/libaio[static-libs(+)] )
209 + alsa? ( >=media-libs/alsa-lib-1.0.13 )
210 + bluetooth? ( net-wireless/bluez )
211 + bzip2? ( app-arch/bzip2[static-libs(+)] )
212 + caps? ( sys-libs/libcap-ng[static-libs(+)] )
213 + curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
214 + fdt? ( >=sys-apps/dtc-1.4.0[static-libs(+)] )
215 + glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
216 + gnutls? (
217 + dev-libs/nettle:=[static-libs(+)]
218 + >=net-libs/gnutls-3.0:=[static-libs(+)]
219 + )
220 + gtk? (
221 + gtk2? (
222 + x11-libs/gtk+:2
223 + vte? ( x11-libs/vte:0 )
224 + )
225 + !gtk2? (
226 + x11-libs/gtk+:3
227 + vte? ( x11-libs/vte:2.91 )
228 + )
229 + )
230 + infiniband? ( sys-fabric/librdmacm:=[static-libs(+)] )
231 + iscsi? ( net-libs/libiscsi )
232 + jpeg? ( virtual/jpeg:0=[static-libs(+)] )
233 + lzo? ( dev-libs/lzo:2[static-libs(+)] )
234 + ncurses? (
235 + sys-libs/ncurses:0=[unicode]
236 + sys-libs/ncurses:0=[static-libs(+)]
237 + )
238 + nfs? ( >=net-fs/libnfs-1.9.3[static-libs(+)] )
239 + numa? ( sys-process/numactl[static-libs(+)] )
240 + opengl? (
241 + virtual/opengl
242 + media-libs/libepoxy[static-libs(+)]
243 + media-libs/mesa[static-libs(+)]
244 + media-libs/mesa[egl,gbm]
245 + )
246 + png? ( media-libs/libpng:0=[static-libs(+)] )
247 + pulseaudio? ( media-sound/pulseaudio )
248 + rbd? ( sys-cluster/ceph[static-libs(+)] )
249 + sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
250 + sdl? (
251 + !sdl2? (
252 + media-libs/libsdl[X]
253 + >=media-libs/libsdl-1.2.11[static-libs(+)]
254 + )
255 + sdl2? (
256 + media-libs/libsdl2[X]
257 + media-libs/libsdl2[static-libs(+)]
258 + )
259 + )
260 + seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
261 + smartcard? ( >=app-emulation/libcacard-2.5.0[static-libs(+)] )
262 + snappy? ( app-arch/snappy:=[static-libs(+)] )
263 + spice? (
264 + >=app-emulation/spice-protocol-0.12.3
265 + >=app-emulation/spice-0.12.0[static-libs(+)]
266 + )
267 + ssh? ( >=net-libs/libssh2-1.2.8[static-libs(+)] )
268 + usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
269 + usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
270 + vde? ( net-misc/vde[static-libs(+)] )
271 + virgl? ( media-libs/virglrenderer[static-libs(+)] )
272 + virtfs? ( sys-libs/libcap )
273 + xen? ( app-emulation/xen-tools:= )
274 + xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
275 +
276 +X86_FIRMWARE_DEPEND="
277 + pin-upstream-blobs? (
278 + ~sys-firmware/edk2-ovmf-2017_pre20170505[binary]
279 + ~sys-firmware/ipxe-1.0.0_p20160620
280 + ~sys-firmware/seabios-1.10.2[binary,seavgabios]
281 + ~sys-firmware/sgabios-0.1_pre8
282 + )
283 + !pin-upstream-blobs? (
284 + sys-firmware/edk2-ovmf
285 + sys-firmware/ipxe
286 + >=sys-firmware/seabios-1.10.2[seavgabios]
287 + sys-firmware/sgabios
288 + )"
289 +
290 +CDEPEND="
291 + !static? (
292 + ${ALL_DEPEND//\[static-libs(+)]}
293 + ${SOFTMMU_TOOLS_DEPEND//\[static-libs(+)]}
294 + )
295 + qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
296 + qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )"
297 +DEPEND="${CDEPEND}
298 + dev-lang/perl
299 + =dev-lang/python-2*
300 + sys-apps/texinfo
301 + virtual/pkgconfig
302 + kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
303 + gtk? ( nls? ( sys-devel/gettext ) )
304 + static? (
305 + ${ALL_DEPEND}
306 + ${SOFTMMU_TOOLS_DEPEND}
307 + )
308 + static-user? ( ${ALL_DEPEND} )
309 + test? (
310 + dev-libs/glib[utils]
311 + sys-devel/bc
312 + )"
313 +RDEPEND="${CDEPEND}
314 + selinux? ( sec-policy/selinux-qemu )"
315 +
316 +PATCHES=(
317 + "${FILESDIR}"/${PN}-2.5.0-cflags.patch
318 + "${FILESDIR}"/${PN}-2.5.0-sysmacros.patch
319 + "${FILESDIR}"/${PN}-2.10.0-CVE-2017-13711.patch # bug 629350
320 +)
321 +
322 +STRIP_MASK="/usr/share/qemu/palcode-clipper"
323 +
324 +QA_PREBUILT="
325 + usr/share/qemu/openbios-ppc
326 + usr/share/qemu/openbios-sparc64
327 + usr/share/qemu/openbios-sparc32
328 + usr/share/qemu/palcode-clipper
329 + usr/share/qemu/s390-ccw.img
330 + usr/share/qemu/u-boot.e500"
331 +
332 +QA_WX_LOAD="usr/bin/qemu-i386
333 + usr/bin/qemu-x86_64
334 + usr/bin/qemu-alpha
335 + usr/bin/qemu-arm
336 + usr/bin/qemu-cris
337 + usr/bin/qemu-m68k
338 + usr/bin/qemu-microblaze
339 + usr/bin/qemu-microblazeel
340 + usr/bin/qemu-mips
341 + usr/bin/qemu-mipsel
342 + usr/bin/qemu-or1k
343 + usr/bin/qemu-ppc
344 + usr/bin/qemu-ppc64
345 + usr/bin/qemu-ppc64abi32
346 + usr/bin/qemu-sh4
347 + usr/bin/qemu-sh4eb
348 + usr/bin/qemu-sparc
349 + usr/bin/qemu-sparc64
350 + usr/bin/qemu-armeb
351 + usr/bin/qemu-sparc32plus
352 + usr/bin/qemu-s390x
353 + usr/bin/qemu-unicore32"
354 +
355 +DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure you have the
356 +kernel module loaded before running kvm. The easiest way to ensure that the
357 +kernel module is loaded is to load it on boot.
358 + For AMD CPUs the module is called 'kvm-amd'.
359 + For Intel CPUs the module is called 'kvm-intel'.
360 +Please review /etc/conf.d/modules for how to load these.
361 +
362 +Make sure your user is in the 'kvm' group. Just run
363 + $ gpasswd -a <USER> kvm
364 +then have <USER> re-login.
365 +
366 +For brand new installs, the default permissions on /dev/kvm might not let
367 +you access it. You can tell udev to reset ownership/perms:
368 + $ udevadm trigger -c add /dev/kvm
369 +
370 +If you want to register binfmt handlers for qemu user targets:
371 +For openrc:
372 + # rc-update add qemu-binfmt
373 +For systemd:
374 + # ln -s /usr/share/qemu/binfmt.d/qemu.conf /etc/binfmt.d/qemu.conf"
375 +
376 +pkg_pretend() {
377 + if use kernel_linux && kernel_is lt 2 6 25; then
378 + eerror "This version of KVM requres a host kernel of 2.6.25 or higher."
379 + elif use kernel_linux; then
380 + if ! linux_config_exists; then
381 + eerror "Unable to check your kernel for KVM support"
382 + else
383 + CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
384 + ERROR_KVM="You must enable KVM in your kernel to continue"
385 + ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
386 + ERROR_KVM_AMD+=" your kernel configuration."
387 + ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
388 + ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
389 + ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
390 + ERROR_TUN+=" into your kernel or loaded as a module to use the"
391 + ERROR_TUN+=" virtual network device if using -net tap."
392 + ERROR_BRIDGE="You will also need support for 802.1d"
393 + ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
394 + use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
395 + ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
396 + ERROR_VHOST_NET+=" support"
397 +
398 + if use amd64 || use x86 || use amd64-linux || use x86-linux; then
399 + CONFIG_CHECK+=" ~KVM_AMD ~KVM_INTEL"
400 + fi
401 +
402 + use python && CONFIG_CHECK+=" ~DEBUG_FS"
403 + ERROR_DEBUG_FS="debugFS support required for kvm_stat"
404 +
405 + # Now do the actual checks setup above
406 + check_extra_config
407 + fi
408 + fi
409 +
410 + if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
411 + eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
412 + eerror "instances are still pointing to it. Please update your"
413 + eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
414 + eerror "and the right system binary (e.g. qemu-system-x86_64)."
415 + die "update your virt configs to not use qemu-kvm"
416 + fi
417 +}
418 +
419 +pkg_setup() {
420 + enewgroup kvm 78
421 +}
422 +
423 +# Sanity check to make sure target lists are kept up-to-date.
424 +check_targets() {
425 + local var=$1 mak=$2
426 + local detected sorted
427 +
428 + pushd "${S}"/default-configs >/dev/null || die
429 +
430 + # Force C locale until glibc is updated. #564936
431 + detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
432 + sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
433 + if [[ ${sorted} != "${detected}" ]] ; then
434 + eerror "The ebuild needs to be kept in sync."
435 + eerror "${var}: ${sorted}"
436 + eerror "$(printf '%-*s' ${#var} configure): ${detected}"
437 + die "sync ${var} to the list of targets"
438 + fi
439 +
440 + popd >/dev/null
441 +}
442 +
443 +handle_locales() {
444 + # Make sure locale list is kept up-to-date.
445 + local detected sorted
446 + detected=$(echo $(cd po && printf '%s\n' *.po | grep -v messages.po | sed 's:.po$::' | sort -u))
447 + sorted=$(echo $(printf '%s\n' ${PLOCALES} | sort -u))
448 + if [[ ${sorted} != "${detected}" ]] ; then
449 + eerror "The ebuild needs to be kept in sync."
450 + eerror "PLOCALES: ${sorted}"
451 + eerror " po/*.po: ${detected}"
452 + die "sync PLOCALES"
453 + fi
454 +
455 + # Deal with selective install of locales.
456 + if use nls ; then
457 + # Delete locales the user does not want. #577814
458 + rm_loc() { rm po/$1.po || die; }
459 + l10n_for_each_disabled_locale_do rm_loc
460 + else
461 + # Cheap hack to disable gettext .mo generation.
462 + rm -f po/*.po
463 + fi
464 +}
465 +
466 +src_prepare() {
467 + check_targets IUSE_SOFTMMU_TARGETS softmmu
468 + check_targets IUSE_USER_TARGETS linux-user
469 +
470 + # Alter target makefiles to accept CFLAGS set via flag-o
471 + sed -i -r \
472 + -e 's/^(C|OP_C|HELPER_C)FLAGS=/\1FLAGS+=/' \
473 + Makefile Makefile.target || die
474 +
475 + default
476 +
477 + # Fix ld and objcopy being called directly
478 + tc-export AR LD OBJCOPY
479 +
480 + # Verbose builds
481 + MAKEOPTS+=" V=1"
482 +
483 + # Run after we've applied all patches.
484 + handle_locales
485 +}
486 +
487 +##
488 +# configures qemu based on the build directory and the build type
489 +# we are using.
490 +#
491 +qemu_src_configure() {
492 + debug-print-function ${FUNCNAME} "$@"
493 +
494 + local buildtype=$1
495 + local builddir="${S}/${buildtype}-build"
496 +
497 + mkdir "${builddir}"
498 +
499 + local conf_opts=(
500 + --prefix=/usr
501 + --sysconfdir=/etc
502 + --libdir=/usr/$(get_libdir)
503 + --docdir=/usr/share/doc/${PF}/html
504 + --disable-bsd-user
505 + --disable-guest-agent
506 + --disable-strip
507 + --disable-werror
508 + # We support gnutls/nettle for crypto operations. It is possible
509 + # to use gcrypt when gnutls/nettle are disabled (but not when they
510 + # are enabled), but it's not really worth the hassle. Disable it
511 + # all the time to avoid automatically detecting it. #568856
512 + --disable-gcrypt
513 + --python="${PYTHON}"
514 + --cc="$(tc-getCC)"
515 + --cxx="$(tc-getCXX)"
516 + --host-cc="$(tc-getBUILD_CC)"
517 + $(use_enable debug debug-info)
518 + $(use_enable debug debug-tcg)
519 + --enable-docs
520 + $(use_enable tci tcg-interpreter)
521 + $(use_enable xattr attr)
522 + )
523 +
524 + # Disable options not used by user targets. This simplifies building
525 + # static user targets (USE=static-user) considerably.
526 + conf_notuser() {
527 + if [[ ${buildtype} == "user" ]] ; then
528 + echo "--disable-${2:-$1}"
529 + else
530 + use_enable "$@"
531 + fi
532 + }
533 + conf_opts+=(
534 + $(conf_notuser accessibility brlapi)
535 + $(conf_notuser aio linux-aio)
536 + $(conf_notuser bzip2)
537 + $(conf_notuser bluetooth bluez)
538 + $(conf_notuser caps cap-ng)
539 + $(conf_notuser curl)
540 + $(conf_notuser fdt)
541 + $(conf_notuser glusterfs)
542 + $(conf_notuser gnutls)
543 + $(conf_notuser gnutls nettle)
544 + $(conf_notuser gtk)
545 + $(conf_notuser infiniband rdma)
546 + $(conf_notuser iscsi libiscsi)
547 + $(conf_notuser jpeg vnc-jpeg)
548 + $(conf_notuser kernel_linux kvm)
549 + $(conf_notuser lzo)
550 + $(conf_notuser ncurses curses)
551 + $(conf_notuser nfs libnfs)
552 + $(conf_notuser numa)
553 + $(conf_notuser opengl)
554 + $(conf_notuser png vnc-png)
555 + $(conf_notuser rbd)
556 + $(conf_notuser sasl vnc-sasl)
557 + $(conf_notuser sdl)
558 + $(conf_notuser seccomp)
559 + $(conf_notuser smartcard)
560 + $(conf_notuser snappy)
561 + $(conf_notuser spice)
562 + $(conf_notuser ssh libssh2)
563 + $(conf_notuser usb libusb)
564 + $(conf_notuser usbredir usb-redir)
565 + $(conf_notuser vde)
566 + $(conf_notuser vhost-net)
567 + $(conf_notuser virgl virglrenderer)
568 + $(conf_notuser virtfs)
569 + $(conf_notuser vnc)
570 + $(conf_notuser vte)
571 + $(conf_notuser xen)
572 + $(conf_notuser xen xen-pci-passthrough)
573 + $(conf_notuser xfs xfsctl)
574 + )
575 +
576 + if [[ ! ${buildtype} == "user" ]] ; then
577 + # audio options
578 + local audio_opts="oss"
579 + use alsa && audio_opts="alsa,${audio_opts}"
580 + use sdl && audio_opts="sdl,${audio_opts}"
581 + use pulseaudio && audio_opts="pa,${audio_opts}"
582 + conf_opts+=(
583 + --audio-drv-list="${audio_opts}"
584 + )
585 + use gtk && conf_opts+=( --with-gtkabi=$(usex gtk2 2.0 3.0) )
586 + use sdl && conf_opts+=( --with-sdlabi=$(usex sdl2 2.0 1.2) )
587 + fi
588 +
589 + case ${buildtype} in
590 + user)
591 + conf_opts+=(
592 + --enable-linux-user
593 + --disable-system
594 + --disable-blobs
595 + --disable-tools
596 + )
597 + local static_flag="static-user"
598 + ;;
599 + softmmu)
600 + conf_opts+=(
601 + --disable-linux-user
602 + --enable-system
603 + --disable-tools
604 + --with-system-pixman
605 + )
606 + local static_flag="static"
607 + ;;
608 + tools)
609 + conf_opts+=(
610 + --disable-linux-user
611 + --disable-system
612 + --disable-blobs
613 + --enable-tools
614 + )
615 + local static_flag="static"
616 + ;;
617 + esac
618 +
619 + local targets="${buildtype}_targets"
620 + [[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
621 +
622 + # Add support for SystemTAP
623 + use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
624 +
625 + # We always want to attempt to build with PIE support as it results
626 + # in a more secure binary. But it doesn't work with static or if
627 + # the current GCC doesn't have PIE support.
628 + if use ${static_flag}; then
629 + conf_opts+=( --static --disable-pie )
630 + else
631 + tc-enables-pie && conf_opts+=( --enable-pie )
632 + fi
633 +
634 + echo "../configure ${conf_opts[*]}"
635 + cd "${builddir}"
636 + ../configure "${conf_opts[@]}" || die "configure failed"
637 +
638 + # FreeBSD's kernel does not support QEMU assigning/grabbing
639 + # host USB devices yet
640 + use kernel_FreeBSD && \
641 + sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
642 +}
643 +
644 +src_configure() {
645 + local target
646 +
647 + python_setup
648 +
649 + softmmu_targets= softmmu_bins=()
650 + user_targets= user_bins=()
651 +
652 + for target in ${IUSE_SOFTMMU_TARGETS} ; do
653 + if use "qemu_softmmu_targets_${target}"; then
654 + softmmu_targets+=",${target}-softmmu"
655 + softmmu_bins+=( "qemu-system-${target}" )
656 + fi
657 + done
658 +
659 + for target in ${IUSE_USER_TARGETS} ; do
660 + if use "qemu_user_targets_${target}"; then
661 + user_targets+=",${target}-linux-user"
662 + user_bins+=( "qemu-${target}" )
663 + fi
664 + done
665 +
666 + softmmu_targets=${softmmu_targets#,}
667 + user_targets=${user_targets#,}
668 +
669 + [[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
670 + [[ -n ${user_targets} ]] && qemu_src_configure "user"
671 + qemu_src_configure "tools"
672 +}
673 +
674 +src_compile() {
675 + if [[ -n ${user_targets} ]]; then
676 + cd "${S}/user-build"
677 + default
678 + fi
679 +
680 + if [[ -n ${softmmu_targets} ]]; then
681 + cd "${S}/softmmu-build"
682 + default
683 + fi
684 +
685 + cd "${S}/tools-build"
686 + default
687 +}
688 +
689 +src_test() {
690 + if [[ -n ${softmmu_targets} ]]; then
691 + cd "${S}/softmmu-build"
692 + pax-mark m */qemu-system-* #515550
693 + emake -j1 check
694 + emake -j1 check-report.html
695 + fi
696 +}
697 +
698 +qemu_python_install() {
699 + python_domodule "${S}/scripts/qmp/qmp.py"
700 +
701 + python_doscript "${S}/scripts/kvm/vmxcap"
702 + python_doscript "${S}/scripts/qmp/qmp-shell"
703 + python_doscript "${S}/scripts/qmp/qemu-ga-client"
704 +}
705 +
706 +# Generate binfmt support files.
707 +# - /etc/init.d/qemu-binfmt script which registers the user handlers (openrc)
708 +# - /usr/share/qemu/binfmt.d/qemu.conf (for use with systemd-binfmt)
709 +generate_initd() {
710 + local out="${T}/qemu-binfmt"
711 + local out_systemd="${T}/qemu.conf"
712 + local d="${T}/binfmt.d"
713 +
714 + einfo "Generating qemu binfmt scripts and configuration files"
715 +
716 + # Generate the debian fragments first.
717 + mkdir -p "${d}"
718 + "${S}"/scripts/qemu-binfmt-conf.sh \
719 + --debian \
720 + --exportdir "${d}" \
721 + --qemu-path "${EPREFIX}/usr/bin" \
722 + || die
723 + # Then turn the fragments into a shell script we can source.
724 + sed -E -i \
725 + -e 's:^([^ ]+) (.*)$:\1="\2":' \
726 + "${d}"/* || die
727 +
728 + # Generate the init.d script by assembling the fragments from above.
729 + local f qcpu package interpreter magic mask
730 + cat "${FILESDIR}"/qemu-binfmt.initd.head >"${out}" || die
731 + for f in "${d}"/qemu-* ; do
732 + source "${f}"
733 +
734 + # Normalize the cpu logic like we do in the init.d for the native cpu.
735 + qcpu=${package#qemu-}
736 + case ${qcpu} in
737 + arm*) qcpu="arm";;
738 + mips*) qcpu="mips";;
739 + ppc*) qcpu="ppc";;
740 + s390*) qcpu="s390";;
741 + sh*) qcpu="sh";;
742 + sparc*) qcpu="sparc";;
743 + esac
744 +
745 + cat <<EOF >>"${out}"
746 + if [ "\${cpu}" != "${qcpu}" -a -x "${interpreter}" ] ; then
747 + echo ':${package}:M::${magic}:${mask}:${interpreter}:'"\${QEMU_BINFMT_FLAGS}" >/proc/sys/fs/binfmt_misc/register
748 + fi
749 +EOF
750 +
751 + echo ":${package}:M::${magic}:${mask}:${interpreter}:OC" >>"${out_systemd}"
752 +
753 + done
754 + cat "${FILESDIR}"/qemu-binfmt.initd.tail >>"${out}" || die
755 +}
756 +
757 +src_install() {
758 + if [[ -n ${user_targets} ]]; then
759 + cd "${S}/user-build"
760 + emake DESTDIR="${ED}" install
761 +
762 + # Install binfmt handler init script for user targets.
763 + generate_initd
764 + doinitd "${T}/qemu-binfmt"
765 +
766 + # Install binfmt/qemu.conf.
767 + insinto "/usr/share/qemu/binfmt.d"
768 + doins "${T}/qemu.conf"
769 + fi
770 +
771 + if [[ -n ${softmmu_targets} ]]; then
772 + cd "${S}/softmmu-build"
773 + emake DESTDIR="${ED}" install
774 +
775 + # This might not exist if the test failed. #512010
776 + [[ -e check-report.html ]] && dohtml check-report.html
777 +
778 + if use kernel_linux; then
779 + udev_newrules "${FILESDIR}"/65-kvm.rules-r1 65-kvm.rules
780 + fi
781 +
782 + if use python; then
783 + python_foreach_impl qemu_python_install
784 + fi
785 + fi
786 +
787 + cd "${S}/tools-build"
788 + emake DESTDIR="${ED}" install
789 +
790 + # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
791 + pushd "${ED}"/usr/bin >/dev/null
792 + pax-mark mr "${softmmu_bins[@]}" "${user_bins[@]}" # bug 575594
793 + popd >/dev/null
794 +
795 + # Install config file example for qemu-bridge-helper
796 + insinto "/etc/qemu"
797 + doins "${FILESDIR}/bridge.conf"
798 +
799 + cd "${S}"
800 + dodoc Changelog MAINTAINERS docs/specs/pci-ids.txt
801 + newdoc pc-bios/README README.pc-bios
802 + dodoc docs/qmp-*.txt
803 +
804 + if [[ -n ${softmmu_targets} ]]; then
805 + # Remove SeaBIOS since we're using the SeaBIOS packaged one
806 + rm "${ED}/usr/share/qemu/bios.bin"
807 + rm "${ED}/usr/share/qemu/bios-256k.bin"
808 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
809 + dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
810 + dosym ../seabios/bios-256k.bin /usr/share/qemu/bios-256k.bin
811 + fi
812 +
813 + # Remove vgabios since we're using the seavgabios packaged one
814 + rm "${ED}/usr/share/qemu/vgabios.bin"
815 + rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
816 + rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
817 + rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
818 + rm "${ED}/usr/share/qemu/vgabios-virtio.bin"
819 + rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
820 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
821 + dosym ../seavgabios/vgabios-isavga.bin /usr/share/qemu/vgabios.bin
822 + dosym ../seavgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
823 + dosym ../seavgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
824 + dosym ../seavgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
825 + dosym ../seavgabios/vgabios-virtio.bin /usr/share/qemu/vgabios-virtio.bin
826 + dosym ../seavgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
827 + fi
828 +
829 + # Remove sgabios since we're using the sgabios packaged one
830 + rm "${ED}/usr/share/qemu/sgabios.bin"
831 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
832 + dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
833 + fi
834 +
835 + # Remove iPXE since we're using the iPXE packaged one
836 + rm "${ED}"/usr/share/qemu/pxe-*.rom
837 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
838 + dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
839 + dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
840 + dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
841 + dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
842 + dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
843 + dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
844 + fi
845 + fi
846 +
847 + DISABLE_AUTOFORMATTING=true
848 + readme.gentoo_create_doc
849 +}
850 +
851 +firmware_abi_change() {
852 + local pv
853 + for pv in ${REPLACING_VERSIONS}; do
854 + if ! version_is_at_least ${FIRMWARE_ABI_VERSION} ${pv}; then
855 + return 0
856 + fi
857 + done
858 + return 1
859 +}
860 +
861 +pkg_postinst() {
862 + if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
863 + udev_reload
864 + fi
865 +
866 + fcaps cap_net_admin /usr/libexec/qemu-bridge-helper
867 +
868 + DISABLE_AUTOFORMATTING=true
869 + readme.gentoo_print_elog
870 +
871 + if use pin-upstream-blobs && firmware_abi_change; then
872 + ewarn "This version of qemu pins new versions of firmware blobs:"
873 + ewarn " $(best_version sys-firmware/edk2-ovmf)"
874 + ewarn " $(best_version sys-firmware/ipxe)"
875 + ewarn " $(best_version sys-firmware/seabios)"
876 + ewarn " $(best_version sys-firmware/sgabios)"
877 + ewarn "This might break resume of hibernated guests (started with a different"
878 + ewarn "firmware version) and live migration to/from qemu versions with different"
879 + ewarn "firmware. Please (cold) restart all running guests. For functional"
880 + ewarn "guest migration ensure that all"
881 + ewarn "hosts run at least"
882 + ewarn " app-emulation/qemu-${FIRMWARE_ABI_VERSION}."
883 + fi
884 +}
885 +
886 +pkg_info() {
887 + echo "Using:"
888 + echo " $(best_version app-emulation/spice-protocol)"
889 + echo " $(best_version sys-firmware/edk2-ovmf)"
890 + if has_version 'sys-firmware/edk2-ovmf[binary]'; then
891 + echo " USE=binary"
892 + else
893 + echo " USE=''"
894 + fi
895 + echo " $(best_version sys-firmware/ipxe)"
896 + echo " $(best_version sys-firmware/seabios)"
897 + if has_version 'sys-firmware/seabios[binary]'; then
898 + echo " USE=binary"
899 + else
900 + echo " USE=''"
901 + fi
902 + echo " $(best_version sys-firmware/sgabios)"
903 +}