From patchwork Wed Aug 16 13:39:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1821845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20221208.gappssmtp.com header.i=@daynix-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=apjasUEC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RQqFz6mlxz1yNm for ; Wed, 16 Aug 2023 23:47:51 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWGp9-0005CP-Qe; Wed, 16 Aug 2023 09:44:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWGom-0004Yk-FC for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:44:13 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWGoj-0002Oa-0f for qemu-devel@nongnu.org; Wed, 16 Aug 2023 09:44:12 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68706b39c4cso4750809b3a.2 for ; Wed, 16 Aug 2023 06:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692193443; x=1692798243; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kNR+2DDMQySc8psqEDhnZbBav2KTV36MZCBGyLQQO2o=; b=apjasUECty4E3j3H1yWaQ2ypXdq1EM5noHQtAyFyRpHIcMP4TRKtUC/1XY60F4FFa7 /o/R6gD8qU7/9t9bsvMOchXDJ+zatKQFeUkQ2JrbEtYZ8EnRuByS4QhQGc+MhgCAbvbW 2aupMn0dvFec+wHuaetOnIrdn2MNs1wS95We/4KDB0fd/agMWEv2ycQezGVEsU5jHJqs Iq11kjqZdGQIJ2o+eF20sztGK+sGIKMuRI44JTpYajjibD2B8MrU75pdizStXG9Gw39g 8T+pAtqe+RFyGH9CwpPBTNRF7YzL8HM58tluFUbxEWhRnQFIlcoa4S7xrYd6tdKhhpQc 0XFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692193443; x=1692798243; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kNR+2DDMQySc8psqEDhnZbBav2KTV36MZCBGyLQQO2o=; b=EbUXaP8At9GpPXE/M6sRyOCAl0kqKc3AnZKvwDG6jyX9rpOvYthyjKMeaxaqr4PJ7s v5Fsnfq2lap14BiO1OrPD/zTVm1S3zfG2OEo0eO2+mq1qjIEoIu4ddMhMF8w2JfMBoW2 rrEehD9yHCj9rPOwcy+yM2xLrGmXWYuEe7DTUa9obUlFyqg0dS3Ppa5zR08YCjZn5OMg fKC2FVvNi9dK34ZhoP6ImJ8+/En+g2BgY5iAJlikMJTa0Td81f5KIz9x5e0uuqs7cNQn imZRDRVezrUoX56FyMEJlbipNqP11ssR1OGbuCyD3KCV6fT0YC11rSagbkLz06qkbOtc VK5A== X-Gm-Message-State: AOJu0YxKC6EVo9A5zQb9aEXURBI/raQ1N0hTh+jQmVqmf9YjW0j7GDo2 S9f2rBI3JmXPrPp242YWxIiydA== X-Google-Smtp-Source: AGHT+IHrpTXk7bmJEfe0yYLFA3VDDTCbJD8Nw5TkYQRy67Dy8S3RZxehlcveaw6g63mji3enpJP6Cg== X-Received: by 2002:a05:6a00:8d1:b0:67a:8f2a:2cb2 with SMTP id s17-20020a056a0008d100b0067a8f2a2cb2mr1985856pfu.20.1692193443324; Wed, 16 Aug 2023 06:44:03 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id k3-20020a637b43000000b0056601f864aesm928355pgn.2.2023.08.16.06.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 06:44:03 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang , Richard Henderson , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v3 25/25] contrib/plugins: Add cc plugin Date: Wed, 16 Aug 2023 22:39:35 +0900 Message-ID: <20230816133938.18310-26-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816133938.18310-1-akihiko.odaki@daynix.com> References: <20230816133938.18310-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::434; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This demonstrates how to write a plugin in C++. Signed-off-by: Akihiko Odaki --- docs/devel/tcg-plugins.rst | 8 ++++++++ configure | 15 ++++++++++++--- contrib/plugins/Makefile | 5 +++++ contrib/plugins/cc.cc | 17 +++++++++++++++++ tests/tcg/Makefile.target | 3 +++ 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 contrib/plugins/cc.cc diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index c9f8b27590..0a11f8036c 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -584,6 +584,14 @@ The plugin has a number of arguments, all of them are optional: configuration arguments implies ``l2=on``. (default: N = 2097152 (2MB), B = 64, A = 16) +- contrib/plugins/cc.cc + +cc plugin demonstrates how to write a plugin in C++. It simply outputs +"hello, world" to the plugin log:: + + $ qemu-system-arm $(QEMU_ARGS) \ + -plugin ./contrib/plugins/libcc.so -d plugin + API --- diff --git a/configure b/configure index 26ec5e4f54..0065b0dfe0 100755 --- a/configure +++ b/configure @@ -293,10 +293,18 @@ else cc="${CC-${cross_prefix}gcc}" fi -if test -z "${CXX}${cross_prefix}"; then - cxx="c++" +if test -n "${CXX+x}"; then + cxx="$CXX" else - cxx="${CXX-${cross_prefix}g++}" + if test -n "${cross_prefix}"; then + cxx="${cross_prefix}g++" + else + cxx="c++" + fi + + if ! has "$cxx"; then + cxx= + fi fi # Preferred ObjC compiler: @@ -1702,6 +1710,7 @@ echo "MESON=$meson" >> $config_host_mak echo "NINJA=$ninja" >> $config_host_mak echo "PKG_CONFIG=${pkg_config}" >> $config_host_mak echo "CC=$cc" >> $config_host_mak +echo "CXX=$cxx" >> $config_host_mak echo "EXESUF=$EXESUF" >> $config_host_mak # use included Linux headers diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index b2b9db9f51..93d86b3d07 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -21,6 +21,9 @@ NAMES += lockstep NAMES += hwprofile NAMES += cache NAMES += drcov +ifneq ($(CXX),) +NAMES += cc +endif SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) @@ -31,6 +34,8 @@ CFLAGS += -fPIC -Wall CFLAGS += $(if $(CONFIG_DEBUG_TCG), -ggdb -O0) CFLAGS += -I$(SRC_PATH)/include/qemu +CXXFLAGS := $(CFLAGS) + all: $(SONAMES) %.o: %.c diff --git a/contrib/plugins/cc.cc b/contrib/plugins/cc.cc new file mode 100644 index 0000000000..83a5528db0 --- /dev/null +++ b/contrib/plugins/cc.cc @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include + +extern "C" { + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, int argc, + char **argv) +{ + qemu_plugin_outs("hello, world\n"); + return 0; +} + +}; diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 462289f47c..3d7837d3b8 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -149,6 +149,9 @@ PLUGIN_SRC=$(SRC_PATH)/tests/plugin PLUGIN_LIB=../../plugin VPATH+=$(PLUGIN_LIB) PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c))) +ifneq ($(CXX),) +PLUGINS+=$(patsubst %.cc, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.cc))) +endif # We need to ensure expand the run-plugin-TEST-with-PLUGIN # pre-requistes manually here as we can't use stems to handle it. We