blob: 54aac742d095be1930ee785fe142050acd8c90da [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"
Eugene Zelenko1a299ea2016-04-21 17:14:10 +000011#include "Config.h"
Rui Ueyama8fd9fb92015-06-01 02:58:15 +000012#include "Error.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000013#include "InputFiles.h"
Rui Ueyama67fcd1a02015-08-05 19:51:28 +000014#include "Symbols.h"
Eugene Zelenko1a299ea2016-04-21 17:14:10 +000015#include "llvm/ADT/SmallVector.h"
16#include "llvm/ADT/Triple.h"
17#include "llvm/ADT/Twine.h"
Rafael Espindola3d49d7a2015-12-04 16:22:09 +000018#include "llvm/IR/LLVMContext.h"
Peter Collingbourne765aa2d2016-07-14 21:30:37 +000019#include "llvm/LTO/legacy/LTOModule.h"
Eugene Zelenko1a299ea2016-04-21 17:14:10 +000020#include "llvm/Object/Binary.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000021#include "llvm/Object/COFF.h"
22#include "llvm/Support/COFF.h"
Eugene Zelenko1a299ea2016-04-21 17:14:10 +000023#include "llvm/Support/Casting.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000024#include "llvm/Support/Endian.h"
Eugene Zelenko1a299ea2016-04-21 17:14:10 +000025#include "llvm/Support/Error.h"
26#include "llvm/Support/ErrorOr.h"
27#include "llvm/Support/FileSystem.h"
28#include "llvm/Target/TargetOptions.h"
29#include "llvm-c/lto.h"
30#include <cstring>
31#include <system_error>
32#include <utility>
Rui Ueyama411c63602015-05-28 19:09:30 +000033
Rui Ueyama1c79ce92015-07-08 20:22:50 +000034using namespace llvm::COFF;
Rui Ueyama411c63602015-05-28 19:09:30 +000035using namespace llvm::object;
36using namespace llvm::support::endian;
Eugene Zelenko1a299ea2016-04-21 17:14:10 +000037
Rui Ueyamaea533cd2015-07-09 19:54:13 +000038using llvm::Triple;
Rui Ueyamacd3f99b2015-07-24 23:51:14 +000039using llvm::support::ulittle32_t;
Rui Ueyama411c63602015-05-28 19:09:30 +000040
41namespace lld {
42namespace coff {
43
Rui Ueyama65813ed2015-07-02 20:33:48 +000044int InputFile::NextIndex = 0;
Rui Ueyama34b60f12016-04-14 21:41:44 +000045llvm::LLVMContext BitcodeFile::Context;
Rui Ueyama65813ed2015-07-02 20:33:48 +000046
Rui Ueyama411c63602015-05-28 19:09:30 +000047// Returns the last element of a path, which is supposed to be a filename.
48static StringRef getBasename(StringRef Path) {
Rui Ueyamaea63a282015-06-18 20:16:26 +000049 size_t Pos = Path.find_last_of("\\/");
Rui Ueyama411c63602015-05-28 19:09:30 +000050 if (Pos == StringRef::npos)
51 return Path;
52 return Path.substr(Pos + 1);
53}
54
55// Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
56std::string InputFile::getShortName() {
57 if (ParentName == "")
58 return getName().lower();
59 std::string Res = (getBasename(ParentName) + "(" +
60 getBasename(getName()) + ")").str();
61 return StringRef(Res).lower();
62}
63
Rafael Espindolab835ae82015-08-06 14:58:50 +000064void ArchiveFile::parse() {
Rui Ueyamad7c2f582015-05-31 21:04:56 +000065 // Parse a MemoryBufferRef as an archive file.
Rui Ueyama659a4f22016-07-15 01:06:38 +000066 File = check(Archive::create(MB), "Failed to parse static library");
Rui Ueyama411c63602015-05-28 19:09:30 +000067
68 // Allocate a buffer for Lazy objects.
Rui Ueyama605e1f62015-06-26 23:51:45 +000069 size_t NumSyms = File->getNumberOfSymbols();
Rui Ueyama8d3010a2015-06-30 19:35:21 +000070 LazySymbols.reserve(NumSyms);
Rui Ueyama411c63602015-05-28 19:09:30 +000071
72 // Read the symbol table to construct Lazy objects.
Rui Ueyama95b781d2015-08-18 09:06:41 +000073 for (const Archive::Symbol &Sym : File->symbols())
Rafael Espindolafb497d72015-09-02 16:07:11 +000074 LazySymbols.emplace_back(this, Sym);
Rui Ueyama159fb4cd2015-07-14 03:09:59 +000075
76 // Seen is a map from member files to boolean values. Initially
77 // all members are mapped to false, which indicates all these files
78 // are not read yet.
Lang Hames622ef172016-07-14 02:35:18 +000079 Error Err;
80 for (auto &Child : File->children(Err))
Rafael Espindola9f141ef2015-07-14 21:28:07 +000081 Seen[Child.getChildOffset()].clear();
Rui Ueyama0d09a862016-07-15 00:40:46 +000082 if (Err)
83 fatal(Err, "Failed to parse static library");
Rui Ueyama411c63602015-05-28 19:09:30 +000084}
85
86// Returns a buffer pointing to a member file containing a given symbol.
Rui Ueyamaadcde532015-07-05 22:50:00 +000087// This function is thread-safe.
Rafael Espindolab835ae82015-08-06 14:58:50 +000088MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) {
Rui Ueyama659a4f22016-07-15 01:06:38 +000089 const Archive::Child &C =
90 check(Sym->getMember(),
91 "Could not get the member for symbol " + Sym->getName());
Rui Ueyama411c63602015-05-28 19:09:30 +000092
93 // Return an empty buffer if we have already returned the same buffer.
Rafael Espindola543f29d2015-11-05 14:34:56 +000094 if (Seen[C.getChildOffset()].test_and_set())
Rui Ueyama411c63602015-05-28 19:09:30 +000095 return MemoryBufferRef();
Rui Ueyama659a4f22016-07-15 01:06:38 +000096 return check(C.getMemoryBufferRef(),
97 "Could not get the buffer for the member defining symbol " +
98 Sym->getName());
Rui Ueyama411c63602015-05-28 19:09:30 +000099}
100
Rafael Espindolab835ae82015-08-06 14:58:50 +0000101void ObjectFile::parse() {
Rui Ueyama411c63602015-05-28 19:09:30 +0000102 // Parse a memory buffer as a COFF file.
Rui Ueyama659a4f22016-07-15 01:06:38 +0000103 std::unique_ptr<Binary> Bin =
104 check(createBinary(MB), "Failed to parse object file");
Rui Ueyama411c63602015-05-28 19:09:30 +0000105
106 if (auto *Obj = dyn_cast<COFFObjectFile>(Bin.get())) {
107 Bin.release();
108 COFFObj.reset(Obj);
109 } else {
Rui Ueyama1a3fd132016-07-14 23:43:36 +0000110 fatal(getName() + " is not a COFF file.");
Rui Ueyama411c63602015-05-28 19:09:30 +0000111 }
112
113 // Read section and symbol tables.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000114 initializeChunks();
115 initializeSymbols();
116 initializeSEH();
Rui Ueyama411c63602015-05-28 19:09:30 +0000117}
118
Rafael Espindolab835ae82015-08-06 14:58:50 +0000119void ObjectFile::initializeChunks() {
Rui Ueyama411c63602015-05-28 19:09:30 +0000120 uint32_t NumSections = COFFObj->getNumberOfSections();
121 Chunks.reserve(NumSections);
122 SparseChunks.resize(NumSections + 1);
123 for (uint32_t I = 1; I < NumSections + 1; ++I) {
124 const coff_section *Sec;
125 StringRef Name;
Rui Ueyama0d09a862016-07-15 00:40:46 +0000126 if (auto EC = COFFObj->getSection(I, Sec))
127 fatal(EC, "getSection failed: #" + Twine(I));
128 if (auto EC = COFFObj->getSectionName(Sec, Name))
129 fatal(EC, "getSectionName failed: #" + Twine(I));
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000130 if (Name == ".sxdata") {
131 SXData = Sec;
132 continue;
133 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000134 if (Name == ".drectve") {
135 ArrayRef<uint8_t> Data;
136 COFFObj->getSectionContents(Sec, Data);
Rui Ueyama0569ecf2015-07-04 03:27:46 +0000137 Directives = std::string((const char *)Data.data(), Data.size());
Rui Ueyama411c63602015-05-28 19:09:30 +0000138 continue;
139 }
Rui Ueyama2832ce92015-07-28 01:06:58 +0000140 // Skip non-DWARF debug info. MSVC linker converts the sections into
141 // a PDB file, but we don't support that.
142 if (Name == ".debug" || Name.startswith(".debug$"))
143 continue;
David Majnemer2c345a32015-07-08 16:37:50 +0000144 // We want to preserve DWARF debug sections only when /debug is on.
145 if (!Config->Debug && Name.startswith(".debug"))
Rui Ueyama411c63602015-05-28 19:09:30 +0000146 continue;
147 if (Sec->Characteristics & llvm::COFF::IMAGE_SCN_LNK_REMOVE)
148 continue;
Peter Collingbournebd3a29d2015-06-24 00:12:36 +0000149 auto *C = new (Alloc) SectionChunk(this, Sec);
Rui Ueyama411c63602015-05-28 19:09:30 +0000150 Chunks.push_back(C);
151 SparseChunks[I] = C;
152 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000153}
154
Rafael Espindolab835ae82015-08-06 14:58:50 +0000155void ObjectFile::initializeSymbols() {
Rui Ueyama411c63602015-05-28 19:09:30 +0000156 uint32_t NumSymbols = COFFObj->getNumberOfSymbols();
157 SymbolBodies.reserve(NumSymbols);
158 SparseSymbolBodies.resize(NumSymbols);
David Majnemer2aa29ee2016-03-20 22:56:31 +0000159 llvm::SmallVector<std::pair<Undefined *, uint32_t>, 8> WeakAliases;
Rui Ueyama411c63602015-05-28 19:09:30 +0000160 int32_t LastSectionNumber = 0;
161 for (uint32_t I = 0; I < NumSymbols; ++I) {
162 // Get a COFFSymbolRef object.
Rui Ueyama659a4f22016-07-15 01:06:38 +0000163 COFFSymbolRef Sym =
164 check(COFFObj->getSymbol(I), "broken object file: " + getName());
Rui Ueyama411c63602015-05-28 19:09:30 +0000165
Rui Ueyama411c63602015-05-28 19:09:30 +0000166 const void *AuxP = nullptr;
167 if (Sym.getNumberOfAuxSymbols())
168 AuxP = COFFObj->getSymbol(I + 1)->getRawPtr();
169 bool IsFirst = (LastSectionNumber != Sym.getSectionNumber());
170
Rui Ueyamadae16612015-06-29 22:16:21 +0000171 SymbolBody *Body = nullptr;
172 if (Sym.isUndefined()) {
173 Body = createUndefined(Sym);
174 } else if (Sym.isWeakExternal()) {
David Majnemer2aa29ee2016-03-20 22:56:31 +0000175 Body = createUndefined(Sym);
176 uint32_t TagIndex =
177 static_cast<const coff_aux_weak_external *>(AuxP)->TagIndex;
178 WeakAliases.emplace_back((Undefined *)Body, TagIndex);
Rui Ueyamadae16612015-06-29 22:16:21 +0000179 } else {
180 Body = createDefined(Sym, AuxP, IsFirst);
181 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000182 if (Body) {
183 SymbolBodies.push_back(Body);
184 SparseSymbolBodies[I] = Body;
185 }
186 I += Sym.getNumberOfAuxSymbols();
187 LastSectionNumber = Sym.getSectionNumber();
188 }
David Majnemer2aa29ee2016-03-20 22:56:31 +0000189 for (auto WeakAlias : WeakAliases)
190 WeakAlias.first->WeakAlias = SparseSymbolBodies[WeakAlias.second];
Rui Ueyama411c63602015-05-28 19:09:30 +0000191}
192
Rui Ueyamadae16612015-06-29 22:16:21 +0000193Undefined *ObjectFile::createUndefined(COFFSymbolRef Sym) {
Rui Ueyama57fe78d2015-06-08 19:43:59 +0000194 StringRef Name;
Rui Ueyamadae16612015-06-29 22:16:21 +0000195 COFFObj->getSymbolName(Sym, Name);
196 return new (Alloc) Undefined(Name);
197}
198
Rui Ueyamadae16612015-06-29 22:16:21 +0000199Defined *ObjectFile::createDefined(COFFSymbolRef Sym, const void *AuxP,
200 bool IsFirst) {
201 StringRef Name;
Rui Ueyama411c63602015-05-28 19:09:30 +0000202 if (Sym.isCommon()) {
Rui Ueyamafc510f42015-06-25 19:10:58 +0000203 auto *C = new (Alloc) CommonChunk(Sym);
Rui Ueyama411c63602015-05-28 19:09:30 +0000204 Chunks.push_back(C);
Rui Ueyama68633f12015-06-25 23:22:00 +0000205 return new (Alloc) DefinedCommon(this, Sym, C);
Rui Ueyama411c63602015-05-28 19:09:30 +0000206 }
Rui Ueyama57fe78d2015-06-08 19:43:59 +0000207 if (Sym.isAbsolute()) {
208 COFFObj->getSymbolName(Sym, Name);
209 // Skip special symbols.
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000210 if (Name == "@comp.id")
Rui Ueyama57fe78d2015-06-08 19:43:59 +0000211 return nullptr;
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000212 // COFF spec 5.10.1. The .sxdata section.
213 if (Name == "@feat.00") {
214 if (Sym.getValue() & 1)
215 SEHCompat = true;
216 return nullptr;
217 }
Rui Ueyamaccde19d2015-06-26 03:09:23 +0000218 return new (Alloc) DefinedAbsolute(Name, Sym);
Rui Ueyama57fe78d2015-06-08 19:43:59 +0000219 }
David Majnemer272de1e2016-03-15 16:47:28 +0000220 int32_t SectionNumber = Sym.getSectionNumber();
221 if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
Peter Collingbournec7b685d2015-06-24 00:05:50 +0000222 return nullptr;
Chandler Carruthee5bf522015-06-29 21:32:37 +0000223
David Majnemer272de1e2016-03-15 16:47:28 +0000224 // Reserved sections numbers don't have contents.
225 if (llvm::COFF::isReservedSectionNumber(SectionNumber))
Rui Ueyama1a3fd132016-07-14 23:43:36 +0000226 fatal("broken object file: " + getName());
David Majnemer272de1e2016-03-15 16:47:28 +0000227
228 // This symbol references a section which is not present in the section
229 // header.
230 if ((uint32_t)SectionNumber >= SparseChunks.size())
Rui Ueyama1a3fd132016-07-14 23:43:36 +0000231 fatal("broken object file: " + getName());
David Majnemer272de1e2016-03-15 16:47:28 +0000232
Chandler Carruthee5bf522015-06-29 21:32:37 +0000233 // Nothing else to do without a section chunk.
David Majnemer272de1e2016-03-15 16:47:28 +0000234 auto *SC = cast_or_null<SectionChunk>(SparseChunks[SectionNumber]);
Chandler Carruthee5bf522015-06-29 21:32:37 +0000235 if (!SC)
236 return nullptr;
237
Rui Ueyama2dcc2352015-09-04 20:45:50 +0000238 // Handle section definitions
Rui Ueyama411c63602015-05-28 19:09:30 +0000239 if (IsFirst && AuxP) {
Chandler Carruthee5bf522015-06-29 21:32:37 +0000240 auto *Aux = reinterpret_cast<const coff_aux_section_definition *>(AuxP);
241 if (Aux->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE)
242 if (auto *ParentSC = cast_or_null<SectionChunk>(
243 SparseChunks[Aux->getNumber(Sym.isBigObj())]))
244 ParentSC->addAssociative(SC);
Rui Ueyama2dcc2352015-09-04 20:45:50 +0000245 SC->Checksum = Aux->CheckSum;
Rui Ueyama411c63602015-05-28 19:09:30 +0000246 }
Chandler Carruthee5bf522015-06-29 21:32:37 +0000247
248 auto *B = new (Alloc) DefinedRegular(this, Sym, SC);
249 if (SC->isCOMDAT() && Sym.getValue() == 0 && !AuxP)
250 SC->setSymbol(B);
251
252 return B;
Rui Ueyama411c63602015-05-28 19:09:30 +0000253}
254
Rafael Espindolab835ae82015-08-06 14:58:50 +0000255void ObjectFile::initializeSEH() {
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000256 if (!SEHCompat || !SXData)
Rafael Espindolab835ae82015-08-06 14:58:50 +0000257 return;
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000258 ArrayRef<uint8_t> A;
259 COFFObj->getSectionContents(SXData, A);
Rafael Espindolab835ae82015-08-06 14:58:50 +0000260 if (A.size() % 4 != 0)
Rui Ueyama60604792016-07-14 23:37:14 +0000261 fatal(".sxdata must be an array of symbol table indices");
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000262 auto *I = reinterpret_cast<const ulittle32_t *>(A.data());
263 auto *E = reinterpret_cast<const ulittle32_t *>(A.data() + A.size());
264 for (; I != E; ++I)
265 SEHandlers.insert(SparseSymbolBodies[*I]);
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000266}
267
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000268MachineTypes ObjectFile::getMachineType() {
269 if (COFFObj)
270 return static_cast<MachineTypes>(COFFObj->getMachine());
271 return IMAGE_FILE_MACHINE_UNKNOWN;
272}
273
Rui Ueyamaa841bb02015-07-09 20:22:41 +0000274StringRef ltrim1(StringRef S, const char *Chars) {
275 if (!S.empty() && strchr(Chars, S[0]))
276 return S.substr(1);
277 return S;
278}
279
Rafael Espindolab835ae82015-08-06 14:58:50 +0000280void ImportFile::parse() {
Rui Ueyamad7c2f582015-05-31 21:04:56 +0000281 const char *Buf = MB.getBufferStart();
282 const char *End = MB.getBufferEnd();
Rui Ueyama411c63602015-05-28 19:09:30 +0000283 const auto *Hdr = reinterpret_cast<const coff_import_header *>(Buf);
284
285 // Check if the total size is valid.
Rafael Espindolab835ae82015-08-06 14:58:50 +0000286 if ((size_t)(End - Buf) != (sizeof(*Hdr) + Hdr->SizeOfData))
Rui Ueyama60604792016-07-14 23:37:14 +0000287 fatal("broken import library");
Rui Ueyama411c63602015-05-28 19:09:30 +0000288
289 // Read names and create an __imp_ symbol.
290 StringRef Name = StringAlloc.save(StringRef(Buf + sizeof(*Hdr)));
Rui Ueyama1a3fd132016-07-14 23:43:36 +0000291 StringRef ImpName = StringAlloc.save("__imp_" + Name);
Rui Ueyamad1570882015-08-17 08:30:31 +0000292 const char *NameStart = Buf + sizeof(coff_import_header) + Name.size() + 1;
Rui Ueyamabfbd2772015-09-02 07:27:31 +0000293 DLLName = StringRef(NameStart);
Rui Ueyama1c79ce92015-07-08 20:22:50 +0000294 StringRef ExtName;
295 switch (Hdr->getNameType()) {
296 case IMPORT_ORDINAL:
297 ExtName = "";
298 break;
299 case IMPORT_NAME:
300 ExtName = Name;
301 break;
302 case IMPORT_NAME_NOPREFIX:
Rui Ueyamaa841bb02015-07-09 20:22:41 +0000303 ExtName = ltrim1(Name, "?@_");
Rui Ueyama1c79ce92015-07-08 20:22:50 +0000304 break;
305 case IMPORT_NAME_UNDECORATE:
Rui Ueyamaa841bb02015-07-09 20:22:41 +0000306 ExtName = ltrim1(Name, "?@_");
Rui Ueyama1c79ce92015-07-08 20:22:50 +0000307 ExtName = ExtName.substr(0, ExtName.find('@'));
308 break;
309 }
Rui Ueyamae73e4182015-08-17 07:27:45 +0000310 ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExtName, Hdr);
Rui Ueyama411c63602015-05-28 19:09:30 +0000311 SymbolBodies.push_back(ImpSym);
312
313 // If type is function, we need to create a thunk which jump to an
314 // address pointed by the __imp_ symbol. (This allows you to call
315 // DLL functions just like regular non-DLL functions.)
Rui Ueyamae73e4182015-08-17 07:27:45 +0000316 if (Hdr->getType() != llvm::COFF::IMPORT_CODE)
317 return;
318 ThunkSym = new (Alloc) DefinedImportThunk(Name, ImpSym, Hdr->Machine);
319 SymbolBodies.push_back(ThunkSym);
Rui Ueyama411c63602015-05-28 19:09:30 +0000320}
321
Rafael Espindolab835ae82015-08-06 14:58:50 +0000322void BitcodeFile::parse() {
Rui Ueyamaebb0ebf2015-09-19 23:14:51 +0000323 // Usually parse() is thread-safe, but bitcode file is an exception.
324 std::lock_guard<std::mutex> Lock(Mu);
325
Duncan P. N. Exon Smith28d8d042016-04-19 04:57:40 +0000326 Context.enableDebugTypeODRUniquing();
Rui Ueyama34b60f12016-04-14 21:41:44 +0000327 ErrorOr<std::unique_ptr<LTOModule>> ModOrErr = LTOModule::createFromBuffer(
328 Context, MB.getBufferStart(), MB.getBufferSize(), llvm::TargetOptions());
Rui Ueyama659a4f22016-07-15 01:06:38 +0000329 M = check(std::move(ModOrErr), "Could not create lto module");
Peter Collingbourne60c16162015-06-01 20:10:10 +0000330
Rafael Espindolaf0461ba2015-08-13 01:07:08 +0000331 llvm::StringSaver Saver(Alloc);
Peter Collingbourne60c16162015-06-01 20:10:10 +0000332 for (unsigned I = 0, E = M->getSymbolCount(); I != E; ++I) {
Peter Collingbournedf637ea2015-06-08 20:21:28 +0000333 lto_symbol_attributes Attrs = M->getSymbolAttributes(I);
334 if ((Attrs & LTO_SYMBOL_SCOPE_MASK) == LTO_SYMBOL_SCOPE_INTERNAL)
335 continue;
336
Rui Ueyama223fe1b2015-06-18 20:29:41 +0000337 StringRef SymName = Saver.save(M->getSymbolName(I));
Peter Collingbournedf637ea2015-06-08 20:21:28 +0000338 int SymbolDef = Attrs & LTO_SYMBOL_DEFINITION_MASK;
339 if (SymbolDef == LTO_SYMBOL_DEFINITION_UNDEFINED) {
Peter Collingbourne60c16162015-06-01 20:10:10 +0000340 SymbolBodies.push_back(new (Alloc) Undefined(SymName));
341 } else {
Peter Collingbourne2612a322015-07-04 05:28:41 +0000342 bool Replaceable =
343 (SymbolDef == LTO_SYMBOL_DEFINITION_TENTATIVE || // common
344 (Attrs & LTO_SYMBOL_COMDAT) || // comdat
345 (SymbolDef == LTO_SYMBOL_DEFINITION_WEAK && // weak external
346 (Attrs & LTO_SYMBOL_ALIAS)));
Peter Collingbournef7b27d12015-06-30 00:47:52 +0000347 SymbolBodies.push_back(new (Alloc) DefinedBitcode(this, SymName,
348 Replaceable));
Peter Collingbourne60c16162015-06-01 20:10:10 +0000349 }
350 }
Peter Collingbourneace2f092015-06-06 02:00:45 +0000351
Peter Collingbourne79cfd432015-06-29 23:26:28 +0000352 Directives = M->getLinkerOpts();
Peter Collingbourne60c16162015-06-01 20:10:10 +0000353}
Rui Ueyama81b030c2015-06-01 21:19:43 +0000354
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000355MachineTypes BitcodeFile::getMachineType() {
356 if (!M)
357 return IMAGE_FILE_MACHINE_UNKNOWN;
358 switch (Triple(M->getTargetTriple()).getArch()) {
359 case Triple::x86_64:
Rui Ueyama5e706b32015-07-25 21:54:50 +0000360 return AMD64;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000361 case Triple::x86:
Rui Ueyama5e706b32015-07-25 21:54:50 +0000362 return I386;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000363 case Triple::arm:
Rui Ueyama5e706b32015-07-25 21:54:50 +0000364 return ARMNT;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000365 default:
366 return IMAGE_FILE_MACHINE_UNKNOWN;
367 }
368}
369
Rui Ueyamaebb0ebf2015-09-19 23:14:51 +0000370std::mutex BitcodeFile::Mu;
371
Rui Ueyama411c63602015-05-28 19:09:30 +0000372} // namespace coff
373} // namespace lld