Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions llvm/include/llvm/Support/SystemZ/zOSSupport.h
Original file line number Diff line number Diff line change
@@ -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.
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.
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
4 changes: 4 additions & 0 deletions llvm/lib/Support/Unix/Process.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Support/Unix/Program.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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};
Expand Down