[llvm] [XCOFF] Ensure .file is emitted before any .info pseudo-ops (PR #71577)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 11:27:29 PST 2023


https://github.com/stephenpeckham updated https://github.com/llvm/llvm-project/pull/71577

>From 42c2fbf9af85406c453a3db3ecf328a42605fd76 Mon Sep 17 00:00:00 2001
From: Stephen Peckham <speckham at us.ibm.com>
Date: Tue, 7 Nov 2023 14:17:00 -0500
Subject: [PATCH 1/2] [XCOFF] Ensure .file is emitted before any .info
 pseudo-ops

---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp     | 12 ++++++++++--
 llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll    |  4 ++--
 llvm/test/DebugInfo/XCOFF/empty.ll             |  8 ++++----
 llvm/test/DebugInfo/XCOFF/explicit-section.ll  |  4 ++--
 llvm/test/DebugInfo/XCOFF/function-sections.ll |  4 ++--
 5 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 71bee8cce65126b..8637d0658c2c905 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -443,7 +443,12 @@ bool AsmPrinter::doInitialization(Module &M) {
   const_cast<TargetLoweringObjectFile &>(getObjFileLowering())
       .getModuleMetadata(M);
 
-  OutStreamer->initSections(false, *TM.getMCSubtargetInfo());
+  // On AIX, we delay emitting any section information until
+  // after emitting the .file pseudo-op.  This allows additional
+  // information (such as the embedded command line) to be associated
+  // with all sections in the object file rather than a single section.
+  if (!TM.getTargetTriple().isOSBinFormatXCOFF())
+    OutStreamer->initSections(false, *TM.getMCSubtargetInfo());
 
   // Emit the version-min deployment target directive if needed.
   //
@@ -489,8 +494,11 @@ bool AsmPrinter::doInitialization(Module &M) {
 
   // On AIX, emit bytes for llvm.commandline metadata after .file so that the
   // C_INFO symbol is preserved if any csect is kept by the linker.
-  if (TM.getTargetTriple().isOSBinFormatXCOFF())
+  if (TM.getTargetTriple().isOSBinFormatXCOFF()) {
     emitModuleCommandLines(M);
+    // Now we can generate section information
+    OutStreamer->initSections(false, *TM.getMCSubtargetInfo());
+  }
 
   GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
   assert(MI && "AsmPrinter didn't require GCModuleInfo?");
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
index 49135499386701d..e84f0b138d25bdd 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
@@ -45,8 +45,8 @@
 
 ; CHECK-NOT: .toc
 
-; CHECK:      .csect [PR],5
-; CHECK-NEXT:  .file
+; CHECK:  .file
+; CHECK-NEXT:      .csect [PR],5
 
 ; CHECK:      .csect .data[RW],5
 ; CHECK-NEXT: .globl  ivar
diff --git a/llvm/test/DebugInfo/XCOFF/empty.ll b/llvm/test/DebugInfo/XCOFF/empty.ll
index 3cb4be26cf04e26..90edc6a6224dd7e 100644
--- a/llvm/test/DebugInfo/XCOFF/empty.ll
+++ b/llvm/test/DebugInfo/XCOFF/empty.ll
@@ -35,8 +35,8 @@ entry:
 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
 !12 = !DILocation(line: 3, column: 3, scope: !8)
 
-; ASM32:               .csect [PR],5
-; ASM32-NEXT:          .file   "1.c"
+; ASM32:          .file   "1.c"
+; ASM32-NEXT:               .csect [PR],5
 ; ASM32-NEXT:          .globl  main[DS]                        # -- Begin function main
 ; ASM32-NEXT:          .globl  .main
 ; ASM32-NEXT:          .align  2
@@ -236,8 +236,8 @@ entry:
 ; ASM32-NEXT:          .byte   1
 ; ASM32-NEXT:  L..debug_line_end0:
 
-; ASM64:               .csect [PR],5
-; ASM64-NEXT:          .file   "1.c"
+; ASM64:          .file   "1.c"
+; ASM64-NEXT:               .csect [PR],5
 ; ASM64-NEXT:          .globl  main[DS]                        # -- Begin function main
 ; ASM64-NEXT:          .globl  .main
 ; ASM64-NEXT:          .align  2
diff --git a/llvm/test/DebugInfo/XCOFF/explicit-section.ll b/llvm/test/DebugInfo/XCOFF/explicit-section.ll
index 5008721795a4100..452c650c6f7f692 100644
--- a/llvm/test/DebugInfo/XCOFF/explicit-section.ll
+++ b/llvm/test/DebugInfo/XCOFF/explicit-section.ll
@@ -42,8 +42,8 @@ entry:
 !15 = !DILocation(line: 3, column: 10, scope: !14)
 !16 = !DILocation(line: 3, column: 3, scope: !14)
 
-; CHECK:               .csect [PR],5
-; CHECK-NEXT:          .file   "2.c"
+; CHECK:          .file   "2.c"
+; CHECK-NEXT:               .csect [PR],5
 ; CHECK-NEXT:          .globl  bar[DS]                         # -- Begin function bar
 ; CHECK-NEXT:          .globl  .bar
 ; CHECK-NEXT:          .align  2
diff --git a/llvm/test/DebugInfo/XCOFF/function-sections.ll b/llvm/test/DebugInfo/XCOFF/function-sections.ll
index 9f4f55623c7de8c..ef3100483e654a9 100644
--- a/llvm/test/DebugInfo/XCOFF/function-sections.ll
+++ b/llvm/test/DebugInfo/XCOFF/function-sections.ll
@@ -37,8 +37,8 @@ entry:
 !13 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 6, type: !9, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
 !14 = !DILocation(line: 8, column: 3, scope: !13)
 
-; CHECK:               .csect [PR],5
-; CHECK-NEXT:          .file   "1.c"
+; CHECK:          .file   "1.c"
+; CHECK-NEXT:               .csect [PR],5
 ; CHECK-NEXT:          .csect .foo[PR],5
 ; CHECK-NEXT:          .globl  foo[DS]                         # -- Begin function foo
 ; CHECK-NEXT:          .globl  .foo[PR]

>From 0f99ee569dc4d8020718dd67c9622e93ccf5915e Mon Sep 17 00:00:00 2001
From: Stephen Peckham <speckham at us.ibm.com>
Date: Wed, 8 Nov 2023 14:26:44 -0500
Subject: [PATCH 2/2] Fix alignment

---
 llvm/test/DebugInfo/XCOFF/empty.ll             | 8 ++++----
 llvm/test/DebugInfo/XCOFF/explicit-section.ll  | 4 ++--
 llvm/test/DebugInfo/XCOFF/function-sections.ll | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/llvm/test/DebugInfo/XCOFF/empty.ll b/llvm/test/DebugInfo/XCOFF/empty.ll
index 90edc6a6224dd7e..be7933485e31237 100644
--- a/llvm/test/DebugInfo/XCOFF/empty.ll
+++ b/llvm/test/DebugInfo/XCOFF/empty.ll
@@ -35,8 +35,8 @@ entry:
 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
 !12 = !DILocation(line: 3, column: 3, scope: !8)
 
-; ASM32:          .file   "1.c"
-; ASM32-NEXT:               .csect [PR],5
+; ASM32:               .file   "1.c"
+; ASM32-NEXT:          .csect [PR],5
 ; ASM32-NEXT:          .globl  main[DS]                        # -- Begin function main
 ; ASM32-NEXT:          .globl  .main
 ; ASM32-NEXT:          .align  2
@@ -236,8 +236,8 @@ entry:
 ; ASM32-NEXT:          .byte   1
 ; ASM32-NEXT:  L..debug_line_end0:
 
-; ASM64:          .file   "1.c"
-; ASM64-NEXT:               .csect [PR],5
+; ASM64:               .file   "1.c"
+; ASM64-NEXT:          .csect [PR],5
 ; ASM64-NEXT:          .globl  main[DS]                        # -- Begin function main
 ; ASM64-NEXT:          .globl  .main
 ; ASM64-NEXT:          .align  2
diff --git a/llvm/test/DebugInfo/XCOFF/explicit-section.ll b/llvm/test/DebugInfo/XCOFF/explicit-section.ll
index 452c650c6f7f692..88ca64e7eda1f7b 100644
--- a/llvm/test/DebugInfo/XCOFF/explicit-section.ll
+++ b/llvm/test/DebugInfo/XCOFF/explicit-section.ll
@@ -42,8 +42,8 @@ entry:
 !15 = !DILocation(line: 3, column: 10, scope: !14)
 !16 = !DILocation(line: 3, column: 3, scope: !14)
 
-; CHECK:          .file   "2.c"
-; CHECK-NEXT:               .csect [PR],5
+; CHECK:               .file   "2.c"
+; CHECK-NEXT:          .csect [PR],5
 ; CHECK-NEXT:          .globl  bar[DS]                         # -- Begin function bar
 ; CHECK-NEXT:          .globl  .bar
 ; CHECK-NEXT:          .align  2
diff --git a/llvm/test/DebugInfo/XCOFF/function-sections.ll b/llvm/test/DebugInfo/XCOFF/function-sections.ll
index ef3100483e654a9..9137c9b2585faa7 100644
--- a/llvm/test/DebugInfo/XCOFF/function-sections.ll
+++ b/llvm/test/DebugInfo/XCOFF/function-sections.ll
@@ -37,8 +37,8 @@ entry:
 !13 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 6, type: !9, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
 !14 = !DILocation(line: 8, column: 3, scope: !13)
 
-; CHECK:          .file   "1.c"
-; CHECK-NEXT:               .csect [PR],5
+; CHECK:               .file   "1.c"
+; CHECK-NEXT:          .csect [PR],5
 ; CHECK-NEXT:          .csect .foo[PR],5
 ; CHECK-NEXT:          .globl  foo[DS]                         # -- Begin function foo
 ; CHECK-NEXT:          .globl  .foo[PR]



More information about the llvm-commits mailing list