Skip to content

Commit 9af2e4e

Browse files
committed
Emit .cfi_sections before the first .cfi_startproc
GNU as rejects input where .cfi_sections is used after .cfi_startproc, if the new section differs from the old. Adjust our output to always emit .cfi_sections before the first .cfi_startproc to minimize necessary code. Differential Revision: https://reviews.llvm.org/D28011 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290817 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 2c8e9c4 commit 9af2e4e

File tree

6 files changed

+100
-19
lines changed

6 files changed

+100
-19
lines changed

lib/CodeGen/AsmPrinter/ARMException.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,20 @@ ARMTargetStreamer &ARMException::getTargetStreamer() {
4343
return static_cast<ARMTargetStreamer &>(TS);
4444
}
4545

46-
/// endModule - Emit all exception information that should come after the
47-
/// content.
48-
void ARMException::endModule() {
49-
if (shouldEmitCFI)
50-
Asm->OutStreamer->EmitCFISections(false, true);
51-
}
52-
5346
void ARMException::beginFunction(const MachineFunction *MF) {
5447
if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
5548
getTargetStreamer().emitFnStart();
5649
// See if we need call frame info.
5750
AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
5851
assert(MoveType != AsmPrinter::CFI_M_EH &&
5952
"non-EH CFI not yet supported in prologue with EHABI lowering");
53+
6054
if (MoveType == AsmPrinter::CFI_M_Debug) {
55+
if (!hasEmittedCFISections) {
56+
Asm->OutStreamer->EmitCFISections(false, true);
57+
hasEmittedCFISections = true;
58+
}
59+
6160
shouldEmitCFI = true;
6261
Asm->OutStreamer->EmitCFIStartProc(false);
6362
}

lib/CodeGen/AsmPrinter/DwarfCFIException.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
using namespace llvm;
4040

4141
DwarfCFIExceptionBase::DwarfCFIExceptionBase(AsmPrinter *A)
42-
: EHStreamer(A), shouldEmitCFI(false) {}
42+
: EHStreamer(A), shouldEmitCFI(false), hasEmittedCFISections(false) {}
4343

4444
void DwarfCFIExceptionBase::markFunctionEnd() {
4545
endFragment();
@@ -59,7 +59,7 @@ void DwarfCFIExceptionBase::endFragment() {
5959
DwarfCFIException::DwarfCFIException(AsmPrinter *A)
6060
: DwarfCFIExceptionBase(A), shouldEmitPersonality(false),
6161
forceEmitPersonality(false), shouldEmitLSDA(false),
62-
shouldEmitMoves(false), moveTypeModule(AsmPrinter::CFI_M_None) {}
62+
shouldEmitMoves(false) {}
6363

6464
DwarfCFIException::~DwarfCFIException() {}
6565

@@ -70,9 +70,6 @@ void DwarfCFIException::endModule() {
7070
if (!Asm->MAI->usesCFIForEH())
7171
return;
7272

73-
if (moveTypeModule == AsmPrinter::CFI_M_Debug)
74-
Asm->OutStreamer->EmitCFISections(false, true);
75-
7673
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
7774

7875
unsigned PerEncoding = TLOF.getPersonalityEncoding();
@@ -102,10 +99,6 @@ void DwarfCFIException::beginFunction(const MachineFunction *MF) {
10299

103100
// See if we need frame move info.
104101
AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
105-
if (MoveType == AsmPrinter::CFI_M_EH ||
106-
(MoveType == AsmPrinter::CFI_M_Debug &&
107-
moveTypeModule == AsmPrinter::CFI_M_None))
108-
moveTypeModule = MoveType;
109102

110103
shouldEmitMoves = MoveType != AsmPrinter::CFI_M_None;
111104

@@ -143,6 +136,12 @@ void DwarfCFIException::beginFragment(const MachineBasicBlock *MBB,
143136
if (!shouldEmitCFI)
144137
return;
145138

139+
if (!hasEmittedCFISections) {
140+
if (Asm->needsCFIMoves() == AsmPrinter::CFI_M_Debug)
141+
Asm->OutStreamer->EmitCFISections(false, true);
142+
hasEmittedCFISections = true;
143+
}
144+
146145
Asm->OutStreamer->EmitCFIStartProc(/*IsSimple=*/false);
147146

148147
// Indicate personality routine, if any.

lib/CodeGen/AsmPrinter/DwarfException.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class LLVM_LIBRARY_VISIBILITY DwarfCFIExceptionBase : public EHStreamer {
2828

2929
/// Per-function flag to indicate if frame CFI info should be emitted.
3030
bool shouldEmitCFI;
31+
/// Per-module flag to indicate if .cfi_section has beeen emitted.
32+
bool hasEmittedCFISections;
3133

3234
void markFunctionEnd() override;
3335
void endFragment() override;
@@ -46,8 +48,6 @@ class LLVM_LIBRARY_VISIBILITY DwarfCFIException : public DwarfCFIExceptionBase {
4648
/// Per-function flag to indicate if frame moves info should be emitted.
4749
bool shouldEmitMoves;
4850

49-
AsmPrinter::CFIMoveType moveTypeModule;
50-
5151
public:
5252
//===--------------------------------------------------------------------===//
5353
// Main entry points.
@@ -81,7 +81,7 @@ class LLVM_LIBRARY_VISIBILITY ARMException : public DwarfCFIExceptionBase {
8181
~ARMException() override;
8282

8383
/// Emit all exception information that should come after the content.
84-
void endModule() override;
84+
void endModule() override {}
8585

8686
/// Gather pre-function exception information. Assumes being emitted
8787
/// immediately after the function entry point.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc < %s | FileCheck %s
2+
; RUN: llc -mtriple=arm-netbsd-eabi < %s | FileCheck %s
3+
; CHECK-NOT: .cfi_startproc
4+
; CHECK: .cfi_sections .debug_frame
5+
; CHECK: .cfi_startproc
6+
7+
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
8+
target triple = "armv4t--linux"
9+
10+
; Function Attrs: nounwind
11+
define arm_aapcscc void @f() #0 !dbg !7 {
12+
entry:
13+
ret void, !dbg !10
14+
}
15+
16+
attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="arm7tdmi" "target-features"="+soft-float,+strict-align,-crypto,-neon" "unsafe-fp-math"="false" "use-soft-float"="true" }
17+
18+
!llvm.dbg.cu = !{!0}
19+
!llvm.module.flags = !{!3, !4, !5, !6}
20+
21+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 (trunk 290216)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
22+
!1 = !DIFile(filename: "test.c", directory: "/tmp")
23+
!2 = !{}
24+
!3 = !{i32 2, !"Dwarf Version", i32 4}
25+
!4 = !{i32 2, !"Debug Info Version", i32 3}
26+
!5 = !{i32 1, !"wchar_size", i32 4}
27+
!6 = !{i32 1, !"min_enum_size", i32 4}
28+
!7 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
29+
!8 = !DISubroutineType(types: !9)
30+
!9 = !{null}
31+
!10 = !DILocation(line: 1, column: 1, scope: !7)

test/CodeGen/ARM/no-cfi.ll

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: llc < %s | FileCheck %s
2+
; RUN: llc -mtriple=arm-netbsd-eabi < %s | FileCheck %s
3+
; CHECK-NOT: .cfi_startproc
4+
; CHECK-NOT: .cfi_sections
5+
6+
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
7+
target triple = "armv4t--linux"
8+
9+
@f = common global i32 0, align 4, !dbg !0
10+
11+
!llvm.dbg.cu = !{!2}
12+
!llvm.module.flags = !{!7, !8, !9, !10}
13+
14+
!0 = !DIGlobalVariableExpression(var: !1)
15+
!1 = distinct !DIGlobalVariable(name: "f", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
16+
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0 (trunk 290216)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
17+
!3 = !DIFile(filename: "test2.c", directory: "/tmp")
18+
!4 = !{}
19+
!5 = !{!0}
20+
!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
21+
!7 = !{i32 2, !"Dwarf Version", i32 4}
22+
!8 = !{i32 2, !"Debug Info Version", i32 3}
23+
!9 = !{i32 1, !"wchar_size", i32 4}
24+
!10 = !{i32 1, !"min_enum_size", i32 4}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llc < %s | FileCheck %s
2+
; CHECK-NOT: .cfi_startproc
3+
; CHECK: .cfi_sections .debug_frame
4+
; CHECK: .cfi_startproc
5+
6+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7+
target triple = "x86_64-unknown-linux-gnu"
8+
9+
; Function Attrs: nounwind
10+
define void @f() #0 !dbg !5 {
11+
entry:
12+
ret void, !dbg !8
13+
}
14+
15+
attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
16+
17+
!llvm.dbg.cu = !{!0}
18+
!llvm.module.flags = !{!3, !4}
19+
20+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 (trunk 290216)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
21+
!1 = !DIFile(filename: "test.c", directory: "/tmp")
22+
!2 = !{}
23+
!3 = !{i32 2, !"Dwarf Version", i32 4}
24+
!4 = !{i32 2, !"Debug Info Version", i32 3}
25+
!5 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
26+
!6 = !DISubroutineType(types: !7)
27+
!7 = !{null}
28+
!8 = !DILocation(line: 1, column: 1, scope: !5)

0 commit comments

Comments
 (0)