diff options
author | Fangrui Song <maskray@google.com> | 2020-06-19 09:05:28 -0700 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2020-06-19 09:05:37 -0700 |
commit | c4d13f72a6599179f34481d6d848e9fce4ba5ef4 (patch) | |
tree | 407e958f2a394330f54409fd58fbc7da1cbf0f41 /llvm/unittests/Support/FileCheckTest.cpp | |
parent | 2b87a44c493132de15b415424a5b5e9e1cdd9c83 (diff) | |
download | llvm-c4d13f72a6599179f34481d6d848e9fce4ba5ef4.zip llvm-c4d13f72a6599179f34481d6d848e9fce4ba5ef4.tar.gz llvm-c4d13f72a6599179f34481d6d848e9fce4ba5ef4.tar.bz2 |
[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
Diffstat (limited to 'llvm/unittests/Support/FileCheckTest.cpp')
0 files changed, 0 insertions, 0 deletions