blob: 1e0b97a82be29470d4110a6e9ccfad6f6f221c23 [file] [log] [blame]
Rafael Espindolabeee25e2015-08-14 14:12:541//===- InputFiles.h ---------------------------------------------*- C++ -*-===//
Rui Ueyama411c63602015-05-28 19:09:302//
Chandler Carruth2946cd72019-01-19 08:50:563// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Rui Ueyama411c63602015-05-28 19:09:306//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLD_COFF_INPUT_FILES_H
10#define LLD_COFF_INPUT_FILES_H
11
Rui Ueyama9aa82f72017-05-24 22:30:0612#include "Config.h"
Rui Ueyama3f851702017-10-02 21:00:4113#include "lld/Common/LLVM.h"
Rui Ueyama411c63602015-05-28 19:09:3014#include "llvm/ADT/ArrayRef.h"
Martin Storsjo21858a9b2018-08-06 21:26:0915#include "llvm/ADT/DenseMap.h"
Peter Collingbourne8155dfa2016-12-12 03:16:1416#include "llvm/ADT/DenseSet.h"
Bob Haarman7dc5e7a02019-09-03 20:32:1617#include "llvm/BinaryFormat/Magic.h"
Rui Ueyama411c63602015-05-28 19:09:3018#include "llvm/Object/Archive.h"
19#include "llvm/Object/COFF.h"
Rafael Espindola9bd82e92015-06-13 12:50:1320#include "llvm/Support/StringSaver.h"
Rui Ueyama411c63602015-05-28 19:09:3021#include <memory>
22#include <set>
23#include <vector>
24
Reid Kleckner8cbdd0c2017-06-13 15:49:1325namespace llvm {
Martin Storsjo65b1c492019-10-21 08:01:5926struct DILineInfo;
Reid Kleckner8cbdd0c2017-06-13 15:49:1327namespace pdb {
28class DbiModuleDescriptorBuilder;
Reid Kleckner54a335a2020-05-09 13:58:1529class NativeSession;
Reid Kleckner8cbdd0c2017-06-13 15:49:1330}
Reid Klecknerf24c3352019-11-14 21:46:0031namespace lto {
32class InputFile;
33}
Reid Kleckner8cbdd0c2017-06-13 15:49:1334}
35
Rui Ueyama411c63602015-05-28 19:09:3036namespace lld {
Reid Kleckneradfad4d2019-11-14 22:16:2137class DWARFCache;
38
Rui Ueyama411c63602015-05-28 19:09:3039namespace coff {
40
Rui Ueyama136d27a2019-07-11 05:40:3041std::vector<MemoryBufferRef> getArchiveMembers(llvm::object::Archive *file);
Rui Ueyamaf59b7092017-08-30 20:55:1842
Rui Ueyamaea533cd2015-07-09 19:54:1343using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
44using llvm::COFF::MachineTypes;
Rui Ueyama411c63602015-05-28 19:09:3045using llvm::object::Archive;
46using llvm::object::COFFObjectFile;
Chandler Carruthbe6e80b2015-06-29 18:50:1147using llvm::object::COFFSymbolRef;
Peter Collingbourne79a5e6b2016-12-09 21:55:2448using llvm::object::coff_import_header;
Rui Ueyamacd3f99b2015-07-24 23:51:1449using llvm::object::coff_section;
Chandler Carruthbe6e80b2015-06-29 18:50:1150
51class Chunk;
Rui Ueyamadae16612015-06-29 22:16:2152class Defined;
Rui Ueyamae73e4182015-08-17 07:27:4553class DefinedImportData;
54class DefinedImportThunk;
Nico Weber04db8cb2019-02-14 03:16:4455class DefinedRegular;
Rui Ueyamabe939b32016-11-21 17:22:3556class SectionChunk;
Rui Ueyamaf52496e2017-11-03 21:21:4757class Symbol;
Rui Ueyamadae16612015-06-29 22:16:2158class Undefined;
Alexandre Ganeabf55c4e2019-04-01 13:36:5959class TpiSource;
Rui Ueyama411c63602015-05-28 19:09:3060
61// The root class of input files.
62class InputFile {
63public:
Bob Haarman7dc5e7a02019-09-03 20:32:1664 enum Kind {
65 ArchiveKind,
66 ObjectKind,
67 LazyObjectKind,
Reid Kleckner54a335a2020-05-09 13:58:1568 PDBKind,
Bob Haarman7dc5e7a02019-09-03 20:32:1669 ImportKind,
70 BitcodeKind
71 };
Rui Ueyama136d27a2019-07-11 05:40:3072 Kind kind() const { return fileKind; }
Rui Ueyama411c63602015-05-28 19:09:3073 virtual ~InputFile() {}
74
75 // Returns the filename.
Rui Ueyama136d27a2019-07-11 05:40:3076 StringRef getName() const { return mb.getBufferIdentifier(); }
Rui Ueyama411c63602015-05-28 19:09:3077
Rui Ueyama1574b8e2015-08-06 19:57:2178 // Reads a file (the constructor doesn't do that).
Rafael Espindolab835ae82015-08-06 14:58:5079 virtual void parse() = 0;
Rui Ueyama411c63602015-05-28 19:09:3080
Rui Ueyamaea533cd2015-07-09 19:54:1381 // Returns the CPU type this file was compiled to.
82 virtual MachineTypes getMachineType() { return IMAGE_FILE_MACHINE_UNKNOWN; }
83
Rui Ueyama136d27a2019-07-11 05:40:3084 MemoryBufferRef mb;
Bob Haarman41108162017-04-21 21:38:0185
Rui Ueyamaa45d45e2016-12-07 23:17:0286 // An archive file name if this file is created from an archive.
Rui Ueyama136d27a2019-07-11 05:40:3087 StringRef parentName;
Rui Ueyama411c63602015-05-28 19:09:3088
Rui Ueyamaeeae5dd2015-06-08 06:00:1089 // Returns .drectve section contents if exist.
Rui Ueyama136d27a2019-07-11 05:40:3090 StringRef getDirectives() { return directives; }
Rui Ueyamaeeae5dd2015-06-08 06:00:1091
Rui Ueyama411c63602015-05-28 19:09:3092protected:
Rui Ueyama136d27a2019-07-11 05:40:3093 InputFile(Kind k, MemoryBufferRef m) : mb(m), fileKind(k) {}
Rui Ueyama65813ed2015-07-02 20:33:4894
Rui Ueyama136d27a2019-07-11 05:40:3095 StringRef directives;
Rui Ueyama411c63602015-05-28 19:09:3096
97private:
Rui Ueyama136d27a2019-07-11 05:40:3098 const Kind fileKind;
Rui Ueyama411c63602015-05-28 19:09:3099};
100
101// .lib or .a file.
102class ArchiveFile : public InputFile {
103public:
Rui Ueyama136d27a2019-07-11 05:40:30104 explicit ArchiveFile(MemoryBufferRef m);
105 static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; }
Rafael Espindolab835ae82015-08-06 14:58:50106 void parse() override;
Rui Ueyama411c63602015-05-28 19:09:30107
Peter Collingbourne6ee0b4e2016-12-15 04:02:23108 // Enqueues an archive member load for the given symbol. If we've already
109 // enqueued a load for the same archive member, this function does nothing,
110 // which ensures that we don't load the same member more than once.
Nico Webercb2c5002019-07-19 13:29:10111 void addMember(const Archive::Symbol &sym);
Rui Ueyama411c63602015-05-28 19:09:30112
113private:
Rui Ueyama136d27a2019-07-11 05:40:30114 std::unique_ptr<Archive> file;
115 llvm::DenseSet<uint64_t> seen;
Rui Ueyama411c63602015-05-28 19:09:30116};
117
Bob Haarman7dc5e7a02019-09-03 20:32:16118// .obj or .o file between -start-lib and -end-lib.
119class LazyObjFile : public InputFile {
120public:
121 explicit LazyObjFile(MemoryBufferRef m) : InputFile(LazyObjectKind, m) {}
122 static bool classof(const InputFile *f) {
123 return f->kind() == LazyObjectKind;
124 }
125 // Makes this object file part of the link.
126 void fetch();
127 // Adds the symbols in this file to the symbol table as LazyObject symbols.
128 void parse() override;
129
130private:
131 std::vector<Symbol *> symbols;
132};
133
Rui Ueyama411c63602015-05-28 19:09:30134// .obj or .o file. This may be a member of an archive file.
Rui Ueyamae1b48e02017-07-26 23:05:24135class ObjFile : public InputFile {
Rui Ueyama411c63602015-05-28 19:09:30136public:
Rui Ueyama136d27a2019-07-11 05:40:30137 explicit ObjFile(MemoryBufferRef m) : InputFile(ObjectKind, m) {}
Bob Haarman7dc5e7a02019-09-03 20:32:16138 explicit ObjFile(MemoryBufferRef m, std::vector<Symbol *> &&symbols)
139 : InputFile(ObjectKind, m), symbols(std::move(symbols)) {}
Rui Ueyama136d27a2019-07-11 05:40:30140 static bool classof(const InputFile *f) { return f->kind() == ObjectKind; }
Rafael Espindolab835ae82015-08-06 14:58:50141 void parse() override;
Rui Ueyamaea533cd2015-07-09 19:54:13142 MachineTypes getMachineType() override;
Rui Ueyama136d27a2019-07-11 05:40:30143 ArrayRef<Chunk *> getChunks() { return chunks; }
144 ArrayRef<SectionChunk *> getDebugChunks() { return debugChunks; }
Reid Kleckner3774bcf2020-05-14 18:21:53145 ArrayRef<SectionChunk *> getSXDataChunks() { return sxDataChunks; }
Rui Ueyama136d27a2019-07-11 05:40:30146 ArrayRef<SectionChunk *> getGuardFidChunks() { return guardFidChunks; }
147 ArrayRef<SectionChunk *> getGuardLJmpChunks() { return guardLJmpChunks; }
148 ArrayRef<Symbol *> getSymbols() { return symbols; }
Rui Ueyama411c63602015-05-28 19:09:30149
Rui Ueyama136d27a2019-07-11 05:40:30150 ArrayRef<uint8_t> getDebugSection(StringRef secName);
Alexandre Ganead307c4c2019-02-23 01:46:18151
Fangrui Song2e2038b2019-07-16 08:26:38152 // Returns a Symbol object for the symbolIndex'th symbol in the
Rui Ueyama411c63602015-05-28 19:09:30153 // underlying object file.
Rui Ueyama136d27a2019-07-11 05:40:30154 Symbol *getSymbol(uint32_t symbolIndex) {
155 return symbols[symbolIndex];
Chandler Carruth52eb3552015-06-27 03:40:10156 }
Rui Ueyama411c63602015-05-28 19:09:30157
Alexandre Ganea71c43ce2018-11-05 19:20:47158 // Returns the underlying COFF file.
Rui Ueyama136d27a2019-07-11 05:40:30159 COFFObjectFile *getCOFFObj() { return coffObj.get(); }
Rui Ueyama411c63602015-05-28 19:09:30160
Reid Kleckner16004902019-03-28 18:30:03161 // Add a symbol for a range extension thunk. Return the new symbol table
162 // index. This index can be used to modify a relocation.
Rui Ueyama136d27a2019-07-11 05:40:30163 uint32_t addRangeThunkSymbol(Symbol *thunk) {
164 symbols.push_back(thunk);
165 return symbols.size() - 1;
Reid Kleckner16004902019-03-28 18:30:03166 }
167
Martin Storsjo3d3a9b32019-08-30 06:56:33168 void includeResourceChunks();
169
170 bool isResourceObjFile() const { return !resourceChunks.empty(); }
171
Rui Ueyama136d27a2019-07-11 05:40:30172 static std::vector<ObjFile *> instances;
Rui Ueyamaacd632d2017-07-27 00:45:26173
Reid Kleckneraf2f7da2018-02-06 01:58:26174 // Flags in the absolute @feat.00 symbol if it is present. These usually
175 // indicate if an object was compiled with certain security features enabled
176 // like stack guard, safeseh, /guard:cf, or other things.
Rui Ueyama136d27a2019-07-11 05:40:30177 uint32_t feat00Flags = 0;
Rui Ueyamacd3f99b2015-07-24 23:51:14178
Reid Kleckneraf2f7da2018-02-06 01:58:26179 // True if this object file is compatible with SEH. COFF-specific and
180 // x86-only. COFF spec 5.10.1. The .sxdata section.
Rui Ueyama136d27a2019-07-11 05:40:30181 bool hasSafeSEH() { return feat00Flags & 0x1; }
Reid Kleckneraf2f7da2018-02-06 01:58:26182
183 // True if this file was compiled with /guard:cf.
Rui Ueyama136d27a2019-07-11 05:40:30184 bool hasGuardCF() { return feat00Flags & 0x800; }
Rui Ueyamacd3f99b2015-07-24 23:51:14185
Reid Kleckner8cbdd0c2017-06-13 15:49:13186 // Pointer to the PDB module descriptor builder. Various debug info records
187 // will reference object files by "module index", which is here. Things like
188 // source files and section contributions are also recorded here. Will be null
189 // if we are not producing a PDB.
Rui Ueyama136d27a2019-07-11 05:40:30190 llvm::pdb::DbiModuleDescriptorBuilder *moduleDBI = nullptr;
Reid Kleckner8cbdd0c2017-06-13 15:49:13191
Rui Ueyama136d27a2019-07-11 05:40:30192 const coff_section *addrsigSec = nullptr;
Peter Collingbourneab038022018-08-23 17:44:42193
Zequan Wu763671f2020-07-21 20:46:11194 const coff_section *callgraphSec = nullptr;
195
Alexandre Ganea71c43ce2018-11-05 19:20:47196 // When using Microsoft precompiled headers, this is the PCH's key.
197 // The same key is used by both the precompiled object, and objects using the
198 // precompiled object. Any difference indicates out-of-date objects.
Rui Ueyama136d27a2019-07-11 05:40:30199 llvm::Optional<uint32_t> pchSignature;
Alexandre Ganea71c43ce2018-11-05 19:20:47200
Nico Weberaf6bc652019-06-11 15:22:28201 // Whether this file was compiled with /hotpatch.
Rui Ueyama136d27a2019-07-11 05:40:30202 bool hotPatchable = false;
Alexandre Ganead307c4c2019-02-23 01:46:18203
Nico Weberaf6bc652019-06-11 15:22:28204 // Whether the object was already merged into the final PDB.
Rui Ueyama136d27a2019-07-11 05:40:30205 bool mergedIntoPDB = false;
Alexandre Ganea74d5b332019-03-22 22:07:27206
Alexandre Ganeabf55c4e2019-04-01 13:36:59207 // If the OBJ has a .debug$T stream, this tells how it will be handled.
Rui Ueyama136d27a2019-07-11 05:40:30208 TpiSource *debugTypesObj = nullptr;
Alexandre Ganeabf55c4e2019-04-01 13:36:59209
Reid Klecknerde3fb1e2019-11-14 22:27:48210 // The .debug$P or .debug$T section data if present. Empty otherwise.
211 ArrayRef<uint8_t> debugTypes;
Alexandre Ganeabf55c4e2019-04-01 13:36:59212
Martin Storsjob38f5772019-10-18 10:43:15213 llvm::Optional<std::pair<StringRef, uint32_t>>
214 getVariableLocation(StringRef var);
215
Martin Storsjo65b1c492019-10-21 08:01:59216 llvm::Optional<llvm::DILineInfo> getDILineInfo(uint32_t offset,
217 uint32_t sectionIndex);
218
Rui Ueyama411c63602015-05-28 19:09:30219private:
Rui Ueyama136d27a2019-07-11 05:40:30220 const coff_section* getSection(uint32_t i);
221 const coff_section *getSection(COFFSymbolRef sym) {
222 return getSection(sym.getSectionNumber());
Nico Weber04db8cb2019-02-14 03:16:44223 }
Nico Weber48dc1102019-01-30 02:17:27224
Rafael Espindolab835ae82015-08-06 14:58:50225 void initializeChunks();
226 void initializeSymbols();
Alexandre Ganead307c4c2019-02-23 01:46:18227 void initializeFlags();
Alexandre Ganeabf55c4e2019-04-01 13:36:59228 void initializeDependencies();
Rui Ueyama411c63602015-05-28 19:09:30229
Peter Collingbourne1621c202017-11-28 01:30:07230 SectionChunk *
Rui Ueyama136d27a2019-07-11 05:40:30231 readSection(uint32_t sectionNumber,
232 const llvm::object::coff_aux_section_definition *def,
233 StringRef leaderName);
Peter Collingbourne1621c202017-11-28 01:30:07234
235 void readAssociativeDefinition(
Rui Ueyama136d27a2019-07-11 05:40:30236 COFFSymbolRef coffSym,
237 const llvm::object::coff_aux_section_definition *def);
Peter Collingbourne1621c202017-11-28 01:30:07238
Martin Storsjo21858a9b2018-08-06 21:26:09239 void readAssociativeDefinition(
Rui Ueyama136d27a2019-07-11 05:40:30240 COFFSymbolRef coffSym,
241 const llvm::object::coff_aux_section_definition *def,
242 uint32_t parentSection);
Martin Storsjo21858a9b2018-08-06 21:26:09243
244 void recordPrevailingSymbolForMingw(
Rui Ueyama136d27a2019-07-11 05:40:30245 COFFSymbolRef coffSym,
246 llvm::DenseMap<StringRef, uint32_t> &prevailingSectionMap);
Martin Storsjo21858a9b2018-08-06 21:26:09247
248 void maybeAssociateSEHForMingw(
Rui Ueyama136d27a2019-07-11 05:40:30249 COFFSymbolRef sym, const llvm::object::coff_aux_section_definition *def,
250 const llvm::DenseMap<StringRef, uint32_t> &prevailingSectionMap);
Martin Storsjo21858a9b2018-08-06 21:26:09251
Nico Weber04db8cb2019-02-14 03:16:44252 // Given a new symbol Sym with comdat selection Selection, if the new
253 // symbol is not (yet) Prevailing and the existing comdat leader set to
254 // Leader, emits a diagnostic if the new symbol and its selection doesn't
255 // match the existing symbol and its selection. If either old or new
256 // symbol have selection IMAGE_COMDAT_SELECT_LARGEST, Sym might replace
257 // the existing leader. In that case, Prevailing is set to true.
Rui Ueyama136d27a2019-07-11 05:40:30258 void handleComdatSelection(COFFSymbolRef sym,
259 llvm::COFF::COMDATType &selection,
260 bool &prevailing, DefinedRegular *leader);
Nico Weber04db8cb2019-02-14 03:16:44261
Peter Collingbourne1621c202017-11-28 01:30:07262 llvm::Optional<Symbol *>
Rui Ueyama136d27a2019-07-11 05:40:30263 createDefined(COFFSymbolRef sym,
Peter Collingbourne1621c202017-11-28 01:30:07264 std::vector<const llvm::object::coff_aux_section_definition *>
Rui Ueyama136d27a2019-07-11 05:40:30265 &comdatDefs,
266 bool &prevailingComdat);
267 Symbol *createRegular(COFFSymbolRef sym);
268 Symbol *createUndefined(COFFSymbolRef sym);
Rui Ueyama411c63602015-05-28 19:09:30269
Rui Ueyama136d27a2019-07-11 05:40:30270 std::unique_ptr<COFFObjectFile> coffObj;
Rui Ueyama411c63602015-05-28 19:09:30271
272 // List of all chunks defined by this file. This includes both section
273 // chunks and non-section chunks for common symbols.
Rui Ueyama136d27a2019-07-11 05:40:30274 std::vector<Chunk *> chunks;
Rui Ueyama411c63602015-05-28 19:09:30275
Martin Storsjo3d3a9b32019-08-30 06:56:33276 std::vector<SectionChunk *> resourceChunks;
277
Rui Ueyamabe939b32016-11-21 17:22:35278 // CodeView debug info sections.
Rui Ueyama136d27a2019-07-11 05:40:30279 std::vector<SectionChunk *> debugChunks;
Rui Ueyamabe939b32016-11-21 17:22:35280
Reid Kleckneraf2f7da2018-02-06 01:58:26281 // Chunks containing symbol table indices of exception handlers. Only used for
282 // 32-bit x86.
Reid Kleckner3774bcf2020-05-14 18:21:53283 std::vector<SectionChunk *> sxDataChunks;
Reid Kleckneraf2f7da2018-02-06 01:58:26284
Reid Klecknerfd520962018-02-13 20:32:53285 // Chunks containing symbol table indices of address taken symbols and longjmp
286 // targets. These are not linked into the final binary when /guard:cf is set.
Rui Ueyama136d27a2019-07-11 05:40:30287 std::vector<SectionChunk *> guardFidChunks;
288 std::vector<SectionChunk *> guardLJmpChunks;
Reid Kleckneraf2f7da2018-02-06 01:58:26289
Peter Collingbourne80f961a2017-11-20 18:52:53290 // This vector contains a list of all symbols defined or referenced by this
291 // file. They are indexed such that you can get a Symbol by symbol
Rui Ueyama411c63602015-05-28 19:09:30292 // index. Nonexistent indices (which are occupied by auxiliary
293 // symbols in the real symbol table) are filled with null pointers.
Rui Ueyama136d27a2019-07-11 05:40:30294 std::vector<Symbol *> symbols;
Martin Storsjob38f5772019-10-18 10:43:15295
Reid Kleckner11d1aa02020-06-02 01:46:51296 // This vector contains the same chunks as Chunks, but they are
297 // indexed such that you can get a SectionChunk by section index.
298 // Nonexistent section indices are filled with null pointers.
299 // (Because section number is 1-based, the first slot is always a
300 // null pointer.) This vector is only valid during initialization.
301 std::vector<SectionChunk *> sparseChunks;
302
Martin Storsjo150a9ad2019-10-21 09:35:34303 DWARFCache *dwarf = nullptr;
Rui Ueyama411c63602015-05-28 19:09:30304};
305
Reid Kleckner54a335a2020-05-09 13:58:15306// This is a PDB type server dependency, that is not a input file per se, but
307// needs to be treated like one. Such files are discovered from the debug type
308// stream.
309class PDBInputFile : public InputFile {
310public:
311 explicit PDBInputFile(MemoryBufferRef m);
312 ~PDBInputFile();
313 static bool classof(const InputFile *f) { return f->kind() == PDBKind; }
314 void parse() override;
315
316 static void enqueue(StringRef path, ObjFile *fromFile);
317
318 static PDBInputFile *findFromRecordPath(StringRef path, ObjFile *fromFile);
319
320 static std::map<std::string, PDBInputFile *> instances;
321
322 // Record possible errors while opening the PDB file
323 llvm::Optional<Error> loadErr;
324
325 // This is the actual interface to the PDB (if it was opened successfully)
326 std::unique_ptr<llvm::pdb::NativeSession> session;
327
328 // If the PDB has a .debug$T stream, this tells how it will be handled.
329 TpiSource *debugTypesObj = nullptr;
330};
331
Rui Ueyama411c63602015-05-28 19:09:30332// This type represents import library members that contain DLL names
333// and symbols exported from the DLLs. See Microsoft PE/COFF spec. 7
334// for details about the format.
335class ImportFile : public InputFile {
336public:
Rui Ueyama136d27a2019-07-11 05:40:30337 explicit ImportFile(MemoryBufferRef m) : InputFile(ImportKind, m) {}
Rui Ueyama9aa82f72017-05-24 22:30:06338
Rui Ueyama136d27a2019-07-11 05:40:30339 static bool classof(const InputFile *f) { return f->kind() == ImportKind; }
Rui Ueyama411c63602015-05-28 19:09:30340
Rui Ueyama136d27a2019-07-11 05:40:30341 static std::vector<ImportFile *> instances;
Rui Ueyamaacd632d2017-07-27 00:45:26342
Rui Ueyama136d27a2019-07-11 05:40:30343 Symbol *impSym = nullptr;
344 Symbol *thunkSym = nullptr;
345 std::string dllName;
Rui Ueyamae73e4182015-08-17 07:27:45346
Rui Ueyama411c63602015-05-28 19:09:30347private:
Rafael Espindolab835ae82015-08-06 14:58:50348 void parse() override;
Rui Ueyama411c63602015-05-28 19:09:30349
Peter Collingbourne79a5e6b2016-12-09 21:55:24350public:
Rui Ueyama136d27a2019-07-11 05:40:30351 StringRef externalName;
352 const coff_import_header *hdr;
353 Chunk *location = nullptr;
Rui Ueyama9aa82f72017-05-24 22:30:06354
355 // We want to eliminate dllimported symbols if no one actually refers them.
Peter Collingbournee28faed2018-05-10 19:01:28356 // These "Live" bits are used to keep track of which import library members
Rui Ueyama9aa82f72017-05-24 22:30:06357 // are actually in use.
358 //
359 // If the Live bit is turned off by MarkLive, Writer will ignore dllimported
Peter Collingbournee28faed2018-05-10 19:01:28360 // symbols provided by this import library member. We also track whether the
361 // imported symbol is used separately from whether the thunk is used in order
362 // to avoid creating unnecessary thunks.
Rui Ueyama136d27a2019-07-11 05:40:30363 bool live = !config->doGC;
364 bool thunkLive = !config->doGC;
Rui Ueyama411c63602015-05-28 19:09:30365};
366
Peter Collingbourne60c16162015-06-01 20:10:10367// Used for LTO.
368class BitcodeFile : public InputFile {
369public:
Rui Ueyama136d27a2019-07-11 05:40:30370 BitcodeFile(MemoryBufferRef mb, StringRef archiveName,
Reid Klecknerf24c3352019-11-14 21:46:00371 uint64_t offsetInArchive);
Bob Haarman7dc5e7a02019-09-03 20:32:16372 explicit BitcodeFile(MemoryBufferRef m, StringRef archiveName,
373 uint64_t offsetInArchive,
374 std::vector<Symbol *> &&symbols);
Reid Klecknerf24c3352019-11-14 21:46:00375 ~BitcodeFile();
Rui Ueyama136d27a2019-07-11 05:40:30376 static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }
377 ArrayRef<Symbol *> getSymbols() { return symbols; }
Rui Ueyamaea533cd2015-07-09 19:54:13378 MachineTypes getMachineType() override;
Rui Ueyama136d27a2019-07-11 05:40:30379 static std::vector<BitcodeFile *> instances;
380 std::unique_ptr<llvm::lto::InputFile> obj;
Rui Ueyama34b60f12016-04-14 21:41:44381
Peter Collingbourne60c16162015-06-01 20:10:10382private:
Rafael Espindolab835ae82015-08-06 14:58:50383 void parse() override;
Peter Collingbourne60c16162015-06-01 20:10:10384
Rui Ueyama136d27a2019-07-11 05:40:30385 std::vector<Symbol *> symbols;
Peter Collingbourne60c16162015-06-01 20:10:10386};
Bob Haarman5011b832019-07-11 18:48:58387
Bob Haarman7dc5e7a02019-09-03 20:32:16388inline bool isBitcode(MemoryBufferRef mb) {
389 return identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode;
390}
391
Bob Haarman5011b832019-07-11 18:48:58392std::string replaceThinLTOSuffix(StringRef path);
Rui Ueyama411c63602015-05-28 19:09:30393} // namespace coff
Rui Ueyamace039262017-01-06 10:04:08394
Rui Ueyama136d27a2019-07-11 05:40:30395std::string toString(const coff::InputFile *file);
Rui Ueyama411c63602015-05-28 19:09:30396} // namespace lld
397
398#endif