blob: 7599121de2b06c9c84c1c598b008b384e5aece63 [file] [log] [blame]
Eugene Zelenko149178d2017-10-10 22:33:29 +00001//===- CodeGen/AsmPrinter/EHStreamer.cpp - Exception Directive Streamer ---===//
Bill Wendlingd64cd2b2009-05-15 01:12:28 +00002//
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//
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000010// This file contains support for writing exception info into assembly files.
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000011//
12//===----------------------------------------------------------------------===//
13
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000014#include "EHStreamer.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000015#include "llvm/ADT/SmallVector.h"
16#include "llvm/ADT/Twine.h"
17#include "llvm/ADT/iterator_range.h"
18#include "llvm/BinaryFormat/Dwarf.h"
Chris Lattnerda790ea2010-04-05 05:28:23 +000019#include "llvm/CodeGen/AsmPrinter.h"
David Greenea5be1b12009-08-19 21:55:33 +000020#include "llvm/CodeGen/MachineFunction.h"
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000021#include "llvm/CodeGen/MachineInstr.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000022#include "llvm/CodeGen/MachineOperand.h"
23#include "llvm/IR/DataLayout.h"
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000024#include "llvm/IR/Function.h"
Chris Lattnerb8666022009-09-16 01:46:41 +000025#include "llvm/MC/MCAsmInfo.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000026#include "llvm/MC/MCContext.h"
Chris Lattner4b7dadb2009-08-19 05:49:37 +000027#include "llvm/MC/MCStreamer.h"
Chris Lattner555ceabe2010-01-16 18:37:32 +000028#include "llvm/MC/MCSymbol.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000029#include "llvm/MC/MCTargetOptions.h"
30#include "llvm/Support/Casting.h"
Logan Chien5b776b72014-02-22 14:00:39 +000031#include "llvm/Support/LEB128.h"
David Blaikie6054e652018-03-23 23:58:19 +000032#include "llvm/Target/TargetLoweringObjectFile.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000033#include <algorithm>
34#include <cassert>
35#include <cstdint>
36#include <vector>
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000037
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000038using namespace llvm;
39
Rafael Espindoladc4263c2015-03-17 13:57:48 +000040EHStreamer::EHStreamer(AsmPrinter *A) : Asm(A), MMI(Asm->MMI) {}
Bill Wendlingdd20b982009-05-15 01:18:50 +000041
Eugene Zelenko149178d2017-10-10 22:33:29 +000042EHStreamer::~EHStreamer() = default;
Bill Wendlingdd20b982009-05-15 01:18:50 +000043
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000044/// How many leading type ids two landing pads have in common.
45unsigned EHStreamer::sharedTypeIDs(const LandingPadInfo *L,
46 const LandingPadInfo *R) {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000047 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
48 unsigned LSize = LIds.size(), RSize = RIds.size();
49 unsigned MinSize = LSize < RSize ? LSize : RSize;
50 unsigned Count = 0;
51
52 for (; Count != MinSize; ++Count)
53 if (LIds[Count] != RIds[Count])
54 return Count;
55
56 return Count;
57}
58
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000059/// Compute the actions table and gather the first action index for each landing
60/// pad site.
Rafael Espindolad09b4162018-02-09 17:00:25 +000061void EHStreamer::computeActionsTable(
62 const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
63 SmallVectorImpl<ActionEntry> &Actions,
64 SmallVectorImpl<unsigned> &FirstActions) {
Bill Wendling0e749fe2009-08-20 22:02:24 +000065 // The action table follows the call-site table in the LSDA. The individual
66 // records are of two types:
67 //
68 // * Catch clause
69 // * Exception specification
70 //
71 // The two record kinds have the same format, with only small differences.
72 // They are distinguished by the "switch value" field: Catch clauses
73 // (TypeInfos) have strictly positive switch values, and exception
74 // specifications (FilterIds) have strictly negative switch values. Value 0
75 // indicates a catch-all clause.
76 //
Bill Wendling1fddd872009-07-28 23:22:13 +000077 // Negative type IDs index into FilterIds. Positive type IDs index into
78 // TypeInfos. The value written for a positive type ID is just the type ID
79 // itself. For a negative type ID, however, the value written is the
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000080 // (negative) byte offset of the corresponding FilterIds entry. The byte
Bill Wendling1fddd872009-07-28 23:22:13 +000081 // offset is usually equal to the type ID (because the FilterIds entries are
82 // written using a variable width encoding, which outputs one byte per entry
83 // as long as the value written is not too large) but can differ. This kind
84 // of complication does not occur for positive type IDs because type infos are
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000085 // output using a fixed width encoding. FilterOffsets[i] holds the byte
86 // offset corresponding to FilterIds[i].
Bill Wendling45057342009-07-29 21:19:44 +000087
Matthias Braund0ee66c2016-12-01 19:32:15 +000088 const std::vector<unsigned> &FilterIds = Asm->MF->getFilterIds();
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000089 SmallVector<int, 16> FilterOffsets;
90 FilterOffsets.reserve(FilterIds.size());
91 int Offset = -1;
Bill Wendling45057342009-07-29 21:19:44 +000092
93 for (std::vector<unsigned>::const_iterator
94 I = FilterIds.begin(), E = FilterIds.end(); I != E; ++I) {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000095 FilterOffsets.push_back(Offset);
Logan Chien5b776b72014-02-22 14:00:39 +000096 Offset -= getULEB128Size(*I);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000097 }
98
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000099 FirstActions.reserve(LandingPads.size());
100
101 int FirstAction = 0;
Heejin Ahn9d224342018-10-03 21:30:15 +0000102 unsigned SizeActions = 0; // Total size of all action entries for a function
Craig Topper353eda42014-04-24 06:44:33 +0000103 const LandingPadInfo *PrevLPI = nullptr;
Bill Wendling45057342009-07-29 21:19:44 +0000104
Bill Wendling23b177e2009-07-28 23:44:43 +0000105 for (SmallVectorImpl<const LandingPadInfo *>::const_iterator
Bill Wendling1fddd872009-07-28 23:22:13 +0000106 I = LandingPads.begin(), E = LandingPads.end(); I != E; ++I) {
107 const LandingPadInfo *LPI = *I;
108 const std::vector<int> &TypeIds = LPI->TypeIds;
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000109 unsigned NumShared = PrevLPI ? sharedTypeIDs(LPI, PrevLPI) : 0;
Heejin Ahn9d224342018-10-03 21:30:15 +0000110 unsigned SizeSiteActions = 0; // Total size of all entries for a landingpad
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000111
112 if (NumShared < TypeIds.size()) {
Heejin Ahn9d224342018-10-03 21:30:15 +0000113 // Size of one action entry (typeid + next action)
114 unsigned SizeActionEntry = 0;
Bill Wendling7742b642010-02-10 21:41:57 +0000115 unsigned PrevAction = (unsigned)-1;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000116
117 if (NumShared) {
Chris Lattner07c1b942010-04-04 20:10:41 +0000118 unsigned SizePrevIds = PrevLPI->TypeIds.size();
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000119 assert(Actions.size());
Bill Wendling7742b642010-02-10 21:41:57 +0000120 PrevAction = Actions.size() - 1;
Heejin Ahn9d224342018-10-03 21:30:15 +0000121 SizeActionEntry = getSLEB128Size(Actions[PrevAction].NextAction) +
122 getSLEB128Size(Actions[PrevAction].ValueForTypeID);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000123
124 for (unsigned j = NumShared; j != SizePrevIds; ++j) {
Bill Wendling7742b642010-02-10 21:41:57 +0000125 assert(PrevAction != (unsigned)-1 && "PrevAction is invalid!");
Heejin Ahn9d224342018-10-03 21:30:15 +0000126 SizeActionEntry -= getSLEB128Size(Actions[PrevAction].ValueForTypeID);
127 SizeActionEntry += -Actions[PrevAction].NextAction;
Bill Wendling7742b642010-02-10 21:41:57 +0000128 PrevAction = Actions[PrevAction].Previous;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000129 }
130 }
131
132 // Compute the actions.
Bill Wendling1fddd872009-07-28 23:22:13 +0000133 for (unsigned J = NumShared, M = TypeIds.size(); J != M; ++J) {
134 int TypeID = TypeIds[J];
135 assert(-1 - TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
Reid Kleckner0a57f652015-01-14 01:05:27 +0000136 int ValueForTypeID =
137 isFilterEHSelector(TypeID) ? FilterOffsets[-1 - TypeID] : TypeID;
Logan Chien5b776b72014-02-22 14:00:39 +0000138 unsigned SizeTypeID = getSLEB128Size(ValueForTypeID);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000139
Heejin Ahn9d224342018-10-03 21:30:15 +0000140 int NextAction = SizeActionEntry ? -(SizeActionEntry + SizeTypeID) : 0;
141 SizeActionEntry = SizeTypeID + getSLEB128Size(NextAction);
142 SizeSiteActions += SizeActionEntry;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000143
Bill Wendling0e749fe2009-08-20 22:02:24 +0000144 ActionEntry Action = { ValueForTypeID, NextAction, PrevAction };
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000145 Actions.push_back(Action);
Bill Wendling7742b642010-02-10 21:41:57 +0000146 PrevAction = Actions.size() - 1;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000147 }
148
149 // Record the first action of the landing pad site.
Heejin Ahn9d224342018-10-03 21:30:15 +0000150 FirstAction = SizeActions + SizeSiteActions - SizeActionEntry + 1;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000151 } // else identical - re-use previous FirstAction
152
Eric Christopherd72f78e2018-01-09 23:25:38 +0000153 // Information used when creating the call-site table. The action record
Bill Wendling0e749fe2009-08-20 22:02:24 +0000154 // field of the call site record is the offset of the first associated
155 // action record, relative to the start of the actions table. This value is
Bill Wendling7742b642010-02-10 21:41:57 +0000156 // biased by 1 (1 indicating the start of the actions table), and 0
Bill Wendling0e749fe2009-08-20 22:02:24 +0000157 // indicates that there are no actions.
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000158 FirstActions.push_back(FirstAction);
159
160 // Compute this sites contribution to size.
161 SizeActions += SizeSiteActions;
Bill Wendling1fddd872009-07-28 23:22:13 +0000162
163 PrevLPI = LPI;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000164 }
Bill Wendling1fddd872009-07-28 23:22:13 +0000165}
166
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000167/// Return `true' if this is a call to a function marked `nounwind'. Return
168/// `false' otherwise.
169bool EHStreamer::callToNoUnwindFunction(const MachineInstr *MI) {
Evan Cheng7f8e5632011-12-07 07:15:52 +0000170 assert(MI->isCall() && "This should be a call instruction!");
Bill Wendlinge4120642009-11-12 21:59:20 +0000171
172 bool MarkedNoUnwind = false;
173 bool SawFunc = false;
174
175 for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
176 const MachineOperand &MO = MI->getOperand(I);
177
Chris Lattner17d38592010-03-31 06:09:04 +0000178 if (!MO.isGlobal()) continue;
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000179
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000180 const Function *F = dyn_cast<Function>(MO.getGlobal());
Craig Topper353eda42014-04-24 06:44:33 +0000181 if (!F) continue;
Bill Wendlingc781d7a2009-11-12 23:13:08 +0000182
Chris Lattner17d38592010-03-31 06:09:04 +0000183 if (SawFunc) {
184 // Be conservative. If we have more than one function operand for this
185 // call, then we can't make the assumption that it's the callee and
186 // not a parameter to the call.
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000187 //
Chris Lattner17d38592010-03-31 06:09:04 +0000188 // FIXME: Determine if there's a way to say that `F' is the callee or
189 // parameter.
190 MarkedNoUnwind = false;
191 break;
Bill Wendlinge4120642009-11-12 21:59:20 +0000192 }
Chris Lattner17d38592010-03-31 06:09:04 +0000193
194 MarkedNoUnwind = F->doesNotThrow();
195 SawFunc = true;
Bill Wendlinge4120642009-11-12 21:59:20 +0000196 }
197
198 return MarkedNoUnwind;
199}
200
David Majnemercde33032015-03-30 22:58:10 +0000201void EHStreamer::computePadMap(
202 const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
203 RangeMapType &PadMap) {
204 // Invokes and nounwind calls have entries in PadMap (due to being bracketed
205 // by try-range labels when lowered). Ordinary calls do not, so appropriate
206 // try-ranges for them need be deduced so we can put them in the LSDA.
207 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
208 const LandingPadInfo *LandingPad = LandingPads[i];
209 for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
210 MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
211 assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
212 PadRange P = { i, j };
213 PadMap[BeginLabel] = P;
214 }
215 }
216}
217
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000218/// Compute the call-site table. The entry for an invoke has a try-range
219/// containing the call, a non-zero landing pad, and an appropriate action. The
220/// entry for an ordinary call has a try-range containing the call and zero for
221/// the landing pad and the action. Calls marked 'nounwind' have no entry and
222/// must not be contained in the try-range of any entry - they form gaps in the
223/// table. Entries must be ordered by try-range address.
224void EHStreamer::
225computeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
Bill Wendlingb67440e2009-07-29 00:31:35 +0000226 const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
227 const SmallVectorImpl<unsigned> &FirstActions) {
Reid Klecknerf2acbba2014-12-19 22:30:08 +0000228 RangeMapType PadMap;
David Majnemercde33032015-03-30 22:58:10 +0000229 computePadMap(LandingPads, PadMap);
Reid Klecknerf2acbba2014-12-19 22:30:08 +0000230
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000231 // The end label of the previous invoke or nounwind try-range.
Craig Topper353eda42014-04-24 06:44:33 +0000232 MCSymbol *LastLabel = nullptr;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000233
234 // Whether there is a potentially throwing instruction (currently this means
235 // an ordinary call) between the end of the previous try-range and now.
236 bool SawPotentiallyThrowing = false;
237
Bill Wendling23b177e2009-07-28 23:44:43 +0000238 // Whether the last CallSite entry was for an invoke.
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000239 bool PreviousIsInvoke = false;
240
Reid Kleckner93acac62014-12-19 22:19:48 +0000241 bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
242
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000243 // Visit all instructions in order of address.
Alexey Samsonov41b977d2014-04-30 18:29:51 +0000244 for (const auto &MBB : *Asm->MF) {
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000245 for (const auto &MI : MBB) {
246 if (!MI.isEHLabel()) {
247 if (MI.isCall())
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000248 SawPotentiallyThrowing |= !callToNoUnwindFunction(&MI);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000249 continue;
250 }
251
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000252 // End of the previous try-range?
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000253 MCSymbol *BeginLabel = MI.getOperand(0).getMCSymbol();
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000254 if (BeginLabel == LastLabel)
255 SawPotentiallyThrowing = false;
256
257 // Beginning of a new try-range?
Jeffrey Yasskinb40d3f72009-11-10 01:02:17 +0000258 RangeMapType::const_iterator L = PadMap.find(BeginLabel);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000259 if (L == PadMap.end())
260 // Nope, it was just some random label.
261 continue;
262
Bill Wendling0e749fe2009-08-20 22:02:24 +0000263 const PadRange &P = L->second;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000264 const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000265 assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
266 "Inconsistent landing pad map!");
267
Bill Wendling0e749fe2009-08-20 22:02:24 +0000268 // For Dwarf exception handling (SjLj handling doesn't use this). If some
269 // instruction between the previous try-range and this one may throw,
270 // create a call-site entry with no landing pad for the region between the
271 // try-ranges.
Reid Kleckner5cc15692015-01-23 18:49:01 +0000272 if (SawPotentiallyThrowing && Asm->MAI->usesCFIForEH()) {
Craig Topper353eda42014-04-24 06:44:33 +0000273 CallSiteEntry Site = { LastLabel, BeginLabel, nullptr, 0 };
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000274 CallSites.push_back(Site);
275 PreviousIsInvoke = false;
276 }
277
278 LastLabel = LandingPad->EndLabels[P.RangeIndex];
279 assert(BeginLabel && LastLabel && "Invalid landing pad!");
280
Chris Lattner17d38592010-03-31 06:09:04 +0000281 if (!LandingPad->LandingPadLabel) {
282 // Create a gap.
283 PreviousIsInvoke = false;
284 } else {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000285 // This try-range is for an invoke.
Bill Wendling0e749fe2009-08-20 22:02:24 +0000286 CallSiteEntry Site = {
287 BeginLabel,
288 LastLabel,
Reid Kleckner0a57f652015-01-14 01:05:27 +0000289 LandingPad,
Bill Wendling0e749fe2009-08-20 22:02:24 +0000290 FirstActions[P.PadIndex]
291 };
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000292
Jim Grosbach5afbf2b2009-09-01 17:19:13 +0000293 // Try to merge with the previous call-site. SJLJ doesn't do this
Reid Kleckner93acac62014-12-19 22:19:48 +0000294 if (PreviousIsInvoke && !IsSJLJ) {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000295 CallSiteEntry &Prev = CallSites.back();
Reid Kleckner0a57f652015-01-14 01:05:27 +0000296 if (Site.LPad == Prev.LPad && Site.Action == Prev.Action) {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000297 // Extend the range of the previous entry.
298 Prev.EndLabel = Site.EndLabel;
299 continue;
300 }
301 }
302
303 // Otherwise, create a new call-site.
Reid Kleckner93acac62014-12-19 22:19:48 +0000304 if (!IsSJLJ)
Jim Grosbach54c05302010-01-28 01:45:32 +0000305 CallSites.push_back(Site);
306 else {
307 // SjLj EH must maintain the call sites in the order assigned
308 // to them by the SjLjPrepare pass.
Matthias Braund0ee66c2016-12-01 19:32:15 +0000309 unsigned SiteNo = Asm->MF->getCallSiteBeginLabel(BeginLabel);
Jim Grosbach54c05302010-01-28 01:45:32 +0000310 if (CallSites.size() < SiteNo)
311 CallSites.resize(SiteNo);
312 CallSites[SiteNo - 1] = Site;
313 }
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000314 PreviousIsInvoke = true;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000315 }
316 }
317 }
318
319 // If some instruction between the previous try-range and the end of the
320 // function may throw, create a call-site entry with no landing pad for the
321 // region following the try-range.
Reid Klecknerc2f1bbf2017-05-31 22:18:49 +0000322 if (SawPotentiallyThrowing && !IsSJLJ) {
Craig Topper353eda42014-04-24 06:44:33 +0000323 CallSiteEntry Site = { LastLabel, nullptr, nullptr, 0 };
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000324 CallSites.push_back(Site);
325 }
Bill Wendlingb67440e2009-07-29 00:31:35 +0000326}
327
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000328/// Emit landing pads and actions.
Bill Wendling2cf00142009-07-29 00:50:05 +0000329///
330/// The general organization of the table is complex, but the basic concepts are
331/// easy. First there is a header which describes the location and organization
332/// of the three components that follow.
Eric Christopherd517ac02009-08-28 22:33:43 +0000333///
Bill Wendling2cf00142009-07-29 00:50:05 +0000334/// 1. The landing pad site information describes the range of code covered by
335/// the try. In our case it's an accumulation of the ranges covered by the
336/// invokes in the try. There is also a reference to the landing pad that
337/// handles the exception once processed. Finally an index into the actions
338/// table.
Bill Wendling0e749fe2009-08-20 22:02:24 +0000339/// 2. The action table, in our case, is composed of pairs of type IDs and next
Bill Wendling2cf00142009-07-29 00:50:05 +0000340/// action offset. Starting with the action index from the landing pad
Bill Wendling0e749fe2009-08-20 22:02:24 +0000341/// site, each type ID is checked for a match to the current exception. If
Bill Wendling2cf00142009-07-29 00:50:05 +0000342/// it matches then the exception and type id are passed on to the landing
343/// pad. Otherwise the next action is looked up. This chain is terminated
Bill Wendling023ed642009-09-10 06:50:01 +0000344/// with a next action of zero. If no type id is found then the frame is
Bill Wendling2cf00142009-07-29 00:50:05 +0000345/// unwound and handling continues.
Bill Wendling0e749fe2009-08-20 22:02:24 +0000346/// 3. Type ID table contains references to all the C++ typeinfo for all
Bill Wendling023ed642009-09-10 06:50:01 +0000347/// catches in the function. This tables is reverse indexed base 1.
Heejin Ahn24faf852018-10-25 23:55:10 +0000348///
349/// Returns the starting symbol of an exception table.
350MCSymbol *EHStreamer::emitExceptionTable() {
Matthias Braund0ee66c2016-12-01 19:32:15 +0000351 const MachineFunction *MF = Asm->MF;
352 const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
353 const std::vector<unsigned> &FilterIds = MF->getFilterIds();
354 const std::vector<LandingPadInfo> &PadInfos = MF->getLandingPads();
Bill Wendlingb67440e2009-07-29 00:31:35 +0000355
356 // Sort the landing pads in order of their type ids. This is used to fold
357 // duplicate actions.
358 SmallVector<const LandingPadInfo *, 64> LandingPads;
359 LandingPads.reserve(PadInfos.size());
360
361 for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
362 LandingPads.push_back(&PadInfos[i]);
363
Benjamin Kramerb0f74b22014-03-07 21:35:39 +0000364 // Order landing pads lexicographically by type id.
Fangrui Song0cac7262018-09-27 02:13:45 +0000365 llvm::sort(LandingPads, [](const LandingPadInfo *L, const LandingPadInfo *R) {
366 return L->TypeIds < R->TypeIds;
367 });
Bill Wendlingb67440e2009-07-29 00:31:35 +0000368
369 // Compute the actions table and gather the first action index for each
370 // landing pad site.
371 SmallVector<ActionEntry, 32> Actions;
372 SmallVector<unsigned, 64> FirstActions;
Rafael Espindolad09b4162018-02-09 17:00:25 +0000373 computeActionsTable(LandingPads, Actions, FirstActions);
Bill Wendlingb67440e2009-07-29 00:31:35 +0000374
Bill Wendlingb67440e2009-07-29 00:31:35 +0000375 // Compute the call-site table.
376 SmallVector<CallSiteEntry, 64> CallSites;
Reid Klecknerf2acbba2014-12-19 22:30:08 +0000377 computeCallSiteTable(CallSites, LandingPads, FirstActions);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000378
Chris Lattnerfd795022010-04-05 00:26:50 +0000379 bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
Heejin Ahn24faf852018-10-25 23:55:10 +0000380 bool IsWasm = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::Wasm;
Rafael Espindolac052fa02018-02-09 17:13:37 +0000381 unsigned CallSiteEncoding =
382 IsSJLJ ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_uleb128;
383 bool HaveTTData = !TypeInfos.empty() || !FilterIds.empty();
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000384
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000385 // Type infos.
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000386 MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection();
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000387 unsigned TTypeEncoding;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000388
Bill Wendlingbf562682009-09-10 01:12:47 +0000389 if (!HaveTTData) {
Rafael Espindolac052fa02018-02-09 17:13:37 +0000390 // If there is no TypeInfo, then we just explicitly say that we're omitting
391 // that bit.
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000392 TTypeEncoding = dwarf::DW_EH_PE_omit;
Chris Lattner47fc2352009-07-31 22:03:47 +0000393 } else {
Chris Lattner7005cd32009-08-02 03:59:56 +0000394 // Okay, we have actual filters or typeinfos to emit. As such, we need to
395 // pick a type encoding for them. We're about to emit a list of pointers to
396 // typeinfo objects at the end of the LSDA. However, unless we're in static
397 // mode, this reference will require a relocation by the dynamic linker.
Chris Lattnerf4b92a82009-07-31 22:18:14 +0000398 //
Chris Lattner7005cd32009-08-02 03:59:56 +0000399 // Because of this, we have a couple of options:
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000400 //
Chris Lattner7005cd32009-08-02 03:59:56 +0000401 // 1) If we are in -static mode, we can always use an absolute reference
402 // from the LSDA, because the static linker will resolve it.
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000403 //
Chris Lattner7005cd32009-08-02 03:59:56 +0000404 // 2) Otherwise, if the LSDA section is writable, we can output the direct
405 // reference to the typeinfo and allow the dynamic linker to relocate
406 // it. Since it is in a writable section, the dynamic linker won't
407 // have a problem.
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000408 //
Chris Lattner7005cd32009-08-02 03:59:56 +0000409 // 3) Finally, if we're in PIC mode and the LDSA section isn't writable,
410 // we need to use some form of indirection. For example, on Darwin,
411 // we can output a statically-relocatable reference to a dyld stub. The
412 // offset to the stub is constant, but the contents are in a section
413 // that is updated by the dynamic linker. This is easy enough, but we
414 // need to tell the personality function of the unwinder to indirect
415 // through the dyld stub.
416 //
Bill Wendlingbf562682009-09-10 01:12:47 +0000417 // FIXME: When (3) is actually implemented, we'll have to emit the stubs
Chris Lattner7005cd32009-08-02 03:59:56 +0000418 // somewhere. This predicate should be moved to a shared location that is
419 // in target-independent code.
420 //
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000421 TTypeEncoding = Asm->getObjFileLowering().getTTypeEncoding();
Bill Wendling243ac562009-09-10 02:07:37 +0000422 }
Bill Wendlingbf562682009-09-10 01:12:47 +0000423
Bill Wendling243ac562009-09-10 02:07:37 +0000424 // Begin the exception table.
Anton Korobeynikovfe3a6e02011-01-30 22:07:31 +0000425 // Sometimes we want not to emit the data into separate section (e.g. ARM
426 // EHABI). In this case LSDASection will be NULL.
Anton Korobeynikovb15beb22011-01-24 22:38:40 +0000427 if (LSDASection)
Lang Hames9ff69c82015-04-24 19:11:51 +0000428 Asm->OutStreamer->SwitchSection(LSDASection);
Chris Lattner9e06e532010-04-28 01:05:45 +0000429 Asm->EmitAlignment(2);
Bill Wendlingbf562682009-09-10 01:12:47 +0000430
Bill Wendling88fdcd32010-02-24 23:34:35 +0000431 // Emit the LSDA.
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000432 MCSymbol *GCCETSym =
Jim Grosbach6f482002015-05-18 18:43:14 +0000433 Asm->OutContext.getOrCreateSymbol(Twine("GCC_except_table")+
Chris Lattnerfd795022010-04-05 00:26:50 +0000434 Twine(Asm->getFunctionNumber()));
Lang Hames9ff69c82015-04-24 19:11:51 +0000435 Asm->OutStreamer->EmitLabel(GCCETSym);
436 Asm->OutStreamer->EmitLabel(Asm->getCurExceptionSym());
Bill Wendling243ac562009-09-10 02:07:37 +0000437
Bill Wendling88fdcd32010-02-24 23:34:35 +0000438 // Emit the LSDA header.
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000439 Asm->EmitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart");
440 Asm->EmitEncodingByte(TTypeEncoding, "@TType");
Bill Wendling243ac562009-09-10 02:07:37 +0000441
Rafael Espindolad09b4162018-02-09 17:00:25 +0000442 MCSymbol *TTBaseLabel = nullptr;
Bill Wendling24c74f12010-02-25 23:52:44 +0000443 if (HaveTTData) {
Rafael Espindolad09b4162018-02-09 17:00:25 +0000444 // N.B.: There is a dependency loop between the size of the TTBase uleb128
445 // here and the amount of padding before the aligned type table. The
446 // assembler must sometimes pad this uleb128 or insert extra padding before
447 // the type table. See PR35809 or GNU as bug 4029.
448 MCSymbol *TTBaseRefLabel = Asm->createTempSymbol("ttbaseref");
449 TTBaseLabel = Asm->createTempSymbol("ttbase");
450 Asm->EmitLabelDifferenceAsULEB128(TTBaseLabel, TTBaseRefLabel);
451 Asm->OutStreamer->EmitLabel(TTBaseRefLabel);
Bill Wendling24c74f12010-02-25 23:52:44 +0000452 }
Bill Wendling15349f82009-07-28 22:23:45 +0000453
Lang Hames9ff69c82015-04-24 19:11:51 +0000454 bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000455
Rafael Espindolad09b4162018-02-09 17:00:25 +0000456 // Emit the landing pad call site table.
457 MCSymbol *CstBeginLabel = Asm->createTempSymbol("cst_begin");
458 MCSymbol *CstEndLabel = Asm->createTempSymbol("cst_end");
Rafael Espindolac052fa02018-02-09 17:13:37 +0000459 Asm->EmitEncodingByte(CallSiteEncoding, "Call site");
Rafael Espindolad09b4162018-02-09 17:00:25 +0000460 Asm->EmitLabelDifferenceAsULEB128(CstEndLabel, CstBeginLabel);
461 Asm->OutStreamer->EmitLabel(CstBeginLabel);
462
Heejin Ahn24faf852018-10-25 23:55:10 +0000463 // SjLj / Wasm Exception handling
464 if (IsSJLJ || IsWasm) {
Jim Grosbach486be662009-08-17 16:41:22 +0000465 unsigned idx = 0;
466 for (SmallVectorImpl<CallSiteEntry>::const_iterator
467 I = CallSites.begin(), E = CallSites.end(); I != E; ++I, ++idx) {
468 const CallSiteEntry &S = *I;
Bill Wendling0e749fe2009-08-20 22:02:24 +0000469
Rafael Espindolad09b4162018-02-09 17:00:25 +0000470 // Index of the call site entry.
Bill Wendlingddec6832011-06-21 22:40:24 +0000471 if (VerboseAsm) {
Lang Hames9ff69c82015-04-24 19:11:51 +0000472 Asm->OutStreamer->AddComment(">> Call Site " + Twine(idx) + " <<");
473 Asm->OutStreamer->AddComment(" On exception at call site "+Twine(idx));
Bill Wendlingddec6832011-06-21 22:40:24 +0000474 }
Bill Wendlingddec6832011-06-21 22:40:24 +0000475 Asm->EmitULEB128(idx);
Bill Wendling0e749fe2009-08-20 22:02:24 +0000476
477 // Offset of the first associated action record, relative to the start of
478 // the action table. This value is biased by 1 (1 indicates the start of
479 // the action table), and 0 indicates that there are no actions.
Renato Golinc8d40652011-08-18 23:43:14 +0000480 if (VerboseAsm) {
481 if (S.Action == 0)
Lang Hames9ff69c82015-04-24 19:11:51 +0000482 Asm->OutStreamer->AddComment(" Action: cleanup");
Renato Golinc8d40652011-08-18 23:43:14 +0000483 else
Lang Hames9ff69c82015-04-24 19:11:51 +0000484 Asm->OutStreamer->AddComment(" Action: " +
485 Twine((S.Action - 1) / 2 + 1));
Renato Golinc8d40652011-08-18 23:43:14 +0000486 }
Bill Wendlingddec6832011-06-21 22:40:24 +0000487 Asm->EmitULEB128(S.Action);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000488 }
Jim Grosbach693e36a2009-08-11 00:09:57 +0000489 } else {
Reid Kleckner93acac62014-12-19 22:19:48 +0000490 // Itanium LSDA exception handling
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000491
Bill Wendling0e749fe2009-08-20 22:02:24 +0000492 // The call-site table is a list of all call sites that may throw an
493 // exception (including C++ 'throw' statements) in the procedure
494 // fragment. It immediately follows the LSDA header. Each entry indicates,
495 // for a given call, the first corresponding action record and corresponding
496 // landing pad.
497 //
498 // The table begins with the number of bytes, stored as an LEB128
499 // compressed, unsigned integer. The records immediately follow the record
500 // count. They are sorted in increasing call-site address. Each record
501 // indicates:
502 //
503 // * The position of the call-site.
504 // * The position of the landing pad.
505 // * The first action record for that call site.
506 //
507 // A missing entry in the call-site table indicates that a call is not
Bill Wendling023ed642009-09-10 06:50:01 +0000508 // supposed to throw.
Bill Wendling0e749fe2009-08-20 22:02:24 +0000509
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000510 unsigned Entry = 0;
Jim Grosbach693e36a2009-08-11 00:09:57 +0000511 for (SmallVectorImpl<CallSiteEntry>::const_iterator
512 I = CallSites.begin(), E = CallSites.end(); I != E; ++I) {
513 const CallSiteEntry &S = *I;
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000514
Rafael Espindola629cdba2015-02-27 18:18:39 +0000515 MCSymbol *EHFuncBeginSym = Asm->getFunctionBegin();
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000516
Chris Lattner34adc8d2010-03-14 01:41:15 +0000517 MCSymbol *BeginLabel = S.BeginLabel;
Craig Topper353eda42014-04-24 06:44:33 +0000518 if (!BeginLabel)
Chris Lattner34adc8d2010-03-14 01:41:15 +0000519 BeginLabel = EHFuncBeginSym;
520 MCSymbol *EndLabel = S.EndLabel;
Craig Topper353eda42014-04-24 06:44:33 +0000521 if (!EndLabel)
Rafael Espindola629cdba2015-02-27 18:18:39 +0000522 EndLabel = Asm->getFunctionEnd();
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000523
Rafael Espindolad09b4162018-02-09 17:00:25 +0000524 // Offset of the call site relative to the start of the procedure.
Renato Golinc8d40652011-08-18 23:43:14 +0000525 if (VerboseAsm)
Lang Hames9ff69c82015-04-24 19:11:51 +0000526 Asm->OutStreamer->AddComment(">> Call Site " + Twine(++Entry) + " <<");
Rafael Espindolac052fa02018-02-09 17:13:37 +0000527 Asm->EmitLabelDifferenceAsULEB128(BeginLabel, EHFuncBeginSym);
Renato Golinc8d40652011-08-18 23:43:14 +0000528 if (VerboseAsm)
Lang Hames9ff69c82015-04-24 19:11:51 +0000529 Asm->OutStreamer->AddComment(Twine(" Call between ") +
530 BeginLabel->getName() + " and " +
531 EndLabel->getName());
Rafael Espindolac052fa02018-02-09 17:13:37 +0000532 Asm->EmitLabelDifferenceAsULEB128(EndLabel, BeginLabel);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000533
Rafael Espindolad09b4162018-02-09 17:00:25 +0000534 // Offset of the landing pad relative to the start of the procedure.
Reid Kleckner0a57f652015-01-14 01:05:27 +0000535 if (!S.LPad) {
Renato Golinc8d40652011-08-18 23:43:14 +0000536 if (VerboseAsm)
Lang Hames9ff69c82015-04-24 19:11:51 +0000537 Asm->OutStreamer->AddComment(" has no landing pad");
Rafael Espindolac052fa02018-02-09 17:13:37 +0000538 Asm->EmitULEB128(0);
Renato Golinc8d40652011-08-18 23:43:14 +0000539 } else {
540 if (VerboseAsm)
Lang Hames9ff69c82015-04-24 19:11:51 +0000541 Asm->OutStreamer->AddComment(Twine(" jumps to ") +
542 S.LPad->LandingPadLabel->getName());
Rafael Espindolac052fa02018-02-09 17:13:37 +0000543 Asm->EmitLabelDifferenceAsULEB128(S.LPad->LandingPadLabel,
544 EHFuncBeginSym);
Renato Golinc8d40652011-08-18 23:43:14 +0000545 }
Jim Grosbach693e36a2009-08-11 00:09:57 +0000546
Bill Wendling0e749fe2009-08-20 22:02:24 +0000547 // Offset of the first associated action record, relative to the start of
548 // the action table. This value is biased by 1 (1 indicates the start of
549 // the action table), and 0 indicates that there are no actions.
Renato Golinc8d40652011-08-18 23:43:14 +0000550 if (VerboseAsm) {
551 if (S.Action == 0)
Lang Hames9ff69c82015-04-24 19:11:51 +0000552 Asm->OutStreamer->AddComment(" On action: cleanup");
Renato Golinc8d40652011-08-18 23:43:14 +0000553 else
Lang Hames9ff69c82015-04-24 19:11:51 +0000554 Asm->OutStreamer->AddComment(" On action: " +
555 Twine((S.Action - 1) / 2 + 1));
Renato Golinc8d40652011-08-18 23:43:14 +0000556 }
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000557 Asm->EmitULEB128(S.Action);
Jim Grosbach693e36a2009-08-11 00:09:57 +0000558 }
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000559 }
Rafael Espindolad09b4162018-02-09 17:00:25 +0000560 Asm->OutStreamer->EmitLabel(CstEndLabel);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000561
Bill Wendling0e749fe2009-08-20 22:02:24 +0000562 // Emit the Action Table.
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000563 int Entry = 0;
Bill Wendling23b177e2009-07-28 23:44:43 +0000564 for (SmallVectorImpl<ActionEntry>::const_iterator
565 I = Actions.begin(), E = Actions.end(); I != E; ++I) {
566 const ActionEntry &Action = *I;
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000567
568 if (VerboseAsm) {
569 // Emit comments that decode the action table.
Lang Hames9ff69c82015-04-24 19:11:51 +0000570 Asm->OutStreamer->AddComment(">> Action Record " + Twine(++Entry) + " <<");
Renato Golinc8d40652011-08-18 23:43:14 +0000571 }
572
573 // Type Filter
574 //
575 // Used by the runtime to match the type of the thrown exception to the
576 // type of the catch clauses or the types in the exception specification.
577 if (VerboseAsm) {
Duncan Sands2e679372011-09-28 09:13:02 +0000578 if (Action.ValueForTypeID > 0)
Lang Hames9ff69c82015-04-24 19:11:51 +0000579 Asm->OutStreamer->AddComment(" Catch TypeInfo " +
580 Twine(Action.ValueForTypeID));
Duncan Sands2e679372011-09-28 09:13:02 +0000581 else if (Action.ValueForTypeID < 0)
Lang Hames9ff69c82015-04-24 19:11:51 +0000582 Asm->OutStreamer->AddComment(" Filter TypeInfo " +
583 Twine(Action.ValueForTypeID));
Duncan Sands2e679372011-09-28 09:13:02 +0000584 else
Lang Hames9ff69c82015-04-24 19:11:51 +0000585 Asm->OutStreamer->AddComment(" Cleanup");
Renato Golinc8d40652011-08-18 23:43:14 +0000586 }
587 Asm->EmitSLEB128(Action.ValueForTypeID);
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000588
Renato Golinc8d40652011-08-18 23:43:14 +0000589 // Action Record
590 //
591 // Self-relative signed displacement in bytes of the next action record,
592 // or 0 if there is no next action record.
593 if (VerboseAsm) {
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000594 if (Action.NextAction == 0) {
Lang Hames9ff69c82015-04-24 19:11:51 +0000595 Asm->OutStreamer->AddComment(" No further actions");
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000596 } else {
597 unsigned NextAction = Entry + (Action.NextAction + 1) / 2;
Lang Hames9ff69c82015-04-24 19:11:51 +0000598 Asm->OutStreamer->AddComment(" Continue to action "+Twine(NextAction));
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000599 }
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000600 }
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000601 Asm->EmitSLEB128(Action.NextAction);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000602 }
603
Rafael Espindolad09b4162018-02-09 17:00:25 +0000604 if (HaveTTData) {
605 Asm->EmitAlignment(2);
606 emitTypeInfos(TTypeEncoding, TTBaseLabel);
607 }
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000608
609 Asm->EmitAlignment(2);
Heejin Ahn24faf852018-10-25 23:55:10 +0000610 return GCCETSym;
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000611}
612
Rafael Espindolad09b4162018-02-09 17:00:25 +0000613void EHStreamer::emitTypeInfos(unsigned TTypeEncoding, MCSymbol *TTBaseLabel) {
Matthias Braund0ee66c2016-12-01 19:32:15 +0000614 const MachineFunction *MF = Asm->MF;
615 const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
616 const std::vector<unsigned> &FilterIds = MF->getFilterIds();
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000617
Lang Hames9ff69c82015-04-24 19:11:51 +0000618 bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000619
620 int Entry = 0;
Bill Wendling4f0b8d72009-10-22 20:48:59 +0000621 // Emit the Catch TypeInfos.
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000622 if (VerboseAsm && !TypeInfos.empty()) {
Lang Hames9ff69c82015-04-24 19:11:51 +0000623 Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
624 Asm->OutStreamer->AddBlankLine();
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000625 Entry = TypeInfos.size();
Chris Lattner566cae92010-03-09 23:52:58 +0000626 }
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000627
Pete Cooper7679afd2015-07-24 21:13:43 +0000628 for (const GlobalValue *GV : make_range(TypeInfos.rbegin(),
629 TypeInfos.rend())) {
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000630 if (VerboseAsm)
Lang Hames9ff69c82015-04-24 19:11:51 +0000631 Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000632 Asm->EmitTTypeReference(GV, TTypeEncoding);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000633 }
634
Rafael Espindolad09b4162018-02-09 17:00:25 +0000635 Asm->OutStreamer->EmitLabel(TTBaseLabel);
636
Bill Wendling4f0b8d72009-10-22 20:48:59 +0000637 // Emit the Exception Specifications.
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000638 if (VerboseAsm && !FilterIds.empty()) {
Lang Hames9ff69c82015-04-24 19:11:51 +0000639 Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
640 Asm->OutStreamer->AddBlankLine();
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000641 Entry = 0;
Chris Lattner566cae92010-03-09 23:52:58 +0000642 }
Bill Wendling23b177e2009-07-28 23:44:43 +0000643 for (std::vector<unsigned>::const_iterator
644 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
645 unsigned TypeID = *I;
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000646 if (VerboseAsm) {
647 --Entry;
Reid Kleckner0a57f652015-01-14 01:05:27 +0000648 if (isFilterEHSelector(TypeID))
Lang Hames9ff69c82015-04-24 19:11:51 +0000649 Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000650 }
651
652 Asm->EmitULEB128(TypeID);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000653 }
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000654}