mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 10:58:11 +08:00
[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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -149,11 +149,6 @@ public:
|
||||
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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 &);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -109,9 +109,6 @@ public:
|
||||
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 @@ public:
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user