1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
graphic: 0.954
user-level: 0.952
permissions: 0.949
virtual: 0.947
semantic: 0.945
register: 0.940
mistranslation: 0.939
peripherals: 0.937
TCG: 0.937
debug: 0.936
vnc: 0.934
network: 0.934
assembly: 0.934
ppc: 0.932
arm: 0.931
boot: 0.929
hypervisor: 0.926
architecture: 0.925
performance: 0.924
socket: 0.924
PID: 0.922
risc-v: 0.920
files: 0.917
VMM: 0.913
kernel: 0.911
device: 0.909
KVM: 0.907
x86: 0.900
i386: 0.832
building plugin failed on Windows with mingw
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.
If I keep "-Wl,-soname,$@" in the command , I got similar linking errors.
makefile:
SONAMES := $(addsuffix .dll,$(addprefix lib,$(NAMES)))
QEMU_CFLAGS += -fPIC -fno-stack-protector -DBUILDING_DLL
QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu
all: $(SONAMES)
lib%.dll: %.o
$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS)
output:
x86_64-w64-mingw32-gcc -shared -Wl,-soname,libbb.dll -o libbb.dll bb.o
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `g_autoptr_cleanup_generic_gfree':
C:/msys64/mingw64/include/glib-2.0/glib/glib-autocleanups.h:28: undefined reference to `g_free'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `plugin_exit':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:27: undefined reference to `g_strdup_printf'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:29: undefined reference to `qemu_plugin_outs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `vcpu_tb_trans':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:42: undefined reference to `qemu_plugin_tb_n_insns'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:45: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:47: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:50: undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `qemu_plugin_install':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:64: undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:65: undefined reference to `qemu_plugin_register_atexit_cb'
collect2.exe: error: ld returned 1 exit status
On windows, I replace $LDLIBS with $LIBS here, because $LDLIBS seems undefined. But still yields linking error, except.
lib%.dll: %.o
$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LIBS)"
x86_64-w64-mingw32-gcc -shared -Wl,-soname,libbb.dll -o libbb.dll bb.o -ldl -LC:/msys64/mingw64/lib -lz -LC:/msys64/mingw64/lib -lgmodule-2.0 -pthread -lglib-2.0 -lintl -LC:/msys64/mingw64/lib -lgthread-2.0 -pthread -lglib-2.0 -lintl -lwinmm -lws2_32 -liphlpapi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `plugin_exit':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:29: undefined reference to `qemu_plugin_outs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `vcpu_tb_trans':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:42: undefined reference to `qemu_plugin_tb_n_insns'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:45: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:47: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:50: undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `qemu_plugin_install':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:64: undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:65: undefined reference to `qemu_plugin_register_atexit_cb'
The libdl library (where dlopen() is defined) was not shipped with MSYS2 mingw . It is compiled from source(https://github.com/dlfcn-win32/dlfcn-win32), and I place the generated libdl.dll, libdl.a, libdl.dll.a in C:\msys64\mingw64\include. dlfcn.h in C:\msys64\mingw64\include.
Xiaolei <email address hidden> writes:
> If I keep "-Wl,-soname,$@" in the command , I got similar linking errors.
>
> makefile:
> SONAMES := $(addsuffix .dll,$(addprefix lib,$(NAMES)))
>
> QEMU_CFLAGS += -fPIC -fno-stack-protector -DBUILDING_DLL
> QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu
>
> all: $(SONAMES)
> lib%.dll: %.o
> $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS)
>
> output:
> x86_64-w64-mingw32-gcc -shared -Wl,-soname,libbb.dll -o libbb.dll bb.o
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `g_autoptr_cleanup_generic_gfree':
> C:/msys64/mingw64/include/glib-2.0/glib/glib-autocleanups.h:28: undefined reference to `g_free'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `plugin_exit':
> C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:27: undefined reference to `g_strdup_printf'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:29: undefined reference to `qemu_plugin_outs'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `vcpu_tb_trans':
> C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:42: undefined reference to `qemu_plugin_tb_n_insns'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:45: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:47: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:50: undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `qemu_plugin_install':
> C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:64: undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:65: undefined reference to `qemu_plugin_register_atexit_cb'
> collect2.exe: error: ld returned 1 exit status
Cc'ing Emilio as he wrote the initial code so I assume built it at one point.
--
Alex Bennée
I never built the plugin code on anything other than Linux :(
All I did for Windows is to try to follow https://gcc.gnu.org/wiki/Visibility
Can you please try the following patch (with no other changes)?
The patch applies on top of v4.2.0.
diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile
index 75467b6db8..5b3611ad63 100644
--- a/tests/plugin/Makefile
+++ b/tests/plugin/Makefile
@@ -16,7 +16,7 @@ NAMES += hotpages
SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
-QEMU_CFLAGS += -fPIC
+QEMU_CFLAGS += -fPIC -DBUILDING_DLL
QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu
all: $(SONAMES)
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
Hi,
I patched configure file and makefile. The output is listed below.
The project is configured as :
#../configure --target-list=dsp-softmmu --cross-prefix=x86_64-w64-mingw32- --enable-gtk --enable-sdl --enable-debug --enable-plugins --extra-cflags="-DBUILDING_DLL"
But running make yeilds error:
CC dsp-softmmu/trace/generated-helpers.o
CC dsp-softmmu/trace/control-target.o
LINK dsp-softmmu/qemu-system-dspw.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lfdt
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile:208: qemu-system-dspw.exe] Error 1
make: *** [Makefile:491: dsp-softmmu/all] Error 2
We then reconfigured by disable the -fdt :
../configure --target-list=dsp-softmmu --cross-prefix=x86_64-w64-mingw32- --enable-gtk --enable-sdl --enable-debug --enable-plugins --disable-fdt --extra-cflags="-DBUILDING_DLL"
Build finished and running "make -C tests/plugin" gets similar linking errors:
x86_64-w64-mingw32-gcc -shared -Wl,-soname,libbb.so -o libbb.so bb.o
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `g_autoptr_cleanup_generic_gfree':
C:/msys64/mingw64/include/glib-2.0/glib/glib-autocleanups.h:28: undefined reference to `g_free'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `plugin_exit':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:27: undefined reference to `g_strdup_printf'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:29: undefined reference to `qemu_plugin_outs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:30: undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `vcpu_tb_trans':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:42: undefined reference to `qemu_plugin_tb_n_insns'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:45: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:47: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:50: undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `qemu_plugin_install':
C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:64: undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:65: undefined reference to `qemu_plugin_register_atexit_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.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
---------makefile -----------
BUILD_DIR := $(CURDIR)/../..
include $(BUILD_DIR)/config-host.mak
include $(SRC_PATH)/rules.mak
$(call set-vpath, $(SRC_PATH)/tests/plugin)
#out
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
QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu
all: $(SONAMES)
lib%.so: %.o
$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS)
clean:
rm -f *.o *.so *.d
rm -Rf .libs
.PHONY: all clean
You're getting close.
1. From the build directory, find the import library created, e.g. `find . -name 'libqemu_plugin.dll.a'`. If you're building x86_64-linux-user, it should be in `x86_64-linux-user/libqemu_plugin.dll.a`.
2. Go back to the `build/tests/plugin` directory.
3. Link the empty plugin with:
x86_64-w64-mingw32-gcc -shared -Wl,-soname,libempty.so -o libempty.so empty.o -L/path/to/libqemu_plugin.dll.a/directory -lqemu_plugin.dll
Note the added -L and -l flags.
If that works, move on to the other plugins, although you might have to comment out the glib-dependent code. But let's not go there yet; try to build the empty plugin first.
Hi Emilio,
I got the ideas for the attempt with a dummy dll. However, my collegue and I both failed to generate libqemu_plugin.dll.a during make process.
And running "make install" yields errors as follows:
mkdir -p "C:/QEMU_install/QEMUa/applications"
install -c -m 0644 /c/QRS_Project/simdsp/qemu-4.2.0/ui/qemu.desktop \
"C:/QEMU_install/QEMUa/applications/qemu.desktop"
make -C po install
make[1]: enter “/c/QRS_Project/simdsp/qemu-4.2.0/dsp_debug/po”
for obj in bg.mo de_DE.mo fr_FR.mo hu.mo it.mo tr.mo zh_CN.mo; do \
base=$(basename $obj .mo); \
install -d C:/QEMU_install/QEMUa/share/locale/$base/LC_MESSAGES; \
install -m644 $obj C:/QEMU_install/QEMUa/share/locale/$base/LC_MESSAGES/qemu.mo; \
done
make[1]: leave “/c/QRS_Project/simdsp/qemu-4.2.0/dsp_debug/po”
install -c -m 0644 /c/QRS_Project/simdsp/qemu-4.2.0/include/qemu/qemu-plugin.h "C:/QEMU_install/QEMUa/include/qemu-plugin.h"
for d in dsp-softmmu; do \
install -c -m 0644 "$d/libqemu_plugin.dll.a" "C:/QEMU_install/QEMUa/lib/$d/libqemu_plugin.dll.a"; \
done
install: unable to get 'dsp-softmmu/libqemu_plugin.dll.a' file status (stat): No such file or directory
make: *** [Makefile:890:install] error 1
Any ideas?
You should then find out why libqemu_plugin.dll.a is not working. It is possible though that your linked is calling the import library something else, for instance adding a .dll extension to it.
You will have to run a few tests with your linker (I'd just use the examples from the stackoverflow links I posted above) to see the name of the import library that gets created. My assumption is that some library gets created, otherwise the linked should give you an error and AFAICT it does not.
Once you find what the import library us, you should be in good shape to adapt the above for QEMU. Let us know how it goes!
Emilio G. Cota <email address hidden> writes:
> You should then find out why libqemu_plugin.dll.a is not working. It is
> possible though that your linked is calling the import library something
> else, for instance adding a .dll extension to it.
>
> You will have to run a few tests with your linker (I'd just use the
> examples from the stackoverflow links I posted above) to see the name of
> the import library that gets created. My assumption is that some library
> gets created, otherwise the linked should give you an error and AFAICT
> it does not.
>
> Once you find what the import library us, you should be in good shape to
> adapt the above for QEMU. Let us know how it goes!
I did have a go but couldn't get far with the mingw docker images. I got
somewhat distracted yesterday solving the mysterious regenerating
syscall_nr.h problem so I've run out of bandwidth to look at this any
longer. If the two of you find an eventual solution please send me a
patch.
Thanks.
--
Alex Bennée
The QEMU project is currently moving its bug tracking to another system.
For this we need to know which bugs are still valid and which could be
closed already. Thus we are setting the bug state to "Incomplete" now.
If the bug has already been fixed in the latest upstream version of QEMU,
then please close this ticket as "Fix released".
If it is not fixed yet and you think that this bug report here is still
valid, then you have two options:
1) If you already have an account on gitlab.com, please open a new ticket
for this problem in our new tracker here:
https://gitlab.com/qemu-project/qemu/-/issues
and then close this ticket here on Launchpad (or let it expire auto-
matically after 60 days). Please mention the URL of this bug ticket on
Launchpad in the new ticket on GitLab.
2) If you don't have an account on gitlab.com and don't intend to get
one, but still would like to keep this ticket opened, then please switch
the state back to "New" within the next 60 days (otherwise it will get
closed as "Expired"). We will then eventually migrate the ticket auto-
matically to the new system (but you won't be the reporter of the bug
in the new system and thus won't get notified on changes anymore).
Thank you and sorry for the inconvenience.
[Expired for QEMU because there has been no activity for 60 days.]
|