[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
Tue Dec 12 08:41:39 PST 2023


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

>From e09bc72650ac808c6f9dab2bcc8fd983db617da3 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Mon, 11 Dec 2023 15:47:06 -0500
Subject: [PATCH 1/3] Create separate support header file

---
 .../include/llvm/Support/SystemZ/zOSSupport.h | 39 +++++++++++++++++++
 llvm/lib/Support/Unix/Process.inc             |  4 ++
 llvm/lib/Support/Unix/Program.inc             |  3 +-
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 llvm/include/llvm/Support/SystemZ/zOSSupport.h

diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
new file mode 100644
index 00000000000000..719fb93414657e
--- /dev/null
+++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
@@ -0,0 +1,39 @@
+//===- zOSSupport.h - Common z/OS Include File ------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines z/OS implementations for common functions.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_ZOSSUPPORT_H
+#define LLVM_SUPPORT_ZOSSUPPORT_H
+
+#ifdef __MVS__
+#include <sys/resource.h>
+#include <sys/wait.h>
+
+// z/OS Unix System Services does not have strsignal() support, so the
+// strsignal() function is implemented here.
+static inline char *strsignal(int sig) {
+  static char msg[256];
+  sprintf(msg, "%d", sig);
+  return msg;
+}
+
+// z/OS Unix System Services does not have wait4() support, so the wait4
+// function is implemented here.
+static inline pid_t wait4(pid_t pid, int *wstatus, int options,
+                          struct rusage *rusage) {
+  pid_t Result = waitpid(pid, wstatus, options);
+  int GetrusageRC = getrusage(RUSAGE_CHILDREN, rusage);
+  assert(!GetrusageRC && "Must have valid measure of the resources!");
+  return Result;
+}
+
+#endif
+#endif
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..895fdfc711e5c9 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -25,6 +25,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/raw_ostream.h"
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
@@ -466,7 +467,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};

>From dbfaf3eb1d25ef045aadd4241de2586252fdbaa9 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Tue, 12 Dec 2023 09:07:26 -0500
Subject: [PATCH 2/3] formatting

---
 llvm/lib/Support/Unix/Process.inc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index bf781eabf5c60b..551f0d7f0f029d 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;

>From 6f21e601684503bbccffd53d199c041f35ea2c8a Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Tue, 12 Dec 2023 11:41:28 -0500
Subject: [PATCH 3/3] remove static

---
 llvm/include/llvm/Support/SystemZ/zOSSupport.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
index 719fb93414657e..ee78147cb21554 100644
--- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h
+++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
@@ -19,7 +19,7 @@
 
 // z/OS Unix System Services does not have strsignal() support, so the
 // strsignal() function is implemented here.
-static inline char *strsignal(int sig) {
+inline char *strsignal(int sig) {
   static char msg[256];
   sprintf(msg, "%d", sig);
   return msg;
@@ -27,8 +27,8 @@ static inline char *strsignal(int sig) {
 
 // z/OS Unix System Services does not have wait4() support, so the wait4
 // function is implemented here.
-static inline pid_t wait4(pid_t pid, int *wstatus, int options,
-                          struct rusage *rusage) {
+inline pid_t wait4(pid_t pid, int *wstatus, int options,
+                   struct rusage *rusage) {
   pid_t Result = waitpid(pid, wstatus, options);
   int GetrusageRC = getrusage(RUSAGE_CHILDREN, rusage);
   assert(!GetrusageRC && "Must have valid measure of the resources!");



More information about the llvm-commits mailing list