[llvm] 7fd291b - [GOFF] Set reference to ADA (#179734)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 10:31:10 PDT 2026


Author: Kai Nacke
Date: 2026-03-09T13:31:05-04:00
New Revision: 7fd291b400bece84e4e893d7367ab0d09d588ff7

URL: https://github.com/llvm/llvm-project/commit/7fd291b400bece84e4e893d7367ab0d09d588ff7
DIFF: https://github.com/llvm/llvm-project/commit/7fd291b400bece84e4e893d7367ab0d09d588ff7.diff

LOG: [GOFF] Set reference to ADA (#179734)

Function symbols must have a reference to the ADA, because this becomes
the value of the r5 register when the function is called. Simply get the
value from the begin symbol of the section.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCSymbolGOFF.h
    llvm/lib/MC/MCAsmInfoGOFF.cpp
    llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
    llvm/lib/Target/SystemZ/MCTargetDesc/SystemZTargetStreamer.h
    llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
    llvm/test/CodeGen/SystemZ/zos-func-alias.ll
    llvm/test/CodeGen/SystemZ/zos-section-1.ll
    llvm/test/CodeGen/SystemZ/zos-symbol-1.ll
    llvm/test/CodeGen/SystemZ/zos-symbol-2.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCSymbolGOFF.h b/llvm/include/llvm/MC/MCSymbolGOFF.h
index 8bbd53f824f1e..5ac37f28c43f0 100644
--- a/llvm/include/llvm/MC/MCSymbolGOFF.h
+++ b/llvm/include/llvm/MC/MCSymbolGOFF.h
@@ -43,6 +43,7 @@ class MCSymbolGOFF : public MCSymbol {
       : MCSymbol(Name, IsTemporary) {}
 
   void setADA(MCSectionGOFF *AssociatedDataArea) {
+    assert(AssociatedDataArea && "ADA must be non-null");
     ADA = AssociatedDataArea;
     AssociatedDataArea->RequiresNonZeroLength = true;
   }

diff  --git a/llvm/lib/MC/MCAsmInfoGOFF.cpp b/llvm/lib/MC/MCAsmInfoGOFF.cpp
index 325854a0e740f..9ec61c137a06f 100644
--- a/llvm/lib/MC/MCAsmInfoGOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoGOFF.cpp
@@ -13,8 +13,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/MC/MCAsmInfoGOFF.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/BinaryFormat/GOFF.h"
 #include "llvm/MC/MCSectionGOFF.h"
+#include "llvm/MC/MCSymbolGOFF.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
@@ -83,17 +85,21 @@ static void emitCATTR(raw_ostream &OS, StringRef Name, GOFF::ESDRmode Rmode,
   OS << '\n';
 }
 
-static void emitXATTR(raw_ostream &OS, StringRef Name,
+static void emitXATTR(raw_ostream &OS, StringRef Name, MCSectionGOFF *ADA,
                       GOFF::ESDLinkageType Linkage,
                       GOFF::ESDExecutable Executable,
                       GOFF::ESDBindingScope BindingScope) {
+  llvm::ListSeparator Sep(",");
   OS << Name << " XATTR ";
-  OS << "LINKAGE(" << (Linkage == GOFF::ESD_LT_OS ? "OS" : "XPLINK") << "),";
+  OS << Sep << "LINKAGE(" << (Linkage == GOFF::ESD_LT_OS ? "OS" : "XPLINK")
+     << ")";
   if (Executable != GOFF::ESD_EXE_Unspecified)
-    OS << "REFERENCE(" << (Executable == GOFF::ESD_EXE_CODE ? "CODE" : "DATA")
-       << "),";
+    OS << Sep << "REFERENCE("
+       << (Executable == GOFF::ESD_EXE_CODE ? "CODE" : "DATA") << ")";
+  if (ADA)
+    OS << Sep << "PSECT(" << ADA->getName() << ")";
   if (BindingScope != GOFF::ESD_BSC_Unspecified) {
-    OS << "SCOPE(";
+    OS << Sep << "SCOPE(";
     switch (BindingScope) {
     case GOFF::ESD_BSC_Section:
       OS << "SECTION";
@@ -138,6 +144,12 @@ void MCAsmInfoGOFF::printSwitchToSection(const MCSection &Section,
                 Sec.EDAttributes.Alignment, Sec.EDAttributes.LoadBehavior,
                 GOFF::ESD_EXE_Unspecified, Sec.EDAttributes.IsReadOnly, 0,
                 Sec.EDAttributes.FillByteValue, StringRef());
+      if (auto *BeginSym = static_cast<MCSymbolGOFF *>(Sec.getBeginSymbol())) {
+        if (BeginSym->getADA())
+          emitXATTR(OS, BeginSym->getName(), BeginSym->getADA(),
+                    GOFF::ESD_LT_XPLink, GOFF::ESD_EXE_Unspecified,
+                    GOFF::ESD_BSC_Section);
+      }
       Sec.Emitted = true;
       EmitExternalName();
     } else
@@ -153,7 +165,11 @@ void MCAsmInfoGOFF::printSwitchToSection(const MCSection &Section,
                 Sec.PRAttributes.Executable, ED->EDAttributes.IsReadOnly,
                 Sec.PRAttributes.SortKey, ED->EDAttributes.FillByteValue,
                 Sec.getName());
-      emitXATTR(OS, Sec.getName(), Sec.PRAttributes.Linkage,
+      MCSectionGOFF *ADA =
+          Sec.getBeginSymbol() != nullptr
+              ? static_cast<MCSymbolGOFF *>(Sec.getBeginSymbol())->getADA()
+              : nullptr;
+      emitXATTR(OS, Sec.getName(), ADA, Sec.PRAttributes.Linkage,
                 Sec.PRAttributes.Executable, Sec.PRAttributes.BindingScope);
       ED->Emitted = true;
       Sec.Emitted = true;

diff  --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
index d1c3253330f46..51442a8ca47eb 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
@@ -193,8 +193,8 @@ void SystemZHLASMAsmStreamer::emitInstruction(const MCInst &Inst,
   EmitEOL();
 }
 
-static void emitXATTR(raw_ostream &OS, StringRef Name, bool IsIndirectReference,
-                      GOFF::ESDLinkageType Linkage,
+static void emitXATTR(raw_ostream &OS, StringRef Name, MCSectionGOFF *ADA,
+                      bool IsIndirectReference, GOFF::ESDLinkageType Linkage,
                       GOFF::ESDExecutable Executable,
                       GOFF::ESDBindingScope BindingScope) {
   llvm::ListSeparator Sep(",");
@@ -215,6 +215,8 @@ static void emitXATTR(raw_ostream &OS, StringRef Name, bool IsIndirectReference,
 
     OS << ")";
   }
+  if (ADA)
+    OS << Sep << "PSECT(" << ADA->getName() << ")";
   if (BindingScope != GOFF::ESD_BSC_Unspecified) {
     OS << Sep << "SCOPE(";
     switch (BindingScope) {
@@ -255,8 +257,8 @@ void SystemZHLASMAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
       EmitEOL();
     }
 
-    emitXATTR(OS, Sym->getName(), Sym->isIndirect(), Sym->getLinkage(),
-              Sym->getCodeData(), Sym->getBindingScope());
+    emitXATTR(OS, Sym->getName(), Sym->getADA(), Sym->isIndirect(),
+              Sym->getLinkage(), Sym->getCodeData(), Sym->getBindingScope());
     EmitEOL();
     if (Sym->hasExternalName())
       OS << Sym->getName() << " ALIAS C'" << Sym->getExternalName() << "'\n";
@@ -367,8 +369,8 @@ void SystemZHLASMAsmStreamer::finishImpl() {
     auto &Sym = static_cast<MCSymbolGOFF &>(const_cast<MCSymbol &>(Symbol));
     OS << " " << (Sym.isWeak() ? "WXTRN" : "EXTRN") << " " << Sym.getName();
     EmitEOL();
-    emitXATTR(OS, Sym.getName(), Sym.isIndirect(), Sym.getLinkage(),
-              Sym.getCodeData(), Sym.getBindingScope());
+    emitXATTR(OS, Sym.getName(), Sym.getADA(), Sym.isIndirect(),
+              Sym.getLinkage(), Sym.getCodeData(), Sym.getBindingScope());
     EmitEOL();
     if (Sym.hasExternalName())
       OS << Sym.getName() << " ALIAS C'" << Sym.getExternalName() << "'\n";

diff  --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZTargetStreamer.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZTargetStreamer.h
index 878600a67edbc..0c98557703517 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZTargetStreamer.h
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZTargetStreamer.h
@@ -67,6 +67,8 @@ class SystemZTargetStreamer : public MCTargetStreamer {
                                            const MCSymbol *Lo) {
     return nullptr;
   }
+
+  virtual void emitADA(MCSymbol *Sym, MCSection *Section) {}
 };
 
 class SystemZTargetGOFFStreamer : public SystemZTargetStreamer {
@@ -80,6 +82,10 @@ class SystemZTargetGOFFStreamer : public SystemZTargetStreamer {
   virtual void emitExternalName(MCSection *Sec, StringRef Name) override {
     static_cast<MCSectionGOFF *>(Sec)->setExternalName(Name);
   }
+  void emitADA(MCSymbol *Sym, MCSection *Section) override {
+    static_cast<MCSymbolGOFF *>(Sym)->setADA(
+        static_cast<MCSectionGOFF *>(Section));
+  }
 };
 
 class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {
@@ -97,6 +103,10 @@ class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {
   virtual void emitExternalName(MCSection *Sec, StringRef Name) override {
     static_cast<MCSectionGOFF *>(Sec)->setExternalName(Name);
   }
+  void emitADA(MCSymbol *Sym, MCSection *Section) override {
+    static_cast<MCSymbolGOFF *>(Sym)->setADA(
+        static_cast<MCSectionGOFF *>(Section));
+  }
 };
 
 class SystemZTargetELFStreamer : public SystemZTargetStreamer {

diff  --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index cb451a1ca4f55..8be75196f0482 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -1925,6 +1925,9 @@ void SystemZAsmPrinter::emitFunctionEntryLabel() {
         OutStreamer->AddComment("  Bit 2: 0 = Does not use alloca");
     }
     OutStreamer->emitInt32(DSAAndFlags);
+
+    getTargetStreamer()->emitADA(CurrentFnSym,
+                                 getObjFileLowering().getADASection());
   }
 
   AsmPrinter::emitFunctionEntryLabel();

diff  --git a/llvm/test/CodeGen/SystemZ/zos-func-alias.ll b/llvm/test/CodeGen/SystemZ/zos-func-alias.ll
index ee862cafc6776..a0c4d3fdece2a 100644
--- a/llvm/test/CodeGen/SystemZ/zos-func-alias.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-func-alias.ll
@@ -3,7 +3,7 @@
 ; RUN: llc < %s -mtriple=s390x-ibm-zos | FileCheck %s
 
 ; CHECK:      ENTRY foo
-; CHECK-NEXT: foo XATTR LINKAGE(XPLINK),REFERENCE(CODE),SCOPE(LIBRARY)
+; CHECK-NEXT: foo XATTR LINKAGE(XPLINK),REFERENCE(CODE),PSECT(stdin#S),SCOPE(LIBRARY)
 ; CHECK-NEXT: foo DS 0H
 ; CHECK-NEXT: ENTRY foo
 ; CHECK-NEXT: foo1 XATTR LINKAGE(XPLINK),REFERENCE(CODE),SCOPE(LIBRARY)

diff  --git a/llvm/test/CodeGen/SystemZ/zos-section-1.ll b/llvm/test/CodeGen/SystemZ/zos-section-1.ll
index 0fe781c94b6f2..ac9b6fc362c36 100644
--- a/llvm/test/CodeGen/SystemZ/zos-section-1.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-section-1.ll
@@ -116,7 +116,7 @@ entry:
 ; The name is me.
 ; CHECK-NEXT: 000370 03 00 00 02 [[ME:00 00 00 0a]] [[C_CODE64]] 00 00 00 00
 ; CHECK-NEXT: 000380 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00
-; CHECK-NEXT: 000390 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
+; CHECK-NEXT: 000390 00 00 00 00 00 00 00 00 01 00 00 00 [[TESTS]]
 ; CHECK-NEXT: 0003a0 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 02
 ; CHECK-NEXT: 0003b0 00 04 20 00 00 00 00 02 94 85 00 00 00 00 00 00
 

diff  --git a/llvm/test/CodeGen/SystemZ/zos-symbol-1.ll b/llvm/test/CodeGen/SystemZ/zos-symbol-1.ll
index 3e737dd66c514..85e0858e796d2 100644
--- a/llvm/test/CodeGen/SystemZ/zos-symbol-1.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-symbol-1.ll
@@ -20,14 +20,18 @@ entry:
   ret void
 }
 
+; CHECK:      stdin#C CSECT
+; CHECK-NEXT: C_CODE64 CATTR ALIGN(3),FILL(0),READONLY,RMODE(64)
+; CHECK-NEXT: stdin#C XATTR LINKAGE(XPLINK),PSECT(stdin#S),SCOPE(SECTION)
+
 ; CHECK:        ENTRY me1
-; CHECK-NEXT: me1 XATTR LINKAGE(XPLINK),REFERENCE(CODE),SCOPE(SECTION)
+; CHECK-NEXT: me1 XATTR LINKAGE(XPLINK),REFERENCE(CODE),PSECT(stdin#S),SCOPE(SECTION)
 
 ; CHECK:       ENTRY me2
-; CHECK-NEXT: me2 XATTR LINKAGE(XPLINK),REFERENCE(CODE),SCOPE(LIBRARY)
+; CHECK-NEXT: me2 XATTR LINKAGE(XPLINK),REFERENCE(CODE),PSECT(stdin#S),SCOPE(LIBRARY)
 
 ; CHECK:       ENTRY me3
-; CHECK-NEXT: me3 XATTR LINKAGE(XPLINK),REFERENCE(CODE),SCOPE(EXPORT)
+; CHECK-NEXT: me3 XATTR LINKAGE(XPLINK),REFERENCE(CODE),PSECT(stdin#S),SCOPE(EXPORT)
 
 ; CHECK:       EXTRN CELQSTRT
 ; CHECK-NEXT: CELQSTRT XATTR LINKAGE(OS),SCOPE(EXPORT)

diff  --git a/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll b/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
index 663c01ccd80dc..bccbe7c672be7 100644
--- a/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
@@ -19,7 +19,7 @@ entry:
 
 ; Check the attributes on the function
 ; CHECK:       ENTRY calc
-; CHECK-NEXT: calc XATTR LINKAGE(XPLINK),REFERENCE(CODE),SCOPE(EXPORT)
+; CHECK-NEXT: calc XATTR LINKAGE(XPLINK),REFERENCE(CODE),PSECT(stdin#S),SCOPE(EXPORT)
 ; CHECK-NEXT: calc DS 0H
 
 ; Check the definition of the variable


        


More information about the llvm-commits mailing list