Skip to content

Commit

Permalink
Merge tag 'modules-for-v5.4-rc3' of git://git.kernel.org/pub/scm/linu…
Browse files Browse the repository at this point in the history
…x/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
  • Loading branch information
torvalds committed Oct 11, 2019
2 parents 56c642e + fcfacb9 commit c6f6ebd
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions Documentation/core-api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Core utilities
protection-keys
../RCU/index
gcc-plugins
symbol-namespaces


Interfaces for kernel debugging
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -11544,6 +11544,7 @@ NSDEPS
M: Matthias Maennich <[email protected]>
S: Maintained
F: scripts/nsdeps
F: Documentation/core-api/symbol-namespaces.rst

NTB AMD DRIVER
M: Shyam Sundar S K <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ endif
# in addition to whatever we do anyway.
# 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
endif

Expand Down
10 changes: 5 additions & 5 deletions include/linux/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ extern struct module __this_module;
__ADDRESSABLE(sym) \
asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
" .balign 4 \n" \
"__ksymtab_" #sym NS_SEPARATOR #ns ": \n" \
"__ksymtab_" #ns NS_SEPARATOR #sym ": \n" \
" .long " #sym "- . \n" \
" .long __kstrtab_" #sym "- . \n" \
" .long __kstrtab_ns_" #sym "- . \n" \
" .long __kstrtabns_" #sym "- . \n" \
" .previous \n")

#define __KSYMTAB_ENTRY(sym, sec) \
Expand All @@ -76,10 +76,10 @@ struct kernel_symbol {
#else
#define __KSYMTAB_ENTRY_NS(sym, sec, 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)) \
__aligned(sizeof(void *)) \
= { (unsigned long)&sym, __kstrtab_##sym, __kstrtab_ns_##sym }
= { (unsigned long)&sym, __kstrtab_##sym, __kstrtabns_##sym }

#define __KSYMTAB_ENTRY(sym, sec) \
static const struct kernel_symbol __ksymtab_##sym \
Expand Down Expand Up @@ -112,7 +112,7 @@ struct kernel_symbol {
/* For every exported symbol, place a struct in the __ksymtab section */
#define ___EXPORT_SYMBOL_NS(sym, sec, ns) \
___export_symbol_common(sym, sec); \
static const char __kstrtab_ns_##sym[] \
static const char __kstrtabns_##sym[] \
__attribute__((section("__ksymtab_strings"), used, aligned(1))) \
= #ns; \
__KSYMTAB_ENTRY_NS(sym, sec, ns)
Expand Down
2 changes: 2 additions & 0 deletions scripts/coccinelle/misc/add_namespace.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/// add a missing namespace tag to a module source file.
///

virtual report

@has_ns_import@
declarer name MODULE_IMPORT_NS;
identifier virtual.ns;
Expand Down
29 changes: 15 additions & 14 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ struct symbol {
struct module *module;
unsigned int crc;
int crc_valid;
const char *namespace;
char *namespace;
unsigned int weak:1;
unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */
unsigned int kernel:1; /* 1 if symbol is from kernel
Expand Down Expand Up @@ -348,20 +348,18 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
return export_unknown;
}

static const char *sym_extract_namespace(const char **symname)
static char *sym_extract_namespace(const char **symname)
{
size_t n;
char *dupsymname;
char *namespace = NULL;
char *ns_separator;

n = strcspn(*symname, ".");
if (n < strlen(*symname) - 1) {
dupsymname = NOFAIL(strdup(*symname));
dupsymname[n] = '\0';
*symname = dupsymname;
return dupsymname + n + 1;
ns_separator = strchr(*symname, '.');
if (ns_separator) {
namespace = NOFAIL(strndup(*symname, ns_separator - *symname));
*symname = ns_separator + 1;
}

return NULL;
return namespace;
}

/**
Expand All @@ -375,7 +373,6 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace,

if (!s) {
s = new_symbol(name, mod, export);
s->namespace = namespace;
} else {
if (!s->preloaded) {
warn("%s: '%s' exported twice. Previous export was in %s%s\n",
Expand All @@ -386,6 +383,8 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace,
s->module = mod;
}
}
free(s->namespace);
s->namespace = namespace ? strdup(namespace) : NULL;
s->preloaded = 0;
s->vmlinux = is_vmlinux(mod->name);
s->kernel = 0;
Expand Down Expand Up @@ -672,7 +671,8 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
unsigned int crc;
enum export export;
bool is_crc = false;
const char *name, *namespace;
const char *name;
char *namespace;

if ((!is_vmlinux(mod->name) || mod->is_dot_o) &&
strstarts(symname, "__ksymtab"))
Expand Down Expand Up @@ -747,6 +747,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
name = symname + strlen("__ksymtab_");
namespace = sym_extract_namespace(&name);
sym_add_exported(name, namespace, mod, export);
free(namespace);
}
if (strcmp(symname, "init_module") == 0)
mod->has_init = 1;
Expand Down Expand Up @@ -2195,7 +2196,7 @@ static int check_exports(struct module *mod)
else
basename = mod->name;

if (exp->namespace) {
if (exp->namespace && exp->namespace[0]) {
add_namespace(&mod->required_namespaces,
exp->namespace);

Expand Down
4 changes: 2 additions & 2 deletions scripts/nsdeps
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Linux kernel symbol namespace import generator
#
Expand Down Expand Up @@ -41,7 +41,7 @@ generate_deps() {
for source_file in $mod_source_files; do
sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp
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
if ! diff -q ${source_file} ${source_file}.tmp; then
mv ${source_file}.tmp ${source_file}
Expand Down

0 comments on commit c6f6ebd

Please sign in to comment.