[llvm] [SystemZ][z/OS] Add AMODE to PR symbols (PR #223541)

Kai Nacke via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 13:47:03 PDT 2026


https://github.com/redstar updated https://github.com/llvm/llvm-project/pull/223541

>From 838b328bf8aadc9e2ec3c5345716f4abde76f8be Mon Sep 17 00:00:00 2001
From: Kai Nacke <kai.peter.nacke at ibm.com>
Date: Mon, 14 Sep 2026 16:57:32 -0400
Subject: [PATCH 1/2] [SystemZ][z/OS] Add AMODE to PR symbols

Contrary to the documentation, setting the AMODE at PR symbols is
required. The symptom is that references to variables `optind` and
`optarg` (from include `<getopt.h>`, the LE-provided C runtime)
results in "missing symbol" errors.
Fix is to add AMODE to PrAttr, analog to LdAttr.
---
 llvm/include/llvm/MC/MCGOFFAttributes.h           | 1 +
 llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 7 ++++---
 llvm/lib/MC/GOFFObjectWriter.cpp                  | 3 ++-
 llvm/lib/MC/MCObjectFileInfo.cpp                  | 6 ++++--
 llvm/lib/MC/MCSymbolGOFF.cpp                      | 3 ++-
 llvm/test/CodeGen/SystemZ/zos-common-global.ll    | 2 +-
 llvm/test/CodeGen/SystemZ/zos-section-2.ll        | 4 ++--
 llvm/test/CodeGen/SystemZ/zos-symbol-2.ll         | 2 +-
 llvm/test/tools/llvm-ar/zos-symattrs.test         | 2 +-
 9 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/llvm/include/llvm/MC/MCGOFFAttributes.h b/llvm/include/llvm/MC/MCGOFFAttributes.h
index 4af5717fccfe6..2dd15f1378bd6 100644
--- a/llvm/include/llvm/MC/MCGOFFAttributes.h
+++ b/llvm/include/llvm/MC/MCGOFFAttributes.h
@@ -76,6 +76,7 @@ struct PRAttr {
   GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
   GOFF::ESDBindingStrength BindingStrength = GOFF::ESD_BST_Strong;
   GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDAmode Amode;
   GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
   uint32_t SortKey = 0;
 };
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index d47b35cfa7bcf..3610b800dbc40 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2916,7 +2916,7 @@ MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA(
   return getContext().getGOFFSection(
       SectionKind::getData(), Name,
       GOFF::PRAttr{true, GOFF::ESD_EXE_DATA, GOFF::ESD_BST_Strong,
-                   GOFF::ESD_LT_XPLink, GOFF::ESD_BSC_Section, 0},
+                   GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_64, GOFF::ESD_BSC_Section, 0},
       WSA);
 }
 
@@ -2951,7 +2951,7 @@ MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
     MCSectionGOFF *PR = getContext().getGOFFSection(
         Kind, Symbol->getName(),
         GOFF::PRAttr{false, GOFF::ESD_EXE_DATA, GOFF::ESD_BST_Strong,
-                     GOFF::ESD_LT_XPLink, PRBindingScope, 0},
+                     GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_64, PRBindingScope, 0},
         ED);
     // The binder rejects zero-length PR sections. Mark the PR so the writer
     // inflates it to a valid length if needed.
@@ -2988,7 +2988,8 @@ TargetLoweringObjectFileGOFF::getStaticXtorSection(unsigned Priority) const {
   MCSectionGOFF *Xtor = Ctx.getGOFFSection(
       SectionKind::getData(), Name,
       GOFF::PRAttr{true, GOFF::ESD_EXE_DATA, GOFF::ESD_BST_Strong,
-                   GOFF::ESD_LT_XPLink, GOFF::ESD_BSC_Section, Prio},
+                   GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_64,
+                   GOFF::ESD_BSC_Section, Prio},
       SInit);
   return Xtor;
 }
diff --git a/llvm/lib/MC/GOFFObjectWriter.cpp b/llvm/lib/MC/GOFFObjectWriter.cpp
index 9593375e957e8..713abd5f2a36c 100644
--- a/llvm/lib/MC/GOFFObjectWriter.cpp
+++ b/llvm/lib/MC/GOFFObjectWriter.cpp
@@ -267,6 +267,7 @@ class GOFFSymbol {
     BehavAttrs.setExecutable(Attr.Executable);
     BehavAttrs.setBindingStrength(Attr.BindingStrength);
     BehavAttrs.setLinkageType(Attr.Linkage);
+    BehavAttrs.setAmode(Attr.Amode);
     BehavAttrs.setBindingScope(Attr.BindingScope);
     BehavAttrs.setAlignment(Alignment);
   }
@@ -403,7 +404,7 @@ void GOFFWriter::defineExtern(const MCSymbolGOFF &Symbol) {
                   ED->getEDAttributes(), ED->getEDAlignment(),
                   GOFF::PRAttr{/*IsRenamable*/ false, Symbol.getCodeData(),
                                Symbol.getBindingStrength(), Symbol.getLinkage(),
-                               Symbol.getBindingScope(), 0});
+                               GOFF::ESD_AMODE_64, Symbol.getBindingScope(), 0});
     writeSymbol(PR);
   } else {
     GOFFSymbol ER(Symbol.getExternalName(), Symbol.getIndex(),
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 41e5adf304d35..36ef62b0d0fe8 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -587,7 +587,8 @@ void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
   ADASection = Ctx->getGOFFSection(
       SectionKind::getData(), "#S",
       GOFF::PRAttr{false, GOFF::ESD_EXE_DATA, GOFF::ESD_BST_Strong,
-                   GOFF::ESD_LT_XPLink, GOFF::ESD_BSC_Section, 0},
+                   GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_None,
+                   GOFF::ESD_BSC_Section, 0},
       ADAEDSection);
 
   TextSection = Ctx->getGOFFSection(
@@ -608,7 +609,8 @@ void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {
   PPA2ListSection = Ctx->getGOFFSection(
       SectionKind::getData(), ".&ppa2",
       GOFF::PRAttr{true, GOFF::ESD_EXE_DATA, GOFF::ESD_BST_Strong,
-                   GOFF::ESD_LT_OS, GOFF::ESD_BSC_Section, 0},
+                   GOFF::ESD_LT_OS, GOFF::ESD_AMODE_None,
+                   GOFF::ESD_BSC_Section, 0},
       PPA2ListEDSection);
 
   IDRLSection = Ctx->getGOFFSection(
diff --git a/llvm/lib/MC/MCSymbolGOFF.cpp b/llvm/lib/MC/MCSymbolGOFF.cpp
index 43939f8f407b5..52b8328444b58 100644
--- a/llvm/lib/MC/MCSymbolGOFF.cpp
+++ b/llvm/lib/MC/MCSymbolGOFF.cpp
@@ -31,7 +31,8 @@ MCSectionGOFF *MCSymbolGOFF::getSectionForCommonSymbol(MCContext &Ctx,
   return Ctx.getGOFFSection(
       SectionKind::getBSS(), getName(),
       GOFF::PRAttr{false, GOFF::ESD_EXE_DATA, GOFF::ESD_BST_Strong,
-                   GOFF::ESD_LT_XPLink, getBindingScope(), 0},
+                   GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_64,
+                   getBindingScope(), 0},
       ED);
 }
 
diff --git a/llvm/test/CodeGen/SystemZ/zos-common-global.ll b/llvm/test/CodeGen/SystemZ/zos-common-global.ll
index a169181f3d631..ca63a959faffd 100644
--- a/llvm/test/CodeGen/SystemZ/zos-common-global.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-common-global.ll
@@ -29,5 +29,5 @@
 ; 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: 0002b0 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 01
 ; CHECK-NEXT: 0002c0 00 04 22 00 00 00 00 01 a7 00 00 00 00 00 00 00
diff --git a/llvm/test/CodeGen/SystemZ/zos-section-2.ll b/llvm/test/CodeGen/SystemZ/zos-section-2.ll
index eb6e64cd73aa1..60f587499ed63 100644
--- a/llvm/test/CodeGen/SystemZ/zos-section-2.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-section-2.ll
@@ -88,7 +88,7 @@ source_filename = "test.ll"
 ; CHECK-NEXT: 000280 03 00 00 03 [[DATA_PR:00 00 00 07]] [[DATA_WSA]] 00 00 00 00
 ; CHECK-NEXT: 000290 00 00 00 00 00 00 00 00 [[DATA_LEN: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: 0002b0 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 01
 ; CHECK-NEXT: 0002c0 00 03 22 00 00 00 00 04 84 81 a3 81 00 00 00 00
 
 ; ESD record, type SD.
@@ -112,7 +112,7 @@ source_filename = "test.ll"
 ; CHECK-NEXT: 000370 03 00 00 03 [[BSS_PR:00 00 00 0a]] [[BSS_WSA]] 00 00 00 00
 ; CHECK-NEXT: 000380 00 00 00 00 00 00 00 00 [[BSS_LEN:00 00 00 08]] 00 00 00 00
 ; CHECK-NEXT: 000390 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
-; CHECK-NEXT: 0003a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
+; CHECK-NEXT: 0003a0 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 01
 ; CHECK-NEXT: 0003b0 00 03 23 00 00 00 00 03 82 a2 a2 00 00 00 00 00
 
 ; ESD record, type ED.
diff --git a/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll b/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
index 9d3133b29ee6a..c5e77cfc612a2 100644
--- a/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
@@ -42,7 +42,7 @@ entry:
 ; CHECKREL:      0004b0 03 00 00 03 00 00 00 0e [[C_WSA64]] 00 00 00 00
 ; CHECKREL-NEXT: 0004c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ; CHECKREL-NEXT: 0004d0 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
-; CHECKREL-NEXT: 0004e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
+; CHECKREL-NEXT: 0004e0 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 01
 ; CHECKREL-NEXT: 0004f0 00 04 24 00 00 00 00 01 82 00 00 00 00 00 00 00
 
 ; Check the relocation data directory.
diff --git a/llvm/test/tools/llvm-ar/zos-symattrs.test b/llvm/test/tools/llvm-ar/zos-symattrs.test
index 239cdce6dce75..c88877cedc76b 100644
--- a/llvm/test/tools/llvm-ar/zos-symattrs.test
+++ b/llvm/test/tools/llvm-ar/zos-symattrs.test
@@ -27,7 +27,7 @@
 
 # ARMAP:      Archive map
 # ARMAP-NEXT: s_func in func.o (flags: 0x00000006 [64-bit + XPLink])
-# ARMAP-NEXT: s_data in data.o (flags: 0x00000003 [XPLink + WSA])
+# ARMAP-NEXT: s_data in data.o (flags: 0x00000007 [64-bit + XPLink + WSA])
 
 ## 2. Test that basic archive operations still work on a GOFF archive.
 ##    llvm-ar t should list exactly the expected member names and nothing else.

>From 824500a41ea67f309afb1e7907e313b6aebd8a88 Mon Sep 17 00:00:00 2001
From: Kai Nacke <kai.peter.nacke at ibm.com>
Date: Tue, 29 Sep 2026 16:46:25 -0400
Subject: [PATCH 2/2] Re-check setting of AMODE.

---
 llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 3610b800dbc40..cf03edf8185e8 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2916,7 +2916,7 @@ MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA(
   return getContext().getGOFFSection(
       SectionKind::getData(), Name,
       GOFF::PRAttr{true, GOFF::ESD_EXE_DATA, GOFF::ESD_BST_Strong,
-                   GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_64, GOFF::ESD_BSC_Section, 0},
+                   GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_None, GOFF::ESD_BSC_Section, 0},
       WSA);
 }
 
@@ -2988,7 +2988,7 @@ TargetLoweringObjectFileGOFF::getStaticXtorSection(unsigned Priority) const {
   MCSectionGOFF *Xtor = Ctx.getGOFFSection(
       SectionKind::getData(), Name,
       GOFF::PRAttr{true, GOFF::ESD_EXE_DATA, GOFF::ESD_BST_Strong,
-                   GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_64,
+                   GOFF::ESD_LT_XPLink, GOFF::ESD_AMODE_None,
                    GOFF::ESD_BSC_Section, Prio},
       SInit);
   return Xtor;



More information about the llvm-commits mailing list