1 //===- SymbolTable.h --------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_COFF_SYMBOL_TABLE_H
11 #define LLD_COFF_SYMBOL_TABLE_H
13 #include "InputFiles.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/DenseMapInfo.h"
16 #include "llvm/Support/Allocator.h"
17 #include "llvm/Support/raw_ostream.h"
20 // <future> depends on <eh.h> for __uncaught_exception.
27 struct LTOCodeGenerator;
39 // SymbolTable is a bucket of all known symbols, including defined,
40 // undefined, or lazy symbols (the last one is symbols in archive
41 // files whose archive members are not yet loaded).
43 // We put all symbols of all files to a SymbolTable, and the
44 // SymbolTable selects the "best" symbols if there are name
45 // conflicts. For example, obviously, a defined symbol is better than
46 // an undefined symbol. Or, if there's a conflict between a lazy and a
47 // undefined, it'll read an archive member to read a real definition
48 // to replace the lazy symbol. The logic is implemented in resolve().
51 void addFile(std::unique_ptr<InputFile> File);
52 std::vector<std::unique_ptr<InputFile>> &getFiles() { return Files; }
57 // Print an error message on undefined symbols. If Resolve is true, try to
58 // resolve any undefined symbols and update the symbol table accordingly.
59 void reportRemainingUndefines(bool Resolve);
61 // Returns a list of chunks of selected symbols.
62 std::vector<Chunk *> getChunks();
64 // Returns a symbol for a given name. Returns a nullptr if not found.
65 Symbol *find(StringRef Name);
66 Symbol *findUnderscore(StringRef Name);
68 // Occasionally we have to resolve an undefined symbol to its
69 // mangled symbol. This function tries to find a mangled name
70 // for U from the symbol table, and if found, set the symbol as
71 // a weak alias for U.
72 void mangleMaybe(Undefined *U);
73 StringRef findMangle(StringRef Name);
75 // Print a layout map to OS.
76 void printMap(llvm::raw_ostream &OS);
78 // Build a set of COFF objects representing the combined contents of
79 // BitcodeFiles and add them to the symbol table. Called after all files are
80 // added and before the writer writes results to a file.
81 void addCombinedLTOObjects();
83 // The writer needs to handle DLL import libraries specially in
84 // order to create the import descriptor table.
85 std::vector<ImportFile *> ImportFiles;
87 // The writer needs to infer the machine type from the object files.
88 std::vector<ObjectFile *> ObjectFiles;
90 // Creates an Undefined symbol for a given name.
91 Undefined *addUndefined(StringRef Name);
92 DefinedRelative *addRelative(StringRef Name, uint64_t VA);
93 DefinedAbsolute *addAbsolute(StringRef Name, uint64_t VA);
95 // A list of chunks which to be added to .rdata.
96 std::vector<Chunk *> LocalImportChunks;
102 void addSymbol(SymbolBody *New);
103 void addLazy(Lazy *New, std::vector<Symbol *> *Accum);
104 Symbol *insert(SymbolBody *New);
105 StringRef findByPrefix(StringRef Prefix);
107 void addMemberFile(Lazy *Body);
108 void addCombinedLTOObject(ObjectFile *Obj);
109 std::vector<ObjectFile *> createLTOObjects(llvm::LTOCodeGenerator *CG);
111 llvm::DenseMap<StringRef, Symbol *> Symtab;
113 std::vector<std::unique_ptr<InputFile>> Files;
114 std::vector<std::future<ArchiveFile *>> ArchiveQueue;
115 std::vector<std::future<InputFile *>> ObjectQueue;
117 std::vector<BitcodeFile *> BitcodeFiles;
118 std::vector<SmallString<0>> Objs;
119 llvm::BumpPtrAllocator Alloc;