https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/75339
This patch adds strnlen to the zOSSupport.h file to fix build failures in multiple files. >From 1b234e926dc6396fe4053f3c3463ed36e5d58778 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan <abhina.sreeskanthara...@ibm.com> Date: Wed, 13 Dec 2023 08:35:52 -0500 Subject: [PATCH] fix strnlen build failure for z/OS --- clang/lib/Lex/HeaderMap.cpp | 1 + llvm/include/llvm/Support/SystemZ/zOSSupport.h | 8 ++++++++ llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp | 1 + llvm/lib/ObjCopy/MachO/MachOObject.cpp | 1 + llvm/lib/ObjCopy/MachO/MachOReader.cpp | 1 + llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 + llvm/lib/ObjectYAML/MachOYAML.cpp | 1 + llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 + llvm/tools/llvm-readobj/ELFDumper.cpp | 1 + llvm/tools/llvm-readobj/ObjDumper.cpp | 1 + llvm/tools/obj2yaml/macho2yaml.cpp | 1 + 11 files changed, 18 insertions(+) diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index 22a1532c2d9383..adc56dc270e5f0 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SwapByteOrder.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/Debug.h" #include <cstring> #include <memory> diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h b/llvm/include/llvm/Support/SystemZ/zOSSupport.h index ee78147cb21554..f9a61f887d5dd1 100644 --- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h +++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h @@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options, return Result; } +// z/OS Unix System Services does not have strnlen() support, so the strnlen() +// function is implemented here. +inline std::size_t strnlen(const char *S, std::size_t MaxLen) { + const char *PtrToNullChar = + static_cast<const char *>(std::memchr(S, '\0', MaxLen)); + return PtrToNullChar ? PtrToNullChar - S : MaxLen; +} + #endif #endif diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp index 067ef39d90522f..a3d4ba3a94f7ac 100644 --- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "llvm/Support/Alignment.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SystemZ/zOSSupport.h" using namespace llvm; using namespace llvm::objcopy::macho; diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp index 9a4abadc8710a4..d593d6788e112f 100644 --- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp @@ -8,6 +8,7 @@ #include "MachOObject.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include <unordered_set> using namespace llvm; diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp index 25f8c020cde94d..4549977c12c3db 100644 --- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp +++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp @@ -11,6 +11,7 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Errc.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include <memory> using namespace llvm; diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index 6bcc2cee27edb6..c08b389daea9c3 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp index 86342c5501c708..82b2eaecec9be9 100644 --- a/llvm/lib/ObjectYAML/MachOYAML.cpp +++ b/llvm/lib/ObjectYAML/MachOYAML.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/Support/Format.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 2d396df7337f89..7bb0218ed53386 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #ifdef __linux__ #ifdef HAVE_LIBPFM diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 96564211622d26..3cf7c5a3b18955 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -57,6 +57,7 @@ #include "llvm/Support/RISCVAttributeParser.h" #include "llvm/Support/RISCVAttributes.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cinttypes> diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp index 6dde3725b4d655..59060ac217e32f 100644 --- a/llvm/tools/llvm-readobj/ObjDumper.cpp +++ b/llvm/tools/llvm-readobj/ObjDumper.cpp @@ -18,6 +18,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include "llvm/Support/raw_ostream.h" #include <map> diff --git a/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp index c006c0d2cbea4a..cdd871e8c1d684 100644 --- a/llvm/tools/obj2yaml/macho2yaml.cpp +++ b/llvm/tools/obj2yaml/macho2yaml.cpp @@ -15,6 +15,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/SystemZ/zOSSupport.h" #include <string.h> // for memcpy _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits