summaryrefslogtreecommitdiffstats
path: root/recipes-devtools/clang/clang/0004-llvm-Fix-inconsistent-uses-of-.cfi_sections.patch
blob: c77a8d256897cad020519f297a31d5970e20dafd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
From 260b42499a218f18730b946f053890cc1641e4c3 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sun, 7 Aug 2016 22:48:44 -0700
Subject: [PATCH 4/5] llvm:  Fix inconsistent uses of .cfi_sections

Error: inconsistent uses of .cfi_sections

From the 2.27 binutils assemblers. It seems that 2.27 doesn't like the

.cfi_sections .debug_frame

directive following previous .cfi directives. The assemblers seem to be happy if the .cfi_sections directive precedes any other .cfi directive. Is this a bug in binutils or LLVM? It looks as if a fix might be to move the generation of the .cfi_sections directive from endModule() to somewhere else (maybe a non-existant beginModule()?).

As a work-around I modified DwarfCFIException.cpp and ARMException.cpp to send the .cfi_sections directive before the first function is processed. Seems to work.

-Rich

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 lib/CodeGen/AsmPrinter/ARMException.cpp      | 10 +++++++++-
 lib/CodeGen/AsmPrinter/DwarfCFIException.cpp | 11 ++++++++++-
 lib/CodeGen/AsmPrinter/DwarfException.h      |  4 ++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lib/CodeGen/AsmPrinter/ARMException.cpp b/lib/CodeGen/AsmPrinter/ARMException.cpp
index 5294c98..8295326 100644
--- a/lib/CodeGen/AsmPrinter/ARMException.cpp
+++ b/lib/CodeGen/AsmPrinter/ARMException.cpp
@@ -34,7 +34,8 @@
 #include "llvm/Target/TargetRegisterInfo.h"
 using namespace llvm;
 
-ARMException::ARMException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {}
+ARMException::ARMException(AsmPrinter *A)
+    : DwarfCFIExceptionBase(A) {}
 
 ARMException::~ARMException() {}
 
@@ -46,8 +47,10 @@ ARMTargetStreamer &ARMException::getTargetStreamer() {
 /// endModule - Emit all exception information that should come after the
 /// content.
 void ARMException::endModule() {
+#if RICH
   if (shouldEmitCFI)
     Asm->OutStreamer->EmitCFISections(false, true);
+#endif
 }
 
 void ARMException::beginFunction(const MachineFunction *MF) {
@@ -59,6 +62,11 @@ void ARMException::beginFunction(const MachineFunction *MF) {
          "non-EH CFI not yet supported in prologue with EHABI lowering");
   if (MoveType == AsmPrinter::CFI_M_Debug) {
     shouldEmitCFI = true;
+    // RICH:
+    if (cfiSectionsNeeded) {
+      Asm->OutStreamer->EmitCFISections(false, true);
+      cfiSectionsNeeded = false;
+    }
     Asm->OutStreamer->EmitCFIStartProc(false);
   }
 }
diff --git a/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp b/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
index 2eae1b2..af4c081 100644
--- a/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
@@ -39,7 +39,7 @@
 using namespace llvm;
 
 DwarfCFIExceptionBase::DwarfCFIExceptionBase(AsmPrinter *A)
-    : EHStreamer(A), shouldEmitCFI(false) {}
+    : EHStreamer(A), shouldEmitCFI(false), cfiSectionsNeeded(true) {}
 
 void DwarfCFIExceptionBase::markFunctionEnd() {
   endFragment();
@@ -70,8 +70,10 @@ void DwarfCFIException::endModule() {
   if (!Asm->MAI->usesCFIForEH())
     return;
 
+#if RICH
   if (moveTypeModule == AsmPrinter::CFI_M_Debug)
     Asm->OutStreamer->EmitCFISections(false, true);
+#endif
 
   const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
 
@@ -97,6 +99,13 @@ void DwarfCFIException::beginFunction(const MachineFunction *MF) {
   shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false;
   const Function *F = MF->getFunction();
 
+  // RICH: SjLj uses this pass and it doesn't need this info.
+  if (cfiSectionsNeeded && Asm->MAI->usesCFIForEH()) {
+    if (moveTypeModule == AsmPrinter::CFI_M_Debug)
+      Asm->OutStreamer->EmitCFISections(false, true);
+  }
+  cfiSectionsNeeded = false;
+
   // If any landing pads survive, we need an EH table.
   bool hasLandingPads = !MMI->getLandingPads().empty();
 
diff --git a/lib/CodeGen/AsmPrinter/DwarfException.h b/lib/CodeGen/AsmPrinter/DwarfException.h
index 8287f28..f150f4e 100644
--- a/lib/CodeGen/AsmPrinter/DwarfException.h
+++ b/lib/CodeGen/AsmPrinter/DwarfException.h
@@ -29,6 +29,9 @@ protected:
   /// Per-function flag to indicate if frame CFI info should be emitted.
   bool shouldEmitCFI;
 
+  /// Cleared if the .cfi_sections directive has been output.
+  bool cfiSectionsNeeded;
+
   void markFunctionEnd() override;
   void endFragment() override;
 };
@@ -46,6 +49,7 @@ class LLVM_LIBRARY_VISIBILITY DwarfCFIException : public DwarfCFIExceptionBase {
   /// Per-function flag to indicate if frame moves info should be emitted.
   bool shouldEmitMoves;
 
+
   AsmPrinter::CFIMoveType moveTypeModule;
 
 public:
-- 
2.9.2