When running regular ('clang++ foo.cc') native compilation on Linux target in a typical configuration, an attempt to detect distribution type is performed 4 times at least:
- during an attempt to detect CUDA installation in clang::driver::CudaInstallationDetector::CudaInstallationDetector();
- during an instantiation of Linux-specific toolchain driver (clang::driver::toolchains::Linux::Linux());
- when special handling of '-faddrsig' is performed in clang::driver::tools::Clang::ConstructJob();
- finally when constructing a linker job in clang::driver::toolchains::Linux::getDynamicLinker().
Since distribution detection involves VFS, filesystem I/O and even parsing of file(s) contents, it looks desirable to cache the result and perform the whole procedure just once.
You can leave out the -1 since this isn't serialized.