xref: /freebsd/contrib/llvm-project/lld/COFF/InputFiles.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===- InputFiles.h ---------------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLD_COFF_INPUT_FILES_H
100b57cec5SDimitry Andric #define LLD_COFF_INPUT_FILES_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "Config.h"
130b57cec5SDimitry Andric #include "lld/Common/LLVM.h"
140b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
150b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h"
160b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h"
17fe6060f1SDimitry Andric #include "llvm/ADT/StringSet.h"
1885868e8aSDimitry Andric #include "llvm/BinaryFormat/Magic.h"
190b57cec5SDimitry Andric #include "llvm/Object/Archive.h"
200b57cec5SDimitry Andric #include "llvm/Object/COFF.h"
210b57cec5SDimitry Andric #include "llvm/Support/StringSaver.h"
220b57cec5SDimitry Andric #include <memory>
230b57cec5SDimitry Andric #include <set>
240b57cec5SDimitry Andric #include <vector>
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric namespace llvm {
2785868e8aSDimitry Andric struct DILineInfo;
280b57cec5SDimitry Andric namespace pdb {
290b57cec5SDimitry Andric class DbiModuleDescriptorBuilder;
305ffd83dbSDimitry Andric class NativeSession;
310b57cec5SDimitry Andric }
32480093f4SDimitry Andric namespace lto {
33480093f4SDimitry Andric class InputFile;
34480093f4SDimitry Andric }
350b57cec5SDimitry Andric }
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric namespace lld {
38480093f4SDimitry Andric class DWARFCache;
39480093f4SDimitry Andric 
400b57cec5SDimitry Andric namespace coff {
41349cc55cSDimitry Andric class COFFLinkerContext;
420b57cec5SDimitry Andric 
430b57cec5SDimitry Andric std::vector<MemoryBufferRef> getArchiveMembers(llvm::object::Archive *file);
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
460b57cec5SDimitry Andric using llvm::COFF::MachineTypes;
470b57cec5SDimitry Andric using llvm::object::Archive;
480b57cec5SDimitry Andric using llvm::object::COFFObjectFile;
490b57cec5SDimitry Andric using llvm::object::COFFSymbolRef;
500b57cec5SDimitry Andric using llvm::object::coff_import_header;
510b57cec5SDimitry Andric using llvm::object::coff_section;
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric class Chunk;
540b57cec5SDimitry Andric class Defined;
550b57cec5SDimitry Andric class DefinedImportData;
560b57cec5SDimitry Andric class DefinedImportThunk;
570b57cec5SDimitry Andric class DefinedRegular;
580b57cec5SDimitry Andric class SectionChunk;
590b57cec5SDimitry Andric class Symbol;
600b57cec5SDimitry Andric class Undefined;
610b57cec5SDimitry Andric class TpiSource;
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric // The root class of input files.
640b57cec5SDimitry Andric class InputFile {
650b57cec5SDimitry Andric public:
6685868e8aSDimitry Andric   enum Kind {
6785868e8aSDimitry Andric     ArchiveKind,
6885868e8aSDimitry Andric     ObjectKind,
6985868e8aSDimitry Andric     LazyObjectKind,
705ffd83dbSDimitry Andric     PDBKind,
7185868e8aSDimitry Andric     ImportKind,
72fe6060f1SDimitry Andric     BitcodeKind,
73fe6060f1SDimitry Andric     DLLKind
7485868e8aSDimitry Andric   };
kind()750b57cec5SDimitry Andric   Kind kind() const { return fileKind; }
~InputFile()760b57cec5SDimitry Andric   virtual ~InputFile() {}
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   // Returns the filename.
getName()790b57cec5SDimitry Andric   StringRef getName() const { return mb.getBufferIdentifier(); }
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   // Reads a file (the constructor doesn't do that).
820b57cec5SDimitry Andric   virtual void parse() = 0;
830b57cec5SDimitry Andric 
840b57cec5SDimitry Andric   // Returns the CPU type this file was compiled to.
getMachineType()850b57cec5SDimitry Andric   virtual MachineTypes getMachineType() { return IMAGE_FILE_MACHINE_UNKNOWN; }
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric   MemoryBufferRef mb;
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric   // An archive file name if this file is created from an archive.
900b57cec5SDimitry Andric   StringRef parentName;
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric   // Returns .drectve section contents if exist.
getDirectives()930b57cec5SDimitry Andric   StringRef getDirectives() { return directives; }
940b57cec5SDimitry Andric 
95349cc55cSDimitry Andric   COFFLinkerContext &ctx;
96349cc55cSDimitry Andric 
970b57cec5SDimitry Andric protected:
9804eeddc0SDimitry Andric   InputFile(COFFLinkerContext &c, Kind k, MemoryBufferRef m, bool lazy = false)
mb(m)9904eeddc0SDimitry Andric       : mb(m), ctx(c), fileKind(k), lazy(lazy) {}
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   StringRef directives;
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric private:
1040b57cec5SDimitry Andric   const Kind fileKind;
10504eeddc0SDimitry Andric 
10604eeddc0SDimitry Andric public:
10704eeddc0SDimitry Andric   // True if this is a lazy ObjFile or BitcodeFile.
10804eeddc0SDimitry Andric   bool lazy = false;
1090b57cec5SDimitry Andric };
1100b57cec5SDimitry Andric 
1110b57cec5SDimitry Andric // .lib or .a file.
1120b57cec5SDimitry Andric class ArchiveFile : public InputFile {
1130b57cec5SDimitry Andric public:
114349cc55cSDimitry Andric   explicit ArchiveFile(COFFLinkerContext &ctx, MemoryBufferRef m);
classof(const InputFile * f)1150b57cec5SDimitry Andric   static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; }
1160b57cec5SDimitry Andric   void parse() override;
1170b57cec5SDimitry Andric 
1180b57cec5SDimitry Andric   // Enqueues an archive member load for the given symbol. If we've already
1190b57cec5SDimitry Andric   // enqueued a load for the same archive member, this function does nothing,
1200b57cec5SDimitry Andric   // which ensures that we don't load the same member more than once.
1210b57cec5SDimitry Andric   void addMember(const Archive::Symbol &sym);
1220b57cec5SDimitry Andric 
1230b57cec5SDimitry Andric private:
1240b57cec5SDimitry Andric   std::unique_ptr<Archive> file;
1250b57cec5SDimitry Andric   llvm::DenseSet<uint64_t> seen;
1260b57cec5SDimitry Andric };
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric // .obj or .o file. This may be a member of an archive file.
1290b57cec5SDimitry Andric class ObjFile : public InputFile {
1300b57cec5SDimitry Andric public:
13104eeddc0SDimitry Andric   explicit ObjFile(COFFLinkerContext &ctx, MemoryBufferRef m, bool lazy = false)
InputFile(ctx,ObjectKind,m,lazy)13204eeddc0SDimitry Andric       : InputFile(ctx, ObjectKind, m, lazy) {}
classof(const InputFile * f)1330b57cec5SDimitry Andric   static bool classof(const InputFile *f) { return f->kind() == ObjectKind; }
1340b57cec5SDimitry Andric   void parse() override;
13504eeddc0SDimitry Andric   void parseLazy();
1360b57cec5SDimitry Andric   MachineTypes getMachineType() override;
getChunks()1370b57cec5SDimitry Andric   ArrayRef<Chunk *> getChunks() { return chunks; }
getDebugChunks()1380b57cec5SDimitry Andric   ArrayRef<SectionChunk *> getDebugChunks() { return debugChunks; }
getSXDataChunks()1395ffd83dbSDimitry Andric   ArrayRef<SectionChunk *> getSXDataChunks() { return sxDataChunks; }
getGuardFidChunks()1400b57cec5SDimitry Andric   ArrayRef<SectionChunk *> getGuardFidChunks() { return guardFidChunks; }
getGuardIATChunks()141e8d8bef9SDimitry Andric   ArrayRef<SectionChunk *> getGuardIATChunks() { return guardIATChunks; }
getGuardLJmpChunks()1420b57cec5SDimitry Andric   ArrayRef<SectionChunk *> getGuardLJmpChunks() { return guardLJmpChunks; }
getGuardEHContChunks()143fe6060f1SDimitry Andric   ArrayRef<SectionChunk *> getGuardEHContChunks() { return guardEHContChunks; }
getSymbols()1440b57cec5SDimitry Andric   ArrayRef<Symbol *> getSymbols() { return symbols; }
1450b57cec5SDimitry Andric 
getMutableSymbols()146e8d8bef9SDimitry Andric   MutableArrayRef<Symbol *> getMutableSymbols() { return symbols; }
147e8d8bef9SDimitry Andric 
1480b57cec5SDimitry Andric   ArrayRef<uint8_t> getDebugSection(StringRef secName);
1490b57cec5SDimitry Andric 
1500b57cec5SDimitry Andric   // Returns a Symbol object for the symbolIndex'th symbol in the
1510b57cec5SDimitry Andric   // underlying object file.
getSymbol(uint32_t symbolIndex)1520b57cec5SDimitry Andric   Symbol *getSymbol(uint32_t symbolIndex) {
1530b57cec5SDimitry Andric     return symbols[symbolIndex];
1540b57cec5SDimitry Andric   }
1550b57cec5SDimitry Andric 
1560b57cec5SDimitry Andric   // Returns the underlying COFF file.
getCOFFObj()1570b57cec5SDimitry Andric   COFFObjectFile *getCOFFObj() { return coffObj.get(); }
1580b57cec5SDimitry Andric 
1590b57cec5SDimitry Andric   // Add a symbol for a range extension thunk. Return the new symbol table
1600b57cec5SDimitry Andric   // index. This index can be used to modify a relocation.
addRangeThunkSymbol(Symbol * thunk)1610b57cec5SDimitry Andric   uint32_t addRangeThunkSymbol(Symbol *thunk) {
1620b57cec5SDimitry Andric     symbols.push_back(thunk);
1630b57cec5SDimitry Andric     return symbols.size() - 1;
1640b57cec5SDimitry Andric   }
1650b57cec5SDimitry Andric 
16685868e8aSDimitry Andric   void includeResourceChunks();
16785868e8aSDimitry Andric 
isResourceObjFile()16885868e8aSDimitry Andric   bool isResourceObjFile() const { return !resourceChunks.empty(); }
16985868e8aSDimitry Andric 
1700b57cec5SDimitry Andric   // Flags in the absolute @feat.00 symbol if it is present. These usually
1710b57cec5SDimitry Andric   // indicate if an object was compiled with certain security features enabled
1720b57cec5SDimitry Andric   // like stack guard, safeseh, /guard:cf, or other things.
1730b57cec5SDimitry Andric   uint32_t feat00Flags = 0;
1740b57cec5SDimitry Andric 
1750b57cec5SDimitry Andric   // True if this object file is compatible with SEH.  COFF-specific and
1760b57cec5SDimitry Andric   // x86-only. COFF spec 5.10.1. The .sxdata section.
hasSafeSEH()1770b57cec5SDimitry Andric   bool hasSafeSEH() { return feat00Flags & 0x1; }
1780b57cec5SDimitry Andric 
1790b57cec5SDimitry Andric   // True if this file was compiled with /guard:cf.
hasGuardCF()18006c3fb27SDimitry Andric   bool hasGuardCF() { return feat00Flags & 0x800; }
18106c3fb27SDimitry Andric 
18206c3fb27SDimitry Andric   // True if this file was compiled with /guard:ehcont.
hasGuardEHCont()18306c3fb27SDimitry Andric   bool hasGuardEHCont() { return feat00Flags & 0x4000; }
1840b57cec5SDimitry Andric 
1850b57cec5SDimitry Andric   // Pointer to the PDB module descriptor builder. Various debug info records
1860b57cec5SDimitry Andric   // will reference object files by "module index", which is here. Things like
1870b57cec5SDimitry Andric   // source files and section contributions are also recorded here. Will be null
1880b57cec5SDimitry Andric   // if we are not producing a PDB.
1890b57cec5SDimitry Andric   llvm::pdb::DbiModuleDescriptorBuilder *moduleDBI = nullptr;
1900b57cec5SDimitry Andric 
1910b57cec5SDimitry Andric   const coff_section *addrsigSec = nullptr;
1920b57cec5SDimitry Andric 
193e8d8bef9SDimitry Andric   const coff_section *callgraphSec = nullptr;
194e8d8bef9SDimitry Andric 
1950b57cec5SDimitry Andric   // When using Microsoft precompiled headers, this is the PCH's key.
1960b57cec5SDimitry Andric   // The same key is used by both the precompiled object, and objects using the
1970b57cec5SDimitry Andric   // precompiled object. Any difference indicates out-of-date objects.
198bdd1243dSDimitry Andric   std::optional<uint32_t> pchSignature;
1990b57cec5SDimitry Andric 
2000b57cec5SDimitry Andric   // Whether this file was compiled with /hotpatch.
2010b57cec5SDimitry Andric   bool hotPatchable = false;
2020b57cec5SDimitry Andric 
2030b57cec5SDimitry Andric   // Whether the object was already merged into the final PDB.
2040b57cec5SDimitry Andric   bool mergedIntoPDB = false;
2050b57cec5SDimitry Andric 
2060b57cec5SDimitry Andric   // If the OBJ has a .debug$T stream, this tells how it will be handled.
2070b57cec5SDimitry Andric   TpiSource *debugTypesObj = nullptr;
2080b57cec5SDimitry Andric 
209480093f4SDimitry Andric   // The .debug$P or .debug$T section data if present. Empty otherwise.
210480093f4SDimitry Andric   ArrayRef<uint8_t> debugTypes;
2110b57cec5SDimitry Andric 
212bdd1243dSDimitry Andric   std::optional<std::pair<StringRef, uint32_t>>
21385868e8aSDimitry Andric   getVariableLocation(StringRef var);
21485868e8aSDimitry Andric 
215bdd1243dSDimitry Andric   std::optional<llvm::DILineInfo> getDILineInfo(uint32_t offset,
21685868e8aSDimitry Andric                                                 uint32_t sectionIndex);
21785868e8aSDimitry Andric 
2180b57cec5SDimitry Andric private:
2190b57cec5SDimitry Andric   const coff_section* getSection(uint32_t i);
getSection(COFFSymbolRef sym)2200b57cec5SDimitry Andric   const coff_section *getSection(COFFSymbolRef sym) {
2210b57cec5SDimitry Andric     return getSection(sym.getSectionNumber());
2220b57cec5SDimitry Andric   }
2230b57cec5SDimitry Andric 
224349cc55cSDimitry Andric   void enqueuePdbFile(StringRef path, ObjFile *fromFile);
225349cc55cSDimitry Andric 
2260b57cec5SDimitry Andric   void initializeChunks();
2270b57cec5SDimitry Andric   void initializeSymbols();
2280b57cec5SDimitry Andric   void initializeFlags();
2290b57cec5SDimitry Andric   void initializeDependencies();
230*0fca6ea1SDimitry Andric   void initializeECThunks();
2310b57cec5SDimitry Andric 
2320b57cec5SDimitry Andric   SectionChunk *
2330b57cec5SDimitry Andric   readSection(uint32_t sectionNumber,
2340b57cec5SDimitry Andric               const llvm::object::coff_aux_section_definition *def,
2350b57cec5SDimitry Andric               StringRef leaderName);
2360b57cec5SDimitry Andric 
2370b57cec5SDimitry Andric   void readAssociativeDefinition(
2380b57cec5SDimitry Andric       COFFSymbolRef coffSym,
2390b57cec5SDimitry Andric       const llvm::object::coff_aux_section_definition *def);
2400b57cec5SDimitry Andric 
2410b57cec5SDimitry Andric   void readAssociativeDefinition(
2420b57cec5SDimitry Andric       COFFSymbolRef coffSym,
2430b57cec5SDimitry Andric       const llvm::object::coff_aux_section_definition *def,
2440b57cec5SDimitry Andric       uint32_t parentSection);
2450b57cec5SDimitry Andric 
2460b57cec5SDimitry Andric   void recordPrevailingSymbolForMingw(
2470b57cec5SDimitry Andric       COFFSymbolRef coffSym,
2480b57cec5SDimitry Andric       llvm::DenseMap<StringRef, uint32_t> &prevailingSectionMap);
2490b57cec5SDimitry Andric 
2500b57cec5SDimitry Andric   void maybeAssociateSEHForMingw(
2510b57cec5SDimitry Andric       COFFSymbolRef sym, const llvm::object::coff_aux_section_definition *def,
2520b57cec5SDimitry Andric       const llvm::DenseMap<StringRef, uint32_t> &prevailingSectionMap);
2530b57cec5SDimitry Andric 
2540b57cec5SDimitry Andric   // Given a new symbol Sym with comdat selection Selection, if the new
2550b57cec5SDimitry Andric   // symbol is not (yet) Prevailing and the existing comdat leader set to
2560b57cec5SDimitry Andric   // Leader, emits a diagnostic if the new symbol and its selection doesn't
2570b57cec5SDimitry Andric   // match the existing symbol and its selection. If either old or new
2580b57cec5SDimitry Andric   // symbol have selection IMAGE_COMDAT_SELECT_LARGEST, Sym might replace
2590b57cec5SDimitry Andric   // the existing leader. In that case, Prevailing is set to true.
260e8d8bef9SDimitry Andric   void
261e8d8bef9SDimitry Andric   handleComdatSelection(COFFSymbolRef sym, llvm::COFF::COMDATType &selection,
262e8d8bef9SDimitry Andric                         bool &prevailing, DefinedRegular *leader,
263e8d8bef9SDimitry Andric                         const llvm::object::coff_aux_section_definition *def);
2640b57cec5SDimitry Andric 
265bdd1243dSDimitry Andric   std::optional<Symbol *>
2660b57cec5SDimitry Andric   createDefined(COFFSymbolRef sym,
2670b57cec5SDimitry Andric                 std::vector<const llvm::object::coff_aux_section_definition *>
2680b57cec5SDimitry Andric                     &comdatDefs,
2690b57cec5SDimitry Andric                 bool &prevailingComdat);
2700b57cec5SDimitry Andric   Symbol *createRegular(COFFSymbolRef sym);
2710b57cec5SDimitry Andric   Symbol *createUndefined(COFFSymbolRef sym);
2720b57cec5SDimitry Andric 
2730b57cec5SDimitry Andric   std::unique_ptr<COFFObjectFile> coffObj;
2740b57cec5SDimitry Andric 
2750b57cec5SDimitry Andric   // List of all chunks defined by this file. This includes both section
2760b57cec5SDimitry Andric   // chunks and non-section chunks for common symbols.
2770b57cec5SDimitry Andric   std::vector<Chunk *> chunks;
2780b57cec5SDimitry Andric 
27985868e8aSDimitry Andric   std::vector<SectionChunk *> resourceChunks;
28085868e8aSDimitry Andric 
2810b57cec5SDimitry Andric   // CodeView debug info sections.
2820b57cec5SDimitry Andric   std::vector<SectionChunk *> debugChunks;
2830b57cec5SDimitry Andric 
2840b57cec5SDimitry Andric   // Chunks containing symbol table indices of exception handlers. Only used for
2850b57cec5SDimitry Andric   // 32-bit x86.
2865ffd83dbSDimitry Andric   std::vector<SectionChunk *> sxDataChunks;
2870b57cec5SDimitry Andric 
288e8d8bef9SDimitry Andric   // Chunks containing symbol table indices of address taken symbols, address
289fe6060f1SDimitry Andric   // taken IAT entries, longjmp and ehcont targets. These are not linked into
290fe6060f1SDimitry Andric   // the final binary when /guard:cf is set.
2910b57cec5SDimitry Andric   std::vector<SectionChunk *> guardFidChunks;
292e8d8bef9SDimitry Andric   std::vector<SectionChunk *> guardIATChunks;
2930b57cec5SDimitry Andric   std::vector<SectionChunk *> guardLJmpChunks;
294fe6060f1SDimitry Andric   std::vector<SectionChunk *> guardEHContChunks;
2950b57cec5SDimitry Andric 
296*0fca6ea1SDimitry Andric   std::vector<SectionChunk *> hybmpChunks;
297*0fca6ea1SDimitry Andric 
2980b57cec5SDimitry Andric   // This vector contains a list of all symbols defined or referenced by this
2990b57cec5SDimitry Andric   // file. They are indexed such that you can get a Symbol by symbol
3000b57cec5SDimitry Andric   // index. Nonexistent indices (which are occupied by auxiliary
3010b57cec5SDimitry Andric   // symbols in the real symbol table) are filled with null pointers.
3020b57cec5SDimitry Andric   std::vector<Symbol *> symbols;
30385868e8aSDimitry Andric 
3045ffd83dbSDimitry Andric   // This vector contains the same chunks as Chunks, but they are
3055ffd83dbSDimitry Andric   // indexed such that you can get a SectionChunk by section index.
3065ffd83dbSDimitry Andric   // Nonexistent section indices are filled with null pointers.
3075ffd83dbSDimitry Andric   // (Because section number is 1-based, the first slot is always a
3085ffd83dbSDimitry Andric   // null pointer.) This vector is only valid during initialization.
3095ffd83dbSDimitry Andric   std::vector<SectionChunk *> sparseChunks;
3105ffd83dbSDimitry Andric 
31185868e8aSDimitry Andric   DWARFCache *dwarf = nullptr;
3120b57cec5SDimitry Andric };
3130b57cec5SDimitry Andric 
3145ffd83dbSDimitry Andric // This is a PDB type server dependency, that is not a input file per se, but
3155ffd83dbSDimitry Andric // needs to be treated like one. Such files are discovered from the debug type
3165ffd83dbSDimitry Andric // stream.
3175ffd83dbSDimitry Andric class PDBInputFile : public InputFile {
3185ffd83dbSDimitry Andric public:
319349cc55cSDimitry Andric   explicit PDBInputFile(COFFLinkerContext &ctx, MemoryBufferRef m);
3205ffd83dbSDimitry Andric   ~PDBInputFile();
classof(const InputFile * f)3215ffd83dbSDimitry Andric   static bool classof(const InputFile *f) { return f->kind() == PDBKind; }
3225ffd83dbSDimitry Andric   void parse() override;
3235ffd83dbSDimitry Andric 
324349cc55cSDimitry Andric   static PDBInputFile *findFromRecordPath(const COFFLinkerContext &ctx,
325349cc55cSDimitry Andric                                           StringRef path, ObjFile *fromFile);
3265ffd83dbSDimitry Andric 
3275ffd83dbSDimitry Andric   // Record possible errors while opening the PDB file
328bdd1243dSDimitry Andric   std::optional<std::string> loadErrorStr;
3295ffd83dbSDimitry Andric 
3305ffd83dbSDimitry Andric   // This is the actual interface to the PDB (if it was opened successfully)
3315ffd83dbSDimitry Andric   std::unique_ptr<llvm::pdb::NativeSession> session;
3325ffd83dbSDimitry Andric 
3335ffd83dbSDimitry Andric   // If the PDB has a .debug$T stream, this tells how it will be handled.
3345ffd83dbSDimitry Andric   TpiSource *debugTypesObj = nullptr;
3355ffd83dbSDimitry Andric };
3365ffd83dbSDimitry Andric 
3370b57cec5SDimitry Andric // This type represents import library members that contain DLL names
3380b57cec5SDimitry Andric // and symbols exported from the DLLs. See Microsoft PE/COFF spec. 7
3390b57cec5SDimitry Andric // for details about the format.
3400b57cec5SDimitry Andric class ImportFile : public InputFile {
3410b57cec5SDimitry Andric public:
342bdd1243dSDimitry Andric   explicit ImportFile(COFFLinkerContext &ctx, MemoryBufferRef m);
3430b57cec5SDimitry Andric 
classof(const InputFile * f)3440b57cec5SDimitry Andric   static bool classof(const InputFile *f) { return f->kind() == ImportKind; }
3450b57cec5SDimitry Andric 
3460b57cec5SDimitry Andric   Symbol *impSym = nullptr;
3470b57cec5SDimitry Andric   Symbol *thunkSym = nullptr;
3480b57cec5SDimitry Andric   std::string dllName;
3490b57cec5SDimitry Andric 
3500b57cec5SDimitry Andric private:
3510b57cec5SDimitry Andric   void parse() override;
3520b57cec5SDimitry Andric 
3530b57cec5SDimitry Andric public:
3540b57cec5SDimitry Andric   StringRef externalName;
3550b57cec5SDimitry Andric   const coff_import_header *hdr;
3560b57cec5SDimitry Andric   Chunk *location = nullptr;
3570b57cec5SDimitry Andric 
358e8d8bef9SDimitry Andric   // We want to eliminate dllimported symbols if no one actually refers to them.
3590b57cec5SDimitry Andric   // These "Live" bits are used to keep track of which import library members
3600b57cec5SDimitry Andric   // are actually in use.
3610b57cec5SDimitry Andric   //
3620b57cec5SDimitry Andric   // If the Live bit is turned off by MarkLive, Writer will ignore dllimported
3630b57cec5SDimitry Andric   // symbols provided by this import library member. We also track whether the
3640b57cec5SDimitry Andric   // imported symbol is used separately from whether the thunk is used in order
3650b57cec5SDimitry Andric   // to avoid creating unnecessary thunks.
366bdd1243dSDimitry Andric   bool live;
367bdd1243dSDimitry Andric   bool thunkLive;
3680b57cec5SDimitry Andric };
3690b57cec5SDimitry Andric 
3700b57cec5SDimitry Andric // Used for LTO.
3710b57cec5SDimitry Andric class BitcodeFile : public InputFile {
3720b57cec5SDimitry Andric public:
37304eeddc0SDimitry Andric   explicit BitcodeFile(COFFLinkerContext &ctx, MemoryBufferRef mb,
374349cc55cSDimitry Andric                        StringRef archiveName, uint64_t offsetInArchive,
37504eeddc0SDimitry Andric                        bool lazy);
376480093f4SDimitry Andric   ~BitcodeFile();
classof(const InputFile * f)3770b57cec5SDimitry Andric   static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }
getSymbols()3780b57cec5SDimitry Andric   ArrayRef<Symbol *> getSymbols() { return symbols; }
3790b57cec5SDimitry Andric   MachineTypes getMachineType() override;
38004eeddc0SDimitry Andric   void parseLazy();
3810b57cec5SDimitry Andric   std::unique_ptr<llvm::lto::InputFile> obj;
3820b57cec5SDimitry Andric 
3830b57cec5SDimitry Andric private:
3840b57cec5SDimitry Andric   void parse() override;
3850b57cec5SDimitry Andric 
3860b57cec5SDimitry Andric   std::vector<Symbol *> symbols;
3870b57cec5SDimitry Andric };
3880b57cec5SDimitry Andric 
389fe6060f1SDimitry Andric // .dll file. MinGW only.
390fe6060f1SDimitry Andric class DLLFile : public InputFile {
391fe6060f1SDimitry Andric public:
DLLFile(COFFLinkerContext & ctx,MemoryBufferRef m)392349cc55cSDimitry Andric   explicit DLLFile(COFFLinkerContext &ctx, MemoryBufferRef m)
393349cc55cSDimitry Andric       : InputFile(ctx, DLLKind, m) {}
classof(const InputFile * f)394fe6060f1SDimitry Andric   static bool classof(const InputFile *f) { return f->kind() == DLLKind; }
395fe6060f1SDimitry Andric   void parse() override;
396fe6060f1SDimitry Andric   MachineTypes getMachineType() override;
397fe6060f1SDimitry Andric 
398fe6060f1SDimitry Andric   struct Symbol {
399fe6060f1SDimitry Andric     StringRef dllName;
400fe6060f1SDimitry Andric     StringRef symbolName;
401fe6060f1SDimitry Andric     llvm::COFF::ImportNameType nameType;
402fe6060f1SDimitry Andric     llvm::COFF::ImportType importType;
403fe6060f1SDimitry Andric   };
404fe6060f1SDimitry Andric 
405fe6060f1SDimitry Andric   void makeImport(Symbol *s);
406fe6060f1SDimitry Andric 
407fe6060f1SDimitry Andric private:
408fe6060f1SDimitry Andric   std::unique_ptr<COFFObjectFile> coffObj;
409fe6060f1SDimitry Andric   llvm::StringSet<> seen;
410fe6060f1SDimitry Andric };
411fe6060f1SDimitry Andric 
isBitcode(MemoryBufferRef mb)41285868e8aSDimitry Andric inline bool isBitcode(MemoryBufferRef mb) {
41385868e8aSDimitry Andric   return identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode;
41485868e8aSDimitry Andric }
41585868e8aSDimitry Andric 
416bdd1243dSDimitry Andric std::string replaceThinLTOSuffix(StringRef path, StringRef suffix,
417bdd1243dSDimitry Andric                                  StringRef repl);
4180b57cec5SDimitry Andric } // namespace coff
4190b57cec5SDimitry Andric 
4200b57cec5SDimitry Andric std::string toString(const coff::InputFile *file);
4210b57cec5SDimitry Andric } // namespace lld
4220b57cec5SDimitry Andric 
4230b57cec5SDimitry Andric #endif
424