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, bool isPrivateExtern);
37 
38   Symbol *addUndefined(StringRef name, bool isWeakRef);
39 
40   Symbol *addCommon(StringRef name, InputFile *, uint64_t size, uint32_t align,
41                     bool isPrivateExtern);
42 
43   Symbol *addDylib(StringRef name, DylibFile *file, bool isWeakDef, bool isTlv);
44 
45   Symbol *addLazy(StringRef name, ArchiveFile *file,
46                   const llvm::object::Archive::Symbol &sym);
47 
48   Symbol *addDSOHandle(const MachHeaderSection *);
49 
50   ArrayRef<Symbol *> getSymbols() const { return symVector; }
51   Symbol *find(StringRef name);
52 
53 private:
54   std::pair<Symbol *, bool> insert(StringRef name);
55   llvm::DenseMap<llvm::CachedHashStringRef, int> symMap;
56   std::vector<Symbol *> symVector;
57 };
58 
59 extern void treatUndefinedSymbol(StringRef symbolName, StringRef fileName);
60 
61 extern SymbolTable *symtab;
62 
63 } // namespace macho
64 } // namespace lld
65 
66 #endif
67