All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Samuel Thibault" <samuel.thibault@ens-lyon.org>,
	qemu-block@nongnu.org, "David Hildenbrand" <david@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Peter Lieven" <pl@kamp.de>, "Greg Kurz" <groug@kaod.org>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	qemu-s390x@nongnu.org,
	"Ronnie Sahlberg" <ronniesahlberg@gmail.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>,
	qemu-ppc@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH v4 03/34] modules: generate modinfo.c
Date: Thu, 24 Jun 2021 12:38:05 +0200	[thread overview]
Message-ID: <20210624103836.2382472-4-kraxel@redhat.com> (raw)
In-Reply-To: <20210624103836.2382472-1-kraxel@redhat.com>

Add script to generate C source with a small
database containing the module meta-data.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 scripts/modinfo-generate.py | 84 +++++++++++++++++++++++++++++++++++++
 include/qemu/module.h       | 17 ++++++++
 softmmu/vl.c                |  4 ++
 util/module.c               | 11 +++++
 meson.build                 | 13 +++++-
 5 files changed, 128 insertions(+), 1 deletion(-)
 create mode 100755 scripts/modinfo-generate.py

diff --git a/scripts/modinfo-generate.py b/scripts/modinfo-generate.py
new file mode 100755
index 000000000000..a6d98a6bc4cc
--- /dev/null
+++ b/scripts/modinfo-generate.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+
+def print_array(name, values):
+    if len(values) == 0:
+        return
+    list = ", ".join(values)
+    print("    .%s = ((const char*[]){ %s, NULL })," % (name, list))
+
+def parse_line(line):
+    kind = ""
+    data = ""
+    get_kind = False
+    get_data = False
+    for item in line.split():
+        if item == "MODINFO_START":
+            get_kind = True
+            continue
+        if item.startswith("MODINFO_END"):
+            get_data = False
+            continue
+        if get_kind:
+            kind = item
+            get_kind = False
+            get_data = True
+            continue
+        if get_data:
+            data += " " + item
+            continue
+    return (kind, data)
+
+def generate(name, lines):
+    arch = ""
+    objs = []
+    deps = []
+    opts = []
+    for line in lines:
+        if line.find("MODINFO_START") != -1:
+            (kind, data) = parse_line(line)
+            if kind == 'obj':
+                objs.append(data)
+            elif kind == 'dep':
+                deps.append(data)
+            elif kind == 'opts':
+                opts.append(data)
+            elif kind == 'arch':
+                arch = data;
+            else:
+                print("unknown:", kind)
+                exit(1)
+
+    print("    .name = \"%s\"," % name)
+    if arch != "":
+        print("    .arch = %s," % arch)
+    print_array("objs", objs)
+    print_array("deps", deps)
+    print_array("opts", opts)
+    print("},{");
+
+def print_pre():
+    print("/* generated by scripts/modinfo-generate.py */")
+    print("#include \"qemu/osdep.h\"")
+    print("#include \"qemu/module.h\"")
+    print("const QemuModinfo qemu_modinfo[] = {{")
+
+def print_post():
+    print("    /* end of list */")
+    print("}};")
+
+def main(args):
+    print_pre()
+    for modinfo in args:
+        with open(modinfo) as f:
+            lines = f.readlines()
+        print("    /* %s */" % modinfo)
+        (basename, ext) = os.path.splitext(modinfo)
+        generate(basename, lines)
+    print_post()
+
+if __name__ == "__main__":
+    main(sys.argv[1:])
diff --git a/include/qemu/module.h b/include/qemu/module.h
index 81ef086da023..a98748d501d3 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -98,4 +98,21 @@ void module_load_qom_all(void);
 /* module registers QemuOpts <name> */
 #define module_opts(name) modinfo(opts, name)
 
+/*
+ * module info database
+ *
+ * scripts/modinfo-generate.c will build this using the data collected
+ * by scripts/modinfo-collect.py
+ */
+typedef struct QemuModinfo QemuModinfo;
+struct QemuModinfo {
+    const char *name;
+    const char *arch;
+    const char **objs;
+    const char **deps;
+    const char **opts;
+};
+extern const QemuModinfo qemu_modinfo[];
+void module_init_info(const QemuModinfo *info);
+
 #endif
diff --git a/softmmu/vl.c b/softmmu/vl.c
index feb4d201f30f..e001505d79f7 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2740,6 +2740,10 @@ void qemu_init(int argc, char **argv, char **envp)
     error_init(argv[0]);
     qemu_init_exec_dir(argv[0]);
 
+#ifdef CONFIG_MODULES
+    module_init_info(qemu_modinfo);
+#endif
+
     qemu_init_subsystems();
 
     /* first pass of option parsing */
diff --git a/util/module.c b/util/module.c
index eee8ff2de136..8d3e8275b9f7 100644
--- a/util/module.c
+++ b/util/module.c
@@ -110,6 +110,17 @@ void module_call_init(module_init_type type)
 }
 
 #ifdef CONFIG_MODULES
+
+static const QemuModinfo module_info_stub[] = { {
+    /* end of list */
+} };
+static const QemuModinfo *module_info = module_info_stub;
+
+void module_init_info(const QemuModinfo *info)
+{
+    module_info = info;
+}
+
 static int module_load_file(const char *fname, bool mayfail, bool export_symbols)
 {
     GModule *g_module;
diff --git a/meson.build b/meson.build
index 30ca06c6c2d4..6ae2b9ab9443 100644
--- a/meson.build
+++ b/meson.build
@@ -2022,6 +2022,7 @@ subdir('tests/qtest/fuzz')
 ########################
 
 modinfo_collect = find_program('scripts/modinfo-collect.py')
+modinfo_generate = find_program('scripts/modinfo-generate.py')
 modinfo_files = []
 
 block_mods = []
@@ -2047,7 +2048,6 @@ foreach d, list : modules
                                        output: d + '-' + m + '.modinfo',
                                        input: module_ss.sources(),
                                        capture: true,
-                                       build_by_default: true, # to be removed when added to a target
                                        command: [modinfo_collect, '@INPUT@'])
       endif
     else
@@ -2060,6 +2060,17 @@ foreach d, list : modules
   endforeach
 endforeach
 
+if enable_modules
+  modinfo_src = custom_target('modinfo.c',
+                              output: 'modinfo.c',
+                              input: modinfo_files,
+                              command: [modinfo_generate, '@INPUT@'],
+                              capture: true)
+  modinfo_lib = static_library('modinfo', modinfo_src)
+  modinfo_dep = declare_dependency(link_whole: modinfo_lib)
+  softmmu_ss.add(modinfo_dep)
+endif
+
 nm = find_program('nm')
 undefsym = find_program('scripts/undefsym.py')
 block_syms = custom_target('block.syms', output: 'block.syms',
-- 
2.31.1



  parent reply	other threads:[~2021-06-24 10:40 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24 10:38 [PATCH v4 00/34] modules: add meta-data database Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 01/34] modules: add modinfo macros Gerd Hoffmann
2021-06-24 20:37   ` Eduardo Habkost
2021-07-06 17:07     ` Paolo Bonzini
2021-06-24 10:38 ` [PATCH v4 02/34] modules: collect module meta-data Gerd Hoffmann
2021-06-24 10:38 ` Gerd Hoffmann [this message]
2021-06-24 10:38 ` [PATCH v4 04/34] modules: check if all dependencies can be satisfied Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 05/34] modules: add qxl module annotations Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 06/34] modules: add virtio-gpu " Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 07/34] modules: add chardev " Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 08/34] modules: add audio " Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 09/34] modules: add usb-redir " Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 10/34] modules: add ccid " Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 11/34] modules: add ui " Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 12/34] modules: add s390x " Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 13/34] modules: add block " Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 14/34] modules: use modinfo for dependencies Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 15/34] modules: use modinfo for qom load Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 16/34] modules: use modinfo for qemu opts load Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 17/34] modules: add tracepoints Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 18/34] modules: check arch and block load on mismatch Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 19/34] modules: check arch on qom lookup Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 20/34] modules: target-specific module build infrastructure Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 21/34] modules: add documentation for module sourcesets Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 22/34] modules: add module_obj() note to QOM docs Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 23/34] modules: module.h kerneldoc annotations Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 24/34] modules: hook up modules.h to docs build Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 25/34] accel: autoload modules Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 26/34] accel: add qtest module annotations Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 27/34] accel: build qtest modular Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 28/34] accel: add tcg module annotations Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 29/34] accel: build tcg modular Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 30/34] monitor: allow register hmp commands Gerd Hoffmann
2021-06-24 14:55   ` Dr. David Alan Gilbert
2021-06-24 17:40     ` Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 31/34] usb: drop usb_host_dev_is_scsi_storage hook Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 32/34] monitor/usb: register 'info usbhost' dynamically Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 33/34] usb: build usb-host as module Gerd Hoffmann
2021-06-24 10:38 ` [PATCH v4 34/34] monitor/tcg: move tcg hmp commands to accel/tcg, register them dynamically Gerd Hoffmann
2021-06-24 14:57   ` Dr. David Alan Gilbert
2021-06-24 14:48 ` [PATCH v4 00/34] modules: add meta-data database Jose R. Ziviani
2021-06-24 15:01 ` Dr. David Alan Gilbert
2021-06-24 17:28   ` Gerd Hoffmann
2021-06-24 18:02     ` Dr. David Alan Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210624103836.2382472-4-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=crosa@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=groug@kaod.org \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.