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

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 14:03:49 PST 2023


Author: stephenpeckham
Date: 2023-11-09T16:03:45-06:00
New Revision: 1d1fede493ad6a0e2f9a7b6677f7b77f7e3a00bb

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

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

When generating the assembly code for AIX/XCOFF, the .file pseudo-op
needs to be emitted first, before any csects are generated. Otherwise,
information such as the embedded command line will be associated with
part of the object file rather than the entire object file.

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
    llvm/test/DebugInfo/XCOFF/empty.ll
    llvm/test/DebugInfo/XCOFF/explicit-section.ll
    llvm/test/DebugInfo/XCOFF/function-sections.ll

Removed: 
    


################################################################################
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..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:               .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..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:               .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..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:               .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]


        


More information about the llvm-commits mailing list