Skip to content

Commit

Permalink
[ELF] Assert on invalid GOT or PLT relocations
Browse files Browse the repository at this point in the history
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
  • Loading branch information
smeenai committed Apr 20, 2022
1 parent e5f025d commit 610a0e8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lld/ELF/SyntheticSections.cpp
Expand Up @@ -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,
Expand Down

0 comments on commit 610a0e8

Please sign in to comment.