From patchwork Tue Jan 14 11:38:09 2025 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: 857234 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp1872569wrc; Tue, 14 Jan 2025 03:41:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWeNSvMdcegkk4WS1KPNguXN9AEchO/kYKQBXe3S0V7yFcvd9R2wHTCOJrK+ZDNmS8+EbHAig==@linaro.org X-Google-Smtp-Source: AGHT+IGO49j0Sdu17sR/v+CBRp1xaZ4DIB7M2MioXf3XHUoRJNMHwvXxYB0M7XH5XJqh8fnS655n X-Received: by 2002:ac8:7c4e:0:b0:466:ac8d:7341 with SMTP id d75a77b69052e-46c710841e4mr361451491cf.35.1736854884692; Tue, 14 Jan 2025 03:41:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736854884; cv=none; d=google.com; s=arc-20240605; b=UfqVSdEyd7R4+rsgakdNPTFeNJUQWts+gqIFR9xey1WeavaTG+QCicpJNQB0rK6uHe l5V1JfBtvgzPQw3JpRzoR61wuFbi+vFQw5pAZa4epSkxF9DT+DTO4OXOPWoqEokZ4/Zr E0GbqQoTv9VeC2eviXz54EvbhNkPxwSAPUtoJJ1uNxivPhmc709iyTqw//FkPPu6a4GA ZfnK6ae/yYstOUZOoEY9whBAE8heEaGbsjQzksv/ngmxW6SU96SuDg5pMZAsgZaHVn6R zunOYYY4FSj3ql6ZF80bYteGi+kIjDIoW2HoyNYTXb6F4uSFYnU+GePflY2MfszYisNE 9hYQ== 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=castUuYEMS9/+bXLMhhSaPLlf0YHd3GiZGeVC9CY3P4=; fh=LVtTL688RvcRbDMJFiq0qHc5jRevRPVbQ8L9IWmjaH0=; b=k1ynLyScgA+yhgq1HevzAR7RAOnYPHVqz8TF8nzpq9BZpkd1vddMUxRU3TiVXAD89B 1zxhQ/JfZIjLvS7PzaAFWGpNqDxB3eKSvuW/RbWA0jucIOPHdVcIpAsfhodYC/b8SFgX KTBTyys/MBzfIo4iLadwLQsXat9hAHbSOGDwotsB6nJEairw5dAC9flWVadcVJfWe8rz t1FhAcbnqCrduDdMgCKast6Gd51dluZ1IyOCSfzM9sp/Vx9Q4QARZT+amRZzWb3XCXOu qLzeo9Y1wRJ4WFLipdPYDUA+JTDpNvYqJkeQm8cQkq7FH9g7ExdRdpiH6zor5yyES9mP Bgdw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bwqhtIft; 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-46c87413f17si113086801cf.554.2025.01.14.03.41.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Jan 2025 03:41:24 -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=bwqhtIft; 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 1tXfFw-0005De-LO; Tue, 14 Jan 2025 06:38:48 -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 1tXfFk-00057u-V0 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 06:38:39 -0500 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tXfFi-0005RI-2F for qemu-devel@nongnu.org; Tue, 14 Jan 2025 06:38:36 -0500 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5d414b8af7bso9602522a12.0 for ; Tue, 14 Jan 2025 03:38:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736854713; x=1737459513; 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=castUuYEMS9/+bXLMhhSaPLlf0YHd3GiZGeVC9CY3P4=; b=bwqhtIfttTmB7N5DbHXjHxsx9so4aljvjfvaw8WX+oXfSf0Qliwhl7xTymivnenPms EPjR9PBYMopJM1ZgDuTwwmhams/70cq3IxT/1zpK7Ku1mjWQEITYYKl6xUjIntsIfjwZ ZYR4SFPLE0yQL/wQr3ziNW0cjYisv9WfX+7f8RdaPuwvgfiAvHqIfj3d7uZWT6R+gOqn ZHrnTTFPHdVJohHVYZkRNBhy9j58bDmCyH/IjnHkkBgvBcQK3/n3QXoWzHJzzsNMmFHg i4VnFbC6KsB22lg7Ma73LDdvNiSpRJLr1Ej8xEi5tELpYmxSyzXPZZl28KF993iFb7vB tcgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736854713; x=1737459513; 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=castUuYEMS9/+bXLMhhSaPLlf0YHd3GiZGeVC9CY3P4=; b=jKjtLy85cwkkCWc8tOo0GqRE+HOqiDMzMiPhmrf9pDrFU5JVkbANZcJ8RjUAewEfvF pw1uFUd3PswgKbZSJmfZ7H+U86KQoMt289GaE0CHCA6RNm+G+/i4441Gjkj+DbHYVwAc D3rzuerdU3xu/tCLbx7ts9A6GZtNmbYrz0GUftfZ3o0Y9Hwxxi86AGsDjVw8J6lUTC4u ZwgB+6M1p9MB8NWCI1Cotd7YBgNv82ynpcpJ7Xx0RJe6BDP1XIQThB3O59E8IY3lo/PO a0yhoVrThRY/AmLedxZZSMzUcoOOIUtH7ZWgpsvBWP+7+GCKvN8v1jqzOPy7yhEhNLbE pHqw== X-Gm-Message-State: AOJu0YyvGbcD5QMaa5cjhIWOv4nLWvk+OLTHosxO5YabIx/uyOtxrdPP XTCibvafqRwNmFgO331F32eXXy8J4RfeSPOujApSpyjaV/Fbb41Ma1UrJ1IXlts= X-Gm-Gg: ASbGnct0elBuEOqRzCSGIHnY+Tn8e9f/wg3bs5WqN3IZMAsg+jqTxsxwYBA/U12euz/ nbVe/XhQRMAi6EtwtAtZUNMhF5VhnRdukjURDYB2TEBqIf9fiMaMcB7DkVa5kfoBGZMKdb3GtMl qcNAhARNfv7yjy0IB0Bcjvz3FRcTGZSrFF8wh13PqSOxh/L1CqYC94YTJiiLRPYRjIHjdAUBv46 veMox22xSFi39jQDjLeOJK4pLoPXWWPL83Wq5hxyJAGkIsh0CHPFdc= X-Received: by 2002:a05:6402:2355:b0:5d9:a55:4307 with SMTP id 4fb4d7f45d1cf-5d972e4eeabmr23355229a12.22.1736854712680; Tue, 14 Jan 2025 03:38:32 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d99046d7d5sm5911756a12.66.2025.01.14.03.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 03:38:32 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 2A45B5FA99; Tue, 14 Jan 2025 11:38:24 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefan Weil , Pierrick Bouvier , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= Subject: [PATCH v2 25/37] plugins: enable linking with clang/lld Date: Tue, 14 Jan 2025 11:38:09 +0000 Message-Id: <20250114113821.768750-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250114113821.768750-1-alex.bennee@linaro.org> References: <20250114113821.768750-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x534.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 Windows uses a special mechanism to enable plugins to work (DLL delay loading). Option for lld is different than ld. MSYS2 clang based environment use lld by default, so restricting to this config on Windows is safe, and will avoid false bug reports. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Pierrick Bouvier Tested-by: Stefan Weil Tested-by: Philippe Mathieu-Daudé Message-Id: <20250110203401.178532-4-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- meson.build | 5 +++++ contrib/plugins/meson.build | 2 +- plugins/meson.build | 24 ++++++++++++++++++++---- tests/tcg/plugins/meson.build | 3 +-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index da279cc112..15a066043b 100644 --- a/meson.build +++ b/meson.build @@ -377,6 +377,11 @@ elif host_os == 'sunos' qemu_common_flags += '-D__EXTENSIONS__' elif host_os == 'haiku' qemu_common_flags += ['-DB_USE_POSITIVE_POSIX_ERRORS', '-D_BSD_SOURCE', '-fPIC'] +elif host_os == 'windows' + # plugins use delaylib, and clang needs to be used with lld to make it work. + if compiler.get_id() == 'clang' and compiler.get_linker_id() != 'ld.lld' + error('On windows, you need to use lld with clang - use msys2 clang64/clangarm64 env') + endif endif # Choose instruction set (currently x86-only) diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build index 63a32c2b4f..484b9a808c 100644 --- a/contrib/plugins/meson.build +++ b/contrib/plugins/meson.build @@ -12,7 +12,7 @@ if get_option('plugins') t += shared_module(i, files(i + '.c') + 'win32_linker.c', include_directories: '../../include/qemu', link_depends: [win32_qemu_plugin_api_lib], - link_args: ['-Lplugins', '-lqemu_plugin_api'], + link_args: win32_qemu_plugin_api_link_flags, dependencies: glib) else t += shared_module(i, files(i + '.c'), diff --git a/plugins/meson.build b/plugins/meson.build index 98542e926f..d60be2a4d6 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -17,14 +17,15 @@ if not enable_modules capture: true, command: ['sed', '-ne', 's/^[[:space:]]*\\(qemu_.*\\);/_\\1/p', '@INPUT@']) emulator_link_args += ['-Wl,-exported_symbols_list,plugins/qemu-plugins-ld64.symbols'] + elif host_os == 'windows' and meson.get_compiler('c').get_id() == 'clang' + # 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=' + qemu_plugin_symbols.full_path()] endif endif if host_os == 'windows' - dlltool = find_program('dlltool', required: true) - # Generate a .lib file for plugins to link against. # First, create a .def file listing all the symbols a plugin should expect to have # available in qemu @@ -33,12 +34,27 @@ if host_os == 'windows' output: 'qemu_plugin_api.def', capture: true, command: ['sed', '-e', '0,/^/s//EXPORTS/; s/[{};]//g', '@INPUT@']) + # then use dlltool to assemble a delaylib. + # The delaylib will have an "imaginary" name (qemu.exe), that is used by the + # linker file we add with plugins (win32_linker.c) to identify that we want + # to find missing symbols in current program. + win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api'] + if meson.get_compiler('c').get_id() == 'clang' + # With LLVM/lld, delaylib is specified at link time (-delayload) + dlltool = find_program('llvm-dlltool', required: true) + dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe'] + win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe'] + else + # With gcc/ld, delay lib is built with a specific delay parameter. + dlltool = find_program('dlltool', required: true) + dlltool_cmd = [dlltool, '--input-def', '@INPUT@', + '--output-delaylib', '@OUTPUT@', '--dllname', 'qemu.exe'] + endif win32_qemu_plugin_api_lib = configure_file( input: win32_plugin_def, output: 'libqemu_plugin_api.a', - command: [dlltool, '--input-def', '@INPUT@', - '--output-delaylib', '@OUTPUT@', '--dllname', 'qemu.exe'] + command: dlltool_cmd ) endif specific_ss.add(files( diff --git a/tests/tcg/plugins/meson.build b/tests/tcg/plugins/meson.build index f847849b1b..87a17d67bd 100644 --- a/tests/tcg/plugins/meson.build +++ b/tests/tcg/plugins/meson.build @@ -5,9 +5,8 @@ if get_option('plugins') t += shared_module(i, files(i + '.c') + '../../../contrib/plugins/win32_linker.c', include_directories: '../../../include/qemu', link_depends: [win32_qemu_plugin_api_lib], - link_args: ['-Lplugins', '-lqemu_plugin_api'], + link_args: win32_qemu_plugin_api_link_flags, dependencies: glib) - else t += shared_module(i, files(i + '.c'), include_directories: '../../../include/qemu',