Skip to content

Commit 1d1fede

Browse files
[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.
1 parent 5d6304f commit 1d1fede

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,12 @@ bool AsmPrinter::doInitialization(Module &M) {
443443
const_cast<TargetLoweringObjectFile &>(getObjFileLowering())
444444
.getModuleMetadata(M);
445445

446-
OutStreamer->initSections(false, *TM.getMCSubtargetInfo());
446+
// On AIX, we delay emitting any section information until
447+
// after emitting the .file pseudo-op. This allows additional
448+
// information (such as the embedded command line) to be associated
449+
// with all sections in the object file rather than a single section.
450+
if (!TM.getTargetTriple().isOSBinFormatXCOFF())
451+
OutStreamer->initSections(false, *TM.getMCSubtargetInfo());
447452

448453
// Emit the version-min deployment target directive if needed.
449454
//
@@ -489,8 +494,11 @@ bool AsmPrinter::doInitialization(Module &M) {
489494

490495
// On AIX, emit bytes for llvm.commandline metadata after .file so that the
491496
// C_INFO symbol is preserved if any csect is kept by the linker.
492-
if (TM.getTargetTriple().isOSBinFormatXCOFF())
497+
if (TM.getTargetTriple().isOSBinFormatXCOFF()) {
493498
emitModuleCommandLines(M);
499+
// Now we can generate section information
500+
OutStreamer->initSections(false, *TM.getMCSubtargetInfo());
501+
}
494502

495503
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
496504
assert(MI && "AsmPrinter didn't require GCModuleInfo?");

llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545

4646
; CHECK-NOT: .toc
4747

48-
; CHECK: .csect [PR],5
49-
; CHECK-NEXT: .file
48+
; CHECK: .file
49+
; CHECK-NEXT: .csect [PR],5
5050

5151
; CHECK: .csect .data[RW],5
5252
; CHECK-NEXT: .globl ivar

llvm/test/DebugInfo/XCOFF/empty.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ entry:
3535
!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
3636
!12 = !DILocation(line: 3, column: 3, scope: !8)
3737

38-
; ASM32: .csect [PR],5
39-
; ASM32-NEXT: .file "1.c"
38+
; ASM32: .file "1.c"
39+
; ASM32-NEXT: .csect [PR],5
4040
; ASM32-NEXT: .globl main[DS] # -- Begin function main
4141
; ASM32-NEXT: .globl .main
4242
; ASM32-NEXT: .align 2
@@ -236,8 +236,8 @@ entry:
236236
; ASM32-NEXT: .byte 1
237237
; ASM32-NEXT: L..debug_line_end0:
238238

239-
; ASM64: .csect [PR],5
240-
; ASM64-NEXT: .file "1.c"
239+
; ASM64: .file "1.c"
240+
; ASM64-NEXT: .csect [PR],5
241241
; ASM64-NEXT: .globl main[DS] # -- Begin function main
242242
; ASM64-NEXT: .globl .main
243243
; ASM64-NEXT: .align 2

llvm/test/DebugInfo/XCOFF/explicit-section.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ entry:
4242
!15 = !DILocation(line: 3, column: 10, scope: !14)
4343
!16 = !DILocation(line: 3, column: 3, scope: !14)
4444

45-
; CHECK: .csect [PR],5
46-
; CHECK-NEXT: .file "2.c"
45+
; CHECK: .file "2.c"
46+
; CHECK-NEXT: .csect [PR],5
4747
; CHECK-NEXT: .globl bar[DS] # -- Begin function bar
4848
; CHECK-NEXT: .globl .bar
4949
; CHECK-NEXT: .align 2

llvm/test/DebugInfo/XCOFF/function-sections.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ entry:
3737
!13 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 6, type: !9, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
3838
!14 = !DILocation(line: 8, column: 3, scope: !13)
3939

40-
; CHECK: .csect [PR],5
41-
; CHECK-NEXT: .file "1.c"
40+
; CHECK: .file "1.c"
41+
; CHECK-NEXT: .csect [PR],5
4242
; CHECK-NEXT: .csect .foo[PR],5
4343
; CHECK-NEXT: .globl foo[DS] # -- Begin function foo
4444
; CHECK-NEXT: .globl .foo[PR]

0 commit comments

Comments
 (0)