diff options
Diffstat (limited to 'lld/wasm/Symbols.h')
-rw-r--r-- | lld/wasm/Symbols.h | 334 |
1 files changed, 167 insertions, 167 deletions
diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h index cb4691395eb..499a265be73 100644 --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -20,10 +20,10 @@ namespace wasm { // Shared string constants // The default module name to use for symbol imports. -extern const char *DefaultModule; +extern const char *defaultModule; // The name under which to import or export the wasm table. -extern const char *FunctionTableName; +extern const char *functionTableName; using llvm::wasm::WasmSymbolType; @@ -54,16 +54,16 @@ public: LazyKind, }; - Kind kind() const { return SymbolKind; } + Kind kind() const { return symbolKind; } bool isDefined() const { return !isLazy() && !isUndefined(); } bool isUndefined() const { - return SymbolKind == UndefinedFunctionKind || - SymbolKind == UndefinedDataKind || SymbolKind == UndefinedGlobalKind; + return symbolKind == UndefinedFunctionKind || + symbolKind == UndefinedDataKind || symbolKind == UndefinedGlobalKind; } - bool isLazy() const { return SymbolKind == LazyKind; } + bool isLazy() const { return symbolKind == LazyKind; } bool isLocal() const; bool isWeak() const; @@ -80,12 +80,12 @@ public: } // Returns the symbol name. - StringRef getName() const { return Name; } + StringRef getName() const { return name; } // Returns the file from which this symbol was created. - InputFile *getFile() const { return File; } + InputFile *getFile() const { return file; } - uint32_t getFlags() const { return Flags; } + uint32_t getFlags() const { return flags; } InputChunk *getChunk() const; @@ -97,120 +97,120 @@ public: // final image. void markLive(); - void setHidden(bool IsHidden); + void setHidden(bool isHidden); // Get/set the index in the output symbol table. This is only used for // relocatable output. uint32_t getOutputSymbolIndex() const; - void setOutputSymbolIndex(uint32_t Index); + void setOutputSymbolIndex(uint32_t index); WasmSymbolType getWasmType() const; bool isExported() const; const WasmSignature* getSignature() const; - bool isInGOT() const { return GOTIndex != INVALID_INDEX; } + bool isInGOT() const { return gotIndex != INVALID_INDEX; } uint32_t getGOTIndex() const { - assert(GOTIndex != INVALID_INDEX); - return GOTIndex; + assert(gotIndex != INVALID_INDEX); + return gotIndex; } - void setGOTIndex(uint32_t Index); - bool hasGOTIndex() const { return GOTIndex != INVALID_INDEX; } + void setGOTIndex(uint32_t index); + bool hasGOTIndex() const { return gotIndex != INVALID_INDEX; } protected: - Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F) - : Name(Name), File(F), Flags(Flags), SymbolKind(K), - Referenced(!Config->GcSections), IsUsedInRegularObj(false), - ForceExport(false), CanInline(false), Traced(false) {} - - StringRef Name; - InputFile *File; - uint32_t Flags; - uint32_t OutputSymbolIndex = INVALID_INDEX; - uint32_t GOTIndex = INVALID_INDEX; - Kind SymbolKind; + Symbol(StringRef name, Kind k, uint32_t flags, InputFile *f) + : name(name), file(f), flags(flags), symbolKind(k), + referenced(!config->gcSections), isUsedInRegularObj(false), + forceExport(false), canInline(false), traced(false) {} + + StringRef name; + InputFile *file; + uint32_t flags; + uint32_t outputSymbolIndex = INVALID_INDEX; + uint32_t gotIndex = INVALID_INDEX; + Kind symbolKind; public: - bool Referenced : 1; + bool referenced : 1; // True if the symbol was used for linking and thus need to be added to the // output file's symbol table. This is true for all symbols except for // unreferenced DSO symbols, lazy (archive) symbols, and bitcode symbols that // are unreferenced except by other bitcode objects. - bool IsUsedInRegularObj : 1; + bool isUsedInRegularObj : 1; // True if ths symbol is explicity marked for export (i.e. via the -e/--export // command line flag) - bool ForceExport : 1; + bool forceExport : 1; // False if LTO shouldn't inline whatever this symbol points to. If a symbol // is overwritten after LTO, LTO shouldn't inline the symbol because it // doesn't know the final contents of the symbol. - bool CanInline : 1; + bool canInline : 1; // True if this symbol is specified by --trace-symbol option. - bool Traced : 1; + bool traced : 1; }; class FunctionSymbol : public Symbol { public: - static bool classof(const Symbol *S) { - return S->kind() == DefinedFunctionKind || - S->kind() == UndefinedFunctionKind; + static bool classof(const Symbol *s) { + return s->kind() == DefinedFunctionKind || + s->kind() == UndefinedFunctionKind; } // Get/set the table index - void setTableIndex(uint32_t Index); + void setTableIndex(uint32_t index); uint32_t getTableIndex() const; bool hasTableIndex() const; // Get/set the function index uint32_t getFunctionIndex() const; - void setFunctionIndex(uint32_t Index); + void setFunctionIndex(uint32_t index); bool hasFunctionIndex() const; - const WasmSignature *Signature; + const WasmSignature *signature; protected: - FunctionSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, - const WasmSignature *Sig) - : Symbol(Name, K, Flags, F), Signature(Sig) {} + FunctionSymbol(StringRef name, Kind k, uint32_t flags, InputFile *f, + const WasmSignature *sig) + : Symbol(name, k, flags, f), signature(sig) {} - uint32_t TableIndex = INVALID_INDEX; - uint32_t FunctionIndex = INVALID_INDEX; + uint32_t tableIndex = INVALID_INDEX; + uint32_t functionIndex = INVALID_INDEX; }; class DefinedFunction : public FunctionSymbol { public: - DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F, - InputFunction *Function); + DefinedFunction(StringRef name, uint32_t flags, InputFile *f, + InputFunction *function); - static bool classof(const Symbol *S) { - return S->kind() == DefinedFunctionKind; + static bool classof(const Symbol *s) { + return s->kind() == DefinedFunctionKind; } - InputFunction *Function; + InputFunction *function; }; class UndefinedFunction : public FunctionSymbol { public: - UndefinedFunction(StringRef Name, StringRef ImportName, - StringRef ImportModule, uint32_t Flags, - InputFile *File = nullptr, - const WasmSignature *Type = nullptr, - bool IsCalledDirectly = true) - : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type), - ImportName(ImportName), ImportModule(ImportModule), IsCalledDirectly(IsCalledDirectly) {} - - static bool classof(const Symbol *S) { - return S->kind() == UndefinedFunctionKind; + UndefinedFunction(StringRef name, StringRef importName, + StringRef importModule, uint32_t flags, + InputFile *file = nullptr, + const WasmSignature *type = nullptr, + bool isCalledDirectly = true) + : FunctionSymbol(name, UndefinedFunctionKind, flags, file, type), + importName(importName), importModule(importModule), isCalledDirectly(isCalledDirectly) {} + + static bool classof(const Symbol *s) { + return s->kind() == UndefinedFunctionKind; } - StringRef ImportName; - StringRef ImportModule; - bool IsCalledDirectly; + StringRef importName; + StringRef importModule; + bool isCalledDirectly; }; // Section symbols for output sections are different from those for input @@ -218,128 +218,128 @@ public: // rather than an InputSection. class OutputSectionSymbol : public Symbol { public: - OutputSectionSymbol(const OutputSection *S) + OutputSectionSymbol(const OutputSection *s) : Symbol("", OutputSectionKind, llvm::wasm::WASM_SYMBOL_BINDING_LOCAL, nullptr), - Section(S) {} + section(s) {} - static bool classof(const Symbol *S) { - return S->kind() == OutputSectionKind; + static bool classof(const Symbol *s) { + return s->kind() == OutputSectionKind; } - const OutputSection *Section; + const OutputSection *section; }; class SectionSymbol : public Symbol { public: - SectionSymbol(uint32_t Flags, const InputSection *S, InputFile *F = nullptr) - : Symbol("", SectionKind, Flags, F), Section(S) {} + SectionSymbol(uint32_t flags, const InputSection *s, InputFile *f = nullptr) + : Symbol("", SectionKind, flags, f), section(s) {} - static bool classof(const Symbol *S) { return S->kind() == SectionKind; } + static bool classof(const Symbol *s) { return s->kind() == SectionKind; } const OutputSectionSymbol *getOutputSectionSymbol() const; - const InputSection *Section; + const InputSection *section; }; class DataSymbol : public Symbol { public: - static bool classof(const Symbol *S) { - return S->kind() == DefinedDataKind || S->kind() == UndefinedDataKind; + static bool classof(const Symbol *s) { + return s->kind() == DefinedDataKind || s->kind() == UndefinedDataKind; } protected: - DataSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F) - : Symbol(Name, K, Flags, F) {} + DataSymbol(StringRef name, Kind k, uint32_t flags, InputFile *f) + : Symbol(name, k, flags, f) {} }; class DefinedData : public DataSymbol { public: // Constructor for regular data symbols originating from input files. - DefinedData(StringRef Name, uint32_t Flags, InputFile *F, - InputSegment *Segment, uint32_t Offset, uint32_t Size) - : DataSymbol(Name, DefinedDataKind, Flags, F), Segment(Segment), - Offset(Offset), Size(Size) {} + DefinedData(StringRef name, uint32_t flags, InputFile *f, + InputSegment *segment, uint32_t offset, uint32_t size) + : DataSymbol(name, DefinedDataKind, flags, f), segment(segment), + offset(offset), size(size) {} // Constructor for linker synthetic data symbols. - DefinedData(StringRef Name, uint32_t Flags) - : DataSymbol(Name, DefinedDataKind, Flags, nullptr) {} + DefinedData(StringRef name, uint32_t flags) + : DataSymbol(name, DefinedDataKind, flags, nullptr) {} - static bool classof(const Symbol *S) { return S->kind() == DefinedDataKind; } + static bool classof(const Symbol *s) { return s->kind() == DefinedDataKind; } // Returns the output virtual address of a defined data symbol. uint32_t getVirtualAddress() const; - void setVirtualAddress(uint32_t VA); + void setVirtualAddress(uint32_t va); // Returns the offset of a defined data symbol within its OutputSegment. uint32_t getOutputSegmentOffset() const; uint32_t getOutputSegmentIndex() const; - uint32_t getSize() const { return Size; } + uint32_t getSize() const { return size; } - InputSegment *Segment = nullptr; + InputSegment *segment = nullptr; protected: - uint32_t Offset = 0; - uint32_t Size = 0; + uint32_t offset = 0; + uint32_t size = 0; }; class UndefinedData : public DataSymbol { public: - UndefinedData(StringRef Name, uint32_t Flags, InputFile *File = nullptr) - : DataSymbol(Name, UndefinedDataKind, Flags, File) {} - static bool classof(const Symbol *S) { - return S->kind() == UndefinedDataKind; + UndefinedData(StringRef name, uint32_t flags, InputFile *file = nullptr) + : DataSymbol(name, UndefinedDataKind, flags, file) {} + static bool classof(const Symbol *s) { + return s->kind() == UndefinedDataKind; } }; class GlobalSymbol : public Symbol { public: - static bool classof(const Symbol *S) { - return S->kind() == DefinedGlobalKind || S->kind() == UndefinedGlobalKind; + static bool classof(const Symbol *s) { + return s->kind() == DefinedGlobalKind || s->kind() == UndefinedGlobalKind; } - const WasmGlobalType *getGlobalType() const { return GlobalType; } + const WasmGlobalType *getGlobalType() const { return globalType; } // Get/set the global index uint32_t getGlobalIndex() const; - void setGlobalIndex(uint32_t Index); + void setGlobalIndex(uint32_t index); bool hasGlobalIndex() const; protected: - GlobalSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, - const WasmGlobalType *GlobalType) - : Symbol(Name, K, Flags, F), GlobalType(GlobalType) {} + GlobalSymbol(StringRef name, Kind k, uint32_t flags, InputFile *f, + const WasmGlobalType *globalType) + : Symbol(name, k, flags, f), globalType(globalType) {} - const WasmGlobalType *GlobalType; - uint32_t GlobalIndex = INVALID_INDEX; + const WasmGlobalType *globalType; + uint32_t globalIndex = INVALID_INDEX; }; class DefinedGlobal : public GlobalSymbol { public: - DefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File, - InputGlobal *Global); + DefinedGlobal(StringRef name, uint32_t flags, InputFile *file, + InputGlobal *global); - static bool classof(const Symbol *S) { - return S->kind() == DefinedGlobalKind; + static bool classof(const Symbol *s) { + return s->kind() == DefinedGlobalKind; } - InputGlobal *Global; + InputGlobal *global; }; class UndefinedGlobal : public GlobalSymbol { public: - UndefinedGlobal(StringRef Name, StringRef ImportName, StringRef ImportModule, - uint32_t Flags, InputFile *File = nullptr, - const WasmGlobalType *Type = nullptr) - : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File, Type), - ImportName(ImportName), ImportModule(ImportModule) {} - - static bool classof(const Symbol *S) { - return S->kind() == UndefinedGlobalKind; + UndefinedGlobal(StringRef name, StringRef importName, StringRef importModule, + uint32_t flags, InputFile *file = nullptr, + const WasmGlobalType *type = nullptr) + : GlobalSymbol(name, UndefinedGlobalKind, flags, file, type), + importName(importName), importModule(importModule) {} + + static bool classof(const Symbol *s) { + return s->kind() == UndefinedGlobalKind; } - StringRef ImportName; - StringRef ImportModule; + StringRef importName; + StringRef importModule; }; // Wasm events are features that suspend the current execution and transfer the @@ -356,34 +356,34 @@ public: // are used, and has name '__cpp_exception' for linking. class EventSymbol : public Symbol { public: - static bool classof(const Symbol *S) { return S->kind() == DefinedEventKind; } + static bool classof(const Symbol *s) { return s->kind() == DefinedEventKind; } - const WasmEventType *getEventType() const { return EventType; } + const WasmEventType *getEventType() const { return eventType; } // Get/set the event index uint32_t getEventIndex() const; - void setEventIndex(uint32_t Index); + void setEventIndex(uint32_t index); bool hasEventIndex() const; - const WasmSignature *Signature; + const WasmSignature *signature; protected: - EventSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F, - const WasmEventType *EventType, const WasmSignature *Sig) - : Symbol(Name, K, Flags, F), Signature(Sig), EventType(EventType) {} + EventSymbol(StringRef name, Kind k, uint32_t flags, InputFile *f, + const WasmEventType *eventType, const WasmSignature *sig) + : Symbol(name, k, flags, f), signature(sig), eventType(eventType) {} - const WasmEventType *EventType; - uint32_t EventIndex = INVALID_INDEX; + const WasmEventType *eventType; + uint32_t eventIndex = INVALID_INDEX; }; class DefinedEvent : public EventSymbol { public: - DefinedEvent(StringRef Name, uint32_t Flags, InputFile *File, - InputEvent *Event); + DefinedEvent(StringRef name, uint32_t flags, InputFile *file, + InputEvent *event); - static bool classof(const Symbol *S) { return S->kind() == DefinedEventKind; } + static bool classof(const Symbol *s) { return s->kind() == DefinedEventKind; } - InputEvent *Event; + InputEvent *event; }; // LazySymbol represents a symbol that is not yet in the link, but we know where @@ -397,11 +397,11 @@ public: // symbols into consideration. class LazySymbol : public Symbol { public: - LazySymbol(StringRef Name, uint32_t Flags, InputFile *File, - const llvm::object::Archive::Symbol &Sym) - : Symbol(Name, LazyKind, Flags, File), ArchiveSymbol(Sym) {} + LazySymbol(StringRef name, uint32_t flags, InputFile *file, + const llvm::object::Archive::Symbol &sym) + : Symbol(name, LazyKind, flags, file), archiveSymbol(sym) {} - static bool classof(const Symbol *S) { return S->kind() == LazyKind; } + static bool classof(const Symbol *s) { return s->kind() == LazyKind; } void fetch(); // Lazy symbols can have a signature because they can replace an @@ -409,71 +409,71 @@ public: // signture. // TODO(sbc): This repetition of the signature field is inelegant. Revisit // the use of class hierarchy to represent symbol taxonomy. - const WasmSignature *Signature = nullptr; + const WasmSignature *signature = nullptr; private: - llvm::object::Archive::Symbol ArchiveSymbol; + llvm::object::Archive::Symbol archiveSymbol; }; // linker-generated symbols struct WasmSym { // __global_base // Symbol marking the start of the global section. - static DefinedData *GlobalBase; + static DefinedData *globalBase; // __stack_pointer // Global that holds the address of the top of the explicit value stack in // linear memory. - static GlobalSymbol *StackPointer; + static GlobalSymbol *stackPointer; // __data_end // Symbol marking the end of the data and bss. - static DefinedData *DataEnd; + static DefinedData *dataEnd; // __heap_base // Symbol marking the end of the data, bss and explicit stack. Any linear // memory following this address is not used by the linked code and can // therefore be used as a backing store for brk()/malloc() implementations. - static DefinedData *HeapBase; + static DefinedData *heapBase; // __wasm_call_ctors // Function that directly calls all ctors in priority order. - static DefinedFunction *CallCtors; + static DefinedFunction *callCtors; // __wasm_init_memory // Function that initializes passive data segments post-instantiation. - static DefinedFunction *InitMemory; + static DefinedFunction *initMemory; // __wasm_apply_relocs // Function that applies relocations to data segment post-instantiation. - static DefinedFunction *ApplyRelocs; + static DefinedFunction *applyRelocs; // __dso_handle // Symbol used in calls to __cxa_atexit to determine current DLL - static DefinedData *DsoHandle; + static DefinedData *dsoHandle; // __table_base // Used in PIC code for offset of indirect function table - static UndefinedGlobal *TableBase; + static UndefinedGlobal *tableBase; // __memory_base // Used in PIC code for offset of global data - static UndefinedGlobal *MemoryBase; + static UndefinedGlobal *memoryBase; }; // 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. union SymbolUnion { - alignas(DefinedFunction) char A[sizeof(DefinedFunction)]; - alignas(DefinedData) char B[sizeof(DefinedData)]; - alignas(DefinedGlobal) char C[sizeof(DefinedGlobal)]; - alignas(DefinedEvent) char D[sizeof(DefinedEvent)]; - alignas(LazySymbol) char E[sizeof(LazySymbol)]; - alignas(UndefinedFunction) char F[sizeof(UndefinedFunction)]; - alignas(UndefinedData) char G[sizeof(UndefinedData)]; - alignas(UndefinedGlobal) char H[sizeof(UndefinedGlobal)]; - alignas(SectionSymbol) char I[sizeof(SectionSymbol)]; + alignas(DefinedFunction) char a[sizeof(DefinedFunction)]; + alignas(DefinedData) char b[sizeof(DefinedData)]; + alignas(DefinedGlobal) char c[sizeof(DefinedGlobal)]; + alignas(DefinedEvent) char d[sizeof(DefinedEvent)]; + alignas(LazySymbol) char e[sizeof(LazySymbol)]; + alignas(UndefinedFunction) char f[sizeof(UndefinedFunction)]; + alignas(UndefinedData) char g[sizeof(UndefinedData)]; + alignas(UndefinedGlobal) char h[sizeof(UndefinedGlobal)]; + alignas(SectionSymbol) char i[sizeof(SectionSymbol)]; }; // It is important to keep the size of SymbolUnion small for performance and @@ -481,11 +481,11 @@ union SymbolUnion { // UndefinedFunction on a 64-bit system. static_assert(sizeof(SymbolUnion) <= 96, "SymbolUnion too large"); -void printTraceSymbol(Symbol *Sym); -void printTraceSymbolUndefined(StringRef Name, const InputFile* File); +void printTraceSymbol(Symbol *sym); +void printTraceSymbolUndefined(StringRef name, const InputFile* file); template <typename T, typename... ArgT> -T *replaceSymbol(Symbol *S, ArgT &&... Arg) { +T *replaceSymbol(Symbol *s, ArgT &&... arg) { static_assert(std::is_trivially_destructible<T>(), "Symbol types must be trivially destructible"); static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small"); @@ -494,28 +494,28 @@ T *replaceSymbol(Symbol *S, ArgT &&... Arg) { assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr && "Not a Symbol"); - Symbol SymCopy = *S; + Symbol symCopy = *s; - T *S2 = new (S) T(std::forward<ArgT>(Arg)...); - S2->IsUsedInRegularObj = SymCopy.IsUsedInRegularObj; - S2->ForceExport = SymCopy.ForceExport; - S2->CanInline = SymCopy.CanInline; - S2->Traced = SymCopy.Traced; + T *s2 = new (s) T(std::forward<ArgT>(arg)...); + s2->isUsedInRegularObj = symCopy.isUsedInRegularObj; + s2->forceExport = symCopy.forceExport; + s2->canInline = symCopy.canInline; + s2->traced = symCopy.traced; // Print out a log message if --trace-symbol was specified. // This is for debugging. - if (S2->Traced) - printTraceSymbol(S2); + if (s2->traced) + printTraceSymbol(s2); - return S2; + return s2; } } // 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); +std::string toString(const wasm::Symbol &sym); +std::string toString(wasm::Symbol::Kind kind); +std::string maybeDemangleSymbol(StringRef name); } // namespace lld |