Skip to content

Commit bc35d4b

Browse files
committed
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>
1 parent bbc55bd commit bc35d4b

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎Documentation/core-api/symbol-namespaces.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,6 @@ in-tree modules::
152152
- notice the warning of modpost telling about a missing import
153153
- run `make nsdeps` to add the import to the correct code location
154154

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

‎Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ endif
10081008
PHONY += prepare0
10091009

10101010
export MODORDER := $(extmod-prefix)modules.order
1011+
export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps
10111012

10121013
ifeq ($(KBUILD_EXTMOD),)
10131014
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
@@ -1620,7 +1621,7 @@ _emodinst_post: _emodinst_
16201621
$(call cmd,depmod)
16211622

16221623
clean-dirs := $(KBUILD_EXTMOD)
1623-
clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers
1624+
clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps
16241625

16251626
PHONY += /
16261627
/:

‎scripts/Makefile.modpost‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ __modpost:
6666
else
6767

6868
MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s -T - \
69-
$(if $(KBUILD_NSDEPS),-d modules.nsdeps)
69+
$(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS))
7070

7171
ifeq ($(KBUILD_EXTMOD),)
7272
MODPOST += $(wildcard vmlinux)

‎scripts/nsdeps‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ if [ "$SPATCH_VERSION_NUM" -lt "$SPATCH_REQ_VERSION_NUM" ] ; then
2121
exit 1
2222
fi
2323

24+
if [ "$KBUILD_EXTMOD" ]; then
25+
src_prefix=
26+
else
27+
src_prefix=$srctree/
28+
fi
29+
2430
generate_deps_for_ns() {
2531
$SPATCH --very-quiet --in-place --sp-file \
2632
$srctree/scripts/coccinelle/misc/add_namespace.cocci -D ns=$1 $2
@@ -32,7 +38,7 @@ generate_deps() {
3238
local namespaces="$*"
3339
local mod_source_files="`cat $mod.mod | sed -n 1p \
3440
| sed -e 's/\.o/\.c/g' \
35-
| sed "s|[^ ]* *|${srctree}/&|g"`"
41+
| sed "s|[^ ]* *|${src_prefix}&|g"`"
3642
for ns in $namespaces; do
3743
echo "Adding namespace $ns to module $mod.ko."
3844
generate_deps_for_ns $ns "$mod_source_files"
@@ -54,4 +60,4 @@ generate_deps() {
5460
while read line
5561
do
5662
generate_deps $line
57-
done < modules.nsdeps
63+
done < $MODULES_NSDEPS

0 commit comments

Comments
 (0)