summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Windows/Program.inc
AgeCommit message (Collapse)Author
2025-11-10Remove unused standard headers: <string>, <optional>, <numeric>, <tuple> ↵serge-sans-paille
(#167232)
2025-09-16Fix comment from https://github.com/llvm/llvm-project/pull/158719 (#159157)Hiroshi Yamauchi
2025-09-16Fix ExecuteAndWait with empty environment on Windows (#158719)Hiroshi Yamauchi
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)
2024-03-08[llvm][Support] Add and use errnoAsErrorCode (#84423)Michael Spencer
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 Sughrue
(#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)"cpsughrue
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 Sughrue
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.
2022-12-22Support: Add polling option to sys::WaitMatt Arsenault
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-14Support: Make Wait's SecondsToWait be std::optional [NFC]Matt Arsenault
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.
2022-12-01Support: Convert Program APIs to std::optionalMatt Arsenault
2022-11-26[Support] Apply clang-format on .inc files. NFC.Alexandre Ganea
Apply clang-format on llvm/lib/Support/Windows/ and llvm/lib/Support/Unix/ since .inc files in these folders aren't picked up by default. Eventually we need to add this extension in the monorepo .clang-format file. Differential Revision: https://reviews.llvm.org/D138714
2022-03-11Cleanup include: TableGenserge-sans-paille
This also includes a few cleanup from Support. Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121331
2022-01-11Support: Avoid SmallVector::set_size() in Windows codeDuncan P. N. Exon Smith
Replace a few `reserve()` / `set_size()` pairs with `resize_for_overwrite()` / `truncate()` in the platform-specific code for Windows. Differential Revision: https://reviews.llvm.org/D115390
2021-11-05[Support] [Windows] Convert paths to the preferred formMartin Storsjö
This normalizes most paths (except ones input from the user as command line arguments) into the preferred form, if `real_style()` evaluates to `windows_forward`. Differential Revision: https://reviews.llvm.org/D111880
2021-04-16[SystemZ][z/OS][Windows] Add new functions that set Text/Binary mode for ↵Abhina Sreeskantharajan
Stdin and Stdout based on OpenFlags On Windows, we want to open a file in Binary mode if OF_CRLF bit is not set. On z/OS, we want to open a file in Binary mode if the OF_Text bit is not set. This patch creates two new functions called ChangeStdinMode and ChangeStdoutMode which will take OpenFlags as an arg to determine which mode to set stdin and stdout to. This will enable patches like https://reviews.llvm.org/D100056 to not affect Windows when setting the OF_Text flag for raw_fd_streams. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D100130
2021-04-06[SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag ↵Abhina Sreeskantharajan
instead of OF_Text Problem: On SystemZ we need to open text files in text mode. On Windows, files opened in text mode adds a CRLF '\r\n' which may not be desirable. Solution: This patch adds two new flags - OF_CRLF which indicates that CRLF translation is used. - OF_TextWithCRLF = OF_Text | OF_CRLF indicates that the file is text and uses CRLF translation. Developers should now use either the OF_Text or OF_TextWithCRLF for text files and OF_None for binary files. If the developer doesn't want carriage returns on Windows, they should use OF_Text, if they do want carriage returns on Windows, they should use OF_TextWithCRLF. So this is the behaviour per platform with my patch: z/OS: OF_None: open in binary mode OF_Text : open in text mode OF_TextWithCRLF: open in text mode Windows: OF_None: open file with no carriage return OF_Text: open file with no carriage return OF_TextWithCRLF: open file with carriage return The Major change is in llvm/lib/Support/Windows/Path.inc to only set text mode if the OF_CRLF is set. ``` if (Flags & OF_CRLF) CrtOpenFlags |= _O_TEXT; ``` These following files are the ones that still use OF_Text which I left unchanged. I modified all these except raw_ostream.cpp in recent patches so I know these were previously in Binary mode on Windows. ./llvm/lib/Support/raw_ostream.cpp ./llvm/lib/TableGen/Main.cpp ./llvm/tools/dsymutil/DwarfLinkerForBinary.cpp ./llvm/unittests/Support/Path.cpp ./clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp ./clang/lib/Frontend/CompilerInstance.cpp ./clang/lib/Driver/Driver.cpp ./clang/lib/Driver/ToolChains/Clang.cpp Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D99426
2021-03-25[Support][Windows] Make sure only executables are found by ↵Markus Böck
sys::findProgramByName The function utilizes Windows' SearchPathW function, which as I found out today, may also return directories. After looking at the Unix implementation of the file I found that it contains a check whether the found path is also executable. While fixing the Windows implementation, I also learned that sys::fs::access returns successfully when querying whether directories are executable, which the Unix version does not. This patch makes both of these functions equivalent to their Unix implementation and insures that any path returned by sys::findProgramByName on Windows may only be executable, just like the Unix implementation. The equivalent additions I have made to the Windows implementation, in the Unix implementation are here: sys::findProgramByName: https://github.com/llvm/llvm-project/blob/39ecfe614350fa5db7b8f13f81212f8e3831a390/llvm/lib/Support/Unix/Program.inc#L90 sys::fs::access: https://github.com/llvm/llvm-project/blob/c2a84771bb63947695ea50b89160c02b36fb634d/llvm/lib/Support/Unix/Path.inc#L608 I encountered this issue when running the LLVM testsuite. Commands of the form not test ... would fail to correctly execute test.exe, which is part of GnuWin32, as it actually tried to execute a folder called test, which happened to be in a directory on my PATH. Differential Revision: https://reviews.llvm.org/D99357
2021-01-14Re-land [Support] On Windows, take the affinity mask into accountAlexandre Ganea
The number of hardware threads available to a ThreadPool can be limited if setting an affinity mask. For example: > start /B /AFFINITY 0xF lld-link.exe ... Would let LLD only use 4 hyper-threads. Previously, there was an outstanding issue on Windows Server 2019 on dual-CPU machines, which was preventing from using both CPU sockets. In normal conditions, when no affinity mask was set, ProcessorGroup::AllThreads was different from ProcessorGroup::UsableThreads. The previous code in llvm/lib/Support/Windows/Threading.inc L201 was improperly assuming those two values to be equal, and consequently was limiting the execution to only one CPU socket. Differential Revision: https://reviews.llvm.org/D92419
2021-01-13Revert "[Support] On Windows, take the affinity mask into account"Alexandre Ganea
This reverts commit 336ab2d51dfdd5ca09c2a9c506453db4fe653584.
2021-01-13[Support] On Windows, take the affinity mask into accountAlexandre Ganea
The number of hardware threads available to a ThreadPool can be limited if setting an affinity mask. For example: > start /B /AFFINITY 0xF lld-link.exe ... Would let LLD only use 4 hyper-threads. Previously, there was an outstanding issue on Windows Server 2019 on dual-CPU machines, which was preventing from using both CPU sockets. In normal conditions, when no affinity mask was set, ProcessorGroup::AllThreads was different from ProcessorGroup::UsableThreads. The previous code in llvm/lib/Support/Windows/Threading.inc L201 was improperly assuming those two values to be equal, and consequently was limiting the execution to only one CPU socket. Differential Revision: https://reviews.llvm.org/D92419
2021-01-06[llvm] Use llvm::append_range (NFC)Kazu Hirata
2020-07-23[Windows] Fix limit on command line sizeSerge Pavlov
This reapplies commit d4020ef7c474, reverted in ac0edc55887b because it broke build of LLDB. This commit contains appropriate changes for LLDB. The original commit message is below. Documentation on CreateProcessW states that maximal size of command line is 32767 characters including ternimation null character. In the function llvm::sys::commandLineFitsWithinSystemLimits this limit was set to 32768. As a result if command line was exactly 32768 characters long, a response file was not created and CreateProcessW was called with too long command line. Differential Revision: https://reviews.llvm.org/D83772
2020-07-22Revert "[Windows] Fix limit on command line size"Serge Pavlov
This reverts commit d4020ef7c474b5e695d77aa100d7f68dc0c66b4e. It broke LLDB buildbot: http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/17702.
2020-07-21[Windows] Fix limit on command line sizeSerge Pavlov
Documentation on CreateProcessW states that maximal size of command line is 32767 characters including ternimation null character. In the function llvm::sys::commandLineFitsWithinSystemLimits this limit was set to 32768. As a result if command line was exactly 32768 characters long, a response file was not created and CreateProcessW was called with too long command line. Differential Revision: https://reviews.llvm.org/D83772
2020-06-20[Support] Fix building for mingw on a case sensitive file systemMartin Storsjö
This fixes cross building on a case sensitive file system after 2e613d2ded2c465bd06bd3cac30ffb4576bf72cc. (The official Windows SDKs don't have self-consistent casing and can't be used as such on case sentisive file systems without case fixups, while mingw headers consistently use lower case.)
2020-06-17[Support] Get process statistics in ExecuteAndWait and WaitSerge Pavlov
The functions sys::ExcecuteAndWait and sys::Wait now have additional argument of type pointer to structure, which is filled with process execution statistics upon process termination. These are total and user execution times and peak memory consumption. By default this argument is nullptr so existing users of these function must not change behavior. Differential Revision: https://reviews.llvm.org/D78901
2020-03-19[Support] Improve Windows widenPath and add support for long UNC pathsAndrew Ng
Check the path length limit against the length of the UTF-16 version of the input rather than the UTF-8 equivalent, as the UTF-16 length may be shorter. Move widenPath from the llvm::sys::path namespace in Path.h to the llvm::sys::windows namespace in WindowsSupport.h. Only use the reduced path length limit for create directory. Canonicalize using sys::path::remove_dots(). Differential Revision: https://reviews.llvm.org/D75372
2020-02-28llvm-ar: Fix MinGW compilationHans Wennborg
llvm-ar is using CompareStringOrdinal which is available only starting with Windows Vista (WINVER 0x600). Fix this by hoising WindowsSupport.h, which sets _WIN32_WINNT to 0x0601, up to llvm/include/llvm/Support and use it in llvm-ar. Patch by Cristian Adam! Differential revision: https://reviews.llvm.org/D74599
2020-01-29[Support] Fix implicit std::string conversions on Win32.Benjamin Kramer
2020-01-07Fix issues reported by -Wrange-loop-analysis when building with latest Clang ↵Alexandre Ganea
(trunk). NFC. Fixes warning: loop variable 'E' of type 'const llvm::StringRef' creates a copy from type 'const llvm::StringRef' [-Wrange-loop-analysis]
2019-08-05Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFCFangrui Song
F_{None,Text,Append} are kept for compatibility since r334221. llvm-svn: 367800
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-11-06[Windows] Simplify WindowsSupport.hReid Kleckner
Sink Windows version detection code from WindowsSupport.h to Path.inc. These functions don't need to be inlined. I randomly picked Process.inc for the Windows version helpers, since that's the most related file. Sink MakeErrMsg to Program.inc since it's the main client. Move those functions into the llvm namespace, and delete the scoped handle copy and assignment operators. Reviewers: zturner, aganea Differential Revision: https://reviews.llvm.org/D54182 llvm-svn: 346280
2018-09-11[Support] Quote arguments containing \n on WindowsReid Kleckner
Fixes at_file.c test failure caused by r341988. We may want to change how we treat \n in our tokenizer, but this is probably a good fix regardless, since we can invoke all kinds of programs with different interpretations of the command line quoting rules. llvm-svn: 341992
2018-06-12Refactor ExecuteAndWait to take StringRefs.Zachary Turner
This simplifies some code which had StringRefs to begin with, and makes other code more complicated which had const char* to begin with. In the end, I think this makes for a more idiomatic and platform agnostic API. Not all platforms launch process with null terminated c-string arrays for the environment pointer and argv, but the api was designed that way because it allowed easy pass-through for posix-based platforms. There's a little additional overhead now since on posix based platforms we'll be takign StringRefs which were constructed from null terminated strings and then copying them to null terminate them again, but from a readability and usability standpoint of the API user, I think this API signature is strictly better. llvm-svn: 334518
2018-06-10Attempt 3: Resubmit "[Support] Expose flattenWindowsCommandLine."Zachary Turner
I took some liberties and quoted fewer characters than before, based on an article from MSDN which says that only certain characters cause an arg to require quoting. This seems to be incorrect, though, and worse it seems to be a difference in Windows version. The bot that fails is Windows 7, and I can't reproduce the failure on Win 10. But it's definitely related to quoting and special characters, because both tests that fail have a * in the argument, which is one of the special characters that would cause an argument to be quoted before but not any longer after the new patch. Since I don't have Win 7, all I can do is just guess that I need to restore the old quoting rules. So this patch does that in hopes that it fixes the problem on Windows 7. llvm-svn: 334375
2018-06-10Revert "Resubmit "[Support] Expose flattenWindowsCommandLine.""Zachary Turner
This reverts commit 65243b6d19143cb7a03f68df0169dcb63e8b4632. Seems like it's not a flake. It might have something to do with the '*' character being in a command line. llvm-svn: 334356
2018-06-10Resubmit "[Support] Expose flattenWindowsCommandLine."Zachary Turner
There were a few linux compilation failures, but other than that I think this was just a flake that caused the tests to fail. I'm going to resubmit and see if the failures go away, if not I'll revert again. llvm-svn: 334355
2018-06-09Revert "[Support] Expose flattenWindowsCommandLine."Zachary Turner
This reverts commit 10d2e88e87150a35dc367ba30716189d2af26774. This is causing some test failures for some reason, reverting while I investigate. llvm-svn: 334354
2018-06-09[Support] Expose flattenWindowsCommandLine.Zachary Turner
This function was internal to Program.inc, but I've needed this on several occasions when I've had to use CreateProcess without llvm's sys::Execute functions. In doing so, I noticed that the function was written using unsafe C-string access and was pretty hard to understand / make sense of, so I've also re-written the functions to use more modern LLVM constructs. llvm-svn: 334353
2018-06-08Clean up some code in Program.Zachary Turner
NFC here, this just raises some platform specific ifdef hackery out of a class and creates proper platform-independent typedefs for the relevant things. This allows these typedefs to be reused in other places without having to reinvent this preprocessor logic. llvm-svn: 334294
2018-06-07[FileSystem] Split up the OpenFlags enumeration.Zachary Turner
This breaks the OpenFlags enumeration into two separate enumerations: OpenFlags and CreationDisposition. The first controls the behavior of the API depending on whether or not the target file already exists, and is not a flags-based enum. The second controls more flags-like values. This yields a more easy to understand API, while also allowing flags to be passed to the openForRead api, where most of the values didn't make sense before. This also makes the apis more testable as it becomes easy to enumerate all the configurations which make sense, so I've added many new tests to exercise all the different values. llvm-svn: 334221
2018-06-01Move some function declarations out of WindowsSupport.hZachary Turner
The idea behind WindowsSupport.h is that it's in the source directory so that windows.h'isms don't leak out into the larger LLVM project. To that end, any symbol that references a symbol from windows.h must be in this private header, and not in a public header. However, we had some useful utility functions in WindowsSupport.h which have no dependency on the Windows API, but still only make sense on Windows. Those functions should be usable outside of Support since there is no risk of causing a windows.h leak. Although this introduces some preprocessor logic in some header files, It's not too egregious and it's better than the alternative of duplicating a ton of code. Differential Revision: https://reviews.llvm.org/D47662 llvm-svn: 333798
2017-09-13Convenience/safety fix for llvm::sys::Execute(And|No)WaitAlexander Kornienko
Summary: Change the type of the Redirects parameter of llvm::sys::ExecuteAndWait, ExecuteNoWait and other APIs that wrap them from `const StringRef **` to `ArrayRef<Optional<StringRef>>`, which is safer and simplifies the use of these APIs (no more local StringRef variables just to get a pointer to). Corresponding clang changes will be posted as a separate patch. Reviewers: bkramer Reviewed By: bkramer Subscribers: vsk, llvm-commits Differential Revision: https://reviews.llvm.org/D37563 llvm-svn: 313155
2017-09-06Minor style fixes in lib/Support/**/Program.(inc|cpp).Alexander Kornienko
No functional changes intended. llvm-svn: 312646
2017-03-31Remove more name space pollution from .inc filesKristof Beyls
llvm-svn: 299222
2016-01-05[Clang/Support/Windows/Unix] Command lines created by clang may exceed the ↵Oleg Ranevskyy
command length limit set by the OS Summary: Hi Rafael, Would you be able to review this patch, please? (Clang part of the patch is D15832). When clang runs an external tool, e.g. a linker, it may create a command line that exceeds the length limit. Clang uses the llvm::sys::argumentsFitWithinSystemLimits function to check if command line length fits the OS limitation. There are two problems in this function that may cause exceeding of the limit: 1. It ignores the length of the program path in its calculations. On the other hand, clang adds the program path to the command line when it runs the program. 2. It assumes no space character is inserted after the last argument, which is not true for Windows. The flattenArgs function adds the trailing space for *each* argument. The result of this is that the terminating NULL character is not counted and may be placed beyond the length limit if the command line is exactly 32768 characters long. The WinAPI's CreateProcess does not find the NULL character and fails. Reviewers: rafael, ygao, probinson Subscribers: asl, llvm-commits Differential Revision: http://reviews.llvm.org/D15831 llvm-svn: 256866
2015-11-23Add Windows error code and tidy formatting for system errors.Paul Robinson
Differential Revision: http://reviews.llvm.org/D14892 llvm-svn: 253888
2015-10-08Windows: Fixed sys::findProgramByName to work with files containing dot in ↵George Rimar
their name. Problem was in SearchPathW function that does not attach an extension if file already has one. That does not work for executables like ld.lld2 for example which require to have .exe extension but SearchPath thinks that its "lld2". Solution was to add the extension manually. Differential Revision: http://reviews.llvm.org/D13536 llvm-svn: 249696
2015-09-10Add .exe check to Execute to fix clang-modernize tests broken in r247358Reid Kleckner
llvm-svn: 247361