Skip to content

Commit

Permalink
kunit: Fix 'hooks.o' build by recursing into kunit
Browse files Browse the repository at this point in the history
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 <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/linux-kselftest/CAHk-=wiEf7irTKwPJ0jTMOF3CS-13UXmF6Fns3wuWpOZ_wGyZQ@mail.gmail.com/
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
sulix authored and torvalds committed Feb 27, 2023
1 parent 5ca26d6 commit 32ff683
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,10 @@ CFLAGS_test_fpu.o += $(FPU_CFLAGS)

obj-$(CONFIG_TEST_LIVEPATCH) += livepatch/

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

ifeq ($(CONFIG_DEBUG_KOBJECT),y)
Expand Down
2 changes: 1 addition & 1 deletion lib/kunit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kunit-objs += debugfs.o
endif

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

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

Expand Down

0 comments on commit 32ff683

Please sign in to comment.