diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 71bee8cce6512..8637d0658c2c9 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(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(); 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 4913549938670..e84f0b138d25b 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 3cb4be26cf04e..be7933485e312 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 5008721795a41..88ca64e7eda1f 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 9f4f55623c7de..9137c9b2585fa 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]