HomePhabricator

[llvm-objcopy] --add-symbol: fix crash if SHT_SYMTAB does not exist

Authored by MaskRay on Oct 17 2019, 4:21 AM.

Description

[llvm-objcopy] --add-symbol: fix crash if SHT_SYMTAB does not exist

Exposed by D69041. If SHT_SYMTAB does not exist, ELFObjcopy.cpp:handleArgs will crash due
to a null pointer dereference.

for (const NewSymbolInfo &SI : Config.ELF->SymbolsToAdd) {
  ...
  Obj.SymbolTable->addSymbol(

Fix this by creating .symtab and .strtab on demand in ELFBuilder<ELFT>::readSections,
if --add-symbol is specified.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D69093

llvm-svn: 375105

Details