Commit c6f6ebd7 authored by Linus Torvalds's avatar Linus Torvalds

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
parents 56c642e2 fcfacb9f
...@@ -38,6 +38,7 @@ Core utilities ...@@ -38,6 +38,7 @@ Core utilities
protection-keys protection-keys
../RCU/index ../RCU/index
gcc-plugins gcc-plugins
symbol-namespaces
Interfaces for kernel debugging Interfaces for kernel debugging
......
...@@ -11544,6 +11544,7 @@ NSDEPS ...@@ -11544,6 +11544,7 @@ NSDEPS
M: Matthias Maennich <maennich@google.com> M: Matthias Maennich <maennich@google.com>
S: Maintained S: Maintained
F: scripts/nsdeps F: scripts/nsdeps
F: Documentation/core-api/symbol-namespaces.rst
NTB AMD DRIVER NTB AMD DRIVER
M: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> M: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
......
...@@ -599,7 +599,7 @@ endif ...@@ -599,7 +599,7 @@ endif
# in addition to whatever we do anyway. # in addition to whatever we do anyway.
# Just "make" or "make all" shall build modules as well # Just "make" or "make all" shall build modules as well
ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) ifneq ($(filter all _all modules nsdeps,$(MAKECMDGOALS)),)
KBUILD_MODULES := 1 KBUILD_MODULES := 1
endif endif
......
...@@ -52,10 +52,10 @@ extern struct module __this_module; ...@@ -52,10 +52,10 @@ extern struct module __this_module;
__ADDRESSABLE(sym) \ __ADDRESSABLE(sym) \
asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
" .balign 4 \n" \ " .balign 4 \n" \
"__ksymtab_" #sym NS_SEPARATOR #ns ": \n" \ "__ksymtab_" #ns NS_SEPARATOR #sym ": \n" \
" .long " #sym "- . \n" \ " .long " #sym "- . \n" \
" .long __kstrtab_" #sym "- . \n" \ " .long __kstrtab_" #sym "- . \n" \
" .long __kstrtab_ns_" #sym "- . \n" \ " .long __kstrtabns_" #sym "- . \n" \
" .previous \n") " .previous \n")
#define __KSYMTAB_ENTRY(sym, sec) \ #define __KSYMTAB_ENTRY(sym, sec) \
...@@ -76,10 +76,10 @@ struct kernel_symbol { ...@@ -76,10 +76,10 @@ struct kernel_symbol {
#else #else
#define __KSYMTAB_ENTRY_NS(sym, sec, ns) \ #define __KSYMTAB_ENTRY_NS(sym, sec, ns) \
static const struct kernel_symbol __ksymtab_##sym##__##ns \ static const struct kernel_symbol __ksymtab_##sym##__##ns \
asm("__ksymtab_" #sym NS_SEPARATOR #ns) \ asm("__ksymtab_" #ns NS_SEPARATOR #sym) \
__attribute__((section("___ksymtab" sec "+" #sym), used)) \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \
__aligned(sizeof(void *)) \ __aligned(sizeof(void *)) \
= { (unsigned long)&sym, __kstrtab_##sym, __kstrtab_ns_##sym } = { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }
#define __KSYMTAB_ENTRY(sym, sec) \ #define __KSYMTAB_ENTRY(sym, sec) \
static const struct kernel_symbol __ksymtab_##sym \ static const struct kernel_symbol __ksymtab_##sym \
...@@ -112,7 +112,7 @@ struct kernel_symbol { ...@@ -112,7 +112,7 @@ struct kernel_symbol {
/* For every exported symbol, place a struct in the __ksymtab section */ /* For every exported symbol, place a struct in the __ksymtab section */
#define ___EXPORT_SYMBOL_NS(sym, sec, ns) \ #define ___EXPORT_SYMBOL_NS(sym, sec, ns) \
___export_symbol_common(sym, sec); \ ___export_symbol_common(sym, sec); \
static const char __kstrtab_ns_##sym[] \ static const char __kstrtabns_##sym[] \
__attribute__((section("__ksymtab_strings"), used, aligned(1))) \ __attribute__((section("__ksymtab_strings"), used, aligned(1))) \
= #ns; \ = #ns; \
__KSYMTAB_ENTRY_NS(sym, sec, ns) __KSYMTAB_ENTRY_NS(sym, sec, ns)
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
/// add a missing namespace tag to a module source file. /// add a missing namespace tag to a module source file.
/// ///
virtual report
@has_ns_import@ @has_ns_import@
declarer name MODULE_IMPORT_NS; declarer name MODULE_IMPORT_NS;
identifier virtual.ns; identifier virtual.ns;
......
...@@ -166,7 +166,7 @@ struct symbol { ...@@ -166,7 +166,7 @@ struct symbol {
struct module *module; struct module *module;
unsigned int crc; unsigned int crc;
int crc_valid; int crc_valid;
const char *namespace; char *namespace;
unsigned int weak:1; unsigned int weak:1;
unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */ unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */
unsigned int kernel:1; /* 1 if symbol is from kernel 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,20 +348,18 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
return export_unknown; return export_unknown;
} }
static const char *sym_extract_namespace(const char **symname) static char *sym_extract_namespace(const char **symname)
{ {
size_t n; char *namespace = NULL;
char *dupsymname; char *ns_separator;
n = strcspn(*symname, "."); ns_separator = strchr(*symname, '.');
if (n < strlen(*symname) - 1) { if (ns_separator) {
dupsymname = NOFAIL(strdup(*symname)); namespace = NOFAIL(strndup(*symname, ns_separator - *symname));
dupsymname[n] = '\0'; *symname = ns_separator + 1;
*symname = dupsymname;
return dupsymname + n + 1;
} }
return NULL; return namespace;
} }
/** /**
...@@ -375,7 +373,6 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace, ...@@ -375,7 +373,6 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace,
if (!s) { if (!s) {
s = new_symbol(name, mod, export); s = new_symbol(name, mod, export);
s->namespace = namespace;
} else { } else {
if (!s->preloaded) { if (!s->preloaded) {
warn("%s: '%s' exported twice. Previous export was in %s%s\n", 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,6 +383,8 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace,
s->module = mod; s->module = mod;
} }
} }
free(s->namespace);
s->namespace = namespace ? strdup(namespace) : NULL;
s->preloaded = 0; s->preloaded = 0;
s->vmlinux = is_vmlinux(mod->name); s->vmlinux = is_vmlinux(mod->name);
s->kernel = 0; s->kernel = 0;
...@@ -672,7 +671,8 @@ static void handle_modversions(struct module *mod, struct elf_info *info, ...@@ -672,7 +671,8 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
unsigned int crc; unsigned int crc;
enum export export; enum export export;
bool is_crc = false; bool is_crc = false;
const char *name, *namespace; const char *name;
char *namespace;
if ((!is_vmlinux(mod->name) || mod->is_dot_o) && if ((!is_vmlinux(mod->name) || mod->is_dot_o) &&
strstarts(symname, "__ksymtab")) strstarts(symname, "__ksymtab"))
...@@ -747,6 +747,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, ...@@ -747,6 +747,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
name = symname + strlen("__ksymtab_"); name = symname + strlen("__ksymtab_");
namespace = sym_extract_namespace(&name); namespace = sym_extract_namespace(&name);
sym_add_exported(name, namespace, mod, export); sym_add_exported(name, namespace, mod, export);
free(namespace);
} }
if (strcmp(symname, "init_module") == 0) if (strcmp(symname, "init_module") == 0)
mod->has_init = 1; mod->has_init = 1;
...@@ -2195,7 +2196,7 @@ static int check_exports(struct module *mod) ...@@ -2195,7 +2196,7 @@ static int check_exports(struct module *mod)
else else
basename = mod->name; basename = mod->name;
if (exp->namespace) { if (exp->namespace && exp->namespace[0]) {
add_namespace(&mod->required_namespaces, add_namespace(&mod->required_namespaces,
exp->namespace); exp->namespace);
......
#!/bin/bash #!/bin/sh
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
# Linux kernel symbol namespace import generator # Linux kernel symbol namespace import generator
# #
...@@ -41,7 +41,7 @@ generate_deps() { ...@@ -41,7 +41,7 @@ generate_deps() {
for source_file in $mod_source_files; do for source_file in $mod_source_files; do
sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp
offset=$(wc -l ${source_file}.tmp | awk '{print $1;}') offset=$(wc -l ${source_file}.tmp | awk '{print $1;}')
cat $source_file | grep MODULE_IMPORT_NS | sort -u >> ${source_file}.tmp cat $source_file | grep MODULE_IMPORT_NS | LANG=C sort -u >> ${source_file}.tmp
tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp
if ! diff -q ${source_file} ${source_file}.tmp; then if ! diff -q ${source_file} ${source_file}.tmp; then
mv ${source_file}.tmp ${source_file} mv ${source_file}.tmp ${source_file}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment