linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cristina Moraru <cristina.moraru09@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: mcgrof@kernel.org, teg@jklm.no, kay@vrfy.org,
	rusty@rustcorp.com.au, akpm@linux-foundation.org,
	Cristina Moraru <cristina.moraru09@gmail.com>
Subject: [RFC PATCH 3/3] Add dynamic pegging of Kconfig symbol
Date: Sun, 31 Jul 2016 17:33:52 +0200	[thread overview]
Message-ID: <1469979232-15531-4-git-send-email-cristina.moraru09@gmail.com> (raw)
In-Reply-To: <1469979232-15531-1-git-send-email-cristina.moraru09@gmail.com>

Update modpost to add dynamic pegging of CONFIG_* symbol
from file ./scripts/mod/Module.ksymb into kconfig_symbol
attribute of struct module. This information will be
further exposed in userspace for extracting build options
for the required modules.

Note: this patch is part of a proof of concept and does
not represent the final version.

This patch is part of a research project within
Google Summer of Code of porting 'make localmodconfig'
for backported drivers.

Signed-off-by: Cristina Moraru <cristina.moraru09@gmail.com>
---
 scripts/mod/modpost.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 scripts/mod/modpost.h |  1 +
 2 files changed, 48 insertions(+)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 48958d3..d80c062 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -42,6 +42,8 @@ static int sec_mismatch_fatal = 0;
 /* ignore missing files */
 static int ignore_missing_files;
 
+#define MOD_KSYMB_FILENAME "scripts/mod/Module.ksymb"
+
 enum export {
 	export_plain,      export_unused,     export_gpl,
 	export_unused_gpl, export_gpl_future, export_unknown
@@ -2245,6 +2247,50 @@ static void add_srcversion(struct buffer *b, struct module *mod)
 	}
 }
 
+static void get_kconfig_symbol(struct module *mod) {
+
+	unsigned long size, pos = 0;
+	void *file = grab_file(MOD_KSYMB_FILENAME, &size);
+	char *line, *short_name;
+
+	if (!file)
+		return;
+
+	short_name = strrchr(mod->name, '/');
+	short_name++;
+
+	while ((line = get_next_line(&pos, file, size))) {
+		char *modname, *kconfig_symbol, *p;
+
+		modname = line;
+		if (!(p = strchr(line, ' ')))
+			goto fail;
+		*p++ = '\0';
+		if (!strcmp(short_name, modname)) {
+			kconfig_symbol = p;
+			if ((p = strchr(kconfig_symbol, ' ')))
+				*p = '\0';
+			strcpy(mod->kconfig_symbol, kconfig_symbol);
+			break;
+		}
+	}
+	release_file(file, size);
+	return;
+fail:
+	release_file(file, size);
+	fatal("parse error in Module.ksymb file\n");
+}
+
+static void add_kconfig_symbol(struct buffer *b, struct module *mod)
+{
+	get_kconfig_symbol(mod);
+	if (mod->kconfig_symbol[0]) {
+		buf_printf(b, "\n");
+		buf_printf(b, "MODULE_INFO(kconfig_symbol, \"%s\");\n",
+			   mod->kconfig_symbol);
+	}
+}
+
 static void write_if_changed(struct buffer *b, const char *fname)
 {
 	char *tmp;
@@ -2478,6 +2524,7 @@ int main(int argc, char **argv)
 		add_depends(&buf, mod, modules);
 		add_moddevtable(&buf, mod);
 		add_srcversion(&buf, mod);
+		add_kconfig_symbol(&buf, mod);
 
 		sprintf(fname, "%s.mod.c", mod->name);
 		write_if_changed(&buf, fname);
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 6a5e151..1ba48b1 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -119,6 +119,7 @@ struct module {
 	int has_cleanup;
 	struct buffer dev_table_buf;
 	char	     srcversion[25];
+	char	     kconfig_symbol[50];
 	int is_dot_o;
 };
 
-- 
2.7.4

  parent reply	other threads:[~2016-07-31 15:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-31 15:33 [RFC PATCH 0/3] Add kconfig symbol as module attribute Cristina Moraru
2016-07-31 15:33 ` [RFC PATCH 1/3] Add kconfig_symbol attribute to struct module Cristina Moraru
2016-07-31 15:33 ` [RFC PATCH 2/3] Add generation of Module.ksymb file in streamline_config.pl Cristina Moraru
2016-08-08 19:15   ` Luis R. Rodriguez
2016-08-08 20:32     ` Julia Lawall
2016-08-08 21:54       ` Luis R. Rodriguez
2016-08-09  6:54     ` Geert Uytterhoeven
2016-07-31 15:33 ` Cristina Moraru [this message]
2016-08-08 20:05   ` [RFC PATCH 3/3] Add dynamic pegging of Kconfig symbol Luis R. Rodriguez
2016-08-08 17:25 ` [RFC PATCH 0/3] Add kconfig symbol as module attribute Luis R. Rodriguez

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=1469979232-15531-4-git-send-email-cristina.moraru09@gmail.com \
    --to=cristina.moraru09@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=teg@jklm.no \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).