[llvm] [SystemZ][z/OS] Fix build errors on z/OS in the Unix .inc files (PR #74758)

Abhina Sree via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 12:35:19 PST 2023


https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/74758

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

>From d639111183e8bfa94d694101b75648a02ad44e1d Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Thu, 7 Dec 2023 15:33:38 -0500
Subject: [PATCH] Fix build errors on z/OS in the Unix .inc files

---
 llvm/lib/Support/Unix/Process.inc |  4 ++++
 llvm/lib/Support/Unix/Program.inc | 15 +++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 2babf07944bf7b..bf781eabf5c60b 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -62,7 +62,9 @@ getRUsageTimes() {
   ::getrusage(RUSAGE_SELF, &RU);
   return {toDuration(RU.ru_utime), toDuration(RU.ru_stime)};
 #else
+#ifndef __MVS__  // Exclude for MVS in case -pedantic is used
 #warning Cannot get usage times on this platform
+#endif
   return {std::chrono::microseconds::zero(), std::chrono::microseconds::zero()};
 #endif
 }
@@ -117,7 +119,9 @@ size_t Process::GetMallocUsage() {
     return EndOfMemory - StartOfMemory;
   return 0;
 #else
+#ifndef __MVS__  // Exclude for MVS in case -pedantic is used
 #warning Cannot get malloc info on this platform
+#endif
   return 0;
 #endif
 }
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index 9466d0f0ba859e..f5881003a43bcc 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -342,7 +342,7 @@ namespace sys {
 
 #if defined(_AIX)
 static pid_t(wait4)(pid_t pid, int *status, int options, struct rusage *usage);
-#elif !defined(__Fuchsia__)
+#elif !defined(__Fuchsia__) && !defined(__MVS__)
 using ::wait4;
 #endif
 
@@ -420,7 +420,14 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
     ProcStat->reset();
 
   do {
+#ifdef __MVS__
+    WaitResult.Pid = waitpid(ChildPid, &status, WaitPidOptions);
+    int GetrusageRC = getrusage(RUSAGE_CHILDREN, &Info);
+    assert(!GetrusageRC &&
+           "Must have valid measure of the resources!");
+#else
     WaitResult.Pid = sys::wait4(ChildPid, &status, WaitPidOptions, &Info);
+#endif
   } while (WaitUntilTerminates && WaitResult.Pid == -1 && errno == EINTR);
 #endif
 
@@ -466,7 +473,7 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
     std::chrono::microseconds UserT = toDuration(Info.ru_utime);
     std::chrono::microseconds KernelT = toDuration(Info.ru_stime);
     uint64_t PeakMemory = 0;
-#ifndef __HAIKU__
+#if !defined(__HAIKU__) && !defined(__MVS__)
     PeakMemory = static_cast<uint64_t>(Info.ru_maxrss);
 #endif
     *ProcStat = ProcessStatistics{UserT + KernelT, UserT, PeakMemory};
@@ -494,7 +501,11 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
     }
   } else if (WIFSIGNALED(status)) {
     if (ErrMsg) {
+#ifdef __MVS__
+      *ErrMsg = "Signal " + std::to_string(WTERMSIG(status));
+#else
       *ErrMsg = strsignal(WTERMSIG(status));
+#endif
 #ifdef WCOREDUMP
       if (WCOREDUMP(status))
         *ErrMsg += " (core dumped)";



More information about the llvm-commits mailing list