[PATCH] D83037: [llvm-readobj] - Fix a crash scenario in GNUStyle<ELFT>::printHashSymbols().

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 3 03:45:00 PDT 2020


grimar added inline comments.


================
Comment at: llvm/tools/llvm-readobj/ELFDumper.cpp:4047
 
+    const Elf_Sym *FirstSym = DynSyms.empty() ? nullptr : &DynSyms[0];
+    if (!FirstSym) {
----------------
jhenderson wrote:
> I'm not sure if this does this, but I think we need to distinguish between the dynsym being actually empty (i.e. sh_size == 0 specified by the .dynsym section header) and we just don't know it's empty (i.e. there's no section header at all, but there is a DT_SYMTAB tag). See rGb259ce99 for context. If this code already does that, what in the test ensures we haven't broken this situation? I'm having a bit of a struggle remembering how that change worked, so this might not be relevant at all.
`dynamic_symbols` returns an empty range for both cases when either there is no `DynSymRegion` at all or when it is found, but empty:

```
  Elf_Sym_Range dynamic_symbols() const {
    if (!DynSymRegion)
      return Elf_Sym_Range();
    return DynSymRegion->getAsArrayRef<Elf_Sym>();
  }
```

To distinguish between these cases we can additionally check the `DynSymRegion` when reporting a warning. I've did it and added test cases.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83037/new/

https://reviews.llvm.org/D83037





More information about the llvm-commits mailing list