Daniel Dunbar | badeace | 2009-06-23 23:39:15 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===// |
Daniel Dunbar | ca29e4d | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 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 | |
| 10 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 86dfd73 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/SmallString.h" |
| 12 | #include "llvm/ADT/Twine.h" |
Rafael Espindola | 24d285d | 2015-05-26 00:32:28 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCAssembler.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmInfo.h" |
| 15 | #include "llvm/MC/MCDwarf.h" |
| 16 | #include "llvm/MC/MCLabel.h" |
| 17 | #include "llvm/MC/MCObjectFileInfo.h" |
| 18 | #include "llvm/MC/MCRegisterInfo.h" |
| 19 | #include "llvm/MC/MCSectionCOFF.h" |
| 20 | #include "llvm/MC/MCSectionELF.h" |
| 21 | #include "llvm/MC/MCSectionMachO.h" |
Pete Cooper | ef21bd4 | 2015-03-04 01:24:11 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCStreamer.h" |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCSymbolELF.h" |
Rafael Espindola | aea4958 | 2011-01-23 04:28:49 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ELF.h" |
Jim Grosbach | b18b409 | 2012-01-26 23:20:11 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Rafael Espindola | ef03b9f | 2013-06-14 20:26:58 +0000 | [diff] [blame] | 26 | #include "llvm/Support/FileSystem.h" |
Eric Christopher | 906da23 | 2012-12-18 00:31:01 +0000 | [diff] [blame] | 27 | #include "llvm/Support/MemoryBuffer.h" |
Jim Grosbach | b18b409 | 2012-01-26 23:20:11 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Signals.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 29 | #include "llvm/Support/SourceMgr.h" |
David Blaikie | 15b25df | 2013-10-22 23:41:52 +0000 | [diff] [blame] | 30 | #include <map> |
| 31 | |
Daniel Dunbar | ca29e4d | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 32 | using namespace llvm; |
| 33 | |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 34 | MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri, |
Pedro Artigas | e84b13f | 2012-12-06 22:12:44 +0000 | [diff] [blame] | 35 | const MCObjectFileInfo *mofi, const SourceMgr *mgr, |
David Blaikie | 7400a97 | 2014-03-27 20:45:58 +0000 | [diff] [blame] | 36 | bool DoAutoReset) |
| 37 | : SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi), Allocator(), |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 38 | Symbols(Allocator), UsedNames(Allocator), |
David Blaikie | 7400a97 | 2014-03-27 20:45:58 +0000 | [diff] [blame] | 39 | CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), DwarfLocSeen(false), |
David Blaikie | 6f68758 | 2014-05-01 19:55:34 +0000 | [diff] [blame] | 40 | GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4), |
David Blaikie | 7400a97 | 2014-03-27 20:45:58 +0000 | [diff] [blame] | 41 | AllowTemporaryLabels(true), DwarfCompileUnitID(0), |
| 42 | AutoReset(DoAutoReset) { |
Pedro Artigas | 7212ee4 | 2012-12-12 22:59:46 +0000 | [diff] [blame] | 43 | |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 44 | std::error_code EC = llvm::sys::fs::current_path(CompilationDir); |
Andrew Trick | 32591d3 | 2013-12-10 04:39:09 +0000 | [diff] [blame] | 45 | if (EC) |
| 46 | CompilationDir.clear(); |
Rafael Espindola | ef03b9f | 2013-06-14 20:26:58 +0000 | [diff] [blame] | 47 | |
Kevin Enderby | e233dda | 2010-06-28 21:45:58 +0000 | [diff] [blame] | 48 | SecureLogFile = getenv("AS_SECURE_LOG_FILE"); |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 49 | SecureLog = nullptr; |
Kevin Enderby | e233dda | 2010-06-28 21:45:58 +0000 | [diff] [blame] | 50 | SecureLogUsed = false; |
Eric Christopher | 906da23 | 2012-12-18 00:31:01 +0000 | [diff] [blame] | 51 | |
Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 52 | if (SrcMgr && SrcMgr->getNumBuffers()) |
| 53 | MainFileName = |
| 54 | SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())->getBufferIdentifier(); |
Pedro Artigas | e84b13f | 2012-12-06 22:12:44 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | MCContext::~MCContext() { |
Pedro Artigas | 7212ee4 | 2012-12-12 22:59:46 +0000 | [diff] [blame] | 58 | if (AutoReset) |
| 59 | reset(); |
Pedro Artigas | e84b13f | 2012-12-06 22:12:44 +0000 | [diff] [blame] | 60 | |
| 61 | // NOTE: The symbols are all allocated out of a bump pointer allocator, |
| 62 | // we don't need to free them here. |
Andrew Trick | 1c6a4c3 | 2013-12-10 04:39:05 +0000 | [diff] [blame] | 63 | |
Pedro Artigas | e84b13f | 2012-12-06 22:12:44 +0000 | [diff] [blame] | 64 | // If the stream for the .secure_log_unique directive was created free it. |
Jim Grosbach | 008359a | 2015-05-18 18:43:23 +0000 | [diff] [blame] | 65 | delete (raw_ostream *)SecureLog; |
Pedro Artigas | e84b13f | 2012-12-06 22:12:44 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | //===----------------------------------------------------------------------===// |
| 69 | // Module Lifetime Management |
| 70 | //===----------------------------------------------------------------------===// |
| 71 | |
Pedro Artigas | 7212ee4 | 2012-12-12 22:59:46 +0000 | [diff] [blame] | 72 | void MCContext::reset() { |
Rafael Espindola | ed34d58 | 2015-05-26 01:52:19 +0000 | [diff] [blame] | 73 | // Call the destructors so the fragments are freed |
| 74 | for (auto &I : ELFUniquingMap) |
| 75 | I.second->~MCSectionELF(); |
| 76 | for (auto &I : COFFUniquingMap) |
| 77 | I.second->~MCSectionCOFF(); |
| 78 | for (auto &I : MachOUniquingMap) |
| 79 | I.second->~MCSectionMachO(); |
| 80 | |
Pedro Artigas | e84b13f | 2012-12-06 22:12:44 +0000 | [diff] [blame] | 81 | UsedNames.clear(); |
| 82 | Symbols.clear(); |
| 83 | Allocator.Reset(); |
| 84 | Instances.clear(); |
Yaron Keren | 559b47d | 2014-09-17 09:25:36 +0000 | [diff] [blame] | 85 | CompilationDir.clear(); |
| 86 | MainFileName.clear(); |
David Blaikie | d9012ba | 2014-03-13 21:59:51 +0000 | [diff] [blame] | 87 | MCDwarfLineTablesCUMap.clear(); |
Rafael Espindola | e074679 | 2015-05-21 16:52:32 +0000 | [diff] [blame] | 88 | SectionsForRanges.clear(); |
Pedro Artigas | e84b13f | 2012-12-06 22:12:44 +0000 | [diff] [blame] | 89 | MCGenDwarfLabelEntries.clear(); |
| 90 | DwarfDebugFlags = StringRef(); |
Pedro Artigas | 7ba2edc | 2013-02-20 00:10:29 +0000 | [diff] [blame] | 91 | DwarfCompileUnitID = 0; |
Jim Grosbach | 008359a | 2015-05-18 18:43:23 +0000 | [diff] [blame] | 92 | CurrentDwarfLoc = MCDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0); |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 93 | |
David Blaikie | 9ec3212 | 2014-04-10 23:55:11 +0000 | [diff] [blame] | 94 | MachOUniquingMap.clear(); |
| 95 | ELFUniquingMap.clear(); |
| 96 | COFFUniquingMap.clear(); |
Pedro Artigas | 7212ee4 | 2012-12-12 22:59:46 +0000 | [diff] [blame] | 97 | |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 98 | NextID.clear(); |
Pedro Artigas | 7212ee4 | 2012-12-12 22:59:46 +0000 | [diff] [blame] | 99 | AllowTemporaryLabels = true; |
| 100 | DwarfLocSeen = false; |
| 101 | GenDwarfForAssembly = false; |
| 102 | GenDwarfFileNumber = 0; |
Daniel Dunbar | ca29e4d | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Chris Lattner | 2073112 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 105 | //===----------------------------------------------------------------------===// |
| 106 | // Symbol Manipulation |
| 107 | //===----------------------------------------------------------------------===// |
| 108 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 109 | MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) { |
Yaron Keren | 1ee89fc | 2015-03-17 09:51:17 +0000 | [diff] [blame] | 110 | SmallString<128> NameSV; |
| 111 | StringRef NameRef = Name.toStringRef(NameSV); |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 112 | |
Yaron Keren | 1ee89fc | 2015-03-17 09:51:17 +0000 | [diff] [blame] | 113 | assert(!NameRef.empty() && "Normal symbols cannot be unnamed!"); |
Rafael Espindola | 5fe5f45 | 2010-12-01 20:46:11 +0000 | [diff] [blame] | 114 | |
Yaron Keren | 1ee89fc | 2015-03-17 09:51:17 +0000 | [diff] [blame] | 115 | MCSymbol *&Sym = Symbols[NameRef]; |
David Blaikie | 5106ce7 | 2014-11-19 05:49:42 +0000 | [diff] [blame] | 116 | if (!Sym) |
Rafael Espindola | 3e9e72a | 2015-06-02 22:52:13 +0000 | [diff] [blame^] | 117 | Sym = createSymbol(NameRef, false, false); |
Rafael Espindola | 5fe5f45 | 2010-12-01 20:46:11 +0000 | [diff] [blame] | 118 | |
Rafael Espindola | 5fe5f45 | 2010-12-01 20:46:11 +0000 | [diff] [blame] | 119 | return Sym; |
| 120 | } |
| 121 | |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 122 | MCSymbolELF *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) { |
| 123 | MCSymbolELF *&Sym = SectionSymbols[&Section]; |
Rafael Espindola | b661302 | 2014-10-17 01:48:58 +0000 | [diff] [blame] | 124 | if (Sym) |
| 125 | return Sym; |
| 126 | |
| 127 | StringRef Name = Section.getSectionName(); |
| 128 | |
David Blaikie | 5106ce7 | 2014-11-19 05:49:42 +0000 | [diff] [blame] | 129 | MCSymbol *&OldSym = Symbols[Name]; |
Rafael Espindola | b661302 | 2014-10-17 01:48:58 +0000 | [diff] [blame] | 130 | if (OldSym && OldSym->isUndefined()) { |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 131 | Sym = cast<MCSymbolELF>(OldSym); |
| 132 | return Sym; |
Rafael Espindola | b661302 | 2014-10-17 01:48:58 +0000 | [diff] [blame] | 133 | } |
| 134 | |
David Blaikie | 5106ce7 | 2014-11-19 05:49:42 +0000 | [diff] [blame] | 135 | auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first; |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 136 | Sym = new (*this) MCSymbolELF(&*NameIter, /*isTemporary*/ false); |
Rafael Espindola | b661302 | 2014-10-17 01:48:58 +0000 | [diff] [blame] | 137 | |
David Blaikie | 5106ce7 | 2014-11-19 05:49:42 +0000 | [diff] [blame] | 138 | if (!OldSym) |
| 139 | OldSym = Sym; |
Rafael Espindola | b661302 | 2014-10-17 01:48:58 +0000 | [diff] [blame] | 140 | |
| 141 | return Sym; |
| 142 | } |
| 143 | |
Reid Kleckner | cfb9ce5 | 2015-03-05 18:26:34 +0000 | [diff] [blame] | 144 | MCSymbol *MCContext::getOrCreateFrameAllocSymbol(StringRef FuncName, |
| 145 | unsigned Idx) { |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 146 | return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName + |
Reid Kleckner | cfb9ce5 | 2015-03-05 18:26:34 +0000 | [diff] [blame] | 147 | "$frame_escape_" + Twine(Idx)); |
Reid Kleckner | e9b8931 | 2015-01-13 00:48:10 +0000 | [diff] [blame] | 148 | } |
| 149 | |
David Majnemer | a225a19 | 2015-03-31 22:35:44 +0000 | [diff] [blame] | 150 | MCSymbol *MCContext::getOrCreateParentFrameOffsetSymbol(StringRef FuncName) { |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 151 | return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName + |
David Majnemer | a225a19 | 2015-03-31 22:35:44 +0000 | [diff] [blame] | 152 | "$parent_frame_offset"); |
| 153 | } |
| 154 | |
Reid Kleckner | 2632f0d | 2015-05-20 23:08:04 +0000 | [diff] [blame] | 155 | MCSymbol *MCContext::getOrCreateLSDASymbol(StringRef FuncName) { |
| 156 | return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "__ehtable$" + |
| 157 | FuncName); |
| 158 | } |
| 159 | |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 160 | MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name, |
| 161 | bool IsTemporary) { |
| 162 | bool IsELF = MOFI && MOFI->getObjectFileType() == MCObjectFileInfo::IsELF; |
| 163 | if (IsELF) |
| 164 | return new (*this) MCSymbolELF(Name, IsTemporary); |
| 165 | return new (*this) MCSymbol(false, Name, IsTemporary); |
| 166 | } |
| 167 | |
Rafael Espindola | 3e9e72a | 2015-06-02 22:52:13 +0000 | [diff] [blame^] | 168 | MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix, |
| 169 | bool IsTemporary) { |
| 170 | if (IsTemporary && !UseNamesOnTempLabels) |
| 171 | return createSymbolImpl(nullptr, true); |
| 172 | |
| 173 | // Determine whether this is an user writter assembler temporary or normal |
| 174 | // label, if used. |
| 175 | IsTemporary = false; |
Daniel Dunbar | 4ee0d03 | 2011-03-28 22:49:15 +0000 | [diff] [blame] | 176 | if (AllowTemporaryLabels) |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 177 | IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix()); |
Rafael Espindola | 5fe5f45 | 2010-12-01 20:46:11 +0000 | [diff] [blame] | 178 | |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 179 | SmallString<128> NewName = Name; |
| 180 | bool AddSuffix = AlwaysAddSuffix; |
| 181 | unsigned &NextUniqueID = NextID[Name]; |
| 182 | for (;;) { |
| 183 | if (AddSuffix) { |
Benjamin Kramer | 2b6c96b | 2011-04-09 11:26:27 +0000 | [diff] [blame] | 184 | NewName.resize(Name.size()); |
| 185 | raw_svector_ostream(NewName) << NextUniqueID++; |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 186 | } |
| 187 | auto NameEntry = UsedNames.insert(std::make_pair(NewName, true)); |
| 188 | if (NameEntry.second) { |
| 189 | // Ok, we found a name. Have the MCSymbol object itself refer to the copy |
| 190 | // of the string that is embedded in the UsedNames entry. |
Rafael Espindola | a869576 | 2015-06-02 00:25:12 +0000 | [diff] [blame] | 191 | return createSymbolImpl(&*NameEntry.first, IsTemporary); |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 192 | } |
| 193 | assert(IsTemporary && "Cannot rename non-temporary symbols"); |
| 194 | AddSuffix = true; |
Rafael Espindola | 5fe5f45 | 2010-12-01 20:46:11 +0000 | [diff] [blame] | 195 | } |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 196 | llvm_unreachable("Infinite loop"); |
Chris Lattner | 3f5738d | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 199 | MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) { |
Rafael Espindola | 629cdba | 2015-02-27 18:18:39 +0000 | [diff] [blame] | 200 | SmallString<128> NameSV; |
| 201 | raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name; |
Rafael Espindola | 3e9e72a | 2015-06-02 22:52:13 +0000 | [diff] [blame^] | 202 | return createSymbol(NameSV, AlwaysAddSuffix, true); |
Rafael Espindola | 629cdba | 2015-02-27 18:18:39 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 205 | MCSymbol *MCContext::createLinkerPrivateTempSymbol() { |
Alp Toker | e69170a | 2014-06-26 22:52:05 +0000 | [diff] [blame] | 206 | SmallString<128> NameSV; |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 207 | raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp"; |
Rafael Espindola | 3e9e72a | 2015-06-02 22:52:13 +0000 | [diff] [blame^] | 208 | return createSymbol(NameSV, true, false); |
Tim Northover | c3988b4 | 2014-03-29 07:05:06 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 211 | MCSymbol *MCContext::createTempSymbol() { |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 212 | return createTempSymbol("tmp", true); |
Chris Lattner | 073d817 | 2010-03-14 08:23:30 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Rafael Espindola | 4269b9e | 2014-03-13 18:09:26 +0000 | [diff] [blame] | 215 | unsigned MCContext::NextInstance(unsigned LocalLabelVal) { |
Benjamin Kramer | ab7be75 | 2010-05-18 12:15:34 +0000 | [diff] [blame] | 216 | MCLabel *&Label = Instances[LocalLabelVal]; |
| 217 | if (!Label) |
| 218 | Label = new (*this) MCLabel(0); |
| 219 | return Label->incInstance(); |
Kevin Enderby | 0510b48 | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Rafael Espindola | 4269b9e | 2014-03-13 18:09:26 +0000 | [diff] [blame] | 222 | unsigned MCContext::GetInstance(unsigned LocalLabelVal) { |
Benjamin Kramer | ab7be75 | 2010-05-18 12:15:34 +0000 | [diff] [blame] | 223 | MCLabel *&Label = Instances[LocalLabelVal]; |
| 224 | if (!Label) |
| 225 | Label = new (*this) MCLabel(0); |
| 226 | return Label->getInstance(); |
Kevin Enderby | 0510b48 | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Rafael Espindola | 4269b9e | 2014-03-13 18:09:26 +0000 | [diff] [blame] | 229 | MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal, |
| 230 | unsigned Instance) { |
| 231 | MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)]; |
| 232 | if (!Sym) |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 233 | Sym = createTempSymbol(); |
Rafael Espindola | 4269b9e | 2014-03-13 18:09:26 +0000 | [diff] [blame] | 234 | return Sym; |
Kevin Enderby | 0510b48 | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 235 | } |
Rafael Espindola | 4269b9e | 2014-03-13 18:09:26 +0000 | [diff] [blame] | 236 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 237 | MCSymbol *MCContext::createDirectionalLocalSymbol(unsigned LocalLabelVal) { |
Rafael Espindola | 4269b9e | 2014-03-13 18:09:26 +0000 | [diff] [blame] | 238 | unsigned Instance = NextInstance(LocalLabelVal); |
| 239 | return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance); |
| 240 | } |
| 241 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 242 | MCSymbol *MCContext::getDirectionalLocalSymbol(unsigned LocalLabelVal, |
Rafael Espindola | 4269b9e | 2014-03-13 18:09:26 +0000 | [diff] [blame] | 243 | bool Before) { |
| 244 | unsigned Instance = GetInstance(LocalLabelVal); |
| 245 | if (!Before) |
| 246 | ++Instance; |
| 247 | return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance); |
Kevin Enderby | 0510b48 | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 250 | MCSymbol *MCContext::lookupSymbol(const Twine &Name) const { |
Roman Divacky | 0be3359 | 2012-09-18 17:10:37 +0000 | [diff] [blame] | 251 | SmallString<128> NameSV; |
Yaron Keren | d7c546c | 2015-03-17 18:55:30 +0000 | [diff] [blame] | 252 | StringRef NameRef = Name.toStringRef(NameSV); |
| 253 | return Symbols.lookup(NameRef); |
Roman Divacky | 0be3359 | 2012-09-18 17:10:37 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Chris Lattner | 2073112 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 256 | //===----------------------------------------------------------------------===// |
| 257 | // Section Management |
| 258 | //===----------------------------------------------------------------------===// |
| 259 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 260 | MCSectionMachO *MCContext::getMachOSection(StringRef Segment, StringRef Section, |
| 261 | unsigned TypeAndAttributes, |
| 262 | unsigned Reserved2, SectionKind Kind, |
| 263 | const char *BeginSymName) { |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 264 | |
Chris Lattner | 2073112 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 265 | // We unique sections by their segment/section pair. The returned section |
| 266 | // may not have the same flags as the requested section, if so this should be |
| 267 | // diagnosed by the client as an error. |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 268 | |
Chris Lattner | 2073112 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 269 | // Form the name to look up. |
| 270 | SmallString<64> Name; |
| 271 | Name += Segment; |
| 272 | Name.push_back(','); |
| 273 | Name += Section; |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 274 | |
Chris Lattner | 2073112 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 275 | // Do the lookup, if we have a hit, return it. |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 276 | MCSectionMachO *&Entry = MachOUniquingMap[Name]; |
Rafael Espindola | 6ed58a2 | 2015-03-10 21:16:18 +0000 | [diff] [blame] | 277 | if (Entry) |
| 278 | return Entry; |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 279 | |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 280 | MCSymbol *Begin = nullptr; |
| 281 | if (BeginSymName) |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 282 | Begin = createTempSymbol(BeginSymName, false); |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 283 | |
Chris Lattner | 2073112 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 284 | // Otherwise, return a new section. |
Chris Lattner | 5418dd5 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 285 | return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes, |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 286 | Reserved2, Kind, Begin); |
Chris Lattner | 2073112 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 287 | } |
Chris Lattner | 5418dd5 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 288 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 289 | void MCContext::renameELFSection(MCSectionELF *Section, StringRef Name) { |
David Blaikie | 8019bf8 | 2014-04-10 21:53:53 +0000 | [diff] [blame] | 290 | StringRef GroupName; |
| 291 | if (const MCSymbol *Group = Section->getGroup()) |
| 292 | GroupName = Group->getName(); |
| 293 | |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 294 | unsigned UniqueID = Section->getUniqueID(); |
| 295 | ELFUniquingMap.erase( |
| 296 | ELFSectionKey{Section->getSectionName(), GroupName, UniqueID}); |
| 297 | auto I = ELFUniquingMap.insert(std::make_pair( |
| 298 | ELFSectionKey{Name, GroupName, UniqueID}, |
Jim Grosbach | 008359a | 2015-05-18 18:43:23 +0000 | [diff] [blame] | 299 | Section)) |
| 300 | .first; |
Rafael Espindola | 44d5057 | 2015-03-27 21:34:24 +0000 | [diff] [blame] | 301 | StringRef CachedName = I->first.SectionName; |
Jim Grosbach | 008359a | 2015-05-18 18:43:23 +0000 | [diff] [blame] | 302 | const_cast<MCSectionELF *>(Section)->setSectionName(CachedName); |
David Blaikie | 8019bf8 | 2014-04-10 21:53:53 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 305 | MCSectionELF *MCContext::createELFRelSection(StringRef Name, unsigned Type, |
| 306 | unsigned Flags, unsigned EntrySize, |
Rafael Espindola | 0ccf9b7 | 2015-06-02 21:30:13 +0000 | [diff] [blame] | 307 | const MCSymbolELF *Group, |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 308 | const MCSectionELF *Associated) { |
Rafael Espindola | c9d0692 | 2015-03-30 13:39:16 +0000 | [diff] [blame] | 309 | StringMap<bool>::iterator I; |
| 310 | bool Inserted; |
| 311 | std::tie(I, Inserted) = ELFRelSecNames.insert(std::make_pair(Name, true)); |
| 312 | |
| 313 | return new (*this) |
| 314 | MCSectionELF(I->getKey(), Type, Flags, SectionKind::getReadOnly(), |
Rafael Espindola | b73b70e | 2015-04-06 03:09:30 +0000 | [diff] [blame] | 315 | EntrySize, Group, true, nullptr, Associated); |
Rafael Espindola | c9d0692 | 2015-03-30 13:39:16 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 318 | MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type, |
| 319 | unsigned Flags, unsigned EntrySize, |
| 320 | StringRef Group, unsigned UniqueID, |
| 321 | const char *BeginSymName) { |
Rafael Espindola | 0ccf9b7 | 2015-06-02 21:30:13 +0000 | [diff] [blame] | 322 | MCSymbolELF *GroupSym = nullptr; |
Rafael Espindola | 61e8ce3 | 2015-04-06 04:25:18 +0000 | [diff] [blame] | 323 | if (!Group.empty()) |
Rafael Espindola | 0ccf9b7 | 2015-06-02 21:30:13 +0000 | [diff] [blame] | 324 | GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group)); |
Rafael Espindola | d3ac79b | 2015-03-30 13:59:06 +0000 | [diff] [blame] | 325 | |
Rafael Espindola | 61e8ce3 | 2015-04-06 04:25:18 +0000 | [diff] [blame] | 326 | return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID, |
| 327 | BeginSymName, nullptr); |
| 328 | } |
| 329 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 330 | MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type, |
| 331 | unsigned Flags, unsigned EntrySize, |
Rafael Espindola | 0ccf9b7 | 2015-06-02 21:30:13 +0000 | [diff] [blame] | 332 | const MCSymbolELF *GroupSym, |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 333 | unsigned UniqueID, |
| 334 | const char *BeginSymName, |
| 335 | const MCSectionELF *Associated) { |
Rafael Espindola | 61e8ce3 | 2015-04-06 04:25:18 +0000 | [diff] [blame] | 336 | StringRef Group = ""; |
| 337 | if (GroupSym) |
| 338 | Group = GroupSym->getName(); |
Chris Lattner | 5418dd5 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 339 | // Do the lookup, if we have a hit, return it. |
David Blaikie | 9ec3212 | 2014-04-10 23:55:11 +0000 | [diff] [blame] | 340 | auto IterBool = ELFUniquingMap.insert( |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 341 | std::make_pair(ELFSectionKey{Section, Group, UniqueID}, nullptr)); |
David Blaikie | 9ec3212 | 2014-04-10 23:55:11 +0000 | [diff] [blame] | 342 | auto &Entry = *IterBool.first; |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 343 | if (!IterBool.second) |
Rafael Espindola | 68fa249 | 2015-02-17 20:48:01 +0000 | [diff] [blame] | 344 | return Entry.second; |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 345 | |
Rafael Espindola | 44d5057 | 2015-03-27 21:34:24 +0000 | [diff] [blame] | 346 | StringRef CachedName = Entry.first.SectionName; |
Rafael Espindola | ba31e27 | 2015-01-29 17:33:21 +0000 | [diff] [blame] | 347 | |
| 348 | SectionKind Kind; |
| 349 | if (Flags & ELF::SHF_EXECINSTR) |
| 350 | Kind = SectionKind::getText(); |
| 351 | else |
| 352 | Kind = SectionKind::getReadOnly(); |
| 353 | |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 354 | MCSymbol *Begin = nullptr; |
| 355 | if (BeginSymName) |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 356 | Begin = createTempSymbol(BeginSymName, false); |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 357 | |
Rafael Espindola | b73b70e | 2015-04-06 03:09:30 +0000 | [diff] [blame] | 358 | MCSectionELF *Result = |
| 359 | new (*this) MCSectionELF(CachedName, Type, Flags, Kind, EntrySize, |
Rafael Espindola | 61e8ce3 | 2015-04-06 04:25:18 +0000 | [diff] [blame] | 360 | GroupSym, UniqueID, Begin, Associated); |
Rafael Espindola | 8ca44f0 | 2015-04-04 18:02:01 +0000 | [diff] [blame] | 361 | Entry.second = Result; |
Chris Lattner | 5418dd5 | 2010-04-08 21:26:26 +0000 | [diff] [blame] | 362 | return Result; |
| 363 | } |
| 364 | |
Rafael Espindola | 0ccf9b7 | 2015-06-02 21:30:13 +0000 | [diff] [blame] | 365 | MCSectionELF *MCContext::createELFGroupSection(const MCSymbolELF *Group) { |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 366 | MCSectionELF *Result = new (*this) |
| 367 | MCSectionELF(".group", ELF::SHT_GROUP, 0, SectionKind::getReadOnly(), 4, |
Rafael Espindola | 55a3afb | 2015-04-28 21:07:28 +0000 | [diff] [blame] | 368 | Group, ~0, nullptr, nullptr); |
Rafael Espindola | a3e9a22 | 2010-11-11 18:13:52 +0000 | [diff] [blame] | 369 | return Result; |
| 370 | } |
| 371 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 372 | MCSectionCOFF *MCContext::getCOFFSection(StringRef Section, |
| 373 | unsigned Characteristics, |
| 374 | SectionKind Kind, |
| 375 | StringRef COMDATSymName, int Selection, |
| 376 | const char *BeginSymName) { |
Rafael Espindola | d3ac79b | 2015-03-30 13:59:06 +0000 | [diff] [blame] | 377 | MCSymbol *COMDATSymbol = nullptr; |
| 378 | if (!COMDATSymName.empty()) { |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 379 | COMDATSymbol = getOrCreateSymbol(COMDATSymName); |
Rafael Espindola | d3ac79b | 2015-03-30 13:59:06 +0000 | [diff] [blame] | 380 | COMDATSymName = COMDATSymbol->getName(); |
| 381 | } |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 382 | |
Rafael Espindola | d3ac79b | 2015-03-30 13:59:06 +0000 | [diff] [blame] | 383 | // Do the lookup, if we have a hit, return it. |
Rafael Espindola | 44d5057 | 2015-03-27 21:34:24 +0000 | [diff] [blame] | 384 | COFFSectionKey T{Section, COMDATSymName, Selection}; |
David Majnemer | c57d038 | 2014-06-27 17:19:44 +0000 | [diff] [blame] | 385 | auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr)); |
David Blaikie | 9ec3212 | 2014-04-10 23:55:11 +0000 | [diff] [blame] | 386 | auto Iter = IterBool.first; |
| 387 | if (!IterBool.second) |
Rafael Espindola | 60ec383 | 2013-11-19 19:52:52 +0000 | [diff] [blame] | 388 | return Iter->second; |
Michael J. Spencer | f13f442 | 2010-11-26 04:16:08 +0000 | [diff] [blame] | 389 | |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 390 | MCSymbol *Begin = nullptr; |
| 391 | if (BeginSymName) |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 392 | Begin = createTempSymbol(BeginSymName, false); |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 393 | |
Rafael Espindola | 44d5057 | 2015-03-27 21:34:24 +0000 | [diff] [blame] | 394 | StringRef CachedName = Iter->first.SectionName; |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 395 | MCSectionCOFF *Result = new (*this) MCSectionCOFF( |
| 396 | CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin); |
Rafael Espindola | 60ec383 | 2013-11-19 19:52:52 +0000 | [diff] [blame] | 397 | |
| 398 | Iter->second = Result; |
Chris Lattner | 87cffa9 | 2010-05-07 17:17:41 +0000 | [diff] [blame] | 399 | return Result; |
| 400 | } |
Kevin Enderby | e5930f1 | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 401 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 402 | MCSectionCOFF *MCContext::getCOFFSection(StringRef Section, |
| 403 | unsigned Characteristics, |
| 404 | SectionKind Kind, |
| 405 | const char *BeginSymName) { |
Rafael Espindola | 6b9998b | 2015-03-10 22:00:25 +0000 | [diff] [blame] | 406 | return getCOFFSection(Section, Characteristics, Kind, "", 0, BeginSymName); |
Rafael Espindola | 60ec383 | 2013-11-19 19:52:52 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 409 | MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) { |
Rafael Espindola | 44d5057 | 2015-03-27 21:34:24 +0000 | [diff] [blame] | 410 | COFFSectionKey T{Section, "", 0}; |
David Majnemer | c57d038 | 2014-06-27 17:19:44 +0000 | [diff] [blame] | 411 | auto Iter = COFFUniquingMap.find(T); |
David Blaikie | 9ec3212 | 2014-04-10 23:55:11 +0000 | [diff] [blame] | 412 | if (Iter == COFFUniquingMap.end()) |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 413 | return nullptr; |
Rafael Espindola | 60ec383 | 2013-11-19 19:52:52 +0000 | [diff] [blame] | 414 | return Iter->second; |
Nico Rieck | a37acf7 | 2013-07-06 12:13:10 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 417 | MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec, |
| 418 | const MCSymbol *KeySym) { |
Reid Kleckner | 7c4059e | 2014-09-04 17:42:03 +0000 | [diff] [blame] | 419 | // Return the normal section if we don't have to be associative. |
| 420 | if (!KeySym) |
| 421 | return Sec; |
| 422 | |
| 423 | // Make an associative section with the same name and kind as the normal |
| 424 | // section. |
| 425 | unsigned Characteristics = |
| 426 | Sec->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT; |
| 427 | return getCOFFSection(Sec->getSectionName(), Characteristics, Sec->getKind(), |
| 428 | KeySym->getName(), |
| 429 | COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE); |
| 430 | } |
| 431 | |
Kevin Enderby | e5930f1 | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 432 | //===----------------------------------------------------------------------===// |
| 433 | // Dwarf Management |
| 434 | //===----------------------------------------------------------------------===// |
| 435 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 436 | /// getDwarfFile - takes a file name an number to place in the dwarf file and |
Kevin Enderby | e5930f1 | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 437 | /// directory tables. If the file number has already been allocated it is an |
| 438 | /// error and zero is returned and the client reports the error, else the |
| 439 | /// allocated file number is returned. The file numbers may be in any order. |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 440 | unsigned MCContext::getDwarfFile(StringRef Directory, StringRef FileName, |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 441 | unsigned FileNumber, unsigned CUID) { |
David Blaikie | d9012ba | 2014-03-13 21:59:51 +0000 | [diff] [blame] | 442 | MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID]; |
David Blaikie | 498589c | 2014-03-13 19:15:04 +0000 | [diff] [blame] | 443 | return Table.getFile(Directory, FileName, FileNumber); |
Kevin Enderby | e5930f1 | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 444 | } |
Kevin Enderby | 1264b7c | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 445 | |
Kevin Enderby | a68d004 | 2010-10-04 20:17:24 +0000 | [diff] [blame] | 446 | /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it |
Kevin Enderby | 1264b7c | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 447 | /// currently is assigned and false otherwise. |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 448 | bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) { |
Jim Grosbach | 008359a | 2015-05-18 18:43:23 +0000 | [diff] [blame] | 449 | const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles = getMCDwarfFiles(CUID); |
| 450 | if (FileNumber == 0 || FileNumber >= MCDwarfFiles.size()) |
Kevin Enderby | 1264b7c | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 451 | return false; |
| 452 | |
David Blaikie | a55ddad | 2014-03-13 18:55:04 +0000 | [diff] [blame] | 453 | return !MCDwarfFiles[FileNumber].Name.empty(); |
Kevin Enderby | 1264b7c | 2010-08-24 20:32:42 +0000 | [diff] [blame] | 454 | } |
Jim Grosbach | b18b409 | 2012-01-26 23:20:11 +0000 | [diff] [blame] | 455 | |
Rafael Espindola | e074679 | 2015-05-21 16:52:32 +0000 | [diff] [blame] | 456 | /// Remove empty sections from SectionStartEndSyms, to avoid generating |
Oliver Stannard | 8b27308 | 2014-06-19 15:52:37 +0000 | [diff] [blame] | 457 | /// useless debug info for them. |
| 458 | void MCContext::finalizeDwarfSections(MCStreamer &MCOS) { |
Benjamin Kramer | 412c4db | 2015-05-31 18:49:28 +0000 | [diff] [blame] | 459 | SectionsForRanges.remove_if( |
| 460 | [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); }); |
Oliver Stannard | 8b27308 | 2014-06-19 15:52:37 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 463 | void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) const { |
Jim Grosbach | b18b409 | 2012-01-26 23:20:11 +0000 | [diff] [blame] | 464 | // If we have a source manager and a location, use it. Otherwise just |
| 465 | // use the generic report_fatal_error(). |
| 466 | if (!SrcMgr || Loc == SMLoc()) |
Jim Grosbach | 9a3284f | 2014-03-14 22:41:58 +0000 | [diff] [blame] | 467 | report_fatal_error(Msg, false); |
Jim Grosbach | b18b409 | 2012-01-26 23:20:11 +0000 | [diff] [blame] | 468 | |
| 469 | // Use the source manager to print the message. |
| 470 | SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg); |
| 471 | |
| 472 | // If we reached here, we are failing ungracefully. Run the interrupt handlers |
| 473 | // to make sure any special cleanups get done, in particular that we remove |
| 474 | // files registered with RemoveFileOnSignal. |
| 475 | sys::RunInterruptHandlers(); |
| 476 | exit(1); |
| 477 | } |