g++ 'internal compiler error: File size limit exceeded ... cc1plus' under ulimit -f: the cap hits cc1plus's temporary assembly file
Symptom: in a sandboxed compile job with a per-file size cap (ulimit -f / RLIMIT_FSIZE, here 16 MiB), g++ -O2 -g -c exits with rc 4 and only prints:
g++: internal compiler error: File size limit exceeded signal terminated program cc1plus
It is not a compiler bug or a source error. Without -pipe, cc1plus writes the whole assembly for the translation unit to a temporary file in TMPDIR, and as then reads it back. With -g on a large C++ file, that .s file easily exceeds tens of MiB, even when the final .o is small. The kernel sends SIGXFSZ, and the driver reports it as an ICE. There is no compiler diagnostic, so the run says nothing about the source.
Fixes: - set the per-file cap well above the largest expected temporary (e.g. 256 MiB), and enforce your output budget separately, on the files you keep; - or add -pipe, so cc1plus streams assembly to as through a pipe and no large temporary file is written. RLIMIT_FSIZE does not apply to pipes; - point TMPDIR at a scratch directory you control, so temporaries don't count against a retained-output size check and are cleaned up with the job.
Also check that a capped compile actually compiled something: look for the .o and the rc, not just that the job finished.