blob: e819c1b9680d392d4c62986c71839de834e59401 [file] [log] [blame]
Rui Ueyama411c63602015-05-28 19:09:30 +00001//===- InputFiles.cpp -----------------------------------------------------===//
2//
3// The LLVM Linker
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 "Chunks.h"
Rui Ueyama8fd9fb92015-06-01 02:58:15 +000011#include "Error.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000012#include "InputFiles.h"
Rui Ueyama67fcd1a02015-08-05 19:51:28 +000013#include "Symbols.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000014#include "llvm/ADT/STLExtras.h"
Peter Collingbourne60c16162015-06-01 20:10:10 +000015#include "llvm/LTO/LTOModule.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000016#include "llvm/Object/COFF.h"
17#include "llvm/Support/COFF.h"
18#include "llvm/Support/Debug.h"
19#include "llvm/Support/Endian.h"
20#include "llvm/Support/raw_ostream.h"
21
Rui Ueyama1c79ce92015-07-08 20:22:50 +000022using namespace llvm::COFF;
Rui Ueyama411c63602015-05-28 19:09:30 +000023using namespace llvm::object;
24using namespace llvm::support::endian;
Rui Ueyama411c63602015-05-28 19:09:30 +000025using llvm::RoundUpToAlignment;
Rui Ueyamaea533cd2015-07-09 19:54:13 +000026using llvm::Triple;
Rui Ueyamacd3f99b2015-07-24 23:51:14 +000027using llvm::support::ulittle32_t;
Rui Ueyama411c63602015-05-28 19:09:30 +000028using llvm::sys::fs::file_magic;
Rui Ueyamaea533cd2015-07-09 19:54:13 +000029using llvm::sys::fs::identify_magic;
Rui Ueyama411c63602015-05-28 19:09:30 +000030
31namespace lld {
32namespace coff {
33
Rui Ueyama65813ed2015-07-02 20:33:48 +000034int InputFile::NextIndex = 0;
35
Rui Ueyama411c63602015-05-28 19:09:30 +000036// Returns the last element of a path, which is supposed to be a filename.
37static StringRef getBasename(StringRef Path) {
Rui Ueyamaea63a282015-06-18 20:16:26 +000038 size_t Pos = Path.find_last_of("\\/");
Rui Ueyama411c63602015-05-28 19:09:30 +000039 if (Pos == StringRef::npos)
40 return Path;
41 return Path.substr(Pos + 1);
42}
43
44// Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
45std::string InputFile::getShortName() {
46 if (ParentName == "")
47 return getName().lower();
48 std::string Res = (getBasename(ParentName) + "(" +
49 getBasename(getName()) + ")").str();
50 return StringRef(Res).lower();
51}
52
Rafael Espindolab835ae82015-08-06 14:58:50 +000053void ArchiveFile::parse() {
Rui Ueyamad7c2f582015-05-31 21:04:56 +000054 // Parse a MemoryBufferRef as an archive file.
55 auto ArchiveOrErr = Archive::create(MB);
Rafael Espindolab835ae82015-08-06 14:58:50 +000056 error(ArchiveOrErr, "Failed to parse static library");
Rui Ueyama04ec69aa2015-08-18 09:18:15 +000057 File = std::move(*ArchiveOrErr);
Rui Ueyama411c63602015-05-28 19:09:30 +000058
59 // Allocate a buffer for Lazy objects.
Rui Ueyama605e1f62015-06-26 23:51:45 +000060 size_t NumSyms = File->getNumberOfSymbols();
Rui Ueyama8d3010a2015-06-30 19:35:21 +000061 LazySymbols.reserve(NumSyms);
Rui Ueyama411c63602015-05-28 19:09:30 +000062
63 // Read the symbol table to construct Lazy objects.
Rui Ueyama95b781d2015-08-18 09:06:41 +000064 for (const Archive::Symbol &Sym : File->symbols())
Rafael Espindolafb497d72015-09-02 16:07:11 +000065 LazySymbols.emplace_back(this, Sym);
Rui Ueyama159fb4cd2015-07-14 03:09:59 +000066
67 // Seen is a map from member files to boolean values. Initially
68 // all members are mapped to false, which indicates all these files
69 // are not read yet.
Kevin Enderby35dfc952015-11-05 19:25:47 +000070 for (auto &ChildOrErr : File->children()) {
71 error(ChildOrErr, "Failed to parse static library");
72 const Archive::Child &Child = *ChildOrErr;
Rafael Espindola9f141ef2015-07-14 21:28:07 +000073 Seen[Child.getChildOffset()].clear();
Kevin Enderby35dfc952015-11-05 19:25:47 +000074 }
Rui Ueyama411c63602015-05-28 19:09:30 +000075}
76
77// Returns a buffer pointing to a member file containing a given symbol.
Rui Ueyamaadcde532015-07-05 22:50:00 +000078// This function is thread-safe.
Rafael Espindolab835ae82015-08-06 14:58:50 +000079MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) {
Rafael Espindola543f29d2015-11-05 14:34:56 +000080 auto COrErr = Sym->getMember();
81 error(COrErr, Twine("Could not get the member for symbol ") + Sym->getName());
82 const Archive::Child &C = *COrErr;
Rui Ueyama411c63602015-05-28 19:09:30 +000083
84 // Return an empty buffer if we have already returned the same buffer.
Rafael Espindola543f29d2015-11-05 14:34:56 +000085 if (Seen[C.getChildOffset()].test_and_set())
Rui Ueyama411c63602015-05-28 19:09:30 +000086 return MemoryBufferRef();
Rafael Espindola543f29d2015-11-05 14:34:56 +000087 ErrorOr<MemoryBufferRef> Ret = C.getMemoryBufferRef();
Rafael Espindolab835ae82015-08-06 14:58:50 +000088 error(Ret, Twine("Could not get the buffer for the member defining symbol ") +
89 Sym->getName());
90 return *Ret;
Rui Ueyama411c63602015-05-28 19:09:30 +000091}
92
Rafael Espindolab835ae82015-08-06 14:58:50 +000093void ObjectFile::parse() {
Rui Ueyama411c63602015-05-28 19:09:30 +000094 // Parse a memory buffer as a COFF file.
Rui Ueyamad7c2f582015-05-31 21:04:56 +000095 auto BinOrErr = createBinary(MB);
Rafael Espindolab835ae82015-08-06 14:58:50 +000096 error(BinOrErr, "Failed to parse object file");
Rui Ueyama04ec69aa2015-08-18 09:18:15 +000097 std::unique_ptr<Binary> Bin = std::move(*BinOrErr);
Rui Ueyama411c63602015-05-28 19:09:30 +000098
99 if (auto *Obj = dyn_cast<COFFObjectFile>(Bin.get())) {
100 Bin.release();
101 COFFObj.reset(Obj);
102 } else {
Rafael Espindolab835ae82015-08-06 14:58:50 +0000103 error(Twine(getName()) + " is not a COFF file.");
Rui Ueyama411c63602015-05-28 19:09:30 +0000104 }
105
106 // Read section and symbol tables.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000107 initializeChunks();
108 initializeSymbols();
109 initializeSEH();
Rui Ueyama411c63602015-05-28 19:09:30 +0000110}
111
Rafael Espindolab835ae82015-08-06 14:58:50 +0000112void ObjectFile::initializeChunks() {
Rui Ueyama411c63602015-05-28 19:09:30 +0000113 uint32_t NumSections = COFFObj->getNumberOfSections();
114 Chunks.reserve(NumSections);
115 SparseChunks.resize(NumSections + 1);
116 for (uint32_t I = 1; I < NumSections + 1; ++I) {
117 const coff_section *Sec;
118 StringRef Name;
Rafael Espindolab835ae82015-08-06 14:58:50 +0000119 std::error_code EC = COFFObj->getSection(I, Sec);
Rui Ueyama8e186df2015-09-13 20:22:22 +0000120 error(EC, Twine("getSection failed: #") + Twine(I));
Rafael Espindolab835ae82015-08-06 14:58:50 +0000121 EC = COFFObj->getSectionName(Sec, Name);
Rui Ueyama8e186df2015-09-13 20:22:22 +0000122 error(EC, Twine("getSectionName failed: #") + Twine(I));
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000123 if (Name == ".sxdata") {
124 SXData = Sec;
125 continue;
126 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000127 if (Name == ".drectve") {
128 ArrayRef<uint8_t> Data;
129 COFFObj->getSectionContents(Sec, Data);
Rui Ueyama0569ecf2015-07-04 03:27:46 +0000130 Directives = std::string((const char *)Data.data(), Data.size());
Rui Ueyama411c63602015-05-28 19:09:30 +0000131 continue;
132 }
Rui Ueyama2832ce92015-07-28 01:06:58 +0000133 // Skip non-DWARF debug info. MSVC linker converts the sections into
134 // a PDB file, but we don't support that.
135 if (Name == ".debug" || Name.startswith(".debug$"))
136 continue;
David Majnemer2c345a32015-07-08 16:37:50 +0000137 // We want to preserve DWARF debug sections only when /debug is on.
138 if (!Config->Debug && Name.startswith(".debug"))
Rui Ueyama411c63602015-05-28 19:09:30 +0000139 continue;
140 if (Sec->Characteristics & llvm::COFF::IMAGE_SCN_LNK_REMOVE)
141 continue;
Peter Collingbournebd3a29d2015-06-24 00:12:36 +0000142 auto *C = new (Alloc) SectionChunk(this, Sec);
Rui Ueyama411c63602015-05-28 19:09:30 +0000143 Chunks.push_back(C);
144 SparseChunks[I] = C;
145 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000146}
147
Rafael Espindolab835ae82015-08-06 14:58:50 +0000148void ObjectFile::initializeSymbols() {
Rui Ueyama411c63602015-05-28 19:09:30 +0000149 uint32_t NumSymbols = COFFObj->getNumberOfSymbols();
150 SymbolBodies.reserve(NumSymbols);
151 SparseSymbolBodies.resize(NumSymbols);
Rui Ueyama7171c822015-08-17 23:35:43 +0000152 llvm::SmallVector<Undefined *, 8> WeakAliases;
Rui Ueyama411c63602015-05-28 19:09:30 +0000153 int32_t LastSectionNumber = 0;
154 for (uint32_t I = 0; I < NumSymbols; ++I) {
155 // Get a COFFSymbolRef object.
156 auto SymOrErr = COFFObj->getSymbol(I);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000157 error(SymOrErr, Twine("broken object file: ") + getName());
158
Rui Ueyama04ec69aa2015-08-18 09:18:15 +0000159 COFFSymbolRef Sym = *SymOrErr;
Rui Ueyama411c63602015-05-28 19:09:30 +0000160
Rui Ueyama411c63602015-05-28 19:09:30 +0000161 const void *AuxP = nullptr;
162 if (Sym.getNumberOfAuxSymbols())
163 AuxP = COFFObj->getSymbol(I + 1)->getRawPtr();
164 bool IsFirst = (LastSectionNumber != Sym.getSectionNumber());
165
Rui Ueyamadae16612015-06-29 22:16:21 +0000166 SymbolBody *Body = nullptr;
167 if (Sym.isUndefined()) {
168 Body = createUndefined(Sym);
169 } else if (Sym.isWeakExternal()) {
170 Body = createWeakExternal(Sym, AuxP);
Rui Ueyama7171c822015-08-17 23:35:43 +0000171 WeakAliases.push_back((Undefined *)Body);
Rui Ueyamadae16612015-06-29 22:16:21 +0000172 } else {
173 Body = createDefined(Sym, AuxP, IsFirst);
174 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000175 if (Body) {
176 SymbolBodies.push_back(Body);
177 SparseSymbolBodies[I] = Body;
178 }
179 I += Sym.getNumberOfAuxSymbols();
180 LastSectionNumber = Sym.getSectionNumber();
181 }
Rui Ueyama7171c822015-08-17 23:35:43 +0000182 for (Undefined *U : WeakAliases)
183 U->WeakAlias = SparseSymbolBodies[(uintptr_t)U->WeakAlias];
Rui Ueyama411c63602015-05-28 19:09:30 +0000184}
185
Rui Ueyamadae16612015-06-29 22:16:21 +0000186Undefined *ObjectFile::createUndefined(COFFSymbolRef Sym) {
Rui Ueyama57fe78d2015-06-08 19:43:59 +0000187 StringRef Name;
Rui Ueyamadae16612015-06-29 22:16:21 +0000188 COFFObj->getSymbolName(Sym, Name);
189 return new (Alloc) Undefined(Name);
190}
191
192Undefined *ObjectFile::createWeakExternal(COFFSymbolRef Sym, const void *AuxP) {
193 StringRef Name;
194 COFFObj->getSymbolName(Sym, Name);
Rui Ueyama48975962015-07-01 22:32:23 +0000195 auto *U = new (Alloc) Undefined(Name);
Rui Ueyamadae16612015-06-29 22:16:21 +0000196 auto *Aux = (const coff_aux_weak_external *)AuxP;
Rui Ueyama7171c822015-08-17 23:35:43 +0000197 U->WeakAlias = (Undefined *)(uintptr_t)Aux->TagIndex;
Rui Ueyama48975962015-07-01 22:32:23 +0000198 return U;
Rui Ueyamadae16612015-06-29 22:16:21 +0000199}
200
201Defined *ObjectFile::createDefined(COFFSymbolRef Sym, const void *AuxP,
202 bool IsFirst) {
203 StringRef Name;
Rui Ueyama411c63602015-05-28 19:09:30 +0000204 if (Sym.isCommon()) {
Rui Ueyamafc510f42015-06-25 19:10:58 +0000205 auto *C = new (Alloc) CommonChunk(Sym);
Rui Ueyama411c63602015-05-28 19:09:30 +0000206 Chunks.push_back(C);
Rui Ueyama68633f12015-06-25 23:22:00 +0000207 return new (Alloc) DefinedCommon(this, Sym, C);
Rui Ueyama411c63602015-05-28 19:09:30 +0000208 }
Rui Ueyama57fe78d2015-06-08 19:43:59 +0000209 if (Sym.isAbsolute()) {
210 COFFObj->getSymbolName(Sym, Name);
211 // Skip special symbols.
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000212 if (Name == "@comp.id")
Rui Ueyama57fe78d2015-06-08 19:43:59 +0000213 return nullptr;
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000214 // COFF spec 5.10.1. The .sxdata section.
215 if (Name == "@feat.00") {
216 if (Sym.getValue() & 1)
217 SEHCompat = true;
218 return nullptr;
219 }
Rui Ueyamaccde19d2015-06-26 03:09:23 +0000220 return new (Alloc) DefinedAbsolute(Name, Sym);
Rui Ueyama57fe78d2015-06-08 19:43:59 +0000221 }
Peter Collingbournec7b685d2015-06-24 00:05:50 +0000222 if (Sym.getSectionNumber() == llvm::COFF::IMAGE_SYM_DEBUG)
223 return nullptr;
Chandler Carruthee5bf522015-06-29 21:32:37 +0000224
225 // Nothing else to do without a section chunk.
226 auto *SC = cast_or_null<SectionChunk>(SparseChunks[Sym.getSectionNumber()]);
227 if (!SC)
228 return nullptr;
229
Rui Ueyama2dcc2352015-09-04 20:45:50 +0000230 // Handle section definitions
Rui Ueyama411c63602015-05-28 19:09:30 +0000231 if (IsFirst && AuxP) {
Chandler Carruthee5bf522015-06-29 21:32:37 +0000232 auto *Aux = reinterpret_cast<const coff_aux_section_definition *>(AuxP);
233 if (Aux->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE)
234 if (auto *ParentSC = cast_or_null<SectionChunk>(
235 SparseChunks[Aux->getNumber(Sym.isBigObj())]))
236 ParentSC->addAssociative(SC);
Rui Ueyama2dcc2352015-09-04 20:45:50 +0000237 SC->Checksum = Aux->CheckSum;
Rui Ueyama411c63602015-05-28 19:09:30 +0000238 }
Chandler Carruthee5bf522015-06-29 21:32:37 +0000239
240 auto *B = new (Alloc) DefinedRegular(this, Sym, SC);
241 if (SC->isCOMDAT() && Sym.getValue() == 0 && !AuxP)
242 SC->setSymbol(B);
243
244 return B;
Rui Ueyama411c63602015-05-28 19:09:30 +0000245}
246
Rafael Espindolab835ae82015-08-06 14:58:50 +0000247void ObjectFile::initializeSEH() {
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000248 if (!SEHCompat || !SXData)
Rafael Espindolab835ae82015-08-06 14:58:50 +0000249 return;
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000250 ArrayRef<uint8_t> A;
251 COFFObj->getSectionContents(SXData, A);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000252 if (A.size() % 4 != 0)
253 error(".sxdata must be an array of symbol table indices");
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000254 auto *I = reinterpret_cast<const ulittle32_t *>(A.data());
255 auto *E = reinterpret_cast<const ulittle32_t *>(A.data() + A.size());
256 for (; I != E; ++I)
257 SEHandlers.insert(SparseSymbolBodies[*I]);
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000258}
259
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000260MachineTypes ObjectFile::getMachineType() {
261 if (COFFObj)
262 return static_cast<MachineTypes>(COFFObj->getMachine());
263 return IMAGE_FILE_MACHINE_UNKNOWN;
264}
265
Rui Ueyamaa841bb02015-07-09 20:22:41 +0000266StringRef ltrim1(StringRef S, const char *Chars) {
267 if (!S.empty() && strchr(Chars, S[0]))
268 return S.substr(1);
269 return S;
270}
271
Rafael Espindolab835ae82015-08-06 14:58:50 +0000272void ImportFile::parse() {
Rui Ueyamad7c2f582015-05-31 21:04:56 +0000273 const char *Buf = MB.getBufferStart();
274 const char *End = MB.getBufferEnd();
Rui Ueyama411c63602015-05-28 19:09:30 +0000275 const auto *Hdr = reinterpret_cast<const coff_import_header *>(Buf);
276
277 // Check if the total size is valid.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000278 if ((size_t)(End - Buf) != (sizeof(*Hdr) + Hdr->SizeOfData))
279 error("broken import library");
Rui Ueyama411c63602015-05-28 19:09:30 +0000280
281 // Read names and create an __imp_ symbol.
282 StringRef Name = StringAlloc.save(StringRef(Buf + sizeof(*Hdr)));
283 StringRef ImpName = StringAlloc.save(Twine("__imp_") + Name);
Rui Ueyamad1570882015-08-17 08:30:31 +0000284 const char *NameStart = Buf + sizeof(coff_import_header) + Name.size() + 1;
Rui Ueyamabfbd2772015-09-02 07:27:31 +0000285 DLLName = StringRef(NameStart);
Rui Ueyama1c79ce92015-07-08 20:22:50 +0000286 StringRef ExtName;
287 switch (Hdr->getNameType()) {
288 case IMPORT_ORDINAL:
289 ExtName = "";
290 break;
291 case IMPORT_NAME:
292 ExtName = Name;
293 break;
294 case IMPORT_NAME_NOPREFIX:
Rui Ueyamaa841bb02015-07-09 20:22:41 +0000295 ExtName = ltrim1(Name, "?@_");
Rui Ueyama1c79ce92015-07-08 20:22:50 +0000296 break;
297 case IMPORT_NAME_UNDECORATE:
Rui Ueyamaa841bb02015-07-09 20:22:41 +0000298 ExtName = ltrim1(Name, "?@_");
Rui Ueyama1c79ce92015-07-08 20:22:50 +0000299 ExtName = ExtName.substr(0, ExtName.find('@'));
300 break;
301 }
Rui Ueyamae73e4182015-08-17 07:27:45 +0000302 ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExtName, Hdr);
Rui Ueyama411c63602015-05-28 19:09:30 +0000303 SymbolBodies.push_back(ImpSym);
304
305 // If type is function, we need to create a thunk which jump to an
306 // address pointed by the __imp_ symbol. (This allows you to call
307 // DLL functions just like regular non-DLL functions.)
Rui Ueyamae73e4182015-08-17 07:27:45 +0000308 if (Hdr->getType() != llvm::COFF::IMPORT_CODE)
309 return;
310 ThunkSym = new (Alloc) DefinedImportThunk(Name, ImpSym, Hdr->Machine);
311 SymbolBodies.push_back(ThunkSym);
Rui Ueyama411c63602015-05-28 19:09:30 +0000312}
313
Rafael Espindolab835ae82015-08-06 14:58:50 +0000314void BitcodeFile::parse() {
Rui Ueyamaebb0ebf2015-09-19 23:14:51 +0000315 // Usually parse() is thread-safe, but bitcode file is an exception.
316 std::lock_guard<std::mutex> Lock(Mu);
317
Peter Collingbourne60c16162015-06-01 20:10:10 +0000318 std::string Err;
Rui Ueyama81b030c2015-06-01 21:19:43 +0000319 M.reset(LTOModule::createFromBuffer(MB.getBufferStart(),
320 MB.getBufferSize(),
321 llvm::TargetOptions(), Err));
Rafael Espindolab835ae82015-08-06 14:58:50 +0000322 if (!Err.empty())
323 error(Err);
Peter Collingbourne60c16162015-06-01 20:10:10 +0000324
Rafael Espindolaf0461ba2015-08-13 01:07:08 +0000325 llvm::StringSaver Saver(Alloc);
Peter Collingbourne60c16162015-06-01 20:10:10 +0000326 for (unsigned I = 0, E = M->getSymbolCount(); I != E; ++I) {
Peter Collingbournedf637ea2015-06-08 20:21:28 +0000327 lto_symbol_attributes Attrs = M->getSymbolAttributes(I);
328 if ((Attrs & LTO_SYMBOL_SCOPE_MASK) == LTO_SYMBOL_SCOPE_INTERNAL)
329 continue;
330
Rui Ueyama223fe1b2015-06-18 20:29:41 +0000331 StringRef SymName = Saver.save(M->getSymbolName(I));
Peter Collingbournedf637ea2015-06-08 20:21:28 +0000332 int SymbolDef = Attrs & LTO_SYMBOL_DEFINITION_MASK;
333 if (SymbolDef == LTO_SYMBOL_DEFINITION_UNDEFINED) {
Peter Collingbourne60c16162015-06-01 20:10:10 +0000334 SymbolBodies.push_back(new (Alloc) Undefined(SymName));
335 } else {
Peter Collingbourne2612a322015-07-04 05:28:41 +0000336 bool Replaceable =
337 (SymbolDef == LTO_SYMBOL_DEFINITION_TENTATIVE || // common
338 (Attrs & LTO_SYMBOL_COMDAT) || // comdat
339 (SymbolDef == LTO_SYMBOL_DEFINITION_WEAK && // weak external
340 (Attrs & LTO_SYMBOL_ALIAS)));
Peter Collingbournef7b27d12015-06-30 00:47:52 +0000341 SymbolBodies.push_back(new (Alloc) DefinedBitcode(this, SymName,
342 Replaceable));
Peter Collingbourne60c16162015-06-01 20:10:10 +0000343 }
344 }
Peter Collingbourneace2f092015-06-06 02:00:45 +0000345
Peter Collingbourne79cfd432015-06-29 23:26:28 +0000346 Directives = M->getLinkerOpts();
Peter Collingbourne60c16162015-06-01 20:10:10 +0000347}
Rui Ueyama81b030c2015-06-01 21:19:43 +0000348
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000349MachineTypes BitcodeFile::getMachineType() {
350 if (!M)
351 return IMAGE_FILE_MACHINE_UNKNOWN;
352 switch (Triple(M->getTargetTriple()).getArch()) {
353 case Triple::x86_64:
Rui Ueyama5e706b32015-07-25 21:54:50 +0000354 return AMD64;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000355 case Triple::x86:
Rui Ueyama5e706b32015-07-25 21:54:50 +0000356 return I386;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000357 case Triple::arm:
Rui Ueyama5e706b32015-07-25 21:54:50 +0000358 return ARMNT;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000359 default:
360 return IMAGE_FILE_MACHINE_UNKNOWN;
361 }
362}
363
Rui Ueyamaebb0ebf2015-09-19 23:14:51 +0000364std::mutex BitcodeFile::Mu;
365
Rui Ueyama411c63602015-05-28 19:09:30 +0000366} // namespace coff
367} // namespace lld