Path: blob/main/contrib/llvm-project/lld/ELF/SymbolTable.h
34870 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_ELF_SYMBOL_TABLE_H9#define LLD_ELF_SYMBOL_TABLE_H1011#include "Symbols.h"12#include "llvm/ADT/CachedHashString.h"13#include "llvm/ADT/DenseMap.h"14#include "llvm/Support/Compiler.h"1516namespace lld::elf {1718class InputFile;19class SharedFile;2021struct ArmCmseEntryFunction {22Symbol *acleSeSym;23Symbol *sym;24};2526// SymbolTable is a bucket of all known symbols, including defined,27// undefined, or lazy symbols (the last one is symbols in archive28// files whose archive members are not yet loaded).29//30// We put all symbols of all files to a SymbolTable, and the31// SymbolTable selects the "best" symbols if there are name32// conflicts. For example, obviously, a defined symbol is better than33// an undefined symbol. Or, if there's a conflict between a lazy and a34// undefined, it'll read an archive member to read a real definition35// to replace the lazy symbol. The logic is implemented in the36// add*() functions, which are called by input files as they are parsed. There37// is one add* function per symbol type.38class SymbolTable {39public:40ArrayRef<Symbol *> getSymbols() const { return symVector; }4142void wrap(Symbol *sym, Symbol *real, Symbol *wrap);4344Symbol *insert(StringRef name);4546template <typename T> Symbol *addSymbol(const T &newSym) {47Symbol *sym = insert(newSym.getName());48sym->resolve(newSym);49return sym;50}51Symbol *addAndCheckDuplicate(const Defined &newSym);5253void scanVersionScript();5455Symbol *find(StringRef name);5657void handleDynamicList();5859Symbol *addUnusedUndefined(StringRef name,60uint8_t binding = llvm::ELF::STB_GLOBAL);6162// Set of .so files to not link the same shared object file more than once.63llvm::DenseMap<llvm::CachedHashStringRef, SharedFile *> soNames;6465// Comdat groups define "link once" sections. If two comdat groups have the66// same name, only one of them is linked, and the other is ignored. This map67// is used to uniquify them.68llvm::DenseMap<llvm::CachedHashStringRef, const InputFile *> comdatGroups;6970// The Map of __acle_se_<sym>, <sym> pairs found in the input objects.71// Key is the <sym> name.72llvm::SmallMapVector<StringRef, ArmCmseEntryFunction, 1> cmseSymMap;7374// Map of symbols defined in the Arm CMSE import library. The linker must75// preserve the addresses in the output objects.76llvm::StringMap<Defined *> cmseImportLib;7778// True if <sym> from the input Arm CMSE import library is written to the79// output Arm CMSE import library.80llvm::StringMap<bool> inCMSEOutImpLib;8182private:83SmallVector<Symbol *, 0> findByVersion(SymbolVersion ver);84SmallVector<Symbol *, 0> findAllByVersion(SymbolVersion ver,85bool includeNonDefault);8687llvm::StringMap<SmallVector<Symbol *, 0>> &getDemangledSyms();88bool assignExactVersion(SymbolVersion ver, uint16_t versionId,89StringRef versionName, bool includeNonDefault);90void assignWildcardVersion(SymbolVersion ver, uint16_t versionId,91bool includeNonDefault);9293// Global symbols and a map from symbol name to the index. The order is not94// defined. We can use an arbitrary order, but it has to be deterministic even95// when cross linking.96llvm::DenseMap<llvm::CachedHashStringRef, int> symMap;97SmallVector<Symbol *, 0> symVector;9899// A map from demangled symbol names to their symbol objects.100// This mapping is 1:N because two symbols with different versions101// can have the same name. We use this map to handle "extern C++ {}"102// directive in version scripts.103std::optional<llvm::StringMap<SmallVector<Symbol *, 0>>> demangledSyms;104};105106LLVM_LIBRARY_VISIBILITY extern SymbolTable symtab;107108} // namespace lld::elf109110#endif111112113