[llvm-branch-commits] [llvm] [PowerPC][GlobalMerge] Enable GlobalMerge by default on AIX (PR #101226)

2024-07-30 Thread Kai Nacke via llvm-branch-commits


@@ -500,7 +500,10 @@ void PPCPassConfig::addIRPasses() {
 }
 
 bool PPCPassConfig::addPreISel() {
-  if (EnableGlobalMerge)
+  if ((EnableGlobalMerge.getNumOccurrences() > 0)
+  ? EnableGlobalMerge
+  : (TM->getTargetTriple().isOSAIX() &&
+ getOptLevel() != CodeGenOptLevel::None))

redstar wrote:

I think the condition can be simplified:

```suggestion
  if (EnableGlobalMerge
  || (TM->getTargetTriple().isOSAIX() &&
 getOptLevel() != CodeGenOptLevel::None))
```
(formatting is most likely wrong)

https://github.com/llvm/llvm-project/pull/101226
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [PowerPC][GlobalMerge] Reduce TOC usage by merging internal and private global data (PR #101224)

2024-07-30 Thread Kai Nacke via llvm-branch-commits


@@ -720,8 +731,14 @@ bool GlobalMergeImpl::run(Module &M) {
 
 Pass *llvm::createGlobalMergePass(const TargetMachine *TM, unsigned Offset,
   bool OnlyOptimizeForSize,
-  bool MergeExternalByDefault) {
+  bool MergeExternalByDefault,
+  bool MergePrivateByDefault,
+  bool MergeConstantByDefault) {
   bool MergeExternal = (EnableGlobalMergeOnExternal == cl::BOU_UNSET) ?
 MergeExternalByDefault : (EnableGlobalMergeOnExternal == cl::BOU_TRUE);
-  return new GlobalMerge(TM, Offset, OnlyOptimizeForSize, MergeExternal);
+  bool MergeConstant = EnableGlobalMergeOnConst.getNumOccurrences() > 0
+   ? EnableGlobalMergeOnConst
+   : MergeConstantByDefault;

redstar wrote:

```suggestion
  bool MergeConstant = EnableGlobalMergeOnConst || MergeConstantByDefault;
```

https://github.com/llvm/llvm-project/pull/101224
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [PowerPC][GlobalMerge] Reduce TOC usage by merging internal and private global data (PR #101224)

2024-08-02 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/101224
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [PowerPC][GlobalMerge] Enable GlobalMerge by default on AIX (PR #101226)

2024-08-02 Thread Kai Nacke via llvm-branch-commits


@@ -500,7 +500,10 @@ void PPCPassConfig::addIRPasses() {
 }
 
 bool PPCPassConfig::addPreISel() {
-  if (EnableGlobalMerge)
+  if ((EnableGlobalMerge.getNumOccurrences() > 0)
+  ? EnableGlobalMerge
+  : (TM->getTargetTriple().isOSAIX() &&
+ getOptLevel() != CodeGenOptLevel::None))

redstar wrote:

First thought: there is a slight change in the semantics.
The condition `EnableGlobalMerge.getNumOccurrences() > 0` checks how often the 
option was specified on the command line. If I specify 
`-ppc-global-merge=false` then the original `if` returns `false` (because the 
option was specified 1 time, and it's value is `false` but the value of the 
changed condition depends on being on AIX or not.

If the former is really the intended functionality then IMHO it warrants a big 
comment (e.g. "Specifying the command line option overrides AIX default"), just 
to clarify it.

https://github.com/llvm/llvm-project/pull/101226
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] ff99f3a - [SystemZ/z/OS] Add alias for XPLINK return

2022-02-12 Thread Kai Nacke via llvm-branch-commits

Author: Kai Nacke
Date: 2022-02-11T11:52:25-05:00
New Revision: ff99f3a5c0b36d49f4be1b990cc7509e897d48c7

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

LOG: [SystemZ/z/OS] Add alias for XPLINK return

The XPLINK return `b 2(7)` has size 4 bytes, while the Linux return
`br 7` only has size 2 bytes. Thus a new alias is required to have correct
instruction byte count. It also fixes the conditional return code.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D119437

Added: 


Modified: 
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
llvm/lib/Target/SystemZ/SystemZInstrInfo.td
llvm/lib/Target/SystemZ/SystemZScheduleZ13.td
llvm/lib/Target/SystemZ/SystemZScheduleZ14.td
llvm/lib/Target/SystemZ/SystemZScheduleZ15.td
llvm/lib/Target/SystemZ/SystemZScheduleZ196.td
llvm/lib/Target/SystemZ/SystemZScheduleZEC12.td

Removed: 




diff  --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp 
b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index e01adcce04ab1..84b337685c148 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -126,15 +126,18 @@ static MCInst lowerSubvectorStore(const MachineInstr *MI, 
unsigned Opcode) {
 
 void SystemZAsmPrinter::emitInstruction(const MachineInstr *MI) {
   SystemZMCInstLower Lower(MF->getContext(), *this);
-  const SystemZSubtarget *Subtarget = &MF->getSubtarget();
   MCInst LoweredMI;
   switch (MI->getOpcode()) {
   case SystemZ::Return:
-if (Subtarget->isTargetXPLINK64())
-  LoweredMI =
-  MCInstBuilder(SystemZ::B).addReg(SystemZ::R7D).addImm(2).addReg(0);
-else
-  LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D);
+LoweredMI = MCInstBuilder(SystemZ::BR)
+  .addReg(SystemZ::R14D);
+break;
+
+  case SystemZ::Return_XPLINK:
+LoweredMI = MCInstBuilder(SystemZ::B)
+  .addReg(SystemZ::R7D)
+  .addImm(2)
+  .addReg(0);
 break;
 
   case SystemZ::CondReturn:
@@ -144,6 +147,15 @@ void SystemZAsmPrinter::emitInstruction(const MachineInstr 
*MI) {
   .addReg(SystemZ::R14D);
 break;
 
+  case SystemZ::CondReturn_XPLINK:
+LoweredMI = MCInstBuilder(SystemZ::BC)
+  .addImm(MI->getOperand(0).getImm())
+  .addImm(MI->getOperand(1).getImm())
+  .addReg(SystemZ::R7D)
+  .addImm(2)
+  .addReg(0);
+break;
+
   case SystemZ::CRBReturn:
 LoweredMI = MCInstBuilder(SystemZ::CRB)
   .addReg(MI->getOperand(0).getReg())

diff  --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp 
b/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
index 4b6aa60f5d55a..aca1c27f97954 100644
--- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
@@ -674,6 +674,7 @@ bool SystemZInstrInfo::FoldImmediate(MachineInstr &UseMI, 
MachineInstr &DefMI,
 bool SystemZInstrInfo::isPredicable(const MachineInstr &MI) const {
   unsigned Opcode = MI.getOpcode();
   if (Opcode == SystemZ::Return ||
+  Opcode == SystemZ::Return_XPLINK ||
   Opcode == SystemZ::Trap ||
   Opcode == SystemZ::CallJG ||
   Opcode == SystemZ::CallBR)
@@ -731,11 +732,13 @@ bool SystemZInstrInfo::PredicateInstruction(
   .addReg(SystemZ::CC, RegState::Implicit);
 return true;
   }
-  if (Opcode == SystemZ::Return) {
-MI.setDesc(get(SystemZ::CondReturn));
+  if (Opcode == SystemZ::Return || Opcode == SystemZ::Return_XPLINK) {
+MI.setDesc(get(Opcode == SystemZ::Return ? SystemZ::CondReturn
+ : SystemZ::CondReturn_XPLINK));
 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
-  .addImm(CCValid).addImm(CCMask)
-  .addReg(SystemZ::CC, RegState::Implicit);
+.addImm(CCValid)
+.addImm(CCMask)
+.addReg(SystemZ::CC, RegState::Implicit);
 return true;
   }
   if (Opcode == SystemZ::CallJG) {

diff  --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.td 
b/llvm/lib/Target/SystemZ/SystemZInstrInfo.td
index 84f1e0fb428c3..c47731b26e95d 100644
--- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.td
+++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.td
@@ -336,13 +336,25 @@ let isCall = 1, isTerminator = 1, isReturn = 1 in {
   def CLGIBCall : Alias<6, (outs), (ins GR64:$R1, imm64zx8:$I2, cond4:$M3, 
ADDR64:$R4), []>;
 }
 
-// A return instruction (br %r14) for ELF and (b 2 %r7) for XPLink.
-let isReturn = 1, isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in
-  def Return : Alias<2, (outs), (ins), [(z_retflag)]>;
+let Predicates = [IsTargetXPLINK64] in {
+  // A return instruction (b 2(%r7)).
+  let isReturn = 1, isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in
+def Return_XPLINK : Alias<4, (outs), (ins), [(z_retflag)]>;
+
+  // A conditiona

[llvm-branch-commits] [llvm-branch] r260584 - Add LDC compiler to list of external OS projects using LLVM 3.8

2016-02-11 Thread Kai Nacke via llvm-branch-commits
Author: redstar
Date: Thu Feb 11 14:42:16 2016
New Revision: 260584

URL: http://llvm.org/viewvc/llvm-project?rev=260584&view=rev
Log:
Add LDC compiler to list of external OS projects using LLVM 3.8

Modified:
llvm/branches/release_38/docs/ReleaseNotes.rst

Modified: llvm/branches/release_38/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_38/docs/ReleaseNotes.rst?rev=260584&r1=260583&r2=260584&view=diff
==
--- llvm/branches/release_38/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_38/docs/ReleaseNotes.rst Thu Feb 11 14:42:16 2016
@@ -210,7 +210,19 @@ An exciting aspect of LLVM is that it is
 a lot of other language and tools projects. This section lists some of the
 projects that have already been updated to work with LLVM 3.8.
 
-* A project
+LDC - the LLVM-based D compiler
+---
+
+`D `_ is a language with C-like syntax and static typing. It
+pragmatically combines efficiency, control, and modeling power, with safety and
+programmer productivity. D supports powerful concepts like Compile-Time 
Function
+Execution (CTFE) and Template Meta-Programming, provides an innovative approach
+to concurrency and offers many classical paradigms.
+
+`LDC `_ uses the frontend from the reference 
compiler
+combined with LLVM as backend to produce efficient native code. LDC targets
+x86/x86_64 systems like Linux, OS X and Windows and also PowerPC (32/64 bit)
+and ARM. Ports to other architectures like AArch64 and MIPS64 are underway.
 
 
 Additional Information


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm-branch] r278045 - Add LDC compiler to list of external OS projects using LLVM 3.9

2016-08-08 Thread Kai Nacke via llvm-branch-commits
Author: redstar
Date: Mon Aug  8 15:17:36 2016
New Revision: 278045

URL: http://llvm.org/viewvc/llvm-project?rev=278045&view=rev
Log:
Add LDC compiler to list of external OS projects using LLVM 3.9

Modified:
llvm/branches/release_39/docs/ReleaseNotes.rst

Modified: llvm/branches/release_39/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/docs/ReleaseNotes.rst?rev=278045&r1=278044&r2=278045&view=diff
==
--- llvm/branches/release_39/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_39/docs/ReleaseNotes.rst Mon Aug  8 15:17:36 2016
@@ -283,6 +283,21 @@ projects that have already been updated
 
 * A project
 
+LDC - the LLVM-based D compiler
+---
+
+`D `_ is a language with C-like syntax and static typing. It
+pragmatically combines efficiency, control, and modeling power, with safety and
+programmer productivity. D supports powerful concepts like Compile-Time 
Function
+Execution (CTFE) and Template Meta-Programming, provides an innovative approach
+to concurrency and offers many classical paradigms.
+
+`LDC `_ uses the frontend from the reference 
compiler
+combined with LLVM as backend to produce efficient native code. LDC targets
+x86/x86_64 systems like Linux, OS X, FreeBSD and Windows and also Linux on ARM
+and PowerPC (32/64 bit). Ports to other architectures like AArch64 and MIPS64
+are underway.
+
 
 Additional Information
 ==


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm-branch] r295367 - Add external project LDC to release notes.

2017-02-16 Thread Kai Nacke via llvm-branch-commits
Author: redstar
Date: Thu Feb 16 13:35:37 2017
New Revision: 295367

URL: http://llvm.org/viewvc/llvm-project?rev=295367&view=rev
Log:
Add external project LDC to release notes.

LDC, the LLVM-based D compiler, is already ready for LLVM 4.0.

Modified:
llvm/branches/release_40/docs/ReleaseNotes.rst

Modified: llvm/branches/release_40/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/docs/ReleaseNotes.rst?rev=295367&r1=295366&r2=295367&view=diff
==
--- llvm/branches/release_40/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_40/docs/ReleaseNotes.rst Thu Feb 16 13:35:37 2017
@@ -292,6 +292,21 @@ External Open Source Projects Using LLVM
 
 * A project...
 
+LDC - the LLVM-based D compiler
+---
+
+`D `_ is a language with C-like syntax and static typing. It
+pragmatically combines efficiency, control, and modeling power, with safety and
+programmer productivity. D supports powerful concepts like Compile-Time 
Function
+Execution (CTFE) and Template Meta-Programming, provides an innovative approach
+to concurrency and offers many classical paradigms.
+
+`LDC `_ uses the frontend from the reference 
compiler
+combined with LLVM as backend to produce efficient native code. LDC targets
+x86/x86_64 systems like Linux, OS X, FreeBSD and Windows and also Linux on ARM
+and PowerPC (32/64 bit). Ports to other architectures like AArch64 and MIPS64
+are underway.
+
 
 Additional Information
 ==


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm-branch] r311064 - Add external project LDC to release notes.

2017-08-16 Thread Kai Nacke via llvm-branch-commits
Author: redstar
Date: Wed Aug 16 22:02:41 2017
New Revision: 311064

URL: http://llvm.org/viewvc/llvm-project?rev=311064&view=rev
Log:
Add external project LDC to release notes.

LDC, the LLVM-based D compiler, is already ready for LLVM 5.0.

Modified:
llvm/branches/release_50/docs/ReleaseNotes.rst

Modified: llvm/branches/release_50/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_50/docs/ReleaseNotes.rst?rev=311064&r1=311063&r2=311064&view=diff
==
--- llvm/branches/release_50/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_50/docs/ReleaseNotes.rst Wed Aug 16 22:02:41 2017
@@ -181,6 +181,22 @@ intended to eventually take the place of
 optimized native code and to cross-compile for any target out of the box. Zig
 is in alpha; with a beta release expected in September.
 
+LDC - the LLVM-based D compiler
+---
+
+`D `_ is a language with C-like syntax and static typing. It
+pragmatically combines efficiency, control, and modeling power, with safety and
+programmer productivity. D supports powerful concepts like Compile-Time 
Function
+Execution (CTFE) and Template Meta-Programming, provides an innovative approach
+to concurrency and offers many classical paradigms.
+
+`LDC `_ uses the frontend from the reference 
compiler
+combined with LLVM as backend to produce efficient native code. LDC targets
+x86/x86_64 systems like Linux, OS X, FreeBSD and Windows and also Linux on ARM
+and PowerPC (32/64 bit). Ports to other architectures like AArch64 and MIPS64
+are underway.
+
+
 Additional Information
 ==
 


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm-branch] r323186 - Add external project LDC to release notes.

2018-01-23 Thread Kai Nacke via llvm-branch-commits
Author: redstar
Date: Tue Jan 23 03:03:55 2018
New Revision: 323186

URL: http://llvm.org/viewvc/llvm-project?rev=323186&view=rev
Log:
Add external project LDC to release notes.

LDC, the LLVM-based D compiler, is already ready for LLVM 6.0.0.

Modified:
llvm/branches/release_60/docs/ReleaseNotes.rst

Modified: llvm/branches/release_60/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/docs/ReleaseNotes.rst?rev=323186&r1=323185&r2=323186&view=diff
==
--- llvm/branches/release_60/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_60/docs/ReleaseNotes.rst Tue Jan 23 03:03:55 2018
@@ -148,6 +148,20 @@ import of .h symbols - even inline funct
 with lazily building compiler-rt to provide out-of-the-box cross-compiling for
 all supported targets.
 
+LDC - the LLVM-based D compiler
+---
+
+`D `_ is a language with C-like syntax and static typing. It
+pragmatically combines efficiency, control, and modeling power, with safety and
+programmer productivity. D supports powerful concepts like Compile-Time 
Function
+Execution (CTFE) and Template Meta-Programming, provides an innovative approach
+to concurrency and offers many classical paradigms.
+
+`LDC `_ uses the frontend from the reference 
compiler
+combined with LLVM as backend to produce efficient native code. LDC targets
+x86/x86_64 systems like Linux, OS X, FreeBSD and Windows and also Linux on ARM
+and PowerPC (32/64 bit). Ports to other architectures like AArch64 and MIPS64
+are underway.
 
 Additional Information
 ==


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 9399681 - [Doc] Fix example in codegen doc.

2021-01-18 Thread Kai Nacke via llvm-branch-commits

Author: Kai Nacke
Date: 2021-01-18T08:24:10-05:00
New Revision: 9399681a57cef143dc4d087706947a03af819ef5

URL: 
https://github.com/llvm/llvm-project/commit/9399681a57cef143dc4d087706947a03af819ef5
DIFF: 
https://github.com/llvm/llvm-project/commit/9399681a57cef143dc4d087706947a03af819ef5.diff

LOG: [Doc] Fix example in codegen doc.

The attributes in the example are placed wrong:
They belong after the type, not after the parameter name.

Reviewed by: abhina.sreeskantharajan

Differential Revision: https://reviews.llvm.org/D94683

Added: 


Modified: 
llvm/docs/CodeGenerator.rst

Removed: 




diff  --git a/llvm/docs/CodeGenerator.rst b/llvm/docs/CodeGenerator.rst
index 875a96ca4e2a..7644242d2d61 100644
--- a/llvm/docs/CodeGenerator.rst
+++ b/llvm/docs/CodeGenerator.rst
@@ -2112,7 +2112,7 @@ Call as ``llc -tailcallopt test.ll``.
 
   define fastcc i32 @tailcaller(i32 %in1, i32 %in2) {
 %l1 = add i32 %in1, %in2
-%tmp = tail call fastcc i32 @tailcallee(i32 %in1 inreg, i32 %in2 inreg, 
i32 %in1, i32 %l1)
+%tmp = tail call fastcc i32 @tailcallee(i32 inreg %in1, i32 inreg %in2, 
i32 %in1, i32 %l1)
 ret i32 %tmp
   }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] e2e86f4 - [Doc][SystemZ] Add Linux/SystemZ to Getting Started guide.

2020-12-16 Thread Kai Nacke via llvm-branch-commits

Author: Kai Nacke
Date: 2020-12-16T10:46:05-05:00
New Revision: e2e86f4e77ec2fd79743f4d0e94689e9668600ad

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

LOG: [Doc][SystemZ] Add Linux/SystemZ to Getting Started guide.

The Linux/SystemZ platform is missing in the Getting Started guide
as platform on which LLVM is known to work.

Reviewed by: uweigand

Differential Revision: https://reviews.llvm.org/D93388

Added: 


Modified: 
llvm/docs/GettingStarted.rst

Removed: 




diff  --git a/llvm/docs/GettingStarted.rst b/llvm/docs/GettingStarted.rst
index 70e12b0f877a..05d2994fed2b 100644
--- a/llvm/docs/GettingStarted.rst
+++ b/llvm/docs/GettingStarted.rst
@@ -121,6 +121,7 @@ Linux  amd64 GCC, Clang
 Linux  ARM   GCC, Clang
 Linux  Mips  GCC, Clang
 Linux  PowerPC   GCC, Clang
+Linux  SystemZ   GCC, Clang
 SolarisV9 (Ultrasparc)   GCC
 FreeBSDx86\ :sup:`1` GCC, Clang
 FreeBSDamd64 GCC, Clang



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] f03c21d - [SystemZ] Adding extra extended mnemonics for SystemZ target

2020-12-02 Thread Kai Nacke via llvm-branch-commits

Author: Anirudh Prasad
Date: 2020-12-02T08:25:31-05:00
New Revision: f03c21df7b845e2ffcef42f242764f36603fdbb4

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

LOG: [SystemZ] Adding extra extended mnemonics for SystemZ target

This patch consists of the addition of some common additional
extended mnemonics to the SystemZ target.

- These are jnop, jct, jctg, jas, jasl, jxh, jxhg, jxle,
  jxleg, bru, brul, br*, br*l.
- These mnemonics and the instructions they map to are
  defined here, Chapter 4 - Branching with extended
  mnemonic codes.
- Except for jnop (which is a variant of brc 0, label), every
  other mnemonic is marked as a MnemonicAlias since there is
  already a "defined" instruction with the same encoding
  and/or condition mask values.
- brc 0, label doesn't have a defined extended mnemonic, thus
  jnop is defined using as an InstAlias. Furthermore, the
  applyMnemonicAliases function is called in the overridden
  parseInstruction function in SystemZAsmParser.cpp to ensure
  any mnemonic aliases are applied before any further
  processing on the instruction is done.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D92185

Added: 


Modified: 
llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
llvm/lib/Target/SystemZ/SystemZInstrFormats.td
llvm/lib/Target/SystemZ/SystemZInstrInfo.td
llvm/test/MC/SystemZ/insn-bad.s
llvm/test/MC/SystemZ/insn-good.s

Removed: 




diff  --git a/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp 
b/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
index 8da460381783..2b815a366ccd 100644
--- a/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
+++ b/llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
@@ -1322,6 +1322,11 @@ OperandMatchResultTy 
SystemZAsmParser::tryParseRegister(unsigned &RegNo,
 bool SystemZAsmParser::ParseInstruction(ParseInstructionInfo &Info,
 StringRef Name, SMLoc NameLoc,
 OperandVector &Operands) {
+
+  // Apply mnemonic aliases first, before doing anything else, in
+  // case the target uses it.
+  applyMnemonicAliases(Name, getAvailableFeatures(), 0 /*VariantID*/);
+
   Operands.push_back(SystemZOperand::createToken(Name, NameLoc));
 
   // Read the remaining operands.

diff  --git a/llvm/lib/Target/SystemZ/SystemZInstrFormats.td 
b/llvm/lib/Target/SystemZ/SystemZInstrFormats.td
index 4aac2eec655f..95e94c4c8e1c 100644
--- a/llvm/lib/Target/SystemZ/SystemZInstrFormats.td
+++ b/llvm/lib/Target/SystemZ/SystemZInstrFormats.td
@@ -1911,6 +1911,11 @@ class ICV
 !cast("IntCondVariant"#name).suffix,
 !cast("IntCondVariant"#name).alternate>;
 
+// Defines a class that makes it easier to define
+// a MnemonicAlias when CondVariant's are involved.
+class MnemonicCondBranchAlias
+  : MnemonicAlias;
+
 
//===--===//
 // Instruction definitions with semantics
 
//===--===//

diff  --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.td 
b/llvm/lib/Target/SystemZ/SystemZInstrInfo.td
index d11404ed7c1b..c37e30556ddb 100644
--- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.td
+++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.td
@@ -110,6 +110,12 @@ let isAsmParserOnly = 1, hasNoSchedulingInfo = 1, M1 = 0, 
XBD2 = 0 in
 def NOPR : InstAlias<"nopr\t$R", (BCRAsm 0, GR64:$R), 0>;
 def NOPR_bare : InstAlias<"nopr", (BCRAsm 0, R0D), 0>;
 
+// An alias of BRC 0, label
+def JNOP : InstAlias<"jnop\t$RI2", (BRCAsm 0, brtarget16:$RI2), 0>;
+
+// An alias of BRCL 0, label
+def JGNOP : InstAlias<"jgnop\t$RI2", (BRCLAsm 0, brtarget32:$RI2), 0>;
+
 // Fused compare-and-branch instructions.
 //
 // These instructions do not use or clobber the condition codes.
@@ -2338,3 +2344,25 @@ defm : BlockLoadStore;
 defm : BlockLoadStore;
+
+//===--===//
+// Mnemonic Aliases
+//===--===//
+
+def JCT   : MnemonicAlias<"jct", "brct">;
+def JCTG  : MnemonicAlias<"jctg", "brctg">;
+def JAS   : MnemonicAlias<"jas", "bras">;
+def JASL  : MnemonicAlias<"jasl", "brasl">;
+def JXH   : MnemonicAlias<"jxh", "brxh">;
+def JXLE  : MnemonicAlias<"jxle", "brxle">;
+def JXHG  : MnemonicAlias<"jxhg", "brxhg">;
+def JXLEG : MnemonicAlias<"jxleg", "brxlg">;
+
+def BRU   : MnemonicAlias<"bru", "j">;
+def BRUL  : MnemonicAlias<"brul", "jg">;
+
+foreach V = [ "E", "NE", "H", "NH", "L", "NL", "HE", "NHE", "LE", "NLE",
+  "Z", "NZ", "P", "NP", "M", "NM", "LH", "NLH", "O", "NO" ] in {
+  def BRUAsm#V : MnemonicCondBranchAlias , "br#", "j#">;
+  

[llvm-branch-commits] [llvm-branch] r353466 - Add external project LDC to release notes.

2019-02-07 Thread Kai Nacke via llvm-branch-commits
Author: redstar
Date: Thu Feb  7 13:09:53 2019
New Revision: 353466

URL: http://llvm.org/viewvc/llvm-project?rev=353466&view=rev
Log:
Add external project LDC to release notes.

LDC, the LLVM-based D compiler, is already ready for LLVM 8.0.0.

Modified:
llvm/branches/release_80/docs/ReleaseNotes.rst

Modified: llvm/branches/release_80/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_80/docs/ReleaseNotes.rst?rev=353466&r1=353465&r2=353466&view=diff
==
--- llvm/branches/release_80/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_80/docs/ReleaseNotes.rst Thu Feb  7 13:09:53 2019
@@ -156,6 +156,21 @@ Changes to the DAG infrastructure
 External Open Source Projects Using LLVM 8
 ==
 
+LDC - the LLVM-based D compiler
+---
+
+`D `_ is a language with C-like syntax and static typing. It
+pragmatically combines efficiency, control, and modeling power, with safety and
+programmer productivity. D supports powerful concepts like Compile-Time 
Function
+Execution (CTFE) and Template Meta-Programming, provides an innovative approach
+to concurrency and offers many classical paradigms.
+
+`LDC `_ uses the frontend from the reference 
compiler
+combined with LLVM as backend to produce efficient native code. LDC targets
+x86/x86_64 systems like Linux, OS X, FreeBSD and Windows and also Linux on ARM
+and PowerPC (32/64 bit). Ports to other architectures like AArch64 and MIPS64
+are underway.
+
 Zig Programming Language
 
 


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm-branch] r372167 - Add external project LDC to release notes.

2019-09-17 Thread Kai Nacke via llvm-branch-commits
Author: redstar
Date: Tue Sep 17 12:16:16 2019
New Revision: 372167

URL: http://llvm.org/viewvc/llvm-project?rev=372167&view=rev
Log:
Add external project LDC to release notes.

LDC, the LLVM-based D compiler, is already ready for LLVM 9.0.0.

Modified:
llvm/branches/release_90/docs/ReleaseNotes.rst

Modified: llvm/branches/release_90/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/llvm/branches/release_90/docs/ReleaseNotes.rst?rev=372167&r1=372166&r2=372167&view=diff
==
--- llvm/branches/release_90/docs/ReleaseNotes.rst (original)
+++ llvm/branches/release_90/docs/ReleaseNotes.rst Tue Sep 17 12:16:16 2019
@@ -349,6 +349,21 @@ LLD combined with lazily building compil
 cross-compiling for all supported targets.
 
 
+LDC - the LLVM-based D compiler
+---
+
+`D `_ is a language with C-like syntax and static typing. It
+pragmatically combines efficiency, control, and modeling power, with safety and
+programmer productivity. D supports powerful concepts like Compile-Time 
Function
+Execution (CTFE) and Template Meta-Programming, provides an innovative approach
+to concurrency and offers many classical paradigms.
+
+`LDC `_ uses the frontend from the reference 
compiler
+combined with LLVM as backend to produce efficient native code. LDC targets
+x86/x86_64 systems like Linux, OS X, FreeBSD and Windows and also Linux on ARM
+and PowerPC (32/64 bit). Ports to other architectures are underway.
+
+
 Additional Information
 ==
 


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-04 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

I refactored the code in the suggested way. Some notes:

- I section to emit the code/data is either the ED or the PR. The other 
sections are linked via the `Parent` pointer. `MCGOFFStreamer::changeSection()` 
makes sure that all sections are registered in the correct order.
- I use the ordinal number +1 of the section as the section number, but still 
need a counter for the symbols.
- I still need to check that the LD symbols are emitted in the correct order.
- The textual output is currently not correct.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-05 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,73 @@
+; RUN: llc <%s --mtriple s390x-ibm-zos --filetype=obj -o - | \
+; RUN:   od -Ax -tx1 -v | FileCheck --ignore-case %s
+; REQUIRES: systemz-registered-target

redstar wrote:

Removed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-05 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,148 @@
+//===- MCGOFFSymbolMapper.h - Maps MC section/symbol to GOFF symbols 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Maps a section or a symbol to the GOFF symbols it is composed of, and their
+// attributes.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFSYMBOLMAPPER_H
+#define LLVM_MC_MCGOFFSYMBOLMAPPER_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/Support/Alignment.h"
+#include 
+#include 
+
+namespace llvm {
+class MCAssembler;
+class MCContext;
+class MCSectionGOFF;
+
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE64.

redstar wrote:

It's AMODE not ILP :-)

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-05 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

I implemented the suggestion from @uweigand. The GOFF attributes are set 
directly at the `MCSectionGOFF`, and the `GOFFSymbolMapper` is gone. I still 
need to update a couple of tests, since now the section names have changed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-05 Thread Kai Nacke via llvm-branch-commits


@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }

redstar wrote:

Changed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Kai Nacke via llvm-branch-commits


@@ -16,34 +16,94 @@
 #define LLVM_MC_MCSECTIONGOFF_H
 
 #include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/MC/MCGOFFAttributes.h"
 #include "llvm/MC/MCSection.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
 
 class MCExpr;
 
 class MCSectionGOFF final : public MCSection {
-private:
-  MCSection *Parent;
-  uint32_t Subsection;
+  // Parent of this section. Implies that the parent is emitted first.
+  MCSectionGOFF *Parent;
+
+  // The attributes of the GOFF symbols.
+  GOFF::SDAttr SDAttributes;
+  GOFF::EDAttr EDAttributes;
+  GOFF::PRAttr PRAttributes;
+
+  // The type of this section.
+  GOFF::ESDSymbolType SymbolType;
+
+  // Indicates that the PR symbol needs to set the length of the section to a
+  // non-zero value. This is only a problem with the ADA PR - the binder will
+  // generate an error in this case.
+  unsigned RequiresNonZeroLength : 1;
 
   friend class MCContext;
-  MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, uint32_t Sub)
+  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::ESDSymbolType SymbolType,
+GOFF::SDAttr SDAttributes, GOFF::EDAttr EDAttributes,
+GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent = nullptr)
   : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
-Parent(P), Subsection(Sub) {}
+Parent(Parent), SDAttributes(SDAttributes), EDAttributes(EDAttributes),
+PRAttributes(PRAttributes), SymbolType(SymbolType) {}
 
 public:
   void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
 raw_ostream &OS,
-uint32_t /*Subsection*/) const override {
-OS << "\t.section\t\"" << getName() << "\"\n";
+uint32_t Subsection) const override {
+switch (SymbolType) {
+case GOFF::ESD_ST_SectionDefinition:
+  OS << Name << " CSECT\n";
+  break;
+case GOFF::ESD_ST_ElementDefinition:
+  getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+  OS << Name << " CATTR\n";
+  break;
+case GOFF::ESD_ST_PartReference:
+  getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+  OS << Name << " XATTR\n";

redstar wrote:

Yes, true, I need to update my HLASM skills.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +298,63 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+  if (Section.isSD()) {
+GOFFSymbol SD(Section.getName(), Section.getId(),
+  Section.getSDAttributes());
+writeSymbol(SD);
+  }
+
+  if (Section.isED()) {
+GOFFSymbol ED(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getEDAttributes());
+if (Section.requiresLength())
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+writeSymbol(ED);
+  }
+
+  if (Section.isPR()) {
+GOFFSymbol PR(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getPRAttributes());
+PR.SectionLength = Asm.getSectionAddressSize(Section);
+if (Section.requiresNonZeroLength()) {

redstar wrote:

> Or, in the alternative, should we simply not set the ADA link if the target 
> section is empty? If an ADA section, it cannot actually be used for anything, 
> so do we even need to register it as ADA for a text section?

That is a simple solution, too. I am not sure if this works with the HLASM 
output. 

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +298,63 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+  if (Section.isSD()) {
+GOFFSymbol SD(Section.getName(), Section.getId(),
+  Section.getSDAttributes());
+writeSymbol(SD);
+  }
+
+  if (Section.isED()) {
+GOFFSymbol ED(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getEDAttributes());
+if (Section.requiresLength())
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+writeSymbol(ED);
+  }
+
+  if (Section.isPR()) {
+GOFFSymbol PR(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getPRAttributes());
+PR.SectionLength = Asm.getSectionAddressSize(Section);
+if (Section.requiresNonZeroLength()) {

redstar wrote:

PR sections of size zero are allowed. However, if a text section is associated 
with an data section (the ADAEsdId field of the LD symbol of the text section 
is set to the PR symbol of the ADA) then the binder produces an error. This is 
a work-around for that situation.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-10 Thread Kai Nacke via llvm-branch-commits


@@ -2759,6 +2762,29 @@ MCSection 
*TargetLoweringObjectFileXCOFF::getSectionForLSDA(
 
//===--===//
 TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF() = default;
 
+void TargetLoweringObjectFileGOFF::getModuleMetadata(Module &M) {
+  // Construct the default names for the root SD and the ADA PR symbol.
+  StringRef FileName = sys::path::stem(M.getSourceFileName());
+  if (FileName.size() > 1 && FileName.starts_with('<') &&
+  FileName.ends_with('>'))
+FileName = FileName.substr(1, FileName.size() - 2);
+  DefaultRootSDName = Twine(FileName).concat("#C").str();

redstar wrote:

Using a name and setting the binding scope to "section scope" is similar to 
using " " as name and leaving the binding scope unspecified.
The XLC and Open XL compilers provide a command line option to change this name 
(XLC: `-qcsect`, `-qnocsect`; Open XL: `-mcsect`, `-mnocsect`). The Open XL 
compiler defaults to the variant coded here but that can be changed to having a 
name with binding scope unspecified (`-mcsect=a`) or set to space (`-mnocsect`).
Using `-mcsect=a` results in exactly the problem you describe.
The compiler option will be added later to clang, along with the required code 
here.

The front end (aka clang) provides this value in the `source_filename` 
property. All strings in LLVM/clang are in UTF-8 so there is no other choice. 
The same problem arises for symbols derived from function names etc.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-08 Thread Kai Nacke via llvm-branch-commits


@@ -16,34 +16,95 @@
 #define LLVM_MC_MCSECTIONGOFF_H
 
 #include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/MC/MCGOFFAttributes.h"
 #include "llvm/MC/MCSection.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
 
 class MCExpr;
 
 class MCSectionGOFF final : public MCSection {
-private:
-  MCSection *Parent;
-  uint32_t Subsection;
+  // Parent of this section. Implies that the parent is emitted first.
+  MCSectionGOFF *Parent;
+
+  // The attributes of the GOFF symbols.
+  GOFF::SDAttr SDAttributes;
+  GOFF::EDAttr EDAttributes;
+  GOFF::PRAttr PRAttributes;

redstar wrote:

Changed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-08 Thread Kai Nacke via llvm-branch-commits


@@ -230,10 +230,11 @@ class MCObjectFileInfo {
   MCSection *GLJMPSection = nullptr;
 
   // GOFF specific sections.
-  MCSection *PPA1Section = nullptr;
-  MCSection *PPA2Section = nullptr;
-  MCSection *PPA2ListSection = nullptr;
-  MCSection *ADASection = nullptr;
+  MCSection *RootSDSection = nullptr;
+  MCSection *PPA2ListEDSection = nullptr;
+  MCSection *PPA2ListPRSection = nullptr;
+  MCSection *ADAEDSection = nullptr;
+  MCSection *ADAPRSection = nullptr;

redstar wrote:

Removed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-08 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

> > I use the ordinal number +1 of the section as the section number, but still 
> > need a counter for the symbols.
> 
> Can't we just set the ordinal to the correct value to begin with? ELF sets 
> the ordinals while writing out the sections; I think we might as well do the 
> same. (The point being that if we have already ensured we write sections in 
> the correct order, then we will only ever need to refer to ordinals of 
> sections that have already been written.) Then we'd be back to a single 
> counter used by the writer for all GOFF symbol records, those that come from 
> sections as well as those that come from symbols.

At first I was a bit confused about this, because the `MCAssembler` sets the 
ordinal. Well, it seems that the ELF writer overwrites those values. :-) Sure, 
I can do the same.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-08 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +298,63 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+  if (Section.isSD()) {
+GOFFSymbol SD(Section.getName(), Section.getId(),
+  Section.getSDAttributes());
+writeSymbol(SD);
+  }
+
+  if (Section.isED()) {
+GOFFSymbol ED(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getEDAttributes());
+if (Section.requiresLength())
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+writeSymbol(ED);
+  }
+
+  if (Section.isPR()) {
+GOFFSymbol PR(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getPRAttributes());
+PR.SectionLength = Asm.getSectionAddressSize(Section);
+if (Section.requiresNonZeroLength()) {

redstar wrote:

For this specific case I do not know what happens under the hood.
For an externally callable function, a function descriptor is generated in the 
ADA by the _binder_. From the LLVM point of view, the ADA would still be empty. 
The simple example is:
```
void empty() {}
```
Here, the ADA is empty. Still, the binder generates the function descriptor. A 
caller of this function can use a function descriptor in its own compilation 
unit:
```
DC  R(empty)
DC  V(empty)
```
I would expect that I get a binder error on `R(empty)` if no associated data 
area was given for the code section. But I have not tried.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-08 Thread Kai Nacke via llvm-branch-commits


@@ -230,10 +230,11 @@ class MCObjectFileInfo {
   MCSection *GLJMPSection = nullptr;
 
   // GOFF specific sections.
-  MCSection *PPA1Section = nullptr;
-  MCSection *PPA2Section = nullptr;
-  MCSection *PPA2ListSection = nullptr;
-  MCSection *ADASection = nullptr;
+  MCSection *RootSDSection = nullptr;

redstar wrote:

Removed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-08 Thread Kai Nacke via llvm-branch-commits


@@ -2759,6 +2760,12 @@ MCSection 
*TargetLoweringObjectFileXCOFF::getSectionForLSDA(
 
//===--===//
 TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF() = default;
 
+void TargetLoweringObjectFileGOFF::getModuleMetadata(Module &M) {
+  // Set the main file name if not set previously by the tool.
+  if (getContext().getMainFileName().empty())
+getContext().setMainFileName(M.getSourceFileName());

redstar wrote:

Not using anymore.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-09 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +298,63 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+  if (Section.isSD()) {
+GOFFSymbol SD(Section.getName(), Section.getId(),
+  Section.getSDAttributes());
+writeSymbol(SD);
+  }
+
+  if (Section.isED()) {
+GOFFSymbol ED(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getEDAttributes());
+if (Section.requiresLength())
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+writeSymbol(ED);
+  }
+
+  if (Section.isPR()) {
+GOFFSymbol PR(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getPRAttributes());
+PR.SectionLength = Asm.getSectionAddressSize(Section);
+if (Section.requiresNonZeroLength()) {

redstar wrote:

I talked to a colleague. Exactly this ^^^ case will not work. The binder gives 
no warning/error but it will cause problems at runtime because the environment 
parameter is zero.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-10 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +298,63 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+  if (Section.isSD()) {
+GOFFSymbol SD(Section.getName(), Section.getId(),
+  Section.getSDAttributes());
+writeSymbol(SD);
+  }
+
+  if (Section.isED()) {
+GOFFSymbol ED(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getEDAttributes());
+if (Section.requiresLength())
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+writeSymbol(ED);
+  }
+
+  if (Section.isPR()) {
+GOFFSymbol PR(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getPRAttributes());
+PR.SectionLength = Asm.getSectionAddressSize(Section);
+if (Section.requiresNonZeroLength()) {

redstar wrote:

> That is a simple solution, too. I am not sure if this works with the HLASM 
> output.

Ok, I contradict myself. Setting the ADA to null gets around the binder error 
but other parts assume that there is always an ADA. E.g. when calling an 
external functions.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-10 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;

redstar wrote:

There may be no LD. For example, the `B_IDRL` section has only SD and ED.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-03-31 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar created 
https://github.com/llvm/llvm-project/pull/133799

The GOFF format uses symbol definitions to represent sections and symbols. 
Introducing a section can require up to 3 symbol definitions. However, most of 
these details are not needed by the AsmPrinter. To mapped from a section (a 
MCSectionGOFF) to the symbol definitions, a new class called MCGOFFSymbolMapper 
is used. The same information can also be used by the assembly output, which 
justifies this centralized approach. Writing the mapped symbols is then 
straight forward.

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Re

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-08 Thread Kai Nacke via llvm-branch-commits


@@ -26,6 +27,29 @@ GOFFObjectWriter &MCGOFFStreamer::getWriter() {
   return static_cast(getAssembler().getWriter());
 }
 
+void MCGOFFStreamer::initSections(bool /*NoExecStack*/,
+  const MCSubtargetInfo &STI) {
+  MCContext &Ctx = getContext();
+  // Emit the text section.
+  switchSection(Ctx.getObjectFileInfo()->getTextSection());
+}

redstar wrote:

Removed, not needed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-11 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;

redstar wrote:

Yes, that's true. I missed that somehow.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-11 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDBindingStrength BindingStrength = GOFF::ESD_BST_Strong;
+  GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for PR symbols.
+struct PRAttr {
+  bool IsRenamable = false;
+  bool IsReadOnly = false; //  Not documented.
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;

redstar wrote:

Removed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-11 Thread Kai Nacke via llvm-branch-commits


@@ -223,13 +197,95 @@ void GOFFOstream::finalizeRecord() {
 }
 
 namespace {
+// A GOFFSymbol holds all the data required for writing an ESD record.
+class GOFFSymbol {
+public:
+  std::string Name;
+  uint32_t EsdId;
+  uint32_t ParentEsdId;
+  uint64_t Offset = 0; // Offset of the symbol into the section. LD only.
+   // Offset is only 32 bit, the larger type is used to
+   // enable error checking.
+  GOFF::ESDSymbolType SymbolType;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_ProgramManagementBinder;
+
+  GOFF::BehavioralAttributes BehavAttrs;
+  GOFF::SymbolFlags SymbolFlags;
+  uint32_t SortKey = 0;
+  uint32_t SectionLength = 0;
+  uint32_t ADAEsdId = 0;
+  uint32_t EASectionEDEsdId = 0;
+  uint32_t EASectionOffset = 0;
+  uint8_t FillByteValue = 0;
+
+  GOFFSymbol() : EsdId(0), ParentEsdId(0) {}
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, const GOFF::SDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(0),
+SymbolType(GOFF::ESD_ST_SectionDefinition) {
+BehavAttrs.setTaskingBehavior(Attr.TaskingBehavior);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const GOFF::EDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_ElementDefinition) {
+this->NameSpace = Attr.NameSpace;
+// TODO Do we need/should set the "mangled" flag?
+SymbolFlags.setFillBytePresence(1);

redstar wrote:

Only a result of using the default value, but I should be more explicit here.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Kai Nacke via llvm-branch-commits


@@ -26,6 +27,29 @@ GOFFObjectWriter &MCGOFFStreamer::getWriter() {
   return static_cast(getAssembler().getWriter());
 }
 
+void MCGOFFStreamer::initSections(bool /*NoExecStack*/,
+  const MCSubtargetInfo &STI) {
+  MCContext &Ctx = getContext();
+  // Emit the text section.
+  switchSection(Ctx.getObjectFileInfo()->getTextSection());
+}
+
+namespace {
+// Make sure that all section are registered in the correct order.
+void registerSectionHierarchy(MCAssembler &Asm, MCSectionGOFF *Section) {
+  if (Section->isRegistered())
+return;
+  if (Section->getParent())
+registerSectionHierarchy(Asm, Section->getParent());
+  registerSectionHierarchy(Asm, Section);

redstar wrote:

Yes, that's a bug. It should call `Asm.registerSection()` instead.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +298,63 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+  if (Section.isSD()) {
+GOFFSymbol SD(Section.getName(), Section.getId(),
+  Section.getSDAttributes());
+writeSymbol(SD);
+  }
+
+  if (Section.isED()) {
+GOFFSymbol ED(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getEDAttributes());
+if (Section.requiresLength())

redstar wrote:

> so it's size should be zero naturally?

Yes, that's true, and it makes the code easier.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-14 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;

redstar wrote:

Ok, I removed this. However, it feels like that there is an inconsistency in 
the documentation / implementations. The following HLASM code
```
stdin#C CSECT
C_WSA64 CATTR ALIGN(4),DEFLOAD,NOTEXECUTABLE,PART(a),RMODE(64)
DC  0X
END
```
results in `RMODE(64)` set at the ED symbol, and `AMODE(64)` set at the PR 
symbol.
Setting the Amode on a PR symbol makes sense to me because it is not possible 
to add a LD symbol to the part - this is causing binder errors. To reference 
the part from a different compilation unit, I have to use `a`, thus the PR has 
also some symbol semantics. 

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-14 Thread Kai Nacke via llvm-branch-commits


@@ -2759,6 +2762,29 @@ MCSection 
*TargetLoweringObjectFileXCOFF::getSectionForLSDA(
 
//===--===//
 TargetLoweringObjectFileGOFF::TargetLoweringObjectFileGOFF() = default;
 
+void TargetLoweringObjectFileGOFF::getModuleMetadata(Module &M) {
+  // Construct the default names for the root SD and the ADA PR symbol.
+  StringRef FileName = sys::path::stem(M.getSourceFileName());
+  if (FileName.size() > 1 && FileName.starts_with('<') &&
+  FileName.ends_with('>'))
+FileName = FileName.substr(1, FileName.size() - 2);
+  DefaultRootSDName = Twine(FileName).concat("#C").str();

redstar wrote:

Yes, my plan is to request an update to the documentation. 

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-14 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,145 @@
+//===- MCSectionGOFF.cpp - GOFF Code Section Representation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/MC/MCSectionGOFF.h"
+#include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+void emitRMode(raw_ostream &OS, GOFF::ESDRmode Rmode, bool UseParenthesis) {
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << "RMODE" << (UseParenthesis ? '(' : ' ');
+switch (Rmode) {
+case GOFF::ESD_RMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_RMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_RMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_RMODE_None:
+  break;
+}
+if (UseParenthesis)
+  OS << ')';
+  }
+}
+
+void emitCATTR(raw_ostream &OS, StringRef Name, StringRef ParentName,
+   bool EmitAmodeAndRmode, GOFF::ESDAmode Amode,
+   GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment,
+   GOFF::ESDLoadingBehavior LoadBehavior,
+   GOFF::ESDExecutable Executable, bool IsReadOnly,
+   StringRef PartName) {
+  if (EmitAmodeAndRmode && Amode != GOFF::ESD_AMODE_None) {
+OS << ParentName << " AMODE ";
+switch (Amode) {
+case GOFF::ESD_AMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_AMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_AMODE_ANY:
+  OS << "ANY";
+  break;
+case GOFF::ESD_AMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_AMODE_MIN:
+  OS << "ANY64";
+  break;
+case GOFF::ESD_AMODE_None:
+  break;
+}
+OS << "\n";
+  }
+  if (EmitAmodeAndRmode && Rmode != GOFF::ESD_RMODE_None) {
+OS << ParentName << ' ';
+emitRMode(OS, Rmode, /*UseParenthesis=*/false);

redstar wrote:

I changed it, only the `CATTR RMODE` is now emitted.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-14 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDBindingStrength BindingStrength = GOFF::ESD_BST_Strong;
+  GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for PR symbols.
+struct PRAttr {
+  bool IsRenamable = false;
+  bool IsReadOnly = false; //  Not documented.
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDAmode Amode;

redstar wrote:

Removed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDBindingStrength BindingStrength = GOFF::ESD_BST_Strong;
+  GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for PR symbols.
+struct PRAttr {
+  bool IsRenamable = false;
+  bool IsReadOnly = false; //  Not documented.
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+  GOFF::ESDDuplicateSymbolSeverity DuplicateSymbolSeverity =
+  GOFF::ESD_DSS_NoWarning;

redstar wrote:

Me too. I need to ask someone with more HLASM knowledge.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDBindingStrength BindingStrength = GOFF::ESD_BST_Strong;
+  GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for PR symbols.
+struct PRAttr {
+  bool IsRenamable = false;
+  bool IsReadOnly = false; //  Not documented.
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+  GOFF::ESDDuplicateSymbolSeverity DuplicateSymbolSeverity =
+  GOFF::ESD_DSS_NoWarning;

redstar wrote:

On the other hand, this is the default value and we do not set it to a 
different value, thus we do not need to specify it.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-04-24 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar created 
https://github.com/llvm/llvm-project/pull/137235

Sections which are not allowed to carry data are marked as virtual. Only 
complication when writing out the text is that it must be written in chunks of 
32k-1 bytes, which is done by having a wrapper stream writing those records.
Data of BSS sections is not written, since the contents is known to be zero. 
Instead, the fill byte value is used.

>From 0e5c36a691fcbaa6f63c46f4cf86fa16857e137c Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Wed, 9 Apr 2025 15:08:52 -0400
Subject: [PATCH] [GOFF] Add writing of text records

Sections which are not allowed to carry data are marked as virtual.
Only complication when writing out the text is that it must be
written in chunks of 32k-1 bytes, which is done by having a wrapper
stream writing those records.
Data of BSS sections is not written, since the contents is known to
be zero. Instead, the fill byte value is used.
---
 llvm/include/llvm/MC/MCContext.h  |  6 +-
 llvm/include/llvm/MC/MCSectionGOFF.h  | 47 +++
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  |  5 +-
 llvm/lib/MC/GOFFObjectWriter.cpp  | 78 +++
 llvm/lib/MC/MCContext.cpp | 19 +++--
 llvm/lib/MC/MCObjectFileInfo.cpp  |  8 +-
 llvm/test/CodeGen/SystemZ/zos-section-1.ll| 27 +--
 llvm/test/CodeGen/SystemZ/zos-section-2.ll| 30 +--
 8 files changed, 180 insertions(+), 40 deletions(-)

diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 8eb904966f4de..2cdba64be116d 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -366,7 +366,8 @@ class MCContext {
 
   template 
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
-TAttr SDAttributes, MCSection *Parent);
+TAttr SDAttributes, MCSection *Parent,
+bool IsVirtual);
 
   /// Map of currently defined macros.
   StringMap MacroMap;
@@ -607,7 +608,8 @@ class MCContext {
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
 GOFF::SDAttr SDAttributes);
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
-GOFF::EDAttr EDAttributes, MCSection *Parent);
+GOFF::EDAttr EDAttributes, MCSection *Parent,
+bool IsVirtual);
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
 GOFF::PRAttr PRAttributes, MCSection *Parent);
 
diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h 
b/llvm/include/llvm/MC/MCSectionGOFF.h
index b8b8cf112a34d..b2ca74c3ba78a 100644
--- a/llvm/include/llvm/MC/MCSectionGOFF.h
+++ b/llvm/include/llvm/MC/MCSectionGOFF.h
@@ -39,6 +39,9 @@ class MCSectionGOFF final : public MCSection {
   // The type of this section.
   GOFF::ESDSymbolType SymbolType;
 
+  // This section is a BSS section.
+  unsigned IsBSS : 1;
+
   // Indicates that the PR symbol needs to set the length of the section to a
   // non-zero value. This is only a problem with the ADA PR - the binder will
   // generate an error in this case.
@@ -50,26 +53,26 @@ class MCSectionGOFF final : public MCSection {
   friend class MCContext;
   friend class MCSymbolGOFF;
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::SDAttr SDAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+GOFF::SDAttr SDAttributes, MCSectionGOFF *Parent)
+  : MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
 Parent(Parent), SDAttributes(SDAttributes),
-SymbolType(GOFF::ESD_ST_SectionDefinition), RequiresNonZeroLength(0),
-Emitted(0) {}
+SymbolType(GOFF::ESD_ST_SectionDefinition), IsBSS(K.isBSS()),
+RequiresNonZeroLength(0), Emitted(0) {}
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::EDAttr EDAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+GOFF::EDAttr EDAttributes, MCSectionGOFF *Parent)
+  : MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
 Parent(Parent), EDAttributes(EDAttributes),
-SymbolType(GOFF::ESD_ST_ElementDefinition), RequiresNonZeroLength(0),
-Emitted(0) {}
+SymbolType(GOFF::ESD_ST_ElementDefinition), IsBSS(K.isBSS()),
+RequiresNonZeroLength(0), Emitted(0) {}
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::PRAttr PRAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+ 

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-23 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

@uweigand I made all the suggested changes.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-04-30 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

I had to force-push to get the fixed test cases.

https://github.com/llvm/llvm-project/pull/137235
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-04-30 Thread Kai Nacke via llvm-branch-commits

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



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-14 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;

redstar wrote:

I had to do a bit of research here. The Amode at the ED symbol acts as a 
default when no Amode at the LD/ER is present. The Amode at the PR seems to be 
not necessary. However, I need to check if this results in binder errors if I 
remove this.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-14 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;

redstar wrote:

No binding problems, so it seems sage to make this change. That said, amblist 
shows the Amode on PR and ED symbols.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-05-06 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

@MaskRay Sorry, your comment is basically empty. I guess a GitHub problem?

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-05-06 Thread Kai Nacke via llvm-branch-commits

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

>From c9b5b19f6f6cb74f0aaf5eac950158342d3a3ada Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Wed, 9 Apr 2025 15:08:52 -0400
Subject: [PATCH 1/4] [GOFF] Add writing of text records

Sections which are not allowed to carry data are marked as virtual.
Only complication when writing out the text is that it must be
written in chunks of 32k-1 bytes, which is done by having a wrapper
stream writing those records.
Data of BSS sections is not written, since the contents is known to
be zero. Instead, the fill byte value is used.
---
 llvm/include/llvm/MC/MCContext.h  |  6 +-
 llvm/include/llvm/MC/MCSectionGOFF.h  | 47 +++
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  |  5 +-
 llvm/lib/MC/GOFFObjectWriter.cpp  | 78 +++
 llvm/lib/MC/MCContext.cpp | 19 +++--
 llvm/lib/MC/MCObjectFileInfo.cpp  |  9 +--
 llvm/test/CodeGen/SystemZ/zos-section-1.ll| 27 +--
 llvm/test/CodeGen/SystemZ/zos-section-2.ll| 30 +--
 8 files changed, 180 insertions(+), 41 deletions(-)

diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 8eb904966f4de..2cdba64be116d 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -366,7 +366,8 @@ class MCContext {
 
   template 
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
-TAttr SDAttributes, MCSection *Parent);
+TAttr SDAttributes, MCSection *Parent,
+bool IsVirtual);
 
   /// Map of currently defined macros.
   StringMap MacroMap;
@@ -607,7 +608,8 @@ class MCContext {
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
 GOFF::SDAttr SDAttributes);
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
-GOFF::EDAttr EDAttributes, MCSection *Parent);
+GOFF::EDAttr EDAttributes, MCSection *Parent,
+bool IsVirtual);
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
 GOFF::PRAttr PRAttributes, MCSection *Parent);
 
diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h 
b/llvm/include/llvm/MC/MCSectionGOFF.h
index b8b8cf112a34d..b2ca74c3ba78a 100644
--- a/llvm/include/llvm/MC/MCSectionGOFF.h
+++ b/llvm/include/llvm/MC/MCSectionGOFF.h
@@ -39,6 +39,9 @@ class MCSectionGOFF final : public MCSection {
   // The type of this section.
   GOFF::ESDSymbolType SymbolType;
 
+  // This section is a BSS section.
+  unsigned IsBSS : 1;
+
   // Indicates that the PR symbol needs to set the length of the section to a
   // non-zero value. This is only a problem with the ADA PR - the binder will
   // generate an error in this case.
@@ -50,26 +53,26 @@ class MCSectionGOFF final : public MCSection {
   friend class MCContext;
   friend class MCSymbolGOFF;
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::SDAttr SDAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+GOFF::SDAttr SDAttributes, MCSectionGOFF *Parent)
+  : MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
 Parent(Parent), SDAttributes(SDAttributes),
-SymbolType(GOFF::ESD_ST_SectionDefinition), RequiresNonZeroLength(0),
-Emitted(0) {}
+SymbolType(GOFF::ESD_ST_SectionDefinition), IsBSS(K.isBSS()),
+RequiresNonZeroLength(0), Emitted(0) {}
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::EDAttr EDAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+GOFF::EDAttr EDAttributes, MCSectionGOFF *Parent)
+  : MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
 Parent(Parent), EDAttributes(EDAttributes),
-SymbolType(GOFF::ESD_ST_ElementDefinition), RequiresNonZeroLength(0),
-Emitted(0) {}
+SymbolType(GOFF::ESD_ST_ElementDefinition), IsBSS(K.isBSS()),
+RequiresNonZeroLength(0), Emitted(0) {}
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::PRAttr PRAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent)
+  : MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
 Parent(Parent), PRAttributes(PRAttributes),
-SymbolType(GOFF::ESD_ST_PartReference), RequiresNonZeroLength(0),
-Emitted(0) {}
+SymbolType(GOFF::ESD_ST_PartReference), IsBSS(K.isBSS()

[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-05-06 Thread Kai Nacke via llvm-branch-commits


@@ -688,28 +689,32 @@ MCSectionGOFF *MCContext::getGOFFSection(SectionKind 
Kind, StringRef Name,
 return Iter->second;
 
   StringRef CachedName = StringRef(Iter->first.c_str(), Name.size());
-  MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate()) MCSectionGOFF(
-  CachedName, Kind, Attributes, static_cast(Parent));
+  MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate())
+  MCSectionGOFF(CachedName, Kind, IsVirtual, Attributes,
+static_cast(Parent));
   Iter->second = GOFFSection;
   allocInitialFragment(*GOFFSection);
   return GOFFSection;
 }
 
 MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef Name,
  GOFF::SDAttr SDAttributes) {
-  return getGOFFSection(Kind, Name, SDAttributes, nullptr);
+  return getGOFFSection(Kind, Name, SDAttributes, nullptr,
+  /*IsVirtual=*/true);
 }
 
 MCSectionGOFF *MCContext::getGOFFSection(SectionKind Kind, StringRef Name,
  GOFF::EDAttr EDAttributes,
- MCSection *Parent) {
-  return getGOFFSection(Kind, Name, EDAttributes, Parent);
+ MCSection *Parent, bool IsVirtual) {
+  return getGOFFSection(Kind, Name, EDAttributes, Parent,
+  IsVirtual);

redstar wrote:

Good point, changed.

https://github.com/llvm/llvm-project/pull/137235
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-04-24 Thread Kai Nacke via llvm-branch-commits

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

>From 0e5c36a691fcbaa6f63c46f4cf86fa16857e137c Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Wed, 9 Apr 2025 15:08:52 -0400
Subject: [PATCH 1/2] [GOFF] Add writing of text records

Sections which are not allowed to carry data are marked as virtual.
Only complication when writing out the text is that it must be
written in chunks of 32k-1 bytes, which is done by having a wrapper
stream writing those records.
Data of BSS sections is not written, since the contents is known to
be zero. Instead, the fill byte value is used.
---
 llvm/include/llvm/MC/MCContext.h  |  6 +-
 llvm/include/llvm/MC/MCSectionGOFF.h  | 47 +++
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  |  5 +-
 llvm/lib/MC/GOFFObjectWriter.cpp  | 78 +++
 llvm/lib/MC/MCContext.cpp | 19 +++--
 llvm/lib/MC/MCObjectFileInfo.cpp  |  8 +-
 llvm/test/CodeGen/SystemZ/zos-section-1.ll| 27 +--
 llvm/test/CodeGen/SystemZ/zos-section-2.ll| 30 +--
 8 files changed, 180 insertions(+), 40 deletions(-)

diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 8eb904966f4de..2cdba64be116d 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -366,7 +366,8 @@ class MCContext {
 
   template 
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
-TAttr SDAttributes, MCSection *Parent);
+TAttr SDAttributes, MCSection *Parent,
+bool IsVirtual);
 
   /// Map of currently defined macros.
   StringMap MacroMap;
@@ -607,7 +608,8 @@ class MCContext {
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
 GOFF::SDAttr SDAttributes);
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
-GOFF::EDAttr EDAttributes, MCSection *Parent);
+GOFF::EDAttr EDAttributes, MCSection *Parent,
+bool IsVirtual);
   MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
 GOFF::PRAttr PRAttributes, MCSection *Parent);
 
diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h 
b/llvm/include/llvm/MC/MCSectionGOFF.h
index b8b8cf112a34d..b2ca74c3ba78a 100644
--- a/llvm/include/llvm/MC/MCSectionGOFF.h
+++ b/llvm/include/llvm/MC/MCSectionGOFF.h
@@ -39,6 +39,9 @@ class MCSectionGOFF final : public MCSection {
   // The type of this section.
   GOFF::ESDSymbolType SymbolType;
 
+  // This section is a BSS section.
+  unsigned IsBSS : 1;
+
   // Indicates that the PR symbol needs to set the length of the section to a
   // non-zero value. This is only a problem with the ADA PR - the binder will
   // generate an error in this case.
@@ -50,26 +53,26 @@ class MCSectionGOFF final : public MCSection {
   friend class MCContext;
   friend class MCSymbolGOFF;
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::SDAttr SDAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+GOFF::SDAttr SDAttributes, MCSectionGOFF *Parent)
+  : MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
 Parent(Parent), SDAttributes(SDAttributes),
-SymbolType(GOFF::ESD_ST_SectionDefinition), RequiresNonZeroLength(0),
-Emitted(0) {}
+SymbolType(GOFF::ESD_ST_SectionDefinition), IsBSS(K.isBSS()),
+RequiresNonZeroLength(0), Emitted(0) {}
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::EDAttr EDAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+GOFF::EDAttr EDAttributes, MCSectionGOFF *Parent)
+  : MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
 Parent(Parent), EDAttributes(EDAttributes),
-SymbolType(GOFF::ESD_ST_ElementDefinition), RequiresNonZeroLength(0),
-Emitted(0) {}
+SymbolType(GOFF::ESD_ST_ElementDefinition), IsBSS(K.isBSS()),
+RequiresNonZeroLength(0), Emitted(0) {}
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::PRAttr PRAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,
+GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent)
+  : MCSection(SV_GOFF, Name, K.isText(), IsVirtual, nullptr),
 Parent(Parent), PRAttributes(PRAttributes),
-SymbolType(GOFF::ESD_ST_PartReference), RequiresNonZeroLength(0),
-Emitted(0) {}
+SymbolType(GOFF::ESD_ST_PartReference), IsBSS(K.isBSS())

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDBindingStrength BindingStrength = GOFF::ESD_BST_Strong;

redstar wrote:

This is actually needed for C++ inline functions etc. which can end up in 
several object files. Also for weak definitions, e.g.:

```
// a.c
#include 

__attribute__((weak)) void fun() {
  printf("Weak fun\n");
}

void feature() {
  fun();
}
```
and
```
#include 

extern void feature();

void fun() {
  printf("Other fun\n");
}

int main(int argc, char *argv[]) {
  feature();
  return 0;
}
```
(example taken from a blog by @MaskRay)

Another case were the documentation needs an update.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,145 @@
+//===- MCSectionGOFF.cpp - GOFF Code Section Representation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/MC/MCSectionGOFF.h"
+#include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+void emitRMode(raw_ostream &OS, GOFF::ESDRmode Rmode, bool UseParenthesis) {
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << "RMODE" << (UseParenthesis ? '(' : ' ');
+switch (Rmode) {
+case GOFF::ESD_RMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_RMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_RMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_RMODE_None:
+  break;
+}
+if (UseParenthesis)
+  OS << ')';
+  }
+}
+
+void emitCATTR(raw_ostream &OS, StringRef Name, StringRef ParentName,
+   bool EmitAmodeAndRmode, GOFF::ESDAmode Amode,
+   GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment,
+   GOFF::ESDLoadingBehavior LoadBehavior,
+   GOFF::ESDExecutable Executable, bool IsReadOnly,
+   StringRef PartName) {
+  if (EmitAmodeAndRmode && Amode != GOFF::ESD_AMODE_None) {
+OS << ParentName << " AMODE ";
+switch (Amode) {
+case GOFF::ESD_AMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_AMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_AMODE_ANY:
+  OS << "ANY";
+  break;
+case GOFF::ESD_AMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_AMODE_MIN:
+  OS << "ANY64";
+  break;
+case GOFF::ESD_AMODE_None:
+  break;
+}
+OS << "\n";
+  }
+  if (EmitAmodeAndRmode && Rmode != GOFF::ESD_RMODE_None) {
+OS << ParentName << ' ';
+emitRMode(OS, Rmode, /*UseParenthesis=*/false);
+OS << "\n";
+  }
+  OS << Name << " CATTR ";
+  OS << "ALIGN(" << static_cast(Alignment) << ")";
+  switch (LoadBehavior) {
+  case GOFF::ESD_LB_Deferred:
+OS << ",DEFLOAD";
+break;
+  case GOFF::ESD_LB_NoLoad:
+OS << ",NOLOAD";
+break;
+  default:
+break;
+  }
+  switch (Executable) {
+  case GOFF::ESD_EXE_CODE:
+OS << ",EXECUTABLE";
+break;
+  case GOFF::ESD_EXE_DATA:
+OS << ",NOTEXECUTABLE";
+break;
+  default:
+break;
+  }
+  if (IsReadOnly)
+OS << ",READONLY";
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << ',';
+emitRMode(OS, Rmode, /*UseParenthesis=*/true);
+  }
+  if (!PartName.empty())
+OS << ",PART(" << PartName << ")";
+  OS << '\n';
+}
+} // namespace
+
+void MCSectionGOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
+ raw_ostream &OS,
+ uint32_t Subsection) const {
+  switch (SymbolType) {
+  case GOFF::ESD_ST_SectionDefinition: {
+OS << Name << " CSECT\n";
+Emitted = true;
+break;
+  }
+  case GOFF::ESD_ST_ElementDefinition: {
+bool ParentEmitted = getParent()->Emitted;
+getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+if (!Emitted) {
+  emitCATTR(OS, Name, getParent()->getName(), !ParentEmitted,
+EDAttributes.Amode, EDAttributes.Rmode, EDAttributes.Alignment,
+EDAttributes.LoadBehavior, EDAttributes.Executable,
+EDAttributes.IsReadOnly, StringRef());
+  Emitted = true;
+} else
+  OS << Name << " CATTR ,\n";
+break;
+  }
+  case GOFF::ESD_ST_PartReference: {
+MCSectionGOFF *ED = getParent();
+bool SDEmitted = ED->getParent()->Emitted;
+ED->getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+if (!Emitted) {
+  emitCATTR(OS, ED->getName(), ED->getParent()->getName(), !SDEmitted,
+PRAttributes.Amode, getParent()->EDAttributes.Rmode,
+PRAttributes.Alignment, getParent()->EDAttributes.LoadBehavior,

redstar wrote:

The HLASM statement
```
C_WSA64 CATTR ALIGN(4),DEFLOAD,NOTEXECUTABLE,RMODE(64),PART(a)
```
generates both the ED symbol `C_WSA64` and the PR symbol `a`.
At the ED symbol, Rmode and LoadBehaviour are set.
At the PR symbol, Amode (derived from RMode) and the LoadBehaviour are set. The 
latter looks like a HLASM bug. I am not aware of a way to defined the class 
(ED) and the part (PR) separately.


https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar edited 
https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,145 @@
+//===- MCSectionGOFF.cpp - GOFF Code Section Representation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/MC/MCSectionGOFF.h"
+#include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+void emitRMode(raw_ostream &OS, GOFF::ESDRmode Rmode, bool UseParenthesis) {
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << "RMODE" << (UseParenthesis ? '(' : ' ');
+switch (Rmode) {
+case GOFF::ESD_RMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_RMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_RMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_RMODE_None:
+  break;
+}
+if (UseParenthesis)
+  OS << ')';
+  }
+}
+
+void emitCATTR(raw_ostream &OS, StringRef Name, StringRef ParentName,
+   bool EmitAmodeAndRmode, GOFF::ESDAmode Amode,
+   GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment,
+   GOFF::ESDLoadingBehavior LoadBehavior,
+   GOFF::ESDExecutable Executable, bool IsReadOnly,
+   StringRef PartName) {
+  if (EmitAmodeAndRmode && Amode != GOFF::ESD_AMODE_None) {
+OS << ParentName << " AMODE ";

redstar wrote:

>  I think we should actually emit the AMODE for that instead.
I (or Tony) will do when emitting the labels.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,145 @@
+//===- MCSectionGOFF.cpp - GOFF Code Section Representation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/MC/MCSectionGOFF.h"
+#include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+void emitRMode(raw_ostream &OS, GOFF::ESDRmode Rmode, bool UseParenthesis) {
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << "RMODE" << (UseParenthesis ? '(' : ' ');
+switch (Rmode) {
+case GOFF::ESD_RMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_RMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_RMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_RMODE_None:
+  break;
+}
+if (UseParenthesis)
+  OS << ')';
+  }
+}
+
+void emitCATTR(raw_ostream &OS, StringRef Name, StringRef ParentName,
+   bool EmitAmodeAndRmode, GOFF::ESDAmode Amode,
+   GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment,
+   GOFF::ESDLoadingBehavior LoadBehavior,
+   GOFF::ESDExecutable Executable, bool IsReadOnly,
+   StringRef PartName) {
+  if (EmitAmodeAndRmode && Amode != GOFF::ESD_AMODE_None) {
+OS << ParentName << " AMODE ";
+switch (Amode) {
+case GOFF::ESD_AMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_AMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_AMODE_ANY:
+  OS << "ANY";
+  break;
+case GOFF::ESD_AMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_AMODE_MIN:
+  OS << "ANY64";
+  break;
+case GOFF::ESD_AMODE_None:
+  break;
+}
+OS << "\n";
+  }
+  if (EmitAmodeAndRmode && Rmode != GOFF::ESD_RMODE_None) {
+OS << ParentName << ' ';
+emitRMode(OS, Rmode, /*UseParenthesis=*/false);
+OS << "\n";
+  }
+  OS << Name << " CATTR ";
+  OS << "ALIGN(" << static_cast(Alignment) << ")";
+  switch (LoadBehavior) {
+  case GOFF::ESD_LB_Deferred:
+OS << ",DEFLOAD";
+break;
+  case GOFF::ESD_LB_NoLoad:
+OS << ",NOLOAD";
+break;
+  default:
+break;
+  }
+  switch (Executable) {
+  case GOFF::ESD_EXE_CODE:
+OS << ",EXECUTABLE";
+break;
+  case GOFF::ESD_EXE_DATA:
+OS << ",NOTEXECUTABLE";
+break;
+  default:
+break;
+  }
+  if (IsReadOnly)
+OS << ",READONLY";
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << ',';
+emitRMode(OS, Rmode, /*UseParenthesis=*/true);
+  }
+  if (!PartName.empty())
+OS << ",PART(" << PartName << ")";
+  OS << '\n';
+}
+} // namespace
+
+void MCSectionGOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
+ raw_ostream &OS,
+ uint32_t Subsection) const {
+  switch (SymbolType) {
+  case GOFF::ESD_ST_SectionDefinition: {
+OS << Name << " CSECT\n";
+Emitted = true;
+break;
+  }
+  case GOFF::ESD_ST_ElementDefinition: {
+bool ParentEmitted = getParent()->Emitted;
+getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+if (!Emitted) {
+  emitCATTR(OS, Name, getParent()->getName(), !ParentEmitted,
+EDAttributes.Amode, EDAttributes.Rmode, EDAttributes.Alignment,
+EDAttributes.LoadBehavior, EDAttributes.Executable,
+EDAttributes.IsReadOnly, StringRef());
+  Emitted = true;
+} else
+  OS << Name << " CATTR ,\n";
+break;
+  }
+  case GOFF::ESD_ST_PartReference: {
+MCSectionGOFF *ED = getParent();
+bool SDEmitted = ED->getParent()->Emitted;
+ED->getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+if (!Emitted) {
+  emitCATTR(OS, ED->getName(), ED->getParent()->getName(), !SDEmitted,
+PRAttributes.Amode, getParent()->EDAttributes.Rmode,
+PRAttributes.Alignment, getParent()->EDAttributes.LoadBehavior,
+PRAttributes.Executable, PRAttributes.IsReadOnly, Name);

redstar wrote:

Yes, PRIORITY is needed.
I also emit the XATTR now. I emit REFERENCE(CODE/DATA), but I test if it is 
needed. It does not interact with CATTR [NON]EXECUTABLE but may interact with 
the EXECUTABLE/DATA property set at the external symbol referring to this part. 
In the past I got binder errors when when those were not matching but I have to 
check if this is true for PR symbols.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -26,6 +27,23 @@ GOFFObjectWriter &MCGOFFStreamer::getWriter() {
   return static_cast(getAssembler().getWriter());
 }
 
+namespace {
+// Make sure that all section are registered in the correct order.
+void registerSectionHierarchy(MCAssembler &Asm, MCSectionGOFF *Section) {

redstar wrote:

Remove the anonymous namespace, and added `static`.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -599,8 +600,18 @@ class MCContext {
unsigned Flags,
unsigned EntrySize);
 
-  MCSectionGOFF *getGOFFSection(StringRef Section, SectionKind Kind,
-MCSection *Parent, uint32_t Subsection = 0);
+private:

redstar wrote:

Moved the code.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,112 @@
+; RUN: llc <%s --mtriple s390x-ibm-zos --filetype=obj -o - | \

redstar wrote:

Moved the tests.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -26,6 +27,23 @@ GOFFObjectWriter &MCGOFFStreamer::getWriter() {
   return static_cast(getAssembler().getWriter());
 }
 
+namespace {
+// Make sure that all section are registered in the correct order.
+void registerSectionHierarchy(MCAssembler &Asm, MCSectionGOFF *Section) {

redstar wrote:

Remove the anonymous namespace, and added `static`.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,141 @@
+//===- MCSectionGOFF.cpp - GOFF Code Section Representation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/MC/MCSectionGOFF.h"
+#include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+void emitCATTR(raw_ostream &OS, StringRef Name, GOFF::ESDRmode Rmode,

redstar wrote:

Remove the anonymous namespace, and added `static`.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-10 Thread Kai Nacke via llvm-branch-commits


@@ -16,34 +16,95 @@
 #define LLVM_MC_MCSECTIONGOFF_H
 
 #include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/MC/MCGOFFAttributes.h"
 #include "llvm/MC/MCSection.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
 
 class MCExpr;
 
 class MCSectionGOFF final : public MCSection {
-private:
-  MCSection *Parent;
-  uint32_t Subsection;
+  // Parent of this section. Implies that the parent is emitted first.
+  MCSectionGOFF *Parent;
+
+  // The attributes of the GOFF symbols.
+  GOFF::SDAttr SDAttributes;
+  GOFF::EDAttr EDAttributes;
+  GOFF::PRAttr PRAttributes;

redstar wrote:

Yes, I was thinking about that (but wanted to get everything to work first).

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,145 @@
+//===- MCSectionGOFF.cpp - GOFF Code Section Representation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/MC/MCSectionGOFF.h"
+#include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+void emitRMode(raw_ostream &OS, GOFF::ESDRmode Rmode, bool UseParenthesis) {
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << "RMODE" << (UseParenthesis ? '(' : ' ');
+switch (Rmode) {
+case GOFF::ESD_RMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_RMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_RMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_RMODE_None:
+  break;
+}
+if (UseParenthesis)
+  OS << ')';
+  }
+}
+
+void emitCATTR(raw_ostream &OS, StringRef Name, StringRef ParentName,
+   bool EmitAmodeAndRmode, GOFF::ESDAmode Amode,
+   GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment,
+   GOFF::ESDLoadingBehavior LoadBehavior,
+   GOFF::ESDExecutable Executable, bool IsReadOnly,
+   StringRef PartName) {
+  if (EmitAmodeAndRmode && Amode != GOFF::ESD_AMODE_None) {
+OS << ParentName << " AMODE ";
+switch (Amode) {
+case GOFF::ESD_AMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_AMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_AMODE_ANY:
+  OS << "ANY";
+  break;
+case GOFF::ESD_AMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_AMODE_MIN:
+  OS << "ANY64";
+  break;
+case GOFF::ESD_AMODE_None:
+  break;
+}
+OS << "\n";
+  }
+  if (EmitAmodeAndRmode && Rmode != GOFF::ESD_RMODE_None) {
+OS << ParentName << ' ';
+emitRMode(OS, Rmode, /*UseParenthesis=*/false);
+OS << "\n";
+  }
+  OS << Name << " CATTR ";
+  OS << "ALIGN(" << static_cast(Alignment) << ")";
+  switch (LoadBehavior) {
+  case GOFF::ESD_LB_Deferred:
+OS << ",DEFLOAD";
+break;
+  case GOFF::ESD_LB_NoLoad:
+OS << ",NOLOAD";
+break;
+  default:
+break;
+  }
+  switch (Executable) {
+  case GOFF::ESD_EXE_CODE:
+OS << ",EXECUTABLE";
+break;
+  case GOFF::ESD_EXE_DATA:
+OS << ",NOTEXECUTABLE";
+break;
+  default:
+break;
+  }
+  if (IsReadOnly)
+OS << ",READONLY";
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << ',';
+emitRMode(OS, Rmode, /*UseParenthesis=*/true);
+  }
+  if (!PartName.empty())
+OS << ",PART(" << PartName << ")";
+  OS << '\n';
+}
+} // namespace
+
+void MCSectionGOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
+ raw_ostream &OS,
+ uint32_t Subsection) const {
+  switch (SymbolType) {
+  case GOFF::ESD_ST_SectionDefinition: {
+OS << Name << " CSECT\n";
+Emitted = true;
+break;
+  }
+  case GOFF::ESD_ST_ElementDefinition: {
+bool ParentEmitted = getParent()->Emitted;
+getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+if (!Emitted) {
+  emitCATTR(OS, Name, getParent()->getName(), !ParentEmitted,
+EDAttributes.Amode, EDAttributes.Rmode, EDAttributes.Alignment,
+EDAttributes.LoadBehavior, EDAttributes.Executable,
+EDAttributes.IsReadOnly, StringRef());
+  Emitted = true;
+} else
+  OS << Name << " CATTR ,\n";
+break;
+  }
+  case GOFF::ESD_ST_PartReference: {
+MCSectionGOFF *ED = getParent();
+bool SDEmitted = ED->getParent()->Emitted;
+ED->getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+if (!Emitted) {
+  emitCATTR(OS, ED->getName(), ED->getParent()->getName(), !SDEmitted,
+PRAttributes.Amode, getParent()->EDAttributes.Rmode,
+PRAttributes.Alignment, getParent()->EDAttributes.LoadBehavior,
+PRAttributes.Executable, PRAttributes.IsReadOnly, Name);
+  ED->Emitted = true;
+  Emitted = true;
+} else
+  OS << ED->getName() << " CATTR ,\n";

redstar wrote:

My understaning is that it is sometimes done to get past the operand parsing in 
HLASM.
However, I just realized that the part name needs to be emitted, otherwise the 
CATTR statement produces an error.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-15 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar edited 
https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-29 Thread Kai Nacke via llvm-branch-commits


@@ -223,13 +197,95 @@ void GOFFOstream::finalizeRecord() {
 }
 
 namespace {
+// A GOFFSymbol holds all the data required for writing an ESD record.
+class GOFFSymbol {
+public:
+  std::string Name;
+  uint32_t EsdId;
+  uint32_t ParentEsdId;
+  uint64_t Offset = 0; // Offset of the symbol into the section. LD only.
+   // Offset is only 32 bit, the larger type is used to
+   // enable error checking.
+  GOFF::ESDSymbolType SymbolType;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_ProgramManagementBinder;
+
+  GOFF::BehavioralAttributes BehavAttrs;
+  GOFF::SymbolFlags SymbolFlags;
+  uint32_t SortKey = 0;
+  uint32_t SectionLength = 0;
+  uint32_t ADAEsdId = 0;
+  uint32_t EASectionEDEsdId = 0;
+  uint32_t EASectionOffset = 0;
+  uint8_t FillByteValue = 0;
+
+  GOFFSymbol() : EsdId(0), ParentEsdId(0) {}
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, const GOFF::SDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(0),
+SymbolType(GOFF::ESD_ST_SectionDefinition) {
+BehavAttrs.setTaskingBehavior(Attr.TaskingBehavior);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const GOFF::EDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_ElementDefinition) {
+this->NameSpace = Attr.NameSpace;
+// TODO Do we need/should set the "mangled" flag?
+SymbolFlags.setFillBytePresence(1);

redstar wrote:

That is a good point, because then we can also emit BSS data using the ORG 
instruction.
According to the AMBLIST output, the fill byte always ends up at the ED element.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-29 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,145 @@
+//===- MCSectionGOFF.cpp - GOFF Code Section Representation 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/MC/MCSectionGOFF.h"
+#include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+void emitRMode(raw_ostream &OS, GOFF::ESDRmode Rmode, bool UseParenthesis) {
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << "RMODE" << (UseParenthesis ? '(' : ' ');
+switch (Rmode) {
+case GOFF::ESD_RMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_RMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_RMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_RMODE_None:
+  break;
+}
+if (UseParenthesis)
+  OS << ')';
+  }
+}
+
+void emitCATTR(raw_ostream &OS, StringRef Name, StringRef ParentName,
+   bool EmitAmodeAndRmode, GOFF::ESDAmode Amode,
+   GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment,
+   GOFF::ESDLoadingBehavior LoadBehavior,
+   GOFF::ESDExecutable Executable, bool IsReadOnly,
+   StringRef PartName) {
+  if (EmitAmodeAndRmode && Amode != GOFF::ESD_AMODE_None) {
+OS << ParentName << " AMODE ";
+switch (Amode) {
+case GOFF::ESD_AMODE_24:
+  OS << "24";
+  break;
+case GOFF::ESD_AMODE_31:
+  OS << "31";
+  break;
+case GOFF::ESD_AMODE_ANY:
+  OS << "ANY";
+  break;
+case GOFF::ESD_AMODE_64:
+  OS << "64";
+  break;
+case GOFF::ESD_AMODE_MIN:
+  OS << "ANY64";
+  break;
+case GOFF::ESD_AMODE_None:
+  break;
+}
+OS << "\n";
+  }
+  if (EmitAmodeAndRmode && Rmode != GOFF::ESD_RMODE_None) {
+OS << ParentName << ' ';
+emitRMode(OS, Rmode, /*UseParenthesis=*/false);
+OS << "\n";
+  }
+  OS << Name << " CATTR ";
+  OS << "ALIGN(" << static_cast(Alignment) << ")";
+  switch (LoadBehavior) {
+  case GOFF::ESD_LB_Deferred:
+OS << ",DEFLOAD";
+break;
+  case GOFF::ESD_LB_NoLoad:
+OS << ",NOLOAD";
+break;
+  default:
+break;
+  }
+  switch (Executable) {
+  case GOFF::ESD_EXE_CODE:
+OS << ",EXECUTABLE";
+break;
+  case GOFF::ESD_EXE_DATA:
+OS << ",NOTEXECUTABLE";
+break;
+  default:
+break;
+  }
+  if (IsReadOnly)
+OS << ",READONLY";
+  if (Rmode != GOFF::ESD_RMODE_None) {
+OS << ',';
+emitRMode(OS, Rmode, /*UseParenthesis=*/true);
+  }
+  if (!PartName.empty())
+OS << ",PART(" << PartName << ")";
+  OS << '\n';
+}
+} // namespace
+
+void MCSectionGOFF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
+ raw_ostream &OS,
+ uint32_t Subsection) const {
+  switch (SymbolType) {
+  case GOFF::ESD_ST_SectionDefinition: {
+OS << Name << " CSECT\n";
+Emitted = true;
+break;
+  }
+  case GOFF::ESD_ST_ElementDefinition: {
+bool ParentEmitted = getParent()->Emitted;
+getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+if (!Emitted) {
+  emitCATTR(OS, Name, getParent()->getName(), !ParentEmitted,
+EDAttributes.Amode, EDAttributes.Rmode, EDAttributes.Alignment,
+EDAttributes.LoadBehavior, EDAttributes.Executable,
+EDAttributes.IsReadOnly, StringRef());
+  Emitted = true;
+} else
+  OS << Name << " CATTR ,\n";
+break;
+  }
+  case GOFF::ESD_ST_PartReference: {
+MCSectionGOFF *ED = getParent();
+bool SDEmitted = ED->getParent()->Emitted;
+ED->getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+if (!Emitted) {
+  emitCATTR(OS, ED->getName(), ED->getParent()->getName(), !SDEmitted,
+PRAttributes.Amode, getParent()->EDAttributes.Rmode,
+PRAttributes.Alignment, getParent()->EDAttributes.LoadBehavior,

redstar wrote:

IMHO there is no need to replicate the HLASM behaviour. The 
[table](https://www.ibm.com/docs/en/zos/3.1.0?topic=record-esd-item-behavioral-attribute-assignment)
 in the MVS Program Management: Advanced Facilities book clearly states that 
the LoadBehaviour and the Rmode are set at the ED.

Unfortunately, the attributes which can be set at the PR are in [another 
table](https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes),
 inside the notes. This does not include LoadBehaviour and Rmode.

Over the first table there is a similar comment: "Note that the attributes of 
PR items (with the exception of alignment) are determined from the element EDID 
to which they belong." This seems to imply that those attributes set at the ED 
do not need to be set at the PR but I could not verify 

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-29 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,106 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  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;
+};
+
+// Attributes for PR symbols.
+struct PRAttr {
+  bool IsRenamable = false;
+  bool IsReadOnly = false; //  Not documented.
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDLinkageType Linkage = GOFF::ESD_LT_XPLink;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Byte;

redstar wrote:

The requirement for the alignment is that the aligment of ED must be equal or 
higher than the alignment of PR. However, to my knowledge it is not possible to 
share the ED element among several PR elements (because the SD must have the 
same name as the PR). Which means that both alignments are the same.
In HLASM, the alignment is given with the CATTR statement. If the CATTR defines 
no PART, then the alignment is set at the ED element, otherwise the same value 
is set at the ED and PR element.
I remove the alignment in the PR.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-04-29 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

> Why do we need all that "virtual section" stuff? Wouldn't it suffice to exit 
> early from ::writeText if the section length is zero?

A virtual sections cannot contain data, and the MC layer checks that this is 
the case. This is the benefit I see in using a virtual sections. But of course, 
it is sufficient to just check the section length. 

https://github.com/llvm/llvm-project/pull/137235
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-29 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDAmode Amode;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDBindingStrength BindingStrength = GOFF::ESD_BST_Strong;

redstar wrote:

I need to ask for this. I see only WXTRN for weak externals in the HLASM 
documentation.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-04-29 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

> Also, the new tests seem to be failing in CI.

It's also failing in the base PR. Looks like I made a mistake with my last 
update.

https://github.com/llvm/llvm-project/pull/137235
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-29 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,106 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDRmode Rmode;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_NormalName;
+  GOFF::ESDTextStyle TextStyle = GOFF::ESD_TS_ByteOriented;
+  GOFF::ESDBindingAlgorithm BindAlgorithm = GOFF::ESD_BA_Concatenate;
+  GOFF::ESDLoadingBehavior LoadBehavior = GOFF::ESD_LB_Initial;
+  GOFF::ESDReserveQwords ReservedQwords = GOFF::ESD_RQ_0;
+  GOFF::ESDAlignment Alignment = GOFF::ESD_ALIGN_Doubleword;
+};
+
+// Attributes for LD symbols.
+struct LDAttr {
+  bool IsRenamable = false;
+  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;
+};
+
+// Attributes for PR symbols.
+struct PRAttr {
+  bool IsRenamable = false;
+  bool IsReadOnly = false; //  Not documented.

redstar wrote:

I checked again, and it seems we are only using the default value. I remove it.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-21 Thread Kai Nacke via llvm-branch-commits


@@ -0,0 +1,113 @@
+//===- MCGOFFAttributes.h - Attributes of GOFF symbols 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines the various attribute collections defining GOFF symbols.
+//
+//===--===//
+
+#ifndef LLVM_MC_MCGOFFATTRIBUTES_H
+#define LLVM_MC_MCGOFFATTRIBUTES_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/GOFF.h"
+
+namespace llvm {
+namespace GOFF {
+// An "External Symbol Definition" in the GOFF file has a type, and depending 
on
+// the type a different subset of the fields is used.
+//
+// Unlike other formats, a 2 dimensional structure is used to define the
+// location of data. For example, the equivalent of the ELF .text section is
+// made up of a Section Definition (SD) and a class (Element Definition; ED).
+// The name of the SD symbol depends on the application, while the class has 
the
+// predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.
+//
+// Data can be placed into this structure in 2 ways. First, the data (in a text
+// record) can be associated with an ED symbol. To refer to data, a Label
+// Definition (LD) is used to give an offset into the data a name. When 
binding,
+// the whole data is pulled into the resulting executable, and the addresses
+// given by the LD symbols are resolved.
+//
+// The alternative is to use a Part Definition (PR). In this case, the data (in
+// a text record) is associated with the part. When binding, only the data of
+// referenced PRs is pulled into the resulting binary.
+//
+// Both approaches are used, which means that the equivalent of a section in 
ELF
+// results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain
+// sections are fine with just defining SD/ED symbols. The SymbolMapper takes
+// care of all those details.
+
+// Attributes for SD symbols.
+struct SDAttr {
+  GOFF::ESDTaskingBehavior TaskingBehavior = GOFF::ESD_TA_Unspecified;
+  GOFF::ESDBindingScope BindingScope = GOFF::ESD_BSC_Unspecified;
+};
+
+// Attributes for ED symbols.
+struct EDAttr {
+  bool IsReadOnly = false;
+  GOFF::ESDExecutable Executable = GOFF::ESD_EXE_Unspecified;

redstar wrote:

Well, while my statement is true it also means there is no way to refer to such 
data.
I checked, it's not required.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

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

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/7] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

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

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/6] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-04 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

> Thinking a bit more about this, it looks to me that we should treat SD/ED/PR 
> on the one hand differently from LD (and ER) on the other. The former 
> identify a range of address space and may hold contents of those ranges in 
> the form of text records; the latter identify a single address (and hold no 
> content of their own).

Yes, that is correct.

> From that perspective, the former correspond to the "section" concept, while 
> the latter correspond to the "symbol" concept. Now, among the section types 
> SD/ED/PR, GOFF is a bit special in that those are nested - this is somewhat 
> similar to the subsection concept, but it is explicit in the object file 
> format (as opposed to, say, ELF subsections).

I try to implement this. Well, first I'll fix the failing test cases

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

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

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/2] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits


@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)

redstar wrote:

For ED- and PR-type records, this field specifies the amount of space (in 
multiples of 16-byte quadwords) that the Binder will reserve at the origin of 
an element.
It's required, and the documentation needs an update.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

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

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/3] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

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

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/4] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-03 Thread Kai Nacke via llvm-branch-commits


@@ -2767,15 +2774,55 @@ MCSection 
*TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
 MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA(
 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
   std::string Name = ".gcc_exception_table." + F.getName().str();
-  return getContext().getGOFFSection(Name, SectionKind::getData(), nullptr, 0);
+  constexpr bool Is64Bit = true;
+  constexpr bool UsesXPLINK = true;
+  return getContext().getGOFFSection(
+  SectionKind::getData(), GOFF::WSA,
+  GOFF::EDAttr{false, GOFF::ESD_EXE_DATA, GOFF::AMODE,
+   GOFF::RMODE, GOFF::ESD_NS_Parts,
+   GOFF::ESD_TS_ByteOriented, GOFF::ESD_BA_Merge,
+   GOFF::LOADBEHAVIOR, GOFF::ESD_RQ_0,
+   GOFF::ESD_ALIGN_Doubleword},
+  Name,
+  GOFF::PRAttr{true, false, GOFF::ESD_EXE_Unspecified, GOFF::ESD_NS_Parts,
+   GOFF::LINKAGE, GOFF::AMODE,
+   GOFF::ESD_BSC_Section, GOFF::ESD_DSS_NoWarning,
+   GOFF::ESD_ALIGN_Fullword, 0});
 }
 
 MCSection *TargetLoweringObjectFileGOFF::SelectSectionForGlobal(
 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
   auto *Symbol = TM.getSymbol(GO);
-  if (Kind.isBSS())
-return getContext().getGOFFSection(Symbol->getName(), 
SectionKind::getBSS(),
-   nullptr, 0);
-
-  return getContext().getObjectFileInfo()->getTextSection();
+  constexpr bool Is64Bit = true;
+  constexpr bool UsesXPLINK = true;
+
+  if (Kind.isBSS() || Kind.isData()) {

redstar wrote:

Yes.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-03 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +309,102 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::SDAttr 
&Attr) {
+  return GOFFSymbol(Name, ++EsdIdCounter, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::EDAttr 
&Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::LDAttr 
&Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::PRAttr 
&Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+void GOFFWriter::defineRootSymbol(const MCSectionGOFF *Text) {
+  // There is always a text section except for DWARF unit tests, so be lenient.
+  GOFFSymbol RootSD =
+  Text ? createGOFFSymbol(Text->getSDName(), Text->getSDAttributes())
+   : createGOFFSymbol("", GOFF::SDAttr{GOFF::ESD_TA_Unspecified,
+   GOFF::ESD_BSC_Unspecified});
+  writeSymbol(RootSD);
+  RootSDEsdId = RootSD.EsdId;
+}
+
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+uint32_t SDEsdId = RootSDEsdId;
+if (!Section.usesRootSD()) {
+  GOFFSymbol SD =
+  createGOFFSymbol(Section.getSDName(), Section.getSDAttributes());
+  SDEsdId = SD.EsdId;
+  writeSymbol(SD);
+}
+
+GOFFSymbol ED = createGOFFSymbol(Section.getEDName(),
+ Section.getEDAttributes(), SDEsdId);
+if ((!Section.hasLD() && !Section.hasPR()) || Section.hasLD()) {
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+}
+writeSymbol(ED);
+
+if (Section.hasLD()) {
+  GOFFSymbol LD = createGOFFSymbol(Section.getLDorPRName(),
+   Section.getLDAttributes(), ED.EsdId);
+  if (Section.isText())
+LD.ADAEsdId = ADAEsdId;
+  writeSymbol(LD);
+}
+
+if (Section.hasPR()) {
+  GOFFSymbol PR = createGOFFSymbol(Section.getLDorPRName(),
+   Section.getPRAttributes(), ED.EsdId);
+  PR.SectionLength = Asm.getSectionAddressSize(Section);
+  if (Section.getName() == ".ada") {

redstar wrote:

Yes, that does not work.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-03 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar edited 
https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-03 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +309,102 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::SDAttr 
&Attr) {
+  return GOFFSymbol(Name, ++EsdIdCounter, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::EDAttr 
&Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::LDAttr 
&Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::PRAttr 
&Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+void GOFFWriter::defineRootSymbol(const MCSectionGOFF *Text) {
+  // There is always a text section except for DWARF unit tests, so be lenient.
+  GOFFSymbol RootSD =
+  Text ? createGOFFSymbol(Text->getSDName(), Text->getSDAttributes())
+   : createGOFFSymbol("", GOFF::SDAttr{GOFF::ESD_TA_Unspecified,
+   GOFF::ESD_BSC_Unspecified});
+  writeSymbol(RootSD);
+  RootSDEsdId = RootSD.EsdId;
+}
+
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+uint32_t SDEsdId = RootSDEsdId;
+if (!Section.usesRootSD()) {
+  GOFFSymbol SD =
+  createGOFFSymbol(Section.getSDName(), Section.getSDAttributes());
+  SDEsdId = SD.EsdId;
+  writeSymbol(SD);
+}
+
+GOFFSymbol ED = createGOFFSymbol(Section.getEDName(),
+ Section.getEDAttributes(), SDEsdId);
+if ((!Section.hasLD() && !Section.hasPR()) || Section.hasLD()) {
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+}
+writeSymbol(ED);
+
+if (Section.hasLD()) {
+  GOFFSymbol LD = createGOFFSymbol(Section.getLDorPRName(),
+   Section.getLDAttributes(), ED.EsdId);
+  if (Section.isText())
+LD.ADAEsdId = ADAEsdId;
+  writeSymbol(LD);
+}
+
+if (Section.hasPR()) {
+  GOFFSymbol PR = createGOFFSymbol(Section.getLDorPRName(),
+   Section.getPRAttributes(), ED.EsdId);
+  PR.SectionLength = Asm.getSectionAddressSize(Section);
+  if (Section.getName() == ".ada") {

redstar wrote:

Changed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-03 Thread Kai Nacke via llvm-branch-commits


@@ -223,21 +196,222 @@ void GOFFOstream::finalizeRecord() {
 }
 
 namespace {
+// A GOFFSymbol holds all the data required for writing an ESD record.
+class GOFFSymbol {
+public:
+  std::string Name;
+  uint32_t EsdId;
+  uint32_t ParentEsdId;
+  uint64_t Offset = 0; // Offset of the symbol into the section. LD only.
+   // Offset is only 32 bit, the larger type is used to
+   // enable error checking.
+  GOFF::ESDSymbolType SymbolType;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_ProgramManagementBinder;
+
+  GOFF::BehavioralAttributes BehavAttrs;
+  GOFF::SymbolFlags SymbolFlags;
+  uint32_t SortKey = 0;
+  uint32_t SectionLength = 0;
+  uint32_t ADAEsdId = 0;
+  uint32_t EASectionEDEsdId = 0;
+  uint32_t EASectionOffset = 0;
+  uint8_t FillByteValue = 0;
+
+  GOFFSymbol() : EsdId(0), ParentEsdId(0) {}
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, const SDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(0),
+SymbolType(GOFF::ESD_ST_SectionDefinition) {
+BehavAttrs.setTaskingBehavior(Attr.TaskingBehavior);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const EDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_ElementDefinition) {
+this->NameSpace = Attr.NameSpace;
+// TODO Do we need/should set the "mangled" flag?
+SymbolFlags.setFillBytePresence(1);
+SymbolFlags.setReservedQwords(Attr.ReservedQwords);
+BehavAttrs.setReadOnly(Attr.IsReadOnly);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setRmode(Attr.Rmode);
+BehavAttrs.setTextStyle(Attr.TextStyle);
+BehavAttrs.setBindingAlgorithm(Attr.BindAlgorithm);
+BehavAttrs.setLoadingBehavior(Attr.LoadBehavior);
+BehavAttrs.setAlignment(Attr.Alignment);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const LDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_LabelDefinition) {
+this->NameSpace = Attr.NameSpace;
+SymbolFlags.setRenameable(Attr.IsRenamable);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setBindingStrength(Attr.BindingStrength);
+BehavAttrs.setLinkageType(Attr.Linkage);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const PRAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_PartReference) {
+this->NameSpace = Attr.NameSpace;
+SymbolFlags.setRenameable(Attr.IsRenamable);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setAlignment(Attr.Alignment);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setLinkageType(Attr.Linkage);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+BehavAttrs.setDuplicateSymbolSeverity(Attr.DuplicateSymbolSeverity);
+BehavAttrs.setReadOnly(Attr.IsReadOnly);
+  }
+};
+
 class GOFFWriter {
   GOFFOstream OS;
   [[maybe_unused]] MCAssembler &Asm;
 
+  /// Mapping from MCSectionGOFF/MCSymbolGOFF to GOFF symbols and attributes.
+  GOFFSymbolMapper SymbolMapper;
+
+  /// Counter for symbol id's.
+  uint32_t EsdIdCounter = 0;
+
+  /// Id's of some special symbols.
+  uint32_t RootSDEsdId = 0;
+  uint32_t ADAEsdId = 0;
+
   void writeHeader();
+  void writeSymbol(const GOFFSymbol &Symbol);
   void writeEnd();
 
+  GOFFSymbol createGOFFSymbol(StringRef Name, const SDAttr &Attr);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const EDAttr &Attr,
+  uint32_t ParentEsdId);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const LDAttr &Attr,
+  uint32_t ParentEsdId);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const PRAttr &Attr,
+  uint32_t ParentEsdId);
+
+  void defineRootSymbol(const MCSectionGOFF *Text);
+  void defineSectionSymbols(const MCSectionGOFF &Section);
+  void defineSymbols();
+
 public:
   GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm);
   uint64_t writeObject();
 };
 } // namespace
 
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
-: OS(OS), Asm(Asm) {}
+: OS(OS), Asm(Asm), SymbolMapper(Asm) {}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const SDAttr &Attr) {
+  return GOFFSymbol(Name, ++EsdIdCounter, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const EDAttr &Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const LDAttr &Attr,
+uint32_t Par

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-03 Thread Kai Nacke via llvm-branch-commits


@@ -19,7 +19,7 @@
 ; CHECK:.quad   L#PPA2-CELQSTRT * A(PPA2-CELQSTRT)
 ; CHECK: L#PPA1_void_test_0:
 ; CHECK:.long   L#PPA2-L#PPA1_void_test_0   * Offset to PPA2
-; CHECK:.section"B_IDRL"
+; CHECK:.section".idrl"

redstar wrote:

My intention was to have unique, uniform synthetic name for the sections. But 
with Uli's suggestion this is gone now. In the object file/HLASM file, the name 
is indeed B_IDRL.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-03 Thread Kai Nacke via llvm-branch-commits


@@ -2767,15 +2774,55 @@ MCSection 
*TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
 MCSection *TargetLoweringObjectFileGOFF::getSectionForLSDA(
 const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const {
   std::string Name = ".gcc_exception_table." + F.getName().str();
-  return getContext().getGOFFSection(Name, SectionKind::getData(), nullptr, 0);
+  constexpr bool Is64Bit = true;
+  constexpr bool UsesXPLINK = true;

redstar wrote:

My goal was to mark those values somehow, because it is very difficult to 
consistently find those spots again. But using a constant is enough, so this is 
gone now.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-03 Thread Kai Nacke via llvm-branch-commits

redstar wrote:

> Does this make sense or am I missing something here?

I think that splitting the SD/ED/LD into 3 "section"s implies that a 
MCSectionGOFF has a fundamentally different semantic than the other 
MCSectionXXX. This is something I would like to avoid. On the other hand, the 
SD/ED pair is almost the same as an ELF section, so just putting those 2 into a 
MCSectionGOFF instance and handling the LD/PR symbol differently makes sense. 
In HLASM, a section definition looks like
```
HLASMHEL CSECT* The SD symbol
HLASMHEL AMODE 64
HLASMHEL RMODE ANY
C_CODE64 CATTR EXECUTABLE,RENT* The ED symbol; the LD symbol is 
automatically generated.
 ENTRY MAIN
MAIN AMODE 64
MAIN XATTR LINKAGE(XPLINK),SCOPE(LIBRARY),REFERENCE(CODE)
MAIN DS0FD* A "normal" label, with attributes. 
Results in another LD symbol
```

When I switch sections, and later want to continue the code section, then I 
need to repeat both statements in a short form:

```
HLASMHEL CSECT ,
C_CODE64 CATTR ,
```

I thought about this when moving the definitions from the SymbolMapper to the 
MCObjectFileInfo class, but I got no good idea how to handle the LD or PR 
symbol. A possible way could be to attach the LD or PR symbol as the begin 
symbol of a section. I need to try this.

One possible downside is that it makes handling of relocations much more 
complicated. For the base of a relocation, I need the PR symbol (when I have 
the SD/ED/PR case) or the LD and ED (in the SD/ED/LD case). Currently, this 
information is available in the MCSectionGOFF, without the need to chase a list 
to the correct element.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits


@@ -223,21 +196,222 @@ void GOFFOstream::finalizeRecord() {
 }
 
 namespace {
+// A GOFFSymbol holds all the data required for writing an ESD record.
+class GOFFSymbol {
+public:
+  std::string Name;
+  uint32_t EsdId;
+  uint32_t ParentEsdId;
+  uint64_t Offset = 0; // Offset of the symbol into the section. LD only.
+   // Offset is only 32 bit, the larger type is used to
+   // enable error checking.
+  GOFF::ESDSymbolType SymbolType;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_ProgramManagementBinder;
+
+  GOFF::BehavioralAttributes BehavAttrs;
+  GOFF::SymbolFlags SymbolFlags;
+  uint32_t SortKey = 0;
+  uint32_t SectionLength = 0;
+  uint32_t ADAEsdId = 0;
+  uint32_t EASectionEDEsdId = 0;
+  uint32_t EASectionOffset = 0;
+  uint8_t FillByteValue = 0;
+
+  GOFFSymbol() : EsdId(0), ParentEsdId(0) {}
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, const SDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(0),
+SymbolType(GOFF::ESD_ST_SectionDefinition) {
+BehavAttrs.setTaskingBehavior(Attr.TaskingBehavior);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const EDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_ElementDefinition) {
+this->NameSpace = Attr.NameSpace;
+// TODO Do we need/should set the "mangled" flag?
+SymbolFlags.setFillBytePresence(1);
+SymbolFlags.setReservedQwords(Attr.ReservedQwords);
+BehavAttrs.setReadOnly(Attr.IsReadOnly);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setRmode(Attr.Rmode);
+BehavAttrs.setTextStyle(Attr.TextStyle);
+BehavAttrs.setBindingAlgorithm(Attr.BindAlgorithm);
+BehavAttrs.setLoadingBehavior(Attr.LoadBehavior);
+BehavAttrs.setAlignment(Attr.Alignment);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const LDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_LabelDefinition) {
+this->NameSpace = Attr.NameSpace;
+SymbolFlags.setRenameable(Attr.IsRenamable);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setBindingStrength(Attr.BindingStrength);
+BehavAttrs.setLinkageType(Attr.Linkage);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const PRAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_PartReference) {
+this->NameSpace = Attr.NameSpace;
+SymbolFlags.setRenameable(Attr.IsRenamable);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setAlignment(Attr.Alignment);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setLinkageType(Attr.Linkage);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+BehavAttrs.setDuplicateSymbolSeverity(Attr.DuplicateSymbolSeverity);
+BehavAttrs.setReadOnly(Attr.IsReadOnly);
+  }
+};
+
 class GOFFWriter {
   GOFFOstream OS;
   [[maybe_unused]] MCAssembler &Asm;
 
+  /// Mapping from MCSectionGOFF/MCSymbolGOFF to GOFF symbols and attributes.
+  GOFFSymbolMapper SymbolMapper;
+
+  /// Counter for symbol id's.
+  uint32_t EsdIdCounter = 0;
+
+  /// Id's of some special symbols.
+  uint32_t RootSDEsdId = 0;
+  uint32_t ADAEsdId = 0;
+
   void writeHeader();
+  void writeSymbol(const GOFFSymbol &Symbol);
   void writeEnd();
 
+  GOFFSymbol createGOFFSymbol(StringRef Name, const SDAttr &Attr);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const EDAttr &Attr,
+  uint32_t ParentEsdId);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const LDAttr &Attr,
+  uint32_t ParentEsdId);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const PRAttr &Attr,
+  uint32_t ParentEsdId);
+
+  void defineRootSymbol(const MCSectionGOFF *Text);
+  void defineSectionSymbols(const MCSectionGOFF &Section);
+  void defineSymbols();
+
 public:
   GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm);
   uint64_t writeObject();
 };
 } // namespace
 
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
-: OS(OS), Asm(Asm) {}
+: OS(OS), Asm(Asm), SymbolMapper(Asm) {}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const SDAttr &Attr) {
+  return GOFFSymbol(Name, ++EsdIdCounter, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const EDAttr &Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const LDAttr &Attr,
+uint32_t Par

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

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

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/5] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits


@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;

redstar wrote:

Changed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits


@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,

redstar wrote:

Changed.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-05-08 Thread Kai Nacke via llvm-branch-commits

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



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-05-08 Thread Kai Nacke via llvm-branch-commits


@@ -571,7 +571,6 @@ void MCObjectFileInfo::initGOFFMCObjectFileInfo(const 
Triple &T) {
GOFF::ESD_LB_Initial, GOFF::ESD_RQ_0,
GOFF::ESD_ALIGN_Doubleword, 0},
   RootSDSection);
-

redstar wrote:

Fixed.

https://github.com/llvm/llvm-project/pull/137235
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of text records (PR #137235)

2025-05-09 Thread Kai Nacke via llvm-branch-commits


@@ -50,26 +53,26 @@ class MCSectionGOFF final : public MCSection {
   friend class MCContext;
   friend class MCSymbolGOFF;
 
-  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::SDAttr SDAttributes,
-MCSectionGOFF *Parent)
-  : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
+  MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual,

redstar wrote:

Exactly. The idea is to trigger the check in 
[MCAssembler::writeSectionData()](https://github.com/llvm/llvm-project/blob/main/llvm/lib/MC/MCAssembler.cpp#L796)
 for those sections which are not allowed to contain text.

https://github.com/llvm/llvm-project/pull/137235
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Emit symbols for functions. (PR #144437)

2025-06-17 Thread Kai Nacke via llvm-branch-commits

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

>From 2b99eb315cea3e75a6ecc49571d75d9371669116 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 16 Jun 2025 17:27:16 -0400
Subject: [PATCH 1/2] [GOFF] Emit symbols for functions.

A function entry is mapped to a LD symbol with an offset to the begin of the 
section.
---
 llvm/include/llvm/MC/MCGOFFStreamer.h  |  7 +--
 llvm/include/llvm/MC/MCSymbolGOFF.h| 19 ++-
 llvm/lib/MC/CMakeLists.txt |  1 +
 llvm/lib/MC/GOFFObjectWriter.cpp   |  1 +
 llvm/lib/MC/MCGOFFStreamer.cpp | 58 ++
 llvm/lib/MC/MCSymbolGOFF.cpp   | 38 ++
 llvm/test/CodeGen/SystemZ/zos-section-1.ll | 34 -
 7 files changed, 140 insertions(+), 18 deletions(-)
 create mode 100644 llvm/lib/MC/MCSymbolGOFF.cpp

diff --git a/llvm/include/llvm/MC/MCGOFFStreamer.h 
b/llvm/include/llvm/MC/MCGOFFStreamer.h
index 366d7dc08c679..968bef044d175 100644
--- a/llvm/include/llvm/MC/MCGOFFStreamer.h
+++ b/llvm/include/llvm/MC/MCGOFFStreamer.h
@@ -30,9 +30,10 @@ class MCGOFFStreamer : public MCObjectStreamer {
 
   GOFFObjectWriter &getWriter();
 
-  bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override {
-return false;
-  }
+  void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
+
+  bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
+
   void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
 Align ByteAlignment) override {}
   void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override {}
diff --git a/llvm/include/llvm/MC/MCSymbolGOFF.h 
b/llvm/include/llvm/MC/MCSymbolGOFF.h
index d8c570d2de240..b9295d3690803 100644
--- a/llvm/include/llvm/MC/MCSymbolGOFF.h
+++ b/llvm/include/llvm/MC/MCSymbolGOFF.h
@@ -28,7 +28,10 @@ class MCSymbolGOFF : public MCSymbol {
   GOFF::LDAttr LDAttributes;
 
   enum SymbolFlags : uint16_t {
-SF_LD = 0x01, // LD attributes are set.
+SF_LD = 0x01,   // LD attributes are set.
+// Leave place for EX attributes.
+SF_Hidden = 0x04,   // Symbol is hidden, aka not exported.
+SF_Weak = 0x08, // Symbol is weak.
   };
 
 public:
@@ -39,7 +42,8 @@ class MCSymbolGOFF : public MCSymbol {
 modifyFlags(SF_LD, SF_LD);
 LDAttributes = Attr;
   }
-  GOFF::LDAttr getLDAttributes() const { return LDAttributes; }
+  const GOFF::LDAttr &getLDAttributes() const { return LDAttributes; }
+  GOFF::LDAttr &getLDAttributes() { return LDAttributes; }
   bool hasLDAttributes() const { return getFlags() & SF_LD; }
 
   void setADA(MCSectionGOFF *AssociatedDataArea) {
@@ -48,6 +52,17 @@ class MCSymbolGOFF : public MCSymbol {
   }
   MCSectionGOFF *getADA() const { return ADA; }
 
+  void setHidden(bool Value = true) {
+modifyFlags(Value ? SF_Hidden : 0, SF_Hidden);
+  }
+  bool isHidden() const { return getFlags() & SF_Hidden; }
+  bool isExported() const { return !isHidden(); }
+
+  void setWeak(bool Value = true) { modifyFlags(Value ? SF_Weak : 0, SF_Weak); 
}
+  bool isWeak() const { return getFlags() & SF_Weak; }
+
+  void initAttributes();
+
   static bool classof(const MCSymbol *S) { return S->isGOFF(); }
 };
 } // end namespace llvm
diff --git a/llvm/lib/MC/CMakeLists.txt b/llvm/lib/MC/CMakeLists.txt
index d662c42c522fc..85e857d3fb406 100644
--- a/llvm/lib/MC/CMakeLists.txt
+++ b/llvm/lib/MC/CMakeLists.txt
@@ -55,6 +55,7 @@ add_llvm_component_library(LLVMMC
   MCSubtargetInfo.cpp
   MCSymbol.cpp
   MCSymbolELF.cpp
+  MCSymbolGOFF.cpp
   MCSymbolXCOFF.cpp
   MCTargetOptions.cpp
   MCTargetOptionsCommandFlags.cpp
diff --git a/llvm/lib/MC/GOFFObjectWriter.cpp b/llvm/lib/MC/GOFFObjectWriter.cpp
index 214533b99688e..c7fa2e99f6625 100644
--- a/llvm/lib/MC/GOFFObjectWriter.cpp
+++ b/llvm/lib/MC/GOFFObjectWriter.cpp
@@ -329,6 +329,7 @@ void GOFFWriter::defineLabel(const MCSymbolGOFF &Symbol) {
 Section.getEDAttributes().NameSpace, Symbol.getLDAttributes());
   if (Symbol.getADA())
 LD.ADAEsdId = Symbol.getADA()->getOrdinal();
+  LD.Offset = Asm.getSymbolOffset(Symbol);
   writeSymbol(LD);
 }
 
diff --git a/llvm/lib/MC/MCGOFFStreamer.cpp b/llvm/lib/MC/MCGOFFStreamer.cpp
index b7021915e7b70..451acf3b5d781 100644
--- a/llvm/lib/MC/MCGOFFStreamer.cpp
+++ b/llvm/lib/MC/MCGOFFStreamer.cpp
@@ -15,8 +15,11 @@
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCCodeEmitter.h"
 #include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCDirectives.h"
 #include "llvm/MC/MCGOFFObjectWriter.h"
+#include "llvm/MC/MCSymbolGOFF.h"
 #include "llvm/MC/TargetRegistry.h"
+#include "llvm/Support/Casting.h"
 
 using namespace llvm;
 
@@ -41,6 +44,61 @@ void MCGOFFStreamer::changeSection(MCSection *Section, 
uint32_t Subsection) {
   MCObjectStreamer::changeSection(Section, Subsection);
 }
 
+void MCGOFFStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
+  MCObjectStreamer::emitLabel(Symbol, Loc);
+  cast(Symbol)->initAt

  1   2   >