[PATCH] D124041: [ELF] Move SymbolUnion size assertion to source file
Shoaib Meenai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 18:03:17 PDT 2022
smeenai updated this revision to Diff 424348.
smeenai added a comment.
Address review comment and move other asserts
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124041/new/
https://reviews.llvm.org/D124041
Files:
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
Index: lld/ELF/Symbols.h
===================================================================
--- lld/ELF/Symbols.h
+++ 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 <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 {
Index: lld/ELF/Symbols.cpp
===================================================================
--- lld/ELF/Symbols.cpp
+++ 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 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124041.424348.patch
Type: text/x-patch
Size: 2854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220422/c02bdff4/attachment.bin>
More information about the llvm-commits
mailing list