Fixes NVIDIA DKMS modules failing to build on Arch Linux with an
internal compiler error: Segmentation fault — by raising the compiler's stack
limit, not by downgrading gcc.
A pacman -Syu pulls a new kernel or NVIDIA driver, and the DKMS rebuild fails:
inc/libraries/utils/nv_enum.h:397:20: internal compiler error: Segmentation fault
make[1]: *** [Makefile:203: _out/Linux_x86_64/kern_mem_sys_ga100.o] Error 1
make: *** [Makefile:34: src/nvidia/_out/Linux_x86_64/nv-kernel.o] Error 2
Error! Bad return status for module build on kernel: 6.18.38-1-lts (x86_64)
The pacman hooks then regenerate the initramfs without the nvidia modules:
==> ERROR: module not found: 'nvidia'
==> ERROR: module not found: 'nvidia_modeset'
==> ERROR: module not found: 'nvidia_uvm'
==> ERROR: module not found: 'nvidia_drm'
Reboot in that state and you land on a black screen.
This is not "the new gcc can't compile the NVIDIA source". gcc — both 15 and 16 —
segfaults while lexing the very large NV_ENUM_GENERATOR / NV_ENUM_DEF macro
in nv_enum.h. The backtrace sits in the C front-end, not the optimizer:
internal_error(char const*, ...)
c_lex_with_flags(tree_node**, unsigned long*, unsigned char*, int)
c_parse_file()
That is cc1 running out of stack. The default soft stack limit is 8 MB
(ulimit -s → 8192), and expanding that macro overflows it. Upstream this is
gcc bug c++/120257 (deeply
nested macros, marked WONTFIX — clang reports a clean "function scope depth
exceeded" instead of crashing).
It explains two things that usually confuse people:
- Why downgrading gcc "sometimes" helps. An older gcc happens to use slightly less stack and stays under 8 MB by luck. It is not a real fix and stops working the moment that gcc version regresses too.
- Why it fails for one kernel but not another in the same update. Different
kernel headers change the macro expansion just enough to cross the 8 MB line on
one kernel and not the other. Building with fewer parallel jobs (
-j1) can also slip under the line by chance — same reason, not a real fix.
Raise the stack limit before building:
ulimit -s unlimitedWith an unlimited stack the stock gcc builds the modules fine — no downgrade, no
gcc14/gcc15 shim, no clang. Everything else the script does is convenience and
safety around that one line.
Same machine, same nvidia-open-dkms 610.43.03, same kernel 7.1.3-arch1, same
stock gcc 16, same make -j20 — the only variable changed is the stack limit:
| stack limit | result |
|---|---|
| 8 MB (default) | internal compiler error: Segmentation fault |
ulimit -s unlimited |
builds, signs and installs cleanly |
So it is the stack — not the gcc version, not the parallelism (-j), not RAM/OC.
curl -Lo fix-nvidia-dkms https://gist.githubusercontent.com/axelhamil/8b1fec5447334cbc4a2d5eaa0679e17e/raw/fix-nvidia-dkms
chmod +x fix-nvidia-dkms
sudo ./fix-nvidia-dkmsRun it whenever a pacman -Syu leaves your NVIDIA DKMS build broken.
- Raises the stack limit (
ulimit -s unlimited) — the actual fix. - Auto-detects the installed nvidia DKMS version and every kernel that has headers.
- Skips kernels whose module is already built; rebuilds only the ones that failed.
- Re-runs
depmodfor every kernel that carries the module, so an already-built module that is missing frommodules.depstill gets picked up. - Regenerates every initramfs (
mkinitcpio -P). - Verifies each initramfs actually contains the nvidia modules before reporting success — so you never reboot into a black screen.
If a previous run built the module with dkms install --no-depmod (the Arch
pacman hook does this and defers depmod to the end), the module can be present in
/usr/lib/modules/<kver>/updates/dkms/ while modules.dep never learned about
it. Then dkms status says installed, modinfo -k <kver> nvidia says
Module nvidia not found, and mkinitcpio fails with module not found: nvidia.
The build is fine — only the index is stale. Rebuild it:
sudo depmod <kver> && sudo mkinitcpio -p linuxThe script now does this depmod pass unconditionally, so re-running it is enough
to recover from that state without a rebuild.
Force a specific compiler installed alongside (e.g. an older gcc):
sudo FIXNV_CC=gcc-14 ./fix-nvidia-dkmsArch Linux, RTX 50-series, nvidia-open-dkms, gcc 16, linux + linux-lts
kernels.
MIT