Skip to content

Commit b862bcb

Browse files
committed
[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
1 parent f1dbf8e commit b862bcb

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

lld/ELF/Symbols.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Writer.h"
1717
#include "lld/Common/ErrorHandler.h"
1818
#include "lld/Common/Strings.h"
19+
#include "llvm/Support/Compiler.h"
1920
#include <cstring>
2021

2122
using namespace llvm;
@@ -24,6 +25,24 @@ using namespace llvm::ELF;
2425
using namespace lld;
2526
using namespace lld::elf;
2627

28+
static_assert(sizeof(SymbolUnion) <= 64, "SymbolUnion too large");
29+
30+
template <typename T> struct AssertSymbol {
31+
static_assert(std::is_trivially_destructible<T>(),
32+
"Symbol types must be trivially destructible");
33+
static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
34+
static_assert(alignof(T) <= alignof(SymbolUnion),
35+
"SymbolUnion not aligned enough");
36+
};
37+
38+
LLVM_ATTRIBUTE_UNUSED static inline void assertSymbols() {
39+
AssertSymbol<Defined>();
40+
AssertSymbol<CommonSymbol>();
41+
AssertSymbol<Undefined>();
42+
AssertSymbol<SharedSymbol>();
43+
AssertSymbol<LazyObject>();
44+
}
45+
2746
std::string lld::toString(const elf::Symbol &sym) {
2847
StringRef name = sym.getName();
2948
std::string ret = demangle(name, config->demangle);

lld/ELF/Symbols.h

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ struct ElfSym {
479479
// A buffer class that is large enough to hold any Symbol-derived
480480
// object. We allocate memory using this class and instantiate a symbol
481481
// using the placement new.
482+
483+
// It is important to keep the size of SymbolUnion small for performance and
484+
// memory usage reasons. 64 bytes is a soft limit based on the size of Defined
485+
// on a 64-bit system. This is enforced by a static_assert in Symbols.cpp.
482486
union SymbolUnion {
483487
alignas(Defined) char a[sizeof(Defined)];
484488
alignas(CommonSymbol) char b[sizeof(CommonSymbol)];
@@ -487,27 +491,6 @@ union SymbolUnion {
487491
alignas(LazyObject) char e[sizeof(LazyObject)];
488492
};
489493

490-
// It is important to keep the size of SymbolUnion small for performance and
491-
// memory usage reasons. 64 bytes is a soft limit based on the size of Defined
492-
// on a 64-bit system.
493-
static_assert(sizeof(SymbolUnion) <= 64, "SymbolUnion too large");
494-
495-
template <typename T> struct AssertSymbol {
496-
static_assert(std::is_trivially_destructible<T>(),
497-
"Symbol types must be trivially destructible");
498-
static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
499-
static_assert(alignof(T) <= alignof(SymbolUnion),
500-
"SymbolUnion not aligned enough");
501-
};
502-
503-
static inline void assertSymbols() {
504-
AssertSymbol<Defined>();
505-
AssertSymbol<CommonSymbol>();
506-
AssertSymbol<Undefined>();
507-
AssertSymbol<SharedSymbol>();
508-
AssertSymbol<LazyObject>();
509-
}
510-
511494
void printTraceSymbol(const Symbol &sym, StringRef name);
512495

513496
size_t Symbol::getSymbolSize() const {

0 commit comments

Comments
 (0)