From nobody Sat Nov 23 19:43:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1730347539; cv=none; d=zohomail.com; s=zohoarc; b=XdlHaKLKJJBiDbYFhjmIpzhZALn4aL7ptBsI2kumgLqy94UIa2bp9gmRxqCKP/lThVrdDRNpCCg08644pUDowbad8c+7J4n1D/ZuvF9wcLvJuIIcoV4oalz778Gvm1dc1CZkAjrQOIJ0tUdMt8qUuWmXXnUfN1PlUpgfzjq3VFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730347539; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MazmFmRo30op9YnWOmViRpaEpFEJWTUfVA0x4drzOKE=; b=TyKd8CaShWb28FWUQej6F5LzIrSDFT7/F4rcylGk+plCpJMMfaim87cDvfA4jWsMDPMq2aggXP+rpVLvKbK2uY3dtIkdQ3rCay0cliNb//3IR5oWc9ztS2nkdFbtF8wJV4UFV3FmxYxJgtuOChjCwe4D2gJyCRkru1/RKEdJK0o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730347539515172.4674621651169; Wed, 30 Oct 2024 21:05:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6MQr-0003mg-Gk; Thu, 31 Oct 2024 00:05:13 -0400 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 1t6MQn-0003iA-Dv for qemu-devel@nongnu.org; Thu, 31 Oct 2024 00:05:09 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t6MQk-00052o-QF for qemu-devel@nongnu.org; Thu, 31 Oct 2024 00:05:08 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2e3fca72a41so458988a91.1 for ; Wed, 30 Oct 2024 21:05:06 -0700 (PDT) Received: from linaro.. (216-180-64-156.dyn.novuscom.net. [216.180.64.156]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e93db3a023sm428438a91.49.2024.10.30.21.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 21:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730347505; x=1730952305; 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=MazmFmRo30op9YnWOmViRpaEpFEJWTUfVA0x4drzOKE=; b=MZtrlJvIBG4cWcdTt8pd+KKsdh6m/7r0KO91JCsN8EEFlKH+9zUAJpJnRxug0TnLmR wJSMVhs5iv7STZIYrnzzQAvqsF4ilBGISjVVKH2HmRlNmFPdv2g9O+3IIX8DrWl85ovW Qmf6pBrZCzGL9cZ3Hj/1uabpZAWELD8G4IBVSRTqVS9N6Sh+k4Ih9/DDMDf8cxwombeT +hBCNSxed2p09d6bPXyYgKSqWawdcP8YS4WrZnodWA5U78Q8/caajgvtlOFMXj0a1xa1 53bLAMyZS9z9EvYCQMLtQ7hgQ7D++g1CPuKnMh4fJVW+DOZz6cT0JpgYYx3Dchu4NJZm t42A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730347505; x=1730952305; 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=MazmFmRo30op9YnWOmViRpaEpFEJWTUfVA0x4drzOKE=; b=ltXe29v7fgjdju4osMSJm7OgTplerGx2BxUeZoaXY4DPHVIi2eHmT1pJctlBQkaV4Z AKM3usGZPt7Wkyu5m4O3YKr/R/7F3CeZdx2BGWmjlINFkVXoeQ4FB7fse7huZXIpoQC9 3CmwCsTyY7Gg5NUNf919lYrOmJmmz7ieAwG2hyqZyK9DBM4jSCcAZmhykh6vNeCwCpgR vzb2bXnqiyUbxevG2rMAMbHAP11DeDjgcz2a5306M7vU8OGa9KEs4CXFMFDYLRdHlLej gH9bRrRr1TP7Pd6ooG0k+J2qrgcevDz5FezCD8UROtU8diF0G9K50fXhNH2aOhzBRim0 6KVA== X-Gm-Message-State: AOJu0YzD9tzHjz3OV7maVaktr0hRqinJs3FHWHoL3eHnH7h9hgJReu55 I3h2gKeSOFbX7/AtV4ftqJ8L6XL3jfs/wc8ocgzKhQNDKpjjB62pE74K7eoswwKag8wsa/pUoNN suJTTsA== X-Google-Smtp-Source: AGHT+IHdmSiRISRG5n+ZBrvve1XtDbfjxHdxnqVkOlXZXDyKbVyjzGTs5AJSO6xJnFkwQjww9CZpeg== X-Received: by 2002:a17:90b:1a8e:b0:2e5:e43a:1413 with SMTP id 98e67ed59e1d1-2e93c182879mr2408081a91.9.1730347505119; Wed, 30 Oct 2024 21:05:05 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Cleber Rosa , John Snow , Michael Roth , Alexandre Iooss , Konstantin Kostiuk , Stefano Garzarella , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S. Tsirkin" , Mahmoud Mandour , Pierrick Bouvier Subject: [PATCH 08/12] plugins: enable linking with clang/lld Date: Wed, 30 Oct 2024 21:04:22 -0700 Message-Id: <20241031040426.772604-9-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241031040426.772604-1-pierrick.bouvier@linaro.org> References: <20241031040426.772604-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x102e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1730347541243116600 Content-Type: text/plain; charset="utf-8" Windows uses a special mechanism to enable plugins to work (DLL delay loading). Option for lld is different than ld. Signed-off-by: Pierrick Bouvier --- meson.build | 4 ++++ contrib/plugins/meson.build | 2 +- plugins/meson.build | 24 ++++++++++++++++++++---- tests/tcg/plugins/meson.build | 3 +-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index d0d5dbe1479..fe11570b147 100644 --- a/meson.build +++ b/meson.build @@ -334,6 +334,10 @@ elif host_os =3D=3D 'windows' # We use this compilation option instead of relying on gcc_struct attrib= ute # because clang does not support it (but supports the option). qemu_common_flags +=3D ['-mno-ms-bitfields'] + + if compiler.get_id() =3D=3D 'clang' and compiler.get_linker_id() !=3D 'l= d.lld' + error('On windows, you need to use lld with clang - use msys2 clang64/= clangarm64 env') + endif endif =20 # Choose instruction set (currently x86-only) diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build index 63a32c2b4f0..484b9a808c8 100644 --- a/contrib/plugins/meson.build +++ b/contrib/plugins/meson.build @@ -12,7 +12,7 @@ if get_option('plugins') t +=3D 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 +=3D shared_module(i, files(i + '.c'), diff --git a/plugins/meson.build b/plugins/meson.build index 1cc039d29b2..51297582f93 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -11,14 +11,15 @@ if not enable_modules capture: true, command: ['sed', '-ne', 's/^[[:space:]]*\\(qemu_.*\\);/_\\1/p', '@IN= PUT@']) emulator_link_args +=3D ['-Wl,-exported_symbols_list,plugins/qemu-plug= ins-ld64.symbols'] + elif host_os =3D=3D 'windows' and meson.get_compiler('c').get_id() =3D= =3D 'clang' + # LLVM/lld does not support exporting specific symbols. However, it wo= rks + # out of the box with dllexport/dllimport attribute we set in the code. else emulator_link_args +=3D ['-Xlinker', '--dynamic-list=3D' + (meson.proj= ect_source_root() / 'plugins/qemu-plugins.symbols')] endif endif =20 if host_os =3D=3D 'windows' - dlltool =3D 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 expe= ct to have # available in qemu @@ -27,12 +28,27 @@ if host_os =3D=3D '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 w= ant + # to find missing symbols in current program. + win32_qemu_plugin_api_link_flags =3D ['-Lplugins', '-lqemu_plugin_api'] + if meson.get_compiler('c').get_id() =3D=3D 'clang' + # With LLVM/lld, delaylib is specified at link time (-delayload) + dlltool =3D find_program('llvm-dlltool', required: true) + dlltool_cmd =3D [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qe= mu.exe'] + win32_qemu_plugin_api_link_flags +=3D ['-Wl,-delayload=3Dqemu.exe'] + else + # With gcc/ld, delay lib is built with a specific delay parameter. + dlltool =3D find_program('dlltool', required: true) + dlltool_cmd =3D [dlltool, '--input-def', '@INPUT@', + '--output-delaylib', '@OUTPUT@', '--dllname', 'qemu.exe= '] + endif win32_qemu_plugin_api_lib =3D 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 f847849b1b7..87a17d67bd4 100644 --- a/tests/tcg/plugins/meson.build +++ b/tests/tcg/plugins/meson.build @@ -5,9 +5,8 @@ if get_option('plugins') t +=3D 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 +=3D shared_module(i, files(i + '.c'), include_directories: '../../../include/qemu', --=20 2.39.5