Page MenuHomeFreeBSD

Fix `make depend` in sys/modules
ClosedPublic

Authored by ngie on Aug 26 2015, 7:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 2 2026, 4:49 PM
Unknown Object (File)
Jan 31 2026, 10:38 AM
Unknown Object (File)
Jan 12 2026, 7:16 AM
Unknown Object (File)
Dec 17 2025, 4:45 AM
Unknown Object (File)
Nov 23 2025, 2:23 PM
Unknown Object (File)
Nov 21 2025, 12:47 AM
Unknown Object (File)
Nov 15 2025, 4:51 AM
Unknown Object (File)
Nov 14 2025, 10:14 PM

Details

Summary

Fix make depend in sys/modules

Test Plan

cd sys/modules; make depend

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

lwhsu retitled this revision from to Fix `make depend` in sys/modules.
lwhsu updated this object.
lwhsu edited the test plan for this revision. (Show Details)
lwhsu added reviewers: markm, delphij.

Hi,

Can I piggyback this commit and ask you to fix those modules too? (it should be the same fix):

mlx4ib
ibcore
if_tun
if_bridge
oce
cryptodev
padlock_rng
rdrand_rng
sppp
safe
tmpfs
hifn
syscons/dragon
ubsec
ufs
virtio/random
virtio/network
usb/smsc
netgraph/iface

I hope with your initial list and my list we've covered all broken modules.

Hi,

Can I piggyback this commit and ask you to fix those modules too? (it should be the same fix):
[...]
I hope with your initial list and my list we've covered all broken modules.

Sure, I did not found them are broken when doing make depend last time. May I know how do you find these?

In D3486#71362, @lwhsu wrote:

Hi,

Can I piggyback this commit and ask you to fix those modules too? (it should be the same fix):
[...]
I hope with your initial list and my list we've covered all broken modules.

Sure, I did not found them are broken when doing make depend last time. May I know how do you find these?

I've tried to build everything under modules (ALL_MODULES).

imp requested changes to this revision.Aug 26 2015, 1:29 PM
imp added a reviewer: imp.

The bigger problem is that sys/random.h includes opt_random.h.
Header files aren't supposed to include opt_foo.h.

This revision now requires changes to proceed.Aug 26 2015, 1:29 PM
In D3486#71373, @imp wrote:

The bigger problem is that sys/random.h includes opt_random.h.
Header files aren't supposed to include opt_foo.h.

Do you mean that we should remove opt_random.h from sys/random.h first then fix these modules?
Is there anything else need to take care of?

In D3486#71377, @lwhsu wrote:
In D3486#71373, @imp wrote:

The bigger problem is that sys/random.h includes opt_random.h.
Header files aren't supposed to include opt_foo.h.

Do you mean that we should remove opt_random.h from sys/random.h first then fix these modules?
Is there anything else need to take care of?

We should remove opt_random.h from sys/random.h and move the affected options to opt_global.h.
The modules won't need fixing if we do this.

lwhsu edited edge metadata.

It turns out just removing opt_random.h from sys/random.h works fine.
I've done buildworld & buildkernel tests.

Hmm, this might break when using options RANDOM_YARROW or options RANDOM_LOADABLE, is it OK to just set them to opt_global.h in sys/conf/options ?

Except it doesn't. The RANDOM_ parameters are now never defined. This does 'work' in the 'it compiles' sense,
but it doesn't allow any of them to take effect.

This is also needed:

diff -r 4f344ba5ec47 sys/conf/options
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -947,11 +947,11 @@ RCTL		opt_global.h
 # Random number generator(s)
 # Which CSPRNG hash we get.
 # If Yarrow is not chosen, Fortuna is selected.
-RANDOM_YARROW	opt_random.h
+RANDOM_YARROW	opt_global.h
 # With this, no entropy processor is loaded, but the entropy
 # harvesting infrastructure is present. This means an entropy
 # processor may be loaded as a module.
-RANDOM_LOADABLE	opt_random.h
+RANDOM_LOADABLE	opt_global.h
 # This turns on high-rate and potentially expensive harvesting in
 # the uma slab allocator.
 RANDOM_ENABLE_UMA	opt_global.h
lwhsu edited edge metadata.

Move RANDOM_YARROW and RANDOM_LOADABLE to opt_global.h

imp edited edge metadata.

This looks like it will work. Make sure by defining both RANDOM_LOADABLE and RANDOM_YARROW in a kernel config and seeing if you hit the above #error.
If so, commit away. If you don't have a commit bit, let me know and I'll do the deed.

This revision is now accepted and ready to land.Aug 27 2015, 7:34 PM

make -DALL_MODULES buildkernel with options RANDOM_LOADABLE in KERNCONF
got following error:

--- kernel.debug ---
linking kernel.debug
ivy.o: In function `rdrand_modevent':
/usr/src/sys/dev/random/ivy.c:115: undefined reference to `random_source_deregister'
/usr/src/sys/dev/random/ivy.c:108: undefined reference to `random_source_register'
nehemiah.o: In function `nehemiah_modevent':
/usr/src/sys/dev/random/nehemiah.c:136: undefined reference to `random_source_deregister'
/usr/src/sys/dev/random/nehemiah.c:127: undefined reference to `random_source_register'
*** [kernel.debug] Error code 1

I am working on fixing this.

Hi

I’m nearly there - there are a few more of them too!

M

In D3486#72244, @markm wrote:

I’m nearly there - there are a few more of them too!

Thanks, I'm having trouble with how to deal with these functions only exist when _KENREL defined.

Please update this patch (although I don't know if non-original author can) and I can help to test, or please just commit it.

This change is more invasive than it potentially needs to be: https://reviews.freebsd.org/D3594

In D3486#74191, @ngie wrote:

This change is more invasive than it potentially needs to be: https://reviews.freebsd.org/D3594

No, this change is correct. Your change is wrong. It breaks building modules. Sorry, try again.

In D3486#74237, @imp wrote:
In D3486#74191, @ngie wrote:

This change is more invasive than it potentially needs to be: https://reviews.freebsd.org/D3594

No, this change is correct. Your change is wrong. It breaks building modules. Sorry, try again.

It looks like it works to me. make tinderbox is in progress on ref11-amd64:

[ngie@fbsd11 /usr/src/git/sys/modules/random_fortuna]$ make obj
/usr/obj/usr/src/git/sys/modules/random_fortuna created for /usr/src/git/sys/modules/random_fortuna
[ngie@fbsd11 /usr/src/git/sys/modules/random_fortuna]$ make depend
machine -> /usr/src/git/sys/amd64/include
x86 -> /usr/src/git/sys/x86/include
:> opt_param.h
awk -f /usr/src/git/sys/modules/random_fortuna/../../tools/makeobjops.awk /usr/src/git/sys/kern/bus_if.m -h
awk -f /usr/src/git/sys/modules/random_fortuna/../../tools/makeobjops.awk /usr/src/git/sys/kern/device_if.m -h
:> opt_ddb.h
rm -f .depend
mkdep -f .depend -a -nostdinc -DRANDOM_LOADABLE -D_KERNEL -DKLD_MODULE -I. -I/usr/src/git/sys/modules/random_fortuna/../.. -Dprintf=freebsd_kprintf -std=iso9899:1999 /usr/src/git/sys/modules/random_fortuna/../../dev/random/randomdev.c /usr/src/git/sys/modules/random_fortuna/../../dev/random/hash.c /usr/src/git/sys/modules/random_fortuna/../../dev/random/fortuna.c
[ngie@fbsd11 /usr/src/git/sys/modules/random_fortuna]$ make all
cc -O2 -pipe -fno-strict-aliasing -O2 -DRANDOM_LOADABLE -Werror -D_KERNEL -DKLD_MODULE -nostdinc -I. -I/usr/src/git/sys/modules/random_fortuna/../.. -fno-common -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -Dprintf=freebsd_kprintf -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -Wno-error-pointer-sign -mno-aes -mno-avx -std=iso9899:1999 -c /usr/src/git/sys/modules/random_fortuna/../../dev/random/randomdev.c -o randomdev.o
cc -O2 -pipe -fno-strict-aliasing -O2 -DRANDOM_LOADABLE -Werror -D_KERNEL -DKLD_MODULE -nostdinc -I. -I/usr/src/git/sys/modules/random_fortuna/../.. -fno-common -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -Dprintf=freebsd_kprintf -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -Wno-error-pointer-sign -mno-aes -mno-avx -std=iso9899:1999 -c /usr/src/git/sys/modules/random_fortuna/../../dev/random/hash.c -o hash.o
cc -O2 -pipe -fno-strict-aliasing -O2 -DRANDOM_LOADABLE -Werror -D_KERNEL -DKLD_MODULE -nostdinc -I. -I/usr/src/git/sys/modules/random_fortuna/../.. -fno-common -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -Dprintf=freebsd_kprintf -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -Wno-error-pointer-sign -mno-aes -mno-avx -std=iso9899:1999 -c /usr/src/git/sys/modules/random_fortuna/../../dev/random/fortuna.c -o fortuna.o
ld -d -warn-common -r -d -o random_fortuna.ko randomdev.o hash.o fortuna.o
:> export_syms
awk -f /usr/src/git/sys/modules/random_fortuna/../../conf/kmod_syms.awk random_fortuna.ko export_syms | xargs -J% objcopy % random_fortuna.ko
objcopy --strip-debug random_fortuna.ko
[ngie@fbsd11 /usr/src/git/sys/modules/random_fortuna]$ uname -a
FreeBSD fbsd11 11.0-CURRENT FreeBSD 11.0-CURRENT #2 r287529+e3e7b86(isilon-atf): Mon Sep 7 00:12:58 PDT 2015 ngie@fbsd11:/usr/obj/usr/src/git/sys/GENERIC-NODEBUG amd64

It works, in that it compiles. That's never been an acceptable definition of 'works'

Look down a few lines. If you define RANDOM_ENABLE_UMA it won't be picked up by the drivers.
There have been, at other times, other RANDOM_ENABLE_* options, and there will be in the
future. Your change makes sure they are never defined.

That's broken. that's the whole reason I moved them to opt_global.h in the other review.

ngie added a reviewer: lwhsu.

Re-running make tinderbox with the above patch.

In D3486#74245, @ngie wrote:

Re-running make tinderbox with the above patch.

The above patch passed make tinderbox on ref11-amd64. I'm going to commit the above patch soon.

Found this issue on 10.1-RELEASE box building HEAD r290336. The proposed patch didn't fix anything and the problem turned out to be an old kernel-toolchain.

After running building kernel-toolchain the error below disappeared.

Capturing here for posterity as its the the first relevant search result for this error.

--- kernel.full ---
linking kernel.full
random_infra.o:(.data+0xb0): undefined reference to `random_alg_context'
kern_mib.o: In function `sysctl_kern_arnd':
/usr/src/sys/kern/kern_mib.c:164: undefined reference to `read_random'
arc4random.o: In function `arc4_randomstir':
/usr/src/sys/libkern/arc4random.c:61: undefined reference to `read_random'
tcp_subr.o: In function `tcp_new_isn':
/usr/src/sys/netinet/tcp_subr.c:1756: undefined reference to `read_random'
key.o: In function `key_randomfill':
/usr/src/sys/netipsec/key.c:4416: undefined reference to `read_random'
/usr/src/sys/netipsec/key.c:4416: undefined reference to `read_random'
xform_esp.o:/usr/src/sys/netipsec/xform_esp.c:802: more undefined references to `read_random' follow
ivy.o: In function `rdrand_modevent':
/usr/src/sys/dev/random/ivy.c:115: undefined reference to `random_source_deregister'
/usr/src/sys/dev/random/ivy.c:108: undefined reference to `random_source_register'
nehemiah.o: In function `nehemiah_modevent':
/usr/src/sys/dev/random/nehemiah.c:136: undefined reference to `random_source_deregister'
/usr/src/sys/dev/random/nehemiah.c:127: undefined reference to `random_source_register'
*** [kernel.full] Error code 1
In D3486#85423, @smh wrote:

Found this issue on 10.1-RELEASE box building HEAD r290336. The proposed patch didn't fix anything and the problem turned out to be an old kernel-toolchain.

After running building kernel-toolchain the error below disappeared.

Capturing here for posterity as its the the first relevant search result for this error.

--- kernel.full ---
linking kernel.full
random_infra.o:(.data+0xb0): undefined reference to `random_alg_context'
kern_mib.o: In function `sysctl_kern_arnd':
/usr/src/sys/kern/kern_mib.c:164: undefined reference to `read_random'
arc4random.o: In function `arc4_randomstir':
/usr/src/sys/libkern/arc4random.c:61: undefined reference to `read_random'
tcp_subr.o: In function `tcp_new_isn':
/usr/src/sys/netinet/tcp_subr.c:1756: undefined reference to `read_random'
key.o: In function `key_randomfill':
/usr/src/sys/netipsec/key.c:4416: undefined reference to `read_random'
/usr/src/sys/netipsec/key.c:4416: undefined reference to `read_random'
xform_esp.o:/usr/src/sys/netipsec/xform_esp.c:802: more undefined references to `read_random' follow
ivy.o: In function `rdrand_modevent':
/usr/src/sys/dev/random/ivy.c:115: undefined reference to `random_source_deregister'
/usr/src/sys/dev/random/ivy.c:108: undefined reference to `random_source_register'
nehemiah.o: In function `nehemiah_modevent':
/usr/src/sys/dev/random/nehemiah.c:136: undefined reference to `random_source_deregister'
/usr/src/sys/dev/random/nehemiah.c:127: undefined reference to `random_source_register'
*** [kernel.full] Error code 1

What are your random(4)-related kernel options? Are you building random(4) and friends as modules, or statically into the kernel?

In D3486#85431, @ngie wrote:

...

What are your random(4)-related kernel options? Are you building random(4) and friends as modules, or statically into the kernel?

The reason why I ask is because:

  1. Building modules doesn't affect linking kernel.debug, etc.
  2. My looking at sys/conf suggests that (with your error message above) there might be some hidden, unarticulated dependencies in the files, and some additional pollution that was added to libkern, kern, net*, etc that are causing the before mentioned build errors.
In D3486#85431, @ngie wrote:

What are your random(4)-related kernel options? Are you building random(4) and friends as modules, or statically into the kernel?

Nothing specific:

grep -ri RANDOM sys/amd64/conf/GENERIC sys/amd64/conf/MULTIPLAY*
sys/amd64/conf/GENERIC:device           random                  # Entropy device