//===- Symbols.h ------------------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLD_COFF_SYMBOLS_H #define LLD_COFF_SYMBOLS_H #include "Chunks.h" #include "Config.h" #include "lld/Common/LLVM.h" #include "lld/Common/Memory.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" #include <atomic> #include <memory> #include <vector> namespace lld { namespace coff { Archive; COFFSymbolRef; coff_import_header; coff_symbol_generic; class ArchiveFile; class COFFLinkerContext; class InputFile; class ObjFile; class SymbolTable; // The base class for real symbol classes. class Symbol { … }; // The base class for any defined symbols, including absolute symbols, // etc. class Defined : public Symbol { … }; // Symbols defined via a COFF object file or bitcode file. For COFF files, this // stores a coff_symbol_generic*, and names of internal symbols are lazily // loaded through that. For bitcode files, Sym is nullptr and the name is stored // as a decomposed StringRef. class DefinedCOFF : public Defined { … }; // Regular defined symbols read from object file symbol tables. class DefinedRegular : public DefinedCOFF { … }; class DefinedCommon : public DefinedCOFF { … }; // Absolute symbols. class DefinedAbsolute : public Defined { … }; // This symbol is used for linker-synthesized symbols like __ImageBase and // __safe_se_handler_table. class DefinedSynthetic : public Defined { … }; // This class represents a symbol defined in an archive file. It is // created from an archive file header, and it knows how to load an // object file from an archive to replace itself with a defined // symbol. If the resolver finds both Undefined and LazyArchive for // the same name, it will ask the LazyArchive to load a file. class LazyArchive : public Symbol { … }; class LazyObject : public Symbol { … }; // MinGW only. class LazyDLLSymbol : public Symbol { … }; // Undefined symbols. class Undefined : public Symbol { … }; // Windows-specific classes. // This class represents a symbol imported from a DLL. This has two // names for internal use and external use. The former is used for // name resolution, and the latter is used for the import descriptor // table in an output. The former has "__imp_" prefix. class DefinedImportData : public Defined { … }; // This class represents a symbol for a jump table entry which jumps // to a function in a DLL. Linker are supposed to create such symbols // without "__imp_" prefix for all function symbols exported from // DLLs, so that you can call DLL functions as regular functions with // a regular name. A function pointer is given as a DefinedImportData. class DefinedImportThunk : public Defined { … }; // If you have a symbol "foo" in your object file, a symbol name // "__imp_foo" becomes automatically available as a pointer to "foo". // This class is for such automatically-created symbols. // Yes, this is an odd feature. We didn't intend to implement that. // This is here just for compatibility with MSVC. class DefinedLocalImport : public Defined { … }; inline uint64_t Defined::getRVA() { … } inline Chunk *Defined::getChunk() { … } // A buffer class that is large enough to hold any Symbol-derived // object. We allocate memory using this class and instantiate a symbol // using the placement new. SymbolUnion; template <typename T, typename... ArgT> void replaceSymbol(Symbol *s, ArgT &&... arg) { … } } // namespace coff std::string toString(const coff::COFFLinkerContext &ctx, coff::Symbol &b); std::string toCOFFString(const coff::COFFLinkerContext &ctx, const llvm::object::Archive::Symbol &b); } // namespace lld #endif