[ELF] Refactor ObjFile<ELFT>::initializeSymbols to enforce the invariant:...
[ELF] Refactor ObjFile<ELFT>::initializeSymbols to enforce the invariant: InputFile::symbols has non null entry Fixes PR46348. ObjFile<ELFT>::initializeSymbols contains two symbol iteration loops: ``` for each symbol if non-inheriting && non-local fill in this->symbols[i] for each symbol if local fill in this->symbols[i] else symbol resolution ``` Symbol resolution can trigger a duplicate symbol error which will call InputSectionBase::getObjMsg to iterate over InputFile::symbols. If a non-local symbol appears after the non-local symbol being resolved (violating ELF spec), its `this->symbols[i]` entry has not been filled in, InputSectionBase::getObjMsg will crash due to `dyn_cast<Defined>(nullptr)`. To fix the bug, reorganize the two loops to ensure this->symbols is complete before symbol resolution. This enforces the invariant: InputFile::symbols has none null entry when InputFile::getSymbols() is called. ``` for each symbol if non-inheriting fill in this->symbols[i] for each symbol starting from firstGlobal if non-local symbol resolution ``` Additionally, move the (non-local symbol in local part of .symtab) diagnostic from Writer<ELFT>::copyLocalSymbols() to initializeSymbols(). Reviewed By: grimar, jhenderson Differential Revision: https://reviews.llvm.org/D81988
Loading
Please sign in to comment