Path: blob/main/contrib/llvm-project/lld/MachO/SymbolTable.h
34879 views
//===- SymbolTable.h --------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLD_MACHO_SYMBOL_TABLE_H9#define LLD_MACHO_SYMBOL_TABLE_H1011#include "Symbols.h"1213#include "lld/Common/LLVM.h"14#include "llvm/ADT/CachedHashString.h"15#include "llvm/ADT/DenseMap.h"16#include "llvm/Object/Archive.h"1718namespace lld::macho {1920class ArchiveFile;21class DylibFile;22class InputFile;23class ObjFile;24class InputSection;25class MachHeaderSection;26class Symbol;27class Defined;28class Undefined;2930/*31* Note that the SymbolTable handles name collisions by calling32* replaceSymbol(), which does an in-place update of the Symbol via `placement33* new`. Therefore, there is no need to update any relocations that hold34* pointers the "old" Symbol -- they will automatically point to the new one.35*/36class SymbolTable {37public:38Defined *addDefined(StringRef name, InputFile *, InputSection *,39uint64_t value, uint64_t size, bool isWeakDef,40bool isPrivateExtern, bool isReferencedDynamically,41bool noDeadStrip, bool isWeakDefCanBeHidden);4243Defined *aliasDefined(Defined *src, StringRef target, InputFile *newFile,44bool makePrivateExtern = false);4546Symbol *addUndefined(StringRef name, InputFile *, bool isWeakRef);4748Symbol *addCommon(StringRef name, InputFile *, uint64_t size, uint32_t align,49bool isPrivateExtern);5051Symbol *addDylib(StringRef name, DylibFile *file, bool isWeakDef, bool isTlv);52Symbol *addDynamicLookup(StringRef name);5354Symbol *addLazyArchive(StringRef name, ArchiveFile *file,55const llvm::object::Archive::Symbol &sym);56Symbol *addLazyObject(StringRef name, InputFile &file);5758Defined *addSynthetic(StringRef name, InputSection *, uint64_t value,59bool isPrivateExtern, bool includeInSymtab,60bool referencedDynamically);6162ArrayRef<Symbol *> getSymbols() const { return symVector; }63Symbol *find(llvm::CachedHashStringRef name);64Symbol *find(StringRef name) { return find(llvm::CachedHashStringRef(name)); }6566private:67std::pair<Symbol *, bool> insert(StringRef name, const InputFile *);68llvm::DenseMap<llvm::CachedHashStringRef, int> symMap;69std::vector<Symbol *> symVector;70};7172void reportPendingUndefinedSymbols();73void reportPendingDuplicateSymbols();7475// Call reportPendingUndefinedSymbols() to emit diagnostics.76void treatUndefinedSymbol(const Undefined &, StringRef source);77void treatUndefinedSymbol(const Undefined &, const InputSection *,78uint64_t offset);7980extern std::unique_ptr<SymbolTable> symtab;8182} // namespace lld::macho8384#endif858687