qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Cleber Rosa" <crosa@redhat.com>, "John Snow" <jsnow@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Konstantin Kostiuk" <kkostiuk@redhat.com>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>
Subject: [PATCH 10/12] plugins: detect qemu plugin API symbols from header
Date: Wed, 30 Oct 2024 21:04:24 -0700	[thread overview]
Message-ID: <20241031040426.772604-11-pierrick.bouvier@linaro.org> (raw)
In-Reply-To: <20241031040426.772604-1-pierrick.bouvier@linaro.org>

Instead of using a static file (error prone and hard to keep in sync),
we generate it using a script.

Note: if a symbol is not exported, we'll now notice it when linking for
Windows/MacOS platforms.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 MAINTAINERS                    |  1 +
 plugins/meson.build            | 12 ++++++---
 scripts/qemu-plugin-symbols.py | 45 ++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100755 scripts/qemu-plugin-symbols.py

diff --git a/MAINTAINERS b/MAINTAINERS
index f48d9142b8a..d34b6606e95 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3719,6 +3719,7 @@ F: plugins/
 F: tests/tcg/plugins/
 F: tests/avocado/tcg_plugins.py
 F: contrib/plugins/
+F: scripts/qemu-plugin-symbols.py
 
 AArch64 TCG target
 M: Richard Henderson <richard.henderson@linaro.org>
diff --git a/plugins/meson.build b/plugins/meson.build
index 51297582f93..d60be2a4d6d 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -2,11 +2,17 @@ if not get_option('plugins')
   subdir_done()
 endif
 
+qemu_plugin_symbols = configure_file(
+  input: files('../include/qemu/qemu-plugin.h'),
+  output: 'qemu-plugin.symbols',
+  capture: true,
+  command: [files('../scripts/qemu-plugin-symbols.py'), '@INPUT@'])
+
 # Modules need more symbols than just those in plugins/qemu-plugins.symbols
 if not enable_modules
   if host_os == 'darwin'
     configure_file(
-      input: files('qemu-plugins.symbols'),
+      input: qemu_plugin_symbols,
       output: 'qemu-plugins-ld64.symbols',
       capture: true,
       command: ['sed', '-ne', 's/^[[:space:]]*\\(qemu_.*\\);/_\\1/p', '@INPUT@'])
@@ -15,7 +21,7 @@ if not enable_modules
     # LLVM/lld does not support exporting specific symbols. However, it works
     # out of the box with dllexport/dllimport attribute we set in the code.
   else
-    emulator_link_args += ['-Xlinker', '--dynamic-list=' + (meson.project_source_root() / 'plugins/qemu-plugins.symbols')]
+    emulator_link_args += ['-Xlinker', '--dynamic-list=' + qemu_plugin_symbols.full_path()]
   endif
 endif
 
@@ -24,7 +30,7 @@ if host_os == 'windows'
   # First, create a .def file listing all the symbols a plugin should expect to have
   # available in qemu
   win32_plugin_def = configure_file(
-    input: files('qemu-plugins.symbols'),
+    input: qemu_plugin_symbols,
     output: 'qemu_plugin_api.def',
     capture: true,
     command: ['sed', '-e', '0,/^/s//EXPORTS/; s/[{};]//g', '@INPUT@'])
diff --git a/scripts/qemu-plugin-symbols.py b/scripts/qemu-plugin-symbols.py
new file mode 100755
index 00000000000..e285ebb8f9e
--- /dev/null
+++ b/scripts/qemu-plugin-symbols.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Extract QEMU Plugin API symbols from a header file
+#
+# Copyright 2024 Linaro Ltd
+#
+# Author: Pierrick Bouvier <pierrick.bouvier@linaro.org>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import argparse
+import re
+
+def extract_symbols(plugin_header):
+    with open(plugin_header) as file:
+        content = file.read()
+    # Remove QEMU_PLUGIN_API macro definition.
+    content = content.replace('#define QEMU_PLUGIN_API', '')
+    expected = content.count('QEMU_PLUGIN_API')
+    # Find last word between QEMU_PLUGIN_API and (, matching on several lines.
+    # We use *? non-greedy quantifier.
+    syms = re.findall(r'QEMU_PLUGIN_API.*?(\w+)\s*\(', content, re.DOTALL)
+    syms.sort()
+    # Ensure we found as many symbols as API markers.
+    assert len(syms) == expected
+    return syms
+
+def main() -> None:
+    parser = argparse.ArgumentParser(description='Extract QEMU plugin symbols')
+    parser.add_argument('plugin_header', help='Path to QEMU plugin header.')
+    args = parser.parse_args()
+
+    syms = extract_symbols(args.plugin_header)
+
+    print('{')
+    for s in syms:
+        print("  {};".format(s))
+    print('};')
+
+if __name__ == '__main__':
+    main()
-- 
2.39.5



  parent reply	other threads:[~2024-10-31  4:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-31  4:04 [PATCH 00/12] Enable building plugins on Windows with Clang Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 01/12] scripts: remove erroneous file that breaks git clone on Windows Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 02/12] contrib/plugins/cflow: fix warning Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 03/12] meson: build contrib/plugins with meson Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 04/12] contrib/plugins: remove Makefile for contrib/plugins Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 05/12] qga: fix -Wsometimes-uninitialized windows warning Pierrick Bouvier
2024-10-31 13:32   ` Konstantin Kostiuk
2024-11-04 13:43     ` Konstantin Kostiuk
2024-10-31  4:04 ` [PATCH 06/12] qga: fix missing static and prototypes windows warnings Pierrick Bouvier
2024-10-31  4:11   ` Philippe Mathieu-Daudé
2024-10-31 13:32   ` Konstantin Kostiuk
2024-11-04 13:43     ` Konstantin Kostiuk
2024-11-04 22:30       ` Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 07/12] win32: use compiler option instead of attribute gcc_struct Pierrick Bouvier
2024-10-31  9:28   ` Daniel P. Berrangé
2024-10-31 10:44     ` Thomas Huth
2024-10-31 19:01       ` Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 08/12] plugins: enable linking with clang/lld Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 09/12] plugins: add missing export for qemu_plugin_num_vcpus Pierrick Bouvier
2024-10-31  4:14   ` Philippe Mathieu-Daudé
2024-10-31  4:04 ` Pierrick Bouvier [this message]
2024-10-31  4:04 ` [PATCH 11/12] plugins: eradicate qemu-plugins.symbols static file Pierrick Bouvier
2024-10-31  4:04 ` [PATCH 12/12] docs: add information on how to setup build environments Pierrick Bouvier
2024-10-31  9:24   ` Daniel P. Berrangé
2024-10-31 19:38     ` Pierrick Bouvier
2024-11-04 15:58   ` Peter Maydell
2024-11-04 16:08     ` Michael S. Tsirkin
2024-11-04 22:09       ` Pierrick Bouvier
2024-11-04 22:05     ` Pierrick Bouvier
2024-11-05 10:15       ` Peter Maydell
2024-11-06 17:13 ` [PATCH 00/12] Enable building plugins on Windows with Clang Pierrick Bouvier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241031040426.772604-11-pierrick.bouvier@linaro.org \
    --to=pierrick.bouvier@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=crosa@redhat.com \
    --cc=erdnaxe@crans.org \
    --cc=jsnow@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=ma.mandourr@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).