From patchwork Fri Jan 17 13:42:44 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: 858200 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:cc8:b0:385:e875:8a9e with SMTP id dq8csp708346wrb; Fri, 17 Jan 2025 05:53:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVUZT02Aw+bLPW3plHQB8QYa68us/gfNp3t670qr+TQr29vFVBkH61tZku0ZC9YLacExUMgTw==@linaro.org X-Google-Smtp-Source: AGHT+IHPhkUM2irxFOkcg9/hx6ser026WdwYDuo6jF27SKraV0JkgXFQE51mvryS7QWZlcoKnxLz X-Received: by 2002:a05:620a:2547:b0:7b9:a387:3cd8 with SMTP id af79cd13be357-7be6327905dmr402407485a.42.1737122005810; Fri, 17 Jan 2025 05:53:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1737122005; cv=none; d=google.com; s=arc-20240605; b=leTPJK5ctRMYoWfzfi/FrrekK7H3xq6wAx7ntaZadZRSSj4d8Gjej0IW0H4fRtJgSS XZfPyvC3viQsqeX9CAzFPuzIm3ZcpWMUI5KeUycfWEfRTPo43oMX6BF2+nLenVsocIOL v6ag0tot5UVnnqK+ugpcBs2cz0pW+YCcU5UN+kdX+jXyFkMyBNsg6SMYyKMM/5o1Lu8T haZGFD15X7Zcm6wuZKun4oYOWVXpbusm7lRRoJxp9TgnFfBfF7iaU+RCivcGVtlVOCAL tn3GldKHOT5sRss8dBrgFa38TLdCM3b1QFUOPlseyh3/pcc5VCdJjXsuWMX3YP+UkZtl LxSg== 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=+DsD0KNZtCjKGcEGcvgtBm3TE+kh+pIdctH3xrF6qRk=; fh=Y1Yb4IVqdhF7MyHwHB3TF2hTTqe0wP759mSStyiTTHU=; b=P37jZDMzvxGjwWSnHRfu9lgVP4AFx9Wv+sHMqFyXh71wWU8ho9dKOBIptvjLvc9kX5 SvNHC11UZ1X49yxcb0/pC1IsSWLOyFiFvKNi0gZTJWgxE4y7YkwSLlQ65cA2ErrK7E57 XZ25d3Zsn6rn/Bqv2vQHSMCOzwj/+PXs6izL+nlaSi4WYWsZDU1Em3NwtDpMf9mFAE4x WHP3lG24LPrKYoZjN0s8ifDb1i5MKyjUIp15od1ovSSWx4p7fMx8277PPBzVFSE8X2a0 KqFEl1HqnryaVydX/Rxgqhi3WaCe+xnrWjpO6I3SSqci4UOfLknainUrTAGjEYlbFlLU clWQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="fy662R/v"; 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 af79cd13be357-7be6146ca00si273169985a.89.2025.01.17.05.53.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Jan 2025 05:53:25 -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="fy662R/v"; 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 1tYmm3-0002WK-Re; Fri, 17 Jan 2025 08:52:35 -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 1tYmlv-0002UV-B6 for qemu-devel@nongnu.org; Fri, 17 Jan 2025 08:52:27 -0500 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tYmlr-0003kz-2z for qemu-devel@nongnu.org; Fri, 17 Jan 2025 08:52:27 -0500 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-ab2c9b8aecaso330535066b.0 for ; Fri, 17 Jan 2025 05:52:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737121939; x=1737726739; 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=+DsD0KNZtCjKGcEGcvgtBm3TE+kh+pIdctH3xrF6qRk=; b=fy662R/vjX5rwXPgvCPjKyCvfYby9SmriIUm/DHPb4c9/8tVxa3wUWwLJ6aSFUnNhz aPKl1CIrIvpSBTpoobRBHmadEFhq2eX/r47R7JU6KoClHS3lbFomlFXYZXgGUpNE7Qhu ualMixRx4FUbV80bOOqu9Vfnp3EJnQYBcgNRTMair4NITrQlyyr8rKHI92VhktNX0bpW /EPngm6zhvCoTAdpyiqbk4k3KZNDizwT8T/Vg3d54kYdruuWjA+iECO4j9ERnpQkYSKf gphjpPqHB9qZRBHtjqtYi6rO4S+0K26URpqzMW6uDzrKNLfKokcXSczdj9S9vDdFJ6y5 px1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737121939; x=1737726739; 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=+DsD0KNZtCjKGcEGcvgtBm3TE+kh+pIdctH3xrF6qRk=; b=VHKA/OqawLRtZy438kW+BrCN96DtJEgSyqwpHVOUPcH5ofciyiu79ahXLWXt3RFa2+ Ju8e9iIjOFBwRhskGSaQOHhYuRgxHQfJhGRUGGodEfQT9Hlid6Hc+Xd6xBjkV/6XYpMg ZmVq7Fasqqmt03XWPC1PT1vXVdF4pUCVqDkdJ22NqzYSS2mmSEjpefpSsmZH/fLDqMFb y4KgvPbhaZNZinJz1uVgjxIzOFWvtIgYgilLjAd9AVRrYRXdsBXSoFoAY92QmajSZdn6 FWLXSn7BXFj9bAvEHgjRyfL1N2Y85bbzo1iNGP6lo89ZZOq6vaMt+Va1bAZSqOVTOZ2n 967A== X-Gm-Message-State: AOJu0YyZM/ttI/LdQIbv2cwVpsrGHoR4egwF9uNX80s6bgleBKCprI/i gS0PMlDmbD4oTd0gaV8MJJgjlrgp91JqS0U7pjLSASuCYqmq6gDGRJvVgpZCU4k= X-Gm-Gg: ASbGnctRQMr+y7z9DvTRsNwwQ///mDMbpI+vwgij2r/VmK44neRHlN7DIYh22zIqfdi B5UHfEq6bs7vbUDW7XnOoTkOM54KiM0gve2xZvN2qXNBBuTlQJR+Gsx6I4rbI55P/Gsuba+gdwx z2hqWcPRTgqpohrD13E9xYqwER6jBB8X90Y0dkl7Vm7Gt9cHhwGRV4p1IGfRYDGtrhE5afP7DcC /NMG2Lt969Euy7nkFQTH6Aamfgltkqmcyk/jIRvzBq1NvYRkuVXYMY= X-Received: by 2002:a17:907:72c1:b0:ab3:61e8:aa16 with SMTP id a640c23a62f3a-ab38b38134amr322541466b.43.1737121939347; Fri, 17 Jan 2025 05:52:19 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5db73eb59c6sm1482637a12.62.2025.01.17.05.52.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 05:52:16 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 4C1FF608D9; Fri, 17 Jan 2025 13:42:59 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Philippe_Mathi?= =?utf-8?q?eu-Daud=C3=A9?= , Stefan Weil , =?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: [PULL 25/37] plugins: enable linking with clang/lld Date: Fri, 17 Jan 2025 13:42:44 +0000 Message-Id: <20250117134256.2079356-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250117134256.2079356-1-alex.bennee@linaro.org> References: <20250117134256.2079356-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62b.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 Message-Id: <20250116160306.1709518-26-alex.bennee@linaro.org> 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',