You're compiling something on a small VPS or CI runner, and gcc dies mid-build with "Internal error: Killed (program cc1)". No useful error message, no stack trace, just gone.
This happens because the OOM killer stepped in. When your system runs low on memory, Linux picks processes to terminate, and cc1 (the actual compiler process) is often a big memory consumer. So it gets killed first.
The fix is usually straightforward: add swap space temporarily.
# Create a 4GB swap file fallocate -l 4G /swapfile chmod 600 /swapfile mkswap /swapfile swapon /swapfile Run your build, then remove it when done:
swapoff /swapfile rm /swapfile Why does this work? Swap gives the kernel overflow space when physical RAM fills up. The compiler can use disk as temporary memory, which is slower but prevents the OOM killer from stepping in.
A few things to know:
When to use this:
- Small VPS instances (1-2GB RAM) building larger projects
- CI runners with memory limits
- One-off builds where you don't want to provision more RAM permanently
When not to use this:
- Production systems that are consistently memory-constrained (fix the root cause)
- If you're already using significant swap (something else is wrong)
- Performance-critical builds (swap is slow)
Why cc1 specifically?
The gcc frontend is lightweight. The cc1 process does the actual compilation work and allocates most of the memory. That's why you see "program cc1" in the error - that's the process that got terminated.
Checking if it helped:
After your build, look at /proc/meminfo or run free -h. If swap usage is high, you were genuinely memory-constrained. If swap barely touched, the OOM event might have been transient.
This is a band-aid fix, not a solution. If you're hitting this regularly, you probably need more RAM or a different build strategy (parallel jobs reduction, incremental builds, etc). But for occasional builds on constrained systems, temporary swap gets you unblocked in 30 seconds.
The swap file approach is cleaner than swap partitions for temporary needs - no fstab edits, no reboot required, just create-use-destroy.