diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-10-11 13:19:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-10-11 13:19:24 -0400 |
commit | c6f6ebd77ce1bb8931f78412a841dd1371820181 (patch) | |
tree | 3945e2d04047f9a263807f831bbbfd610a046a95 | |
parent | 56c642e2aa1c3be3e51e136eace6502aca8116ab (diff) | |
parent | fcfacb9f83745d9fa97937b8bc94a73bb0607912 (diff) |
Merge tag 'modules-for-v5.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux
Pull module fixes from Jessica Yu:
"Code cleanups and kbuild/namespace related fixups from Masahiro.
Most importantly, it fixes a namespace-related modpost issue for
external module builds
- Fix broken external module builds due to a modpost bug in
read_dump(), where the namespace was not being strdup'd and
sym->namespace would be set to bogus data.
- Various namespace-related kbuild fixes and cleanups thanks to
Masahiro Yamada"
* tag 'modules-for-v5.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux:
doc: move namespaces.rst from kbuild/ to core-api/
nsdeps: make generated patches independent of locale
nsdeps: fix hashbang of scripts/nsdeps
kbuild: fix build error of 'make nsdeps' in clean tree
module: rename __kstrtab_ns_* to __kstrtabns_* to avoid symbol conflict
modpost: fix broken sym->namespace for external module builds
module: swap the order of symbol.namespace
scripts: add_namespace: Fix coccicheck failed
-rw-r--r-- | Documentation/core-api/index.rst | 1 | ||||
-rw-r--r-- | Documentation/core-api/symbol-namespaces.rst (renamed from Documentation/kbuild/namespaces.rst) | 0 | ||||
-rw-r--r-- | MAINTAINERS | 1 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/linux/export.h | 10 | ||||
-rw-r--r-- | scripts/coccinelle/misc/add_namespace.cocci | 2 | ||||
-rw-r--r-- | scripts/mod/modpost.c | 29 | ||||
-rw-r--r-- | scripts/nsdeps | 4 |
8 files changed, 27 insertions, 22 deletions
diff --git a/Documentation/core-api/index.rst b/Documentation/core-api/index.rst index fa16a0538dcb..ab0eae1c153a 100644 --- a/Documentation/core-api/index.rst +++ b/Documentation/core-api/index.rst | |||
@@ -38,6 +38,7 @@ Core utilities | |||
38 | protection-keys | 38 | protection-keys |
39 | ../RCU/index | 39 | ../RCU/index |
40 | gcc-plugins | 40 | gcc-plugins |
41 | symbol-namespaces | ||
41 | 42 | ||
42 | 43 | ||
43 | Interfaces for kernel debugging | 44 | Interfaces for kernel debugging |
diff --git a/Documentation/kbuild/namespaces.rst b/Documentation/core-api/symbol-namespaces.rst index 982ed7b568ac..982ed7b568ac 100644 --- a/Documentation/kbuild/namespaces.rst +++ b/Documentation/core-api/symbol-namespaces.rst | |||
diff --git a/MAINTAINERS b/MAINTAINERS index d44d6732510d..e9b0a4100a29 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -11544,6 +11544,7 @@ NSDEPS | |||
11544 | M: Matthias Maennich <maennich@google.com> | 11544 | M: Matthias Maennich <maennich@google.com> |
11545 | S: Maintained | 11545 | S: Maintained |
11546 | F: scripts/nsdeps | 11546 | F: scripts/nsdeps |
11547 | F: Documentation/core-api/symbol-namespaces.rst | ||
11547 | 11548 | ||
11548 | NTB AMD DRIVER | 11549 | NTB AMD DRIVER |
11549 | M: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> | 11550 | M: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> |
@@ -599,7 +599,7 @@ endif | |||
599 | # in addition to whatever we do anyway. | 599 | # in addition to whatever we do anyway. |
600 | # Just "make" or "make all" shall build modules as well | 600 | # Just "make" or "make all" shall build modules as well |
601 | 601 | ||
602 | ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) | 602 | ifneq ($(filter all _all modules nsdeps,$(MAKECMDGOALS)),) |
603 | KBUILD_MODULES := 1 | 603 | KBUILD_MODULES := 1 |
604 | endif | 604 | endif |
605 | 605 | ||
diff --git a/include/linux/export.h b/include/linux/export.h index 95f55b7f83a0..621158ecd2e2 100644 --- a/include/linux/export.h +++ b/include/linux/export.h | |||
@@ -52,10 +52,10 @@ extern struct module __this_module; | |||
52 | __ADDRESSABLE(sym) \ | 52 | __ADDRESSABLE(sym) \ |
53 | asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ | 53 | asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ |
54 | " .balign 4 \n" \ | 54 | " .balign 4 \n" \ |
55 | "__ksymtab_" #sym NS_SEPARATOR #ns ": \n" \ | 55 | "__ksymtab_" #ns NS_SEPARATOR #sym ": \n" \ |
56 | " .long " #sym "- . \n" \ | 56 | " .long " #sym "- . \n" \ |
57 | " .long __kstrtab_" #sym "- . \n" \ | 57 | " .long __kstrtab_" #sym "- . \n" \ |
58 | " .long __kstrtab_ns_" #sym "- . \n" \ | 58 | " .long __kstrtabns_" #sym "- . \n" \ |
59 | " .previous \n") | 59 | " .previous \n") |
60 | 60 | ||
61 | #define __KSYMTAB_ENTRY(sym, sec) \ | 61 | #define __KSYMTAB_ENTRY(sym, sec) \ |
@@ -76,10 +76,10 @@ struct kernel_symbol { | |||
76 | #else | 76 | #else |
77 | #define __KSYMTAB_ENTRY_NS(sym, sec, ns) \ | 77 | #define __KSYMTAB_ENTRY_NS(sym, sec, ns) \ |
78 | static const struct kernel_symbol __ksymtab_##sym##__##ns \ | 78 | static const struct kernel_symbol __ksymtab_##sym##__##ns \ |
79 | asm("__ksymtab_" #sym NS_SEPARATOR #ns) \ | 79 | asm("__ksymtab_" #ns NS_SEPARATOR #sym) \ |
80 | __attribute__((section("___ksymtab" sec "+" #sym), used)) \ | 80 | __attribute__((section("___ksymtab" sec "+" #sym), used)) \ |
81 | __aligned(sizeof(void *)) \ | 81 | __aligned(sizeof(void *)) \ |
82 | = { (unsigned long)&sym, __kstrtab_##sym, __kstrtab_ns_##sym } | 82 | = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym } |
83 | 83 | ||
84 | #define __KSYMTAB_ENTRY(sym, sec) \ | 84 | #define __KSYMTAB_ENTRY(sym, sec) \ |
85 | static const struct kernel_symbol __ksymtab_##sym \ | 85 | static const struct kernel_symbol __ksymtab_##sym \ |
@@ -112,7 +112,7 @@ struct kernel_symbol { | |||
112 | /* For every exported symbol, place a struct in the __ksymtab section */ | 112 | /* For every exported symbol, place a struct in the __ksymtab section */ |
113 | #define ___EXPORT_SYMBOL_NS(sym, sec, ns) \ | 113 | #define ___EXPORT_SYMBOL_NS(sym, sec, ns) \ |
114 | ___export_symbol_common(sym, sec); \ | 114 | ___export_symbol_common(sym, sec); \ |
115 | static const char __kstrtab_ns_##sym[] \ | 115 | static const char __kstrtabns_##sym[] \ |
116 | __attribute__((section("__ksymtab_strings"), used, aligned(1))) \ | 116 | __attribute__((section("__ksymtab_strings"), used, aligned(1))) \ |
117 | = #ns; \ | 117 | = #ns; \ |
118 | __KSYMTAB_ENTRY_NS(sym, sec, ns) | 118 | __KSYMTAB_ENTRY_NS(sym, sec, ns) |
diff --git a/scripts/coccinelle/misc/add_namespace.cocci b/scripts/coccinelle/misc/add_namespace.cocci index c832bb6445a8..99e93a6c2e24 100644 --- a/scripts/coccinelle/misc/add_namespace.cocci +++ b/scripts/coccinelle/misc/add_namespace.cocci | |||
@@ -6,6 +6,8 @@ | |||
6 | /// add a missing namespace tag to a module source file. | 6 | /// add a missing namespace tag to a module source file. |
7 | /// | 7 | /// |
8 | 8 | ||
9 | virtual report | ||
10 | |||
9 | @has_ns_import@ | 11 | @has_ns_import@ |
10 | declarer name MODULE_IMPORT_NS; | 12 | declarer name MODULE_IMPORT_NS; |
11 | identifier virtual.ns; | 13 | identifier virtual.ns; |
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 442d5e2ad688..936d3ad23c83 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -166,7 +166,7 @@ struct symbol { | |||
166 | struct module *module; | 166 | struct module *module; |
167 | unsigned int crc; | 167 | unsigned int crc; |
168 | int crc_valid; | 168 | int crc_valid; |
169 | const char *namespace; | 169 | char *namespace; |
170 | unsigned int weak:1; | 170 | unsigned int weak:1; |
171 | unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */ | 171 | unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */ |
172 | unsigned int kernel:1; /* 1 if symbol is from kernel | 172 | unsigned int kernel:1; /* 1 if symbol is from kernel |
@@ -348,20 +348,18 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec) | |||
348 | return export_unknown; | 348 | return export_unknown; |
349 | } | 349 | } |
350 | 350 | ||
351 | static const char *sym_extract_namespace(const char **symname) | 351 | static char *sym_extract_namespace(const char **symname) |
352 | { | 352 | { |
353 | size_t n; | 353 | char *namespace = NULL; |
354 | char *dupsymname; | 354 | char *ns_separator; |
355 | 355 | ||
356 | n = strcspn(*symname, "."); | 356 | ns_separator = strchr(*symname, '.'); |
357 | if (n < strlen(*symname) - 1) { | 357 | if (ns_separator) { |
358 | dupsymname = NOFAIL(strdup(*symname)); | 358 | namespace = NOFAIL(strndup(*symname, ns_separator - *symname)); |
359 | dupsymname[n] = '\0'; | 359 | *symname = ns_separator + 1; |
360 | *symname = dupsymname; | ||
361 | return dupsymname + n + 1; | ||
362 | } | 360 | } |
363 | 361 | ||
364 | return NULL; | 362 | return namespace; |
365 | } | 363 | } |
366 | 364 | ||
367 | /** | 365 | /** |
@@ -375,7 +373,6 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace, | |||
375 | 373 | ||
376 | if (!s) { | 374 | if (!s) { |
377 | s = new_symbol(name, mod, export); | 375 | s = new_symbol(name, mod, export); |
378 | s->namespace = namespace; | ||
379 | } else { | 376 | } else { |
380 | if (!s->preloaded) { | 377 | if (!s->preloaded) { |
381 | warn("%s: '%s' exported twice. Previous export was in %s%s\n", | 378 | warn("%s: '%s' exported twice. Previous export was in %s%s\n", |
@@ -386,6 +383,8 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace, | |||
386 | s->module = mod; | 383 | s->module = mod; |
387 | } | 384 | } |
388 | } | 385 | } |
386 | free(s->namespace); | ||
387 | s->namespace = namespace ? strdup(namespace) : NULL; | ||
389 | s->preloaded = 0; | 388 | s->preloaded = 0; |
390 | s->vmlinux = is_vmlinux(mod->name); | 389 | s->vmlinux = is_vmlinux(mod->name); |
391 | s->kernel = 0; | 390 | s->kernel = 0; |
@@ -672,7 +671,8 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
672 | unsigned int crc; | 671 | unsigned int crc; |
673 | enum export export; | 672 | enum export export; |
674 | bool is_crc = false; | 673 | bool is_crc = false; |
675 | const char *name, *namespace; | 674 | const char *name; |
675 | char *namespace; | ||
676 | 676 | ||
677 | if ((!is_vmlinux(mod->name) || mod->is_dot_o) && | 677 | if ((!is_vmlinux(mod->name) || mod->is_dot_o) && |
678 | strstarts(symname, "__ksymtab")) | 678 | strstarts(symname, "__ksymtab")) |
@@ -747,6 +747,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
747 | name = symname + strlen("__ksymtab_"); | 747 | name = symname + strlen("__ksymtab_"); |
748 | namespace = sym_extract_namespace(&name); | 748 | namespace = sym_extract_namespace(&name); |
749 | sym_add_exported(name, namespace, mod, export); | 749 | sym_add_exported(name, namespace, mod, export); |
750 | free(namespace); | ||
750 | } | 751 | } |
751 | if (strcmp(symname, "init_module") == 0) | 752 | if (strcmp(symname, "init_module") == 0) |
752 | mod->has_init = 1; | 753 | mod->has_init = 1; |
@@ -2195,7 +2196,7 @@ static int check_exports(struct module *mod) | |||
2195 | else | 2196 | else |
2196 | basename = mod->name; | 2197 | basename = mod->name; |
2197 | 2198 | ||
2198 | if (exp->namespace) { | 2199 | if (exp->namespace && exp->namespace[0]) { |
2199 | add_namespace(&mod->required_namespaces, | 2200 | add_namespace(&mod->required_namespaces, |
2200 | exp->namespace); | 2201 | exp->namespace); |
2201 | 2202 | ||
diff --git a/scripts/nsdeps b/scripts/nsdeps index ac2b6031dd13..3754dac13b31 100644 --- a/scripts/nsdeps +++ b/scripts/nsdeps | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/sh |
2 | # SPDX-License-Identifier: GPL-2.0 | 2 | # SPDX-License-Identifier: GPL-2.0 |
3 | # Linux kernel symbol namespace import generator | 3 | # Linux kernel symbol namespace import generator |
4 | # | 4 | # |
@@ -41,7 +41,7 @@ generate_deps() { | |||
41 | for source_file in $mod_source_files; do | 41 | for source_file in $mod_source_files; do |
42 | sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp | 42 | sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp |
43 | offset=$(wc -l ${source_file}.tmp | awk '{print $1;}') | 43 | offset=$(wc -l ${source_file}.tmp | awk '{print $1;}') |
44 | cat $source_file | grep MODULE_IMPORT_NS | sort -u >> ${source_file}.tmp | 44 | cat $source_file | grep MODULE_IMPORT_NS | LANG=C sort -u >> ${source_file}.tmp |
45 | tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp | 45 | tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp |
46 | if ! diff -q ${source_file} ${source_file}.tmp; then | 46 | if ! diff -q ${source_file} ${source_file}.tmp; then |
47 | mv ${source_file}.tmp ${source_file} | 47 | mv ${source_file}.tmp ${source_file} |