qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 03/18] modules: add qemu-modinfo utility


From: Gerd Hoffmann
Subject: Re: [PATCH v2 03/18] modules: add qemu-modinfo utility
Date: Tue, 15 Jun 2021 09:56:46 +0200

On Tue, Jun 15, 2021 at 06:49:15AM +0200, Gerd Hoffmann wrote:
>   Hi,
> 
> > Another possibility to eschew .o parsing is to add something like this to
> > the sources
> > 
> > #ifdef QEMU_MODINFO
> > #define MODULE_METADATA(key, value) \
> >    =<>= MODINFO key value
> > #else
> > #define MODULE_METADATA(key, value)
> > #endif
> > 
> > MODULE_METADATA("opts", "spice")
> > 
> > A Python script could parse compile_commands.json, add -E -DQEMU_MODINFO to
> > the command-line option, and look in the output for the metadata.
> 
> Hmm, worth trying, although I guess it would be easier to code this up
> straight in meson.build and pull the information you need out of the
> source set, especially as you'll know then which source files are
> compiled into which module.

Hmm, looks like I actually need both.  Seems there is no easy way to get
the cflags out of a source_set to construct a cpp command line.  Pulling
this out of compile_commands.json with jq works though.

With the patch below I get nice ${module}.modinfo files with the
metadata, now I only need a (probably python) script to collect
them and create a modinfo.c which we can link into qemu.

take care,
  Gerd

>From 3edc033935d2dd4ec607ac6395548a327151ad06 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Tue, 15 Jun 2021 09:23:52 +0200
Subject: [PATCH] try -DQEMU_MODINFO

---
 include/qemu/module.h | 22 ++++++----------------
 meson.build           |  7 +++++++
 scripts/modinfo.sh    |  8 ++++++++
 3 files changed, 21 insertions(+), 16 deletions(-)
 create mode 100644 scripts/modinfo.sh

diff --git a/include/qemu/module.h b/include/qemu/module.h
index 7825f6d8c847..5acfa423dc4f 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -74,22 +74,12 @@ void module_load_qom_one(const char *type);
 void module_load_qom_all(void);
 void module_allow_arch(const char *arch);
 
-/*
- * macros to store module metadata in a .modinfo section.
- * qemu-modinfo utility will collect the metadata.
- *
- * Use "objdump -t -s -j .modinfo ${module}.so" to inspect.
- */
-
-#define ___PASTE(a, b) a##b
-#define __PASTE(a, b) ___PASTE(a, b)
-
-#define modinfo(kind, value)                             \
-    static const char __PASTE(kind, __LINE__)[]          \
-        __attribute__((__used__))                        \
-        __attribute__((section(".modinfo")))             \
-        __attribute__((aligned(1)))                      \
-        = stringify(kind) "=" value
+#ifdef QEMU_MODINFO
+# define modinfo(kind, value) \
+    MODINFO_START kind value MODINFO_END
+#else
+# define modinfo(kind, value)
+#endif
 
 #define module_obj(name) modinfo(obj, name)
 #define module_dep(name) modinfo(dep, name)
diff --git a/meson.build b/meson.build
index 46ebc07dbb67..d8661755adf9 100644
--- a/meson.build
+++ b/meson.build
@@ -2050,12 +2050,19 @@ target_modules += { 'accel' : { 'qtest': 
qtest_module_ss,
 
 block_mods = []
 softmmu_mods = []
+modinfo = find_program('scripts/modinfo.sh')
 foreach d, list : modules
   foreach m, module_ss : list
     if enable_modules and targetos != 'windows'
       module_ss = module_ss.apply(config_all, strict: false)
       sl = static_library(d + '-' + m, [genh, module_ss.sources()],
                           dependencies: [modulecommon, 
module_ss.dependencies()], pic: true)
+      custom_target(d + '-' + m + '.modinfo',
+                    output: d + '-' + m + '.modinfo',
+                    input: module_ss.sources(),
+                    build_by_default: true, # to be removed when added to a 
target
+                    capture: true,
+                    command: [modinfo, '@INPUT@'])
       if d == 'block'
         block_mods += sl
       else
diff --git a/scripts/modinfo.sh b/scripts/modinfo.sh
new file mode 100644
index 000000000000..8f4495d4523d
--- /dev/null
+++ b/scripts/modinfo.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+for input in "$@"; do
+    command=$(jq  -r ".[] | select(.file == \"$input\") | .command " 
compile_commands.json)
+    command="${command%% -M*}"
+    command="$command -DQEMU_MODINFO -E $input"
+    $command
+done | grep MODINFO
+exit 0
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]