1 //===- SymbolTable.h --------------------------------------------*- C++ -*-===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLD_MACHO_SYMBOL_TABLE_H
10 #define LLD_MACHO_SYMBOL_TABLE_H
11 
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/CachedHashString.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/Object/Archive.h"
16 
17 namespace lld {
18 namespace macho {
19 
20 class ArchiveFile;
21 class DylibFile;
22 class InputFile;
23 class InputSection;
24 class MachHeaderSection;
25 class Symbol;
26 
27 /*
28  * Note that the SymbolTable handles name collisions by calling
29  * replaceSymbol(), which does an in-place update of the Symbol via `placement
30  * new`. Therefore, there is no need to update any relocations that hold
31  * pointers the "old" Symbol -- they will automatically point to the new one.
32  */
33 class SymbolTable {
34 public:
35   Symbol *addDefined(StringRef name, InputSection *isec, uint32_t value,
36                      bool isWeakDef);
37 
38   Symbol *addUndefined(StringRef name);
39 
40   Symbol *addCommon(StringRef name, InputFile *, uint64_t size, uint32_t align);
41 
42   Symbol *addDylib(StringRef name, DylibFile *file, bool isWeakDef, bool isTlv);
43 
44   Symbol *addLazy(StringRef name, ArchiveFile *file,
45                   const llvm::object::Archive::Symbol &sym);
46 
47   Symbol *addDSOHandle(const MachHeaderSection *);
48 
getSymbols()49   ArrayRef<Symbol *> getSymbols() const { return symVector; }
50   Symbol *find(StringRef name);
51 
52 private:
53   std::pair<Symbol *, bool> insert(StringRef name);
54   llvm::DenseMap<llvm::CachedHashStringRef, int> symMap;
55   std::vector<Symbol *> symVector;
56 };
57 
58 extern SymbolTable *symtab;
59 
60 } // namespace macho
61 } // namespace lld
62 
63 #endif
64