[llvm] [CMake] Remove some always-true HAVE_XXX_H (PR #123087)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 16 02:45:43 PST 2025


================
@@ -44,9 +44,7 @@
 #include <system_error>
 #include <vector>
 
-#ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
----------------
mstorsjo wrote:

This change, quite surprisingly, broke building LLDB for a mingw target: https://github.com/mstorsjo/llvm-mingw/actions/runs/12799882284/job/35692046639

The culprit seems to be this particular change; `FileSystem.h` doesn't include `config.h` (only `llvm-config.h`), so in many (but not all) cases of including this header, `HAVE_SYS_STAT_H` was not defined, and thus `<sys/stat.h>` wasn't included.

It seems like the `<sys/stat.h>` include here is (mostly?) unnecessary - I've successfully rebuilt LLVM (llvm+clang+lld+lldb+clang-tools-extra) for both macOS and Linux, with this include entirely removed.

The reason for why it broke LLDB for mingw targets, is that LLDB contains a structure with a field named `fstat`: https://github.com/llvm/llvm-project/blob/llvmorg-19.1.7/lldb/source/Plugins/Process/Utility/RegisterContext_x86.h#L271
The mingw-w64 `sys/stat.h` header contains a `#define fstat _fstat64`: https://github.com/mingw-w64/mingw-w64/blob/v12.0.0/mingw-w64-headers/crt/sys/stat.h#L280

This define would work fine if it would be included before the LLDB struct declaration, but not when it gets included between the struct declaration and use.

I guess the most straightforward fix is to just drop the include of `<sys/stat.h>` here which doesn't seem to be needed in practice?

https://github.com/llvm/llvm-project/pull/123087


More information about the llvm-commits mailing list