Trying to create an elf32-sh object from a binary causes a segfault: $ sh-elf-objcopy -B sh -I binary -O elf32-sh infile outfile.elf Segmentation fault: 11 Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 sh-elf-objcopy 0x0000000104282eef _bfd_elf_copy_obj_attributes + 287 1 sh-elf-objcopy 0x000000010425428e sh_elf_copy_private_data + 30 2 sh-elf-objcopy 0x0000000104213423 copy_object + 5827 (objcopy.c:2012) 3 sh-elf-objcopy 0x0000000104214752 copy_file + 2178 (objcopy.c:2340) 4 sh-elf-objcopy 0x0000000104211241 main + 8033 (objcopy.c:4046) 5 sh-elf-objcopy 0x000000010420f2d4 start + 52 Host is OS X 10.7.5, binutils was configured with target=sh-elf and built with the November 2012 Xcode command-line tool release.
The same test also crashes on Linux (tested on Scientific Linux 6.3 64-bit). The crash happens in _bfd_elf_copy_obj_attributes on the line if (in_attr->s && *in_attr->s) At the point of the crash, in_attr->s contains the value 0x2d8322e657274450 which is clearly invalid. The loop index i has the value 56.
CVSROOT: /cvs/src Module name: src Changes by: amodra@sourceware.org 2013-02-07 03:44:27 Modified files: bfd : ChangeLog elf-attrs.c Log message: PR binutils/14873 * elf-attrs.c (_bfd_elf_copy_obj_attributes): Don't attempt to copy attributes from or to non-ELF. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5933&r2=1.5934 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf-attrs.c.diff?cvsroot=src&r1=1.15&r2=1.16
CVSROOT: /cvs/src Module name: src Branch: binutils-2_23-branch Changes by: amodra@sourceware.org 2013-02-07 03:44:41 Modified files: bfd : ChangeLog elf-attrs.c Log message: PR binutils/14873 * elf-attrs.c (_bfd_elf_copy_obj_attributes): Don't attempt to copy attributes from or to non-ELF. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_23-branch&r1=1.5758.2.41&r2=1.5758.2.42 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf-attrs.c.diff?cvsroot=src&only_with_tag=binutils-2_23-branch&r1=1.15&r2=1.15.4.1
Fixed