Page MenuHomeFreeBSD

build: Fix for sporadic build failures.
Needs RevisionPublic

Authored by hselasky on May 21 2023, 4:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Mar 29, 5:34 AM
Unknown Object (File)
Feb 18 2024, 8:28 AM
Unknown Object (File)
Dec 22 2023, 9:51 PM
Unknown Object (File)
Dec 12 2023, 1:49 PM
Unknown Object (File)
Dec 4 2023, 12:37 AM
Unknown Object (File)
Oct 3 2023, 3:15 AM
Unknown Object (File)
Aug 11 2023, 4:27 PM
Unknown Object (File)
Jul 15 2023, 10:43 PM
Subscribers
None

Details

Summary

Autogenerated files must be located in the current object directory
and not the one belonging to the parent build. This prevents kernel
modules from using autogenerated files from the kernel build.
This is only an issue when <bsd.subdir.mk> is used.

MFC after: 1 week
Sponsored by: NVIDIA Networking

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

hselasky created this revision.

.NOPATH is usually a good idea for CLEANFILES etc

This revision is now accepted and ready to land.May 22 2023, 9:25 PM

I will check this a bit more before pushing and see if more developers have anything to say.

sys/conf/kern.mk
341

I thought the whole point of kernel builds was to use the files from the kerndir if they existed and only generate the fallback files if they do not. Doesn't this break that?

.if defined(KERNBUILDDIR)
.PATH: ${KERNBUILDDIR}
CFLAGS+=        -I${KERNBUILDDIR}
.for _src in ${SRCS:Mopt_*.h}
CLEANFILES+=    ${_src}
.if !target(${_src})
${_src}:
        ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET}
.endif
.endfor
.else
.for _src in ${SRCS:Mopt_*.h}
CLEANFILES+=    ${_src}
.if !target(${_src})
${_src}:
        :> ${.TARGET}
.endif
.endfor
.endif

is the part of kmod.mk that I think this breaks. kmod.mk includes kern.mk at the end, so this is very very wrong in my view.

imp requested changes to this revision.May 23 2023, 2:52 AM
This revision now requires changes to proceed.May 23 2023, 2:52 AM
sys/conf/kern.mk
341

For the kernel option files, it works like that.

But for some other files generated during build there seems to be a race (See D40191)

The kernel module generate the required files (See D40191) regardless of presence in the kernel build directory.

And because the kernel build directory is in the .PATH, then the kernel module build think the files are already generated and start building code, while at the same time generating these files locally to the kernel module build.

This opens up a window where the compiler may access files in the middle of being generated.

Most of the time it is OK, but sometimes it triggers.

Generated files are added to CLEAN and CLEANFILES (depending on kmod or kernel build - I added both, because this file is used by both).

Generated files are local to the current object directory, and when bsd.subdir.mk is used, then the .NOPATH prevents shadowing.

CFLAGS is also a keyword. Which directory to look at first. Local or parent.

sys/conf/kern.mk
341

But thr opt_*.h files should not come from . They should come from the kernel. So you've not fixed a race, but are now using the wrong file because there is no shadowing here: just two different scenarios the files are generated under. Yhe build would "work" but generate bad compiles solently.

sys/conf/kern.mk
341

Yes, correct. So CFLAGS must remain. And .NOPATH is probably the solution.