From patchwork Thu Oct 31 04:04:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 839848 Delivered-To: patch@linaro.org Received: by 2002:adf:a38c:0:b0:37d:45d0:187 with SMTP id l12csp79267wrb; Wed, 30 Oct 2024 21:05:39 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUk5eip3QgavyELT19XyyBciZOJj9Z0VHneTWFRK3yMbp61nbowd5xEUY+pWToBu6ibw0vt8w==@linaro.org X-Google-Smtp-Source: AGHT+IHUoBTzKrXrbnE4T0b8qEmSJzuE5/7PQ4uEt8lnnZGNRo5QYilDyNTbNLLonIpYQ2f5lFTO X-Received: by 2002:a05:6214:4890:b0:6cb:ece3:d923 with SMTP id 6a1803df08f44-6d351b25274mr23141656d6.42.1730347539182; Wed, 30 Oct 2024 21:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1730347539; cv=none; d=google.com; s=arc-20240605; b=HIzl36t8ptJp3HNqgNEi8oLJ9wv+6pF8BvwiVpXwZ/mjs9ePJfgf8O+l6a5C7V7ZnM unpqV/mOOObOPA7INTX0GC9zeIgicSUEiOte6PNFN/2iA3DdkQZRIM1b8Y9/bAqTjuqV xVpx0Un/o49kxw0C0fAVf5HeVzYAYDJIxbopQ2qej9HoSih2URVgKBTwrmc5Vnjd/dlK v1oU0WhpswBVJrN5G8n7rToB3JMJducYzJG4G7/iw0pGWVUAg9do4nuTipPlidVZYF/l Gt0cOUAPmJHdUmqSa9dJrUh+2H8STRWSuSj4bp3qt4g1vqQDuCa9PoXmaYbB+4uqvCad Ee+Q== 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=MazmFmRo30op9YnWOmViRpaEpFEJWTUfVA0x4drzOKE=; fh=qCkgi8uX0wPVo2PQZm7xsjDtLlhOh+0Zq/b6I6Z+gew=; b=BAFCBXXh6o5grtuxf2y/csjkacNL19G+EGjv8STf9AHdDPpHx4grUkZbh+uSNdAfmY X7KbsY90SK+PAytImY/+9enj/69VlDOOP7ufcAHIsVOWZfy85nzZZGQr3IXNLwFS+XYN VQbAXsXsyIAuPMyoF7T+xmlo1AKoNu4IEe5V78ugowxi1rWA8fHc/J/DFL1BRXoh1yqG 9Oq/J5MZPCzPAqVIkrGm6WCGMbAuPSyZa8aCBXZ64nZsrpRZrZRVSRRGeOhmMPFsl8Xq J3Rm7mVtnVeySHHgCO8ynyJjZjhxTm4MNg2i/dKhEOeOPGg7gmm7wk1WVvUJPkAs4M0K 9Eiw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MZtrlJvI; 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 6a1803df08f44-6d35418029fsi8267616d6.398.2024.10.30.21.05.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Oct 2024 21:05:39 -0700 (PDT) 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=MZtrlJvI; 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 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) 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-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) 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) 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_P=2E_Berrang=C3=A9?= , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , =?utf-8?q?Ale?= =?utf-8?q?x_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 == 'windows' # We use this compilation option instead of relying on gcc_struct attribute # because clang does not support it (but supports the option). qemu_common_flags += ['-mno-ms-bitfields'] + + 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 63a32c2b4f0..484b9a808c8 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 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', '@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=' + (meson.project_source_root() / 'plugins/qemu-plugins.symbols')] 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 @@ -27,12 +28,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 f847849b1b7..87a17d67bd4 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',