diff options
author | Fangrui Song <maskray@google.com> | 2019-07-05 01:27:39 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-07-05 01:27:39 +0000 |
commit | 9694566289ff70939ed6763c7447fd86cc1284cd (patch) | |
tree | 77adf9a4af338768533a1299a6d9ed0c8b25b1bd | |
parent | 757c1df68577bc46244207d01dd0c814fa03402a (diff) |
[WebAssembly] Reorder Symbol fields to make it smaller
On 64-bit systems, this decreases sizeof(SymbolUnion) from 112 to 96.
Add a static_assert to avoid accidental increases in future.
Reviewed By: sbc100
Differential Revision: https://reviews.llvm.org/D64208
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@365169 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | wasm/Symbols.h | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/wasm/Symbols.h b/wasm/Symbols.h index 1745614bb..5abd33bdd 100644 --- a/wasm/Symbols.h +++ b/wasm/Symbols.h @@ -41,7 +41,7 @@ class OutputSection; // The base class for real symbol classes. class Symbol { public: - enum Kind { + enum Kind : uint8_t { DefinedFunctionKind, DefinedDataKind, DefinedGlobalKind, @@ -107,24 +107,6 @@ public: WasmSymbolType getWasmType() const; bool isExported() const; - // 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. - unsigned IsUsedInRegularObj : 1; - - // True if ths symbol is explicity marked for export (i.e. via the -e/--export - // command line flag) - unsigned 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. - unsigned CanInline : 1; - - // True if this symbol is specified by --trace-symbol option. - unsigned Traced : 1; - const WasmSignature* getSignature() const; bool isInGOT() const { return GOTIndex != INVALID_INDEX; } @@ -139,17 +121,36 @@ public: protected: Symbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F) - : IsUsedInRegularObj(false), ForceExport(false), CanInline(false), - Traced(false), Name(Name), SymbolKind(K), Flags(Flags), File(F), - Referenced(!Config->GcSections) {} + : Name(Name), File(F), Flags(Flags), SymbolKind(K), + Referenced(!Config->GcSections), IsUsedInRegularObj(false), + ForceExport(false), CanInline(false), Traced(false) {} StringRef Name; - Kind SymbolKind; - uint32_t Flags; InputFile *File; + uint32_t Flags; uint32_t OutputSymbolIndex = INVALID_INDEX; uint32_t GOTIndex = INVALID_INDEX; - bool Referenced; + Kind SymbolKind; + unsigned Referenced : 1; + +public: + // 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. + unsigned IsUsedInRegularObj : 1; + + // True if ths symbol is explicity marked for export (i.e. via the -e/--export + // command line flag) + unsigned 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. + unsigned CanInline : 1; + + // True if this symbol is specified by --trace-symbol option. + unsigned Traced : 1; }; class FunctionSymbol : public Symbol { @@ -474,6 +475,11 @@ union SymbolUnion { alignas(SectionSymbol) char I[sizeof(SectionSymbol)]; }; +// 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(sizeof(SymbolUnion) <= 96, "SymbolUnion too large"); + void printTraceSymbol(Symbol *Sym); void printTraceSymbolUndefined(StringRef Name, const InputFile* File); |