From patchwork Sun Jul 5 00:11:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Emilio G. Cota" <1885827@bugs.launchpad.net> X-Patchwork-Id: 1322959 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bugs.launchpad.net Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49zq9v1cKdz9sRf for ; Sun, 5 Jul 2020 10:21:05 +1000 (AEST) Received: from localhost ([::1]:46424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrsOz-0003pN-92 for incoming@patchwork.ozlabs.org; Sat, 04 Jul 2020 20:21:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrsOd-0003on-74 for qemu-devel@nongnu.org; Sat, 04 Jul 2020 20:20:39 -0400 Received: from indium.canonical.com ([91.189.90.7]:37518) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jrsOa-0004e0-Ot for qemu-devel@nongnu.org; Sat, 04 Jul 2020 20:20:38 -0400 Received: from loganberry.canonical.com ([91.189.90.37]) by indium.canonical.com with esmtp (Exim 4.86_2 #2 (Debian)) id 1jrsOY-0001ZP-Mb for ; Sun, 05 Jul 2020 00:20:34 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 9FD772E80E7 for ; Sun, 5 Jul 2020 00:20:34 +0000 (UTC) MIME-Version: 1.0 Date: Sun, 05 Jul 2020 00:11:10 -0000 From: "Emilio G. Cota" <1885827@bugs.launchpad.net> To: qemu-devel@nongnu.org X-Launchpad-Notification-Type: bug X-Launchpad-Bug: product=qemu; status=New; importance=Undecided; assignee=None; X-Launchpad-Bug-Tags: plugins windows X-Launchpad-Bug-Information-Type: Public X-Launchpad-Bug-Private: no X-Launchpad-Bug-Security-Vulnerability: no X-Launchpad-Bug-Commenters: ajbennee casmac cota X-Launchpad-Bug-Reporter: Xiaolei (casmac) X-Launchpad-Bug-Modifier: Emilio G. Cota (cota) References: <159357217483.1717.4076077243388027502.malonedeb@chaenomeles.canonical.com> Message-Id: <159390787028.1458.9877661384077260896.malone@wampee.canonical.com> Subject: [Bug 1885827] Re: building plugin failed on Windows with mingw X-Launchpad-Message-Rationale: Subscriber (QEMU) @qemu-devel-ml X-Launchpad-Message-For: qemu-devel-ml Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="1cbd0aa39df153c901321817f9b57cf3f232b507"; Instance="production-secrets-lazr.conf" X-Launchpad-Hash: 7145bd7f740f5079fceb667355248f678358c54f Received-SPF: none client-ip=91.189.90.7; envelope-from=bounces@canonical.com; helo=indium.canonical.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 20:20:35 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -58 X-Spam_score: -5.9 X-Spam_bar: ----- X-Spam_report: (-5.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Bug 1885827 <1885827@bugs.launchpad.net> Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Xiaolei confirmed to me via email that adding -DBUILDING_DLL is not enough to fix the problem. I looked into this a bit further and it looks like we need an "import library" to be created when compiling the QEMU binary. This is accomplished by adding "-Wl,--out-implib,libqemu_plugin.a" to the linker invocation to build the QEMU binary. See these two stackoverflow questions: - https://stackoverflow.com/questions/17601949/building-a-shared-library-using-gcc-on-linux-and-mingw-on-windows - https://stackoverflow.com/questions/39759060/compile-to-dll-with-some-undefined-references-with-mingw It's not clear to me whether any import library with the symbols needed can work, or whether each target binary needs its corresponding import library, e.g. aarch64-linux-user and x86_64-linux-user need different libraries. The below is an attempt at the latter approach; one would just have to link the appropriate import library with "-l" when building the plugin. Please give this a try, and don't forget to also pass -DBUILDING_DLL to the linker. diff --git a/Makefile b/Makefile index b437a346d7..5cc1bc8e23 100644 --- a/Makefile +++ b/Makefile @@ -866,8 +866,14 @@ ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512 install-includedir: $(INSTALL_DIR) "$(DESTDIR)$(includedir)" +install-libdir: + $(INSTALL_DIR) "$(DESTDIR)$(libdir)" + for d in $(TARGET_DIRS); do \ + $(INSTALL_DIR) "$(DESTDIR)$(libdir)/$$d"; \ + done + install: all $(if $(BUILD_DOCS),install-doc) \ - install-datadir install-localstatedir install-includedir \ + install-datadir install-localstatedir install-includedir install-libdir \ $(if $(INSTALL_BLOBS),$(edk2-decompressed)) \ recurse-install ifneq ($(TOOLS),) @@ -932,6 +938,11 @@ ifdef CONFIG_GTK endif ifeq ($(CONFIG_PLUGIN),y) $(INSTALL_DATA) $(SRC_PATH)/include/qemu/qemu-plugin.h "$(DESTDIR)$(includedir)/qemu-plugin.h" +# ifeq MINGW, WINDOWS or similar. + for d in $(TARGET_DIRS); do \ + $(INSTALL_DATA) "$$d/libqemu_plugin.dll.a" "$(DESTDIR)$(libdir)/$$d/libqemu_plugin.dll.a"; \ + done +# endif endif $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps" set -e; for x in $(KEYMAPS); do \ diff --git a/configure b/configure index 6099be1d84..9606f6e888 100755 --- a/configure +++ b/configure @@ -7455,6 +7455,9 @@ if test "$plugins" = "yes" ; then "If \$plugins=yes, either \$ld_dynamic_list or " \ "\$ld_exported_symbols_list should have been set to 'yes'." fi + # if test "$mingw32" = "yes" ; then # or mingw, or windows; I don't know. + QEMU_LDFLAGS="-Wl,--out-implib,libqemu_plugin.dll.a" + # fi fi if test "$tcg_interpreter" = "yes"; then