[all-commits] [llvm/llvm-project] c4d13f: [ELF] Refactor ObjFile<ELFT>::initializeSymbols to...

Fangrui Song via All-commits all-commits at lists.llvm.org
Fri Jun 19 09:06:00 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: c4d13f72a6599179f34481d6d848e9fce4ba5ef4
      https://github.com/llvm/llvm-project/commit/c4d13f72a6599179f34481d6d848e9fce4ba5ef4
  Author: Fangrui Song <maskray at google.com>
  Date:   2020-06-19 (Fri, 19 Jun 2020)

  Changed paths:
    M lld/ELF/InputFiles.cpp
    M lld/ELF/Writer.cpp
    A lld/test/ELF/invalid/symtab-sh-info-dup.test
    M lld/test/ELF/invalid/symtab-sh-info.s

  Log Message:
  -----------
  [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




More information about the All-commits mailing list