This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[RFA] Make objcopy handle core files.
- From: Michael Snyder <msnyder at cygnus dot com>
- To: binutils at sources dot redhat dot com
- Cc: nickc at redhat dot com
- Date: Wed, 12 Dec 2001 15:23:32 -0800
- Subject: [RFA] Make objcopy handle core files.
A fairly small set of changes enables objcopy to copy corefiles.
2001-12-12 Michael Snyder <msnyder@redhat.com>
* objcopy.c (copy_file): Accept corefiles (format bfd_core).
(copy_object): Don't set the start address or flags of a core file.
(copy_section): Don't relocate a core file. Don't copy contents
if the input section has the contents flag set, but the output
section does not (which happens with the fake 'note' pseudo-
sections that BFD creates for corefiles).
Index: objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.30
diff -p -r1.30 objcopy.c
*** objcopy.c 2001/12/10 11:03:54 1.30
--- objcopy.c 2001/12/12 23:17:33
*************** copy_object (ibfd, obfd)
*** 958,968 ****
start = bfd_get_start_address (ibfd);
start += change_start;
! if (!bfd_set_start_address (obfd, start)
! || !bfd_set_file_flags (obfd,
! (bfd_get_file_flags (ibfd)
! & bfd_applicable_file_flags (obfd))))
! RETURN_NONFATAL (bfd_get_filename (ibfd));
/* Copy architecture of input file to output file. */
if (!bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
--- 958,973 ----
start = bfd_get_start_address (ibfd);
start += change_start;
! /* Neither the start address nor the flags
! need to be set for a core file. */
! if (!bfd_check_format (ibfd, bfd_core))
! {
! if (!bfd_set_start_address (obfd, start)
! || !bfd_set_file_flags (obfd,
! (bfd_get_file_flags (ibfd)
! & bfd_applicable_file_flags (obfd))))
! RETURN_NONFATAL (bfd_get_filename (ibfd));
! }
/* Copy architecture of input file to output file. */
if (!bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
*************** copy_file (input_filename, output_filena
*** 1403,1409 ****
copy_archive (ibfd, obfd, output_target);
}
! else if (bfd_check_format_matches (ibfd, bfd_object, &matching))
{
bfd *obfd;
--- 1408,1415 ----
copy_archive (ibfd, obfd, output_target);
}
! else if (bfd_check_format_matches (ibfd, bfd_object, &matching)
! || bfd_check_format_matches (ibfd, bfd_core, &matching))
{
bfd *obfd;
*************** copy_section (ibfd, isection, obfdarg)
*** 1673,1680 ****
if (size == 0 || osection == 0)
return;
- relsize = bfd_get_reloc_upper_bound (ibfd, isection);
if (relsize < 0)
RETURN_NONFATAL (bfd_get_filename (ibfd));
--- 1679,1691 ----
if (size == 0 || osection == 0)
return;
+
+ /* Core files do not need to be relocated. */
+ if (bfd_check_format (ibfd, bfd_core))
+ relsize = 0;
+ else
+ relsize = bfd_get_reloc_upper_bound (ibfd, isection);
if (relsize < 0)
RETURN_NONFATAL (bfd_get_filename (ibfd));
*************** copy_section (ibfd, isection, obfdarg)
*** 1713,1719 ****
isection->_cooked_size = isection->_raw_size;
isection->reloc_done = true;
! if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS)
{
PTR memhunk = (PTR) xmalloc ((unsigned) size);
--- 1724,1731 ----
isection->_cooked_size = isection->_raw_size;
isection->reloc_done = true;
! if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
! && bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
{
PTR memhunk = (PTR) xmalloc ((unsigned) size);