Skip to content

Commit 61ee923

Browse files
authored
[SystemZ][z/OS] Fix build errors on z/OS in the Unix .inc files (#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
1 parent 3959231 commit 61ee923

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===- zOSSupport.h - Common z/OS Include File ------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines z/OS implementations for common functions.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_SUPPORT_ZOSSUPPORT_H
14+
#define LLVM_SUPPORT_ZOSSUPPORT_H
15+
16+
#ifdef __MVS__
17+
#include <sys/resource.h>
18+
#include <sys/wait.h>
19+
20+
// z/OS Unix System Services does not have strsignal() support, so the
21+
// strsignal() function is implemented here.
22+
inline char *strsignal(int sig) {
23+
static char msg[256];
24+
sprintf(msg, "%d", sig);
25+
return msg;
26+
}
27+
28+
// z/OS Unix System Services does not have wait4() support, so the wait4
29+
// function is implemented here.
30+
inline pid_t wait4(pid_t pid, int *wstatus, int options,
31+
struct rusage *rusage) {
32+
pid_t Result = waitpid(pid, wstatus, options);
33+
int GetrusageRC = getrusage(RUSAGE_CHILDREN, rusage);
34+
assert(!GetrusageRC && "Must have valid measure of the resources!");
35+
return Result;
36+
}
37+
38+
#endif
39+
#endif

llvm/lib/Support/Unix/Process.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ getRUsageTimes() {
6262
::getrusage(RUSAGE_SELF, &RU);
6363
return {toDuration(RU.ru_utime), toDuration(RU.ru_stime)};
6464
#else
65+
#ifndef __MVS__ // Exclude for MVS in case -pedantic is used
6566
#warning Cannot get usage times on this platform
67+
#endif
6668
return {std::chrono::microseconds::zero(), std::chrono::microseconds::zero()};
6769
#endif
6870
}
@@ -117,7 +119,9 @@ size_t Process::GetMallocUsage() {
117119
return EndOfMemory - StartOfMemory;
118120
return 0;
119121
#else
122+
#ifndef __MVS__ // Exclude for MVS in case -pedantic is used
120123
#warning Cannot get malloc info on this platform
124+
#endif
121125
return 0;
122126
#endif
123127
}

llvm/lib/Support/Unix/Program.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/Support/FileSystem.h"
2626
#include "llvm/Support/Path.h"
2727
#include "llvm/Support/StringSaver.h"
28+
#include "llvm/Support/SystemZ/zOSSupport.h"
2829
#include "llvm/Support/raw_ostream.h"
2930
#if HAVE_SYS_STAT_H
3031
#include <sys/stat.h>
@@ -466,7 +467,7 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
466467
std::chrono::microseconds UserT = toDuration(Info.ru_utime);
467468
std::chrono::microseconds KernelT = toDuration(Info.ru_stime);
468469
uint64_t PeakMemory = 0;
469-
#ifndef __HAIKU__
470+
#if !defined(__HAIKU__) && !defined(__MVS__)
470471
PeakMemory = static_cast<uint64_t>(Info.ru_maxrss);
471472
#endif
472473
*ProcStat = ProcessStatistics{UserT + KernelT, UserT, PeakMemory};

0 commit comments

Comments
 (0)