This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
objcopy: Fix --add-gnu-debuglink
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sources dot redhat dot com
- Date: Fri, 27 Jun 2003 08:52:42 +0100
- Subject: objcopy: Fix --add-gnu-debuglink
Hi Guys,
I am applying this patch to fix the --add-gnu-debuglink switch
recently added to objcopy. With this patch applied and with Elena's
recent patch to GDB we are now able to create and use seperate debug
info files.
Cheers
Nick
bfd/ChangeLog
2003-06-27 Nick Clifton <nickc@redhat.com>
* opncls.c (bfd_add_gnu_debuglink_section): Rename to
bfd_add_gnu_debuglink_section and only create the section, do not
fill in its contents.
(bfd_fill_in_gnu_debuglink_section): New function. Fill in the
contents of a .gnu-debuglink section.
* bfd-in2.h: Regenerate.
binutils/ChangeLog
2003-06-27 Nick Clifton <nickc@redhat.com>
* objcopy.c (copy_object): Replace call to
bfd_create_gnu_debuglink_section with seperate calls to
bfd_add_gnu_debuglink_section and
bfd_fill_in_gnu_debuglink_section, seperated by a walk over the
symbol tables.
Index: bfd/opncls.c
===================================================================
RCS file: /cvs/src/src/bfd/opncls.c,v
retrieving revision 1.16
diff -c -3 -p -r1.16 opncls.c
*** bfd/opncls.c 12 Jun 2003 07:23:30 -0000 1.16
--- bfd/opncls.c 27 Jun 2003 07:53:51 -0000
*************** bfd_follow_gnu_debuglink (abfd, dir)
*** 1058,1073 ****
/*
FUNCTION
! bfd_add_gnu_debuglink
SYNOPSIS
! bfd_boolean bfd_add_gnu_debuglink (bfd * abfd, const char * filename);
DESCRIPTION
! Takes a @var{BFD} and adds a .gnu_debuglink section containing a link
! to the specified @var{filename}. The filename should be relative to
! the current directory.
RETURNS
<<TRUE>> is returned if all is ok. Otherwise <<FALSE>> is returned
--- 1058,1139 ----
/*
FUNCTION
! bfd_create_gnu_debuglink_section
SYNOPSIS
! struct sec * bfd_create_gnu_debuglink_section (bfd * abfd, const char * filename);
DESCRIPTION
! Takes a @var{BFD} and adds a .gnu_debuglink section to it. The section is sized
! to be big enough to contain a link to the specified @var{filename}.
!
! RETURNS
! A pointer to the new section is returned if all is ok. Otherwise <<NULL>> is
! returned and bfd_error is set.
! */
!
! asection *
! bfd_create_gnu_debuglink_section
! (bfd * abfd,
! const char * filename)
! {
! asection * sect;
! bfd_size_type debuglink_size;
!
! if (abfd == NULL || filename == NULL)
! {
! bfd_set_error (bfd_error_invalid_operation);
! return NULL;
! }
!
! /* Strip off any path components in filename. */
! filename = lbasename (filename);
!
! sect = bfd_get_section_by_name (abfd, GNU_DEBUGLINK);
! if (sect)
! {
! /* Section already exists. */
! bfd_set_error (bfd_error_invalid_operation);
! return NULL;
! }
!
! sect = bfd_make_section (abfd, GNU_DEBUGLINK);
! if (sect == NULL)
! return NULL;
!
! if (! bfd_set_section_flags (abfd, sect,
! SEC_HAS_CONTENTS | SEC_READONLY | SEC_DEBUGGING))
! /* XXX Should we delete the section from the bfd ? */
! return NULL;
!
!
! debuglink_size = strlen (filename) + 1;
! debuglink_size += 3;
! debuglink_size &= ~3;
! debuglink_size += 4;
!
! if (! bfd_set_section_size (abfd, sect, debuglink_size))
! /* XXX Should we delete the section from the bfd ? */
! return NULL;
!
! return sect;
! }
!
!
! /*
! FUNCTION
! bfd_fill_in_gnu_debuglink_section
!
! SYNOPSIS
! bfd_boolean bfd_fill_in_gnu_debuglink_section (bfd * abfd, struct sec * sect, const char * filename);
!
! DESCRIPTION
!
! Takes a @var{BFD} and containing a .gnu_debuglink section @var{SECT}
! and fills in the contents of the section to contain a link to the
! specified @var{filename}. The filename should be relative to the
! current directory.
RETURNS
<<TRUE>> is returned if all is ok. Otherwise <<FALSE>> is returned
*************** RETURNS
*** 1075,1085 ****
*/
bfd_boolean
! bfd_add_gnu_debuglink (abfd, filename)
! bfd *abfd;
! const char * filename;
{
- asection * sect;
bfd_size_type debuglink_size;
unsigned long crc32;
char * contents;
--- 1141,1151 ----
*/
bfd_boolean
! bfd_fill_in_gnu_debuglink_section
! (bfd * abfd,
! struct sec * sect,
! const char * filename)
{
bfd_size_type debuglink_size;
unsigned long crc32;
char * contents;
*************** bfd_add_gnu_debuglink (abfd, filename)
*** 1088,1094 ****
static char buffer[8 * 1024];
size_t count;
! if (abfd == NULL || filename == NULL)
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
--- 1154,1160 ----
static char buffer[8 * 1024];
size_t count;
! if (abfd == NULL || sect == NULL || filename == NULL)
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
*************** bfd_add_gnu_debuglink (abfd, filename)
*** 1116,1148 ****
now that we no longer need them. */
filename = lbasename (filename);
- sect = bfd_get_section_by_name (abfd, GNU_DEBUGLINK);
- if (sect)
- {
- /* Section already exists. */
- bfd_set_error (bfd_error_invalid_operation);
- return FALSE;
- }
-
- sect = bfd_make_section (abfd, GNU_DEBUGLINK);
- if (sect == NULL)
- return FALSE;
-
- if (! bfd_set_section_flags (abfd, sect,
- SEC_HAS_CONTENTS | SEC_DEBUGGING))
- /* XXX Should we delete the section from the bfd ? */
- return FALSE;
-
-
debuglink_size = strlen (filename) + 1;
debuglink_size += 3;
debuglink_size &= ~3;
debuglink_size += 4;
- if (! bfd_set_section_size (abfd, sect, debuglink_size))
- /* XXX Should we delete the section from the bfd ? */
- return FALSE;
-
contents = malloc (debuglink_size);
if (contents == NULL)
{
--- 1182,1192 ----
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.50
diff -c -3 -p -r1.50 objcopy.c
*** binutils/objcopy.c 26 Jun 2003 08:14:10 -0000 1.50
--- binutils/objcopy.c 27 Jun 2003 07:53:53 -0000
*************** copy_object (ibfd, obfd)
*** 1132,1137 ****
--- 1132,1138 ----
bfd_vma start;
long symcount;
asection **osections = NULL;
+ asection * gnu_debuglink_section = NULL;
bfd_size_type *gaps = NULL;
bfd_size_type max_gap = 0;
long symsize;
*************** copy_object (ibfd, obfd)
*** 1249,1256 ****
if (gnu_debuglink_filename != NULL)
{
! if (! bfd_add_gnu_debuglink (obfd, gnu_debuglink_filename))
RETURN_NONFATAL (gnu_debuglink_filename);
}
if (gap_fill_set || pad_to_set)
--- 1250,1262 ----
if (gnu_debuglink_filename != NULL)
{
! gnu_debuglink_section = bfd_create_gnu_debuglink_section (obfd, gnu_debuglink_filename);
!
! if (gnu_debuglink_section == NULL)
! {
! fprintf (stderr, "UGG\n");
RETURN_NONFATAL (gnu_debuglink_filename);
+ }
}
if (gap_fill_set || pad_to_set)
*************** copy_object (ibfd, obfd)
*** 1410,1415 ****
--- 1416,1431 ----
(file_ptr) 0,
(bfd_size_type) padd->size))
RETURN_NONFATAL (bfd_get_filename (obfd));
+ }
+ }
+
+ if (gnu_debuglink_filename != NULL)
+ {
+ if (! bfd_fill_in_gnu_debuglink_section
+ (obfd, gnu_debuglink_section, gnu_debuglink_filename))
+ {
+ fprintf (stderr, "UGG 2\n");
+ RETURN_NONFATAL (gnu_debuglink_filename);
}
}