[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

Yusra Syeda via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 11:30:12 PST 2023


================
@@ -1026,6 +1030,78 @@ void SystemZAsmPrinter::emitADASection() {
   OutStreamer->popSection();
 }
 
+static uint32_t getProductVersion(Module &M) {
+  if (auto *VersionVal = cast_or_null<ConstantAsMetadata>(
+          M.getModuleFlag("zos_product_major_version")))
+    return cast<ConstantInt>(VersionVal->getValue())->getZExtValue();
+  return LLVM_VERSION_MAJOR;
+}
+
+static uint32_t getProductRelease(Module &M) {
+  if (auto *ReleaseVal = cast_or_null<ConstantAsMetadata>(
+          M.getModuleFlag("zos_product_minor_version")))
+    return cast<ConstantInt>(ReleaseVal->getValue())->getZExtValue();
+  return LLVM_VERSION_MINOR;
+}
+
+static uint32_t getProductPatch(Module &M) {
+  if (auto *PatchVal = cast_or_null<ConstantAsMetadata>(
+          M.getModuleFlag("zos_product_patchlevel")))
+    return cast<ConstantInt>(PatchVal->getValue())->getZExtValue();
+  return LLVM_VERSION_PATCH;
+}
+
+static time_t getTranslationTime(Module &M) {
+  std::time_t Time = 0;
+  if (auto *Val = cast_or_null<ConstantAsMetadata>(
+          M.getModuleFlag("zos_translation_time"))) {
+    long SecondsSinceEpoch = cast<ConstantInt>(Val->getValue())->getSExtValue();
+    Time = static_cast<time_t>(SecondsSinceEpoch);
+  }
+  return Time;
+}
+
+void SystemZAsmPrinter::emitIDRLSection(Module &M) {
+  OutStreamer->pushSection();
+  OutStreamer->switchSection(getObjFileLowering().getIDRLSection());
+  constexpr unsigned IDRLDataLength = 30;
+  std::time_t Time = getTranslationTime(M);
+
+  uint32_t ProductVersion = getProductVersion(M);
+  uint32_t ProductRelease = getProductRelease(M);
+
+  std::string ProductID;
+  if (auto *MD = M.getModuleFlag("zos_product_id"))
+    ProductID = cast<MDString>(MD)->getString().str();
+
+  if (ProductID.empty()) {
+    char ProductIDFormatted[11]; // 10 + null.
+    snprintf(ProductIDFormatted, sizeof(ProductIDFormatted), "LLVM  %02d%02d",
+             ProductVersion, ProductRelease);
+    ProductID = ProductIDFormatted;
+  }
+
+  // Remove - from Product Id, which makes it consistent with legacy.
+  // The binder expects alphanumeric characters only.
+  std::size_t DashFound = ProductID.find("-");
+  if (DashFound != std::string::npos)
+    ProductID.erase(ProductID.begin() + DashFound);
+
+  SmallString<IDRLDataLength + 1> TempStr;
+  raw_svector_ostream O(TempStr);
+  O << formatv("{0}{1,0-2:d}{2,0-2:d}{3:%Y-%m-%d %H:%M:%S}", ProductID.c_str(),
+               ProductVersion, ProductRelease, llvm::sys::toUtcTime(Time));
----------------
ysyeda wrote:

I added a check for this.

https://github.com/llvm/llvm-project/pull/68926


More information about the llvm-commits mailing list