Created attachment 11816 [details] Patch to fix segfault Hi, objdump segfaults when using split out debug symbols and static programs on arm and aarch64: $ cat sh.sh echo 'int main() { return 0; }' > foo.c set -x aarch64-linux-gnu-gcc -static -o foo-arm64 foo.c objcopy --only-keep-debug foo-arm64 foo-arm64.debug objcopy --strip-unneeded foo-arm64 objcopy --add-gnu-debuglink=foo-arm64.debug foo-arm64 objdump -ld foo-arm64 arm-linux-gnueabihf-gcc -static -o foo-arm32 foo.c objcopy --only-keep-debug foo-arm32 foo-arm32.debug objcopy --strip-unneeded foo-arm32 objcopy --add-gnu-debuglink=foo-arm32.debug foo-arm32 objdump -ld foo-arm32 $ sh sh.sh + aarch64-linux-gnu-gcc -static -o foo-arm64 foo.c + objcopy --only-keep-debug foo-arm64 foo-arm64.debug + objcopy --strip-unneeded foo-arm64 + objcopy --add-gnu-debuglink=foo-arm64.debug foo-arm64 + objdump -ld foo-arm64 foo-arm64: file format elf64-littleaarch64 Disassembly of section .init: 00000000004001d8 <.init>: sh.sh: line 7: 31282 Segmentation fault objdump -ld foo-arm64 + arm-linux-gnueabihf-gcc -static -o foo-arm32 foo.c + objcopy --only-keep-debug foo-arm32 foo-arm32.debug + objcopy --strip-unneeded foo-arm32 + objcopy --add-gnu-debuglink=foo-arm32.debug foo-arm32 + objdump -ld foo-arm32 foo-arm32: file format elf32-littlearm Disassembly of section .init: 00010140 <.init>: sh.sh: line 13: 31291 Segmentation fault objdump -ld foo-arm32 $ Problem seems to be that aarch64_elf_find_function/arm_elf_find_function get their symbols argument with NULL which the function is not prepared to handle. Adding a check for NULL makes it work, see attached patch.
Hi Adam, Thanks for the patch and report. The patch looks fine to me but I'm not a maintainer so this still requires maintainer approval. Cheers, Tamar
Hi Adam, Patch approved and applied. Note - I made one small addition - I added a check that the bfd being scanned was in the ELF format. This is probably redundant for these two specific functions, but the test is present in the generic code upon which they are based, and I believe in being paranoid. Cheers Nick
The master branch has been updated by Nick Clifton <nickc@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=62e0492f5723dd3db5e5a48a3a0ac161d7ba2701 commit 62e0492f5723dd3db5e5a48a3a0ac161d7ba2701 Author: Adam Lackorzymski <adam@os.inf.tu-dresden.de> Date: Wed Jun 12 15:05:21 2019 +0100 Prevent a seg-fault from objdup when disassembling binaries which do not contain a symbol table. PR 24643 * elf32-arm.c (arm_elf_find_function): Fail if the symol table is absent, or the bfd is not in the ELF formart. * elfnn-aarch64.c (aarch64_elf_find_function): Likewise.