[lld] 01510ac - [MachO] Move type size asserts to source files. NFC
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 16 17:14:35 PST 2021
Author: Shoaib Meenai
Date: 2021-11-16T17:14:16-08:00
New Revision: 01510ac08474a6c4beae033794b71b6b5ab1e89d
URL: https://github.com/llvm/llvm-project/commit/01510ac08474a6c4beae033794b71b6b5ab1e89d
DIFF: https://github.com/llvm/llvm-project/commit/01510ac08474a6c4beae033794b71b6b5ab1e89d.diff
LOG: [MachO] Move type size asserts to source files. NFC
As discussed in https://reviews.llvm.org/D113809#3128636. It's a bit
unfortunate to move the asserts away from the structs whose sizes
they're checking, but it's a far better developer experience when one of
the asserts is violated, because you get a single error instead of every
single source file including the header erroring out.
Added:
Modified:
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/Relocations.cpp
lld/MachO/Relocations.h
lld/MachO/Symbols.cpp
lld/MachO/Symbols.h
Removed:
################################################################################
diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index ebb4d204d9ac..0dbe6a619e98 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -26,6 +26,11 @@ using namespace llvm::support;
using namespace lld;
using namespace lld::macho;
+// Verify ConcatInputSection's size on 64-bit builds.
+static_assert(sizeof(void *) != 8 || sizeof(ConcatInputSection) == 120,
+ "Try to minimize ConcatInputSection's size, we create many "
+ "instances of it");
+
std::vector<ConcatInputSection *> macho::inputSections;
uint64_t InputSection::getFileSize() const {
diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index d0c0b45c1b66..e8aefc16f6ad 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -149,11 +149,6 @@ class ConcatInputSection final : public InputSection {
uint64_t outSecOff = 0;
};
-// Verify ConcatInputSection's size on 64-bit builds.
-static_assert(sizeof(void *) != 8 || sizeof(ConcatInputSection) == 120,
- "Try to minimize ConcatInputSection's size, we create many "
- "instances of it");
-
// Helper functions to make it easy to sprinkle asserts.
inline bool shouldOmitFromOutput(InputSection *isec) {
diff --git a/lld/MachO/Relocations.cpp b/lld/MachO/Relocations.cpp
index 03cb6973b6ab..2f316154a1ca 100644
--- a/lld/MachO/Relocations.cpp
+++ b/lld/MachO/Relocations.cpp
@@ -17,6 +17,9 @@ using namespace llvm;
using namespace lld;
using namespace lld::macho;
+static_assert(sizeof(void *) != 8 || sizeof(Reloc) == 24,
+ "Try to minimize Reloc's size; we create many instances");
+
bool macho::validateSymbolRelocation(const Symbol *sym,
const InputSection *isec, const Reloc &r) {
const RelocAttrs &relocAttrs = target->getRelocAttrs(r.type);
diff --git a/lld/MachO/Relocations.h b/lld/MachO/Relocations.h
index 57ffcf858f52..9457465ac203 100644
--- a/lld/MachO/Relocations.h
+++ b/lld/MachO/Relocations.h
@@ -63,9 +63,6 @@ struct Reloc {
llvm::PointerUnion<Symbol *, InputSection *> referent = nullptr;
};
-static_assert(sizeof(void *) != 8 || sizeof(Reloc) == 24,
- "Try to minimize Reloc's size; we create many instances");
-
bool validateSymbolRelocation(const Symbol *, const InputSection *,
const Reloc &);
diff --git a/lld/MachO/Symbols.cpp b/lld/MachO/Symbols.cpp
index 97fe33866e90..35b6d040038f 100644
--- a/lld/MachO/Symbols.cpp
+++ b/lld/MachO/Symbols.cpp
@@ -14,6 +14,19 @@ using namespace llvm;
using namespace lld;
using namespace lld::macho;
+static_assert(sizeof(void *) != 8 || sizeof(Symbol) == 48,
+ "Try to minimize Symbol's size; we create many instances");
+
+// The Microsoft ABI doesn't support using parent class tail padding for child
+// members, hence the _MSC_VER check.
+#if !defined(_MSC_VER)
+static_assert(sizeof(void *) != 8 || sizeof(Defined) == 80,
+ "Try to minimize Defined's size; we create many instances");
+#endif
+
+static_assert(sizeof(SymbolUnion) == sizeof(Defined),
+ "Defined should be the largest Symbol kind");
+
// Returns a symbol for an error message.
static std::string demangle(StringRef symName) {
if (config->demangle)
diff --git a/lld/MachO/Symbols.h b/lld/MachO/Symbols.h
index 0212a14e83d4..2b44711861bb 100644
--- a/lld/MachO/Symbols.h
+++ b/lld/MachO/Symbols.h
@@ -109,9 +109,6 @@ class Symbol {
bool used : 1;
};
-static_assert(sizeof(void *) != 8 || sizeof(Symbol) == 48,
- "Try to minimize Symbol's size; we create many instances");
-
class Defined : public Symbol {
public:
Defined(StringRefZ name, InputFile *file, InputSection *isec, uint64_t value,
@@ -174,13 +171,6 @@ class Defined : public Symbol {
ConcatInputSection *compactUnwind = nullptr;
};
-// The Microsoft ABI doesn't support using parent class tail padding for child
-// members, hence the _MSC_VER check.
-#if !defined(_MSC_VER)
-static_assert(sizeof(void *) != 8 || sizeof(Defined) == 80,
- "Try to minimize Defined's size; we create many instances");
-#endif
-
// This enum does double-duty: as a symbol property, it indicates whether & how
// a dylib symbol is referenced. As a DylibFile property, it indicates the kind
// of referenced symbols contained within the file. If there are both weak
@@ -307,9 +297,6 @@ union SymbolUnion {
alignas(LazySymbol) char e[sizeof(LazySymbol)];
};
-static_assert(sizeof(SymbolUnion) == sizeof(Defined),
- "Defined should be the largest Symbol kind");
-
template <typename T, typename... ArgT>
T *replaceSymbol(Symbol *s, ArgT &&...arg) {
static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
More information about the llvm-commits
mailing list