C++ modules: Handle ENOTSUP from posix_fallocate.
Fixes a failure when building GCC on FreeBSD with ZFS due to posix_fallocate returning ENOTSUP when creating module cache files.
GCC’s module support uses posix_fallocate to preallocate space for module cache files. On file systems like ZFS, posix_fallocate may return ENOTSUP if the operation is not supported. The compiler previously only checked for EINVAL, leading to build failures. This commit adds ENOTSUP to the error handling, resolving the issue on FreeBSD and other systems where posix_fallocate isn’t fully supported.
In Details
GCC's C++ module implementation (see module.cc) uses posix_fallocate in elf_out::create_mapping to optimize disk space allocation for module cache files (GCMs). The code already handled EINVAL from this call, falling back to ftruncate. This commit adds handling for ENOTSUP, which can occur on filesystems like ZFS. This is a relatively isolated issue within the module implementation.
For Context
posix_fallocate is a POSIX function that allows a program to preallocate disk space for a file. This can improve performance by preventing fragmentation and ensuring that enough space is available before writing. C++ modules are a way to organize code into logical units, improving build times and code organization. GCC uses module cache files (GCMs) to store compiled module information, which speeds up subsequent builds. This commit ensures that GCC gracefully handles cases where posix_fallocate is not supported by the underlying file system.