summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Unix/Program.inc
AgeCommit message (Collapse)Author
2025-11-18Implement a more seamless way to provide missing functions on z/OS (#167703)Sean Perry
In this PR I'm changing the way we provide the missing functions like strnlen() on z/OS from the separate header file to a wrapper around the system headers that declare these functions. This will be less intrusive. --------- Co-authored-by: Zibi Sarbinowski <zibi@ca.ibm.com>
2025-06-13[SystemZ][z/OS] Refactor AutoConvert more (#143955)Abhina Sree
This patch removes the C++ disablezOSAutoConversion,enablezOSAutoConversion declarations and also updates Path.inc to use the common function.
2025-02-26Support: Do not check if a file exists before executing (#128821)Matt Arsenault
Let the actual syscall error if the file doesn't exist. This produces a more standard "no such file or directory" phrasing of the error message, and avoids an extra step. The same antipattern appears in the windows code, we should probably fix that one too.
2025-01-16[CMake] Remove HAVE_SYS_RESOURCE_H/HAVE_SETRLIMIT/HAVE_GETRLIMITFangrui Song
Only used by Unix/Program.inc and seem always available. Pull Request: https://github.com/llvm/llvm-project/pull/123288
2025-01-16[CMake] Remove some unneeded HAVE_*_HFangrui Song
Pull Request: https://github.com/llvm/llvm-project/pull/123282
2025-01-15[CMake] Remove some always-true HAVE_XXX_HFangrui Song
These are unneeded even on AIX, PURE_WINDOWS, and ZOS (per #104706) * HAVE_ERRNO_H: introduced by 1a93330ffa2ae2aa0b49461f05e6f0d51e8443f8 (2009) but unneeded. The guarded ABI is unconditionally used by lldb. * HAVE_FCNTL_H * HAVE_FENV_H * HAVE_SYS_STAT_H Pull Request: https://github.com/llvm/llvm-project/pull/123087
2024-09-05[NFC][SystemZ][z/OS] Rename autoconversion-related functions to be less ↵Abhina Sree
generic (#107399) This patch renames the functions in AutoConvert.h/cpp to have a less generic name because they are z/OS specific.
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.
2024-01-17[Support] Use SmallString::operator std::string (NFC)Kazu Hirata
2023-12-13[SystemZ][z/OS] Complete EBCDIC I/O support (#75212)Abhina Sree
This patch completes the support for EBCDIC I/O support on z/OS using the autoconversion functions.
2023-12-12[SystemZ][z/OS] Fix build errors on z/OS in the Unix .inc files (#74758)Abhina Sree
This patch resolves the following errors on z/OS: error: no member named 'wait4' in the global namespace error: no member named 'ru_maxrss' in 'rusage' error: use of undeclared identifier 'strsignal' error: Cannot get usage times on this platform error: Cannot get malloc info on this platform
2023-08-23[Support] Avoid wait4 on FuchsiaPetr Hosek
Fuchsia doesn't provide wait4, use waitpid instead. Differential Revision: https://reviews.llvm.org/D155793
2022-12-22Support: Fix broken C++ markerMatt Arsenault
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: Try to fix msan error in sys::WaitMatt Arsenault
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
2021-10-23[llvm] Use StringRef::contains (NFC)Kazu Hirata
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-01-28Support: Simplify __HAIKU__ #ifdef in llvm::sys::Wait, NFCDuncan P. N. Exon Smith
This just reduces the amount of code in the `#ifndef` block as a follow-up to 5c1cea6f406366b85f3c200a1c48f713da4450ba.
2021-01-28[Support] Fix build for HaikuSerge Pavlov
This change fixes two issues with building LLVM on Haiku. The first issue is that LLVM requires wait4(), which on Haiku is hidden behind the _BSD_SOURCE feature flag when using the --std=c++14 flag. Additionally, the wait4() function is only available in libbsd.so, so this is now a dependency. The other fix is that Haiku does not have the (non-standard) rusage.maxrss member, so by default the used memory info will be set to 0 on this platform. Reviewed By: sepavloff Differential Revision: https://reviews.llvm.org/D87920 Patch by Niels Sascha Reedijk.
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
2020-06-25[NFC][Support] Make Unix/Program.inc separately compilableHubert Tong
To improve CI checks, make `Unix/Program.inc` separately compilable.
2020-06-25[Support][AIX] Add declaration of wait4 to fix buildHubert Tong
While `wait4` is not documented for AIX, it is available; however, even on systems where it is available, the system headers do not always provide a declaration of the function. This patch provides a declaration of `wait4` for AIX. Reviewed By: daltenty Differential Revision: https://reviews.llvm.org/D82282
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-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-08-14[Support][NFC] Fix error message for posix_spawn_file_actions_addopen failed ↵Jan Korous
call Seems like a copy-paste from couple lines above. llvm-svn: 368899
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-04-24posix_spawn should retry upon EINTRJF Bastien
Summary: We've seen cases of bots failing with: clang: error: unable to execute command: posix_spawn failed: Interrupted system call Add a small retry loop to posix_spawn in case this happens. Don't retry too much in case there's some systemic problem going on, but retry a few times. <rdar://problem/50181448> Reviewers: Bigcheese, arphaman Subscribers: jkorous, dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61096 llvm-svn: 359152
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-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-08commandLineFitsWithinSystemLimits Overestimates System LimitsAlexander Kornienko
Summary: The function `llvm::sys::commandLineFitsWithinSystemLimits` appears to be overestimating the system limits. This issue was discovered while attempting to enable response files in the Swift compiler. When the compiler submits its frontend jobs, those jobs are subjected to the system limits on command line length. `commandLineFitsWithinSystemLimits` is used to determine if the job's arguments need to be wrapped in a response file. There are some cases where the argument size for the job passes `commandLineFitsWithinSystemLimits`, but actually exceeds the real system limit, and the job fails. `clang` also uses this function to decide whether or not to wrap it's job arguments in response files. See: https://github.com/llvm-mirror/clang/blob/master/lib/Driver/Driver.cpp#L1341. Clang will also fail for response files who's size falls within a certain range. I wrote a script that should find a failure point for `clang++`. All that is needed to run it is Python 2.7, and a simple "hello world" program for `test.cc`. It should run on Linux and on macOS. The script is available here: https://gist.github.com/dabelknap/71bd083cd06b91c5b3cef6a7f4d3d427. When it hits a failure point, you should see a `clang: error: unable to execute command: posix_spawn failed: Argument list too long`. The proposed solution is to mirror the behavior of `xargs` in `commandLinefitsWithinSystemLimits`. `xargs` defaults to 128k for the command line length size (See: https://fossies.org/dox/findutils-4.6.0/buildcmd_8c_source.html#l00551). It adjusts this depending on the value of `ARG_MAX`. Reviewers: alexfh Reviewed By: alexfh Subscribers: llvm-commits Tags: #clang Patch by Austin Belknap! Differential Revision: https://reviews.llvm.org/D47795 llvm-svn: 334295
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-05-16[Unix] Indent ChangeStd{in,out}ToBinary.Fangrui Song
llvm-svn: 332432
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-07-08[Solaris] get rid of _RESTRICT_KYWD warning during the buildKamil Rytarowski
Summary: (re)definition of _RESTRICT_KYWD rightfully causes a warning message during the Solaris build. This hack is not needed if build compiler is properly configured (.e.g /usr/bin/gcc) so just remove it. Reviewers: ro, mgorny, krytarowski, joerg Reviewed By: joerg Subscribers: quenelle, llvm-commits Patch by Fedor Sergeev (Oracle). Differential Revision: https://reviews.llvm.org/D35054 llvm-svn: 307469
2017-06-20Support: chunk writing on LinuxSaleem Abdulrasool
This is a workaround for large file writes. It has been witnessed that write(2) failing with EINVAL (22) due to a large value (>2G). Thanks to James Knight for the help with coming up with a sane test case. llvm-svn: 305846
2017-06-12Support: Don't set RLIMIT_AS on child processes when applying a memory limitDavid Blaikie
It doesn't seem relevant to set an address space limit - this isn't important in any sense that I'm aware & it gets in the way of things that use a lot of address space, like llvm-symbolizer. This came up when I realized that bugpoint regression tests were much slower with -gsplit-dwarf than plain -g. Turned out that bugpoint subprocesses (opt, etc) were crashing and doing symbolization - but bugpoint runs those subprocesses with a 400MB memory limit. So with plain -g, mmaping the opt binary would exceed the memory limit, fail, and thus be really fast - no symbolization occurred. Whereas with -gsplit-dwarf, comically, having less to map in, it would succeed and then spend lots of time symbolizing. I've fixed at least the critical part of bugpoint's perf problem there by adding an option to allow bugpoint to disable symbolization. Thus improving the perfromance for -gsplit-dwarf and making the -g-esque speed available without this quirk/accidental benefit. llvm-svn: 305242
2016-04-05Revert "Fix Clang-tidy modernize-deprecated-headers warnings in remaining ↵Duncan P. N. Exon Smith
files; other minor fixes." This reverts commit r265454 since it broke the build. E.g.: http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_build/22413/ llvm-svn: 265459
2016-04-05Fix Clang-tidy modernize-deprecated-headers warnings in remaining files; ↵Eugene Zelenko
other minor fixes. Some Include What You Use suggestions were used too. Use anonymous namespaces in source files. Differential revision: http://reviews.llvm.org/D18778 llvm-svn: 265454