kbuild: add extra-y to targets-for-modules
PATCH 1/1 kbuild: add extra-y to targets-for-modules
extra-y target doesn't build for 'make M=...' since commit 6212804f2d78 ("kbuild: do not create built-in objects for external module builds").
This especially breaks kpatch, which is using 'extra-y := kpatch.lds' and 'make M=...' to build livepatch patch module.
Add extra-y to targets-for-modules so that such kind of build works properly.
--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.build +1 -1
@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order
Signature · 1 line
2.29.1
Masahiro Yamada
NAKQuoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --
Quoted 2 lines
2.29.1
NACK.
Please fix your Makefile.
Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/
Probably what you should use is 'targets'.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat > Makefile << _EOF_
obj-m += foo.o
ldflags-y += -T $(src)/kpatch.lds
always-y += kpatch.lds
foo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
_EOF_
Take a look into scripts/Makefile.build:488:
__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:
'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because kpatch.lds isn't there.
For 'targets', in case of OOT, does not seem to be useful.
What change do you suggest to make to fix this kind of Makefile?
Thanks,
WANG Chao
Quoted 65 lines · WANG Chao
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat >
Makefile<< _EOF_
obj-m += foo.oldflags-y += -T $(src)/kpatch.lds
always-y +=kpatch.ldsfoo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean_EOF_
Take a look into
scripts/Makefile.build:488:
Quoted 7 lines
__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because
kpatch.ldsisn't there.
Heh, you rely on the targets built from left to right, and you have never thought Make supports the parallel option -j.
You need to specify the dependency if you expect objects are built in the particular order.
However, in this case, using ldflags-y looks wrong in the first place.
The linker script is used when combining the object as well as the final link of *.ko
Quoted 6 lines
For 'targets', in case of OOT, does not seem to be useful.
What change do you suggest to make to fix this kind of
Makefile?Thanks,
WANG Chao
Signature · 2 lines
Best Regards Masahiro Yamada
Sorry for the late reply.
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · WANG Chao
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat >
Makefile<< _EOF_
obj-m += foo.oldflags-y += -T $(src)/kpatch.lds
always-y +=kpatch.ldsfoo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean_EOF_
Take a look into
scripts/Makefile.build:488:__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:
Quoted 6 lines
Quoted 2 lines
'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because
kpatch.ldsisn't there.Heh, you rely on the targets built from left to right, and you have never thought Make supports the parallel option -j.
You're right. I missed that.
Quoted 10 lines
You need to specify the dependency if you expect objects are built in the particular order.
However, in this case, using ldflags-y looks wrong in the first place.
The linker script is used when combining the object as well as the final link of *.ko
I don't have a clean fix to kpatch right now.
I'm looping kpatch forks in. They're also looking at this right now:
https://github.com/dynup/kpatch/pull/1149
Thanks
WANG Chao
Quoted 15 lines
Quoted 8 lines
For 'targets', in case of OOT, does not seem to be useful.
What change do you suggest to make to fix this kind of
Makefile?Thanks,
WANG ChaoSignature · 2 lines
Best Regards Masahiro Yamada
Quoted 74 lines · WANG Chao
Sorry for the late reply.
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · WANG Chao
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat >
Makefile<< _EOF_
obj-m += foo.oldflags-y += -T $(src)/kpatch.lds
always-y +=kpatch.ldsfoo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean_EOF_
Take a look into
scripts/Makefile.build:488:__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:
Quoted 19 lines
Quoted 6 lines
Quoted 2 lines
'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because
kpatch.ldsisn't there.Heh, you rely on the targets built from left to right, and you have never thought Make supports the parallel option -j.
You're right. I missed that.
Quoted 10 lines
You need to specify the dependency if you expect objects are built in the particular order.
However, in this case, using ldflags-y looks wrong in the first place.
The linker script is used when combining the object as well as the final link of *.ko
We want linker script to be used on both those steps, otherwise modpost fails.
It looks like the right thing to do here is leave ldflags-y in, get rid of always-y/extra-y altogether and specify our linker script as a dependency for the object.
Quoted 25 lines
I don't have a clean fix to kpatch right now.
I'm looping kpatch forks in. They're also looking at this right now:
https://github.com/dynup/kpatch/pull/1149
Thanks
WANG ChaoQuoted 15 lines
Quoted 8 lines
For 'targets', in case of OOT, does not seem to be useful.
What change do you suggest to make to fix this kind of
Makefile?Thanks,
WANG ChaoSignature · 2 lines
Best Regards Masahiro Yamada
Signature · 2 lines
Regards, Artem Savkov
Quoted 90 lines · Artem Savkov
Quoted 88 lines · WANG Chao
Sorry for the late reply.
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · WANG Chao
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat >
Makefile<< _EOF_
obj-m += foo.oldflags-y += -T $(src)/kpatch.lds
always-y +=kpatch.ldsfoo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean_EOF_
Take a look into
scripts/Makefile.build:488:__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:Quoted 6 lines
Quoted 2 lines
'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because
kpatch.ldsisn't there.Heh, you rely on the targets built from left to right, and you have never thought Make supports the parallel option -j.
You're right. I missed that.
Quoted 5 lines
You need to specify the dependency if you expect objects are built in the particular order.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
However, in this case, using ldflags-y looks wrong in the first place.
The linker script is used when combining the object as well as the final link of *.ko
We want linker script to be used on both those steps, otherwise modpost fails.
In that case, does the following work?
(untested)
kmod/patch/Makefile +3 -1
@@ -12,7 +12,9 @@ endif obj-m += $(KPATCH_NAME).o ldflags-y += -T $(src)/kpatch.lds -extra-y := kpatch.lds +targets += kpatch.lds + +$(obj)/$(KPATCH_NAME).o: $(obj)/kpatch.lds $(KPATCH_NAME)-objs += patch-hook.o output.o
Quoted 34 lines
It looks like the right thing to do here is leave ldflags-y in, get rid of always-y/extra-y altogether and specify our linker script as a dependency for the object.
Quoted 25 lines
I don't have a clean fix to kpatch right now.
I'm looping kpatch forks in. They're also looking at this right now:
https://github.com/dynup/kpatch/pull/1149
Thanks
WANG ChaoQuoted 15 lines
Quoted 8 lines
For 'targets', in case of OOT, does not seem to be useful.
What change do you suggest to make to fix this kind of
Makefile?Thanks,
WANG Chao--
Best Regards
Masahiro Yamada--
Regards,
Artem Savkov
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 111 lines · Masahiro Yamada
Quoted 90 lines · Artem Savkov
Quoted 88 lines · WANG Chao
Sorry for the late reply.
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · WANG Chao
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat >
Makefile<< _EOF_
obj-m += foo.oldflags-y += -T $(src)/kpatch.lds
always-y +=kpatch.ldsfoo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean_EOF_
Take a look into
scripts/Makefile.build:488:__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:Quoted 6 lines
Quoted 2 lines
'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because
kpatch.ldsisn't there.Heh, you rely on the targets built from left to right, and you have never thought Make supports the parallel option -j.
You're right. I missed that.
Quoted 5 lines
You need to specify the dependency if you expect objects are built in the particular order.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
However, in this case, using ldflags-y looks wrong in the first place.
The linker script is used when combining the object as well as the final link of *.ko
We want linker script to be used on both those steps, otherwise modpost fails.
In that case, does the following work?
(untested)kmod/patch/Makefile +0
-0
kmod/patch/Makefile endif · line 20
Quoted 10 lines
kmod/patch/Makefile +3
-1@@ -12,7 +12,9 @@ endif obj-m += $(KPATCH_NAME).o ldflags-y += -T $(src)/kpatch.lds -extra-y := kpatch.lds +targets += kpatch.lds + +$(obj)/$(KPATCH_NAME).o: $(obj)/kpatch.lds $(KPATCH_NAME)-objs += patch-hook.o output.o
Hi Masahiro,
Yeah this is more or less what Artem came up with:
https://github.com/dynup/kpatch/pull/1149
though we hadn't added kpatch.lds to targets. Is there documentation somewhere on what effect "targets" has for out-of-tree builds?
Thanks,
-- Joe
Quoted 129 lines · Joe Lawrence
Quoted 111 lines · Masahiro Yamada
Quoted 90 lines · Artem Savkov
Quoted 88 lines · WANG Chao
Sorry for the late reply.
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · WANG Chao
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat >
Makefile<< _EOF_
obj-m += foo.oldflags-y += -T $(src)/kpatch.lds
always-y +=kpatch.ldsfoo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean_EOF_
Take a look into
scripts/Makefile.build:488:__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:Quoted 6 lines
Quoted 2 lines
'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because
kpatch.ldsisn't there.Heh, you rely on the targets built from left to right, and you have never thought Make supports the parallel option -j.
You're right. I missed that.
Quoted 5 lines
You need to specify the dependency if you expect objects are built in the particular order.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
However, in this case, using ldflags-y looks wrong in the first place.
The linker script is used when combining the object as well as the final link of *.ko
We want linker script to be used on both those steps, otherwise modpost fails.
In that case, does the following work?
(untested)kmod/patch/Makefile +0
-0kmod/patch/Makefile endif · line 20
Quoted 10 lines
kmod/patch/Makefile +3
-1@@ -12,7 +12,9 @@ endif obj-m += $(KPATCH_NAME).o ldflags-y += -T $(src)/kpatch.lds -extra-y := kpatch.lds +targets += kpatch.lds + +$(obj)/$(KPATCH_NAME).o: $(obj)/kpatch.lds $(KPATCH_NAME)-objs += patch-hook.o output.oHi Masahiro,
Yeah this is more or less what Artem came up with:
https://github.com/dynup/kpatch/pull/1149
Quoted 7 lines
though we hadn't added
kpatch.ldsto targets. Is there documentation somewhere on what effect "targets" has for out-of-tree builds?Thanks,
-- Joe
Please try the rebuild without changing any source code.
If kpatch.lds is needlessly rebuilt, you need to add it to 'targets'.
In linux-next, this is documented.
Documentation/kbuild/makefile.rst:
Any target that utilizes if_changed must be listed in $(targets), otherwise the command line check will fail, and the target will always be built.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 145 lines · Masahiro Yamada
Quoted 129 lines · Joe Lawrence
Quoted 111 lines · Masahiro Yamada
Quoted 90 lines · Artem Savkov
Quoted 88 lines · WANG Chao
Sorry for the late reply.
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · WANG Chao
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat >
Makefile<< _EOF_
obj-m += foo.oldflags-y += -T $(src)/kpatch.lds
always-y +=kpatch.ldsfoo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean_EOF_
Take a look into
scripts/Makefile.build:488:__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:Quoted 6 lines
Quoted 2 lines
'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because
kpatch.ldsisn't there.Heh, you rely on the targets built from left to right, and you have never thought Make supports the parallel option -j.
You're right. I missed that.
Quoted 5 lines
You need to specify the dependency if you expect objects are built in the particular order.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
However, in this case, using ldflags-y looks wrong in the first place.
The linker script is used when combining the object as well as the final link of *.ko
We want linker script to be used on both those steps, otherwise modpost fails.
In that case, does the following work?
(untested)kmod/patch/Makefile +0
-0kmod/patch/Makefile endif · line 20
Quoted 10 lines
kmod/patch/Makefile +3
-1@@ -12,7 +12,9 @@ endif obj-m += $(KPATCH_NAME).o ldflags-y += -T $(src)/kpatch.lds -extra-y := kpatch.lds +targets += kpatch.lds + +$(obj)/$(KPATCH_NAME).o: $(obj)/kpatch.lds $(KPATCH_NAME)-objs += patch-hook.o output.oHi Masahiro,
Yeah this is more or less what Artem came up with:
https://github.com/dynup/kpatch/pull/1149Quoted 7 lines
though we hadn't added
kpatch.ldsto targets. Is there documentation somewhere on what effect "targets" has for out-of-tree builds?Thanks,
-- Joe
Please try the rebuild without changing any source code.
If
kpatch.ldsis needlessly rebuilt, you need to add it to 'targets'.
Quoted 7 lines
In linux-next, this is documented.
Documentation/kbuild/makefile.rst:Any target that utilizes
if_changedmust be listed in $(targets), otherwise the command line check will fail, and the target will always be built.
Ah yes, it did rebuild every time. Thank you for the pointer.
Signature · 1 line
Artem
Quoted 145 lines · Masahiro Yamada
Quoted 129 lines · Joe Lawrence
Quoted 111 lines · Masahiro Yamada
Quoted 90 lines · Artem Savkov
Quoted 88 lines · WANG Chao
Sorry for the late reply.
Quoted 71 lines · Masahiro Yamada
Quoted 70 lines · WANG Chao
Quoted 35 lines · Masahiro Yamada
Quoted 29 lines · WANG Chao
extra-y target doesn't build for 'make M=...' since commit
6212804f2d78("kbuild: do not create built-in objects for external module builds").This especially breaks kpatch, which is using 'extra-y :=
kpatch.lds' and 'make M=...' to build livepatch patch module.Add extra-y to targets-for-modules so that such kind of build works properly.
Signed-off-by WANG Chao <[email protected]>--- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/Makefile.build +1
-2@@ -86,7 +86,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) +targets-for-modules := $(extra-y) $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order --Quoted 2 lines
2.29.1
NACK.
Quoted 7 lines
Please fix your
Makefile.Hint:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/Probably what you should use is 'targets'.
I tried with 'targets' and 'always-y'. Both doesn't work for me.
I narraw it down to the following example:
cat >
Makefile<< _EOF_
obj-m += foo.oldflags-y += -T $(src)/kpatch.lds
always-y +=kpatch.ldsfoo-objs += bar.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean_EOF_
Take a look into
scripts/Makefile.build:488:__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:Quoted 6 lines
Quoted 2 lines
'always-y' is built after 'targets-for-modules'. This makes 'targets-for-modules' fails because
kpatch.ldsisn't there.Heh, you rely on the targets built from left to right, and you have never thought Make supports the parallel option -j.
You're right. I missed that.
Quoted 5 lines
You need to specify the dependency if you expect objects are built in the particular order.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
However, in this case, using ldflags-y looks wrong in the first place.
The linker script is used when combining the object as well as the final link of *.ko
We want linker script to be used on both those steps, otherwise modpost fails.
In that case, does the following work?
(untested)kmod/patch/Makefile +0
-0kmod/patch/Makefile endif · line 20
Quoted 10 lines
kmod/patch/Makefile +3
-1@@ -12,7 +12,9 @@ endif obj-m += $(KPATCH_NAME).o ldflags-y += -T $(src)/kpatch.lds -extra-y := kpatch.lds +targets += kpatch.lds + +$(obj)/$(KPATCH_NAME).o: $(obj)/kpatch.lds $(KPATCH_NAME)-objs += patch-hook.o output.oHi Masahiro,
Yeah this is more or less what Artem came up with:
https://github.com/dynup/kpatch/pull/1149Quoted 7 lines
though we hadn't added
kpatch.ldsto targets. Is there documentation somewhere on what effect "targets" has for out-of-tree builds?Thanks,
-- Joe
Please try the rebuild without changing any source code.
If
kpatch.ldsis needlessly rebuilt, you need to add it to 'targets'.
Quoted 7 lines
In linux-next, this is documented.
Documentation/kbuild/makefile.rst:Any target that utilizes
if_changedmust be listed in $(targets), otherwise the command line check will fail, and the target will always be built.
Ah yes, it did rebuild every time. Thank you for the pointer.
Signature · 1 line
Artem