Bug 24643 - arm/aarch64: SEGV in objdump -ld for static programs with split out debug symbols
Summary: arm/aarch64: SEGV in objdump -ld for static programs with split out debug sym...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-06 20:11 UTC by Adam Lackorzynski
Modified: 2019-06-12 14:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-06-11 00:00:00


Attachments
Patch to fix segfault (319 bytes, patch)
2019-06-06 20:11 UTC, Adam Lackorzynski
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Lackorzynski 2019-06-06 20:11:58 UTC
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.
Comment 1 Tamar Christina 2019-06-11 16:30:42 UTC
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
Comment 2 Nick Clifton 2019-06-12 14:06:53 UTC
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
Comment 3 Sourceware Commits 2019-06-12 14:07:03 UTC
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.