Bug 292869 - x11/nvidia-driver: fix build with clang 21
Summary: x11/nvidia-driver: fix build with clang 21
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Kevin Bowling
URL:
Keywords:
Depends on:
Blocks: 292067
  Show dependency treegraph
 
Reported: 2026-02-01 20:13 UTC by Dimitry Andric
Modified: 2026-02-07 11:56 UTC (History)
3 users (show)

See Also:
kbowling: maintainer-feedback+
kbowling: merge-quarterly-


Attachments
x11/nvidia-driver: fix build with clang 21 (3.24 KB, patch)
2026-02-01 20:26 UTC, Dimitry Andric
no flags Details | Diff
x11/nvidia-kmod: Fix build with clang21 (Probosed update) (818 bytes, patch)
2026-02-02 08:35 UTC, Tomoaki AOKI
junchoon: maintainer-approval? (x11)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric freebsd_committer freebsd_triage 2026-02-01 20:13:47 UTC
With clang 21 x11/nvidia-kmod fails to build, with errors similar to:

    cc  -O2 -pipe -fno-strict-aliasing -DNV_VERSION_STRING=\"580.126.09\" -DNV_SPECTRE_V2=1 -Werror=undef  -Werror -D_KERNEL -DKLD_MODULE -nostdinc  -Imachine -I/usr/src/sys/sys -I../common/inc -include /wrkdirs/usr/ports/x11/nvidia-kmod/work/NVIDIA-FreeBSD-x86_64-580.126.09/src/nvidia-modeset/opt_global.h -I. -I/usr/src/sys -I/usr/src/sys/contrib/ck/include -fno-common  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdebug-prefix-map=./machine=/usr/src/sys/amd64/include -fdebug-prefix-map=./x86=/usr/src/sys/x86/include -fdebug-prefix-map=./i386=/usr/src/sys/i386/include    -MD  -MF.depend.nvidia-modeset-freebsd.o -MTnvidia-modeset-freebsd.o -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fwrapv -fstack-protector  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wswitch -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length   -mno-aes -mno-avx  -std=gnu17 -c nvidia-modeset-freebsd.c -o nvidia-modeset-freebsd.o
    nvidia-modeset-freebsd.c:296:32: error: passing 'printf' format string where 'freebsd_kprintf' format string is expected [-Werror,-Wformat]
      296 |     ret = vsnprintf(str, size, format, ap);
          |                                ^

This is because the kernel headers rely on the `printf` attribute being
called `__printf__`, so that it can be redefined as `__freebsd_kprintf__`.

Change the `nvkms_snprintf` declaration in nvidia-modeset-os-interface.h
so they use `__printf__` instead, and add a similar attribute to
`nvkms_vsnprintf`.
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2026-02-01 20:26:24 UTC
Created attachment 267677 [details]
x11/nvidia-driver: fix build with clang 21
Comment 2 Tomoaki AOKI 2026-02-01 22:55:55 UTC
First report not to be stupidly committed.

As x11/nvidia-driver is the master (parent) port for x11/nvidia-driver-{304|340|390|470|devel} and patches under x11/nvidia-driver/files are shared between x11/nvidia-kmod, which is the master port for x11/nvidia-kmod-{304|340|390|470|devel}, this needs to be conditionalized.

I'll report back once I could take time for confirming thoroughly for all slave (child) ports.


For example:
/usr/ports/x11/nvidia-kmod-304# make
===>  License NVIDIA accepted by the user
===>   nvidia-kmod-304-304.137.1500506 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by nvidia-kmod-304-304.137.1500506 for building
===>  Extracting for nvidia-kmod-304-304.137.1500506
=> SHA256 Checksum OK for NVIDIA-FreeBSD-x86_64-304.137.tar.gz.
===>  Patching for nvidia-kmod-304-304.137.1500506
===>  Applying extra patch /usr/ports/x11/nvidia-kmod-304/work/extra-patch-src-Makefile
===>  Applying extra patch /usr/ports/x11/nvidia-kmod-304/work/extra-patch-src-nv-freebsd.h
===>  Applying extra patch /usr/ports/x11/nvidia-kmod-304/work/extra-patch-src-nvidia_dev.c
===>  Applying extra patch /usr/ports/x11/nvidia-kmod-304/work/extra-patch-src-nvidia_pci.c
===>  Applying extra patch /usr/ports/x11/nvidia-kmod-304/work/extra-patch-src-nvidia_subr.c
===>  Applying extra patch /usr/ports/x11/nvidia-kmod-304/work/extra-patch-src-nvidia_ctl.c
===>  Applying extra patch /usr/ports/x11/nvidia-kmod-304/work/extra-patch-src-nvidia_linux.c
===>  Applying extra patch /usr/ports/x11/nvidia-kmod-304/work/extra-patch-src-nv-misc.h
===>  Applying FreeBSD patches for nvidia-kmod-304-304.137.1500506 from /usr/ports/x11/nvidia-kmod-304/../nvidia-driver/files
File to patch:
Comment 3 Tomoaki AOKI 2026-02-02 08:35:15 UTC
Created attachment 267695 [details]
x11/nvidia-kmod: Fix build with clang21 (Probosed update)

If nvidia-modeset.ko alone is affected, it is NOT included in x11/nvidia-kmod-{304|340}.
And as of differences on prototypes, first proposed patch included in initial diff doesn't applicable for x11/nvidia-kmod-390.

This diff stops using additional patch and use REINPLACE_CMD instead to keep things as simple as possible.

Not actually tested using clang21, but the targed file is edited by REINPLACE_CMD as intended for all variants of x11/nvidia-kmod{-390|-470|-devel} and does not fail on x11/nvidia-kmod-{304|340}.

As x11/nvidia-driver{-304|-340|-390|-470|-devel} no longer include kernel module parts, this version should be sufficient. Targed file is used only for building nvidia-modeset.ko.
Comment 4 Tomoaki AOKI 2026-02-03 10:07:05 UTC
Dimitry, can you confirm my diff work on clang21?
Comment 5 Dimitry Andric freebsd_committer freebsd_triage 2026-02-03 18:55:57 UTC
(In reply to Tomoaki AOKI from comment #4)
Yes, this builds fine with clang 21. Thanks!
Comment 6 commit-hook freebsd_committer freebsd_triage 2026-02-06 18:43:38 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=9eb294e06a534009a55c3667e71fc7f1b73f711b

commit 9eb294e06a534009a55c3667e71fc7f1b73f711b
Author:     Tomoaki AOKI <junchoon@dec.sakura.ne.jp>
AuthorDate: 2026-02-06 18:40:37 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-02-06 18:42:49 +0000

    x11/nvidia-kmod: Fix build with clang 21

    PR:             292869
    Reported by:    dim
    Reviewed by:    ashafer

 x11/nvidia-kmod/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
Comment 7 Tomoaki AOKI 2026-02-07 00:09:45 UTC
(In reply to commit-hook from comment #6)
Confirmed. Thanks!

Dimitry, if you think this needs to be merged into 2026Q1,
please reopen this with comment.
Merge-quarterly flag is now denied and wouldn't be merged.
Maybe it would depend on the timeframe LLVM/Clang21 is
introduced into main branch of base and I think you're the best
person who know it.
Comment 8 Dimitry Andric freebsd_committer freebsd_triage 2026-02-07 10:56:49 UTC
(In reply to Tomoaki AOKI from comment #7)
Bug 292067 is the exp-run tracking bug. Before I can merge clang 21 into base, I have to get permission from portmgr, and it will probably take some time. So there is no hurry.

In any case, this patch is easy to merge later, if needed.
Comment 9 Tomoaki AOKI 2026-02-07 11:56:42 UTC
(In reply to Dimitry Andric from comment #8)
Alright.
Thanks for the clarification!