Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scripts/nsdeps: support nsdeps for external module builds

scripts/nsdeps is written to take care of only in-tree modules.
Perhaps, this is not a bug, but just a design. At least,
Documentation/core-api/symbol-namespaces.rst focuses on in-tree modules.

Having said that, some people already tried nsdeps for external modules.
So, it would be nice to support it.

Reported-by: Steve French <smfrench@gmail.com>
Reported-by: Jessica Yu <jeyu@kernel.org>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Tested-by: Jessica Yu <jeyu@kernel.org>
Acked-by: Jessica Yu <jeyu@kernel.org>
Reviewed-by: Matthias Maennich <maennich@google.com>
Tested-by: Matthias Maennich <maennich@google.com>

+14 -4
+3
Documentation/core-api/symbol-namespaces.rst
··· 152 152 - notice the warning of modpost telling about a missing import 153 153 - run `make nsdeps` to add the import to the correct code location 154 154 155 + You can also run nsdeps for external module builds. A typical usage is:: 156 + 157 + $ make -C <path_to_kernel_src> M=$PWD nsdeps
+2 -1
Makefile
··· 1008 1008 PHONY += prepare0 1009 1009 1010 1010 export MODORDER := $(extmod-prefix)modules.order 1011 + export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps 1011 1012 1012 1013 ifeq ($(KBUILD_EXTMOD),) 1013 1014 core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ ··· 1621 1620 $(call cmd,depmod) 1622 1621 1623 1622 clean-dirs := $(KBUILD_EXTMOD) 1624 - clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers 1623 + clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps 1625 1624 1626 1625 PHONY += / 1627 1626 /:
+1 -1
scripts/Makefile.modpost
··· 66 66 else 67 67 68 68 MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s -T - \ 69 - $(if $(KBUILD_NSDEPS),-d modules.nsdeps) 69 + $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) 70 70 71 71 ifeq ($(KBUILD_EXTMOD),) 72 72 MODPOST += $(wildcard vmlinux)
+8 -2
scripts/nsdeps
··· 21 21 exit 1 22 22 fi 23 23 24 + if [ "$KBUILD_EXTMOD" ]; then 25 + src_prefix= 26 + else 27 + src_prefix=$srctree/ 28 + fi 29 + 24 30 generate_deps_for_ns() { 25 31 $SPATCH --very-quiet --in-place --sp-file \ 26 32 $srctree/scripts/coccinelle/misc/add_namespace.cocci -D ns=$1 $2 ··· 38 32 local namespaces="$*" 39 33 local mod_source_files="`cat $mod.mod | sed -n 1p \ 40 34 | sed -e 's/\.o/\.c/g' \ 41 - | sed "s|[^ ]* *|${srctree}/&|g"`" 35 + | sed "s|[^ ]* *|${src_prefix}&|g"`" 42 36 for ns in $namespaces; do 43 37 echo "Adding namespace $ns to module $mod.ko." 44 38 generate_deps_for_ns $ns "$mod_source_files" ··· 60 54 while read line 61 55 do 62 56 generate_deps $line 63 - done < modules.nsdeps 57 + done < $MODULES_NSDEPS