[lld] b862bcb - [ELF] Move SymbolUnion assertions to source file

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 16:45:18 PDT 2022


Author: Shoaib Meenai
Date: 2022-04-22T16:41:14-07:00
New Revision: b862bcbf4455e3a9f6cb1c9be16ef529415b5357

URL: https://github.com/llvm/llvm-project/commit/b862bcbf4455e3a9f6cb1c9be16ef529415b5357
DIFF: https://github.com/llvm/llvm-project/commit/b862bcbf4455e3a9f6cb1c9be16ef529415b5357.diff

LOG: [ELF] Move SymbolUnion assertions to source file

Otherwise they fires for every single file which includes the header,
which is very noisy when building.

Reviewed By: MaskRay, peter.smith

Differential Revision: https://reviews.llvm.org/D124041

Added: 
    

Modified: 
    lld/ELF/Symbols.cpp
    lld/ELF/Symbols.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index b087dd1823fd3..5706f54c2e0c7 100644
--- 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 <cstring>
 
 using namespace llvm;
@@ -24,6 +25,24 @@ using namespace llvm::ELF;
 using namespace lld;
 using namespace lld::elf;
 
+static_assert(sizeof(SymbolUnion) <= 64, "SymbolUnion too large");
+
+template <typename T> struct AssertSymbol {
+  static_assert(std::is_trivially_destructible<T>(),
+                "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<Defined>();
+  AssertSymbol<CommonSymbol>();
+  AssertSymbol<Undefined>();
+  AssertSymbol<SharedSymbol>();
+  AssertSymbol<LazyObject>();
+}
+
 std::string lld::toString(const elf::Symbol &sym) {
   StringRef name = sym.getName();
   std::string ret = demangle(name, config->demangle);

diff  --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index f968aeac0a2c3..a978b9c5012f1 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -479,6 +479,10 @@ struct ElfSym {
 // 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 @@ union SymbolUnion {
   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 <typename T> struct AssertSymbol {
-  static_assert(std::is_trivially_destructible<T>(),
-                "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<Defined>();
-  AssertSymbol<CommonSymbol>();
-  AssertSymbol<Undefined>();
-  AssertSymbol<SharedSymbol>();
-  AssertSymbol<LazyObject>();
-}
-
 void printTraceSymbol(const Symbol &sym, StringRef name);
 
 size_t Symbol::getSymbolSize() const {


        


More information about the llvm-commits mailing list