|
17 | 17 | #include "llvm/Object/Archive.h"
|
18 | 18 | #include "llvm/Object/ObjectFile.h"
|
19 | 19 | #include "llvm/Bitcode/BitcodeWriterPass.h"
|
| 20 | +#include "llvm/Support/Signals.h" |
20 | 21 |
|
21 | 22 | #include "llvm/IR/CallSite.h"
|
22 | 23 |
|
|
26 | 27 | #include <cstdlib>
|
27 | 28 | #endif
|
28 | 29 |
|
| 30 | +#include <iostream> |
| 31 | + |
29 | 32 | //===----------------------------------------------------------------------===
|
30 | 33 | //
|
31 | 34 | // This file defines alternate interfaces to core functions that are more
|
@@ -62,6 +65,27 @@ static AtomicOrdering fromRust(LLVMAtomicOrdering Ordering) {
|
62 | 65 |
|
63 | 66 | static LLVM_THREAD_LOCAL char *LastError;
|
64 | 67 |
|
| 68 | +// Custom error handler for fatal LLVM errors. |
| 69 | +// |
| 70 | +// Notably it exits the process with code 101, unlike LLVM's default of 1. |
| 71 | +static void FatalErrorHandler(void *UserData, |
| 72 | + const std::string& Reason, |
| 73 | + bool GenCrashDiag) { |
| 74 | + // Do the same thing that the default error handler does. |
| 75 | + std::cerr << "LLVM ERROR: " << Reason << std::endl; |
| 76 | + |
| 77 | + // Since this error handler exits the process, we have to run any cleanup that |
| 78 | + // LLVM would run after handling the error. This might change with an LLVM |
| 79 | + // upgrade. |
| 80 | + sys::RunInterruptHandlers(); |
| 81 | + |
| 82 | + exit(101); |
| 83 | +} |
| 84 | + |
| 85 | +extern "C" void LLVMRustInstallFatalErrorHandler() { |
| 86 | + install_fatal_error_handler(FatalErrorHandler); |
| 87 | +} |
| 88 | + |
65 | 89 | extern "C" LLVMMemoryBufferRef
|
66 | 90 | LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
|
67 | 91 | ErrorOr<std::unique_ptr<MemoryBuffer>> BufOr =
|
|
0 commit comments