linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] modprobe: add --show-exports
@ 2018-11-12 15:49 Yauheni Kaliuta
  2018-11-12 23:15 ` Lucas De Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Yauheni Kaliuta @ 2018-11-12 15:49 UTC (permalink / raw)
  To: linux-modules; +Cc: ykaliuta, Lucas De Marchi

modprobe has --show-modversions switch, which dumps symbols with
their modversion crcs from the __versions sections.

At the moment the section contains information for the dependency
symbols only, while exported symbols add to symtab entries with
__crc_ prefix (the format may differ, see 1e48901166ef libkmod-elf:
resolve CRC if module is built with MODULE_REL_CRCS).

The patch makes it to show exported symbols as well.

The function is basically cut'n'paste of show_modversions(),
but 'version' family replaced with 'symbol' one.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/modprobe.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tools/modprobe.c b/tools/modprobe.c
index 43605ccaf0f0..ca161d09940c 100644
--- a/tools/modprobe.c
+++ b/tools/modprobe.c
@@ -76,6 +76,8 @@ static const struct option cmdopts[] = {
 	{"show-config", no_argument, 0, 'c'},
 	{"show-modversions", no_argument, 0, 4},
 	{"dump-modversions", no_argument, 0, 4},
+	{"show-exports", no_argument, 0, 6},
+	{"dump-exports", no_argument, 0, 6},
 
 	{"dry-run", no_argument, 0, 'n'},
 	{"show", no_argument, 0, 'n'},
@@ -124,6 +126,8 @@ static void help(void)
 		"\t-c, --show-config           Same as --showconfig\n"
 		"\t    --show-modversions      Dump module symbol version and exit\n"
 		"\t    --dump-modversions      Same as --show-modversions\n"
+		"\t    --show-exports          Dump module exported symbol versions and exit\n"
+		"\t    --dump-exports          Same as --show-exports\n"
 		"\n"
 		"General Options:\n"
 		"\t-n, --dry-run               Do not execute operations, just print out\n"
@@ -232,6 +236,34 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename)
 	return 0;
 }
 
+static int show_exports(struct kmod_ctx *ctx, const char *filename)
+{
+	struct kmod_list *l, *list = NULL;
+	struct kmod_module *mod;
+	int err = kmod_module_new_from_path(ctx, filename, &mod);
+	if (err < 0) {
+		LOG("Module %s not found.\n", filename);
+		return err;
+	}
+
+	err = kmod_module_get_symbols(mod, &list);
+	if (err < 0) {
+		LOG("could not get symbols of %s: %s\n",
+			filename, strerror(-err));
+		kmod_module_unref(mod);
+		return err;
+	}
+
+	kmod_list_foreach(l, list) {
+		const char *symbol = kmod_module_symbol_get_symbol(l);
+		uint64_t crc = kmod_module_symbol_get_crc(l);
+		printf("0x%08"PRIx64"\t%s\n", crc, symbol);
+	}
+	kmod_module_symbols_free_list(list);
+	kmod_module_unref(mod);
+	return 0;
+}
+
 static int command_do(struct kmod_module *module, const char *type,
 				const char *command, const char *cmdline_opts)
 {
@@ -727,6 +759,7 @@ static int do_modprobe(int argc, char **orig_argv)
 	int do_remove = 0;
 	int do_show_config = 0;
 	int do_show_modversions = 0;
+	int do_show_exports = 0;
 	int err;
 
 	argv = prepend_options_from_env(&argc, orig_argv);
@@ -783,6 +816,9 @@ static int do_modprobe(int argc, char **orig_argv)
 		case 4:
 			do_show_modversions = 1;
 			break;
+		case 6:
+			do_show_exports = 1;
+			break;
 		case 'n':
 			dry_run = 1;
 			break;
@@ -886,6 +922,8 @@ static int do_modprobe(int argc, char **orig_argv)
 		err = show_config(ctx);
 	else if (do_show_modversions)
 		err = show_modversions(ctx, args[0]);
+	else if (do_show_exports)
+		err = show_exports(ctx, args[0]);
 	else if (do_remove)
 		err = rmmod_all(ctx, args, nargs);
 	else if (use_all)
-- 
2.19.1


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

* Re: [PATCH v2] modprobe: add --show-exports
  2018-11-12 15:49 [PATCH v2] modprobe: add --show-exports Yauheni Kaliuta
@ 2018-11-12 23:15 ` Lucas De Marchi
  2018-11-13  9:00   ` [PATCH v3] " Yauheni Kaliuta
  0 siblings, 1 reply; 4+ messages in thread
From: Lucas De Marchi @ 2018-11-12 23:15 UTC (permalink / raw)
  To: Yauheni Kaliuta; +Cc: linux-modules, ykaliuta, Lucas De Marchi

On Mon, Nov 12, 2018 at 7:48 AM Yauheni Kaliuta
<yauheni.kaliuta@redhat.com> wrote:
>
> modprobe has --show-modversions switch, which dumps symbols with
> their modversion crcs from the __versions sections.
>
> At the moment the section contains information for the dependency
> symbols only, while exported symbols add to symtab entries with
> __crc_ prefix (the format may differ, see 1e48901166ef libkmod-elf:
> resolve CRC if module is built with MODULE_REL_CRCS).
>
> The patch makes it to show exported symbols as well.
>
> The function is basically cut'n'paste of show_modversions(),
> but 'version' family replaced with 'symbol' one.
>
> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
> ---
>  tools/modprobe.c | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
>
> diff --git a/tools/modprobe.c b/tools/modprobe.c
> index 43605ccaf0f0..ca161d09940c 100644
> --- a/tools/modprobe.c
> +++ b/tools/modprobe.c
> @@ -76,6 +76,8 @@ static const struct option cmdopts[] = {
>         {"show-config", no_argument, 0, 'c'},
>         {"show-modversions", no_argument, 0, 4},
>         {"dump-modversions", no_argument, 0, 4},
> +       {"show-exports", no_argument, 0, 6},
> +       {"dump-exports", no_argument, 0, 6},
>
>         {"dry-run", no_argument, 0, 'n'},
>         {"show", no_argument, 0, 'n'},
> @@ -124,6 +126,8 @@ static void help(void)
>                 "\t-c, --show-config           Same as --showconfig\n"
>                 "\t    --show-modversions      Dump module symbol version and exit\n"
>                 "\t    --dump-modversions      Same as --show-modversions\n"
> +               "\t    --show-exports          Dump module exported symbol versions and exit\n"
> +               "\t    --dump-exports          Same as --show-exports\n"

all the others are show-*. The dump-* and show* should be considered
aliases for compatibility. So I don't think we need that on a new one.

Lucas De Marchi

>                 "\n"
>                 "General Options:\n"
>                 "\t-n, --dry-run               Do not execute operations, just print out\n"
> @@ -232,6 +236,34 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename)
>         return 0;
>  }
>
> +static int show_exports(struct kmod_ctx *ctx, const char *filename)
> +{
> +       struct kmod_list *l, *list = NULL;
> +       struct kmod_module *mod;
> +       int err = kmod_module_new_from_path(ctx, filename, &mod);
> +       if (err < 0) {
> +               LOG("Module %s not found.\n", filename);
> +               return err;
> +       }
> +
> +       err = kmod_module_get_symbols(mod, &list);
> +       if (err < 0) {
> +               LOG("could not get symbols of %s: %s\n",
> +                       filename, strerror(-err));
> +               kmod_module_unref(mod);
> +               return err;
> +       }
> +
> +       kmod_list_foreach(l, list) {
> +               const char *symbol = kmod_module_symbol_get_symbol(l);
> +               uint64_t crc = kmod_module_symbol_get_crc(l);
> +               printf("0x%08"PRIx64"\t%s\n", crc, symbol);
> +       }
> +       kmod_module_symbols_free_list(list);
> +       kmod_module_unref(mod);
> +       return 0;
> +}
> +
>  static int command_do(struct kmod_module *module, const char *type,
>                                 const char *command, const char *cmdline_opts)
>  {
> @@ -727,6 +759,7 @@ static int do_modprobe(int argc, char **orig_argv)
>         int do_remove = 0;
>         int do_show_config = 0;
>         int do_show_modversions = 0;
> +       int do_show_exports = 0;
>         int err;
>
>         argv = prepend_options_from_env(&argc, orig_argv);
> @@ -783,6 +816,9 @@ static int do_modprobe(int argc, char **orig_argv)
>                 case 4:
>                         do_show_modversions = 1;
>                         break;
> +               case 6:
> +                       do_show_exports = 1;
> +                       break;
>                 case 'n':
>                         dry_run = 1;
>                         break;
> @@ -886,6 +922,8 @@ static int do_modprobe(int argc, char **orig_argv)
>                 err = show_config(ctx);
>         else if (do_show_modversions)
>                 err = show_modversions(ctx, args[0]);
> +       else if (do_show_exports)
> +               err = show_exports(ctx, args[0]);
>         else if (do_remove)
>                 err = rmmod_all(ctx, args, nargs);
>         else if (use_all)
> --
> 2.19.1
>

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

* [PATCH v3] modprobe: add --show-exports
  2018-11-12 23:15 ` Lucas De Marchi
@ 2018-11-13  9:00   ` Yauheni Kaliuta
  2018-11-13 23:05     ` Lucas De Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Yauheni Kaliuta @ 2018-11-13  9:00 UTC (permalink / raw)
  To: linux-modules; +Cc: ykaliuta, Lucas De Marchi

modprobe has --show-modversions switch, which dumps symbols with
their modversion crcs from the __versions sections.

At the moment the section contains information for the dependency
symbols only, while exported symbols add to symtab entries with
__crc_ prefix (the format may differ, see 1e48901166ef libkmod-elf:
resolve CRC if module is built with MODULE_REL_CRCS).

The patch makes it to show exported symbols as well.

The function is basically cut'n'paste of show_modversions(),
but 'version' family replaced with 'symbol' one.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/modprobe.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
---
Changelog:

v2 -> v3:

- remove --dump-exports
- amend help string to be like --show-depends

v1 -> v2:

- do not abstract show functions, because it requires API change

diff --git a/tools/modprobe.c b/tools/modprobe.c
index 43605ccaf0f0..a9e2331567af 100644
--- a/tools/modprobe.c
+++ b/tools/modprobe.c
@@ -76,6 +76,7 @@ static const struct option cmdopts[] = {
 	{"show-config", no_argument, 0, 'c'},
 	{"show-modversions", no_argument, 0, 4},
 	{"dump-modversions", no_argument, 0, 4},
+	{"show-exports", no_argument, 0, 6},
 
 	{"dry-run", no_argument, 0, 'n'},
 	{"show", no_argument, 0, 'n'},
@@ -124,6 +125,7 @@ static void help(void)
 		"\t-c, --show-config           Same as --showconfig\n"
 		"\t    --show-modversions      Dump module symbol version and exit\n"
 		"\t    --dump-modversions      Same as --show-modversions\n"
+		"\t    --show-exports          Only print module exported symbol versions and exit\n"
 		"\n"
 		"General Options:\n"
 		"\t-n, --dry-run               Do not execute operations, just print out\n"
@@ -232,6 +234,34 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename)
 	return 0;
 }
 
+static int show_exports(struct kmod_ctx *ctx, const char *filename)
+{
+	struct kmod_list *l, *list = NULL;
+	struct kmod_module *mod;
+	int err = kmod_module_new_from_path(ctx, filename, &mod);
+	if (err < 0) {
+		LOG("Module %s not found.\n", filename);
+		return err;
+	}
+
+	err = kmod_module_get_symbols(mod, &list);
+	if (err < 0) {
+		LOG("could not get symbols of %s: %s\n",
+			filename, strerror(-err));
+		kmod_module_unref(mod);
+		return err;
+	}
+
+	kmod_list_foreach(l, list) {
+		const char *symbol = kmod_module_symbol_get_symbol(l);
+		uint64_t crc = kmod_module_symbol_get_crc(l);
+		printf("0x%08"PRIx64"\t%s\n", crc, symbol);
+	}
+	kmod_module_symbols_free_list(list);
+	kmod_module_unref(mod);
+	return 0;
+}
+
 static int command_do(struct kmod_module *module, const char *type,
 				const char *command, const char *cmdline_opts)
 {
@@ -727,6 +757,7 @@ static int do_modprobe(int argc, char **orig_argv)
 	int do_remove = 0;
 	int do_show_config = 0;
 	int do_show_modversions = 0;
+	int do_show_exports = 0;
 	int err;
 
 	argv = prepend_options_from_env(&argc, orig_argv);
@@ -783,6 +814,9 @@ static int do_modprobe(int argc, char **orig_argv)
 		case 4:
 			do_show_modversions = 1;
 			break;
+		case 6:
+			do_show_exports = 1;
+			break;
 		case 'n':
 			dry_run = 1;
 			break;
@@ -886,6 +920,8 @@ static int do_modprobe(int argc, char **orig_argv)
 		err = show_config(ctx);
 	else if (do_show_modversions)
 		err = show_modversions(ctx, args[0]);
+	else if (do_show_exports)
+		err = show_exports(ctx, args[0]);
 	else if (do_remove)
 		err = rmmod_all(ctx, args, nargs);
 	else if (use_all)
-- 
2.19.1


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

* Re: [PATCH v3] modprobe: add --show-exports
  2018-11-13  9:00   ` [PATCH v3] " Yauheni Kaliuta
@ 2018-11-13 23:05     ` Lucas De Marchi
  0 siblings, 0 replies; 4+ messages in thread
From: Lucas De Marchi @ 2018-11-13 23:05 UTC (permalink / raw)
  To: Yauheni Kaliuta; +Cc: linux-modules, ykaliuta, Lucas De Marchi

On Tue, Nov 13, 2018 at 12:59 AM Yauheni Kaliuta
<yauheni.kaliuta@redhat.com> wrote:
>
> modprobe has --show-modversions switch, which dumps symbols with
> their modversion crcs from the __versions sections.
>
> At the moment the section contains information for the dependency
> symbols only, while exported symbols add to symtab entries with
> __crc_ prefix (the format may differ, see 1e48901166ef libkmod-elf:
> resolve CRC if module is built with MODULE_REL_CRCS).
>
> The patch makes it to show exported symbols as well.
>
> The function is basically cut'n'paste of show_modversions(),
> but 'version' family replaced with 'symbol' one.
>
> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
> ---

Applied, thanks

Lucas De Marchi

>  tools/modprobe.c | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
> ---
> Changelog:
>
> v2 -> v3:
>
> - remove --dump-exports
> - amend help string to be like --show-depends
>
> v1 -> v2:
>
> - do not abstract show functions, because it requires API change
>
> diff --git a/tools/modprobe.c b/tools/modprobe.c
> index 43605ccaf0f0..a9e2331567af 100644
> --- a/tools/modprobe.c
> +++ b/tools/modprobe.c
> @@ -76,6 +76,7 @@ static const struct option cmdopts[] = {
>         {"show-config", no_argument, 0, 'c'},
>         {"show-modversions", no_argument, 0, 4},
>         {"dump-modversions", no_argument, 0, 4},
> +       {"show-exports", no_argument, 0, 6},
>
>         {"dry-run", no_argument, 0, 'n'},
>         {"show", no_argument, 0, 'n'},
> @@ -124,6 +125,7 @@ static void help(void)
>                 "\t-c, --show-config           Same as --showconfig\n"
>                 "\t    --show-modversions      Dump module symbol version and exit\n"
>                 "\t    --dump-modversions      Same as --show-modversions\n"
> +               "\t    --show-exports          Only print module exported symbol versions and exit\n"
>                 "\n"
>                 "General Options:\n"
>                 "\t-n, --dry-run               Do not execute operations, just print out\n"
> @@ -232,6 +234,34 @@ static int show_modversions(struct kmod_ctx *ctx, const char *filename)
>         return 0;
>  }
>
> +static int show_exports(struct kmod_ctx *ctx, const char *filename)
> +{
> +       struct kmod_list *l, *list = NULL;
> +       struct kmod_module *mod;
> +       int err = kmod_module_new_from_path(ctx, filename, &mod);
> +       if (err < 0) {
> +               LOG("Module %s not found.\n", filename);
> +               return err;
> +       }
> +
> +       err = kmod_module_get_symbols(mod, &list);
> +       if (err < 0) {
> +               LOG("could not get symbols of %s: %s\n",
> +                       filename, strerror(-err));
> +               kmod_module_unref(mod);
> +               return err;
> +       }
> +
> +       kmod_list_foreach(l, list) {
> +               const char *symbol = kmod_module_symbol_get_symbol(l);
> +               uint64_t crc = kmod_module_symbol_get_crc(l);
> +               printf("0x%08"PRIx64"\t%s\n", crc, symbol);
> +       }
> +       kmod_module_symbols_free_list(list);
> +       kmod_module_unref(mod);
> +       return 0;
> +}
> +
>  static int command_do(struct kmod_module *module, const char *type,
>                                 const char *command, const char *cmdline_opts)
>  {
> @@ -727,6 +757,7 @@ static int do_modprobe(int argc, char **orig_argv)
>         int do_remove = 0;
>         int do_show_config = 0;
>         int do_show_modversions = 0;
> +       int do_show_exports = 0;
>         int err;
>
>         argv = prepend_options_from_env(&argc, orig_argv);
> @@ -783,6 +814,9 @@ static int do_modprobe(int argc, char **orig_argv)
>                 case 4:
>                         do_show_modversions = 1;
>                         break;
> +               case 6:
> +                       do_show_exports = 1;
> +                       break;
>                 case 'n':
>                         dry_run = 1;
>                         break;
> @@ -886,6 +920,8 @@ static int do_modprobe(int argc, char **orig_argv)
>                 err = show_config(ctx);
>         else if (do_show_modversions)
>                 err = show_modversions(ctx, args[0]);
> +       else if (do_show_exports)
> +               err = show_exports(ctx, args[0]);
>         else if (do_remove)
>                 err = rmmod_all(ctx, args, nargs);
>         else if (use_all)
> --
> 2.19.1
>


-- 
Lucas De Marchi

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

end of thread, other threads:[~2018-11-13 23:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-12 15:49 [PATCH v2] modprobe: add --show-exports Yauheni Kaliuta
2018-11-12 23:15 ` Lucas De Marchi
2018-11-13  9:00   ` [PATCH v3] " Yauheni Kaliuta
2018-11-13 23:05     ` Lucas De Marchi

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