[lld] 610a0e8 - [ELF] Assert on invalid GOT or PLT relocations
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 10:46:35 PDT 2022
Author: Shoaib Meenai
Date: 2022-04-20T10:46:04-07:00
New Revision: 610a0e8b5368853b0e67b16812c0fb61d8900356
URL: https://github.com/llvm/llvm-project/commit/610a0e8b5368853b0e67b16812c0fb61d8900356
DIFF: https://github.com/llvm/llvm-project/commit/610a0e8b5368853b0e67b16812c0fb61d8900356.diff
LOG: [ELF] Assert on invalid GOT or PLT relocations
Because of https://llvm.org/PR50675, we can end up producing a PLT
relocation referencing a symbol that's dropped from the dynamic symbol
table, which in turn causes a crash at runtime. We ran into this again
recently, resulting in crashes for our users. A subsequent diff will fix
that issue, but add an assert to catch it if it happens again.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D123985
Added:
Modified:
lld/ELF/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 4a07a4c95bdbd..07bb479d6b2d9 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1589,9 +1589,13 @@ int64_t DynamicReloc::computeAddend() const {
}
uint32_t DynamicReloc::getSymIndex(SymbolTableBaseSection *symTab) const {
- if (needsDynSymIndex())
- return symTab->getSymbolIndex(sym);
- return 0;
+ if (!needsDynSymIndex())
+ return 0;
+
+ size_t index = symTab->getSymbolIndex(sym);
+ assert((index != 0 || type != target->gotRel && type != target->pltRel) &&
+ "GOT or PLT relocation must refer to symbol in dynamic symbol table");
+ return index;
}
RelocationBaseSection::RelocationBaseSection(StringRef name, uint32_t type,
More information about the llvm-commits
mailing list