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_WASM_SYMBOL_TABLE_H
11 #define LLD_WASM_SYMBOL_TABLE_H
13 #include "InputFiles.h"
16 #include "llvm/ADT/CachedHashString.h"
17 #include "llvm/ADT/DenseSet.h"
18 #include "llvm/Support/raw_ostream.h"
20 using llvm::wasm::WasmGlobalType;
21 using llvm::wasm::WasmSignature;
28 // SymbolTable is a bucket of all known symbols, including defined,
29 // undefined, or lazy symbols (the last one is symbols in archive
30 // files whose archive members are not yet loaded).
32 // We put all symbols of all files to a SymbolTable, and the
33 // SymbolTable selects the "best" symbols if there are name
34 // conflicts. For example, obviously, a defined symbol is better than
35 // an undefined symbol. Or, if there's a conflict between a lazy and a
36 // undefined, it'll read an archive member to read a real definition
37 // to replace the lazy symbol. The logic is implemented in the
38 // add*() functions, which are called by input files as they are parsed.
39 // There is one add* function per symbol type.
42 void addFile(InputFile *File);
43 void addCombinedLTOObject();
45 std::vector<ObjFile *> ObjectFiles;
46 std::vector<BitcodeFile *> BitcodeFiles;
47 std::vector<InputFunction *> SyntheticFunctions;
48 std::vector<InputGlobal *> SyntheticGlobals;
50 void reportRemainingUndefines();
52 ArrayRef<Symbol *> getSymbols() const { return SymVector; }
53 Symbol *find(StringRef Name);
55 Symbol *addDefinedFunction(StringRef Name, uint32_t Flags, InputFile *File,
56 InputFunction *Function);
57 Symbol *addDefinedData(StringRef Name, uint32_t Flags, InputFile *File,
58 InputSegment *Segment, uint32_t Address,
60 Symbol *addDefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
63 Symbol *addUndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File,
64 const WasmSignature *Signature);
65 Symbol *addUndefinedData(StringRef Name, uint32_t Flags, InputFile *File);
66 Symbol *addUndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
67 const WasmGlobalType *Type);
69 void addLazy(ArchiveFile *F, const Archive::Symbol *Sym);
71 bool addComdat(StringRef Name);
73 DefinedData *addSyntheticDataSymbol(StringRef Name, uint32_t Flags);
74 DefinedGlobal *addSyntheticGlobal(StringRef Name, uint32_t Flags,
76 DefinedFunction *addSyntheticFunction(StringRef Name, uint32_t Flags,
77 InputFunction *Function);
80 std::pair<Symbol *, bool> insert(StringRef Name);
82 llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> SymMap;
83 std::vector<Symbol *> SymVector;
85 llvm::DenseSet<llvm::CachedHashStringRef> Comdats;
88 std::unique_ptr<BitcodeCompiler> LTO;
91 extern SymbolTable *Symtab;