//===- 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_WASM_SYMBOLS_H #define LLD_WASM_SYMBOLS_H #include "Config.h" #include "lld/Common/LLVM.h" #include "llvm/Object/Archive.h" #include "llvm/Object/Wasm.h" #include <optional> namespace lld { namespace wasm { // Shared string constants // The default module name to use for symbol imports. extern const char *defaultModule; // The name under which to import or export the wasm table. extern const char *functionTableName; // The name under which to import or export the wasm memory. extern const char *memoryName; WasmSymbolType; class InputFile; class InputChunk; class InputSegment; class InputFunction; class InputGlobal; class InputTag; class InputSection; class InputTable; class OutputSection; #define INVALID_INDEX … // The base class for real symbol classes. class Symbol { … }; class FunctionSymbol : public Symbol { … }; class DefinedFunction : public FunctionSymbol { … }; class UndefinedFunction : public FunctionSymbol { … }; // Section symbols for output sections are different from those for input // section. These are generated by the linker and point the OutputSection // rather than an InputSection. class OutputSectionSymbol : public Symbol { … }; class SectionSymbol : public Symbol { … }; class DataSymbol : public Symbol { … }; class DefinedData : public DataSymbol { … }; class SharedData : public DataSymbol { … }; class UndefinedData : public DataSymbol { … }; class GlobalSymbol : public Symbol { … }; class DefinedGlobal : public GlobalSymbol { … }; class UndefinedGlobal : public GlobalSymbol { … }; class TableSymbol : public Symbol { … }; class DefinedTable : public TableSymbol { … }; class UndefinedTable : public TableSymbol { … }; // A tag is a general format to distinguish typed entities. Each tag has an // attribute and a type. Currently the attribute can only specify that the tag // is for an exception tag. // // In exception handling, tags are used to distinguish different kinds of // exceptions. For example, they can be used to distinguish different language's // exceptions, e.g., all C++ exceptions have the same tag and Java exceptions // would have a distinct tag. Wasm can filter the exceptions it catches based on // their tag. // // A single TagSymbol object represents a single tag. The C++ exception symbol // is a weak symbol generated in every object file in which exceptions are used, // and is named '__cpp_exception' for linking. class TagSymbol : public Symbol { … }; class DefinedTag : public TagSymbol { … }; class UndefinedTag : public TagSymbol { … }; class SharedFunctionSymbol : public FunctionSymbol { … }; // LazySymbol symbols represent symbols in object files between --start-lib and // --end-lib options. LLD also handles traditional archives as if all the files // in the archive are surrounded by --start-lib and --end-lib. // // A special complication is the handling of weak undefined symbols. They should // not load a file, but we have to remember we have seen both the weak undefined // and the lazy. We represent that with a lazy symbol with a weak binding. This // means that code looking for undefined symbols normally also has to take lazy // symbols into consideration. class LazySymbol : public Symbol { … }; // linker-generated symbols struct WasmSym { … }; // 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; // It is important to keep the size of SymbolUnion small for performance and // memory usage reasons. 96 bytes is a soft limit based on the size of // UndefinedFunction on a 64-bit system. static_assert …; void printTraceSymbol(Symbol *sym); void printTraceSymbolUndefined(StringRef name, const InputFile* file); template <typename T, typename... ArgT> T *replaceSymbol(Symbol *s, ArgT &&... arg) { … } } // namespace wasm // Returns a symbol name for an error message. std::string toString(const wasm::Symbol &sym); std::string toString(wasm::Symbol::Kind kind); std::string maybeDemangleSymbol(StringRef name); } // namespace lld #endif