diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index efec41a737b62..16f1ab36a88b1 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1647,6 +1647,8 @@ uint64_t DynamicReloc::getOffset() const { int64_t DynamicReloc::computeAddend(Ctx &ctx) const { switch (kind) { + case Computed: + llvm_unreachable("addend already computed"); case AddendOnly: assert(sym == nullptr); return addend; @@ -1748,7 +1750,7 @@ void DynamicReloc::computeRaw(Ctx &ctx, SymbolTableBaseSection *symt) { r_offset = getOffset(); r_sym = getSymIndex(symt); addend = computeAddend(ctx); - kind = AddendOnly; // Catch errors + kind = Computed; // Catch errors } void RelocationBaseSection::computeRels() { diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 5f01513630597..8e069e3dd9565 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -419,6 +419,9 @@ class StringTableSection final : public SyntheticSection { class DynamicReloc { public: enum Kind { + /// The resulting dynamic relocation has already had its addend computed. + /// Calling computeAddend() is an error. Only for internal use. + Computed, /// The resulting dynamic relocation does not reference a symbol (#sym must /// be nullptr) and uses #addend as the result of computeAddend(ctx). AddendOnly, @@ -461,6 +464,7 @@ class DynamicReloc { uint64_t getOffset() const; uint32_t getSymIndex(SymbolTableBaseSection *symTab) const; bool needsDynSymIndex() const { + assert(kind != Computed && "cannot check kind after computeRaw"); return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA; }