[llvm-objcopy] Use getNumberOfSymbols() instead of getRawNumberOfSymbols()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 19 Dec 2022 11:53:02 +0000 (11:53 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 2 Jan 2023 12:22:50 +0000 (13:22 +0100)
commit556af193309f6e283712602b9a8ca5d19adb1792
tree0c06a3645373b5f4cf48ebae2f4aaf9455aa9516
parent9cd113a2a8fa25ee76fe2ed26489c4003f24875a
[llvm-objcopy] Use getNumberOfSymbols() instead of getRawNumberOfSymbols()

getRawNumberOfSymbols() assumes that a symbol table exists, which isn't
always guaranteed, while getNumberOfSymbols() handles and tolerates objects
without a symbol table. When there is a symbol table, both methods return
the same value.

Also add a test to ensure we don't regress in this regard. The test
generates a basic COFF object with symbols and overrides the symbol table
pointer with zeros to craft the input required to verify llvm-objcopy works
as expected in this scenario.
llvm/lib/ObjCopy/COFF/COFFReader.cpp
llvm/test/tools/llvm-objcopy/COFF/Inputs/no-symbol-table.yaml [new file with mode: 0644]
llvm/test/tools/llvm-objcopy/COFF/no-symbol-table.test [new file with mode: 0644]