blob: 960a0716e93e2a148861aa28563e89d5a7c0ea5e [file] [log] [blame]
Daniel Dunbarba1da8a2009-06-23 23:39:15 +00001//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
Daniel Dunbarecc63f82009-06-23 22:01:43 +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
10#include "llvm/MC/MCContext.h"
Chris Lattner7c5b0212009-10-19 22:49:00 +000011#include "llvm/ADT/SmallString.h"
12#include "llvm/ADT/Twine.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000013#include "llvm/MC/MCAsmInfo.h"
14#include "llvm/MC/MCDwarf.h"
15#include "llvm/MC/MCLabel.h"
16#include "llvm/MC/MCObjectFileInfo.h"
17#include "llvm/MC/MCRegisterInfo.h"
18#include "llvm/MC/MCSectionCOFF.h"
19#include "llvm/MC/MCSectionELF.h"
20#include "llvm/MC/MCSectionMachO.h"
21#include "llvm/MC/MCSymbol.h"
Rafael Espindolac85dca62011-01-23 04:28:49 +000022#include "llvm/Support/ELF.h"
Jim Grosbach82f4ce52012-01-26 23:20:11 +000023#include "llvm/Support/ErrorHandling.h"
Rafael Espindola76858a72013-06-14 20:26:58 +000024#include "llvm/Support/FileSystem.h"
Eric Christopher6c583142012-12-18 00:31:01 +000025#include "llvm/Support/MemoryBuffer.h"
Jim Grosbach82f4ce52012-01-26 23:20:11 +000026#include "llvm/Support/Signals.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000027#include "llvm/Support/SourceMgr.h"
David Blaikie2b3ea3c2013-10-22 23:41:52 +000028#include <map>
29
Daniel Dunbarecc63f82009-06-23 22:01:43 +000030using namespace llvm;
31
Bill Wendling99cb6222013-06-18 07:20:20 +000032MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
Pedro Artigas873a1dd2012-12-06 22:12:44 +000033 const MCObjectFileInfo *mofi, const SourceMgr *mgr,
Stephen Hines36b56882014-04-23 16:57:46 -070034 bool DoAutoReset)
35 : SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi), Allocator(),
36 Symbols(Allocator), UsedNames(Allocator), NextUniqueID(0),
37 CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), DwarfLocSeen(false),
Stephen Hinesdce4a402014-05-29 02:49:00 -070038 GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4),
Stephen Hines36b56882014-04-23 16:57:46 -070039 AllowTemporaryLabels(true), DwarfCompileUnitID(0),
40 AutoReset(DoAutoReset) {
Pedro Artigas5399d252012-12-12 22:59:46 +000041
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070042 std::error_code EC = llvm::sys::fs::current_path(CompilationDir);
Stephen Hines36b56882014-04-23 16:57:46 -070043 if (EC)
44 CompilationDir.clear();
Rafael Espindola76858a72013-06-14 20:26:58 +000045
Kevin Enderbyf187ac52010-06-28 21:45:58 +000046 SecureLogFile = getenv("AS_SECURE_LOG_FILE");
Stephen Hinesdce4a402014-05-29 02:49:00 -070047 SecureLog = nullptr;
Kevin Enderbyf187ac52010-06-28 21:45:58 +000048 SecureLogUsed = false;
Eric Christopher6c583142012-12-18 00:31:01 +000049
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070050 if (SrcMgr && SrcMgr->getNumBuffers())
51 MainFileName =
52 SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())->getBufferIdentifier();
Pedro Artigas873a1dd2012-12-06 22:12:44 +000053}
54
55MCContext::~MCContext() {
56
Pedro Artigas5399d252012-12-12 22:59:46 +000057 if (AutoReset)
58 reset();
Pedro Artigas873a1dd2012-12-06 22:12:44 +000059
60 // NOTE: The symbols are all allocated out of a bump pointer allocator,
61 // we don't need to free them here.
Stephen Hines36b56882014-04-23 16:57:46 -070062
Pedro Artigas873a1dd2012-12-06 22:12:44 +000063 // If the stream for the .secure_log_unique directive was created free it.
64 delete (raw_ostream*)SecureLog;
65}
66
67//===----------------------------------------------------------------------===//
68// Module Lifetime Management
69//===----------------------------------------------------------------------===//
70
Pedro Artigas5399d252012-12-12 22:59:46 +000071void MCContext::reset() {
Pedro Artigas873a1dd2012-12-06 22:12:44 +000072 UsedNames.clear();
73 Symbols.clear();
74 Allocator.Reset();
75 Instances.clear();
Stephen Hines36b56882014-04-23 16:57:46 -070076 MCDwarfLineTablesCUMap.clear();
Pedro Artigas873a1dd2012-12-06 22:12:44 +000077 MCGenDwarfLabelEntries.clear();
78 DwarfDebugFlags = StringRef();
Pedro Artigas9e7924d2013-02-20 00:10:29 +000079 DwarfCompileUnitID = 0;
Pedro Artigas873a1dd2012-12-06 22:12:44 +000080 CurrentDwarfLoc = MCDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0);
Michael J. Spencer326990f2010-11-26 04:16:08 +000081
Stephen Hinesdce4a402014-05-29 02:49:00 -070082 MachOUniquingMap.clear();
83 ELFUniquingMap.clear();
84 COFFUniquingMap.clear();
Pedro Artigas5399d252012-12-12 22:59:46 +000085
86 NextUniqueID = 0;
87 AllowTemporaryLabels = true;
88 DwarfLocSeen = false;
89 GenDwarfForAssembly = false;
90 GenDwarfFileNumber = 0;
Daniel Dunbarecc63f82009-06-23 22:01:43 +000091}
92
Chris Lattnerf0559e42010-04-08 20:30:37 +000093//===----------------------------------------------------------------------===//
94// Symbol Manipulation
95//===----------------------------------------------------------------------===//
96
Chris Lattner9b97a732010-03-30 18:10:53 +000097MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
Chris Lattner00685bb2010-03-10 01:29:27 +000098 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
Michael J. Spencer326990f2010-11-26 04:16:08 +000099
Chris Lattnerc28cc092010-03-15 06:15:35 +0000100 // Do the lookup and get the entire StringMapEntry. We want access to the
101 // key if we are creating the entry.
102 StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name);
Rafael Espindola9f447242010-12-01 20:46:11 +0000103 MCSymbol *Sym = Entry.getValue();
104
105 if (Sym)
106 return Sym;
107
108 Sym = CreateSymbol(Name);
109 Entry.setValue(Sym);
110 return Sym;
111}
112
113MCSymbol *MCContext::CreateSymbol(StringRef Name) {
Daniel Dunbarc6cf43d2011-03-28 22:49:15 +0000114 // Determine whether this is an assembler temporary or normal label, if used.
115 bool isTemporary = false;
116 if (AllowTemporaryLabels)
Bill Wendling99cb6222013-06-18 07:20:20 +0000117 isTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
Rafael Espindola9f447242010-12-01 20:46:11 +0000118
119 StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name);
120 if (NameEntry->getValue()) {
Stephen Hines36b56882014-04-23 16:57:46 -0700121 assert(isTemporary && "Cannot rename non-temporary symbols");
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000122 SmallString<128> NewName = Name;
Rafael Espindola9f447242010-12-01 20:46:11 +0000123 do {
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000124 NewName.resize(Name.size());
125 raw_svector_ostream(NewName) << NextUniqueID++;
126 NameEntry = &UsedNames.GetOrCreateValue(NewName);
Rafael Espindola9f447242010-12-01 20:46:11 +0000127 } while (NameEntry->getValue());
128 }
129 NameEntry->setValue(true);
Chris Lattnerc69485e2009-06-24 04:31:49 +0000130
Chris Lattnerc28cc092010-03-15 06:15:35 +0000131 // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer
Rafael Espindola9f447242010-12-01 20:46:11 +0000132 // to the copy of the string that is embedded in the UsedNames entry.
133 MCSymbol *Result = new (*this) MCSymbol(NameEntry->getKey(), isTemporary);
134
135 return Result;
Chris Lattnerc69485e2009-06-24 04:31:49 +0000136}
137
Chris Lattner9b97a732010-03-30 18:10:53 +0000138MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
Chris Lattner7c5b0212009-10-19 22:49:00 +0000139 SmallString<128> NameSV;
Stephen Hines36b56882014-04-23 16:57:46 -0700140 return GetOrCreateSymbol(Name.toStringRef(NameSV));
141}
142
143MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() {
144 SmallString<128> NameSV;
145 raw_svector_ostream(NameSV)
146 << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
147 return CreateSymbol(NameSV);
Chris Lattner7c5b0212009-10-19 22:49:00 +0000148}
149
Chris Lattner1d72a762010-03-14 08:23:30 +0000150MCSymbol *MCContext::CreateTempSymbol() {
Rafael Espindola9f447242010-12-01 20:46:11 +0000151 SmallString<128> NameSV;
Benjamin Kramerc18214a2011-04-09 11:26:27 +0000152 raw_svector_ostream(NameSV)
Bill Wendling99cb6222013-06-18 07:20:20 +0000153 << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
Rafael Espindola9f447242010-12-01 20:46:11 +0000154 return CreateSymbol(NameSV);
Chris Lattner1d72a762010-03-14 08:23:30 +0000155}
156
Stephen Hines36b56882014-04-23 16:57:46 -0700157unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
Benjamin Kramer47f9a492010-05-18 12:15:34 +0000158 MCLabel *&Label = Instances[LocalLabelVal];
159 if (!Label)
160 Label = new (*this) MCLabel(0);
161 return Label->incInstance();
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000162}
163
Stephen Hines36b56882014-04-23 16:57:46 -0700164unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
Benjamin Kramer47f9a492010-05-18 12:15:34 +0000165 MCLabel *&Label = Instances[LocalLabelVal];
166 if (!Label)
167 Label = new (*this) MCLabel(0);
168 return Label->getInstance();
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000169}
170
Stephen Hines36b56882014-04-23 16:57:46 -0700171MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
172 unsigned Instance) {
173 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
174 if (!Sym)
175 Sym = CreateTempSymbol();
176 return Sym;
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000177}
Stephen Hines36b56882014-04-23 16:57:46 -0700178
179MCSymbol *MCContext::CreateDirectionalLocalSymbol(unsigned LocalLabelVal) {
180 unsigned Instance = NextInstance(LocalLabelVal);
181 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
182}
183
184MCSymbol *MCContext::GetDirectionalLocalSymbol(unsigned LocalLabelVal,
185 bool Before) {
186 unsigned Instance = GetInstance(LocalLabelVal);
187 if (!Before)
188 ++Instance;
189 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
Kevin Enderbyebe7fcd2010-05-17 23:08:19 +0000190}
191
Daniel Dunbar2928c832009-11-06 10:58:06 +0000192MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
Daniel Dunbarecc63f82009-06-23 22:01:43 +0000193 return Symbols.lookup(Name);
194}
Chris Lattnerf0559e42010-04-08 20:30:37 +0000195
Roman Divackyf145c132012-09-18 17:10:37 +0000196MCSymbol *MCContext::LookupSymbol(const Twine &Name) const {
197 SmallString<128> NameSV;
198 Name.toVector(NameSV);
199 return LookupSymbol(NameSV.str());
200}
201
Chris Lattnerf0559e42010-04-08 20:30:37 +0000202//===----------------------------------------------------------------------===//
203// Section Management
204//===----------------------------------------------------------------------===//
205
206const MCSectionMachO *MCContext::
207getMachOSection(StringRef Segment, StringRef Section,
208 unsigned TypeAndAttributes,
209 unsigned Reserved2, SectionKind Kind) {
Michael J. Spencer326990f2010-11-26 04:16:08 +0000210
Chris Lattnerf0559e42010-04-08 20:30:37 +0000211 // We unique sections by their segment/section pair. The returned section
212 // may not have the same flags as the requested section, if so this should be
213 // diagnosed by the client as an error.
Michael J. Spencer326990f2010-11-26 04:16:08 +0000214
Chris Lattnerf0559e42010-04-08 20:30:37 +0000215 // Form the name to look up.
216 SmallString<64> Name;
217 Name += Segment;
218 Name.push_back(',');
219 Name += Section;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000220
Chris Lattnerf0559e42010-04-08 20:30:37 +0000221 // Do the lookup, if we have a hit, return it.
Stephen Hinesdce4a402014-05-29 02:49:00 -0700222 const MCSectionMachO *&Entry = MachOUniquingMap[Name.str()];
Chris Lattnerf0559e42010-04-08 20:30:37 +0000223 if (Entry) return Entry;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000224
Chris Lattnerf0559e42010-04-08 20:30:37 +0000225 // Otherwise, return a new section.
Chris Lattner74aae472010-04-08 21:26:26 +0000226 return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes,
227 Reserved2, Kind);
Chris Lattnerf0559e42010-04-08 20:30:37 +0000228}
Chris Lattner74aae472010-04-08 21:26:26 +0000229
Rafael Espindola4283f4b2010-11-10 19:05:07 +0000230const MCSectionELF *MCContext::
Chris Lattner74aae472010-04-08 21:26:26 +0000231getELFSection(StringRef Section, unsigned Type, unsigned Flags,
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000232 SectionKind Kind) {
233 return getELFSection(Section, Type, Flags, Kind, 0, "");
234}
235
Stephen Hinesdce4a402014-05-29 02:49:00 -0700236void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) {
237 StringRef GroupName;
238 if (const MCSymbol *Group = Section->getGroup())
239 GroupName = Group->getName();
240
241 ELFUniquingMap.erase(SectionGroupPair(Section->getSectionName(), GroupName));
242 auto I =
243 ELFUniquingMap.insert(std::make_pair(SectionGroupPair(Name, GroupName),
244 Section)).first;
245 StringRef CachedName = I->first.first;
246 const_cast<MCSectionELF*>(Section)->setSectionName(CachedName);
247}
248
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000249const MCSectionELF *MCContext::
250getELFSection(StringRef Section, unsigned Type, unsigned Flags,
251 SectionKind Kind, unsigned EntrySize, StringRef Group) {
Chris Lattner74aae472010-04-08 21:26:26 +0000252 // Do the lookup, if we have a hit, return it.
Stephen Hinesdce4a402014-05-29 02:49:00 -0700253 auto IterBool = ELFUniquingMap.insert(
254 std::make_pair(SectionGroupPair(Section, Group), nullptr));
255 auto &Entry = *IterBool.first;
256 if (!IterBool.second) return Entry.second;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000257
Jan Wen Voung186e7a02010-09-30 05:59:22 +0000258 // Possibly refine the entry size first.
259 if (!EntrySize) {
260 EntrySize = MCSectionELF::DetermineEntrySize(Kind);
261 }
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000262
Stephen Hinesdce4a402014-05-29 02:49:00 -0700263 MCSymbol *GroupSym = nullptr;
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000264 if (!Group.empty())
265 GroupSym = GetOrCreateSymbol(Group);
266
Stephen Hinesdce4a402014-05-29 02:49:00 -0700267 StringRef CachedName = Entry.first.first;
268 MCSectionELF *Result = new (*this)
269 MCSectionELF(CachedName, Type, Flags, Kind, EntrySize, GroupSym);
270 Entry.second = Result;
Chris Lattner74aae472010-04-08 21:26:26 +0000271 return Result;
272}
273
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000274const MCSectionELF *MCContext::CreateELFGroupSection() {
275 MCSectionELF *Result =
Rafael Espindolac85dca62011-01-23 04:28:49 +0000276 new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
Stephen Hinesdce4a402014-05-29 02:49:00 -0700277 SectionKind::getReadOnly(), 4, nullptr);
Rafael Espindola2ff9e832010-11-11 18:13:52 +0000278 return Result;
279}
280
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700281const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
282 unsigned Characteristics,
283 SectionKind Kind,
284 StringRef COMDATSymName,
285 int Selection) {
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000286 // Do the lookup, if we have a hit, return it.
Michael J. Spencer326990f2010-11-26 04:16:08 +0000287
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700288 SectionGroupTriple T(Section, COMDATSymName, Selection);
289 auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
Stephen Hinesdce4a402014-05-29 02:49:00 -0700290 auto Iter = IterBool.first;
291 if (!IterBool.second)
Bill Wendling0ae07092013-11-27 06:44:18 +0000292 return Iter->second;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000293
Stephen Hinesdce4a402014-05-29 02:49:00 -0700294 const MCSymbol *COMDATSymbol = nullptr;
Bill Wendling0ae07092013-11-27 06:44:18 +0000295 if (!COMDATSymName.empty())
296 COMDATSymbol = GetOrCreateSymbol(COMDATSymName);
297
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700298 StringRef CachedName = std::get<0>(Iter->first);
299 MCSectionCOFF *Result = new (*this)
300 MCSectionCOFF(CachedName, Characteristics, COMDATSymbol, Selection, Kind);
Bill Wendling0ae07092013-11-27 06:44:18 +0000301
302 Iter->second = Result;
Chris Lattnereb40a0f2010-05-07 17:17:41 +0000303 return Result;
304}
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000305
Bill Wendling0ae07092013-11-27 06:44:18 +0000306const MCSectionCOFF *
307MCContext::getCOFFSection(StringRef Section, unsigned Characteristics,
308 SectionKind Kind) {
309 return getCOFFSection(Section, Characteristics, Kind, "", 0);
310}
311
Nico Rieck80646282013-07-06 12:13:10 +0000312const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700313 SectionGroupTriple T(Section, "", 0);
314 auto Iter = COFFUniquingMap.find(T);
Stephen Hinesdce4a402014-05-29 02:49:00 -0700315 if (Iter == COFFUniquingMap.end())
316 return nullptr;
Bill Wendling0ae07092013-11-27 06:44:18 +0000317 return Iter->second;
Nico Rieck80646282013-07-06 12:13:10 +0000318}
319
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000320//===----------------------------------------------------------------------===//
321// Dwarf Management
322//===----------------------------------------------------------------------===//
323
324/// GetDwarfFile - takes a file name an number to place in the dwarf file and
325/// directory tables. If the file number has already been allocated it is an
326/// error and zero is returned and the client reports the error, else the
327/// allocated file number is returned. The file numbers may be in any order.
Nick Lewycky44d798d2011-10-17 23:05:28 +0000328unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
Manman Ren3de61b42013-03-07 01:42:00 +0000329 unsigned FileNumber, unsigned CUID) {
Stephen Hines36b56882014-04-23 16:57:46 -0700330 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
331 return Table.getFile(Directory, FileName, FileNumber);
Kevin Enderby7cbf73a2010-07-28 20:55:35 +0000332}
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000333
Kevin Enderby3f55c242010-10-04 20:17:24 +0000334/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000335/// currently is assigned and false otherwise.
Manman Ren3de61b42013-03-07 01:42:00 +0000336bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
Stephen Hines36b56882014-04-23 16:57:46 -0700337 const SmallVectorImpl<MCDwarfFile>& MCDwarfFiles = getMCDwarfFiles(CUID);
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000338 if(FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
339 return false;
340
Stephen Hines36b56882014-04-23 16:57:46 -0700341 return !MCDwarfFiles[FileNumber].Name.empty();
Kevin Enderbyc1840b32010-08-24 20:32:42 +0000342}
Jim Grosbach82f4ce52012-01-26 23:20:11 +0000343
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700344/// finalizeDwarfSections - Emit end symbols for each non-empty code section.
345/// Also remove empty sections from SectionStartEndSyms, to avoid generating
346/// useless debug info for them.
347void MCContext::finalizeDwarfSections(MCStreamer &MCOS) {
348 MCContext &context = MCOS.getContext();
349
350 auto sec = SectionStartEndSyms.begin();
351 while (sec != SectionStartEndSyms.end()) {
352 assert(sec->second.first && "Start symbol must be set by now");
353 MCOS.SwitchSection(sec->first);
354 if (MCOS.mayHaveInstructions()) {
355 MCSymbol *SectionEndSym = context.CreateTempSymbol();
356 MCOS.EmitLabel(SectionEndSym);
357 sec->second.second = SectionEndSym;
358 ++sec;
359 } else {
360 MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *> >::iterator
361 to_erase = sec;
362 sec = SectionStartEndSyms.erase(to_erase);
363 }
364 }
365}
366
Stephen Hinesdce4a402014-05-29 02:49:00 -0700367void MCContext::FatalError(SMLoc Loc, const Twine &Msg) const {
Jim Grosbach82f4ce52012-01-26 23:20:11 +0000368 // If we have a source manager and a location, use it. Otherwise just
369 // use the generic report_fatal_error().
370 if (!SrcMgr || Loc == SMLoc())
Stephen Hines36b56882014-04-23 16:57:46 -0700371 report_fatal_error(Msg, false);
Jim Grosbach82f4ce52012-01-26 23:20:11 +0000372
373 // Use the source manager to print the message.
374 SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
375
376 // If we reached here, we are failing ungracefully. Run the interrupt handlers
377 // to make sure any special cleanups get done, in particular that we remove
378 // files registered with RemoveFileOnSignal.
379 sys::RunInterruptHandlers();
380 exit(1);
381}