From nobody Tue Feb 10 09:43:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1690966270; cv=none; d=zohomail.com; s=zohoarc; b=P+ICI16qU8AE52JfiTm4tfoaSKoria00iDziz56yA7wgo5f4bb76DZ7dfh8h/wYmSgDy9l00e0KOgSQSQhHqU1uv+gSlSozQuFVGQio9QXIpGGhZii2q6NCw3N/DPxrCMu2m21Zm44aH5Y6mWp/pqe/IPlBWxqBoZvqhWlIQHpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690966270; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=kNR+2DDMQySc8psqEDhnZbBav2KTV36MZCBGyLQQO2o=; b=R1amL2BwnnQjrSKryjRBBuqRBy2zIiaeipvS9AWOLZMb15yL8VfBtabVf3kT3NVzgbGlkSreNyI8qzpoIfMdRMWlfaFiHTd+8CFXb8NvfQhUbggfOQTQ8Ws3TAp0x17axZcbp+qdFmFO+Nl23s9tFdzINM466xxAtpTieAQv+lc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690966270185586.3059446308699; Wed, 2 Aug 2023 01:51:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qR7Yx-0005EQ-0Q; Wed, 02 Aug 2023 04:50: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 1qR7Yu-00057E-JP for qemu-devel@nongnu.org; Wed, 02 Aug 2023 04:50:32 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qR7Yq-0000jS-17 for qemu-devel@nongnu.org; Wed, 02 Aug 2023 04:50:31 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-686b9964ae2so4595411b3a.3 for ; Wed, 02 Aug 2023 01:50:27 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id j22-20020aa79296000000b00659b8313d08sm10592860pfa.78.2023.08.02.01.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 01:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1690966227; x=1691571027; 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=K3R00I0tgQEZb0otU0GHIAVYlvmecLUiB5W39EKRq4ECqfoqWkNTjCmG4zKtIpZoZh VfsG4KPhxENtsIe86jub6NeeRolk5LB9TLjyihIYhW2P65+56Ba8/TwltgAnhLzyA9P9 xGPX7FvX9WUGwemYyrLWJhYPYDCKVkw0qSWaTesj1zHl1Pj4HFb3cgPWnF7Pgwpl5s8K NpyqMiYzhBMrobxSmC6uVYD4aF/1h/joNnykcji0hmsweV4k7Fz+ZeyYelN6HWkAxkC+ 9ZegLOJACRjnrPK/TVG0NmwyITi3ttLvQ3relVP1Erynux1YurQ01HCinx6WEZzUfsF5 +MtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690966227; x=1691571027; 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=YKiUE+RgZYYBTbsH6ANAUgGYiOZkYkeLkPlKBY9JIW9uHxg2e3W6gCSSwoLq4PaEER Im5uLorHEavLrrieRSHFxJW4y/eE3CJ4WUHGer0ued+wfA+aitXZYYkFLmN9/0ekR0K5 E29SRHseJQzVJzdnyM+TBkuv+z3E0QmMwG0EwgwEyF1WRfHtdvqijsEAR2Ddu384129H JX8PfF43C07elOxf1J3BJovyvnKBZAvKAiupkPUWf5CbvqWiGMw91GHUp+AfhvIkUf0o DV9E8RzHwbTrvfuFA6X1HBL76FCMyPAX1A6KwJViWax4/EFgDv+ybvZlMtX00GVDR9zv Ed/w== X-Gm-Message-State: ABy/qLbVwl6Cyxl5w6wgc8pI/HcJk0uZQs+Bl1L1OpQ1tmPUZ4jC7zSm mH0sjMZba69zMI9LhnMJYiq3Rg== X-Google-Smtp-Source: APBJJlFGHdzb68i9hkzSc4thw9evgdTiFF4LBhOLeZ9K59RBAH4Gv68G5UXefQweRnrCHWCvkNy+Sw== X-Received: by 2002:a05:6a20:840b:b0:137:514a:9835 with SMTP id c11-20020a056a20840b00b00137514a9835mr18011045pzd.9.1690966226760; Wed, 02 Aug 2023 01:50:26 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=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=20Le=20Goater?= , 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 v2 24/24] contrib/plugins: Add cc plugin Date: Wed, 2 Aug 2023 17:46:12 +0900 Message-ID: <20230802084614.23619-25-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802084614.23619-1-akihiko.odaki@daynix.com> References: <20230802084614.23619-1-akihiko.odaki@daynix.com> 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: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1690966272008100003 Content-Type: text/plain; charset="utf-8" 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=3Don``. (default: N =3D 2097152 (2MB), B =3D 64, A =3D 16) =20 +- 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 --- =20 diff --git a/configure b/configure index 26ec5e4f54..0065b0dfe0 100755 --- a/configure +++ b/configure @@ -293,10 +293,18 @@ else cc=3D"${CC-${cross_prefix}gcc}" fi =20 -if test -z "${CXX}${cross_prefix}"; then - cxx=3D"c++" +if test -n "${CXX+x}"; then + cxx=3D"$CXX" else - cxx=3D"${CXX-${cross_prefix}g++}" + if test -n "${cross_prefix}"; then + cxx=3D"${cross_prefix}g++" + else + cxx=3D"c++" + fi + + if ! has "$cxx"; then + cxx=3D + fi fi =20 # Preferred ObjC compiler: @@ -1702,6 +1710,7 @@ echo "MESON=3D$meson" >> $config_host_mak echo "NINJA=3D$ninja" >> $config_host_mak echo "PKG_CONFIG=3D${pkg_config}" >> $config_host_mak echo "CC=3D$cc" >> $config_host_mak +echo "CXX=3D$cxx" >> $config_host_mak echo "EXESUF=3D$EXESUF" >> $config_host_mak =20 # 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 +=3D lockstep NAMES +=3D hwprofile NAMES +=3D cache NAMES +=3D drcov +ifneq ($(CXX),) +NAMES +=3D cc +endif =20 SONAMES :=3D $(addsuffix .so,$(addprefix lib,$(NAMES))) =20 @@ -31,6 +34,8 @@ CFLAGS +=3D -fPIC -Wall CFLAGS +=3D $(if $(CONFIG_DEBUG_TCG), -ggdb -O0) CFLAGS +=3D -I$(SRC_PATH)/include/qemu =20 +CXXFLAGS :=3D $(CFLAGS) + all: $(SONAMES) =20 %.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 =3D QEMU_PLUGIN_VERSION; + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, int ar= gc, + 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=3D$(SRC_PATH)/tests/plugin PLUGIN_LIB=3D../../plugin VPATH+=3D$(PLUGIN_LIB) PLUGINS=3D$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c))) +ifneq ($(CXX),) +PLUGINS+=3D$(patsubst %.cc, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c= c))) +endif =20 # 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 --=20 2.41.0