[llvm-branch-commits] [llvm] release/23.x: [SystemZ][z/OS] Implement emitCommonSymbol in MCGOFFStreamer (#210179) (PR #213042)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jul 30 08:20:08 PDT 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/213042
Backport 705d0ec6115cef3232eafe6221f42f78e7b884e8
Requested by: @maryammo
>From 4df58feb98c1daabcb637c323148cdd033ecbcfd Mon Sep 17 00:00:00 2001
From: Maryam Moghadas <maryammo at ca.ibm.com>
Date: Wed, 29 Jul 2026 15:58:16 -0400
Subject: [PATCH] [SystemZ][z/OS] Implement emitCommonSymbol in MCGOFFStreamer
(#210179)
Common globals were not emitted in GOFF object files due to a missing
emitCommonSymbol implementation. This adds the implementation to emit
the required SD/ED/PR ESD records in the GOFF object file.
(cherry picked from commit 705d0ec6115cef3232eafe6221f42f78e7b884e8)
---
llvm/include/llvm/MC/MCGOFFStreamer.h | 2 +-
llvm/lib/MC/MCGOFFStreamer.cpp | 29 +++++++++++++++++++
.../test/CodeGen/SystemZ/zos-common-global.ll | 28 ++++++++++++++++++
3 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/SystemZ/zos-common-global.ll
diff --git a/llvm/include/llvm/MC/MCGOFFStreamer.h b/llvm/include/llvm/MC/MCGOFFStreamer.h
index 756574d1caaf3..92b37681b1225 100644
--- a/llvm/include/llvm/MC/MCGOFFStreamer.h
+++ b/llvm/include/llvm/MC/MCGOFFStreamer.h
@@ -37,7 +37,7 @@ class LLVM_ABI MCGOFFStreamer : public MCObjectStreamer {
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
- Align ByteAlignment) override {}
+ Align ByteAlignment) override;
};
} // end namespace llvm
diff --git a/llvm/lib/MC/MCGOFFStreamer.cpp b/llvm/lib/MC/MCGOFFStreamer.cpp
index 7c99fcbc5451c..ebe8bc0a0207d 100644
--- a/llvm/lib/MC/MCGOFFStreamer.cpp
+++ b/llvm/lib/MC/MCGOFFStreamer.cpp
@@ -73,6 +73,35 @@ bool MCGOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
return static_cast<MCSymbolGOFF *>(Sym)->setSymbolAttribute(Attribute);
}
+void MCGOFFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
+ Align ByteAlignment) {
+ auto *Symbol = static_cast<MCSymbolGOFF *>(S);
+
+ MCSectionGOFF *SD = getContext().getGOFFSection(
+ SectionKind::getMetadata(), Symbol->getName(),
+ GOFF::SDAttr{GOFF::ESD_TA_Unspecified, GOFF::ESD_BSC_Unspecified});
+
+ MCSectionGOFF *ED = getContext().getGOFFSection(
+ SectionKind::getMetadata(), GOFF::CLASS_WSA,
+ GOFF::EDAttr{false, GOFF::ESD_RMODE_64, GOFF::ESD_NS_Parts,
+ GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
+ GOFF::ESD_LB_Deferred, GOFF::ESD_RQ_0, 0},
+ SD);
+ ED->setAlignment(ByteAlignment);
+
+ MCSectionGOFF *Section = getContext().getGOFFSection(
+ SectionKind::getBSS(), Symbol->getName(),
+ GOFF::PRAttr{false, GOFF::ESD_EXE_DATA, GOFF::ESD_LT_XPLink,
+ Symbol->getBindingScope(), 0},
+ ED);
+
+ pushSection();
+ switchSection(Section);
+ emitLabel(Symbol);
+ emitZeros(Size);
+ popSection();
+}
+
MCStreamer *llvm::createGOFFStreamer(MCContext &Context,
std::unique_ptr<MCAsmBackend> &&MAB,
std::unique_ptr<MCObjectWriter> &&OW,
diff --git a/llvm/test/CodeGen/SystemZ/zos-common-global.ll b/llvm/test/CodeGen/SystemZ/zos-common-global.ll
new file mode 100644
index 0000000000000..98d3c357964c5
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/zos-common-global.ll
@@ -0,0 +1,28 @@
+; RUN: llc <%s --mtriple s390x-ibm-zos --filetype=obj | \
+; RUN: od -Ax -tx1 -v | FileCheck --ignore-case %s
+
+ at x = common global i32 0, align 4
+
+; ESD record, type SD.
+; The name is x.
+; CHECK: 0001e0 03 00 00 00 [[X:00 00 00 05]] 00 00 00 00 00 00 00 00
+; CHECK-NEXT: 0001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+; CHECK-NEXT: 000200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+; CHECK-NEXT: 000210 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+; CHECK-NEXT: 000220 00 00 00 00 00 00 00 01 a7 00 00 00 00 00 00 00
+
+; ESD record, type ED.
+; The name is C_WSA64.
+; CHECK-NEXT: 000230 03 00 00 01 [[X_WSA:00 00 00 06]] [[X]] 00 00 00 00
+; CHECK-NEXT: 000240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+; CHECK-NEXT: 000250 00 00 00 00 00 00 00 00 03 80 00 00 00 00 00 00
+; CHECK-NEXT: 000260 00 00 00 00 00 00 00 00 00 00 00 00 00 04 01 00
+; CHECK-NEXT: 000270 00 40 02 00 00 00 00 07 c3 6d e6 e2 c1 f6 f4 00
+
+; ESD record, type PR.
+; The name is x.
+; CHECK-NEXT: 000280 03 00 00 03 [[X_PR:00 00 00 07]] [[X_WSA]] 00 00 00 00
+; CHECK-NEXT: 000290 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00
+; CHECK-NEXT: 0002a0 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
+; CHECK-NEXT: 0002b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
+; CHECK-NEXT: 0002c0 00 04 22 00 00 00 00 01 a7 00 00 00 00 00 00 00
More information about the llvm-branch-commits
mailing list