]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix --add-gnu-debuglink
authorNick Clifton <nickc@redhat.com>
Fri, 27 Jun 2003 08:01:28 +0000 (08:01 +0000)
committerNick Clifton <nickc@redhat.com>
Fri, 27 Jun 2003 08:01:28 +0000 (08:01 +0000)
bfd/ChangeLog
bfd/bfd-in2.h
bfd/opncls.c
binutils/ChangeLog
binutils/objcopy.c

index 6930e04195868896be0cb9472129d036720b0f03..44159e5a1c1dd05f52b46b8b5e57d32dd8599d17 100644 (file)
@@ -1,3 +1,12 @@
+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.
+
 2003-06-27  Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
 
        * elfxx-mips.c: Revert .got alignment to 2**4.
index bdd7a48eb6e2e98e13c3f3e94bb9a0d3c7077949..c6815ccb07b33b90ad84018887d537b2a23c7c45 100644 (file)
@@ -911,8 +911,11 @@ bfd_calc_gnu_debuglink_crc32 PARAMS ((unsigned long crc, const unsigned char *bu
 char *
 bfd_follow_gnu_debuglink PARAMS ((bfd *abfd, const char *dir));
 
+struct sec *
+bfd_create_gnu_debuglink_section PARAMS ((bfd * abfd, const char * filename));
+
 bfd_boolean
-bfd_add_gnu_debuglink PARAMS ((bfd * abfd, const char * filename));
+bfd_fill_in_gnu_debuglink_section PARAMS ((bfd * abfd, struct sec * sect, const char * filename));
 
 /* Extracted from libbfd.c.  */
 
index b6b4097983ad315d30382b52e29d0abbeab490ec..5237190d97ca7b30e275d6acca39453a796d6bd4 100644 (file)
@@ -1058,16 +1058,82 @@ bfd_follow_gnu_debuglink (abfd, dir)
 
 /*
 FUNCTION
-       bfd_add_gnu_debuglink
+       bfd_create_gnu_debuglink_section
 
 SYNOPSIS
-       bfd_boolean bfd_add_gnu_debuglink (bfd * abfd, const char * filename);
+       struct sec * bfd_create_gnu_debuglink_section (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.
+       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
@@ -1075,11 +1141,11 @@ RETURNS
 */
 
 bfd_boolean
-bfd_add_gnu_debuglink (abfd, filename)
-     bfd *abfd;
-     const char * filename;
+bfd_fill_in_gnu_debuglink_section
+    (bfd *        abfd,
+     struct sec * sect,
+     const char * filename)
 {
-  asection * sect;
   bfd_size_type debuglink_size;
   unsigned long crc32;
   char * contents;
@@ -1088,7 +1154,7 @@ bfd_add_gnu_debuglink (abfd, filename)
   static char buffer[8 * 1024];
   size_t count;
 
-  if (abfd == NULL || filename == NULL)
+  if (abfd == NULL || sect == NULL || filename == NULL)
     {
       bfd_set_error (bfd_error_invalid_operation);
       return FALSE;
@@ -1116,33 +1182,11 @@ bfd_add_gnu_debuglink (abfd, filename)
      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)
     {
index 5b0120265ee57ba6cd07c1f4266d6c4bf3a3ec38..1cbaca6d0da048e6edcf4ef6b23b75cb42bc4077 100644 (file)
@@ -1,3 +1,11 @@
+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.
+
 2003-06-26  Roland McGrath  <roland@redhat.com>
 
        * readelf.c (loadaddr): Variable removed.
index de777678962dd8e071fb66ca06dc5ba171dcc4fe..9b87a8a7c754eb1356d8daad820528a568b4e863 100644 (file)
@@ -1132,6 +1132,7 @@ copy_object (ibfd, obfd)
   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;
@@ -1249,8 +1250,13 @@ copy_object (ibfd, obfd)
 
   if (gnu_debuglink_filename != NULL)
     {
-      if (! bfd_add_gnu_debuglink (obfd, gnu_debuglink_filename))
+      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)
@@ -1413,6 +1419,16 @@ copy_object (ibfd, 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);
+       }
+    }
+
   if (gap_fill_set || pad_to_set)
     {
       bfd_byte *buf;