aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Unix/Signals.inc
AgeCommit message (Collapse)AuthorFilesLines
2025-09-06[Support] Remove an unnecessary cast (NFC) (#157312)Kazu Hirata1-2/+1
dli_fname is of type const char *.
2025-07-09[Support] Don't re-raise signals sent from kernel (#145759)Alex Langford1-3/+18
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 Tozer1-0/+15
(#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-05-07[LLVM][Support] check for error return from dladdr. (#138369)jeremyd20191-13/+21
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ła1-1/+1
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-08[Support] Re-raise external signals (#125854)Guy David1-4/+9
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 Smith1-1/+2
(#125186)
2025-01-23[llvm][Support] Put back filename into FileToRemoveList (#124065)Vitaly Buka1-15/+19
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 Song1-1/+1
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 Song1-3/+1
It is sufficient to just use `HAVE_DLOPEN`.
2025-01-16[CMake] Remove some unneeded HAVE_*_HFangrui Song1-2/+0
Pull Request: https://github.com/llvm/llvm-project/pull/123282
2025-01-15[CMake] Remove some always-true HAVE_XXX_HFangrui Song1-2/+0
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 Nacke1-0/+78
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-08-20[CMake] Remove HAVE_LINK_HFangrui Song1-2/+2
We can remove the variable from https://reviews.llvm.org/D5610 since link.h is available on Linux (glibc/musl/Bionic), FreeBSD, and NetBSD. Use `__has_include(<link.h>)` before including it. Pull Request: https://github.com/llvm/llvm-project/pull/104893
2024-07-02Support: Fix typo in commentMatt Arsenault1-1/+1
2023-08-17Fix symbolizer markup backtrace build/test.Daniel Thornburgh1-1/+5
This corrects a Darwin build failure due to a missing stub and an environment-specific Linux test failure due to an overly restrictive test regex. This also backs out of the previous fix attempt; %p is intended to be printed and parsed with the semantics of #.
2023-08-17[llvm][Support] Fix backtrace output by removing '#'. NFCMichael Liao1-1/+1
- '#' has the string "0x" prepended for non-zero values. That results in inconsistent behavior between zero and non-zero values.
2023-08-17Optionally print symbolizer markup backtraces.Daniel Thornburgh1-0/+119
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-05-03[Demangle] remove unused status param of itaniumDemangleNick Desaulniers1-6/+5
No call sites interpreted this value meaningfully. Simplify this interface. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D149707
2023-05-03[Demangle] remove unused params of itaniumDemangleNick Desaulniers1-1/+1
No call sites use these parameters, so drop them. Equivalent to D148940. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D149703
2023-03-05[Support] Implement findModulesAndOffsets on Apple 64-bit platformsLuís Marques1-4/+41
To have line number information in stack traces (per stack frame) it's necessary to implement findModulesAndOffsets. Differential Revision: https://reviews.llvm.org/D142282
2023-03-02Revert "[Support] Implement findModulesAndOffsets on Apple 64-bit platforms"Luís Marques1-43/+6
This reverts commit b8b8aa6f06458212193c4202291c9f68364b2025. It broke AIX.
2023-03-02[Support] Implement findModulesAndOffsets on Apple 64-bit platformsLuís Marques1-6/+43
To have line number information in stack traces (per stack frame) it's necessary to implement findModulesAndOffsets. Differential Revision: https://reviews.llvm.org/D142282
2023-02-24Remove uses of ATOMIC_VAR_INITFangrui Song1-9/+7
ATOMIC_VAR_INIT has a trivial definition `#define ATOMIC_VAR_INIT(value) (value)`, is deprecated in C17/C++20, and will be removed in newer standards.
2022-12-02Use CTAD on llvm::SaveAndRestoreJan Svoboda1-1/+1
Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D139229
2022-11-26[Support] Apply clang-format on .inc files. NFC.Alexandre Ganea1-48/+55
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-11-18Revert "Reapply: Add an error message to the default SIGPIPE handler"Bill Wendling1-4/+0
This patch is spamming compiles with unhelpful and confusing messages. E.g. the Linux kernel uses "grep -q" in several places. It's meant to quit with a return code of zero when the first match is found. This can cause a SIGPIPE signal, but that's expected, and there's no way to turn this error message off to avoid spurious error messages. UNIX03 apparently doesn't require printing an error message on SIGPIPE, but specifically when there's an error on the stdout stream in a normal program flow, e.g. when SIGPIPE trap is disabled. A separate patch is planned to address the specific case we care most about (involving llvm-nm). This reverts commit b89bcefa6202e310eb3167dd1c37f1807377ec8d. Link: https://github.com/llvm/llvm-project/issues/59037 Link: https://github.com/ClangBuiltLinux/linux/issues/1651 Differential Revision: https://reviews.llvm.org/D138244
2022-09-08[llvm] Use std::size instead of llvm::array_lengthofJoe Loser1-5/+5
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133429
2022-06-09Reapply: Add an error message to the default SIGPIPE handlerTim Northover1-0/+4
UNIX03 conformance requires utilities to flush stdout before exiting and raise an error if writing fails. Flushing already happens on a call to exit and thus automatically on a return from main. Write failure is then detected by LLVM's default SIGPIPE handler. The handler already exits with a non-zero code, but conformance additionally requires an error message. First reapply attempt I hadn't noticed the test had changed, hopefully this goes better.
2022-06-09Revert "Add an error message to the default SIGPIPE handler"Tim Northover1-4/+0
It broke PPC bots.
2022-06-08Add an error message to the default SIGPIPE handlerTim Northover1-0/+4
UNIX03 conformance requires utilities to flush stdout before exiting and raise an error if writing fails. Flushing already happens on a call to exit and thus automatically on a return from main. Write failure is then detected by LLVM's default SIGPIPE handler. The handler already exits with a non-zero code, but conformance additionally requires an error message.
2022-06-07[config] Remove RETSIGTYPE from config.h.cmake, NFCReid Kleckner1-4/+4
This doesn't need to be configurable. It was hardcoded to void in all LLVM build systems.
2022-05-12Revert "Add an error message to the default SIGPIPE handler"Tim Northover1-4/+0
It broke a PPC bot, for not immediately obvious reasons.
2022-05-12Add an error message to the default SIGPIPE handlerTim Northover1-0/+4
UNIX03 conformance requires utilities to flush stdout before exiting and raise an error if writing fails. Flushing already happens on a call to exit and thus automatically on a return from main. Write failure is then detected by LLVM's default SIGPIPE handler. The handler already exits with a non-zero code, but conformance additionally requires an error message.
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-5/+5
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille1-5/+5
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2021-04-26Add LLVM_ATTRIBUTE_USED to fix problems which could be exposed by aggressive ↵Fangrui Song1-1/+1
global pointer variable removal Note to BuryPointer.cpp:GraveYard. 'unused' cannot prevent (1) dead store elimination and (2) removal of the global pointer variable (D69428) but 'used' can. Discovered when comparing link maps between HEAD+D69428 and HEAD. Reviewed By: lattner Differential Revision: https://reviews.llvm.org/D101217
2021-01-08[Signal] Re-raise SIGPIPE if the handler is uninstalledVedant Kumar1-3/+5
Instead of falling through to RunSignalHandlers after the SIGPIPE handler is uninstalled and we get a SIGPIPE, re-raise the signal, just like we do for other IntSigs. This was discussed and informally OK'd here: https://reviews.llvm.org/rG9a3f892d018238dce5181e458905311db8e682f5#856804
2020-09-25Hint how to get a symbolized stack trace if llvm-symbolizer is not found on ↵Mehdi Amini1-0/+3
crashes Most users of LLVM tools hit the raw traces and don't know how to get LLVM to symbolize automatically for them. When we print the non-symbolized stack trace, we will add information about how to get it symbolized. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D88269
2020-09-24[Support] On Unix, let the CrashRecoveryContext return the signal codeAlexandre Ganea1-2/+2
Before this patch, the CrashRecoveryContext was returning -2 upon a signal, like ExecuteAndWait does. This didn't match the behavior on Windows, where the the exception code was returned. We now return the signal's code, which optionally allows for re-throwing the signal later. Doing so requires all custom handlers to be removed first, through llvm::sys::unregisterHandlers() which we made a public API. This is part of https://reviews.llvm.org/D70378
2020-08-26[SystemZ/ZOS] Add header file to encapsulate use of <sysexits.h>Kai Nacke1-1/+1
The non-standard header file `<sysexits.h>` provides some return values. `EX_IOERR` is used to as a special value to signal a broken pipe to the clang driver. On z/OS Unix System Services, this header file does not exists. This patch - adds a check for `<sysexits.h>`, removing the dependency on `LLVM_ON_UNIX` - adds a new header file `llvm/Support/ExitCodes`, which either includes `<sysexits.h>` or defines `EX_IOERR` - updates the users of `EX_IOERR` to include the new header file Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D83472
2020-08-26[Support] Allow printing the stack trace only for a given depthDibya Ranjan Mishra1-4/+7
Differential Revision: https://reviews.llvm.org/D85458
2020-08-01Use llvm::is_contained where appropriate (NFC)Kazu Hirata1-2/+1
Use llvm::is_contained where appropriate (NFC) Reviewed By: kazu Differential Revision: https://reviews.llvm.org/D85083
2020-01-11[Support] Optionally call signal handlers when a function wrapped by the the ↵Alexandre Ganea1-0/+16
CrashRecoveryContext fails This patch allows for handling a failure inside a CrashRecoveryContext in the same way as the global exception/signal handler. A failure will have the same side-effect, such as cleanup of temporarty file, printing callstack, calling relevant signal handlers, and finally returning an exception code. This is an optional feature, disabled by default. This is a support patch for D69825. Differential Revision: https://reviews.llvm.org/D70568
2019-12-04[Signal] Allow one-shot SIGPIPE handler to be reachedVedant Kumar1-5/+5
As SIGPIPE is no longer in the IntSigs array, handle SIGPIPE before handling any interrupt signals. Thanks to Alexandre Ganea for pointing out the issue here.
2019-11-18[Signal] Allow llvm clients to opt into one-shot SIGPIPE handlingVedant Kumar1-4/+20
Allow clients of the llvm library to opt-in to one-shot SIGPIPE handling, instead of forcing them to undo llvm's SIGPIPE handler registration (which is brittle). The current behavior is preserved for all llvm-derived tools (except lldb) by means of a default-`true` flag in the InitLLVM constructor. This prevents "IO error" crashes in long-lived processes (lldb is the motivating example) which both a) load llvm as a dynamic library and b) *really* need to ignore SIGPIPE. As llvm signal handlers can be installed when calling into libclang (say, via RemoveFileOnSignal), thereby overriding a previous SIG_IGN for SIGPIPE, there is no clean way to opt-out of "exit-on-SIGPIPE" in the current model. Differential Revision: https://reviews.llvm.org/D70277
2019-10-24Revert "Disable exit-on-SIGPIPE in lldb"Vedant Kumar1-13/+1
This reverts commit 32ce14e55e5a99dd99c3b4fd4bd0ccaaf2948c30. In post-commit review, Pavel pointed out that there's a simpler way to ignore SIGPIPE in lldb that doesn't rely on llvm's handlers.
2019-10-18Disable exit-on-SIGPIPE in lldbVedant Kumar1-1/+13
Occasionally, during test teardown, LLDB writes to a closed pipe. Sometimes the communication is inherently unreliable, so LLDB tries to avoid being killed due to SIGPIPE (it calls `signal(SIGPIPE, SIG_IGN)`). However, LLVM's default SIGPIPE behavior overrides LLDB's, causing it to exit with IO_ERR. Opt LLDB out of the default SIGPIPE behavior. I expect that this will resolve some LLDB test suite flakiness (tests randomly failing with IO_ERR) that we've seen since r344372. rdar://55750240 Differential Revision: https://reviews.llvm.org/D69148 llvm-svn: 375288
2019-08-07Replace llvm::MutexGuard/UniqueLock with their standard equivalentsBenjamin Kramer1-1/+0
All supported platforms have <mutex> now, so we don't need our own copies any longer. No functionality change intended. llvm-svn: 368149
2019-07-12Support for dumping current PrettyStackTrace on SIGINFO (Ctrl-T)Jordan Rose1-14/+53
Support SIGINFO (and SIGUSR1 for POSIX purposes) to tell what long-running jobs are doing, as inspired by BSD tools (including on macOS), by dumping the current PrettyStackTrace. This adds a new kind of signal handler for non-fatal "info" signals, similar to the "interrupt" handler that already exists for SIGINT (Ctrl-C). It then uses that handler to update a "generation count" managed by the PrettyStackTrace infrastructure, which is then checked whenever a PrettyStackTraceEntry is pushed or popped on each thread. If the generation has changed---i.e. if the user has pressed Ctrl-T---the stack trace is dumped, though unfortunately it can't include the deepest entry because that one is currently being constructed/destructed. https://reviews.llvm.org/D63750 llvm-svn: 365911