From nobody Mon Feb 9 01:30:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601567703; cv=none; d=zohomail.com; s=zohoarc; b=QUOyJCt8tO3Dm0F1LDMiILMApO7gqYY2FRSkeqaVEjgrYo/WOaNgZ2NRcOGf80vmqf4xDHK/kxPT6oNoG0v1CWeJVcM7ZLqkbZ/DXlx9dntIl7t2qru4M9Yyu2axNE9QYb6yGhwOUtYanL8fBxqnKSW1OVjbJzMVRo7MJOIDp30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601567703; h=Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=zSYOXeSlcSA7ke+ZuZ7jMFx/GITH0sskN+zpeSvAgv4=; b=WEPbM8RxfW8xW7YHmIBsqKKAutOGe6NNANtNatdmT8IB6IlxK/RUFmo40wWIduOjMJUKPUnP8njGnxzbv0Q7OliopL9MjQRZ32fq6wAfPXMEH2ERyBHF1BWAUPSztbSBEb1ppXMV1bIONbV2gdd+lPG7BmQRFMAKTXOC0e8xfYE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601567703602672.104722294417; Thu, 1 Oct 2020 08:55:03 -0700 (PDT) Received: from localhost ([::1]:46538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kO0v8-00025I-2J for importer@patchew.org; Thu, 01 Oct 2020 11:55:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kO0tV-0008PT-5B for qemu-devel@nongnu.org; Thu, 01 Oct 2020 11:53:21 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:39701) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kO0tS-0005j3-WA for qemu-devel@nongnu.org; Thu, 01 Oct 2020 11:53:20 -0400 Received: by mail-wm1-x32b.google.com with SMTP id t17so3674761wmi.4 for ; Thu, 01 Oct 2020 08:53:18 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:86de:492a:fae3:16f2]) by smtp.gmail.com with ESMTPSA id g14sm9739399wrv.25.2020.10.01.08.53.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 08:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zSYOXeSlcSA7ke+ZuZ7jMFx/GITH0sskN+zpeSvAgv4=; b=JQD0Af2mLBZHxWB+HG2xSQaY1LnAyaizlfEdNMHCf1DLlEoXvOvga0obIDrkHE1Gak Q+Qx47BitZbEmcbrG7Inu378CNSZWmHW2LL5gfhtcwXXOeQ3BforoygRWbgAQgckWgMv nYmf6rikaEwwN8sK22qEGvZ5ijemtjhNQL+VWYEiXHDGHti6klOQNNtMjqe0bJ3+Pp7j xxxq0gZPthUb2TrU+zJWh0GuK72arloTjrTVtSJTWUF/kvcEnG7f+cMZc9PEkELzurOM V+W0Q/DhBuuS046Ju5s8Z/1ptvZiswIjFeO3pQ1zUTMqUCtB37Id7BbNvdDt5TY7lNrK nT8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=zSYOXeSlcSA7ke+ZuZ7jMFx/GITH0sskN+zpeSvAgv4=; b=QO9SZjfDNnDv/OagE7RgXpX3QVBXuDeZdneILYC8uw+0rxP2u+KpU3AsAguOk0JHhH RtQmqTH+71D0Tf3kalb0HViLxF309CqCGSJR3NVDB4m96mePwgyd7AlTJZu1mpsVk2fr 8XNLjZRkotXkLu70Au9Kkxbm4CAlX0M5sekMqCMzEyGm9yY1+hXvviOWxCVo0oi4888a K+czSiX0n8/jlsMzyWYMDWO1VQe4vossIGzXyTxIyuCH9InfmC4DihyV6AXR1mzD0Rax rzhjhos4vidSaoPhBsqhxLG5ba1t5rCtXb4MWi6J0E26lhVfuGauBxxjQlvAydpGfLL+ 4DAA== X-Gm-Message-State: AOAM530xwRrCO2ZUmAiJAbgYJ9mt0iirvVXeAkqFr7yB/DHvTDiCBUY5 jW4iB5ImnYRma+ujDhvsyESM6p26QdQ= X-Google-Smtp-Source: ABdhPJxk8dxxa4URUpjaaqPsq6or3g/bimJ0dn9RDm4oFoxSWE8mj0RbM+qE+19w2L94zfPfbVPwMg== X-Received: by 2002:a1c:7d55:: with SMTP id y82mr692324wmc.100.1601567597048; Thu, 01 Oct 2020 08:53:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH] meson: move sparse detection to Meson and rewrite check_sparse.py Date: Thu, 1 Oct 2020 17:53:13 +0200 Message-Id: <20201001155313.18364-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Pass the path to the program to scripts/check_sparse.py, which previously was not included in config-host.mak. Change scripts/check_sparse.py to work with cgcc, which seems to work better with sparse 0.6.x. Signed-off-by: Paolo Bonzini --- configure | 24 +++--------------- meson.build | 10 +++++--- meson_options.txt | 2 ++ scripts/check_sparse.py | 56 +++++++++++++++++++++++++++++++++-------- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/configure b/configure index 73e3b14749..02a091dafb 100755 --- a/configure +++ b/configure @@ -303,7 +303,7 @@ sdl_image=3D"auto" virtfs=3D"" mpath=3D"auto" vnc=3D"enabled" -sparse=3D"no" +sparse=3D"auto" vde=3D"" vnc_sasl=3D"auto" vnc_jpeg=3D"auto" @@ -1040,9 +1040,9 @@ for opt do ;; --disable-tsan) tsan=3D"no" ;; - --enable-sparse) sparse=3D"yes" + --enable-sparse) sparse=3D"enabled" ;; - --disable-sparse) sparse=3D"no" + --disable-sparse) sparse=3D"disabled" ;; --disable-strip) strip_opt=3D"no" ;; @@ -2875,19 +2875,6 @@ if test "$gettext" !=3D "false" ; then fi fi =20 -########################################## -# Sparse probe -if test "$sparse" !=3D "no" ; then - if has sparse; then - sparse=3Dyes - else - if test "$sparse" =3D "yes" ; then - feature_not_found "sparse" "Install sparse binary" - fi - sparse=3Dno - fi -fi - ########################################## # X11 probe if $pkg_config --exists "x11"; then @@ -7127,9 +7114,6 @@ echo "QEMU_CXXFLAGS=3D$QEMU_CXXFLAGS" >> $config_host= _mak echo "QEMU_INCLUDES=3D$QEMU_INCLUDES" >> $config_host_mak echo "GLIB_CFLAGS=3D$glib_cflags" >> $config_host_mak echo "GLIB_LIBS=3D$glib_libs" >> $config_host_mak -if test "$sparse" =3D "yes" ; then - echo "SPARSE_CFLAGS =3D -Wbitwise -Wno-transparent-union -Wno-old-initia= lizer -Wno-non-pointer-null" >> $config_host_mak -fi echo "QEMU_LDFLAGS=3D$QEMU_LDFLAGS" >> $config_host_mak echo "LDFLAGS_NOPIE=3D$LDFLAGS_NOPIE" >> $config_host_mak echo "LD_I386_EMULATION=3D$ld_i386_emulation" >> $config_host_mak @@ -7383,7 +7367,7 @@ NINJA=3D${ninja:-$PWD/ninjatool} $meson setup \ -Dstrip=3D$(if test "$strip_opt" =3D yes; then echo true; else ech= o false; fi) \ -Db_pie=3D$(if test "$pie" =3D yes; then echo true; else echo fals= e; fi) \ -Db_coverage=3D$(if test "$gcov" =3D yes; then echo true; else ech= o false; fi) \ - -Dmalloc=3D$malloc -Dmalloc_trim=3D$malloc_trim \ + -Dmalloc=3D$malloc -Dmalloc_trim=3D$malloc_trim -Dsparse=3D$sparse \ -Dkvm=3D$kvm -Dhax=3D$hax -Dwhpx=3D$whpx -Dhvf=3D$hvf \ -Dxen=3D$xen -Dxen_pci_passthrough=3D$xen_pci_passthrough -Dtcg=3D$tcg \ -Dcocoa=3D$cocoa -Dmpath=3D$mpath -Dsdl=3D$sdl -Dsdl_image=3D$sdl_image \ diff --git a/meson.build b/meson.build index baaeab459d..40af93fa53 100644 --- a/meson.build +++ b/meson.build @@ -102,11 +102,13 @@ if host_machine.system() =3D=3D 'darwin' add_languages('objc', required: false, native: false) endif =20 -if 'SPARSE_CFLAGS' in config_host +sparse =3D find_program('cgcc', required: get_option('sparse')) +if sparse.found() run_target('sparse', command: [find_program('scripts/check_sparse.py'), - config_host['SPARSE_CFLAGS'].split(), - 'compile_commands.json']) + 'compile_commands.json', sparse.full_path(), '-Wbit= wise', + '-Wno-transparent-union', '-Wno-old-initializer', + '-Wno-non-pointer-null']) endif =20 ########################################### @@ -1556,7 +1558,7 @@ summary_info +=3D {'host CPU': cpu} summary_info +=3D {'host endianness': build_machine.endian()} summary_info +=3D {'target list': ' '.join(target_dirs)} summary_info +=3D {'gprof enabled': config_host.has_key('CONFIG_GPROF'= )} -summary_info +=3D {'sparse enabled': meson.get_compiler('c').cmd_array(= ).contains('cgcc')} +summary_info +=3D {'sparse enabled': sparse.found()} summary_info +=3D {'strip binaries': get_option('strip')} summary_info +=3D {'profiler': config_host.has_key('CONFIG_PROFIL= ER')} summary_info +=3D {'static build': config_host.has_key('CONFIG_STATIC= ')} diff --git a/meson_options.txt b/meson_options.txt index 05adc7a179..bc5c674642 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -5,6 +5,8 @@ option('docdir', type : 'string', value : 'doc', =20 option('gettext', type : 'boolean', value : true, description: 'Localization of the GTK+ user interface') +option('sparse', type : 'feature', value : 'auto', + description: 'sparse checker') =20 option('malloc_trim', type : 'feature', value : 'auto', description: 'enable libc malloc_trim() for memory optimization') diff --git a/scripts/check_sparse.py b/scripts/check_sparse.py index 0de7aa55d9..2956124442 100644 --- a/scripts/check_sparse.py +++ b/scripts/check_sparse.py @@ -1,25 +1,59 @@ #! /usr/bin/env python3 =20 -# Invoke sparse based on the contents of compile_commands.json +# Invoke sparse based on the contents of compile_commands.json, +# also working around several deficiencies in cgcc's command line +# parsing =20 import json import subprocess +import os import sys import shlex =20 -def extract_cflags(shcmd): - cflags =3D shlex.split(shcmd) - return [x for x in cflags - if x.startswith('-D') or x.startswith('-I') or x.startswith('-= W') - or x.startswith('-std=3D')] +def cmdline_for_sparse(sparse, cmdline): + # Do not include the C compiler executable + skip =3D True + arg =3D False + out =3D sparse + ['-no-compile'] + for x in cmdline: + if arg: + out.append(x) + arg =3D False + continue + if skip: + skip =3D False + continue + # prevent sparse from treating output files as inputs + if x =3D=3D '-MF' or x =3D=3D '-MQ' or x =3D=3D '-o': + skip =3D True + continue + # cgcc ignores -no-compile if it sees -M or -MM? + if x.startswith('-M'): + continue + # sparse does not understand these! + if x =3D=3D '-iquote' or x =3D=3D '-isystem': + x =3D '-I' + if x =3D=3D '-I': + arg =3D True + out.append(x) + return out =20 -cflags =3D sys.argv[1:-1] -with open(sys.argv[-1], 'r') as fd: +root_path =3D os.getenv('MESON_BUILD_ROOT') +def build_path(s): + return s if not root_path else os.path.join(root_path, s) + +ccjson_path =3D build_path(sys.argv[1]) +with open(ccjson_path, 'r') as fd: compile_commands =3D json.load(fd) =20 +sparse =3D sys.argv[2:] +sparse_env =3D os.environ.copy() for cmd in compile_commands: - cmd =3D ['sparse'] + cflags + extract_cflags(cmd['command']) + [cmd['f= ile']] - print(' '.join((shlex.quote(x) for x in cmd))) - r =3D subprocess.run(cmd) + cmdline =3D shlex.split(cmd['command']) + cmd =3D cmdline_for_sparse(sparse, cmdline) + print('REAL_CC=3D%s' % shlex.quote(cmdline[0]), + ' '.join((shlex.quote(x) for x in cmd))) + sparse_env['REAL_CC'] =3D cmdline[0] + r =3D subprocess.run(cmd, env=3Dsparse_env, cwd=3Droot_path) if r.returncode !=3D 0: sys.exit(r.returncode) --=20 2.26.2