From nobody Fri Dec 19 19:18:38 2025 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=1693717594; cv=none; d=zohomail.com; s=zohoarc; b=QXNkgv9AhltQqIhlQ2Vn7I16/6j580ihAFQy7MAuWa2SFbP19zmB4d7MKephQ7rhsm03+uisllXfobA0SJFudg7pM0Mn3YfYJqGcpQJYhP8SUjxLJhHiU2ClNU0jQ9KA4XRqndyv/dnqgQhHF9zZ/W9UNpxChTxeVj+pW8N4K3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693717594; 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=c2bscsJzpeRHxPoEuFVzdoUPIwbXoKcsg2VXxI81RBc=; b=EgPgyRTeqrdNOpxwWMS2DQJyEvswpz0Yvib0ZVmjceycio7huxk2UR51HtZJEu5j9TCIY6r0ghTv9cS1isntOcC87QepRb7R+GNRnmhNLOuHDrrJZKVf1kelhYWDq2knOpeXNSLQV30bMqhvASEZxdBm/FBlN2drbHOYg+icOO0= 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 16937175942861014.3755734606286; Sat, 2 Sep 2023 22:06:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qcfHx-00033u-JF; Sun, 03 Sep 2023 01:04:46 -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 1qcfHu-00033O-Ks for qemu-devel@nongnu.org; Sun, 03 Sep 2023 01:04:42 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcfHp-0001pc-S2 for qemu-devel@nongnu.org; Sun, 03 Sep 2023 01:04:42 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bf1935f6c2so2105335ad.1 for ; Sat, 02 Sep 2023 22:04:37 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id l11-20020a170902f68b00b001b8af7f632asm5324835plg.176.2023.09.02.22.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Sep 2023 22:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1693717476; x=1694322276; darn=nongnu.org; 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=c2bscsJzpeRHxPoEuFVzdoUPIwbXoKcsg2VXxI81RBc=; b=O8rvQtANgoGnHsBmTGlXFVbsSHfnqHlrzOnFzz+GxvaFnRSqkbbu3xSyZgdVAJamQR U54uc/4eYoBlxeF4ITYQ3WlI1zszYUHcyaGwgiZqy+fhEzDznYVJenJwl2Rrq7Velg5k RQDOO3uDFiJOiPH5656nrKca5ekkozz+cP6Bh3obkEb3azrl0jx380aY0NY4ZT0wTSSe MSu+giIu8fM6cXaevuCzztg2oMpk9glqCKh4uenpPzI1aAEbV13h4ohMuaoij1fdAvg0 NPfw7mvDpfEAm7WRIqB0QxkwKkzG2FiiQV2LTDOhnfGAj3PRAdodReHSonwpUNbYQ+OK p2nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693717476; x=1694322276; 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=c2bscsJzpeRHxPoEuFVzdoUPIwbXoKcsg2VXxI81RBc=; b=RcUmd/elL/O3ogB41oNiftv/1fkMIj9n9sXcge3KffFFys973/c1uhPCGHoajqlV+s Dc0YgJdvhDt96j8vVzWRNnQx06Nnbz3fuBHdLvDN9a0FG+PaylLe/d5UsxeYVLFibRYO bjJ+6zvVDRV2tYhrXzWc6keBIg2OWTZKg2N9AyA2UCf3TG6Iv1/ZGwVyTq08C3Fyk2ZZ 8NtP4P8/XBjVC6SS1+DcU4vi/Ktu5go0Hv4RdoJRqukvCyecaJwZ3DVNYNJlUrIsPN9H HpiQUfFztGEqnhoUAEUUFNDHbrfhBrHy+daBFpH9JPmdV2acQ3u5r3xttUoWUEC7wsTQ c38Q== X-Gm-Message-State: AOJu0YzrrT+xgXP95Fho969kGNEuT8k5GH7rNVscCHD53AWYjc7+nXby 9Bdo8+XQ/5cUgsCzA1IUps1ObA== X-Google-Smtp-Source: AGHT+IEq6C8xetVFp+xRYS7OhzV5NnK2LFZc+OVbt5e8hLUmj2ZUMJnos1EO+ZgY1nqFzsFtHhi/RA== X-Received: by 2002:a17:902:a386:b0:1bd:9498:f15d with SMTP id x6-20020a170902a38600b001bd9498f15dmr8150261pla.24.1693717476610; Sat, 02 Sep 2023 22:04:36 -0700 (PDT) From: Akihiko Odaki To: Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, Akihiko Odaki , Paolo Bonzini , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 18/18] contrib/plugins: Add cc plugin Date: Sun, 3 Sep 2023 14:03:26 +0900 Message-ID: <20230903050338.35256-19-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230903050338.35256-1-akihiko.odaki@daynix.com> References: <20230903050338.35256-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::62c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62c.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=ham 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1693717594774100001 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.42.0