From patchwork Mon Sep 14 00:01:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249747 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1199935ilg; Sun, 13 Sep 2020 17:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztp4fXz2xeVdN02Ig/I3RYeqM3sBE4op0+IIn7m0xoLHYTjDrtSFHQ7a5gl9Lk9l4rUFXb X-Received: by 2002:ad4:4c0a:: with SMTP id bz10mr11083580qvb.14.1600041804079; Sun, 13 Sep 2020 17:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041804; cv=none; d=google.com; s=arc-20160816; b=fFrT8XHK+csQy5lQ77Rqj23eJnbh8nfkXEo0e7iKWBAMrmi9NIvEqFjwdblc2r+en1 GFQUrJkXdA2PviqUISKZGxvVgk7pEIk8U6erYTzp96EMK6GRx2qYVXi81jZObq9uPFwd 1/itKe7YP2J2TR04v6NNEQorhAchTOsl/knHT6JTXZBSXdKajv2ZyFGZRU2ChgH/knCX UIohJI/FH5nypPij7HRjr6wgujAtXtHEQ9Wn5HA3u659srCwFBjox/8msgQ+VJqV6Dv5 3jL+3GWS//oAsGudVuQ9X5q9Xz/Z7JpBBC0z4l1IoFDrc9rmmI7mUNgpj9VmTu5+pXC7 0WKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=1udUAr8a7IXOV2H9rA8omIwMHcyQUC+GvcI+H0onXWA=; b=hIBZZ6FE/4Og864lcegjglXY2c+frioXU5LqFGTT7q6OyRFKe9qQ+Q4HQRZ0/6PU0W oGWJZPGqr5LoMkEXa2wm3Ru/JtHf6YhLQbD45IUSZa0+NAOay2bp/wN+tCzSm27dfooW M4CMCUx4jPUQlJ0wPtkNohz2siFrDbHDyZaGsAJ4a/SxyGjn5C1aJS2EHP5fHJsU+nYn x104qz1rHKM6u0PSZPgeDFY/vITmQYFpjVgqqqv209W5iP9O8Avwv2qaBwQy0oDxhzgu 2M7KJGFT+SDNwcVqwAJf40SNfRbnpcExjiPK5YBvRMdtFsZK5DNgCrZJsa7piLkoQ3P+ cRPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tH9ekyKb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w54si5728832qtk.197.2020.09.13.17.03.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:03:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tH9ekyKb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbxr-0005CZ-HL for patch@linaro.org; Sun, 13 Sep 2020 20:03:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwW-0002Ua-8i for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:00 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:42415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwU-0004BW-14 for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:01:59 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d6so11043556pfn.9 for ; Sun, 13 Sep 2020 17:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1udUAr8a7IXOV2H9rA8omIwMHcyQUC+GvcI+H0onXWA=; b=tH9ekyKbKNqBu7NOdNeDYHc1kHfGZjX9Q4P+BttxtUy7ZI073n3WDF+AnHW3gpSyiI T0KTeU697vw0Ig5J+9TDKOSUhVOiEw8xICE2gHJ4vHCmC+gbL5w1k3zkB1mA8FFh12sJ KCuvbrffdclxn8MPs1fe3eCwR1ft80V+UOh1+UlTqMm/6E1FcedtMNAFUeGquFPnHyHs zVjZhYgC8XjtWRAon7HCfgimsXiG2OHCCJpgspXYj3IZE4/wOUtiiyjNaqc99j9AOJk4 F52ZQ3iWMyAvKnKBQxhmsKGUzgr1VUZqosyl711uZfsHVUkygGW+0o9l4FEpSiAfn7Hb 8LCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1udUAr8a7IXOV2H9rA8omIwMHcyQUC+GvcI+H0onXWA=; b=WUn9Z6HYxB9t44+QAZqxn79xy0bMlhySegYV0+IxsQnhgcxN4PgRsq4MZ0o4EgJOiM sYEfYznhzeKnmtqsRGxTCs/qF3cxCdntHdzXBvjmRys4qjwaMkWa52U+jwwB8f4kdf6j 4ogJ8HYDosi+EMMf/1cUyGqPBl83HJS2QC5xf++pBnFT9PoWjm1yP+pz/yZT1ysgXX0c uaqgvD9l90a+L8AToD814I12sNUu7N9kcXlidT6YDUwvBKhKu1Ki3blMCbnS/7QDj4fL mEfEVPvDarwPV3Ayc/dDrZJWfuuTeSda6htto56qLwZfG/agG0pybenWjBCDSt5SoncJ bH7g== X-Gm-Message-State: AOAM530OHNcc8tdXrmh+wb+QWsTyiEsh1clOoCaYl4syU7yTk2xiaY+o VmOktKNI/tEb5HzyMwF3O8v90O5gFbFe4Q== X-Received: by 2002:a17:902:eb05:b029:d1:8c50:b1bc with SMTP id l5-20020a170902eb05b02900d18c50b1bcmr11606416plb.35.1600041716306; Sun, 13 Sep 2020 17:01:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.01.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:01:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 01/11] capstone: Convert Makefile bits to meson bits Date: Sun, 13 Sep 2020 17:01:43 -0700 Message-Id: <20200914000153.1725632-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Cc: Paolo Bonzini , luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There are better ways to do this, e.g. meson cmake subproject, but that requires cmake 3.7 and some of our CI environments only provide cmake 3.5. Nor can we add a meson.build file to capstone/, because the git submodule would then always report "untracked files". Fixing that would require creating our own branch on the qemu git mirror, at which point we could just as easily create a native meson subproject. In leiu, build the library via the main meson.build. This improves the current state of affairs in that we will re-link the qemu executables against a changed libcapstone.a, which we wouldn't do before-hand. In addition, the use of the confuration header file instead of command-line -DEFINES means that we will rebuild the capstone objects with changes to meson.build. Cc: Paolo Bonzini Signed-off-by: Richard Henderson --- configure | 24 +++---------- Makefile | 16 --------- meson.build | 89 ++++++++++++++++++++++++++++++++++++++++++++--- meson_options.txt | 3 ++ 4 files changed, 91 insertions(+), 41 deletions(-) -- 2.25.1 diff --git a/configure b/configure index 2b6a1196da..4fc5c15283 100755 --- a/configure +++ b/configure @@ -5146,27 +5146,15 @@ case "$capstone" in esac case "$capstone" in - git | internal) + git) if test "$capstone" = git; then git_submodules="${git_submodules} capstone" fi - mkdir -p capstone - if test "$mingw32" = "yes"; then - LIBCAPSTONE=capstone.lib - else - LIBCAPSTONE=libcapstone.a - fi - capstone_libs="-Lcapstone -lcapstone" - capstone_cflags="-I${source_path}/capstone/include" ;; - system) - capstone_libs="$($pkg_config --libs capstone)" - capstone_cflags="$($pkg_config --cflags capstone)" + internal | system | no) ;; - no) - ;; *) error_exit "Unknown state for capstone: $capstone" ;; @@ -7290,8 +7278,6 @@ if test "$ivshmem" = "yes" ; then fi if test "$capstone" != "no" ; then echo "CONFIG_CAPSTONE=y" >> $config_host_mak - echo "CAPSTONE_CFLAGS=$capstone_cflags" >> $config_host_mak - echo "CAPSTONE_LIBS=$capstone_libs" >> $config_host_mak fi if test "$debug_mutex" = "yes" ; then echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak @@ -7816,9 +7802,6 @@ done # for target in $targets if [ "$fdt" = "git" ]; then subdirs="$subdirs dtc" fi -if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then - subdirs="$subdirs capstone" -fi echo "SUBDIRS=$subdirs" >> $config_host_mak if test -n "$LIBCAPSTONE"; then echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak @@ -8005,7 +7988,8 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \ -Db_coverage=$(if test "$gcov" = yes; then echo true; else echo false; fi) \ -Dsdl=$sdl -Dsdl_image=$sdl_image \ -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \ - -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\ + -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \ + -Dcapstone=$capstone \ $cross_arg \ "$PWD" "$source_path" diff --git a/Makefile b/Makefile index 57f72f56c6..0746aa83e3 100644 --- a/Makefile +++ b/Makefile @@ -156,22 +156,6 @@ dtc/all: .git-submodule-status dtc/libfdt dtc/%: .git-submodule-status @mkdir -p $@ -# Overriding CFLAGS causes us to lose defines added in the sub-makefile. -# Not overriding CFLAGS leads to mis-matches between compilation modes. -# Therefore we replicate some of the logic in the sub-makefile. -# Remove all the extra -Warning flags that QEMU uses that Capstone doesn't; -# no need to annoy QEMU developers with such things. -CAP_CFLAGS = $(patsubst -W%,,$(CFLAGS) $(QEMU_CFLAGS)) $(CAPSTONE_CFLAGS) -CAP_CFLAGS += -DCAPSTONE_USE_SYS_DYN_MEM -CAP_CFLAGS += -DCAPSTONE_HAS_ARM -CAP_CFLAGS += -DCAPSTONE_HAS_ARM64 -CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC -CAP_CFLAGS += -DCAPSTONE_HAS_X86 - -.PHONY: capstone/all -capstone/all: .git-submodule-status - $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE)) - .PHONY: slirp/all slirp/all: .git-submodule-status $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp \ diff --git a/meson.build b/meson.build index 690723b470..4417de1e14 100644 --- a/meson.build +++ b/meson.build @@ -415,11 +415,6 @@ if 'CONFIG_USB_LIBUSB' in config_host libusb = declare_dependency(compile_args: config_host['LIBUSB_CFLAGS'].split(), link_args: config_host['LIBUSB_LIBS'].split()) endif -capstone = not_found -if 'CONFIG_CAPSTONE' in config_host - capstone = declare_dependency(compile_args: config_host['CAPSTONE_CFLAGS'].split(), - link_args: config_host['CAPSTONE_LIBS'].split()) -endif libpmem = not_found if 'CONFIG_LIBPMEM' in config_host libpmem = declare_dependency(compile_args: config_host['LIBPMEM_CFLAGS'].split(), @@ -616,6 +611,90 @@ config_all += { 'CONFIG_ALL': true, } +if get_option('capstone') == 'no' + capstone = not_found +elif get_option('capstone') == 'system' + capstone = dependency('capstone', static: enable_static, required: true) +else + capstone_data = configuration_data() + capstone_data.set('CAPSTONE_USE_SYS_DYN_MEM', '1') + + capstone_files = files( + 'capstone/cs.c', + 'capstone/MCInst.c', + 'capstone/MCInstrDesc.c', + 'capstone/MCRegisterInfo.c', + 'capstone/SStream.c', + 'capstone/utils.c' + ) + + if 'CONFIG_ARM_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_ARM', '1') + capstone_files += files( + 'capstone/arch/ARM/ARMDisassembler.c', + 'capstone/arch/ARM/ARMInstPrinter.c', + 'capstone/arch/ARM/ARMMapping.c', + 'capstone/arch/ARM/ARMModule.c' + ) + endif + + # FIXME: This config entry currently depends on a c++ compiler. + # Which is needed for building libvixl, but not for capstone. + if 'CONFIG_ARM_A64_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_ARM64', '1') + capstone_files += files( + 'capstone/arch/AArch64/AArch64BaseInfo.c', + 'capstone/arch/AArch64/AArch64Disassembler.c', + 'capstone/arch/AArch64/AArch64InstPrinter.c', + 'capstone/arch/AArch64/AArch64Mapping.c', + 'capstone/arch/AArch64/AArch64Module.c' + ) + endif + + if 'CONFIG_PPC_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_POWERPC', '1') + capstone_files += files( + 'capstone/arch/PowerPC/PPCDisassembler.c', + 'capstone/arch/PowerPC/PPCInstPrinter.c', + 'capstone/arch/PowerPC/PPCMapping.c', + 'capstone/arch/PowerPC/PPCModule.c' + ) + endif + + if 'CONFIG_I386_DIS' in config_all_disas + capstone_data.set('CAPSTONE_HAS_X86', 1) + capstone_files += files( + 'capstone/arch/X86/X86Disassembler.c', + 'capstone/arch/X86/X86DisassemblerDecoder.c', + 'capstone/arch/X86/X86ATTInstPrinter.c', + 'capstone/arch/X86/X86IntelInstPrinter.c', + 'capstone/arch/X86/X86Mapping.c', + 'capstone/arch/X86/X86Module.c' + ) + endif + + configure_file(output: 'capstone-defs.h', + configuration: capstone_data) + + capstone_cargs = [ + # FIXME: There does not seem to be a way to completely replace the c_args + # that come from add_project_arguments() -- we can only add to them. + # So: disable all warnings with a big hammer. + '-Wno-error', '-w', + # Include all configuration defines via a header file, which will wind up + # as a dependency on the object file, and thus changes here will result + # in a rebuild. + '-include', 'capstone-defs.h' + ] + + libcapstone = static_library('capstone', + sources: capstone_files, + c_args: capstone_cargs, + include_directories: 'capstone/include') + capstone = declare_dependency(link_with: libcapstone, + include_directories: 'capstone/include') +endif + # Generators hxtool = find_program('scripts/hxtool') diff --git a/meson_options.txt b/meson_options.txt index 543cf70043..99ecd44aca 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -22,3 +22,6 @@ option('vnc_sasl', type : 'feature', value : 'auto', description: 'SASL authentication for VNC server') option('xkbcommon', type : 'feature', value : 'auto', description: 'xkbcommon support') + +option('capstone', type: 'string', value: 'no', + description: 'capstone support')