@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -424,7 +424,11 @@ typedef int (*qemu_plugin_n_max_vcpus_t)(void);
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
QEMU_PLUGIN_EXTERN qemu_plugin_uninstall_t qemu_plugin_uninstall;
QEMU_PLUGIN_EXTERN qemu_plugin_reset_t qemu_plugin_reset;
@@ -463,6 +467,8 @@ QEMU_PLUGIN_EXTERN qemu_plugin_n_vcpus_t qemu_plugin_n_vcpus;
QEMU_PLUGIN_EXTERN qemu_plugin_n_max_vcpus_t qemu_plugin_n_max_vcpus;
QEMU_PLUGIN_EXTERN qemu_plugin_outs_t qemu_plugin_outs;
+#if defined(QEMU_PLUGIN_IMPLEMENTATION)
+
QEMU_PLUGIN_EXPORT int qemu_plugin_initialize(const qemu_info_t *info)
{
qemu_plugin_uninstall = info->dlsym(info->context, "qemu_plugin_uninstall");
@@ -504,6 +510,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_initialize(const qemu_info_t *info)
return 0;
}
+#endif
+
#endif /* QEMU_PLUGIN_API_IMPLEMENTATION */
@@ -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"
@@ -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;
@@ -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;
@@ -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;
@@ -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;
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 Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> --- 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 | 8 ++++++++ plugins/core.c | 1 + tests/plugin/bb.c | 1 + tests/plugin/empty.c | 1 + tests/plugin/insn.c | 1 + tests/plugin/mem.c | 1 + 10 files changed, 17 insertions(+)