From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1tEAWZ-00064i-5c for mharc-qemu-rust@gnu.org; Thu, 21 Nov 2024 11:59:23 -0500 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 1tEAVz-0004wt-Jl for qemu-rust@nongnu.org; Thu, 21 Nov 2024 11:58:51 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tEAVa-00087i-AG for qemu-rust@nongnu.org; Thu, 21 Nov 2024 11:58:46 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4315eeb2601so13243825e9.2 for ; Thu, 21 Nov 2024 08:58:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732208300; x=1732813100; 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=O5sQx390WX16rPflQuG3fyG6MjkwMEEP336vMFADYxQ=; b=Hx3hoKQPrKAAoMuIOAFw9kY/cLrwerCMRpc/3QQMpQxRQgqV/QzWtR1qnkCOz3qOe9 yapgCs93EnOqH4bsakisVkA2l/jS0xKQrQqZvzDvQr4gXZQt12SU+/1sssyN3i/Lg3ws LlEdBOAlB4yh3niXPWjskp6JCFwD1gvk46TKjjx6lw7P9IlOD+QwaskY9g9DfYcN9A4n GgHijXXAAyxLUfRbDtIVlTUp0+5SZItUBTU9I5B42mwuCN776vXFTnS6baIB6q9TSDPL sAgrRWu5aPjeVgplJ9IRuNfLwCdaLw5Ia6lNnNmxs4f2GFjMowJzXYBOW0GYSW2PKMuO w0zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732208300; x=1732813100; 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=O5sQx390WX16rPflQuG3fyG6MjkwMEEP336vMFADYxQ=; b=GDWv7Uyo/nbYzvZSruRAtrZg1OO49wnFR5fA6aT8dR9lmvrZa2aU3RulQJpSh4I02p UM5FoMIgkNia4TrRXj47YwsuKQgo7oRaFjb25bhfTMEEj8U2snPH6cKCnQ/hQTf8lyUJ 9KwLRvdSGawou/X6/y1H0/hrlNQuCG3I5es99Wun6qCjOfhk4KXm9ElbjR5Tvr8p1AJc k1QANqgRH1wf4Iy6tPrwNX1bc7NH8/ZFC6zO8pCN9/YKd8YJnzELrRtCHHCGvneg5wmJ 4FFaUKt6wkWNEb+6V+VIrXb9i6MDngzZG4GFmcjU8He64B5HwA9Wb9rJxKynCAD5zbiF ANFA== X-Forwarded-Encrypted: i=1; AJvYcCWhA9QNzwfZXyP58exnjADdWCqoPVxt2YAcXaHezTMnQbCEVRdJmy8rGi6ev6slSUEyiR5o5BI9UVI=@nongnu.org X-Gm-Message-State: AOJu0Yxg6PrCBEnKShOwR0qQ+uUqT8ANsIlwBEKj/jSOrGUrs90/4zjo BIQ0u6RC2zwm++aZDUrsz8HSD1qRqZtNrwtAAZq/8O9jeAQOe7RaeL03JwiL2Mc= X-Gm-Gg: ASbGncufgUOUnXBhzI3BW+fhCooO96z6rYJ8AtW0fELomOWWBN3UTMyJ3SmJMQzMwFh m61T1kWdmnZI/qCQDKe0XHybT6V26WSuW9jvfrTlJ7Z0eVWfaf4xpYkofDQe2BIxu1p4x6gHH3R cJVky0fWpPQcO48srsnbF6V2R9LGYEWXxO72+ZG45Lf42yJuQpak/FcizMgSgf75+Eh0rRv1UMR mlxz1g9Ws5gapAvfkyyEdgi2/rWhiaVrKGo2OvSg3SZUUtN X-Google-Smtp-Source: AGHT+IFfOxCiQV45h8DxYrwdRyuAkAKBudFuCE/1IvOgdFqlvwf/mDBmijE50A4pf0QU6/MMcK1u6g== X-Received: by 2002:a05:600c:3514:b0:431:9a26:3cf6 with SMTP id 5b1f17b1804b1-43348981878mr80506225e9.4.1732208298915; Thu, 21 Nov 2024 08:58:18 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-433b45d17e3sm64258435e9.5.2024.11.21.08.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 08:58:18 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B509B604F0; Thu, 21 Nov 2024 16:58:09 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Daniel Henrique Barboza , Pierrick Bouvier , Harsh Prateek Bora , Marcel Apfelbaum , Jiaxun Yang , Halil Pasic , Christian Borntraeger , qemu-ppc@nongnu.org, Daniel Henrique Barboza , Alexandre Iooss , qemu-riscv@nongnu.org, Thomas Huth , Bernhard Beschow , Thomas Huth , Eric Farman , Bin Meng , qemu-s390x@nongnu.org, Niek Linnenbank , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , John Snow , Wainer dos Santos Moschetta , Cleber Rosa , qemu-rust@nongnu.org, Nicholas Piggin , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Palmer Dabbelt , Markus Armbruster , Weiwei Li , Mahmoud Mandour , Mark Cave-Ayland , Liu Zhiwei , Aurelien Jarno , Ani Sinha , Alistair Francis Subject: [PATCH 36/39] plugins: detect qemu plugin API symbols from header Date: Thu, 21 Nov 2024 16:58:03 +0000 Message-Id: <20241121165806.476008-37-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241121165806.476008-1-alex.bennee@linaro.org> References: <20241121165806.476008-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.google.com 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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Nov 2024 16:58:56 -0000 From: Pierrick Bouvier 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 Message-Id: <20241112212622.3590693-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- 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 eb7149bf1a..2b1c4abed6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3752,6 +3752,7 @@ F: plugins/ F: tests/tcg/plugins/ F: tests/functional/test_aarch64_tcg_plugins.py F: contrib/plugins/ +F: scripts/qemu-plugin-symbols.py AArch64 TCG target M: Richard Henderson diff --git a/plugins/meson.build b/plugins/meson.build index 1cc039d29b..98542e926f 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -2,17 +2,23 @@ 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@']) emulator_link_args += ['-Wl,-exported_symbols_list,plugins/qemu-plugins-ld64.symbols'] 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 @@ -23,7 +29,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 0000000000..e285ebb8f9 --- /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 +# +# 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