diff options
| author | Vitaly Buka <vitalybuka@google.com> | 2023-12-13 11:24:19 -0800 |
|---|---|---|
| committer | Vitaly Buka <vitalybuka@google.com> | 2023-12-13 11:24:19 -0800 |
| commit | bb8c48999b0361efd053f842566c727b5fbfe96d (patch) | |
| tree | 909da3ecfa7ef50a847f35b817b7fece7d9e1a6f /llvm/lib/Support/InitLLVM.cpp | |
| parent | 2d98fe9115e37c60fd568008c27038015f28c7e3 (diff) | |
| parent | 64fa90bf8966cb886463840e5c85b9602cbbdc52 (diff) | |
[𝘀𝗽𝗿] changes introduced through rebaseusers/vitalybuka/spr/main.asan-install-pthread_atfork
Created using spr 1.3.4
[skip ci]
Diffstat (limited to 'llvm/lib/Support/InitLLVM.cpp')
| -rw-r--r-- | llvm/lib/Support/InitLLVM.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/llvm/lib/Support/InitLLVM.cpp b/llvm/lib/Support/InitLLVM.cpp index 2b7173b28940..7f475f42f3cb 100644 --- a/llvm/lib/Support/InitLLVM.cpp +++ b/llvm/lib/Support/InitLLVM.cpp @@ -8,6 +8,8 @@ #include "llvm/Support/InitLLVM.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/AutoConvert.h" +#include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PrettyStackTrace.h" @@ -15,15 +17,31 @@ #include "llvm/Support/SwapByteOrder.h" #ifdef _WIN32 -#include "llvm/Support/Error.h" #include "llvm/Support/Windows/WindowsSupport.h" #endif +#ifdef __MVS__ +#include <unistd.h> + +void CleanupStdHandles(void *Cookie) { + llvm::raw_ostream *Outs = &llvm::outs(), *Errs = &llvm::errs(); + Outs->flush(); + Errs->flush(); + llvm::restoreStdHandleAutoConversion(STDIN_FILENO); + llvm::restoreStdHandleAutoConversion(STDOUT_FILENO); + llvm::restoreStdHandleAutoConversion(STDERR_FILENO); +} +#endif + using namespace llvm; using namespace llvm::sys; InitLLVM::InitLLVM(int &Argc, const char **&Argv, bool InstallPipeSignalExitHandler) { +#ifdef __MVS__ + // Bring stdin/stdout/stderr into a known state. + sys::AddSignalHandler(CleanupStdHandles, nullptr); +#endif if (InstallPipeSignalExitHandler) // The pipe signal handler must be installed before any other handlers are // registered. This is because the Unix \ref RegisterHandlers function does @@ -37,6 +55,20 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv, sys::PrintStackTraceOnErrorSignal(Argv[0]); install_out_of_memory_new_handler(); +#ifdef __MVS__ + + // We use UTF-8 as the internal character encoding. On z/OS, all external + // output is encoded in EBCDIC. In order to be able to read all + // error messages, we turn conversion to EBCDIC on for stderr fd. + std::string Banner = std::string(Argv[0]) + ": "; + ExitOnError ExitOnErr(Banner); + + // If turning on conversion for stderr fails then the error message + // may be garbled. There is no solution to this problem. + ExitOnErr(errorCodeToError(llvm::enableAutoConversion(STDERR_FILENO))); + ExitOnErr(errorCodeToError(llvm::enableAutoConversion(STDOUT_FILENO))); +#endif + #ifdef _WIN32 // We use UTF-8 as the internal character encoding. On Windows, // arguments passed to main() may not be encoded in UTF-8. In order @@ -61,4 +93,9 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv, #endif } -InitLLVM::~InitLLVM() { llvm_shutdown(); } +InitLLVM::~InitLLVM() { +#ifdef __MVS__ + CleanupStdHandles(nullptr); +#endif + llvm_shutdown(); +} |
