[llvm-objcopy/strip] Fix off-by-one error in SYMTAB_SHNDX need check
authorJames Henderson <james.henderson@sony.com>
Fri, 26 Feb 2021 13:44:48 +0000 (13:44 +0000)
committerJames Henderson <james.henderson@sony.com>
Thu, 4 Mar 2021 10:23:45 +0000 (10:23 +0000)
commit8bb74d16ef04d83f71b1873e7c2e652fb8287b29
tree57f47f7f4099596d750bf968f2ace4b32ebab2a8
parent6e5342a6b0f4172ab6ce49e5d315309ec06b2a27
[llvm-objcopy/strip] Fix off-by-one error in SYMTAB_SHNDX need check

The check for whether an extended symbol index table was required
dropped the first SHN_LORESERVE sections from the sections array before
checking whether the remaining sections had symbols. Unfortunately, the
null section header is not present in this list, so the check was
skipping the first section that might be important. If that section
contained a symbol, and no subsequent ones did, the .symtab_shndx
section would not be emitted, leading to a corrupt object.

Also consolidate and expand test coverage in the area to cover this bug
and other aspects of the SYMTAB_SHNDX section.

Reviewed by: alexshap, MaskRay

Differential Revision: https://reviews.llvm.org/D97661
llvm/test/tools/llvm-objcopy/ELF/auto-remove-add-symtab-shndx.test [new file with mode: 0644]
llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test [deleted file]
llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test [deleted file]
llvm/tools/llvm-objcopy/ELF/Object.cpp