Subject: Re: linux-next: build failure after merge of the char-misc tree

From: Thadeu Lima de Souza Cascardo <[email-masked]>
Date: Thu, 1 May 2025 07:15:09 -0300

On Thu, May 01, 2025 at 04:45:01PM +1000, Stephen Rothwell wrote:
> Hi all,
> 
> After merging the char-misc tree, today's linux-next build (powerpc
> ppc64_defconfig) failed like this:
> 
> ld: warning: discarding dynamic section .glink
> ld: warning: discarding dynamic section .plt
> ld: linkage table error against `__kunit_do_failed_assertion'
> ld: stubs don't match calculated size
> ld: can not build stubs: bad value
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_duplicate_minor':
> misc_minor_kunit.c:(.text+0x180): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.text+0x1e4): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.text+0x240): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_twice':
> misc_minor_kunit.c:(.text+0x3e8): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.text+0x458): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o:misc_minor_kunit.c:(.text+0x4c4): more undefined references to `__kunit_do_failed_assertion' follow
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_find_minors':
> misc_minor_kunit.c:(.text+0xb3c): undefined reference to `kunit_log_append'
> ld: misc_minor_kunit.c:(.text+0xbac): undefined reference to `kunit_log_append'
> ld: misc_minor_kunit.c:(.text+0xc1c): undefined reference to `kunit_log_append'
> ld: misc_minor_kunit.c:(.text+0xc88): undefined reference to `kunit_log_append'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_duplicate_name':
> misc_minor_kunit.c:(.text+0xee4): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.text+0xf40): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.text+0xf90): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_duplicate_error':
> misc_minor_kunit.c:(.text+0x11b4): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.text+0x1210): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o:misc_minor_kunit.c:(.text+0x1264): more undefined references to `__kunit_do_failed_assertion' follow
> ld: drivers/misc/misc_minor_kunit.o:(.toc+0x0): undefined reference to `kunit_binary_assert_format'
> ld: drivers/misc/misc_minor_kunit.o:(.toc+0x8): undefined reference to `kunit_fail_assert_format'
> ld: drivers/misc/misc_minor_kunit.o:(.toc+0x10): undefined reference to `kunit_unary_assert_format'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_can_open':
> misc_minor_kunit.c:(.init.text+0xc0): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x134): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_static_basic':
> misc_minor_kunit.c:(.init.text+0x25c): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x2b4): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_conflict_reverse':
> misc_minor_kunit.c:(.init.text+0x408): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x414): undefined reference to `__kunit_abort'
> ld: misc_minor_kunit.c:(.init.text+0x46c): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x4d8): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x530): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x590): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x5e4): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o:misc_minor_kunit.c:(.init.text+0x63c): more undefined references to `__kunit_do_failed_assertion' follow
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_conflict':
> misc_minor_kunit.c:(.init.text+0x7a0): undefined reference to `__kunit_abort'
> ld: misc_minor_kunit.c:(.init.text+0x7f8): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x85c): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_dynamic_basic':
> misc_minor_kunit.c:(.init.text+0x994): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x9ec): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_collision_reverse':
> misc_minor_kunit.c:(.init.text+0xb20): undefined reference to `kunit_kmalloc_array'
> ld: misc_minor_kunit.c:(.init.text+0xba8): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0xc00): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0xc64): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0xcc0): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_collision':
> misc_minor_kunit.c:(.init.text+0xe30): undefined reference to `kunit_kmalloc_array'
> ld: misc_minor_kunit.c:(.init.text+0xe98): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0xea4): undefined reference to `__kunit_abort'
> ld: misc_minor_kunit.c:(.init.text+0xf04): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0xfac): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x1058): undefined reference to `__kunit_do_failed_assertion'
> ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_dynamic_only_range':
> misc_minor_kunit.c:(.init.text+0x1174): undefined reference to `kunit_kmalloc_array'
> ld: misc_minor_kunit.c:(.init.text+0x1200): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x1248): undefined reference to `__kunit_do_failed_assertion'
> ld: misc_minor_kunit.c:(.init.text+0x12ec): undefined reference to `__kunit_do_failed_assertion'
> 
> Caused by commit
> 
>   20acf4dd46e4 ("char: misc: make miscdevice unit test built-in only")
> 
> $ grep CONFIG_KUNIT .config
> CONFIG_KUNIT=m
> CONFIG_KUNIT_DEBUGFS=y
> CONFIG_KUNIT_FAULT_TEST=y
> CONFIG_KUNIT_TEST=m
> CONFIG_KUNIT_EXAMPLE_TEST=m
> CONFIG_KUNIT_ALL_TESTS=m
> CONFIG_KUNIT_DEFAULT_ENABLED=y
> CONFIG_KUNIT_AUTORUN_ENABLED=y
> $ grep CONFIG_TEST_MINOR .config
> $ 
> 
> I have used the char-misc tree from next-20250428 again.
> 
> -- 
> Cheers,
> Stephen Rothwell

This should fix it. I am sorry for still breaking all these builds. I have
tested this with the ppc64_defconfig (though that had required me to "fix" a
couple of warnings-turned-to-errors under arch/powerpc/). As I am trying to fix
this quickly, I haven't checked other configs. Again, I am sorry for the trouble.

Greg, I understand this may have caused you concern about merging this. Let
me know if you want to apply the fix below and have me submit it properly
or if we should wait for another cycle before applying a v5 after further
testing.

Cascardo.

>From 9e3150cb663e17b748cce6373c2f2b491a14b1a3 Mon Sep 17 00:00:00 2001
From: Thadeu Lima de Souza Cascardo <[email-masked]>
Date: Wed, 30 Apr 2025 08:30:47 -0300
Subject: [PATCH] char: misc: make miscdevice unit test require CONFIG_KUNIT=y

Otherwise, it allows for CONFIG_KUNIT=m, and that leads to build failures
like:

ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_duplicate_minor':
misc_minor_kunit.c:(.text+0x180): undefined reference to `__kunit_do_failed_assertion'
ld: misc_minor_kunit.c:(.text+0x1e4): undefined reference to `__kunit_do_failed_assertion'
ld: misc_minor_kunit.c:(.text+0x240): undefined reference to `__kunit_do_failed_assertion'
ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_test_twice':
misc_minor_kunit.c:(.text+0x3e8): undefined reference to `__kunit_do_failed_assertion'
ld: misc_minor_kunit.c:(.text+0x458): undefined reference to `__kunit_do_failed_assertion'
ld: drivers/misc/misc_minor_kunit.o:misc_minor_kunit.c:(.text+0x4c4): more undefined references to `__kunit_do_failed_assertion' follow
ld: drivers/misc/misc_minor_kunit.o: in function `miscdev_find_minors':
misc_minor_kunit.c:(.text+0xb3c): undefined reference to `kunit_log_append'
ld: misc_minor_kunit.c:(.text+0xbac): undefined reference to `kunit_log_append'
ld: misc_minor_kunit.c:(.text+0xc1c): undefined reference to `kunit_log_append'
ld: misc_minor_kunit.c:(.text+0xc88): undefined reference to `kunit_log_append'

[...]

Reported-by: Stephen Rothwell <[email-masked]>
Closes: https://lore.kernel.org/linux-next/[email-masked]/
Fixes: 45f0de4f8dc3 ("char: misc: add test cases")
Signed-off-by: Thadeu Lima de Souza Cascardo <[email-masked]>
---
 lib/Kconfig.debug | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 0117b852bd13..4049851e5115 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2513,7 +2513,7 @@ config TEST_IDA
 
 config TEST_MISC_MINOR
 	bool "miscdevice KUnit test" if !KUNIT_ALL_TESTS
-	depends on KUNIT
+	depends on KUNIT=y
 	default KUNIT_ALL_TESTS
 	help
 	  Kunit test for miscdevice API, specially its behavior in respect to
-- 
2.47.2