aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Windows
AgeCommit message (Collapse)AuthorFilesLines
10 daysFix comment from https://github.com/llvm/llvm-project/pull/158719 (#159157)Hiroshi Yamauchi1-2/+1
11 daysFix ExecuteAndWait with empty environment on Windows (#158719)Hiroshi Yamauchi1-0/+4
CreateProcessW requires that the environemnt block to be always double null-terminated even with an empty environemnt. https://learn.microsoft.com/en-us/windows/win32/procthread/environment-variables The attached test fails this way without the fix. C:\Users\hiroshi\upstream\llvm-project\llvm\unittests\Support\ProgramTest.cpp(697): error: Value of: ExecutionFailed Actual: true Expected: false Couldn't execute program 'C:\Users\hiroshi\upstream\llvm-project\build\unittests\Support\SupportTests.exe': The parameter is incorrect. (0x57)
12 days[CAS] Add MappedFileRegionArena (#114099)Steven Wu1-0/+17
Add MappedFileRegionArena which can be served as a file system backed persistent memory allocator. The allocator works like a BumpPtrAllocator, and is designed to be thread safe and process safe. The implementation relies on the POSIX compliance of file system and doesn't work on all file systems. If the file system supports lazy tail (doesn't allocate disk space if the tail of the large file is not used), user has more flexibility to declare a larger capacity. The allocator works by using a atomically updated bump ptr at a location that can be customized by the user. The atomic pointer points to the next available space to allocate, and the allocator will resize/truncate to current usage once all clients closed the allocator. Windows implementation contributed by: @hjyamauchi
2025-09-08Fix thread handle leak on Windows (#156854)Lukasz Mielicki1-8/+7
2025-08-20[FileSystem] Allow exclusive file lock (#114098)Steven Wu1-4/+8
Add parameter to file lock API to allow exclusive file lock. Both Unix and Windows support lock the file exclusively for write for one process and LLVM OnDiskCAS uses exclusive file lock to coordinate CAS creation.
2025-08-14[Support] Add mapped_file_region::sync(), equivalent to msync (#153632)Steven Wu1-0/+8
2025-07-31[Support] [Windows] Conditionally compile the SetThreadInformation calls ↵Martin Storsjö1-0/+2
(#151388) The declarations for this API are missing in older mingw-w64 headers (versions before v12). This API is also hidden if building with MS WinSDK if targeting versions before Windows 10. Check whether THREAD_POWER_THROTTLING_CURRENT_VERSION is defined before using this API; this constant is a #define in both WinSDK and mingw-w64.
2025-07-29Windows: use EcoQoS for ThreadPriority::Background (#148797)Tim Blechmann1-0/+60
The SetThreadInformation API allows threads to be scheduled on the most efficient cores on the most efficient frequency. Using this API for ThreadPriority::Background should make clangd-based IDEs a little less CPU hungry. --------- Co-authored-by: Alexandre Ganea <aganea@havenstudios.com>
2025-07-02[DLCov] Origin-Tracking: Enable collecting and symbolizing stack traces ↵Stephen Tozer1-0/+5
(#143591) This patch is part of a series that adds origin-tracking to the debugify source location coverage checks, allowing us to report symbolized stack traces of the point where missing source locations appear. This patch adds a pair of new functions in `signals.h` that can be used to collect and symbolize stack traces respectively. This has major implementation overlap with the existing stack trace collection/symbolizing methods, but the existing functions are specialized for dumping a stack trace to stderr when LLVM crashes, while these new functions are meant to be called repeatedly during the execution of the program, and therefore we need a separate set of functions.
2025-06-26[Support] Remove workarounds for building with mingw.org toolchains (#145683)Martin Storsjö1-64/+0
Assume that mingw builds are made with mingw-w64 headers. The old mingw.org distribution isn't even accessible at the moment, and their project hosting site (osdn.net) seems to have been down for a couple of years, and their old project hosting (at sourceforge.net) hasn't been updated since 2018.
2025-06-24[Support] Remove an outdated MinGW workaround (#145294)Martin Storsjö1-5/+0
mingw-w64 has had the _HEAPOK define since the initial commits in 2007; unclear when/where it was added for mingw.org headers, but it does seem to exist there as well (at least in versions from 2011). This workaround stems from 53fbecce6e8b7d1f024e3dc6df4160fe9a577ff1 from 2004 - it is no longer relevant today.
2025-06-09[Support][Cygwin] Fix handling of Process symbol lookup. (#143072)jeremyd20191-3/+3
In Unix/DynamicLibrary.inc, it was already known that Cygwin required use of `RTLD_DEFAULT` as the `Handle` parameter to `DLSym` to search all modules for a symbol. Unfortunately, RTLD_DEFAULT is defined as NULL, so the existing checks of the `Process` handle meant `DLSym` would never be called on Cygwin. Use the existing `&Invalid` sentinel instead of `nullptr` for the `Process` handle.
2025-06-06[llvm] Call hash_combine_range with ranges (NFC) (#143225)Kazu Hirata1-1/+1
We can now invoke hash_combine_range with a range.
2025-05-21[NFC][ADT/Support] Add {} for else when if body has {} (#140758)Rahul Joshi1-2/+4
2025-01-02[llvm][Support][Windows] Fix slash in path for remove_directories (#121448)Jinsong Ji1-1/+3
Before 925471ed903dad871042d7ed0bab89ab6566a564 remove_directories supports path with slash (instead of backslash). The ILCreateFromPathW in new implementation requires backslash path, so the call to remove_directories will fail if the path contains slash. This is to normalize the path to make sure remove_directories still support path with slash as well.
2024-12-13[llvm][Support][Windows] Refactored remove_directories() w/o CComPtr and ↵Dmitry Vasilyev1-4/+6
atlbase.h (#119843) This is the update of #118677. This patch fixes building with mingw.
2024-12-12[llvm][Support][Windows] Avoid crash calling remove_directories() (#118677)Dmitry Vasilyev1-8/+28
We faced an unexpected crash in SHELL32_CallFileCopyHooks() on the buildbot [lldb-remote-linux-win](https://lab.llvm.org/staging/#/builders/197/builds/1066). The host is Windows Server 2022 w/o any 3rd party shell extensions. See #118032 for more details. Based on [this article](https://devblogs.microsoft.com/oldnewthing/20120330-00/?p=7963).
2024-10-10[Support] Include Support/thread.h before api implementations (#111175)Thomas Fransham1-0/+1
This header was included after the implementations to work around an issue with FreeBSD, however, , this causes some issues when dllexport\explicit visibility attributes will be added to the headers on Windows, since the definitions need to see the declarations for the attributes to apply. This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on windows. --------- Co-authored-by: Tom Stellard <tstellar@redhat.com>
2024-07-30[Support] Silence warnings when retrieving exported functions (#97905)Alexandre Ganea2-18/+23
Since functions exported from DLLs are type-erased, before this patch I was seeing the new Clang 19 warning `-Wcast-function-type-mismatch`. This happens when building LLVM on Windows. Following discussion in https://github.com/llvm/llvm-project/commit/593f708118aef792f434185547f74fedeaf51dd4#commitcomment-143905744
2024-07-06Revert "[Support] Silence function cast warning when building with Clang ToT ↵Alexandre Ganea2-18/+0
targetting Windows" This reverts commit 593f708118aef792f434185547f74fedeaf51dd4.
2024-07-05[Support] Silence function cast warning when building with Clang ToT ↵Alexandre Ganea2-0/+18
targetting Windows
2024-06-03[Support] Handle delete_pending case for Windows fs::status (#90655)Jeremy Day1-4/+4
If a delete is pending on the file queried for status, a misleading `permission_denied` error code will be returned (this is the correct mapping of the error set by GetFileAttributesW). By querying the underlying NTSTATUS code via ntdll's RtlGetLastNtStatus, this case can be disambiguated. If this underlying error code indicates a pending delete, fs::status will return a new `pending_delete` error code to be handled by callers Fixes #89137
2024-04-30[Windows] Restrict searchpath of dbghelp.dll to System32 (#90520)jofrn1-1/+2
LoadLibraryW will lookup dlls in user directories if its search path is left unrestricted. This is a security vulnerability as one can name a shared library the same as that of a system dll in order to run arbitrary code when the shared library is loaded from the path in a user directory. This change modifies it to only search within sys32 when loading dbghelp.dll.
2024-04-05[Support][Windows] Use the original path if GetFinalPathNameByHandleW() ↵Dmitry Vasilyev1-1/+3
failed (#87749) The commit f11b056c (#76304) breaks `clang` and other tools if they are used from a RAMDrive. `GetFinalPathNameByHandleW()` may return 0 and GetLastError 0x28. This patch fixes that issue. Note `real_path()` uses `openFileForRead()` but it reports the error only if failed to open a file. Getting `RealPath` is optional functionality. BTW, `sys::fs::real_path()` resolves not only symlinks, but also network drives and virtual drives created by the `subst` tool. It may break an automation. It is better to detect symlinks and resolve only symlinks.
2024-03-26Return `errc::no_such_file_or_directory` in `fs::access` if ↵Jeremy Day1-0/+4
`GetFileAttributesW` fails (#83495) Fixes https://github.com/llvm/llvm-project/issues/83046 There is a race condition when calling `GetFileAttributesW` that can cause it to return `ERROR_ACCESS_DENIED` on a path which exists, which is unexpected for callers using this function to check for file existence by passing `AccessMode::Exist`. This was manifesting as a compiler crash on Windows downstream in the Swift compiler when using the `-index-store-path` flag (more information in https://github.com/apple/llvm-project/issues/8224). I looked for alternate APIs to avoid bringing in `shlwapi.h`, but didn't see any good candidates. I'm not tied at all to this solution, any feedback and alternative approaches are more than welcome.
2024-03-08[llvm][Support] Add and use errnoAsErrorCode (#84423)Michael Spencer2-3/+3
LLVM is inconsistent about how it converts `errno` to `std::error_code`. This can cause problems because values outside of `std::errc` compare differently if one is system and one is generic on POSIX systems. This is even more of a problem on Windows where use of the system category is just wrong, as that is for Windows errors, which have a completely different mapping than POSIX/generic errors. This patch fixes one instance of this mistake in `JSONTransport.cpp`. This patch adds `errnoAsErrorCode()` which makes it so people do not need to think about this issue in the future. It also cleans up a lot of usage of `errno` in LLVM and Clang.
2024-03-06Reland "[llvm][Support] Add support for executing a detached process ↵Connor Sughrue1-2/+5
(#81708)" (#83367) Relands #81708, which was reverted by f410f74cd5b26319b5796e0404c6a0f3b5cc00a5, now with a corrected unit test. Origionally the test failed on Windows when run with lit as `GetConsoleWindow` could not retrieve a window handle regardless of whether `DetachProcess` was `true` or `false`. The test now uses `GetStdHandle(STD_OUTPUT_HANDLE)` which does not rely on a console window existing. Original commit message below. Adds a new parameter, `bool DetachProcess` with a default option of `false`, to `llvm::sys::ExecuteNoWait`, which, when set to `true`, executes the specified program without a controlling terminal. Functionality added so that the module build daemon can be run without a controlling terminal.
2024-02-26Revert "[llvm][Support] Add support for executing a detached process (#81708)"cpsughrue1-5/+2
This reverts commit 86f6caa562255f81b93e72a501a926b17f5ad244. Unit test was failing on a few windows build bots
2024-02-26[llvm][Support] Add support for executing a detached process (#81708)Connor Sughrue1-2/+5
Adds a new parameter, `bool DetachProcess` with a default option of `false`, to `llvm::sys::ExecuteNoWait`, which, when set to `true`, executes the specified program without a controlling terminal. Functionality added so that the module build daemon can be run without a controlling terminal.
2024-01-31[llvm][Support] Support bright colors in raw_ostream (#80017)Timm Baeder1-1/+1
2024-01-23[Support] Avoid a VirtualBox shared folders mmap bug (#78597)Martin Storsjö1-2/+23
In acd8791c2619f2afc0347c1bff073b32fbffb5d6, a call to FlushFileBuffers was added to work around a rare kernel bug. In 3b9b4d2156673edda50584086fbfb0d66460b4d2, the scope of that workaround was limited, for performance reasons, as the flushes are quite expensive. On VirtualBox shared folders, closing a memory mapping that has been written to, also needs to be explicitly flushed, if renaming the output file before it is closed. Contrary to the kernel bug, this always happens on such mounts. In these cases, the output ends up as a file of the right size, but the contents are all zeros. The sequence to trigger the issue on the VirtualBox Shared Folders is this, summarized: file = CreateFile() mapping = CreateFileMapping(file) mem = MapViewOfFile() CloseHandle(mapping) write(mem) UnmapViewOfFile(mem) SetFileInformationByHandle(file, FileRenameInfo) CloseHandle(file) With this sequence, the output file always ends up with all zeros. See https://github.com/mstorsjo/llvm-mingw/issues/393 for a full reproduction example. To avoid this issue, call FlushFileBuffers() when the file may reside on a VitualBox shared folder. As the flushes are expensive, only do them when the output isn't on a local file system. The issue with VirtualBox shared folders could also be fixed by calling FlushViewOfFile before UnmapViewOfFile, and doing that could be slightly less expensive than FlushFileBuffers. Empirically, the difference between the two is very small though, and as it's not easy to verify whether switching FlushFileBuffers to FlushViewOfFile helps with the rare kernel bug, keep using FlushFileBuffers for both cases, for code simplicity. This fixes downstream bug https://github.com/mstorsjo/llvm-mingw/issues/393.
2024-01-15[Support] Windows Filesystem fs::status Conditionally Call GetFileAttributes ↵Haydn Trigg1-7/+9
(#78118) Rather than conditionally using the output from GetFileAttributesW move the branch to avoid calling GetFileAttributesW entirely if not required. This avoids hitting IO an extra time for a small performance improvement.
2023-12-26[Support] Resolve symlinks in `getMainExecutable()` on Windows (#76304)Alexandre Ganea1-1/+4
This makes the Windows implementation for `getMainExecutable()` behave the same as its Linux counterpart, in regards to symlinks. Previously, when using `cmake ... -DLLVM_USE_SYMLINKS=ON`, calling this function wouldn't resolve to the "real", non-symlinked path.
2023-12-09[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (#74916)Kazu Hirata1-2/+2
This patch renames {starts,ends}with to {starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. Since there are only a handful of occurrences, this patch skips the deprecation phase and simply renames them.
2023-11-03[Support] Use StringRef::starts_with/ends_with instead of ↵Simon Pilgrim2-4/+4
startswith/endswith. NFC. startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-09-12[Windows] Avoid using FileIndex for unique IDsMartin Storsjö1-16/+32
The FileIndex values returned from GetFileInformationByHandle are considered stable and uniquely identifying a file, as long as the handle is open. When handles are closed, there are no guarantees for their stability or uniqueness. On some file systems (such as NTFS), the indices are documented to be stable even across handles. But with some file systems, in particular network mounts, file indices can be reused very soon after handles are closed. When such file indices are used for LLVM's UniqueID, files are considered duplicates as soon as the filesystem driver happens to have used the same file index for the handle used to inspect the file. This caused widespread, non-obvious (seemingly random) breakage. This can happen e.g. if running on a directory that is shared via Remote Desktop or VirtualBox. To avoid the issue, use a hash of the canonicalized path for the file as unique identifier, instead of using FileIndex. This fixes https://github.com/llvm/llvm-project/issues/61401 and https://github.com/llvm/llvm-project/issues/22079. Performance wise, this adds (usually) one extra call to GetFinalPathNameByHandleW for each call to getStatus(). A test cases such as running clang-scan-deps becomes around 1% slower by this, which is considered tolerable. Change the equivalent() function to use getUniqueID instead of checking individual file_status fields. The equivalent(Twine,Twine,bool& result) function calls status() on each path successively, without keeping the file handles open, which also is prone to such false positives. This also gets rid of checks of other superfluous fields in the equivalent(file_status, file_status) function - the unique ID of a file should be enough (that is what is done for Unix anyway). This comes with one known caveat: For hardlinks, each name for the file now gets a different UniqueID, and equivalent() considers them different. While that's not ideal, occasional false negatives for equivalent() is usually that fatal (the cases where we strictly do need to deduplicate files with different path names are quite rare) compared to the issues caused by false positives for equivalent() (where we'd deduplicate and omit totally distinct files). The FileIndex is documented to be stable on NTFS though, so ideally we could maybe have used it in the majority of cases. That would require a heuristic for whether we can rely on FileIndex or not. We considered using the existing function is_local_internal for that; however that caused an unacceptable performance regression (clang-scan-deps became 38% slower in one test, even more than that in another test). Differential Revision: https://reviews.llvm.org/D155579
2023-08-17Optionally print symbolizer markup backtraces.Daniel Thornburgh1-0/+5
When the environment LLVM_ENABLE_SYMBOLIZER_MARKUP is set, if llvm-symbolizer fails or is disabled, this change will print a backtrace in llvm-symbolizer markup instead of falling back to in-process symbolization mechanisms. This allows llvm-symbolizer to be run on the output later to produce a high quality backtrace, even for fully-stripped LLVM utilities. Reviewed By: mcgrathr Differential Revision: https://reviews.llvm.org/D139750
2023-02-20[Support] Silence warning with Clang ToT.Alexandre Ganea1-1/+1
This fixes the following warning on Windows with latest Clang: ``` [160/3057] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.obj In file included from C:/git/llvm-project/llvm/lib/Support/Signals.cpp:260: C:/git/llvm-project/llvm/lib/Support/Windows/Signals.inc(834,15): warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare] if (RetCode == (0xE0000000 | EX_IOERR)) ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~ 1 warning generated.```
2023-02-17[Support] [Windows] Don't check file access time in equivalent(file_status, ↵R. Voggenauer1-2/+0
file_status) The sys::fs::equivalent(file_status, file_status) function is meant to judge whether two file_status structs denote the same individual file. On Unix, this is implemented by only comparing the st_dev and st_ino numbers (from stat), ignoring all other fields. On Windows, lacking reliable fields corresponding to st_dev and st_ino, equivalent(file_status, file_status) compares essentially all fields. However, since 1e39ef331b2b78baec84fdb577d497511cc46bd5 (https://reviews.llvm.org/D18456), file_status also contains the file access time. Including the file access time in equivalent(file_status, file_status) makes it possible to spuriously break. In particular, when invoking equivalent(Twine, Twine), with two paths, there's a race condition - the function calls status() on both input paths. Even if the two paths are the same, the comparison can fail, if the file was accessed between the two status() calls. Thus, it seems like the inclusion of the access time in equivalent(file_status, file_status) was a mistake. This race condition can cause spurious failures when linking with LLD/ELF, where LLD uses equivalent() to check whether a file exists within a specific sysroot, and that sysroot is accessed by other processes concurrently. This fixes downstream issue https://github.com/msys2/MINGW-packages/issues/15695. Differential Revision: https://reviews.llvm.org/D144172
2023-02-12[Support] Use llvm::popcount (NFC)Kazu Hirata1-1/+1
This should fix builds on Windows.
2023-02-10[llvm-driver] Reinvoke clang as described by llvm driver extra argsAlex Brachet1-1/+1
Differential Revision: https://reviews.llvm.org/D137800
2023-02-09[Support] Emulate SIGPIPE handling in raw_fd_ostream write for WindowsAndrew Ng1-3/+20
Prevent errors and crash dumps for broken pipes on Windows. Fixes: https://github.com/llvm/llvm-project/issues/48672 Differential Revision: https://reviews.llvm.org/D142224
2023-01-10Remove the ThreadLocal template from LLVM.Owen Anderson1-50/+0
This has been obsoleted by C++ thread_local for a long time. As far as I know, Xcode was the last supported toolchain to add support for C++ thread_local in 2016. As a precaution, use LLVM_THREAD_LOCAL which provides even greater backwards compatibility, allowing this to function even pre-C++11 versions of GCC. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D141349
2023-01-09Revert "Remove the ThreadLocal template from LLVM."Owen Anderson1-0/+50
This reverts commit 54d78b639b9c18b42abd4fac5c6e76105f06b3ef.
2023-01-09Remove the ThreadLocal template from LLVM.Owen Anderson1-50/+0
This has been obsoleted by C++ thread_local for a long time. As far as I know, Xcode was the last supported toolchain to add support for C++ thread_local in 2016. As a precaution, use LLVM_THREAD_LOCAL which provides even greater backwards compatibility, allowing this to function even pre-C++11 versions of GCC. Reviewed By: majnemer Differential Revision: https://reviews.llvm.org/D141347
2023-01-06[Support] On Windows 11 and Windows Server 2022, fix an affinity mask issue ↵Alexandre Ganea2-25/+75
on large core count machines Before Windows 11 and Windows Server 2022, only one 'processor group' is assigned by default to a starting process, then the program is responsible for dispatching its own threads on more 'processor groups'. That is what 8404aeb56a73ab24f9b295111de3b37a37f0b841 was doing, allowing LLVM tools to automatically use all hardware threads in the machine. After Windows 11 and Windows Server 2022, the OS takes care of that. This has an adverse effect reported in #56618 which is that using `GetProcessAffinityMask()` API in some edge cases seems buggy now. That API is used to detect if an affinity mask was set, and adjust accordingly the available threads for a ThreadPool. With this patch, on one hand, we let the OS dispatch threads on all 'processor groups', but only for Windows 11 & Windows Server 2022 and after. We retain the old behavior for older OS versions. On the other hand, a workaround was added to mitigate the `GetProcessAffinityMask()` issue described above (see Threading.inc, L226). Differential Revision: https://reviews.llvm.org/D138747
2022-12-22Support: Add polling option to sys::WaitMatt Arsenault1-2/+3
Currently the process is terminated after the timeout. Add an option to let the process resume after the timeout instead. https://reviews.llvm.org/D138952
2022-12-20[Support] Move TargetParsers to new componentArchibald Elliott1-35/+0
This is a fairly large changeset, but it can be broken into a few pieces: - `llvm/Support/*TargetParser*` are all moved from the LLVM Support component into a new LLVM Component called "TargetParser". This potentially enables using tablegen to maintain this information, as is shown in https://reviews.llvm.org/D137517. This cannot currently be done, as llvm-tblgen relies on LLVM's Support component. - This also moves two files from Support which use and depend on information in the TargetParser: - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting the current Host machine for info about it, primarily to support getting the host triple, but also for `-mcpu=native` support in e.g. Clang. This is fairly tightly intertwined with the information in `X86TargetParser.h`, so keeping them in the same component makes sense. - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains the target triple parser and representation. This is very intertwined with the Arm target parser, because the arm architecture version appears in canonical triples on arm platforms. - I moved the relevant unittests to their own directory. And so, we end up with a single component that has all the information about the following, which to me seems like a unified component: - Triples that LLVM Knows about - Architecture names and CPUs that LLVM knows about - CPU detection logic for LLVM Given this, I have also moved `RISCVISAInfo.h` into this component, as it seems to me to be part of that same set of functionality. If you get link errors in your components after this patch, you likely need to add TargetParser into LLVM_LINK_COMPONENTS in CMake. Differential Revision: https://reviews.llvm.org/D137838
2022-12-16[Support] llvm::Optional => std::optionalFangrui Song1-1/+1
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-14Support: Make Wait's SecondsToWait be std::optional [NFC]Matt Arsenault1-8/+5
I found the interaction between SecondsToWait and WaitUntilChildTerminates confusing. Rather than have a boolean to ignore the value of SecondsToWait, combine these into one Optional parameter.