From patchwork Mon Nov 25 15:20:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 845345 Delivered-To: patch@linaro.org Received: by 2002:a5d:688e:0:b0:382:43a8:7b94 with SMTP id h14csp1247838wru; Mon, 25 Nov 2024 07:27:02 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVAcBYvzmJ2BQi7I0A66OHtJjV+evF82BAoPJxhBsZlZ1wEtqMfIEMCsCUt4tX0IJj8P5fqZQ==@linaro.org X-Google-Smtp-Source: AGHT+IGhAhoFwdXBb/HI5SGdPDB9ICxcw4dNJnW8O8Du1WesinfiW5bo9M2mGu7zrDK9maO9NowB X-Received: by 2002:ac8:7d0e:0:b0:45f:bc9e:c69c with SMTP id d75a77b69052e-4653d5265d4mr192752241cf.7.1732548421886; Mon, 25 Nov 2024 07:27:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732548421; cv=none; d=google.com; s=arc-20240605; b=J5/B5U4dHRlpCkogsn3xtnpc8gBGXzzkZGe/Xn/0PB9ILxEhpxpyQ/uBhDPQRXxD+/ ez6FTr5riaVKywFY4YFh9cHt9oxT74u1Evrp2DEQoJxZReNJ6WTmsADw3i7N0TctJwTQ qwFxdmWwyLJcT1QJmq3fODjjPUdvjgOcNMtWWmsDzn1FPxaXKGGcOjchjWRQdMNq+YLc wvpCgPZLF4iumJnyzfso0HdA8ebRBvBSQZy35AQGkoSBLYKLhiyUSpT+VQs1F7Pyf3xr qsQsx+34gHQfyS0jRMqrJzIk1V+aDjVKKSO0eXong8ZT/JFKyDv7j7ylcphxvmAqqV/0 yUWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YZrySn/V6spoVfFw52szUouQyzG89nZr7ULlEg8CZ30=; fh=0xMLk5T29NkSTcikq+HiGQ7K6zbj1erOdSOAvxiZ1Z0=; b=DP9YCsx/dV79zOJ6l2m7KpxuCwP+7oB0Cv48uVN1h340xs824anBGTXGFtYCe6AwYr F5XLNh7wg00mTF+BygN0fdsy+pYQiue9qn6l43Uab/UmvtZh68gHCIZmajgCS1HYDAiP k9mSZxw0AoPP1QY2fxFoCOYd0y2VaZQsBIiklJ1GMHRNtxGQFmP1NNDOxwD6VXRmxAE2 oozSRydEZ7+Ody3Jr0VK59PjDz6sM4Rpnu8dirPv9pjhO1Pl+JYlatGAdk9drhmurka+ drrom8b/4Bg18hWxgKuRdrjH45B0QOa29YZkVt3MBKWao808A0uQGGI62zrqtK3T4BaF jIRw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y8VK0qKg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4666fe0145csi80214271cf.328.2024.11.25.07.27.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Nov 2024 07:27:01 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y8VK0qKg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tFaz6-0007Wd-Uk; Mon, 25 Nov 2024 10:26:45 -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 1tFayn-0006zk-TO for qemu-devel@nongnu.org; Mon, 25 Nov 2024 10:26:25 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tFayk-0002Ym-RZ for qemu-devel@nongnu.org; Mon, 25 Nov 2024 10:26:25 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-382442b7d9aso3508324f8f.1 for ; Mon, 25 Nov 2024 07:26:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732548379; x=1733153179; 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=YZrySn/V6spoVfFw52szUouQyzG89nZr7ULlEg8CZ30=; b=Y8VK0qKg7bkAwMDBZehEzPKgIdfh77XUwkZ9aneEy8ByeyjA8cMihoIWYD2LzUVDV/ vakJtPaMN4twUMOub4WIa9mWwZfaa/m3K6UqSIDgd89GfslGLLcMnDM38qBX5bDqVp1i RkZUzBjPVFr2VqKfCJiV/kHlmwCUEOvqUvhPVPDJErk8wIrHYg0vefc2QZaomu+s5/iS CFPuRyEsh1Ir9Y0yQ1wWUc7kmR8dbSS8yRdOo7ZCmLGc9ZCJk5pA0jSc/1u2v71NuIuJ Jr0ooeTV0L/BoIc0xjHUrNMhlrAgM1CUUfvDDu8B0eH398BqzlYc3ENHRloW5LH8yS6g EojQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732548379; x=1733153179; 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=YZrySn/V6spoVfFw52szUouQyzG89nZr7ULlEg8CZ30=; b=Fn13D/NVZ7C75TfVQSCxgjsP/ag2aoq1Uky6siWifrkWQvjHn8u3ZWzchj2a3yHQ7x 2pH8ccfQjssclWCtu4ahoCMyxLFjSQfj670qx5zKGhiulJ4Wq0ujKG2l51wWkIzIvmID cfg+VxiaXd+vMUBOKsoqT5hsUBPH8ClSezgmi9pU2Lz+zXF1oRrGA2Yhw498zGp7P0j4 8cuyYLOh9v2rNAwqaXoSRHU+zRn7pRuOm7+vuvA7qGKrdFyLXsPUn/W0t0ROvUGkMnOO H0Qq3V53F+6srCY0fOCAFIttt75wSxa+4Yana03HulgrSaA5uE8QWpeoqsIWoSsdZNb/ 1QMg== X-Gm-Message-State: AOJu0YzB3rbnvg/OOnsIjIoK75lf1fXeCgTSJKNjarRSyRLNaJIHfAYb Ea61RGclaeoQ7xXLVOfbBn6iGDYZKixXaw2j4SBPt4QtrPNdDPXvYzpqTQfrcPs= X-Gm-Gg: ASbGncurWiPid663udaljZn6vNGJYCTuPKmuVZYVGz8cqjlcg676CczBYruQddcZDoO poGJqqxOj06M7b3oFOKydAMq/vuIQZWJvi6rXrOZlEfHuuan7kILrYnfYCiqy3FPb+MS7MLsx2q u+fM+b4KPB5DfOUgRt1dpYFKBL2a/o+qW97y2oZEjDP07K9NEr/Dp+hWyWayUhD9zvfDrBhXUTs tbjmAPwNUSl4p5G4rDL9ov4AUauZWCYq7vo6/gtCg4AzfzU X-Received: by 2002:a05:6000:144c:b0:37d:2d27:cd93 with SMTP id ffacd0b85a97d-38260bcb460mr12243489f8f.43.1732548378686; Mon, 25 Nov 2024 07:26:18 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3825fbee043sm10684677f8f.104.2024.11.25.07.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 07:26:16 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C8EED62948; Mon, 25 Nov 2024 15:21:07 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour , John Snow , Cleber Rosa Subject: [PULL 22/28] plugins: detect qemu plugin API symbols from header Date: Mon, 25 Nov 2024 15:20:59 +0000 Message-Id: <20241125152105.2100395-23-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241125152105.2100395-1-alex.bennee@linaro.org> References: <20241125152105.2100395-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42b.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=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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 Message-Id: <20241121165806.476008-37-alex.bennee@linaro.org> 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()