Skip to content

Commit 32ff683

Browse files
sulixtorvalds
authored andcommitted
kunit: Fix 'hooks.o' build by recursing into kunit
KUnit's 'hooks.o' file need to be built-in whenever KUnit is enabled (even if CONFIG_KUNIT=m). We'd previously attemtped to do this by adding 'kunit/hooks.o' to obj-y in lib/Makefile, but this caused hooks.c to be rebuilt even when it was unchanged. Instead, always recurse into lib/kunit using obj-y when KUnit is enabled, and add the hooks there. Fixes: 7170b7e ("kunit: Add "hooks" to call into KUnit when it's built as a module"). Reported-by: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/linux-kselftest/CAHk-=wiEf7irTKwPJ0jTMOF3CS-13UXmF6Fns3wuWpOZ_wGyZQ@mail.gmail.com/ Signed-off-by: David Gow <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5ca26d6 commit 32ff683

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

lib/Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,10 @@ CFLAGS_test_fpu.o += $(FPU_CFLAGS)
127127

128128
obj-$(CONFIG_TEST_LIVEPATCH) += livepatch/
129129

130-
obj-$(CONFIG_KUNIT) += kunit/
131-
# Include the KUnit hooks unconditionally. They'll compile to nothing if
132-
# CONFIG_KUNIT=n, otherwise will be a small table of static data (static key,
133-
# function pointers) which need to be built-in even when KUnit is a module.
134-
ifeq ($(CONFIG_KUNIT), m)
135-
obj-y += kunit/hooks.o
136-
else
137-
obj-$(CONFIG_KUNIT) += kunit/hooks.o
130+
# Some KUnit files (hooks.o) need to be built-in even when KUnit is a module,
131+
# so we can't just use obj-$(CONFIG_KUNIT).
132+
ifdef CONFIG_KUNIT
133+
obj-y += kunit/
138134
endif
139135

140136
ifeq ($(CONFIG_DEBUG_KOBJECT),y)

lib/kunit/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ kunit-objs += debugfs.o
1313
endif
1414

1515
# KUnit 'hooks' are built-in even when KUnit is built as a module.
16-
lib-y += hooks.o
16+
obj-y += hooks.o
1717

1818
obj-$(CONFIG_KUNIT_TEST) += kunit-test.o
1919

0 commit comments

Comments
 (0)