blob: 960a0716e93e2a148861aa28563e89d5a7c0ea5e [file] [log] [blame]
Daniel Dunbarbadeace2009-06-23 23:39:15 +00001//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
Daniel Dunbarca29e4d2009-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 Lattner86dfd732009-10-19 22:49:00 +000011#include "llvm/ADT/SmallString.h"
12#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-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 Espindolaaea49582011-01-23 04:28:49 +000022#include "llvm/Support/ELF.h"
Jim Grosbachb18b4092012-01-26 23:20:11 +000023#include "llvm/Support/ErrorHandling.h"
Rafael Espindolaef03b9f2013-06-14 20:26:58 +000024#include "llvm/Support/FileSystem.h"
Eric Christopher906da232012-12-18 00:31:01 +000025#include "llvm/Support/MemoryBuffer.h"
Jim Grosbachb18b4092012-01-26 23:20:11 +000026#include "llvm/Support/Signals.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000027#include "llvm/Support/SourceMgr.h"
David Blaikie15b25df2013-10-22 23:41:52 +000028#include <map>
29
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000030using namespace llvm;
31
Bill Wendlingbc07a892013-06-18 07:20:20 +000032MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
Pedro Artigase84b13f2012-12-06 22:12:44 +000033 const MCObjectFileInfo *mofi, const SourceMgr *mgr,
David Blaikie7400a972014-03-27 20:45:58 +000034 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),
David Blaikie6f687582014-05-01 19:55:34 +000038 GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4),
David Blaikie7400a972014-03-27 20:45:58 +000039 AllowTemporaryLabels(true), DwarfCompileUnitID(0),
40 AutoReset(DoAutoReset) {
Pedro Artigas7212ee42012-12-12 22:59:46 +000041
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +000042 std::error_code EC = llvm::sys::fs::current_path(CompilationDir);
Andrew Trick32591d32013-12-10 04:39:09 +000043 if (EC)
44 CompilationDir.clear();
Rafael Espindolaef03b9f2013-06-14 20:26:58 +000045
Kevin Enderbye233dda2010-06-28 21:45:58 +000046 SecureLogFile = getenv("AS_SECURE_LOG_FILE");
Craig Topperbb694de2014-04-13 04:57:38 +000047 SecureLog = nullptr;
Kevin Enderbye233dda2010-06-28 21:45:58 +000048 SecureLogUsed = false;
Eric Christopher906da232012-12-18 00:31:01 +000049
Alp Tokera55b95b2014-07-06 10:33:31 +000050 if (SrcMgr && SrcMgr->getNumBuffers())
51 MainFileName =
52 SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())->getBufferIdentifier();
Pedro Artigase84b13f2012-12-06 22:12:44 +000053}
54
55MCContext::~MCContext() {
56
Pedro Artigas7212ee42012-12-12 22:59:46 +000057 if (AutoReset)
58 reset();
Pedro Artigase84b13f2012-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.
Andrew Trick1c6a4c32013-12-10 04:39:05 +000062
Pedro Artigase84b13f2012-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 Artigas7212ee42012-12-12 22:59:46 +000071void MCContext::reset() {
Pedro Artigase84b13f2012-12-06 22:12:44 +000072 UsedNames.clear();
73 Symbols.clear();
74 Allocator.Reset();
75 Instances.clear();
David Blaikied9012ba2014-03-13 21:59:51 +000076 MCDwarfLineTablesCUMap.clear();
Pedro Artigase84b13f2012-12-06 22:12:44 +000077 MCGenDwarfLabelEntries.clear();
78 DwarfDebugFlags = StringRef();
Pedro Artigas7ba2edc2013-02-20 00:10:29 +000079 DwarfCompileUnitID = 0;
Pedro Artigase84b13f2012-12-06 22:12:44 +000080 CurrentDwarfLoc = MCDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0);
Michael J. Spencerf13f4422010-11-26 04:16:08 +000081
David Blaikie9ec32122014-04-10 23:55:11 +000082 MachOUniquingMap.clear();
83 ELFUniquingMap.clear();
84 COFFUniquingMap.clear();
Pedro Artigas7212ee42012-12-12 22:59:46 +000085
86 NextUniqueID = 0;
87 AllowTemporaryLabels = true;
88 DwarfLocSeen = false;
89 GenDwarfForAssembly = false;
90 GenDwarfFileNumber = 0;
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000091}
92
Chris Lattner20731122010-04-08 20:30:37 +000093//===----------------------------------------------------------------------===//
94// Symbol Manipulation
95//===----------------------------------------------------------------------===//
96
Chris Lattner98970432010-03-30 18:10:53 +000097MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
Chris Lattnerb973ea82010-03-10 01:29:27 +000098 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
Michael J. Spencerf13f4422010-11-26 04:16:08 +000099
Chris Lattner13348762010-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 Espindola5fe5f452010-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 Dunbar4ee0d032011-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 Wendlingbc07a892013-06-18 07:20:20 +0000117 isTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000118
119 StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name);
120 if (NameEntry->getValue()) {
Alp Tokerf907b892013-12-05 05:44:44 +0000121 assert(isTemporary && "Cannot rename non-temporary symbols");
Benjamin Kramer2b6c96b2011-04-09 11:26:27 +0000122 SmallString<128> NewName = Name;
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000123 do {
Benjamin Kramer2b6c96b2011-04-09 11:26:27 +0000124 NewName.resize(Name.size());
125 raw_svector_ostream(NewName) << NextUniqueID++;
126 NameEntry = &UsedNames.GetOrCreateValue(NewName);
Rafael Espindola5fe5f452010-12-01 20:46:11 +0000127 } while (NameEntry->getValue());
128 }
129 NameEntry->setValue(true);
Chris Lattner3f5738d2009-06-24 04:31:49 +0000130
Chris Lattner13348762010-03-15 06:15:35 +0000131 // Ok, the entry doesn't already exist. Have the MCSymbol object itself refer
Rafael Espindola5fe5f452010-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 Lattner3f5738d2009-06-24 04:31:49 +0000136}
137
Chris Lattner98970432010-03-30 18:10:53 +0000138MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
Chris Lattner86dfd732009-10-19 22:49:00 +0000139 SmallString<128> NameSV;
David Blaikie8e5283a2013-12-03 18:18:28 +0000140 return GetOrCreateSymbol(Name.toStringRef(NameSV));
Chris Lattner86dfd732009-10-19 22:49:00 +0000141}
142
Tim Northoverc3988b42014-03-29 07:05:06 +0000143MCSymbol *MCContext::CreateLinkerPrivateTempSymbol() {
Alp Tokere69170a2014-06-26 22:52:05 +0000144 SmallString<128> NameSV;
145 raw_svector_ostream(NameSV)
146 << MAI->getLinkerPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
147 return CreateSymbol(NameSV);
Tim Northoverc3988b42014-03-29 07:05:06 +0000148}
149
Chris Lattner073d8172010-03-14 08:23:30 +0000150MCSymbol *MCContext::CreateTempSymbol() {
Alp Tokere69170a2014-06-26 22:52:05 +0000151 SmallString<128> NameSV;
152 raw_svector_ostream(NameSV)
153 << MAI->getPrivateGlobalPrefix() << "tmp" << NextUniqueID++;
154 return CreateSymbol(NameSV);
Chris Lattner073d8172010-03-14 08:23:30 +0000155}
156
Rafael Espindola4269b9e2014-03-13 18:09:26 +0000157unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
Benjamin Kramerab7be752010-05-18 12:15:34 +0000158 MCLabel *&Label = Instances[LocalLabelVal];
159 if (!Label)
160 Label = new (*this) MCLabel(0);
161 return Label->incInstance();
Kevin Enderby0510b482010-05-17 23:08:19 +0000162}
163
Rafael Espindola4269b9e2014-03-13 18:09:26 +0000164unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
Benjamin Kramerab7be752010-05-18 12:15:34 +0000165 MCLabel *&Label = Instances[LocalLabelVal];
166 if (!Label)
167 Label = new (*this) MCLabel(0);
168 return Label->getInstance();
Kevin Enderby0510b482010-05-17 23:08:19 +0000169}
170
Rafael Espindola4269b9e2014-03-13 18:09:26 +0000171MCSymbol *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 Enderby0510b482010-05-17 23:08:19 +0000177}
Rafael Espindola4269b9e2014-03-13 18:09:26 +0000178
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 Enderby0510b482010-05-17 23:08:19 +0000190}
191
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000192MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
Daniel Dunbarca29e4d2009-06-23 22:01:43 +0000193 return Symbols.lookup(Name);
194}
Chris Lattner20731122010-04-08 20:30:37 +0000195
Roman Divacky0be33592012-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 Lattner20731122010-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. Spencerf13f4422010-11-26 04:16:08 +0000210
Chris Lattner20731122010-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. Spencerf13f4422010-11-26 04:16:08 +0000214
Chris Lattner20731122010-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. Spencerf13f4422010-11-26 04:16:08 +0000220
Chris Lattner20731122010-04-08 20:30:37 +0000221 // Do the lookup, if we have a hit, return it.
David Blaikie9ec32122014-04-10 23:55:11 +0000222 const MCSectionMachO *&Entry = MachOUniquingMap[Name.str()];
Chris Lattner20731122010-04-08 20:30:37 +0000223 if (Entry) return Entry;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000224
Chris Lattner20731122010-04-08 20:30:37 +0000225 // Otherwise, return a new section.
Chris Lattner5418dd52010-04-08 21:26:26 +0000226 return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes,
227 Reserved2, Kind);
Chris Lattner20731122010-04-08 20:30:37 +0000228}
Chris Lattner5418dd52010-04-08 21:26:26 +0000229
Rafael Espindola36ef57d2010-11-10 19:05:07 +0000230const MCSectionELF *MCContext::
Chris Lattner5418dd52010-04-08 21:26:26 +0000231getELFSection(StringRef Section, unsigned Type, unsigned Flags,
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000232 SectionKind Kind) {
233 return getELFSection(Section, Type, Flags, Kind, 0, "");
234}
235
David Blaikie8019bf82014-04-10 21:53:53 +0000236void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) {
David Blaikie8019bf82014-04-10 21:53:53 +0000237 StringRef GroupName;
238 if (const MCSymbol *Group = Section->getGroup())
239 GroupName = Group->getName();
240
David Blaikie9ec32122014-04-10 23:55:11 +0000241 ELFUniquingMap.erase(SectionGroupPair(Section->getSectionName(), GroupName));
242 auto I =
243 ELFUniquingMap.insert(std::make_pair(SectionGroupPair(Name, GroupName),
244 Section)).first;
David Blaikieb60e61c2014-04-11 22:49:14 +0000245 StringRef CachedName = I->first.first;
246 const_cast<MCSectionELF*>(Section)->setSectionName(CachedName);
David Blaikie8019bf82014-04-10 21:53:53 +0000247}
248
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000249const MCSectionELF *MCContext::
250getELFSection(StringRef Section, unsigned Type, unsigned Flags,
251 SectionKind Kind, unsigned EntrySize, StringRef Group) {
Chris Lattner5418dd52010-04-08 21:26:26 +0000252 // Do the lookup, if we have a hit, return it.
David Blaikie9ec32122014-04-10 23:55:11 +0000253 auto IterBool = ELFUniquingMap.insert(
Craig Topperbb694de2014-04-13 04:57:38 +0000254 std::make_pair(SectionGroupPair(Section, Group), nullptr));
David Blaikie9ec32122014-04-10 23:55:11 +0000255 auto &Entry = *IterBool.first;
256 if (!IterBool.second) return Entry.second;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000257
Jan Wen Voungefbdbe52010-09-30 05:59:22 +0000258 // Possibly refine the entry size first.
259 if (!EntrySize) {
260 EntrySize = MCSectionELF::DetermineEntrySize(Kind);
261 }
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000262
Craig Topperbb694de2014-04-13 04:57:38 +0000263 MCSymbol *GroupSym = nullptr;
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000264 if (!Group.empty())
265 GroupSym = GetOrCreateSymbol(Group);
266
David Blaikieb60e61c2014-04-11 22:49:14 +0000267 StringRef CachedName = Entry.first.first;
268 MCSectionELF *Result = new (*this)
269 MCSectionELF(CachedName, Type, Flags, Kind, EntrySize, GroupSym);
David Blaikie9ec32122014-04-10 23:55:11 +0000270 Entry.second = Result;
Chris Lattner5418dd52010-04-08 21:26:26 +0000271 return Result;
272}
273
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000274const MCSectionELF *MCContext::CreateELFGroupSection() {
275 MCSectionELF *Result =
Rafael Espindolaaea49582011-01-23 04:28:49 +0000276 new (*this) MCSectionELF(".group", ELF::SHT_GROUP, 0,
Craig Topperbb694de2014-04-13 04:57:38 +0000277 SectionKind::getReadOnly(), 4, nullptr);
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000278 return Result;
279}
280
Rafael Espindola0766ae02014-06-06 19:26:12 +0000281const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
282 unsigned Characteristics,
283 SectionKind Kind,
284 StringRef COMDATSymName,
285 int Selection) {
Chris Lattner87cffa92010-05-07 17:17:41 +0000286 // Do the lookup, if we have a hit, return it.
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000287
David Majnemerc57d0382014-06-27 17:19:44 +0000288 SectionGroupTriple T(Section, COMDATSymName, Selection);
289 auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
David Blaikie9ec32122014-04-10 23:55:11 +0000290 auto Iter = IterBool.first;
291 if (!IterBool.second)
Rafael Espindola60ec3832013-11-19 19:52:52 +0000292 return Iter->second;
Michael J. Spencerf13f4422010-11-26 04:16:08 +0000293
Craig Topperbb694de2014-04-13 04:57:38 +0000294 const MCSymbol *COMDATSymbol = nullptr;
Rafael Espindola60ec3832013-11-19 19:52:52 +0000295 if (!COMDATSymName.empty())
296 COMDATSymbol = GetOrCreateSymbol(COMDATSymName);
297
David Majnemerc57d0382014-06-27 17:19:44 +0000298 StringRef CachedName = std::get<0>(Iter->first);
Rafael Espindola0766ae02014-06-06 19:26:12 +0000299 MCSectionCOFF *Result = new (*this)
300 MCSectionCOFF(CachedName, Characteristics, COMDATSymbol, Selection, Kind);
Rafael Espindola60ec3832013-11-19 19:52:52 +0000301
302 Iter->second = Result;
Chris Lattner87cffa92010-05-07 17:17:41 +0000303 return Result;
304}
Kevin Enderbye5930f12010-07-28 20:55:35 +0000305
Rafael Espindola60ec3832013-11-19 19:52:52 +0000306const MCSectionCOFF *
307MCContext::getCOFFSection(StringRef Section, unsigned Characteristics,
308 SectionKind Kind) {
309 return getCOFFSection(Section, Characteristics, Kind, "", 0);
310}
311
Nico Riecka37acf72013-07-06 12:13:10 +0000312const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
David Majnemerc57d0382014-06-27 17:19:44 +0000313 SectionGroupTriple T(Section, "", 0);
314 auto Iter = COFFUniquingMap.find(T);
David Blaikie9ec32122014-04-10 23:55:11 +0000315 if (Iter == COFFUniquingMap.end())
Craig Topperbb694de2014-04-13 04:57:38 +0000316 return nullptr;
Rafael Espindola60ec3832013-11-19 19:52:52 +0000317 return Iter->second;
Nico Riecka37acf72013-07-06 12:13:10 +0000318}
319
Kevin Enderbye5930f12010-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 Lewycky40f8f2f2011-10-17 23:05:28 +0000328unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
Manman Ren1e427202013-03-07 01:42:00 +0000329 unsigned FileNumber, unsigned CUID) {
David Blaikied9012ba2014-03-13 21:59:51 +0000330 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
David Blaikie498589c2014-03-13 19:15:04 +0000331 return Table.getFile(Directory, FileName, FileNumber);
Kevin Enderbye5930f12010-07-28 20:55:35 +0000332}
Kevin Enderby1264b7c2010-08-24 20:32:42 +0000333
Kevin Enderbya68d0042010-10-04 20:17:24 +0000334/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
Kevin Enderby1264b7c2010-08-24 20:32:42 +0000335/// currently is assigned and false otherwise.
Manman Ren1e427202013-03-07 01:42:00 +0000336bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
David Blaikiea55ddad2014-03-13 18:55:04 +0000337 const SmallVectorImpl<MCDwarfFile>& MCDwarfFiles = getMCDwarfFiles(CUID);
Kevin Enderby1264b7c2010-08-24 20:32:42 +0000338 if(FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
339 return false;
340
David Blaikiea55ddad2014-03-13 18:55:04 +0000341 return !MCDwarfFiles[FileNumber].Name.empty();
Kevin Enderby1264b7c2010-08-24 20:32:42 +0000342}
Jim Grosbachb18b4092012-01-26 23:20:11 +0000343
Oliver Stannard8b273082014-06-19 15:52:37 +0000344/// 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
Kevin Enderby7ee97ce2014-04-22 21:42:18 +0000367void MCContext::FatalError(SMLoc Loc, const Twine &Msg) const {
Jim Grosbachb18b4092012-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())
Jim Grosbach9a3284f2014-03-14 22:41:58 +0000371 report_fatal_error(Msg, false);
Jim Grosbachb18b4092012-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}