diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -479,6 +479,10 @@ // 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. + +// It is important to keep the size of SymbolUnion small for performance and +// memory usage reasons. 64 bytes is a soft limit based on the size of Defined +// on a 64-bit system. This is enforced by a static_assert in Symbols.cpp. union SymbolUnion { alignas(Defined) char a[sizeof(Defined)]; alignas(CommonSymbol) char b[sizeof(CommonSymbol)]; @@ -487,27 +491,6 @@ alignas(LazyObject) char e[sizeof(LazyObject)]; }; -// It is important to keep the size of SymbolUnion small for performance and -// memory usage reasons. 64 bytes is a soft limit based on the size of Defined -// on a 64-bit system. -static_assert(sizeof(SymbolUnion) <= 64, "SymbolUnion too large"); - -template struct AssertSymbol { - static_assert(std::is_trivially_destructible(), - "Symbol types must be trivially destructible"); - static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small"); - static_assert(alignof(T) <= alignof(SymbolUnion), - "SymbolUnion not aligned enough"); -}; - -static inline void assertSymbols() { - AssertSymbol(); - AssertSymbol(); - AssertSymbol(); - AssertSymbol(); - AssertSymbol(); -} - void printTraceSymbol(const Symbol &sym, StringRef name); size_t Symbol::getSymbolSize() const { diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -16,6 +16,7 @@ #include "Writer.h" #include "lld/Common/ErrorHandler.h" #include "lld/Common/Strings.h" +#include "llvm/Support/Compiler.h" #include using namespace llvm; @@ -24,6 +25,24 @@ using namespace lld; using namespace lld::elf; +static_assert(sizeof(SymbolUnion) <= 64, "SymbolUnion too large"); + +template struct AssertSymbol { + static_assert(std::is_trivially_destructible(), + "Symbol types must be trivially destructible"); + static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small"); + static_assert(alignof(T) <= alignof(SymbolUnion), + "SymbolUnion not aligned enough"); +}; + +LLVM_ATTRIBUTE_UNUSED static inline void assertSymbols() { + AssertSymbol(); + AssertSymbol(); + AssertSymbol(); + AssertSymbol(); + AssertSymbol(); +} + std::string lld::toString(const elf::Symbol &sym) { StringRef name = sym.getName(); std::string ret = demangle(name, config->demangle);