linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [4/6] modpost: add support for generating namespace dependencies.
@ 2018-07-16 12:21 Martijn Coenen
  0 siblings, 0 replies; 2+ messages in thread
From: Martijn Coenen @ 2018-07-16 12:21 UTC (permalink / raw)
  To: linux-kernel
  Cc: Martijn Coenen, Masahiro Yamada, Michal Marek, Geert Uytterhoeven,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Alan Stern,
	Greg Kroah-Hartman, Oliver Neukum, Arnd Bergmann, Jessica Yu,
	Stephen Boyd, Philippe Ombredanne, Kate Stewart, Sam Ravnborg,
	linux-kbuild, linux-m68k, linux-usb, usb-storage, linux-scsi,
	linux-arch, maco, sspatil, malchev, joelaf

This patch adds an option to modpost to generate a .ns_deps file per
module, containing the namespace depedencies for that module.

This file can subsequently be used by other tools to automatically add
newly introduced namespaces to the modules that require them, saving a
lot of manual work.

Signed-off-by: Martijn Coenen <maco@android.com>
---
 scripts/mod/modpost.c | 58 +++++++++++++++++++++++++++++++++++++++----
 scripts/mod/modpost.h |  2 ++
 2 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index a56a8461a96a..be33d60d5527 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -39,6 +39,8 @@ static int sec_mismatch_verbose = 1;
 static int sec_mismatch_fatal = 0;
 /* ignore missing files */
 static int ignore_missing_files;
+/* Write namespace dependencies */
+static int write_ns_deps;
 
 enum export {
 	export_plain,      export_unused,     export_gpl,
@@ -2151,10 +2153,15 @@ static void check_exports(struct module *mod)
 		else
 			basename = mod->name;
 
-		if (exp->ns && !module_imports_namespace(mod, exp->ns)) {
-			warn("module %s uses symbol %s from namespace %s, "
-			     "but does not import it.\n",
-			     basename, exp->name, exp->ns);
+		if (exp->ns) {
+			add_namespace(&mod->required_namespaces, exp->ns);
+
+			if (!write_ns_deps &&
+			    !module_imports_namespace(mod, exp->ns)) {
+				warn("module %s uses symbol %s from namespace "
+				     "%s, but does not import it.\n",
+				     basename, exp->name, exp->ns);
+			}
 		}
 
 		if (!mod->gpl_compatible)
@@ -2457,6 +2464,38 @@ static void write_dump(const char *fname)
 	free(buf.p);
 }
 
+static void write_ns_deps_files(void)
+{
+	struct module *mod;
+	struct namespace_list *ns;
+	struct buffer ns_deps_buf = { };
+
+	for (mod = modules; mod; mod = mod->next) {
+		char fname[PATH_MAX];
+		const char *basename;
+
+		if (mod->skip)
+			continue;
+
+		ns_deps_buf.pos = 0;
+
+		for (ns = mod->required_namespaces; ns; ns = ns->next)
+			buf_printf(&ns_deps_buf, "%s\n", ns->namespace);
+
+		if (ns_deps_buf.pos == 0)
+			continue;
+
+		basename = strrchr(mod->name, '/');
+		if (basename)
+			basename++;
+		else
+			basename = mod->name;
+
+		sprintf(fname, ".tmp_versions/%s.ns_deps", basename);
+		write_if_changed(&ns_deps_buf, fname);
+	}
+}
+
 struct ext_sym_list {
 	struct ext_sym_list *next;
 	const char *file;
@@ -2473,7 +2512,7 @@ int main(int argc, char **argv)
 	struct ext_sym_list *extsym_iter;
 	struct ext_sym_list *extsym_start = NULL;
 
-	while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) {
+	while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:Ed")) != -1) {
 		switch (opt) {
 		case 'i':
 			kernel_read = optarg;
@@ -2517,6 +2556,9 @@ int main(int argc, char **argv)
 		case 'E':
 			sec_mismatch_fatal = 1;
 			break;
+		case 'd':
+			write_ns_deps = 1;
+			break;
 		default:
 			exit(1);
 		}
@@ -2545,6 +2587,12 @@ int main(int argc, char **argv)
 		check_exports(mod);
 	}
 
+	if (write_ns_deps) {
+		/* Just write namespace dependencies and exit */
+		write_ns_deps_files();
+		return 0;
+	}
+
 	err = 0;
 
 	for (mod = modules; mod; mod = mod->next) {
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 9626bf3e7424..92a926d375d2 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -126,6 +126,8 @@ struct module {
 	struct buffer dev_table_buf;
 	char	     srcversion[25];
 	int is_dot_o;
+	// Required namespace dependencies
+	struct namespace_list *required_namespaces;
 	// Actual imported namespaces
 	struct namespace_list *imported_namespaces;
 };

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [4/6] modpost: add support for generating namespace dependencies.
@ 2018-07-23  6:49 Jessica Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Jessica Yu @ 2018-07-23  6:49 UTC (permalink / raw)
  To: Martijn Coenen
  Cc: linux-kernel, Masahiro Yamada, Michal Marek, Geert Uytterhoeven,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, x86, Alan Stern,
	Greg Kroah-Hartman, Oliver Neukum, Arnd Bergmann, Stephen Boyd,
	Philippe Ombredanne, Kate Stewart, Sam Ravnborg, linux-kbuild,
	linux-m68k, linux-usb, usb-storage, linux-scsi, linux-arch, maco,
	sspatil, malchev, joelaf

+++ Martijn Coenen [16/07/18 14:21 +0200]:
>This patch adds an option to modpost to generate a .ns_deps file per
>module, containing the namespace depedencies for that module.
>
>This file can subsequently be used by other tools to automatically add
>newly introduced namespaces to the modules that require them, saving a
>lot of manual work.
>
>Signed-off-by: Martijn Coenen <maco@android.com>

Regarding modpost, I think it may also be helpful to additionally
output the namespace an exported symbol belongs to (if any) in the
Module.symvers file.

>---
> scripts/mod/modpost.c | 58 +++++++++++++++++++++++++++++++++++++++----
> scripts/mod/modpost.h |  2 ++
> 2 files changed, 55 insertions(+), 5 deletions(-)
>
>diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
>index a56a8461a96a..be33d60d5527 100644
>--- a/scripts/mod/modpost.c
>+++ b/scripts/mod/modpost.c
>@@ -39,6 +39,8 @@ static int sec_mismatch_verbose = 1;
> static int sec_mismatch_fatal = 0;
> /* ignore missing files */
> static int ignore_missing_files;
>+/* Write namespace dependencies */
>+static int write_ns_deps;
>
> enum export {
> 	export_plain,      export_unused,     export_gpl,
>@@ -2151,10 +2153,15 @@ static void check_exports(struct module *mod)
> 		else
> 			basename = mod->name;
>
>-		if (exp->ns && !module_imports_namespace(mod, exp->ns)) {
>-			warn("module %s uses symbol %s from namespace %s, "
>-			     "but does not import it.\n",
>-			     basename, exp->name, exp->ns);
>+		if (exp->ns) {
>+			add_namespace(&mod->required_namespaces, exp->ns);
>+
>+			if (!write_ns_deps &&
>+			    !module_imports_namespace(mod, exp->ns)) {
>+				warn("module %s uses symbol %s from namespace "
>+				     "%s, but does not import it.\n",
>+				     basename, exp->name, exp->ns);
>+			}
> 		}
>
> 		if (!mod->gpl_compatible)
>@@ -2457,6 +2464,38 @@ static void write_dump(const char *fname)
> 	free(buf.p);
> }
>
>+static void write_ns_deps_files(void)
>+{
>+	struct module *mod;
>+	struct namespace_list *ns;
>+	struct buffer ns_deps_buf = { };
>+
>+	for (mod = modules; mod; mod = mod->next) {
>+		char fname[PATH_MAX];
>+		const char *basename;
>+
>+		if (mod->skip)
>+			continue;
>+
>+		ns_deps_buf.pos = 0;
>+
>+		for (ns = mod->required_namespaces; ns; ns = ns->next)
>+			buf_printf(&ns_deps_buf, "%s\n", ns->namespace);
>+
>+		if (ns_deps_buf.pos == 0)
>+			continue;
>+
>+		basename = strrchr(mod->name, '/');
>+		if (basename)
>+			basename++;
>+		else
>+			basename = mod->name;
>+
>+		sprintf(fname, ".tmp_versions/%s.ns_deps", basename);
>+		write_if_changed(&ns_deps_buf, fname);
>+	}
>+}
>+
> struct ext_sym_list {
> 	struct ext_sym_list *next;
> 	const char *file;
>@@ -2473,7 +2512,7 @@ int main(int argc, char **argv)
> 	struct ext_sym_list *extsym_iter;
> 	struct ext_sym_list *extsym_start = NULL;
>
>-	while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) {
>+	while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:Ed")) != -1) {
> 		switch (opt) {
> 		case 'i':
> 			kernel_read = optarg;
>@@ -2517,6 +2556,9 @@ int main(int argc, char **argv)
> 		case 'E':
> 			sec_mismatch_fatal = 1;
> 			break;
>+		case 'd':
>+			write_ns_deps = 1;
>+			break;
> 		default:
> 			exit(1);
> 		}
>@@ -2545,6 +2587,12 @@ int main(int argc, char **argv)
> 		check_exports(mod);
> 	}
>
>+	if (write_ns_deps) {
>+		/* Just write namespace dependencies and exit */
>+		write_ns_deps_files();
>+		return 0;
>+	}
>+
> 	err = 0;
>
> 	for (mod = modules; mod; mod = mod->next) {
>diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
>index 9626bf3e7424..92a926d375d2 100644
>--- a/scripts/mod/modpost.h
>+++ b/scripts/mod/modpost.h
>@@ -126,6 +126,8 @@ struct module {
> 	struct buffer dev_table_buf;
> 	char	     srcversion[25];
> 	int is_dot_o;
>+	// Required namespace dependencies
>+	struct namespace_list *required_namespaces;
> 	// Actual imported namespaces
> 	struct namespace_list *imported_namespaces;
> };
>-- 
>2.18.0.203.gfac676dfb9-goog
>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-23  6:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-16 12:21 [4/6] modpost: add support for generating namespace dependencies Martijn Coenen
  -- strict thread matches above, loose matches on Subject: below --
2018-07-23  6:49 Jessica Yu

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).