summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Unix
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-11-10Remove unused <algorithm> inclusion (#166942)serge-sans-paille
2025-10-19[ADT, Support] Use std::min and std::max (NFC) (#164145)Kazu Hirata
2025-10-03Reland "[LLVM] Add GNU make jobserver support (#145131)"Yaxun (Sam) Liu
With fix for JobServerTest where default parallel scheduling strategy is saved/restored.
2025-10-03Revert "[LLVM] Add GNU make jobserver support (#145131)"Yaxun (Sam) Liu
revert this patch due to failure in unittests/Support, e.g. https://lab.llvm.org/buildbot/#/builders/33/builds/24178/steps/6/logs/FAIL__LLVM-Unit__SupportTests_61 This reverts commit ffc503edd0a2d07121232fe204e480fc29631a90.
2025-10-03[LLVM] Add GNU make jobserver support (#145131)Yaxun (Sam) Liu
This patch introduces support for the jobserver protocol to control parallelism for device offloading tasks. When running a parallel build with a modern build system like `make -jN` or `ninja -jN`, each Clang process might also be configured to use multiple threads for its own tasks (e.g., via `--offload-jobs=4`). This can lead to an explosion of threads (N * 4), causing heavy system load, CPU contention, and ultimately slowing down the entire build. This patch allows Clang to act as a cooperative client of the build system's jobserver. It extends the `--offload-jobs` option to accept the value 'jobserver'. With the recent addition of jobserver support to the Ninja build system, this functionality now benefits users of both Make and Ninja. When `--offload-jobs=jobserver` is specified, Clang's thread pool will: 1. Parse the MAKEFLAGS environment variable to find the jobserver details. 2. Before dispatching a task, acquire a job slot from the jobserver. If none are available, the worker thread will block. 3. Release the job slot once the task is complete. This ensures that the total number of active offload tasks across all Clang processes does not exceed the limit defined by the parent build system, leading to more efficient and controlled parallel builds. Implementation: - A new library, `llvm/Support/Jobserver`, is added to provide a platform-agnostic client for the jobserver protocol, with backends for Unix (FIFO) and Windows (semaphores). - `llvm/Support/ThreadPool` and `llvm/Support/Parallel` are updated with a `jobserver_concurrency` strategy to integrate this logic. - The Clang driver and linker-wrapper are modified to recognize the 'jobserver' argument and enable the new thread pool strategy. - New unit and integration tests are added to validate the feature.
2025-09-15[CAS] Add MappedFileRegionArena (#114099)Steven Wu
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-06[Support] Remove an unnecessary cast (NFC) (#157312)Kazu Hirata
dli_fname is of type const char *.
2025-09-01[Support] Also check the value for HAVE_PTHREAD_(SETNAME/SET_NAME)_NP (#156294)Brad Smith
As was already done for HAVE_PTHREAD_(GETNAME/GET_NAME)_NP
2025-08-20[FileSystem] Allow exclusive file lock (#114098)Steven Wu
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 Wu
2025-07-29[Support] Remove an unnecessary cast (NFC) (#151083)Kazu Hirata
NumRead is already of ssize_t.
2025-07-09[Support] Don't re-raise signals sent from kernel (#145759)Alex Langford
When an llvm tool crashes (e.g. from a segmentation fault), SignalHandler will re-raise the signal. The effect is that crash reports now contain SignalHandler in the stack trace. The crash reports are still useful, but the presence of SignalHandler can confuse tooling and automation that deduplicate or analyze crash reports. rdar://150464802
2025-07-02[DLCov] Origin-Tracking: Enable collecting and symbolizing stack traces ↵Stephen Tozer
(#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-24[LLVM][Support][Cygwin] Add threading support for Cygwin host (#145314)Tomohiro Kashiwada
Cygwin environment has pthread functionality but LLVM integration doesn't care it nor provide fallback. Using Linux integration for Cygwin works fine.
2025-06-17[LLVM] [Support] Disable `ioctl()` terminal size check on Solaris (#144600)Sirraide
#143514 broke the `clang-solaris11-sparcv9` bot; from what I can tell that’s Solaris and according to `SolarisTargetInfo::getOSDefines`, the macro `__sun__` should be defined on Solaris, so check for that and don’t try to query the terminal size if it is defined. Not sure this is the best solution but hopefully it fixes the bot.
2025-06-17[LLVM] [Support] Query the terminal width using `ioctl()` (#143514)Sirraide
On unix systems, we were trying to determine the terminal width using the `COULMNS` environment variable. Unfortunately, `COLUMNS` is not exported by all shells and thus not available on some systems. We were previously using `ioctl()` for this; fall back to doing so if `COLUMNS` does not exist or does not store a positive integer. This essentially reverts a3eb3d3d92d037fe3c9deaad87f6fc42fe9ea766 and parts of https://reviews.llvm.org/D61326. For more information, see #139499. Fixes #139499.
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-06-09[Support][Cygwin] Fix handling of Process symbol lookup. (#143072)jeremyd2019
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[Support] Properly zero initialize CPU set when querying affinity (#142924)Christian Ulmann
This commit resolves a potential issue of working with uninitialized memory when querying the CPU's affinity. The man page of `sched_getaffinity` does not guarantee that the memory will be fully overwritten, so this change should ensure that issues are avoided.
2025-06-04[lldb][llvm][AIX] Added support for getProcFile with TID (#142586)Hemang Gadhavi
This PR is in reference to porting LLDB on AIX. Link to discussions on llvm discourse and github: 1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640 2. https://github.com/llvm/llvm-project/issues/101657 The complete changes for porting are present in this draft PR: https://github.com/llvm/llvm-project/pull/102601 - Added changes to getProcFile() with threadID, including testcase for AIX. - Added support for AIX to get_threadid() from llvm.
2025-05-21[NFC][ADT/Support] Add {} for else when if body has {} (#140758)Rahul Joshi
2025-05-08[llvm] Add managarm support (#138854)no92
This PR is part of a series to upstream managarm support, as laid out in the [RFC](https://discourse.llvm.org/t/rfc-new-proposed-managarm-support-for-llvm-and-clang-87845/85884/1). This PR is a follow-up to #87845. The intention here is to add the managarm target to the LLVM support lib, in preparation for a follow-up that would add the missing clang driver bits.
2025-05-07[LLVM][Support] check for error return from dladdr. (#138369)jeremyd2019
In case of an error, the DL_info struct may have been left uninitialized, so it is not safe to use its members. In one error case, initialize dli_sname to nullptr explicitly, so that the later check against nullptr is guaranteed to be safe.
2025-05-02[LLVM][Cygwin] Fix Signals compatibility with Cygwin API (#138117)Mateusz Mikuła
Cygwin types sometimes do not match Linux exactly. Like in this case: ``` In file included from /h/projects/llvm-project/llvm/include/llvm/Support/Error.h:23, from /h/projects/llvm-project/llvm/include/llvm/Support/FileSystem.h:34, from /h/projects/llvm-project/llvm/lib/Support/Signals.cpp:22: /h/projects/llvm-project/llvm/include/llvm/Support/Format.h: In instantiation of ‘llvm::format_object<Ts>::format_object(const char*, const Ts& ...) [with Ts = {int, char [4096]}]’: /h/projects/llvm-project/llvm/include/llvm/Support/Format.h:126:10: required from ‘llvm::format_object<Ts ...> llvm::format(const char*, const Ts& ...) [with Ts = {int, char [4096]}]’ /h/projects/llvm-project/llvm/lib/Support/Unix/Signals.inc:850:19: required from here /h/projects/llvm-project/llvm/include/llvm/Support/Format.h:106:34: error: no matching function for call to ‘std::tuple<int, char [4096]>::tuple(const int&, const char [4096])’ 106 | : format_object_base(fmt), Vals(vals...) { | ^~~~~~~~~~~~~ ``` Casting here is safe and solves the issue.
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-02-12[Support] Fix building on FreeBSD and OpenBSD (#127005)Brad Smith
Fix building after a6f7cb54d3c268ea4748a0ff783b4b030c3195d9. Check for the function getauxval() instead of just the sys/auxv.h header.
2025-02-13[Support] Prefer AUX vector for page size (#126863)Tristan Ross
Prefers the page size to come from the AUX vector, `getpagesize` is removed from POSIX.1-2001. Also throws in a couple asserts to ensure the page size is a valid value.
2025-02-08[Support] Re-raise external signals (#125854)Guy David
Otherwise, the handler "swallows" the signal and the process continues to execute. While this use case is peculiar, ignoring these signals entirely seems more odd.
2025-01-31[llvm][Support] Enable dl_iterate_phdr support on OpenBSD and DragonFly ↵Brad Smith
(#125186)
2025-01-28[llvm] Android has sched_getaffinity() now (#124689)Brad Smith
2025-01-29[NFC] Remove redundant `sys/file.h` header. (#124684)c8ef
Closes #124652. This header was introduced in https://github.com/llvm/llvm-project/commit/536736995bf5d073853c7e884968c9847b4ae64d, but it appears that including only `fnctl.h` should be enough. Hopefully, this patch will not cause build issues on other Unix platforms.
2025-01-23[llvm][Support] Put back filename into FileToRemoveList (#124065)Vitaly Buka
Prevents avoidable memory leaks. Looks like exchange added in aa1333a91f8d8a060bcf5b14aa32a6e8bab74e8c didn't take "continue" into account. ``` ==llc==2150782==ERROR: LeakSanitizer: detected memory leaks Direct leak of 10 byte(s) in 1 object(s) allocated from: #0 0x5f1b0f9ac14a in strdup llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:593:3 #1 0x5f1b1768428d in FileToRemoveList llvm-project/llvm/lib/Support/Unix/Signals.inc:105:55 ```
2025-01-22[Signals] Exclude dladdr for AIX after #123879Fangrui Song
Widely supported but missing on AIX https://www.austingroupbugs.net/view.php?id=993
2025-01-22[CMake] Remove HAVE_DLFCN_H and HAVE_DLADDR (#123879)Fangrui Song
It is sufficient to just use `HAVE_DLOPEN`.
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 HAVE_SYS_IOCTL_HFangrui Song
2025-01-16[CMake] Remove HAVE_TERMIOS_HFangrui Song
The code path has been dead since 2019. See a3eb3d3d92d037fe3c9deaad87f6fc42fe9ea766
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
2025-01-09[z/OS] Add backtrace support for z/OS. (#121826)Kai Nacke
The system call `__CELQTBCK()` is used to build a backtrace like on other systems. The collected information are the address of the PC, the address of the entry point (EP), the difference between both addresses (+EP), the dynamic storage area (DSA aka the stack pointer), and the function name. The system call is described here: https://www.ibm.com/docs/en/zos/3.1.0?topic=cwicsa6a-celqtbck-also-known-as-celqtbck-64-bit-traceback-service
2024-12-18[llvm][Support] Use __NR_gettid on Linux for compat with older glibc (#120007)Brad Smith
2024-10-10[Support] Include Support/thread.h before api implementations (#111175)Thomas Fransham
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-10-03Fix have pthread_getname for some system (#110854)William Moses
I'm on a system that has have_pthread_getname_np defined but set to 0. The correct behavior here is not to use the function, but presently the macros will attempt to use a non-existing function. This previously worked before https://github.com/llvm/llvm-project/pull/106486/files
2024-09-10[llvm][Support] Determine the max thread length on Haiku (#107801)Brad Smith
Haiku has pthread_setname_np() / pthread_getname_np().
2024-09-09[hurd] Fix accessing f_type field of statvfs (#71851)Samuel Thibault
f4719c4d2cda ("Add support for GNU Hurd in Path.inc and other places") made llvm use an internal __f_type name for the f_type field (which it is not supposed to since accessing double-underscore names is explicitly not supported by standards). In glibc 2.39 this field was renamed to f_type so application can now access the field as the standard says.
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-09-02[llvm][Support] Add support for thread naming under DragonFly BSD and ↵Brad Smith
Solaris/illumos (#106944)
2024-09-02[llvm][Support] Adjust maximum thread name length to the right value for ↵Brad Smith
OpenBSD (#106956) The thread name length is derived from _MAXCOMLEN which is 24.
2024-09-02Add support for retrieving the thread ID on DragonFly BSD (#106938)Brad Smith