[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug 1885827] Re: building plugin failed on Windows with mingw
From: |
Emilio G. Cota |
Subject: |
[Bug 1885827] Re: building plugin failed on Windows with mingw |
Date: |
Sun, 05 Jul 2020 00:11:10 -0000 |
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
--
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1885827
Title:
building plugin failed on Windows with mingw
Status in QEMU:
New
Bug description:
I want to build QEMU 4.2.0's plugin module on Windows 7/10 with Mingw, but
the building process faild.
The step I follow is listed below:
1. create "dsp_build" diretory under source file folder
2. change directory to dsp_build , and run ../configure
--target-list=dsp-softmmu --cross-prefix=x86_64-w64-mingw32- --enable-gtk
--enable-sdl --enable-debug --enable-plugins
3. build qemu project
4. switch dir to /dsp_build, make -C tests/plugin, yeilds error:
CC bb.o
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:17:24:
error: variable 'qemu_plugin_version' definition is marked dllimport
17 | QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
| ^~~~~~~~~~~~~~~~~~~
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:17:24:
warning: 'qemu_plugin_version' redeclared without dllimport attribute: previous
dllimport ignored [-Wattributes]
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c: In
function 'vcpu_tb_exec':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:33:29:
warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
33 | unsigned long n_insns = (unsigned long)udata;
| ^
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c: In
function 'vcpu_tb_trans':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:51:46:
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
51 | (void *)n_insns);
5. Then , I modified the QEMU_flags and the compilation command
arguments($(CC) ..) in the makefile :
BUILD_DIR := $(CURDIR)/../..
include $(BUILD_DIR)/config-host.mak
include $(SRC_PATH)/rules.mak
$(call set-vpath, $(SRC_PATH)/tests/plugin)
NAMES :=
NAMES += bb
NAMES += empty
NAMES += insn
NAMES += mem
NAMES += hotblocks
NAMES += howvec
NAMES += hotpages
SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
QEMU_CFLAGS += -fPIC -DBUILDING_DLL #added
-DBUILDING_DLL
QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu
all: $(SONAMES)
lib%.so: %.o
$(CC) -fPIC -shared -o $@ $^ $(LDLIBS) -L
/c/msys64/mingw64/lib/ -lglib-2.0
# original cmd: $(CC) -shared -Wl,-soname,$@ -o $@ $^
$(LDLIBS)
clean:
rm -f *.o *.so *.d
rm -Rf .libs
.PHONY: all clean
6. Executing make yeilds:
make: enter
“/d/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/build_dsp/tests/plugin”
CC bb.o
x86_64-w64-mingw32-gcc -fPIC -shared -o libbb.so bb.o -L
/c/msys64/mingw64/lib/ -lglib-2.0
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
bb.o: in function `plugin_exit':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:28:
undefined reference to `qemu_plugin_outs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:29:
undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
bb.o: in function `vcpu_tb_trans':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:41:
undefined reference to `qemu_plugin_tb_n_insns'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:44:
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:46:
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:49:
undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
bb.o: in function `qemu_plugin_install':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:63:
undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:64:
undefined reference to `qemu_plugin_register_atexit_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
bb.o:bb.c:(.rdata$.refptr.__stack_chk_guard[.refptr.__stack_chk_guard]+0x0):
undefined reference to `__stack_chk_guard'
collect2.exe: error: ld returned 1 exit status
It looks like linking problem(fail to link functions defined in api.c,
core.c...), but I have no idea what goes wrong. If I mannualy add api.o, core.o
in the compilation command, still get error like undefined reference to
'__stack_chk_guard'.
My collegue can build 4.2.0 plugins on Ubuntu Linux without any problem.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1885827/+subscriptions
- [Bug 1885827] Re: building plugin failed on Windows with mingw, Xiaolei, 2020/07/03
- [Bug 1885827] Re: building plugin failed on Windows with mingw, Emilio G. Cota, 2020/07/03
- [Bug 1885827] Re: building plugin failed on Windows with mingw,
Emilio G. Cota <=
- [Bug 1885827] Re: building plugin failed on Windows with mingw, Xiaolei, 2020/07/06
- [Bug 1885827] Re: building plugin failed on Windows with mingw, Emilio G. Cota, 2020/07/06
- [Bug 1885827] Re: building plugin failed on Windows with mingw, Xiaolei, 2020/07/07
- [Bug 1885827] Re: building plugin failed on Windows with mingw, Emilio G. Cota, 2020/07/08