Skip to contentSkip to conversation

Enable plugin support on msys2/mingw

PATCH Superseded Yonggang Luo 2 participants 20 messages Oct 1, 2020 – Feb 10, 2021

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover Enable plugin support on msys2/mingw

V2-V3
Split following patches out

V1-V2
1. Fixes review comments
2. Increase QEMU_PLUGIN_VERSION to 1 for compat QEMU_PLUGIN_VERSION 0
3. Revise the loader to support for version 0 and 1
4. By export function qemu_plugin_initialize in plugin, and call it in loader= , so
we have no need call it in every plugin. And also provide a standard implem=
entation,
anyway, use can also override it.

Add this feature on msys2/mingw by using glib provided cross-platform dlsym f= unctional.

Yonggang Luo (6):
plugins: Fixes a issue when dlsym failed, the handle not closed
plugin: Fixes compiling errors on msys2/mingw
cirrus: Enable plugin in cirrus for windows
plugin: define QEMU_PLUGIN_API_IMPLEMENTATION first
plugin: getting qemu_plugin_get_hwaddr only expose one function
prototype
plugin: Getting qemu-plugin works under win32.

 .cirrus.yml                  |   3 +-
 Makefile                     |   1 -
 configure                    |  71 -------------
 contrib/plugins/hotblocks.c  |   3 +-
 contrib/plugins/hotpages.c   |   1 +
 contrib/plugins/howvec.c     |   1 +
 contrib/plugins/lockstep.c   |   1 +
 include/qemu/qemu-plugin.h   | 197 +++++++++++++++++++++++++++--------
 meson.build                  |   6 +-
 plugins/api.c                |  71 +++++++------
 plugins/core.c               |  11 +-
 plugins/loader.c             |  51 ++++++++-
 plugins/meson.build          |  10 +-
 plugins/plugin.h             |   1 +
 plugins/qemu-plugins.symbols |  40 -------
 tests/plugin/bb.c            |   5 +-
 tests/plugin/empty.c         |   1 +
 tests/plugin/insn.c          |   1 +
 tests/plugin/mem.c           |   1 +
 19 files changed, 262 insertions(+), 214 deletions(-)
 delete mode 100644 plugins/qemu-plugins.symbols

--=20
2.28.0.windows.1

#1 lore raw

PATCH v3 1/6 plugins: Fixes a issue when dlsym failed, the handle not closed

---
 plugins/loader.c | 1 +
 1 file changed, 1 insertion(+)
plugins/loader.c +1 -0
index 685d334e1a..8ac5dbc20f 100644
@@ -235,6 +235,7 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
     return rc;
 
  err_symbol:
+    g_module_close(ctx->handle);
  err_dlopen:
     qemu_vfree(ctx);
     return 1;
Signature · 1 line
2.28.0.windows.1
#3 lore raw

PATCH v3 2/6 plugin: Fixes compiling errors on msys2/mingw

In reply to Yonggang Luo
---
 contrib/plugins/hotblocks.c | 2 +-
 tests/plugin/bb.c           | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
contrib/plugins/hotblocks.c +1 -1
index 3942a2ca54..37435a3fc7 100644
@@ -102,7 +102,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
 {
     ExecCount *cnt;
     uint64_t pc = qemu_plugin_tb_vaddr(tb);
-    unsigned long insns = qemu_plugin_tb_n_insns(tb);
+    size_t insns = qemu_plugin_tb_n_insns(tb);
     uint64_t hash = pc ^ insns;
 
     g_mutex_lock(&lock);
tests/plugin/bb.c +2 -2
index e4cc7fdd6e..de09bdde4e 100644
@@ -72,7 +72,7 @@ static void vcpu_tb_exec(unsigned int cpu_index, void *udata)
     CPUCount *count = max_cpus ?
         g_ptr_array_index(counts, cpu_index) : &inline_count;
 
-    unsigned long n_insns = (unsigned long)udata;
+    uintptr_t n_insns = (uintptr_t)udata;
     g_mutex_lock(&count->lock);
     count->insn_count += n_insns;
     count->bb_count++;
@@ -81,7 +81,7 @@ static void vcpu_tb_exec(unsigned int cpu_index, void *udata)
 
 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
 {
-    unsigned long n_insns = qemu_plugin_tb_n_insns(tb);
+    size_t n_insns = qemu_plugin_tb_n_insns(tb);
 
     if (do_inline) {
         qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64,
Signature · 1 line
2.28.0.windows.1
#5 lore raw

PATCH v3 3/6 cirrus: Enable plugin in cirrus for windows

In reply to Yonggang Luo
---
 .cirrus.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
.cirrus.yml +2 -1
index 86ea33926a..5363142373 100644
@@ -104,7 +104,8 @@ windows_msys2_task:
     - C:\tools\msys64\usr\bin\bash.exe -lc "mkdir build"
     - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && ../configure
       --python=python3 --ninja=ninja
-      --target-list-exclude=i386-softmmu,arm-softmmu,ppc-softmmu,mips-softmmu"
+      --target-list-exclude=i386-softmmu,arm-softmmu,ppc-softmmu,mips-softmmu
+      --enable-plugins"
     - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && make -j$NUMBER_OF_PROCESSORS"
   test_script:
     - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && make V=1 check"
Signature · 1 line
2.28.0.windows.1
#6 lore raw

Re: [PATCH v3 3/6] cirrus: Enable plugin in cirrus for windows

Quoted 1 line · Yonggang Luo

If the build doesn't work until your later fixes then this should be the last patch in the series.

Quoted 18 lines
---
 .cirrus.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
.cirrus.yml +2 -1
index 86ea33926a..5363142373 100644
@@ -104,7 +104,8 @@ windows_msys2_task:
     - C:\tools\msys64\usr\bin\bash.exe -lc "mkdir build"
     - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && ../configure
       --python=python3 --ninja=ninja
-      --target-list-exclude=i386-softmmu,arm-softmmu,ppc-softmmu,mips-softmmu"
+      --target-list-exclude=i386-softmmu,arm-softmmu,ppc-softmmu,mips-softmmu
+      --enable-plugins"
     - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && make -j$NUMBER_OF_PROCESSORS"
   test_script:
     - C:\tools\msys64\usr\bin\bash.exe -lc "cd build && make V=1 check"
Signature · 1 line
Alex Bennée
#7 lore raw

PATCH v3 4/6 plugin: define QEMU_PLUGIN_API_IMPLEMENTATION first

In reply to Yonggang Luo

This is used to distinguish from the qemu and plugin in header qemu-plugin.h

---
 plugins/api.c  | 1 +
 plugins/core.c | 1 +
 2 files changed, 2 insertions(+)
plugins/api.c +1 -0
index bbdc5a4eb4..f16922ca8b 100644
@@ -35,6 +35,7 @@
  */
 
 #include "qemu/osdep.h"
+#define QEMU_PLUGIN_API_IMPLEMENTATION
 #include "qemu/plugin.h"
 #include "cpu.h"
 #include "sysemu/sysemu.h"
plugins/core.c +1 -0
index 51bfc94787..7a79ea4179 100644
@@ -12,6 +12,7 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 #include "qemu/osdep.h"
+#define QEMU_PLUGIN_API_IMPLEMENTATION
 #include "qemu/error-report.h"
 #include "qemu/config-file.h"
 #include "qapi/error.h"
Signature · 1 line
2.28.0.windows.1
#8 lore raw

Re: [PATCH v3 4/6] plugin: define QEMU_PLUGIN_API_IMPLEMENTATION first

Quoted 14 lines · Yonggang Luo

This is used to distinguish from the qemu and plugin in header qemu-plugin.h

---
 plugins/api.c  | 1 +
 plugins/core.c | 1 +
 2 files changed, 2 insertions(+)
plugins/api.c +0 -0
index bbdc5a4eb4..f16922ca8b 100644

plugins/api.c line 39

Quoted 5 lines
plugins/api.c +1 -0
@@ -35,6 +35,7 @@
  */
 
 #include "qemu/osdep.h"
+#define QEMU_PLUGIN_API_IMPLEMENTATION
 #include "qemu/plugin.h"

This doesn't do anything in this patch. You should split the special handling in the plugin header and combine it in this patch. Also I'm not quite sure of the logic you are trying to achieve later on:

  #if !defined(QEMU_PLUGIN_API_IMPLEMENTATION)
  #if defined(QEMU_PLUGIN_IMPLEMENTATION)
  #define QEMU_PLUGIN_EXTERN
  #else
  #define QEMU_PLUGIN_EXTERN extern
  #endif

It seems to me you could get away with only one symbol - ideally just defined in plugins/api.c so you don't need to churn the plugins with changes, e.g.

  #ifdef QEMU_PLUGIN_API_IMPLEMENTATION
  #define QEMU_PLUGIN_EXTERN
  #else
  #define QEMU_PLUGIN_EXTERN extern
  #endif

But I'd still like to have a better answer as to why we need the extern? Is this a limitation of the mingw compiler or some windows special?

Quoted 7 lines
plugins/api.c +0 -0
 #include "cpu.h"
 #include "sysemu/sysemu.h"
plugins/core.c +0 -0
index 51bfc94787..7a79ea4179 100644

plugins/core.c line 18

Quoted 7 lines
plugins/core.c +1 -0
@@ -12,6 +12,7 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 #include "qemu/osdep.h"
+#define QEMU_PLUGIN_API_IMPLEMENTATION
 #include "qemu/error-report.h"
 #include "qemu/config-file.h"
 #include "qapi/error.h"

I don't think we include qemu/plugin.h from this file although it does raise the question of what happens when other parts of QEMU include the internal qemu/plugins.h header.

Signature · 1 line
Alex Bennée
#9 lore raw

Re: [PATCH v3 4/6] plugin: define QEMU_PLUGIN_API_IMPLEMENTATION first

Hi, I split this out just for easier review, so the lines changed in api.c and core.c
equales to the number of function exported, anyway

Quoted 67 lines · Alex Bennée
Quoted 14 lines · Yonggang Luo

This is used to distinguish from the qemu and plugin in header qemu-plugin.h

---
 plugins/api.c  | 1 +
 plugins/core.c | 1 +
 2 files changed, 2 insertions(+)
plugins/api.c +0 -0
index bbdc5a4eb4..f16922ca8b 100644

plugins/api.c line 39

Quoted 5 lines
plugins/api.c +1 -0
@@ -35,6 +35,7 @@
  */
 
 #include "qemu/osdep.h"
+#define QEMU_PLUGIN_API_IMPLEMENTATION
 #include "qemu/plugin.h"

This doesn't do anything in this patch. You should split the special handling in the plugin header and combine it in this patch. Also I'm not quite sure of the logic you are trying to achieve later on:

  #if !defined(QEMU_PLUGIN_API_IMPLEMENTATION)
  #if defined(QEMU_PLUGIN_IMPLEMENTATION)
  #define QEMU_PLUGIN_EXTERN
  #else
  #define QEMU_PLUGIN_EXTERN extern
  #endif

It seems to me you could get away with only one symbol - ideally just defined in plugins/api.c so you don't need to churn the plugins with changes, e.g.

  #ifdef QEMU_PLUGIN_API_IMPLEMENTATION
  #define QEMU_PLUGIN_EXTERN
  #else
  #define QEMU_PLUGIN_EXTERN extern
  #endif

But I'd still like to have a better answer as to why we need the extern? Is this a limitation of the mingw compiler or some windows special?

Quoted 7 lines
plugins/api.c +0 -0
 #include "cpu.h"
 #include "sysemu/sysemu.h"
plugins/core.c +0 -0
index 51bfc94787..7a79ea4179 100644

plugins/core.c line 18

Quoted 7 lines
plugins/core.c +1 -0
@@ -12,6 +12,7 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 #include "qemu/osdep.h"
+#define QEMU_PLUGIN_API_IMPLEMENTATION
 #include "qemu/error-report.h"
 #include "qemu/config-file.h"
 #include "qapi/error.h"

I don't think we include qemu/plugin.h from this file although it does raise the question of what happens when other parts of QEMU include the internal qemu/plugins.h header.

Quoted 2 lines

--
Alex Bennée

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

#10 lore raw

PATCH v3 5/6 plugin: getting qemu_plugin_get_hwaddr only expose one function prototype

In reply to Yonggang Luo

This is used for counting how much function are export to qemu plugin.

---
 plugins/api.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
plugins/api.c +3 -5
index f16922ca8b..d325084385 100644
@@ -252,10 +252,12 @@ bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info)
 
 #ifdef CONFIG_SOFTMMU
 static __thread struct qemu_plugin_hwaddr hwaddr_info;
+#endif
 
 struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
                                                   uint64_t vaddr)
 {
+#ifdef CONFIG_SOFTMMU
     CPUState *cpu = current_cpu;
     unsigned int mmu_idx = info >> TRACE_MEM_MMU_SHIFT;
     hwaddr_info.is_store = info & TRACE_MEM_ST;
@@ -267,14 +269,10 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
     }
 
     return &hwaddr_info;
-}
 #else
-struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
-                                                  uint64_t vaddr)
-{
     return NULL;
-}
 #endif
+}
 
 bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
 {
Signature · 1 line
2.28.0.windows.1
#11 lore raw

Re: [PATCH v3 5/6] plugin: getting qemu_plugin_get_hwaddr only expose one function prototype

Quoted 27 lines · Yonggang Luo

This is used for counting how much function are export to qemu plugin.

---
 plugins/api.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
plugins/api.c +2 -0
index f16922ca8b..d325084385 100644
@@ -252,10 +252,12 @@ bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info)
 
 #ifdef CONFIG_SOFTMMU
 static __thread struct qemu_plugin_hwaddr hwaddr_info;
+#endif
 
 struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
                                                   uint64_t vaddr)
 {
+#ifdef CONFIG_SOFTMMU
     CPUState *cpu = current_cpu;
     unsigned int mmu_idx = info >> TRACE_MEM_MMU_SHIFT;
     hwaddr_info.is_store = info & TRACE_MEM_ST;
@@ -267,14 +269,10 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
     }
 

plugins/api.c struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, · line 275

Quoted 10 lines
plugins/api.c +1 -5
     return &hwaddr_info;
-}
 #else
-struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
-                                                  uint64_t vaddr)
-{
     return NULL;
-}
 #endif
+}

Hmm I'm not sure about this, surely you want the plugin system to complain early if your plugin is going to use a function that is incorrect for the mode you are running in?

Although we do currently unconditionally export the syscall functions and arguably they should be CONFIG_USER only as well.

Quoted 3 lines
plugins/api.c +0 -0
 bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
 {
Signature · 1 line
Alex Bennée
#12 lore raw

Re: [PATCH v3 5/6] plugin: getting qemu_plugin_get_hwaddr only expose one function prototype

Quoted 11 lines · Alex Bennée
Quoted 7 lines · Yonggang Luo

This is used for counting how much function are export to qemu plugin.

---
 plugins/api.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 5 lines

plugins/api.c bool

Quoted 5 lines
plugins/api.c +0 -0
index f16922ca8b..d325084385 100644
@@ -252,10 +252,12 @@ bool

qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info)

Quoted 6 lines

plugins/api.c bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info)

Quoted 6 lines
plugins/api.c +1 -0
 #ifdef CONFIG_SOFTMMU
 static __thread struct qemu_plugin_hwaddr hwaddr_info;
+#endif
 
 struct qemu_plugin_hwaddr

*qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,

Quoted 7 lines

plugins/api.c struct qemu_plugin_hwaddr

Quoted 7 lines
plugins/api.c +1 -0
                                                   uint64_t vaddr)
 {
+#ifdef CONFIG_SOFTMMU
     CPUState *cpu = current_cpu;
     unsigned int mmu_idx = info >> TRACE_MEM_MMU_SHIFT;
     hwaddr_info.is_store = info & TRACE_MEM_ST;
@@ -267,14 +269,10 @@ struct qemu_plugin_hwaddr

*qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,

Quoted 6 lines

plugins/api.c struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,

Quoted 6 lines
plugins/api.c +0 -2
     }
 
     return &hwaddr_info;
-}
 #else
-struct qemu_plugin_hwaddr

*qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,

Quoted 10 lines

plugins/api.c struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, · line 275

Quoted 6 lines
plugins/api.c +1 -3
-                                                  uint64_t vaddr)
-{
     return NULL;
-}
 #endif
+}

Hmm I'm not sure about this, surely you want the plugin system to complain early if your plugin is going to use a function that is incorrect for the mode you are running in?

I merged these two function for couting how much function are exported, so getting the code easier to review, otherwise
function qemu_plugin_get_hwaddr would be exported twice.

Quoted 11 lines

Although we do currently unconditionally export the syscall functions and arguably they should be CONFIG_USER only as well.

plugins/api.c struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, · line 278

Quoted 3 lines
plugins/api.c +0 -0
 bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
 {

--
Alex Bennée

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

Reviewed-by
#13 lore raw

Re: [PATCH v3 5/6] plugin: getting qemu_plugin_get_hwaddr only expose one function prototype

Quoted 50 lines · 罗勇刚(Yonggang Luo)
Quoted 11 lines · Alex Bennée
Quoted 7 lines · Yonggang Luo

This is used for counting how much function are export to qemu plugin.

---
 plugins/api.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Quoted 5 lines

plugins/api.c bool

Quoted 5 lines
plugins/api.c +0 -0
index f16922ca8b..d325084385 100644
@@ -252,10 +252,12 @@ bool

qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info)

Quoted 6 lines

plugins/api.c bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info)

Quoted 6 lines
plugins/api.c +1 -0
 #ifdef CONFIG_SOFTMMU
 static __thread struct qemu_plugin_hwaddr hwaddr_info;
+#endif
 
 struct qemu_plugin_hwaddr

*qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,

Quoted 7 lines

plugins/api.c struct qemu_plugin_hwaddr

Quoted 7 lines
plugins/api.c +1 -0
                                                   uint64_t vaddr)
 {
+#ifdef CONFIG_SOFTMMU
     CPUState *cpu = current_cpu;
     unsigned int mmu_idx = info >> TRACE_MEM_MMU_SHIFT;
     hwaddr_info.is_store = info & TRACE_MEM_ST;
@@ -267,14 +269,10 @@ struct qemu_plugin_hwaddr

*qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,

Quoted 6 lines

plugins/api.c struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,

Quoted 6 lines
plugins/api.c +0 -2
     }
 
     return &hwaddr_info;
-}
 #else
-struct qemu_plugin_hwaddr

*qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,

Quoted 10 lines

plugins/api.c struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, · line 275

Quoted 6 lines
plugins/api.c +1 -3
-                                                  uint64_t vaddr)
-{
     return NULL;
-}
 #endif
+}

Hmm I'm not sure about this, surely you want the plugin system to complain early if your plugin is going to use a function that is incorrect for the mode you are running in?

Quoted 3 lines

I merged these two function for couting how much function are exported, so getting the code easier to review, otherwise
function qemu_plugin_get_hwaddr would be exported twice.

Ahh I see now..

Signature · 1 line
Alex Bennée
#14 lore raw

PATCH v3 6/6 plugin: Getting qemu-plugin works under win32.

In reply to Yonggang Luo

We removed the need of .symbols file, so is the configure script, if we one expose a function to qemu-plugin just need prefix the function with QEMU_PLUGIN_EXPORT

---
 Makefile                     |   1 -
 configure                    |  71 -------------
 contrib/plugins/hotblocks.c  |   1 +
 contrib/plugins/hotpages.c   |   1 +
 contrib/plugins/howvec.c     |   1 +
 contrib/plugins/lockstep.c   |   1 +
 include/qemu/qemu-plugin.h   | 197 +++++++++++++++++++++++++++--------
 meson.build                  |   6 +-
 plugins/api.c                |  62 +++++------
 plugins/core.c               |  10 +-
 plugins/loader.c             |  50 ++++++++-
 plugins/meson.build          |  10 +-
 plugins/plugin.h             |   1 +
 plugins/qemu-plugins.symbols |  40 -------
 tests/plugin/bb.c            |   1 +
 tests/plugin/empty.c         |   1 +
 tests/plugin/insn.c          |   1 +
 tests/plugin/mem.c           |   1 +
 18 files changed, 251 insertions(+), 205 deletions(-)
 delete mode 100644 plugins/qemu-plugins.symbols
Makefile +0 -1
index 54fc1a9d10..9981dd5209 100644
@@ -105,7 +105,6 @@ config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
 
 # Force configure to re-run if the API symbols are updated
 ifeq ($(CONFIG_PLUGIN),y)
-config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
 
 .PHONY: plugins
 plugins:
configure +0 -71

83 lines not on this page · raw message

contrib/plugins/hotblocks.c +1 -0
index 37435a3fc7..39e77d2980 100644
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
contrib/plugins/hotpages.c +1 -0
index ecd6c18732..1ae3f44aed 100644
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
contrib/plugins/howvec.c +1 -0
index 3b9a6939f2..db1b4e5780 100644
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
contrib/plugins/lockstep.c +1 -0
index a696673dff..7173b2910d 100644
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <errno.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
include/qemu/qemu-plugin.h +151 -46

369 lines not on this page · raw message

meson.build +5 -1
index 853064e983..3998d1f14a 100644
@@ -243,7 +243,11 @@ endif
 rt = cc.find_library('rt', required: false)
 libdl = not_found
 if 'CONFIG_PLUGIN' in config_host
-  libdl = cc.find_library('dl', required: true)
+  if targetos == 'windows'
+    libdl = declare_dependency(compile_args: [], link_args: [])
+  else
+    libdl = cc.find_library('dl', required: true)
+  endif
 endif
 libiscsi = not_found
 if 'CONFIG_LIBISCSI' in config_host
plugins/api.c +31 -31

224 lines not on this page · raw message

plugins/core.c +5 -5
index 7a79ea4179..a59a0bd25b 100644
@@ -234,7 +234,7 @@ static void plugin_vcpu_for_each(gpointer k, gpointer v, gpointer udata)
     args->cb(args->ctx->id, cpu_index);
 }
 
-void qemu_plugin_vcpu_for_each(qemu_plugin_id_t id,
+QEMU_PLUGIN_EXPORT void qemu_plugin_vcpu_for_each(qemu_plugin_id_t id,
                                qemu_plugin_vcpu_simple_cb_t cb)
 {
     struct plugin_for_each_args args;
@@ -385,19 +385,19 @@ void qemu_plugin_vcpu_resume_cb(CPUState *cpu)
     plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_RESUME);
 }
 
-void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id,
+QEMU_PLUGIN_EXPORT void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id,
                                        qemu_plugin_vcpu_simple_cb_t cb)
 {
     plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_IDLE, cb);
 }
 
-void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id,
+QEMU_PLUGIN_EXPORT void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id,
                                          qemu_plugin_vcpu_simple_cb_t cb)
 {
     plugin_register_cb(id, QEMU_PLUGIN_EV_VCPU_RESUME, cb);
 }
 
-void qemu_plugin_register_flush_cb(qemu_plugin_id_t id,
+QEMU_PLUGIN_EXPORT void qemu_plugin_register_flush_cb(qemu_plugin_id_t id,
                                    qemu_plugin_simple_cb_t cb)
 {
     plugin_register_cb(id, QEMU_PLUGIN_EV_FLUSH, cb);
@@ -464,7 +464,7 @@ void qemu_plugin_atexit_cb(void)
     plugin_cb__udata(QEMU_PLUGIN_EV_ATEXIT);
 }
 
-void qemu_plugin_register_atexit_cb(qemu_plugin_id_t id,
+QEMU_PLUGIN_EXPORT void qemu_plugin_register_atexit_cb(qemu_plugin_id_t id,
                                     qemu_plugin_udata_cb_t cb,
                                     void *udata)
 {
plugins/loader.c +49 -1

108 lines not on this page · raw message

plugins/meson.build +1 -9
index e77723010e..16af5d7ca3 100644
@@ -1,13 +1,5 @@
-if 'CONFIG_HAS_LD_DYNAMIC_LIST' in config_host
-  plugin_ldflags = ['-Wl,--dynamic-list=' + (meson.build_root() / 'qemu-plugins-ld.symbols')]
-elif 'CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST' in config_host
-  plugin_ldflags = ['-Wl,-exported_symbols_list,' + (meson.build_root() / 'qemu-plugins-ld64.symbols')]
-else
-  plugin_ldflags = []
-endif
-
 specific_ss.add(when: 'CONFIG_PLUGIN', if_true: [files(
   'loader.c',
   'core.c',
   'api.c',
-), declare_dependency(link_args: plugin_ldflags)])
+), declare_dependency(link_args: [], compile_args: ['-Wno-missing-prototypes'])])
plugins/plugin.h +1 -0
index 1aa29dcadd..406f246a72 100644
@@ -15,6 +15,7 @@
 #include <gmodule.h>
 
 #define QEMU_PLUGIN_MIN_VERSION 0
+#define QEMU_PLUGIN_VERSION_1 1
 
 /* global state */
 struct qemu_plugin_state {
plugins/qemu-plugins.symbols deleted +0 -40
deleted file mode 100644
index 4bdb381f48..0000000000
@@ -1,40 +0,0 @@
-{
-  qemu_plugin_uninstall;
-  qemu_plugin_reset;
-  qemu_plugin_register_vcpu_init_cb;
-  qemu_plugin_register_vcpu_exit_cb;
-  qemu_plugin_register_vcpu_idle_cb;
-  qemu_plugin_register_vcpu_resume_cb;
-  qemu_plugin_register_vcpu_insn_exec_cb;
-  qemu_plugin_register_vcpu_insn_exec_inline;
-  qemu_plugin_register_vcpu_mem_cb;
-  qemu_plugin_register_vcpu_mem_haddr_cb;
-  qemu_plugin_register_vcpu_mem_inline;
-  qemu_plugin_ram_addr_from_host;
-  qemu_plugin_register_vcpu_tb_trans_cb;
-  qemu_plugin_register_vcpu_tb_exec_cb;
-  qemu_plugin_register_vcpu_tb_exec_inline;
-  qemu_plugin_register_flush_cb;
-  qemu_plugin_register_vcpu_syscall_cb;
-  qemu_plugin_register_vcpu_syscall_ret_cb;
-  qemu_plugin_register_atexit_cb;
-  qemu_plugin_tb_n_insns;
-  qemu_plugin_tb_get_insn;
-  qemu_plugin_tb_vaddr;
-  qemu_plugin_insn_data;
-  qemu_plugin_insn_size;
-  qemu_plugin_insn_vaddr;
-  qemu_plugin_insn_haddr;
-  qemu_plugin_insn_disas;
-  qemu_plugin_mem_size_shift;
-  qemu_plugin_mem_is_sign_extended;
-  qemu_plugin_mem_is_big_endian;
-  qemu_plugin_mem_is_store;
-  qemu_plugin_get_hwaddr;
-  qemu_plugin_hwaddr_is_io;
-  qemu_plugin_hwaddr_to_raddr;
-  qemu_plugin_vcpu_for_each;
-  qemu_plugin_n_vcpus;
-  qemu_plugin_n_max_vcpus;
-  qemu_plugin_outs;
-};
tests/plugin/bb.c +1 -0
index de09bdde4e..cda3fbdde9 100644
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
tests/plugin/empty.c +1 -0
index 8fa6bacd93..0c3adf7aa0 100644
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <stdio.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
tests/plugin/insn.c +1 -0
index a9a6e41237..bf86fdafe6 100644
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
tests/plugin/mem.c +1 -0
index 4725bd851d..f39be9c969 100644
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>
 
 QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
Signature · 1 line
2.28.0.windows.1
#15 lore raw

Re: [PATCH v3 6/6] plugin: Getting qemu-plugin works under win32.

Quoted 133 lines · Yonggang Luo

We removed the need of .symbols file, so is the configure script, if we one expose a function to qemu-plugin just need prefix the function with QEMU_PLUGIN_EXPORT

---
 Makefile                     |   1 -
 configure                    |  71 -------------
 contrib/plugins/hotblocks.c  |   1 +
 contrib/plugins/hotpages.c   |   1 +
 contrib/plugins/howvec.c     |   1 +
 contrib/plugins/lockstep.c   |   1 +
 include/qemu/qemu-plugin.h   | 197 +++++++++++++++++++++++++++--------
 meson.build                  |   6 +-
 plugins/api.c                |  62 +++++------
 plugins/core.c               |  10 +-
 plugins/loader.c             |  50 ++++++++-
 plugins/meson.build          |  10 +-
 plugins/plugin.h             |   1 +
 plugins/qemu-plugins.symbols |  40 -------
 tests/plugin/bb.c            |   1 +
 tests/plugin/empty.c         |   1 +
 tests/plugin/insn.c          |   1 +
 tests/plugin/mem.c           |   1 +
 18 files changed, 251 insertions(+), 205 deletions(-)
 delete mode 100644 plugins/qemu-plugins.symbols
Makefile +0 -1
index 54fc1a9d10..9981dd5209 100644
@@ -105,7 +105,6 @@ config-host.mak: $(SRC_PATH)/configure $(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION
 
 # Force configure to re-run if the API symbols are updated
 ifeq ($(CONFIG_PLUGIN),y)
-config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
 
 .PHONY: plugins
 plugins:
configure +0 -71
index 1c21a73c3b..ea447919fc 100755
@@ -5435,61 +5435,6 @@ if compile_prog "" "" ; then
   atomic64=yes
 fi
 
-#########################################
-# See if --dynamic-list is supported by the linker
-ld_dynamic_list="no"
-if test "$static" = "no" ; then
-    cat > $TMPTXT <<EOF
-{
-  foo;
-};
-EOF
-
-    cat > $TMPC <<EOF
-#include <stdio.h>
-void foo(void);
-
-void foo(void)
-{
-  printf("foo\n");
-}
-
-int main(void)
-{
-  foo();
-  return 0;
-}
-EOF
-
-    if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
-        ld_dynamic_list="yes"
-    fi
-fi
-
-#########################################
-# See if -exported_symbols_list is supported by the linker
-
-ld_exported_symbols_list="no"
-if test "$static" = "no" ; then
-    cat > $TMPTXT <<EOF
-  _foo
-EOF
-
-    if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
-        ld_exported_symbols_list="yes"
-    fi
-fi
-
-if  test "$plugins" = "yes" &&
-    test "$ld_dynamic_list" = "no" &&
-    test "$ld_exported_symbols_list" = "no" ; then
-  error_exit \
-      "Plugin support requires dynamic linking and specifying a set of symbols " \
-      "that are exported to plugins. Unfortunately your linker doesn't " \
-      "support the flag (--dynamic-list or -exported_symbols_list) used " \
-      "for this purpose. You can't build with --static."
-fi
-
 ########################################
 # See if __attribute__((alias)) is supported.
 # This false for Xcode 9, but has been remedied for Xcode 10.
@@ -7074,22 +7019,6 @@ fi
 
 if test "$plugins" = "yes" ; then
     echo "CONFIG_PLUGIN=y" >> $config_host_mak
-    # Copy the export object list to the build dir
-    if test "$ld_dynamic_list" = "yes" ; then
-	echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak
-	ld_symbols=qemu-plugins-ld.symbols
-	cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols
-    elif test "$ld_exported_symbols_list" = "yes" ; then
-	echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak
-	ld64_symbols=qemu-plugins-ld64.symbols
-	echo "# Automatically generated by configure - do not modify" > $ld64_symbols
-	grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \
-	    sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols
-    else
-	error_exit \
-	    "If \$plugins=yes, either \$ld_dynamic_list or " \
-	    "\$ld_exported_symbols_list should have been set to 'yes'."
-    fi
 fi
 
 if test -n "$gdb_bin" ; then
contrib/plugins/hotblocks.c +0 -0
index 37435a3fc7..39e77d2980 100644

contrib/plugins/hotblocks.c line 17

Quoted 5 lines
contrib/plugins/hotblocks.c +1 -0
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>

As mentioned in earlier patch we should be able to just have the tweak in api.c and avoid touching all the plugins themselves.

Quoted 19 lines
contrib/plugins/hotblocks.c +8 -1
-#define QEMU_PLUGIN_VERSION 0
+#define QEMU_PLUGIN_VERSION 1
+
+typedef void *(*qemu_plugin_global_dlsym_t)(void* context, const char *name);
 
 typedef struct {
     /* string describing architecture */
@@ -73,8 +71,23 @@ typedef struct {
             int max_vcpus;
         } system;
     };
+    void *context;
+    qemu_plugin_global_dlsym_t dlsym;
 } qemu_info_t;
 
+/**
+ * qemu_plugin_initialize() - Initialize a plugin before install
+ * @info: a block describing some details about the guest

contrib/plugins/hotblocks.c typedef struct { · line 90

Quoted 10 lines
contrib/plugins/hotblocks.c +10 -0
+ *
+ * All plugins must export this symbol, and in most case using qemu-plugin.h
+ * provided implementation directly.
+ * For plugin provide this function, the QEMU_PLUGIN_VERSION should >= 1
+ *
+ * Note: This function only used to loading qemu's exported functions, nothing
+ * else should doding in this function.
+ */
+QEMU_PLUGIN_EXPORT int qemu_plugin_initialize(const qemu_info_t *info);
+

So this is essentially working around the linker/dlopen stage and manually linking in all the API functions? Does this affect the efficiency of the API calls?

contrib/plugins/hotblocks.c typedef struct {

Quoted 9 lines
contrib/plugins/hotblocks.c +8 -1
-void qemu_plugin_outs(const char *string);
+typedef void (*qemu_plugin_outs_t)(const char *string);
+
+#if !defined(QEMU_PLUGIN_API_IMPLEMENTATION)
+#if defined(QEMU_PLUGIN_IMPLEMENTATION)
+#define QEMU_PLUGIN_EXTERN
+#else
+#define QEMU_PLUGIN_EXTERN extern
+#endif

As mentioned in the earlier patch I want to understand why the extern is required. Could we avoid it with a parameter to the compiler when building plugins?

<snip>

Quoted 100 lines

static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info) {

contrib/plugins/hotblocks.c +46 -1
+    qemu_plugin_initialize_func_t initialize = NULL;
     qemu_plugin_install_func_t install;
     struct qemu_plugin_ctx *ctx;
     gpointer sym;
     int rc;
+    int version = -1;
 
     ctx = qemu_memalign(qemu_dcache_linesize, sizeof(*ctx));
     memset(ctx, 0, sizeof(*ctx));
@@ -184,7 +187,7 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
                      desc->path, g_module_error());
         goto err_symbol;
     } else {
-        int version = *(int *)sym;
+        version = *(int *)sym;
         if (version < QEMU_PLUGIN_MIN_VERSION) {
             error_report("TCG plugin %s requires API version %d, but "
                          "this QEMU supports only a minimum version of %d",
@@ -198,6 +201,21 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
         }
     }
 
+    if (version >= QEMU_PLUGIN_VERSION_1) {
+        /* This version should call to qemu_plugin_initialize first */
+        if (!g_module_symbol(ctx->handle, "qemu_plugin_initialize", &sym)) {
+            error_report("%s: %s", __func__, g_module_error());
+            goto err_symbol;
+        }
+        initialize = (qemu_plugin_initialize_func_t) sym;
+        /* symbol was found; it could be NULL though */
+        if (initialize == NULL) {
+            error_report("%s: %s: qemu_plugin_initialize is NULL",
+                        __func__, desc->path);
+            goto err_symbol;
+        }
+    }
+
     qemu_rec_mutex_lock(&plugin.lock);
 
     /* find an unused random id with &ctx as the seed */
@@ -216,6 +234,16 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
         }
     }
     QTAILQ_INSERT_TAIL(&plugin.ctxs, ctx, entry);
+    if (initialize != NULL) {
+        rc = initialize(info);
+        if (rc) {
+            error_report("%s: qemu_plugin_initialize returned error code %d",
+                        __func__, rc);
+            /* qemu_plugin_initialize only loading function symbols */
+            goto err_symbol;
+        }
+    }
+
     ctx->installing = true;
     rc = install(ctx->id, info, desc->argc, desc->argv);
     ctx->installing = false;
@@ -254,6 +282,17 @@ static void plugin_desc_free(struct qemu_plugin_desc *desc)
     g_free(desc);
 }
 
+static void *qemu_plugin_global_dlsym(void* context, const char *name)
+{
+    GModule *global_handle = context;
+    gpointer sym = NULL;
+    if (!g_module_symbol(global_handle, name, &sym)) {
+        error_report("%s: %s", __func__, g_module_error());
+        return NULL;
+    }
+    return sym;
+}
+
 /**
  * qemu_plugin_load_list - load a list of plugins
  * @head: head of the list of descriptors of the plugins to be loaded
@@ -267,6 +306,7 @@ int qemu_plugin_load_list(QemuPluginList *head)
 {
     struct qemu_plugin_desc *desc, *next;
     g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
+    GModule *global_handle = NULL;
 
     info->target_name = TARGET_NAME;
     info->version.min = QEMU_PLUGIN_MIN_VERSION;
@@ -276,6 +316,12 @@ int qemu_plugin_load_list(QemuPluginList *head)
     info->system_emulation = true;
     info->system.smp_vcpus = ms->smp.cpus;
     info->system.max_vcpus = ms->smp.max_cpus;
+    global_handle = g_module_open(NULL, G_MODULE_BIND_LOCAL);
+    if (global_handle == NULL) {
+        goto err_dlopen;
+    }
+    info->dlsym = qemu_plugin_global_dlsym;
+    info->context = (void*)global_handle;
 #else
     info->system_emulation = false;
 #endif

contrib/plugins/hotblocks.c int qemu_plugin_load_list(QemuPluginList *head) · line 340

Quoted 6 lines
contrib/plugins/hotblocks.c +2 -0
@@ -289,6 +335,8 @@ int qemu_plugin_load_list(QemuPluginList *head)
         }
         QTAILQ_REMOVE(head, desc, entry);
     }
+
+err_dlopen:
     return 0;

This doesn't compile cleanly for both linux-user and softmmu:

Compiling C object libqemu-aarch64-linux-user.fa.p/tcg_tcg-common.c.o ../../plugins/loader.c: In function ‘qemu_plugin_load_list’:
../../plugins/loader.c:339:1: error: label ‘err_dlopen’ defined but not used [-Werror=unused-label]
err_dlopen:
^~~~~~~~~~
../../plugins/loader.c:309:14: error: unused variable ‘global_handle’ [-Werror=unused-variable]

       GModule *global_handle = NULL;
                ^~~~~~~~~~~~~
  At top level:
  ../../plugins/loader.c:285:14: error: ‘qemu_plugin_global_dlsym’ defined but not used [-Werror=unused-function]
   static void *qemu_plugin_global_dlsym(void* context, const char *name)
                ^~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make: *** [Makefile.ninja:6703: libqemu-aarch64-linux-user.fa.p/plugins_loader.c.o] Error 1
make: *** Waiting for unfinished jobs....

Signature · 1 line
Alex Bennée
#16 lore raw

Re: [PATCH v3 6/6] plugin: Getting qemu-plugin works under win32.

Quoted 31 lines · Alex Bennée
Quoted 27 lines · Yonggang Luo

We removed the need of .symbols file, so is the configure script, if we one expose a function to qemu-plugin just need prefix the function with QEMU_PLUGIN_EXPORT

---
 Makefile                     |   1 -
 configure                    |  71 -------------
 contrib/plugins/hotblocks.c  |   1 +
 contrib/plugins/hotpages.c   |   1 +
 contrib/plugins/howvec.c     |   1 +
 contrib/plugins/lockstep.c   |   1 +
 include/qemu/qemu-plugin.h   | 197 +++++++++++++++++++++++++++--------
 meson.build                  |   6 +-
 plugins/api.c                |  62 +++++------
 plugins/core.c               |  10 +-
 plugins/loader.c             |  50 ++++++++-
 plugins/meson.build          |  10 +-
 plugins/plugin.h             |   1 +
 plugins/qemu-plugins.symbols |  40 -------
 tests/plugin/bb.c            |   1 +
 tests/plugin/empty.c         |   1 +
 tests/plugin/insn.c          |   1 +
 tests/plugin/mem.c           |   1 +
 18 files changed, 251 insertions(+), 205 deletions(-)
 delete mode 100644 plugins/qemu-plugins.symbols
Quoted 5 lines

Makefile config-host.mak: $(SRC_PATH)/configure

Quoted 5 lines
Makefile +0 -0
index 54fc1a9d10..9981dd5209 100644
@@ -105,7 +105,6 @@ config-host.mak: $(SRC_PATH)/configure

$(SRC_PATH)/pc-bios $(SRC_PATH)/VERSION

Quoted 57 lines
Quoted 57 lines
Makefile +0 -1
 # Force configure to re-run if the API symbols are updated
 ifeq ($(CONFIG_PLUGIN),y)
-config-host.mak: $(SRC_PATH)/plugins/qemu-plugins.symbols
 
 .PHONY: plugins
 plugins:
configure +0 -42
index 1c21a73c3b..ea447919fc 100755
@@ -5435,61 +5435,6 @@ if compile_prog "" "" ; then
   atomic64=yes
 fi
 
-#########################################
-# See if --dynamic-list is supported by the linker
-ld_dynamic_list="no"
-if test "$static" = "no" ; then
-    cat > $TMPTXT <<EOF
-{
-  foo;
-};
-EOF
-
-    cat > $TMPC <<EOF
-#include <stdio.h>
-void foo(void);
-
-void foo(void)
-{
-  printf("foo\n");
-}
-
-int main(void)
-{
-  foo();
-  return 0;
-}
-EOF
-
-    if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
-        ld_dynamic_list="yes"
-    fi
-fi
-
-#########################################
-# See if -exported_symbols_list is supported by the linker
-
-ld_exported_symbols_list="no"
-if test "$static" = "no" ; then
-    cat > $TMPTXT <<EOF
-  _foo
-EOF
-
-    if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
-        ld_exported_symbols_list="yes"
Quoted 8 lines

configure if compile_prog "" "" ; then

Quoted 8 lines
configure +0 -8
-    fi
-fi
-
-if  test "$plugins" = "yes" &&
-    test "$ld_dynamic_list" = "no" &&
-    test "$ld_exported_symbols_list" = "no" ; then
-  error_exit \
-      "Plugin support requires dynamic linking and specifying a set of

symbols " \

Quoted 1 line

configure if compile_prog "" "" ; then · line 5488

Quoted 1 line
configure +0 -1
-      "that are exported to plugins. Unfortunately your linker doesn't

" \

Quoted 1 line

configure if compile_prog "" "" ; then · line 5489

Quoted 1 line
configure +0 -1
-      "support the flag (--dynamic-list or -exported_symbols_list)

used " \

Quoted 8 lines
Quoted 8 lines
configure +0 -3
-      "for this purpose. You can't build with --static."
-fi
-
 ########################################
 # See if __attribute__((alias)) is supported.
 # This false for Xcode 9, but has been remedied for Xcode 10.
@@ -7074,22 +7019,6 @@ fi
 
Quoted 11 lines

configure fi

Quoted 11 lines
configure +0 -9
 if test "$plugins" = "yes" ; then
     echo "CONFIG_PLUGIN=y" >> $config_host_mak
-    # Copy the export object list to the build dir
-    if test "$ld_dynamic_list" = "yes" ; then
-     echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak
-     ld_symbols=qemu-plugins-ld.symbols
-     cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols
-    elif test "$ld_exported_symbols_list" = "yes" ; then
-     echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak
-     ld64_symbols=qemu-plugins-ld64.symbols
-     echo "# Automatically generated by configure - do not modify" >

$ld64_symbols

Quoted 1 line

configure fi · line 7086

Quoted 1 line
configure +0 -1
-     grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed

's/;//g' | \

Quoted 23 lines
Quoted 14 lines
configure +0 -6
-         sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols
-    else
-     error_exit \
-         "If \$plugins=yes, either \$ld_dynamic_list or " \
-         "\$ld_exported_symbols_list should have been set to 'yes'."
-    fi
 fi
 
 if test -n "$gdb_bin" ; then
contrib/plugins/hotblocks.c +0 -0
index 37435a3fc7..39e77d2980 100644

contrib/plugins/hotblocks.c line 17

Quoted 5 lines
contrib/plugins/hotblocks.c +1 -0
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <glib.h>
 
+#define QEMU_PLUGIN_IMPLEMENTATION
 #include <qemu-plugin.h>

As mentioned in earlier patch we should be able to just have the tweak in api.c and avoid touching all the plugins themselves.

Quoted 1 line
Quoted 4 lines

contrib/plugins/hotblocks.c

Quoted 4 lines
contrib/plugins/hotblocks.c +3 -1
-#define QEMU_PLUGIN_VERSION 0
+#define QEMU_PLUGIN_VERSION 1
+
+typedef void *(*qemu_plugin_global_dlsym_t)(void* context, const char

*name);

Quoted 11 lines
Quoted 11 lines
 typedef struct {
     /* string describing architecture */
contrib/plugins/hotblocks.c +2 -0
@@ -73,8 +71,23 @@ typedef struct {
             int max_vcpus;
         } system;
     };
+    void *context;
+    qemu_plugin_global_dlsym_t dlsym;
 } qemu_info_t;
 
Quoted 5 lines

contrib/plugins/hotblocks.c typedef struct { · line 82

Quoted 5 lines
contrib/plugins/hotblocks.c +5 -0
+/**
+ * qemu_plugin_initialize() - Initialize a plugin before install
+ * @info: a block describing some details about the guest
+ *
+ * All plugins must export this symbol, and in most case using

qemu-plugin.h

Quoted 2 lines

contrib/plugins/hotblocks.c typedef struct { · line 84

Quoted 2 lines
contrib/plugins/hotblocks.c +2 -0
+ * provided implementation directly.
+ * For plugin provide this function, the QEMU_PLUGIN_VERSION should >=

1

Quoted 2 lines

contrib/plugins/hotblocks.c typedef struct { · line 86

Quoted 2 lines
contrib/plugins/hotblocks.c +2 -0
+ *
+ * Note: This function only used to loading qemu's exported functions,

nothing

Quoted 8 lines

contrib/plugins/hotblocks.c typedef struct { · line 90

Quoted 4 lines
contrib/plugins/hotblocks.c +4 -0
+ * else should doding in this function.
+ */
+QEMU_PLUGIN_EXPORT int qemu_plugin_initialize(const qemu_info_t *info);
+

So this is essentially working around the linker/dlopen stage and manually linking in all the API functions? Does this affect the efficiency of the API calls?

Quoted 13 lines

contrib/plugins/hotblocks.c typedef struct {

Quoted 9 lines
contrib/plugins/hotblocks.c +8 -1
-void qemu_plugin_outs(const char *string);
+typedef void (*qemu_plugin_outs_t)(const char *string);
+
+#if !defined(QEMU_PLUGIN_API_IMPLEMENTATION)
+#if defined(QEMU_PLUGIN_IMPLEMENTATION)
+#define QEMU_PLUGIN_EXTERN
+#else
+#define QEMU_PLUGIN_EXTERN extern
+#endif

As mentioned in the earlier patch I want to understand why the extern is required. Could we avoid it with a parameter to the compiler when building plugins?

Hi, I've publisehd with v5 of the patch and explain that,

If we only have a single .c file in a plugin, then define QEMU_PLUGIN_EXTERN to empty is OK, but if we have multiple .c files in a plugin, then we need distinguish the implementation and the deceleration. only the main .c file should define the macro QEMU_PLUGIN_IMPLEMENTATION
other sources are user and should use extern

Quoted 4 lines

<snip>

Quoted 2 lines

static int plugin_load(struct qemu_plugin_desc *desc, const

qemu_info_t *info)

Quoted 11 lines

contrib/plugins/hotblocks.c static int plugin_load(struct qemu_plugin_desc

Quoted 11 lines

{

contrib/plugins/hotblocks.c +2 -0
+    qemu_plugin_initialize_func_t initialize = NULL;
     qemu_plugin_install_func_t install;
     struct qemu_plugin_ctx *ctx;
     gpointer sym;
     int rc;
+    int version = -1;
 
     ctx = qemu_memalign(qemu_dcache_linesize, sizeof(*ctx));
     memset(ctx, 0, sizeof(*ctx));
@@ -184,7 +187,7 @@ static int plugin_load(struct qemu_plugin_desc

*desc, const qemu_info_t *info)

Quoted 8 lines

contrib/plugins/hotblocks.c static int plugin_load(struct qemu_plugin_desc · line 193

Quoted 8 lines
contrib/plugins/hotblocks.c +1 -1
                      desc->path, g_module_error());
         goto err_symbol;
     } else {
-        int version = *(int *)sym;
+        version = *(int *)sym;
         if (version < QEMU_PLUGIN_MIN_VERSION) {
             error_report("TCG plugin %s requires API version %d, but "
                          "this QEMU supports only a minimum version of

%d",

Quoted 1 line

contrib/plugins/hotblocks.c static int plugin_load(struct qemu_plugin_desc

Quoted 1 line
contrib/plugins/hotblocks.c +0 -0
@@ -198,6 +201,21 @@ static int plugin_load(struct qemu_plugin_desc

*desc, const qemu_info_t *info)

Quoted 6 lines

contrib/plugins/hotblocks.c static int plugin_load(struct qemu_plugin_desc · line 206

Quoted 6 lines
contrib/plugins/hotblocks.c +3 -0
         }
     }
 
+    if (version >= QEMU_PLUGIN_VERSION_1) {
+        /* This version should call to qemu_plugin_initialize first */
+        if (!g_module_symbol(ctx->handle, "qemu_plugin_initialize",

&sym)) {

Quoted 14 lines
Quoted 14 lines
contrib/plugins/hotblocks.c +12 -0
+            error_report("%s: %s", __func__, g_module_error());
+            goto err_symbol;
+        }
+        initialize = (qemu_plugin_initialize_func_t) sym;
+        /* symbol was found; it could be NULL though */
+        if (initialize == NULL) {
+            error_report("%s: %s: qemu_plugin_initialize is NULL",
+                        __func__, desc->path);
+            goto err_symbol;
+        }
+    }
+
     qemu_rec_mutex_lock(&plugin.lock);
 
Quoted 2 lines

contrib/plugins/hotblocks.c static int plugin_load(struct qemu_plugin_desc

Quoted 2 lines
contrib/plugins/hotblocks.c +0 -0
     /* find an unused random id with &ctx as the seed */
@@ -216,6 +234,16 @@ static int plugin_load(struct qemu_plugin_desc

*desc, const qemu_info_t *info)

Quoted 7 lines

contrib/plugins/hotblocks.c static int plugin_load(struct qemu_plugin_desc · line 240

Quoted 7 lines
contrib/plugins/hotblocks.c +4 -0
         }
     }
     QTAILQ_INSERT_TAIL(&plugin.ctxs, ctx, entry);
+    if (initialize != NULL) {
+        rc = initialize(info);
+        if (rc) {
+            error_report("%s: qemu_plugin_initialize returned error

code %d",

Quoted 10 lines

contrib/plugins/hotblocks.c static void plugin_desc_free(struct

Quoted 10 lines
contrib/plugins/hotblocks.c +6 -0
+                        __func__, rc);
+            /* qemu_plugin_initialize only loading function symbols */
+            goto err_symbol;
+        }
+    }
+
     ctx->installing = true;
     rc = install(ctx->id, info, desc->argc, desc->argv);
     ctx->installing = false;
@@ -254,6 +282,17 @@ static void plugin_desc_free(struct

qemu_plugin_desc *desc)

Quoted 48 lines
Quoted 39 lines
contrib/plugins/hotblocks.c +18 -0
     g_free(desc);
 }
 
+static void *qemu_plugin_global_dlsym(void* context, const char *name)
+{
+    GModule *global_handle = context;
+    gpointer sym = NULL;
+    if (!g_module_symbol(global_handle, name, &sym)) {
+        error_report("%s: %s", __func__, g_module_error());
+        return NULL;
+    }
+    return sym;
+}
+
 /**
  * qemu_plugin_load_list - load a list of plugins
  * @head: head of the list of descriptors of the plugins to be loaded
@@ -267,6 +306,7 @@ int qemu_plugin_load_list(QemuPluginList *head)
 {
     struct qemu_plugin_desc *desc, *next;
     g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
+    GModule *global_handle = NULL;
 
     info->target_name = TARGET_NAME;
     info->version.min = QEMU_PLUGIN_MIN_VERSION;
@@ -276,6 +316,12 @@ int qemu_plugin_load_list(QemuPluginList *head)
     info->system_emulation = true;
     info->system.smp_vcpus = ms->smp.cpus;
     info->system.max_vcpus = ms->smp.max_cpus;
+    global_handle = g_module_open(NULL, G_MODULE_BIND_LOCAL);
+    if (global_handle == NULL) {
+        goto err_dlopen;
+    }
+    info->dlsym = qemu_plugin_global_dlsym;
+    info->context = (void*)global_handle;
 #else
     info->system_emulation = false;
 #endif

contrib/plugins/hotblocks.c int qemu_plugin_load_list(QemuPluginList *head) · line 340

Quoted 6 lines
contrib/plugins/hotblocks.c +2 -0
@@ -289,6 +335,8 @@ int qemu_plugin_load_list(QemuPluginList *head)
         }
         QTAILQ_REMOVE(head, desc, entry);
     }
+
+err_dlopen:
     return 0;

This doesn't compile cleanly for both linux-user and softmmu:

Quoted 3 lines

Compiling C object libqemu-aarch64-linux-user.fa.p/tcg_tcg-common.c.o ../../plugins/loader.c: In function ‘qemu_plugin_load_list’:
../../plugins/loader.c:339:1: error: label ‘err_dlopen’ defined but not

used [-Werror=unused-label]

Quoted 3 lines
   err_dlopen:
   ^~~~~~~~~~

../../plugins/loader.c:309:14: error: unused variable ‘global_handle’

[-Werror=unused-variable]

Quoted 4 lines
       GModule *global_handle = NULL;
                ^~~~~~~~~~~~~

At top level:
../../plugins/loader.c:285:14: error: ‘qemu_plugin_global_dlsym’

defined but not used [-Werror=unused-function]

Quoted 4 lines

static void *qemu_plugin_global_dlsym(void* context, const char *name)

                ^~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make: *** [Makefile.ninja:6703:

libqemu-aarch64-linux-user.fa.p/plugins_loader.c.o] Error 1

Quoted 4 lines

make: *** Waiting for unfinished jobs....

--
Alex Bennée

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

#17 lore raw
In reply to Yonggang Luo
Quoted 13 lines · Yonggang Luo

V2-V3
Split following patches out

V1-V2
1. Fixes review comments
2. Increase QEMU_PLUGIN_VERSION to 1 for compat QEMU_PLUGIN_VERSION 0
3. Revise the loader to support for version 0 and 1
4. By export function qemu_plugin_initialize in plugin, and call it in loader= , so
we have no need call it in every plugin. And also provide a standard implem=
entation,
anyway, use can also override it.

Quoted 2 lines

Add this feature on msys2/mingw by using glib provided cross-platform dlsym f= unctional.

I've grabbed the first two fixes into plugins/next for now. Aside from fixing the review comments I'd like to have an indication that the proposed change to the API linking doesn't adversely affect the performance of the plugins.

It might be worth enabling a --enable-plugins build for mingw gitlab as Cirrus seems a bit broken at the moment.

Thanks,

Signature · 1 line
Alex Bennée
#18 lore raw

Hi alex, when does plugins/next getting PR

Quoted 37 lines · Alex Bennée
Quoted 8 lines · Yonggang Luo

V2-V3
Split following patches out

V1-V2
1. Fixes review comments
2. Increase QEMU_PLUGIN_VERSION to 1 for compat QEMU_PLUGIN_VERSION 0
3. Revise the loader to support for version 0 and 1
4. By export function qemu_plugin_initialize in plugin, and call it in

loader=

Quoted 2 lines

, so
we have no need call it in every plugin. And also provide a standard

implem=

Quoted 4 lines

entation,
anyway, use can also override it.

Add this feature on msys2/mingw by using glib provided cross-platform

dlsym f=

Quoted 1 line

unctional.

I've grabbed the first two fixes into plugins/next for now. Aside from fixing the review comments I'd like to have an indication that the proposed change to the API linking doesn't adversely affect the performance of the plugins.

It might be worth enabling a --enable-plugins build for mingw gitlab as Cirrus
seems a bit broken at the moment.

Thanks,

--
Alex Bennée

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#19 lore raw
Quoted 1 line · 罗勇刚(Yonggang Luo)

Hi alex, when does plugins/next getting PR

Sorry for the delay. I should be cooking up a pre-PR series this week once the recent icount/io_recompile fix has been tested and reviewed. You can see the current state of the tree here:

https://github.com/stsquad/qemu/tree/plugins/next

I'm afraid I've dropped the ball on your plugin patches... I can't seem to find the v5 series referenced.

Quoted 40 lines · Alex Bennée
Quoted 38 lines
Quoted 8 lines · Yonggang Luo

V2-V3
Split following patches out

V1-V2
1. Fixes review comments
2. Increase QEMU_PLUGIN_VERSION to 1 for compat QEMU_PLUGIN_VERSION 0
3. Revise the loader to support for version 0 and 1
4. By export function qemu_plugin_initialize in plugin, and call it in

loader=

Quoted 2 lines

, so
we have no need call it in every plugin. And also provide a standard

implem=

Quoted 4 lines

entation,
anyway, use can also override it.

Add this feature on msys2/mingw by using glib provided cross-platform

dlsym f=

Quoted 1 line

unctional.

I've grabbed the first two fixes into plugins/next for now. Aside from fixing the review comments I'd like to have an indication that the proposed change to the API linking doesn't adversely affect the performance of the plugins.

It might be worth enabling a --enable-plugins build for mingw gitlab as Cirrus
seems a bit broken at the moment.

Thanks,

--
Alex Bennée

Signature · 1 line
Alex Bennée