[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
Fri Dec 8 08:15:03 PST 2023


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

>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 1/4] 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 2babf07944bf7..bf781eabf5c60 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 9466d0f0ba859..f5881003a43bc 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)";

>From 23ff8782c753b9c5157b47b1436de7db6c93ee8f Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Thu, 7 Dec 2023 15:38:40 -0500
Subject: [PATCH 2/4] fix formatting

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

diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index bf781eabf5c60..551f0d7f0f029 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -62,7 +62,7 @@ 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
+#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()};
@@ -119,7 +119,7 @@ size_t Process::GetMallocUsage() {
     return EndOfMemory - StartOfMemory;
   return 0;
 #else
-#ifndef __MVS__  // Exclude for MVS in case -pedantic is used
+#ifndef __MVS__ // Exclude for MVS in case -pedantic is used
 #warning Cannot get malloc info on this platform
 #endif
   return 0;
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index f5881003a43bc..fcfeafb2259c7 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -423,8 +423,7 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
 #ifdef __MVS__
     WaitResult.Pid = waitpid(ChildPid, &status, WaitPidOptions);
     int GetrusageRC = getrusage(RUSAGE_CHILDREN, &Info);
-    assert(!GetrusageRC &&
-           "Must have valid measure of the resources!");
+    assert(!GetrusageRC && "Must have valid measure of the resources!");
 #else
     WaitResult.Pid = sys::wait4(ChildPid, &status, WaitPidOptions, &Info);
 #endif

>From ba17fce5a30d7d8684307743e344cfa86cc7903a Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 8 Dec 2023 11:10:42 -0500
Subject: [PATCH 3/4] create strsignal function instead

---
 llvm/lib/Support/Unix/Program.inc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index fcfeafb2259c7..fd6ad00ace841 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -61,6 +61,14 @@ extern char **environ;
 #endif
 #endif
 
+#ifdef __MVS__
+char *strsignal(int sig) {
+  static char msg[256];
+  sprintf(msg,"%d", sig);
+  return msg;
+}
+#endif
+
 using namespace llvm;
 using namespace sys;
 
@@ -500,11 +508,7 @@ 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)";

>From f9fdfa4f2fca28c27d5c84fe0b10c024e2d7bb79 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 8 Dec 2023 11:14:52 -0500
Subject: [PATCH 4/4] formatting

---
 llvm/lib/Support/Unix/Program.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index fd6ad00ace841..7c6f95d48ad8c 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -64,7 +64,7 @@ extern char **environ;
 #ifdef __MVS__
 char *strsignal(int sig) {
   static char msg[256];
-  sprintf(msg,"%d", sig);
+  sprintf(msg, "%d", sig);
   return msg;
 }
 #endif



More information about the llvm-commits mailing list