[llvm] r252271 - Simplify the alignment handling in FDE emission.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 19:02:51 PST 2015


Author: rafael
Date: Thu Nov  5 21:02:51 2015
New Revision: 252271

URL: http://llvm.org/viewvc/llvm-project?rev=252271&view=rev
Log:
Simplify the alignment handling in FDE emission.

Modified:
    llvm/trunk/lib/MC/MCDwarf.cpp

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=252271&r1=252270&r2=252271&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Thu Nov  5 21:02:51 2015
@@ -1015,7 +1015,8 @@ public:
                           unsigned personalityEncoding, const MCSymbol *lsda,
                           bool IsSignalFrame, unsigned lsdaEncoding,
                           bool IsSimple);
-  MCSymbol *EmitFDE(const MCSymbol &cieStart, const MCDwarfFrameInfo &frame);
+  void EmitFDE(const MCSymbol &cieStart, const MCDwarfFrameInfo &frame,
+               bool LastInSection);
   void EmitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
                            MCSymbol *BaseLabel);
   void EmitCFIInstruction(const MCCFIInstruction &Instr);
@@ -1368,8 +1369,9 @@ const MCSymbol &FrameEmitterImpl::EmitCI
   return *sectionStart;
 }
 
-MCSymbol *FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
-                                    const MCDwarfFrameInfo &frame) {
+void FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
+                               const MCDwarfFrameInfo &frame,
+                               bool LastInSection) {
   MCContext &context = Streamer.getContext();
   MCSymbol *fdeStart = context.createTempSymbol();
   MCSymbol *fdeEnd = context.createTempSymbol();
@@ -1426,9 +1428,13 @@ MCSymbol *FrameEmitterImpl::EmitFDE(cons
   EmitCFIInstructions(frame.Instructions, frame.Begin);
 
   // Padding
-  Streamer.EmitValueToAlignment(PCSize);
+  // The size of a .eh_frame section has to be a multiple of the alignment
+  // since a null CIE is interpreted as the end. Old systems overaligned
+  // .eh_frame, so we do too and account for it in the last FDE.
+  unsigned Align = LastInSection ? asmInfo->getPointerSize() : PCSize;
+  Streamer.EmitValueToAlignment(Align);
 
-  return fdeEnd;
+  Streamer.EmitLabel(fdeEnd);
 }
 
 namespace {
@@ -1519,22 +1525,19 @@ void MCDwarfFrameEmitter::Emit(MCObjectS
   Streamer.EmitLabel(SectionStart);
   Emitter.setSectionStart(SectionStart);
 
-  MCSymbol *FDEEnd = nullptr;
   DenseMap<CIEKey, const MCSymbol *> CIEStarts;
 
   const MCSymbol *DummyDebugKey = nullptr;
   bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
-  for (const MCDwarfFrameInfo &Frame : FrameArray) {
+  for (auto I = FrameArray.begin(), E = FrameArray.end(); I != E;) {
+    const MCDwarfFrameInfo &Frame = *I;
+    ++I;
     if (CanOmitDwarf && Frame.CompactUnwindEncoding !=
           MOFI->getCompactUnwindDwarfEHFrameOnly())
       // Don't generate an EH frame if we don't need one. I.e., it's taken care
       // of by the compact unwind encoding.
       continue;
 
-    // Close the previous FDE.
-    if (FDEEnd)
-      Streamer.EmitLabel(FDEEnd);
-
     CIEKey Key(Frame.Personality, Frame.PersonalityEncoding,
                Frame.LsdaEncoding, Frame.IsSignalFrame, Frame.IsSimple);
     const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey;
@@ -1543,12 +1546,8 @@ void MCDwarfFrameEmitter::Emit(MCObjectS
                                   Frame.Lsda, Frame.IsSignalFrame,
                                   Frame.LsdaEncoding, Frame.IsSimple);
 
-    FDEEnd = Emitter.EmitFDE(*CIEStart, Frame);
+    Emitter.EmitFDE(*CIEStart, Frame, I == E);
   }
-
-  Streamer.EmitValueToAlignment(Context.getAsmInfo()->getPointerSize());
-  if (FDEEnd)
-    Streamer.EmitLabel(FDEEnd);
 }
 
 void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,




More information about the llvm-commits mailing list