Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 1 | //===-- CodeGen/AsmPrinter/DwarfException.cpp - Dwarf Exception Impl ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 10 | // This file contains support for writing DWARF exception info into asm files. |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "DwarfException.h" |
| 15 | #include "llvm/Module.h" |
Chris Lattner | 6d73378 | 2010-04-05 05:28:23 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/AsmPrinter.h" |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineModuleInfo.h" |
| 18 | #include "llvm/CodeGen/MachineFrameInfo.h" |
David Greene | fc4da0c | 2009-08-19 21:55:33 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFunction.h" |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineLocation.h" |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCAsmInfo.h" |
| 22 | #include "llvm/MC/MCContext.h" |
| 23 | #include "llvm/MC/MCExpr.h" |
Bill Wendling | 43e484f | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCSection.h" |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 7a2ba94 | 2010-01-16 18:37:32 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | 45111d1 | 2010-01-16 21:57:06 +0000 | [diff] [blame] | 27 | #include "llvm/Target/Mangler.h" |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetData.h" |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetFrameLowering.h" |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 30 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chris Lattner | 9d1c1ad | 2010-04-04 18:06:11 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetMachine.h" |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 32 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 33 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | 6c2f9e1 | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Dwarf.h" |
Chris Lattner | 0ad9c91 | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 35 | #include "llvm/Support/FormattedStream.h" |
Jim Grosbach | c40d9f9 | 2009-09-01 18:49:12 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/SmallString.h" |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/StringExtras.h" |
Bill Wendling | 1f8075d | 2010-02-09 22:49:16 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/Twine.h" |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 39 | using namespace llvm; |
| 40 | |
Chris Lattner | 75f5072 | 2010-04-04 07:48:20 +0000 | [diff] [blame] | 41 | DwarfException::DwarfException(AsmPrinter *A) |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 42 | : Asm(A), MMI(Asm->MMI), shouldEmitTable(false), shouldEmitMoves(false), |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 43 | shouldEmitTableModule(false), shouldEmitMovesModule(false) {} |
Bill Wendling | bc0d23a | 2009-05-15 01:18:50 +0000 | [diff] [blame] | 44 | |
Bill Wendling | 5f017e8 | 2010-04-07 09:28:04 +0000 | [diff] [blame] | 45 | DwarfException::~DwarfException() {} |
Bill Wendling | bc0d23a | 2009-05-15 01:18:50 +0000 | [diff] [blame] | 46 | |
Bill Wendling | 7ccda0f | 2009-08-25 08:08:33 +0000 | [diff] [blame] | 47 | /// EmitCIE - Emit a Common Information Entry (CIE). This holds information that |
| 48 | /// is shared among many Frame Description Entries. There is at least one CIE |
| 49 | /// in every non-empty .debug_frame section. |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 50 | void DwarfException::EmitCIE(const Function *PersonalityFn, unsigned Index) { |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 51 | // Size and sign of stack growth. |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 52 | int stackGrowth = Asm->getTargetData().getPointerSize(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 53 | if (Asm->TM.getFrameLowering()->getStackGrowthDirection() == |
| 54 | TargetFrameLowering::StackGrowsDown) |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 55 | stackGrowth *= -1; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 56 | |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 57 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 58 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 59 | // Begin eh frame section. |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 60 | Asm->OutStreamer.SwitchSection(TLOF.getEHFrameSection()); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 61 | |
Chris Lattner | 974c0fb | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 62 | MCSymbol *EHFrameSym; |
Chris Lattner | 09d53fe | 2010-03-10 07:20:42 +0000 | [diff] [blame] | 63 | if (TLOF.isFunctionEHFrameSymbolPrivate()) |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 64 | EHFrameSym = Asm->GetTempSymbol("EH_frame", Index); |
Chris Lattner | 974c0fb | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 65 | else |
| 66 | EHFrameSym = Asm->OutContext.GetOrCreateSymbol(Twine("EH_frame") + |
| 67 | Twine(Index)); |
| 68 | Asm->OutStreamer.EmitLabel(EHFrameSym); |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 69 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 70 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_eh_frame", Index)); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 71 | |
| 72 | // Define base labels. |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 73 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_frame_common", Index)); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 74 | |
| 75 | // Define the eh frame length. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 76 | Asm->OutStreamer.AddComment("Length of Common Information Entry"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 77 | Asm->EmitLabelDifference(Asm->GetTempSymbol("eh_frame_common_end", Index), |
| 78 | Asm->GetTempSymbol("eh_frame_common_begin", Index), |
| 79 | 4); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 80 | |
| 81 | // EH frame header. |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 82 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_frame_common_begin",Index)); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 83 | Asm->OutStreamer.AddComment("CIE Identifier Tag"); |
Chris Lattner | bcb83e5 | 2010-01-20 07:41:15 +0000 | [diff] [blame] | 84 | Asm->OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 85 | Asm->OutStreamer.AddComment("DW_CIE_VERSION"); |
Chris Lattner | 066c9ac | 2010-01-22 22:23:57 +0000 | [diff] [blame] | 86 | Asm->OutStreamer.EmitIntValue(dwarf::DW_CIE_VERSION, 1/*size*/, 0/*addr*/); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 87 | |
| 88 | // The personality presence indicates that language specific information will |
Chris Lattner | 8c6ed05 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 89 | // show up in the eh frame. Find out how we are supposed to lower the |
| 90 | // personality function reference: |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 91 | |
| 92 | unsigned LSDAEncoding = TLOF.getLSDAEncoding(); |
| 93 | unsigned FDEEncoding = TLOF.getFDEEncoding(); |
| 94 | unsigned PerEncoding = TLOF.getPersonalityEncoding(); |
Bill Wendling | 52783c6 | 2009-09-09 23:56:55 +0000 | [diff] [blame] | 95 | |
Chris Lattner | 4cf202b | 2010-01-23 03:11:46 +0000 | [diff] [blame] | 96 | char Augmentation[6] = { 0 }; |
Bill Wendling | 52783c6 | 2009-09-09 23:56:55 +0000 | [diff] [blame] | 97 | unsigned AugmentationSize = 0; |
| 98 | char *APtr = Augmentation + 1; |
| 99 | |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 100 | if (PersonalityFn) { |
Bill Wendling | 52783c6 | 2009-09-09 23:56:55 +0000 | [diff] [blame] | 101 | // There is a personality function. |
| 102 | *APtr++ = 'P'; |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 103 | AugmentationSize += 1 + Asm->GetSizeOfEncodedValue(PerEncoding); |
Bill Wendling | 52783c6 | 2009-09-09 23:56:55 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | if (UsesLSDA[Index]) { |
| 107 | // An LSDA pointer is in the FDE augmentation. |
| 108 | *APtr++ = 'L'; |
| 109 | ++AugmentationSize; |
| 110 | } |
| 111 | |
| 112 | if (FDEEncoding != dwarf::DW_EH_PE_absptr) { |
| 113 | // A non-default pointer encoding for the FDE. |
| 114 | *APtr++ = 'R'; |
| 115 | ++AugmentationSize; |
| 116 | } |
| 117 | |
| 118 | if (APtr != Augmentation + 1) |
| 119 | Augmentation[0] = 'z'; |
| 120 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 121 | Asm->OutStreamer.AddComment("CIE Augmentation"); |
Chris Lattner | 4cf202b | 2010-01-23 03:11:46 +0000 | [diff] [blame] | 122 | Asm->OutStreamer.EmitBytes(StringRef(Augmentation, strlen(Augmentation)+1),0); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 123 | |
| 124 | // Round out reader. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 125 | Asm->EmitULEB128(1, "CIE Code Alignment Factor"); |
| 126 | Asm->EmitSLEB128(stackGrowth, "CIE Data Alignment Factor"); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 127 | Asm->OutStreamer.AddComment("CIE Return Address Column"); |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 128 | |
| 129 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 130 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 131 | Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), true)); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 132 | |
Anton Korobeynikov | ac8a3d0 | 2010-02-15 22:36:41 +0000 | [diff] [blame] | 133 | if (Augmentation[0]) { |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 134 | Asm->EmitULEB128(AugmentationSize, "Augmentation Size"); |
Bill Wendling | 52783c6 | 2009-09-09 23:56:55 +0000 | [diff] [blame] | 135 | |
Anton Korobeynikov | ac8a3d0 | 2010-02-15 22:36:41 +0000 | [diff] [blame] | 136 | // If there is a personality, we need to indicate the function's location. |
| 137 | if (PersonalityFn) { |
Chris Lattner | ca6190b | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 138 | Asm->EmitEncodingByte(PerEncoding, "Personality"); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 139 | Asm->OutStreamer.AddComment("Personality"); |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 140 | Asm->EmitReference(PersonalityFn, PerEncoding); |
Anton Korobeynikov | ac8a3d0 | 2010-02-15 22:36:41 +0000 | [diff] [blame] | 141 | } |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 142 | if (UsesLSDA[Index]) |
Chris Lattner | ca6190b | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 143 | Asm->EmitEncodingByte(LSDAEncoding, "LSDA"); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 144 | if (FDEEncoding != dwarf::DW_EH_PE_absptr) |
Chris Lattner | ca6190b | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 145 | Asm->EmitEncodingByte(FDEEncoding, "FDE"); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // Indicate locations of general callee saved registers in frame. |
| 149 | std::vector<MachineMove> Moves; |
Anton Korobeynikov | d9e3385 | 2010-11-18 23:25:52 +0000 | [diff] [blame] | 150 | TFI->getInitialFrameState(Moves); |
Chris Lattner | 02b86b9 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 151 | Asm->EmitFrameMoves(Moves, 0, true); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 152 | |
| 153 | // On Darwin the linker honors the alignment of eh_frame, which means it must |
| 154 | // be 8-byte on 64-bit targets to match what gcc does. Otherwise you get |
| 155 | // holes which confuse readers of eh_frame. |
Chris Lattner | 059ea13 | 2010-04-28 01:05:45 +0000 | [diff] [blame] | 156 | Asm->EmitAlignment(Asm->getTargetData().getPointerSize() == 4 ? 2 : 3); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 157 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_frame_common_end", Index)); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Bill Wendling | 7ccda0f | 2009-08-25 08:08:33 +0000 | [diff] [blame] | 160 | /// EmitFDE - Emit the Frame Description Entry (FDE) for the function. |
| 161 | void DwarfException::EmitFDE(const FunctionEHFrameInfo &EHFrameInfo) { |
Eric Christopher | dbfcdb9 | 2009-08-28 22:33:43 +0000 | [diff] [blame] | 162 | assert(!EHFrameInfo.function->hasAvailableExternallyLinkage() && |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 163 | "Should not emit 'available externally' functions at all"); |
| 164 | |
Chris Lattner | 3e0f60b | 2009-07-17 21:00:50 +0000 | [diff] [blame] | 165 | const Function *TheFunc = EHFrameInfo.function; |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 166 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
Eric Christopher | dbfcdb9 | 2009-08-28 22:33:43 +0000 | [diff] [blame] | 167 | |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 168 | unsigned LSDAEncoding = TLOF.getLSDAEncoding(); |
| 169 | unsigned FDEEncoding = TLOF.getFDEEncoding(); |
| 170 | |
| 171 | Asm->OutStreamer.SwitchSection(TLOF.getEHFrameSection()); |
Eric Christopher | dbfcdb9 | 2009-08-28 22:33:43 +0000 | [diff] [blame] | 172 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 173 | // Externally visible entry into the functions eh frame info. If the |
| 174 | // corresponding function is static, this should not be externally visible. |
Chris Lattner | 09d53fe | 2010-03-10 07:20:42 +0000 | [diff] [blame] | 175 | if (!TheFunc->hasLocalLinkage() && TLOF.isFunctionEHSymbolGlobal()) |
| 176 | Asm->OutStreamer.EmitSymbolAttribute(EHFrameInfo.FunctionEHSym,MCSA_Global); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 177 | |
| 178 | // If corresponding function is weak definition, this should be too. |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 179 | if (TheFunc->isWeakForLinker() && Asm->MAI->getWeakDefDirective()) |
Chris Lattner | 974c0fb | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 180 | Asm->OutStreamer.EmitSymbolAttribute(EHFrameInfo.FunctionEHSym, |
| 181 | MCSA_WeakDefinition); |
Bill Wendling | ee161a6 | 2009-11-11 01:24:59 +0000 | [diff] [blame] | 182 | |
| 183 | // If corresponding function is hidden, this should be too. |
| 184 | if (TheFunc->hasHiddenVisibility()) |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 185 | if (MCSymbolAttr HiddenAttr = Asm->MAI->getHiddenVisibilityAttr()) |
Chris Lattner | 152a29b | 2010-01-23 06:53:23 +0000 | [diff] [blame] | 186 | Asm->OutStreamer.EmitSymbolAttribute(EHFrameInfo.FunctionEHSym, |
| 187 | HiddenAttr); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 188 | |
| 189 | // If there are no calls then you can't unwind. This may mean we can omit the |
| 190 | // EH Frame, but some environments do not handle weak absolute symbols. If |
| 191 | // UnwindTablesMandatory is set we cannot do this optimization; the unwind |
| 192 | // info is to be available for non-EH uses. |
Bill Wendling | b92187a | 2010-05-14 21:14:32 +0000 | [diff] [blame] | 193 | if (!EHFrameInfo.adjustsStack && !UnwindTablesMandatory && |
Chris Lattner | 3e0f60b | 2009-07-17 21:00:50 +0000 | [diff] [blame] | 194 | (!TheFunc->isWeakForLinker() || |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 195 | !Asm->MAI->getWeakDefDirective() || |
Chris Lattner | 09d53fe | 2010-03-10 07:20:42 +0000 | [diff] [blame] | 196 | TLOF.getSupportsWeakOmittedEHFrame())) { |
Chris Lattner | 974c0fb | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 197 | Asm->OutStreamer.EmitAssignment(EHFrameInfo.FunctionEHSym, |
| 198 | MCConstantExpr::Create(0, Asm->OutContext)); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 199 | // This name has no connection to the function, so it might get |
| 200 | // dead-stripped when the function is not, erroneously. Prohibit |
| 201 | // dead-stripping unconditionally. |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 202 | if (Asm->MAI->hasNoDeadStrip()) |
Chris Lattner | 3a9be0e | 2010-01-23 05:51:36 +0000 | [diff] [blame] | 203 | Asm->OutStreamer.EmitSymbolAttribute(EHFrameInfo.FunctionEHSym, |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 204 | MCSA_NoDeadStrip); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 205 | } else { |
Chris Lattner | 974c0fb | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 206 | Asm->OutStreamer.EmitLabel(EHFrameInfo.FunctionEHSym); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 207 | |
| 208 | // EH frame header. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 209 | Asm->OutStreamer.AddComment("Length of Frame Information Entry"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 210 | Asm->EmitLabelDifference( |
| 211 | Asm->GetTempSymbol("eh_frame_end", EHFrameInfo.Number), |
| 212 | Asm->GetTempSymbol("eh_frame_begin", EHFrameInfo.Number), 4); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 213 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 214 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_frame_begin", |
| 215 | EHFrameInfo.Number)); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 216 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 217 | Asm->OutStreamer.AddComment("FDE CIE offset"); |
Chris Lattner | f88dce1 | 2010-04-04 21:31:54 +0000 | [diff] [blame] | 218 | Asm->EmitLabelDifference( |
| 219 | Asm->GetTempSymbol("eh_frame_begin", EHFrameInfo.Number), |
| 220 | Asm->GetTempSymbol("eh_frame_common", |
| 221 | EHFrameInfo.PersonalityIndex), 4); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 222 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 223 | MCSymbol *EHFuncBeginSym = |
| 224 | Asm->GetTempSymbol("eh_func_begin", EHFrameInfo.Number); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 225 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 226 | Asm->OutStreamer.AddComment("FDE initial location"); |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 227 | Asm->EmitReference(EHFuncBeginSym, FDEEncoding); |
Chris Lattner | fb65807 | 2010-03-13 07:40:56 +0000 | [diff] [blame] | 228 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 229 | Asm->OutStreamer.AddComment("FDE address range"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 230 | Asm->EmitLabelDifference(Asm->GetTempSymbol("eh_func_end", |
| 231 | EHFrameInfo.Number), |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 232 | EHFuncBeginSym, |
| 233 | Asm->GetSizeOfEncodedValue(FDEEncoding)); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 234 | |
| 235 | // If there is a personality and landing pads then point to the language |
| 236 | // specific data area in the exception table. |
Eric Christopher | d44fff7 | 2009-08-26 21:30:49 +0000 | [diff] [blame] | 237 | if (MMI->getPersonalities()[0] != NULL) { |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 238 | unsigned Size = Asm->GetSizeOfEncodedValue(LSDAEncoding); |
Duncan Sands | c69d74a | 2009-08-31 16:45:16 +0000 | [diff] [blame] | 239 | |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 240 | Asm->EmitULEB128(Size, "Augmentation size"); |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 241 | Asm->OutStreamer.AddComment("Language Specific Data Area"); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 242 | if (EHFrameInfo.hasLandingPads) |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 243 | Asm->EmitReference(Asm->GetTempSymbol("exception", EHFrameInfo.Number), |
| 244 | LSDAEncoding); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 245 | else |
| 246 | Asm->OutStreamer.EmitIntValue(0, Size/*size*/, 0/*addrspace*/); |
Bill Wendling | d58e9cb | 2010-01-16 01:40:55 +0000 | [diff] [blame] | 247 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 248 | } else { |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 249 | Asm->EmitULEB128(0, "Augmentation size"); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // Indicate locations of function specific callee saved registers in frame. |
Chris Lattner | 02b86b9 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 253 | Asm->EmitFrameMoves(EHFrameInfo.Moves, EHFuncBeginSym, true); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 254 | |
| 255 | // On Darwin the linker honors the alignment of eh_frame, which means it |
| 256 | // must be 8-byte on 64-bit targets to match what gcc does. Otherwise you |
| 257 | // get holes which confuse readers of eh_frame. |
Chris Lattner | 059ea13 | 2010-04-28 01:05:45 +0000 | [diff] [blame] | 258 | Asm->EmitAlignment(Asm->getTargetData().getPointerSize() == 4 ? 2 : 3); |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 259 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_frame_end", |
| 260 | EHFrameInfo.Number)); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 261 | |
| 262 | // If the function is marked used, this table should be also. We cannot |
| 263 | // make the mark unconditional in this case, since retaining the table also |
| 264 | // retains the function in this case, and there is code around that depends |
| 265 | // on unused functions (calling undefined externals) being dead-stripped to |
| 266 | // link correctly. Yes, there really is. |
Chris Lattner | 401e10c | 2009-07-20 06:14:25 +0000 | [diff] [blame] | 267 | if (MMI->isUsedFunction(EHFrameInfo.function)) |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 268 | if (Asm->MAI->hasNoDeadStrip()) |
Chris Lattner | 3a9be0e | 2010-01-23 05:51:36 +0000 | [diff] [blame] | 269 | Asm->OutStreamer.EmitSymbolAttribute(EHFrameInfo.FunctionEHSym, |
Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 270 | MCSA_NoDeadStrip); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 271 | } |
Chris Lattner | 188a87d | 2010-03-10 01:04:13 +0000 | [diff] [blame] | 272 | Asm->OutStreamer.AddBlankLine(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 275 | /// SharedTypeIds - How many leading type ids two landing pads have in common. |
| 276 | unsigned DwarfException::SharedTypeIds(const LandingPadInfo *L, |
| 277 | const LandingPadInfo *R) { |
| 278 | const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds; |
| 279 | unsigned LSize = LIds.size(), RSize = RIds.size(); |
| 280 | unsigned MinSize = LSize < RSize ? LSize : RSize; |
| 281 | unsigned Count = 0; |
| 282 | |
| 283 | for (; Count != MinSize; ++Count) |
| 284 | if (LIds[Count] != RIds[Count]) |
| 285 | return Count; |
| 286 | |
| 287 | return Count; |
| 288 | } |
| 289 | |
| 290 | /// PadLT - Order landing pads lexicographically by type id. |
| 291 | bool DwarfException::PadLT(const LandingPadInfo *L, const LandingPadInfo *R) { |
| 292 | const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds; |
| 293 | unsigned LSize = LIds.size(), RSize = RIds.size(); |
| 294 | unsigned MinSize = LSize < RSize ? LSize : RSize; |
| 295 | |
| 296 | for (unsigned i = 0; i != MinSize; ++i) |
| 297 | if (LIds[i] != RIds[i]) |
| 298 | return LIds[i] < RIds[i]; |
| 299 | |
| 300 | return LSize < RSize; |
| 301 | } |
| 302 | |
Bill Wendling | d460962 | 2009-07-28 23:23:00 +0000 | [diff] [blame] | 303 | /// ComputeActionsTable - Compute the actions table and gather the first action |
| 304 | /// index for each landing pad site. |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 305 | unsigned DwarfException:: |
| 306 | ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*> &LandingPads, |
| 307 | SmallVectorImpl<ActionEntry> &Actions, |
| 308 | SmallVectorImpl<unsigned> &FirstActions) { |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 309 | |
| 310 | // The action table follows the call-site table in the LSDA. The individual |
| 311 | // records are of two types: |
| 312 | // |
| 313 | // * Catch clause |
| 314 | // * Exception specification |
| 315 | // |
| 316 | // The two record kinds have the same format, with only small differences. |
| 317 | // They are distinguished by the "switch value" field: Catch clauses |
| 318 | // (TypeInfos) have strictly positive switch values, and exception |
| 319 | // specifications (FilterIds) have strictly negative switch values. Value 0 |
| 320 | // indicates a catch-all clause. |
| 321 | // |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 322 | // Negative type IDs index into FilterIds. Positive type IDs index into |
| 323 | // TypeInfos. The value written for a positive type ID is just the type ID |
| 324 | // itself. For a negative type ID, however, the value written is the |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 325 | // (negative) byte offset of the corresponding FilterIds entry. The byte |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 326 | // offset is usually equal to the type ID (because the FilterIds entries are |
| 327 | // written using a variable width encoding, which outputs one byte per entry |
| 328 | // as long as the value written is not too large) but can differ. This kind |
| 329 | // of complication does not occur for positive type IDs because type infos are |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 330 | // output using a fixed width encoding. FilterOffsets[i] holds the byte |
| 331 | // offset corresponding to FilterIds[i]. |
Bill Wendling | 409914b | 2009-07-29 21:19:44 +0000 | [diff] [blame] | 332 | |
| 333 | const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 334 | SmallVector<int, 16> FilterOffsets; |
| 335 | FilterOffsets.reserve(FilterIds.size()); |
| 336 | int Offset = -1; |
Bill Wendling | 409914b | 2009-07-29 21:19:44 +0000 | [diff] [blame] | 337 | |
| 338 | for (std::vector<unsigned>::const_iterator |
| 339 | I = FilterIds.begin(), E = FilterIds.end(); I != E; ++I) { |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 340 | FilterOffsets.push_back(Offset); |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 341 | Offset -= MCAsmInfo::getULEB128Size(*I); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 344 | FirstActions.reserve(LandingPads.size()); |
| 345 | |
| 346 | int FirstAction = 0; |
| 347 | unsigned SizeActions = 0; |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 348 | const LandingPadInfo *PrevLPI = 0; |
Bill Wendling | 409914b | 2009-07-29 21:19:44 +0000 | [diff] [blame] | 349 | |
Bill Wendling | 5cff487 | 2009-07-28 23:44:43 +0000 | [diff] [blame] | 350 | for (SmallVectorImpl<const LandingPadInfo *>::const_iterator |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 351 | I = LandingPads.begin(), E = LandingPads.end(); I != E; ++I) { |
| 352 | const LandingPadInfo *LPI = *I; |
| 353 | const std::vector<int> &TypeIds = LPI->TypeIds; |
Chris Lattner | 9be4913 | 2010-04-04 20:10:41 +0000 | [diff] [blame] | 354 | unsigned NumShared = PrevLPI ? SharedTypeIds(LPI, PrevLPI) : 0; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 355 | unsigned SizeSiteActions = 0; |
| 356 | |
| 357 | if (NumShared < TypeIds.size()) { |
| 358 | unsigned SizeAction = 0; |
Bill Wendling | 0a9abcb | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 359 | unsigned PrevAction = (unsigned)-1; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 360 | |
| 361 | if (NumShared) { |
Chris Lattner | 9be4913 | 2010-04-04 20:10:41 +0000 | [diff] [blame] | 362 | unsigned SizePrevIds = PrevLPI->TypeIds.size(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 363 | assert(Actions.size()); |
Bill Wendling | 0a9abcb | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 364 | PrevAction = Actions.size() - 1; |
| 365 | SizeAction = |
| 366 | MCAsmInfo::getSLEB128Size(Actions[PrevAction].NextAction) + |
| 367 | MCAsmInfo::getSLEB128Size(Actions[PrevAction].ValueForTypeID); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 368 | |
| 369 | for (unsigned j = NumShared; j != SizePrevIds; ++j) { |
Bill Wendling | 0a9abcb | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 370 | assert(PrevAction != (unsigned)-1 && "PrevAction is invalid!"); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 371 | SizeAction -= |
Bill Wendling | 0a9abcb | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 372 | MCAsmInfo::getSLEB128Size(Actions[PrevAction].ValueForTypeID); |
| 373 | SizeAction += -Actions[PrevAction].NextAction; |
| 374 | PrevAction = Actions[PrevAction].Previous; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
| 378 | // Compute the actions. |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 379 | for (unsigned J = NumShared, M = TypeIds.size(); J != M; ++J) { |
| 380 | int TypeID = TypeIds[J]; |
| 381 | assert(-1 - TypeID < (int)FilterOffsets.size() && "Unknown filter id!"); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 382 | int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID; |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 383 | unsigned SizeTypeID = MCAsmInfo::getSLEB128Size(ValueForTypeID); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 384 | |
| 385 | int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0; |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 386 | SizeAction = SizeTypeID + MCAsmInfo::getSLEB128Size(NextAction); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 387 | SizeSiteActions += SizeAction; |
| 388 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 389 | ActionEntry Action = { ValueForTypeID, NextAction, PrevAction }; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 390 | Actions.push_back(Action); |
Bill Wendling | 0a9abcb | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 391 | PrevAction = Actions.size() - 1; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | // Record the first action of the landing pad site. |
| 395 | FirstAction = SizeActions + SizeSiteActions - SizeAction + 1; |
| 396 | } // else identical - re-use previous FirstAction |
| 397 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 398 | // Information used when created the call-site table. The action record |
| 399 | // field of the call site record is the offset of the first associated |
| 400 | // action record, relative to the start of the actions table. This value is |
Bill Wendling | 0a9abcb | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 401 | // biased by 1 (1 indicating the start of the actions table), and 0 |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 402 | // indicates that there are no actions. |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 403 | FirstActions.push_back(FirstAction); |
| 404 | |
| 405 | // Compute this sites contribution to size. |
| 406 | SizeActions += SizeSiteActions; |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 407 | |
| 408 | PrevLPI = LPI; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 411 | return SizeActions; |
| 412 | } |
| 413 | |
Bill Wendling | ed060dc | 2009-11-12 21:59:20 +0000 | [diff] [blame] | 414 | /// CallToNoUnwindFunction - Return `true' if this is a call to a function |
| 415 | /// marked `nounwind'. Return `false' otherwise. |
| 416 | bool DwarfException::CallToNoUnwindFunction(const MachineInstr *MI) { |
| 417 | assert(MI->getDesc().isCall() && "This should be a call instruction!"); |
| 418 | |
| 419 | bool MarkedNoUnwind = false; |
| 420 | bool SawFunc = false; |
| 421 | |
| 422 | for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) { |
| 423 | const MachineOperand &MO = MI->getOperand(I); |
| 424 | |
Chris Lattner | cfd3188 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 425 | if (!MO.isGlobal()) continue; |
| 426 | |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 427 | const Function *F = dyn_cast<Function>(MO.getGlobal()); |
Chris Lattner | cfd3188 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 428 | if (F == 0) continue; |
Bill Wendling | ecc260e | 2009-11-12 23:13:08 +0000 | [diff] [blame] | 429 | |
Chris Lattner | cfd3188 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 430 | if (SawFunc) { |
| 431 | // Be conservative. If we have more than one function operand for this |
| 432 | // call, then we can't make the assumption that it's the callee and |
| 433 | // not a parameter to the call. |
| 434 | // |
| 435 | // FIXME: Determine if there's a way to say that `F' is the callee or |
| 436 | // parameter. |
| 437 | MarkedNoUnwind = false; |
| 438 | break; |
Bill Wendling | ed060dc | 2009-11-12 21:59:20 +0000 | [diff] [blame] | 439 | } |
Chris Lattner | cfd3188 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 440 | |
| 441 | MarkedNoUnwind = F->doesNotThrow(); |
| 442 | SawFunc = true; |
Bill Wendling | ed060dc | 2009-11-12 21:59:20 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | return MarkedNoUnwind; |
| 446 | } |
| 447 | |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 448 | /// ComputeCallSiteTable - Compute the call-site table. The entry for an invoke |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 449 | /// has a try-range containing the call, a non-zero landing pad, and an |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 450 | /// appropriate action. The entry for an ordinary call has a try-range |
| 451 | /// containing the call and zero for the landing pad and the action. Calls |
| 452 | /// marked 'nounwind' have no entry and must not be contained in the try-range |
| 453 | /// of any entry - they form gaps in the table. Entries must be ordered by |
| 454 | /// try-range address. |
| 455 | void DwarfException:: |
| 456 | ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites, |
| 457 | const RangeMapType &PadMap, |
| 458 | const SmallVectorImpl<const LandingPadInfo *> &LandingPads, |
| 459 | const SmallVectorImpl<unsigned> &FirstActions) { |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 460 | // The end label of the previous invoke or nounwind try-range. |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 461 | MCSymbol *LastLabel = 0; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 462 | |
| 463 | // Whether there is a potentially throwing instruction (currently this means |
| 464 | // an ordinary call) between the end of the previous try-range and now. |
| 465 | bool SawPotentiallyThrowing = false; |
| 466 | |
Bill Wendling | 5cff487 | 2009-07-28 23:44:43 +0000 | [diff] [blame] | 467 | // Whether the last CallSite entry was for an invoke. |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 468 | bool PreviousIsInvoke = false; |
| 469 | |
| 470 | // Visit all instructions in order of address. |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 471 | for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 472 | I != E; ++I) { |
| 473 | for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end(); |
| 474 | MI != E; ++MI) { |
| 475 | if (!MI->isLabel()) { |
Bill Wendling | ed060dc | 2009-11-12 21:59:20 +0000 | [diff] [blame] | 476 | if (MI->getDesc().isCall()) |
| 477 | SawPotentiallyThrowing |= !CallToNoUnwindFunction(MI); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 478 | continue; |
| 479 | } |
| 480 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 481 | // End of the previous try-range? |
Chris Lattner | 0397ada | 2010-03-14 08:17:53 +0000 | [diff] [blame] | 482 | MCSymbol *BeginLabel = MI->getOperand(0).getMCSymbol(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 483 | if (BeginLabel == LastLabel) |
| 484 | SawPotentiallyThrowing = false; |
| 485 | |
| 486 | // Beginning of a new try-range? |
Jeffrey Yasskin | 81cf432 | 2009-11-10 01:02:17 +0000 | [diff] [blame] | 487 | RangeMapType::const_iterator L = PadMap.find(BeginLabel); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 488 | if (L == PadMap.end()) |
| 489 | // Nope, it was just some random label. |
| 490 | continue; |
| 491 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 492 | const PadRange &P = L->second; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 493 | const LandingPadInfo *LandingPad = LandingPads[P.PadIndex]; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 494 | assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] && |
| 495 | "Inconsistent landing pad map!"); |
| 496 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 497 | // For Dwarf exception handling (SjLj handling doesn't use this). If some |
| 498 | // instruction between the previous try-range and this one may throw, |
| 499 | // create a call-site entry with no landing pad for the region between the |
| 500 | // try-ranges. |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 501 | if (SawPotentiallyThrowing && |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 502 | Asm->MAI->getExceptionHandlingType() == ExceptionHandling::Dwarf) { |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 503 | CallSiteEntry Site = { LastLabel, BeginLabel, 0, 0 }; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 504 | CallSites.push_back(Site); |
| 505 | PreviousIsInvoke = false; |
| 506 | } |
| 507 | |
| 508 | LastLabel = LandingPad->EndLabels[P.RangeIndex]; |
| 509 | assert(BeginLabel && LastLabel && "Invalid landing pad!"); |
| 510 | |
Chris Lattner | cfd3188 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 511 | if (!LandingPad->LandingPadLabel) { |
| 512 | // Create a gap. |
| 513 | PreviousIsInvoke = false; |
| 514 | } else { |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 515 | // This try-range is for an invoke. |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 516 | CallSiteEntry Site = { |
| 517 | BeginLabel, |
| 518 | LastLabel, |
| 519 | LandingPad->LandingPadLabel, |
| 520 | FirstActions[P.PadIndex] |
| 521 | }; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 522 | |
Jim Grosbach | 33668c0 | 2009-09-01 17:19:13 +0000 | [diff] [blame] | 523 | // Try to merge with the previous call-site. SJLJ doesn't do this |
| 524 | if (PreviousIsInvoke && |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 525 | Asm->MAI->getExceptionHandlingType() == ExceptionHandling::Dwarf) { |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 526 | CallSiteEntry &Prev = CallSites.back(); |
| 527 | if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) { |
| 528 | // Extend the range of the previous entry. |
| 529 | Prev.EndLabel = Site.EndLabel; |
| 530 | continue; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | // Otherwise, create a new call-site. |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 535 | if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::Dwarf) |
Jim Grosbach | ca752c9 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 536 | CallSites.push_back(Site); |
| 537 | else { |
| 538 | // SjLj EH must maintain the call sites in the order assigned |
| 539 | // to them by the SjLjPrepare pass. |
| 540 | unsigned SiteNo = MMI->getCallSiteBeginLabel(BeginLabel); |
| 541 | if (CallSites.size() < SiteNo) |
| 542 | CallSites.resize(SiteNo); |
| 543 | CallSites[SiteNo - 1] = Site; |
| 544 | } |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 545 | PreviousIsInvoke = true; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | // If some instruction between the previous try-range and the end of the |
| 551 | // function may throw, create a call-site entry with no landing pad for the |
| 552 | // region following the try-range. |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 553 | if (SawPotentiallyThrowing && |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 554 | Asm->MAI->getExceptionHandlingType() == ExceptionHandling::Dwarf) { |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 555 | CallSiteEntry Site = { LastLabel, 0, 0, 0 }; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 556 | CallSites.push_back(Site); |
| 557 | } |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Bill Wendling | 0dafca9 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 560 | /// EmitExceptionTable - Emit landing pads and actions. |
| 561 | /// |
| 562 | /// The general organization of the table is complex, but the basic concepts are |
| 563 | /// easy. First there is a header which describes the location and organization |
| 564 | /// of the three components that follow. |
Eric Christopher | dbfcdb9 | 2009-08-28 22:33:43 +0000 | [diff] [blame] | 565 | /// |
Bill Wendling | 0dafca9 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 566 | /// 1. The landing pad site information describes the range of code covered by |
| 567 | /// the try. In our case it's an accumulation of the ranges covered by the |
| 568 | /// invokes in the try. There is also a reference to the landing pad that |
| 569 | /// handles the exception once processed. Finally an index into the actions |
| 570 | /// table. |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 571 | /// 2. The action table, in our case, is composed of pairs of type IDs and next |
Bill Wendling | 0dafca9 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 572 | /// action offset. Starting with the action index from the landing pad |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 573 | /// site, each type ID is checked for a match to the current exception. If |
Bill Wendling | 0dafca9 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 574 | /// it matches then the exception and type id are passed on to the landing |
| 575 | /// pad. Otherwise the next action is looked up. This chain is terminated |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 576 | /// with a next action of zero. If no type id is found then the frame is |
Bill Wendling | 0dafca9 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 577 | /// unwound and handling continues. |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 578 | /// 3. Type ID table contains references to all the C++ typeinfo for all |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 579 | /// catches in the function. This tables is reverse indexed base 1. |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 580 | void DwarfException::EmitExceptionTable() { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 581 | const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 582 | const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); |
| 583 | const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 584 | |
| 585 | // Sort the landing pads in order of their type ids. This is used to fold |
| 586 | // duplicate actions. |
| 587 | SmallVector<const LandingPadInfo *, 64> LandingPads; |
| 588 | LandingPads.reserve(PadInfos.size()); |
| 589 | |
| 590 | for (unsigned i = 0, N = PadInfos.size(); i != N; ++i) |
| 591 | LandingPads.push_back(&PadInfos[i]); |
| 592 | |
| 593 | std::sort(LandingPads.begin(), LandingPads.end(), PadLT); |
| 594 | |
| 595 | // Compute the actions table and gather the first action index for each |
| 596 | // landing pad site. |
| 597 | SmallVector<ActionEntry, 32> Actions; |
| 598 | SmallVector<unsigned, 64> FirstActions; |
Bill Wendling | 0a9abcb | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 599 | unsigned SizeActions=ComputeActionsTable(LandingPads, Actions, FirstActions); |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 600 | |
| 601 | // Invokes and nounwind calls have entries in PadMap (due to being bracketed |
| 602 | // by try-range labels when lowered). Ordinary calls do not, so appropriate |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 603 | // try-ranges for them need be deduced when using DWARF exception handling. |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 604 | RangeMapType PadMap; |
| 605 | for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) { |
| 606 | const LandingPadInfo *LandingPad = LandingPads[i]; |
| 607 | for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) { |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 608 | MCSymbol *BeginLabel = LandingPad->BeginLabels[j]; |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 609 | assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!"); |
| 610 | PadRange P = { i, j }; |
| 611 | PadMap[BeginLabel] = P; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | // Compute the call-site table. |
| 616 | SmallVector<CallSiteEntry, 64> CallSites; |
Jim Grosbach | 8b818d7 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 617 | ComputeCallSiteTable(CallSites, PadMap, LandingPads, FirstActions); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 618 | |
| 619 | // Final tallies. |
| 620 | |
| 621 | // Call sites. |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 622 | bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj; |
Bill Wendling | d1a5b37 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 623 | bool HaveTTData = IsSJLJ ? (!TypeInfos.empty() || !FilterIds.empty()) : true; |
Chris Lattner | 9be4913 | 2010-04-04 20:10:41 +0000 | [diff] [blame] | 624 | |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 625 | unsigned CallSiteTableLength; |
Bill Wendling | d1a5b37 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 626 | if (IsSJLJ) |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 627 | CallSiteTableLength = 0; |
Chris Lattner | 9be4913 | 2010-04-04 20:10:41 +0000 | [diff] [blame] | 628 | else { |
| 629 | unsigned SiteStartSize = 4; // dwarf::DW_EH_PE_udata4 |
| 630 | unsigned SiteLengthSize = 4; // dwarf::DW_EH_PE_udata4 |
| 631 | unsigned LandingPadSize = 4; // dwarf::DW_EH_PE_udata4 |
| 632 | CallSiteTableLength = |
| 633 | CallSites.size() * (SiteStartSize + SiteLengthSize + LandingPadSize); |
| 634 | } |
Bill Wendling | d1a5b37 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 635 | |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 636 | for (unsigned i = 0, e = CallSites.size(); i < e; ++i) { |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 637 | CallSiteTableLength += MCAsmInfo::getULEB128Size(CallSites[i].Action); |
Bill Wendling | d1a5b37 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 638 | if (IsSJLJ) |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 639 | CallSiteTableLength += MCAsmInfo::getULEB128Size(i); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 640 | } |
Bill Wendling | d1a5b37 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 641 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 642 | // Type infos. |
Chris Lattner | d5bbb07 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 643 | const MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection(); |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 644 | unsigned TTypeEncoding; |
Bill Wendling | a2f6449 | 2009-09-10 06:27:16 +0000 | [diff] [blame] | 645 | unsigned TypeFormatSize; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 646 | |
Bill Wendling | 43e484f | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 647 | if (!HaveTTData) { |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 648 | // For SjLj exceptions, if there is no TypeInfo, then we just explicitly say |
| 649 | // that we're omitting that bit. |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 650 | TTypeEncoding = dwarf::DW_EH_PE_omit; |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 651 | // dwarf::DW_EH_PE_absptr |
| 652 | TypeFormatSize = Asm->getTargetData().getPointerSize(); |
Chris Lattner | 81c9a06 | 2009-07-31 22:03:47 +0000 | [diff] [blame] | 653 | } else { |
Chris Lattner | ad88bc4 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 654 | // Okay, we have actual filters or typeinfos to emit. As such, we need to |
| 655 | // pick a type encoding for them. We're about to emit a list of pointers to |
| 656 | // typeinfo objects at the end of the LSDA. However, unless we're in static |
| 657 | // mode, this reference will require a relocation by the dynamic linker. |
Chris Lattner | 46b754c | 2009-07-31 22:18:14 +0000 | [diff] [blame] | 658 | // |
Chris Lattner | ad88bc4 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 659 | // Because of this, we have a couple of options: |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 660 | // |
Chris Lattner | ad88bc4 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 661 | // 1) If we are in -static mode, we can always use an absolute reference |
| 662 | // from the LSDA, because the static linker will resolve it. |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 663 | // |
Chris Lattner | ad88bc4 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 664 | // 2) Otherwise, if the LSDA section is writable, we can output the direct |
| 665 | // reference to the typeinfo and allow the dynamic linker to relocate |
| 666 | // it. Since it is in a writable section, the dynamic linker won't |
| 667 | // have a problem. |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 668 | // |
Chris Lattner | ad88bc4 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 669 | // 3) Finally, if we're in PIC mode and the LDSA section isn't writable, |
| 670 | // we need to use some form of indirection. For example, on Darwin, |
| 671 | // we can output a statically-relocatable reference to a dyld stub. The |
| 672 | // offset to the stub is constant, but the contents are in a section |
| 673 | // that is updated by the dynamic linker. This is easy enough, but we |
| 674 | // need to tell the personality function of the unwinder to indirect |
| 675 | // through the dyld stub. |
| 676 | // |
Bill Wendling | 43e484f | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 677 | // FIXME: When (3) is actually implemented, we'll have to emit the stubs |
Chris Lattner | ad88bc4 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 678 | // somewhere. This predicate should be moved to a shared location that is |
| 679 | // in target-independent code. |
| 680 | // |
Anton Korobeynikov | 9184b25 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 681 | TTypeEncoding = Asm->getObjFileLowering().getTTypeEncoding(); |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 682 | TypeFormatSize = Asm->GetSizeOfEncodedValue(TTypeEncoding); |
Bill Wendling | fe22028 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 683 | } |
Bill Wendling | 43e484f | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 684 | |
Bill Wendling | fe22028 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 685 | // Begin the exception table. |
| 686 | Asm->OutStreamer.SwitchSection(LSDASection); |
Chris Lattner | 059ea13 | 2010-04-28 01:05:45 +0000 | [diff] [blame] | 687 | Asm->EmitAlignment(2); |
Bill Wendling | 43e484f | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 688 | |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 689 | // Emit the LSDA. |
Chris Lattner | 974c0fb | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 690 | MCSymbol *GCCETSym = |
| 691 | Asm->OutContext.GetOrCreateSymbol(Twine("GCC_except_table")+ |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 692 | Twine(Asm->getFunctionNumber())); |
Chris Lattner | 974c0fb | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 693 | Asm->OutStreamer.EmitLabel(GCCETSym); |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 694 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("exception", |
| 695 | Asm->getFunctionNumber())); |
Bill Wendling | fe22028 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 696 | |
Chris Lattner | 974c0fb | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 697 | if (IsSJLJ) |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 698 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("_LSDA_", |
| 699 | Asm->getFunctionNumber())); |
Bill Wendling | fe22028 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 700 | |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 701 | // Emit the LSDA header. |
Chris Lattner | ca6190b | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 702 | Asm->EmitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart"); |
| 703 | Asm->EmitEncodingByte(TTypeEncoding, "@TType"); |
Bill Wendling | fe22028 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 704 | |
Bill Wendling | 3dc9b48 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 705 | // The type infos need to be aligned. GCC does this by inserting padding just |
| 706 | // before the type infos. However, this changes the size of the exception |
| 707 | // table, so you need to take this into account when you output the exception |
| 708 | // table size. However, the size is output using a variable length encoding. |
| 709 | // So by increasing the size by inserting padding, you may increase the number |
| 710 | // of bytes used for writing the size. If it increases, say by one byte, then |
| 711 | // you now need to output one less byte of padding to get the type infos |
| 712 | // aligned. However this decreases the size of the exception table. This |
| 713 | // changes the value you have to output for the exception table size. Due to |
| 714 | // the variable length encoding, the number of bytes used for writing the |
| 715 | // length may decrease. If so, you then have to increase the amount of |
| 716 | // padding. And so on. If you look carefully at the GCC code you will see that |
| 717 | // it indeed does this in a loop, going on and on until the values stabilize. |
| 718 | // We chose another solution: don't output padding inside the table like GCC |
| 719 | // does, instead output it before the table. |
| 720 | unsigned SizeTypes = TypeInfos.size() * TypeFormatSize; |
| 721 | unsigned CallSiteTableLengthSize = |
| 722 | MCAsmInfo::getULEB128Size(CallSiteTableLength); |
| 723 | unsigned TTypeBaseOffset = |
| 724 | sizeof(int8_t) + // Call site format |
| 725 | CallSiteTableLengthSize + // Call site table length size |
| 726 | CallSiteTableLength + // Call site table length |
| 727 | SizeActions + // Actions size |
| 728 | SizeTypes; |
| 729 | unsigned TTypeBaseOffsetSize = MCAsmInfo::getULEB128Size(TTypeBaseOffset); |
| 730 | unsigned TotalSize = |
| 731 | sizeof(int8_t) + // LPStart format |
| 732 | sizeof(int8_t) + // TType format |
| 733 | (HaveTTData ? TTypeBaseOffsetSize : 0) + // TType base offset size |
| 734 | TTypeBaseOffset; // TType base offset |
| 735 | unsigned SizeAlign = (4 - TotalSize) & 3; |
| 736 | |
Bill Wendling | 86f0d33 | 2010-02-25 23:52:44 +0000 | [diff] [blame] | 737 | if (HaveTTData) { |
Bill Wendling | 6507eca | 2010-02-26 21:31:01 +0000 | [diff] [blame] | 738 | // Account for any extra padding that will be added to the call site table |
Bill Wendling | f7e90ae | 2010-02-25 21:19:47 +0000 | [diff] [blame] | 739 | // length. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 740 | Asm->EmitULEB128(TTypeBaseOffset, "@TType base offset", SizeAlign); |
Bill Wendling | 1869ac8 | 2010-02-26 22:17:52 +0000 | [diff] [blame] | 741 | SizeAlign = 0; |
Bill Wendling | 86f0d33 | 2010-02-25 23:52:44 +0000 | [diff] [blame] | 742 | } |
Bill Wendling | b0d9c3e | 2009-07-28 22:23:45 +0000 | [diff] [blame] | 743 | |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 744 | // SjLj Exception handling |
Bill Wendling | d1a5b37 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 745 | if (IsSJLJ) { |
Chris Lattner | ca6190b | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 746 | Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); |
Bill Wendling | 1869ac8 | 2010-02-26 22:17:52 +0000 | [diff] [blame] | 747 | |
| 748 | // Add extra padding if it wasn't added to the TType base offset. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 749 | Asm->EmitULEB128(CallSiteTableLength, "Call site table length", SizeAlign); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 750 | |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 751 | // Emit the landing pad site information. |
Jim Grosbach | 8b818d7 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 752 | unsigned idx = 0; |
| 753 | for (SmallVectorImpl<CallSiteEntry>::const_iterator |
| 754 | I = CallSites.begin(), E = CallSites.end(); I != E; ++I, ++idx) { |
| 755 | const CallSiteEntry &S = *I; |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 756 | |
| 757 | // Offset of the landing pad, counted in 16-byte bundles relative to the |
| 758 | // @LPStart address. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 759 | Asm->EmitULEB128(idx, "Landing pad"); |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 760 | |
| 761 | // Offset of the first associated action record, relative to the start of |
| 762 | // the action table. This value is biased by 1 (1 indicates the start of |
| 763 | // the action table), and 0 indicates that there are no actions. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 764 | Asm->EmitULEB128(S.Action, "Action"); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 765 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 766 | } else { |
| 767 | // DWARF Exception handling |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 768 | assert(Asm->MAI->getExceptionHandlingType() == ExceptionHandling::Dwarf); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 769 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 770 | // The call-site table is a list of all call sites that may throw an |
| 771 | // exception (including C++ 'throw' statements) in the procedure |
| 772 | // fragment. It immediately follows the LSDA header. Each entry indicates, |
| 773 | // for a given call, the first corresponding action record and corresponding |
| 774 | // landing pad. |
| 775 | // |
| 776 | // The table begins with the number of bytes, stored as an LEB128 |
| 777 | // compressed, unsigned integer. The records immediately follow the record |
| 778 | // count. They are sorted in increasing call-site address. Each record |
| 779 | // indicates: |
| 780 | // |
| 781 | // * The position of the call-site. |
| 782 | // * The position of the landing pad. |
| 783 | // * The first action record for that call site. |
| 784 | // |
| 785 | // A missing entry in the call-site table indicates that a call is not |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 786 | // supposed to throw. |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 787 | |
| 788 | // Emit the landing pad call site table. |
Chris Lattner | ca6190b | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 789 | Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); |
Bill Wendling | 1869ac8 | 2010-02-26 22:17:52 +0000 | [diff] [blame] | 790 | |
| 791 | // Add extra padding if it wasn't added to the TType base offset. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 792 | Asm->EmitULEB128(CallSiteTableLength, "Call site table length", SizeAlign); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 793 | |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 794 | for (SmallVectorImpl<CallSiteEntry>::const_iterator |
| 795 | I = CallSites.begin(), E = CallSites.end(); I != E; ++I) { |
| 796 | const CallSiteEntry &S = *I; |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 797 | |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 798 | MCSymbol *EHFuncBeginSym = |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 799 | Asm->GetTempSymbol("eh_func_begin", Asm->getFunctionNumber()); |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 800 | |
| 801 | MCSymbol *BeginLabel = S.BeginLabel; |
| 802 | if (BeginLabel == 0) |
| 803 | BeginLabel = EHFuncBeginSym; |
| 804 | MCSymbol *EndLabel = S.EndLabel; |
| 805 | if (EndLabel == 0) |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 806 | EndLabel = Asm->GetTempSymbol("eh_func_end", Asm->getFunctionNumber()); |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 807 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 808 | // Offset of the call site relative to the previous call site, counted in |
| 809 | // number of 16-byte bundles. The first call site is counted relative to |
| 810 | // the start of the procedure fragment. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 811 | Asm->OutStreamer.AddComment("Region start"); |
Chris Lattner | f88dce1 | 2010-04-04 21:31:54 +0000 | [diff] [blame] | 812 | Asm->EmitLabelDifference(BeginLabel, EHFuncBeginSym, 4); |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 813 | |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 814 | Asm->OutStreamer.AddComment("Region length"); |
Chris Lattner | a643718 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 815 | Asm->EmitLabelDifference(EndLabel, BeginLabel, 4); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 816 | |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 817 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 818 | // Offset of the landing pad, counted in 16-byte bundles relative to the |
| 819 | // @LPStart address. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 820 | Asm->OutStreamer.AddComment("Landing pad"); |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 821 | if (!S.PadLabel) |
Chris Lattner | bcb83e5 | 2010-01-20 07:41:15 +0000 | [diff] [blame] | 822 | Asm->OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/); |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 823 | else |
Chris Lattner | f88dce1 | 2010-04-04 21:31:54 +0000 | [diff] [blame] | 824 | Asm->EmitLabelDifference(S.PadLabel, EHFuncBeginSym, 4); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 825 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 826 | // Offset of the first associated action record, relative to the start of |
| 827 | // the action table. This value is biased by 1 (1 indicates the start of |
| 828 | // the action table), and 0 indicates that there are no actions. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 829 | Asm->EmitULEB128(S.Action, "Action"); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 830 | } |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 833 | // Emit the Action Table. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 834 | if (Actions.size() != 0) { |
| 835 | Asm->OutStreamer.AddComment("-- Action Record Table --"); |
| 836 | Asm->OutStreamer.AddBlankLine(); |
| 837 | } |
| 838 | |
Bill Wendling | 5cff487 | 2009-07-28 23:44:43 +0000 | [diff] [blame] | 839 | for (SmallVectorImpl<ActionEntry>::const_iterator |
| 840 | I = Actions.begin(), E = Actions.end(); I != E; ++I) { |
| 841 | const ActionEntry &Action = *I; |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 842 | Asm->OutStreamer.AddComment("Action Record"); |
| 843 | Asm->OutStreamer.AddBlankLine(); |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 844 | |
| 845 | // Type Filter |
| 846 | // |
| 847 | // Used by the runtime to match the type of the thrown exception to the |
| 848 | // type of the catch clauses or the types in the exception specification. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 849 | Asm->EmitSLEB128(Action.ValueForTypeID, " TypeInfo index"); |
Bill Wendling | a583c55 | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 850 | |
| 851 | // Action Record |
| 852 | // |
| 853 | // Self-relative signed displacement in bytes of the next action record, |
| 854 | // or 0 if there is no next action record. |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 855 | Asm->EmitSLEB128(Action.NextAction, " Next action"); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Bill Wendling | 48dc29e | 2009-10-22 20:48:59 +0000 | [diff] [blame] | 858 | // Emit the Catch TypeInfos. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 859 | if (!TypeInfos.empty()) { |
| 860 | Asm->OutStreamer.AddComment("-- Catch TypeInfos --"); |
| 861 | Asm->OutStreamer.AddBlankLine(); |
| 862 | } |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 863 | for (std::vector<const GlobalVariable *>::const_reverse_iterator |
Bill Wendling | 01c6937 | 2009-11-19 00:09:14 +0000 | [diff] [blame] | 864 | I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) { |
Bill Wendling | fb7634f | 2009-11-19 19:21:09 +0000 | [diff] [blame] | 865 | const GlobalVariable *GV = *I; |
Bill Wendling | ec04458 | 2009-11-18 23:18:46 +0000 | [diff] [blame] | 866 | |
Chris Lattner | 90e4af7 | 2010-03-10 00:09:21 +0000 | [diff] [blame] | 867 | Asm->OutStreamer.AddComment("TypeInfo"); |
| 868 | if (GV) |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 869 | Asm->EmitReference(GV, TTypeEncoding); |
Chris Lattner | 90e4af7 | 2010-03-10 00:09:21 +0000 | [diff] [blame] | 870 | else |
Chris Lattner | d2af785 | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 871 | Asm->OutStreamer.EmitIntValue(0,Asm->GetSizeOfEncodedValue(TTypeEncoding), |
| 872 | 0); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Bill Wendling | 48dc29e | 2009-10-22 20:48:59 +0000 | [diff] [blame] | 875 | // Emit the Exception Specifications. |
Chris Lattner | 233f52b | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 876 | if (!FilterIds.empty()) { |
| 877 | Asm->OutStreamer.AddComment("-- Filter IDs --"); |
| 878 | Asm->OutStreamer.AddBlankLine(); |
| 879 | } |
Bill Wendling | 5cff487 | 2009-07-28 23:44:43 +0000 | [diff] [blame] | 880 | for (std::vector<unsigned>::const_iterator |
| 881 | I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) { |
| 882 | unsigned TypeID = *I; |
Chris Lattner | 7e1a8f8 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 883 | Asm->EmitULEB128(TypeID, TypeID != 0 ? "Exception specification" : 0); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Chris Lattner | 059ea13 | 2010-04-28 01:05:45 +0000 | [diff] [blame] | 886 | Asm->EmitAlignment(2); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 889 | /// EndModule - Emit all exception information that should come after the |
| 890 | /// content. |
| 891 | void DwarfException::EndModule() { |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 892 | if (Asm->MAI->getExceptionHandlingType() != ExceptionHandling::Dwarf) |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 893 | return; |
Bill Wendling | b4049fe | 2009-09-09 21:06:24 +0000 | [diff] [blame] | 894 | |
Bill Wendling | 52783c6 | 2009-09-09 23:56:55 +0000 | [diff] [blame] | 895 | if (!shouldEmitMovesModule && !shouldEmitTableModule) |
| 896 | return; |
| 897 | |
Bill Wendling | 57dba1c | 2010-08-01 01:34:21 +0000 | [diff] [blame] | 898 | const std::vector<const Function*> &Personalities = MMI->getPersonalities(); |
Bill Wendling | b4049fe | 2009-09-09 21:06:24 +0000 | [diff] [blame] | 899 | |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 900 | for (unsigned I = 0, E = Personalities.size(); I < E; ++I) |
| 901 | EmitCIE(Personalities[I], I); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 902 | |
Bill Wendling | 52783c6 | 2009-09-09 23:56:55 +0000 | [diff] [blame] | 903 | for (std::vector<FunctionEHFrameInfo>::iterator |
| 904 | I = EHFrames.begin(), E = EHFrames.end(); I != E; ++I) |
| 905 | EmitFDE(*I); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Bill Wendling | 28275fd | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 908 | /// BeginFunction - Gather pre-function exception information. Assumes it's |
| 909 | /// being emitted immediately after the function entry point. |
Chris Lattner | eec791a | 2010-01-26 23:18:02 +0000 | [diff] [blame] | 910 | void DwarfException::BeginFunction(const MachineFunction *MF) { |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 911 | shouldEmitTable = shouldEmitMoves = false; |
| 912 | |
Bill Wendling | 73c5a61 | 2009-09-10 18:28:06 +0000 | [diff] [blame] | 913 | // If any landing pads survive, we need an EH table. |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 914 | shouldEmitTable = !MMI->getLandingPads().empty(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 915 | |
Bill Wendling | 73c5a61 | 2009-09-10 18:28:06 +0000 | [diff] [blame] | 916 | // See if we need frame move info. |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 917 | shouldEmitMoves = |
| 918 | !Asm->MF->getFunction()->doesNotThrow() || UnwindTablesMandatory; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 919 | |
Bill Wendling | 73c5a61 | 2009-09-10 18:28:06 +0000 | [diff] [blame] | 920 | if (shouldEmitMoves || shouldEmitTable) |
| 921 | // Assumes in correct section after the entry point. |
Chris Lattner | c021572 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 922 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin", |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 923 | Asm->getFunctionNumber())); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 924 | |
| 925 | shouldEmitTableModule |= shouldEmitTable; |
| 926 | shouldEmitMovesModule |= shouldEmitMoves; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /// EndFunction - Gather and emit post-function exception information. |
| 930 | /// |
| 931 | void DwarfException::EndFunction() { |
Bill Wendling | 7b09a6c | 2009-09-09 21:08:12 +0000 | [diff] [blame] | 932 | if (!shouldEmitMoves && !shouldEmitTable) return; |
| 933 | |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 934 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end", |
| 935 | Asm->getFunctionNumber())); |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 936 | |
| 937 | // Record if this personality index uses a landing pad. |
| 938 | bool HasLandingPad = !MMI->getLandingPads().empty(); |
| 939 | UsesLSDA[MMI->getPersonalityIndex()] |= HasLandingPad; |
| 940 | |
| 941 | // Map all labels and get rid of any dead landing pads. |
| 942 | MMI->TidyLandingPads(); |
| 943 | |
| 944 | if (HasLandingPad) |
| 945 | EmitExceptionTable(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 946 | |
Chris Lattner | 09d53fe | 2010-03-10 07:20:42 +0000 | [diff] [blame] | 947 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
Chris Lattner | 3a9be0e | 2010-01-23 05:51:36 +0000 | [diff] [blame] | 948 | MCSymbol *FunctionEHSym = |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 949 | Asm->GetSymbolWithGlobalValueBase(Asm->MF->getFunction(), ".eh", |
Chris Lattner | 09d53fe | 2010-03-10 07:20:42 +0000 | [diff] [blame] | 950 | TLOF.isFunctionEHFrameSymbolPrivate()); |
Chris Lattner | 25d812b | 2009-09-16 00:35:39 +0000 | [diff] [blame] | 951 | |
Bill Wendling | 7b09a6c | 2009-09-09 21:08:12 +0000 | [diff] [blame] | 952 | // Save EH frame information |
Bill Wendling | b92187a | 2010-05-14 21:14:32 +0000 | [diff] [blame] | 953 | EHFrames. |
| 954 | push_back(FunctionEHFrameInfo(FunctionEHSym, |
| 955 | Asm->getFunctionNumber(), |
| 956 | MMI->getPersonalityIndex(), |
| 957 | Asm->MF->getFrameInfo()->adjustsStack(), |
| 958 | !MMI->getLandingPads().empty(), |
| 959 | MMI->getFrameMoves(), |
| 960 | Asm->MF->getFunction())); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 961 | } |