[llvm] Support: unlock Windows API support, switch to Windows 10 RS1+ APIs (PR #102240)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 04:51:19 PDT 2024


================
@@ -21,13 +21,16 @@
 #ifndef LLVM_SUPPORT_WINDOWSSUPPORT_H
 #define LLVM_SUPPORT_WINDOWSSUPPORT_H
 
+#if defined(__MINGW32__)
 // mingw-w64 tends to define it as 0x0502 in its headers.
 #undef _WIN32_WINNT
 #undef _WIN32_IE
 
 // Require at least Windows 7 API.
 #define _WIN32_WINNT 0x0601
----------------
mstorsjo wrote:

Leaving this value like this, forcing the headers to target explicitly Windows 7 when building with mingw, obviously would fail. So if we go this way, we'd need to bump this.

To use `FileRenameInfoEx`, we need a fairly new version of mingw-w64, to include the fix in https://github.com/mingw-w64/mingw-w64/commit/837c48d49611f78878fe2cfd1daf8ab0bf73ba16. But that fix is included in the mingw-w64 v12 release, so that's probably acceptable.

One bit of a gotcha, is that `_WIN32_WINNT` affects two aspects in Windows headers - it's both the maximum API level to expose in headers (so newer APIs may not be visible at all), but in some cases it also serves as the minimum target API version. E.g. some headers, such as `psapi.h` use `_WIN32_WINNT ` (or more precisely `NTDDI_VERSION`) to select a newer ABI construct, which only works on the version selected by `_WIN32_WINNT` - also CC @cjacek.

So by just bumping the value of `_WIN32_WINNT`, it's possible to end up requiring ABIs details from a newer version of Windows, even if the calling code isn't changed at all.

Anyway, I tested bumping this to `0x0A00`, and running the binaries on Windows 7, and it seems to work, so I guess it should be fine - but it may require being careful with some APIs at times.

In addition to requiring mingw-w64 v12, we'll also need to manually set `NTDDI_VERSION` to unlock things from mingw-w64 headers past the base version of Windows 10.0.

I amended your patch with these changes, to make it build with mingw-w64 headers, and still run on Windows 7 - see this commit: https://github.com/mstorsjo/llvm-project/commit/windows-rename-fix (This is based on top of #102307.)

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


More information about the llvm-commits mailing list