Make bfd_byte an int8_t, flagword a uint32_t
[binutils-gdb.git] / bfd / opncls.c
index 4d0ca48ee78209c171f67a13b777ec2a374887a6..81e124457e991f505ba56cafe8284155af52b8fe 100644 (file)
@@ -1195,28 +1195,23 @@ bfd_get_debug_link_info_1 (bfd *abfd, void *crc32_out)
   unsigned int crc_offset;
   char *name;
   bfd_size_type size;
-  ufile_ptr file_size;
 
   BFD_ASSERT (abfd);
   BFD_ASSERT (crc32_out);
 
   sect = bfd_get_section_by_name (abfd, GNU_DEBUGLINK);
 
-  if (sect == NULL)
+  if (sect == NULL || (sect->flags & SEC_HAS_CONTENTS) == 0)
     return NULL;
 
   size = bfd_section_size (sect);
-  file_size = bfd_get_size (abfd);
 
   /* PR 22794: Make sure that the section has a reasonable size.  */
-  if (size < 8 || (file_size != 0 && size >= file_size))
+  if (size < 8)
     return NULL;
 
   if (!bfd_malloc_and_get_section (abfd, sect, &contents))
-    {
-      free (contents);
-      return NULL;
-    }
+    return NULL;
 
   /* CRC value is stored after the filename, aligned up to 4 bytes.  */
   name = (char *) contents;
@@ -1224,7 +1219,10 @@ bfd_get_debug_link_info_1 (bfd *abfd, void *crc32_out)
   crc_offset = strnlen (name, size) + 1;
   crc_offset = (crc_offset + 3) & ~3;
   if (crc_offset + 4 > size)
-    return NULL;
+    {
+      free (name);
+      return NULL;
+    }
 
   *crc32 = bfd_get_32 (abfd, contents + crc_offset);
   return name;
@@ -1284,7 +1282,6 @@ bfd_get_alt_debug_link_info (bfd * abfd, bfd_size_type *buildid_len,
   unsigned int buildid_offset;
   char *name;
   bfd_size_type size;
-  ufile_ptr file_size;
 
   BFD_ASSERT (abfd);
   BFD_ASSERT (buildid_len);
@@ -1292,19 +1289,15 @@ bfd_get_alt_debug_link_info (bfd * abfd, bfd_size_type *buildid_len,
 
   sect = bfd_get_section_by_name (abfd, GNU_DEBUGALTLINK);
 
-  if (sect == NULL)
+  if (sect == NULL || (sect->flags & SEC_HAS_CONTENTS) == 0)
     return NULL;
 
   size = bfd_section_size (sect);
-  file_size = bfd_get_size (abfd);
-  if (size < 8 || (file_size != 0 && size >= file_size))
+  if (size < 8)
     return NULL;
 
   if (!bfd_malloc_and_get_section (abfd, sect, & contents))
-    {
-      free (contents);
-      return NULL;
-    }
+    return NULL;
 
   /* BuildID value is stored after the filename.  */
   name = (char *) contents;
@@ -1706,8 +1699,8 @@ SYNOPSIS
 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.
+       specified @var{filename}.  The filename should be absolute or
+       relative to the current directory.
 
        <<TRUE>> is returned if all is ok.  Otherwise <<FALSE>> is returned
        and bfd_error is set.
@@ -1733,12 +1726,7 @@ bfd_fill_in_gnu_debuglink_section (bfd *abfd,
       return false;
     }
 
-  /* Make sure that we can read the file.
-     XXX - Should we attempt to locate the debug info file using the same
-     algorithm as gdb ?  At the moment, since we are creating the
-     .gnu_debuglink section, we insist upon the user providing us with a
-     correct-for-section-creation-time path, but this need not conform to
-     the gdb location algorithm.  */
+  /* Open the linked file so that we can compute a CRC.  */
   handle = _bfd_real_fopen (filename, FOPEN_RB);
   if (handle == NULL)
     {
@@ -1810,7 +1798,8 @@ get_build_id (bfd *abfd)
     return (struct bfd_build_id *) abfd->build_id;
 
   sect = bfd_get_section_by_name (abfd, ".note.gnu.build-id");
-  if (sect == NULL)
+  if (sect == NULL
+      || (sect->flags & SEC_HAS_CONTENTS) == 0)
     {
       bfd_set_error (bfd_error_no_debug_section);
       return NULL;
@@ -1825,10 +1814,7 @@ get_build_id (bfd *abfd)
     }
 
   if (!bfd_malloc_and_get_section (abfd, sect, & contents))
-    {
-      free (contents);
-      return NULL;
-    }
+    return NULL;
 
   /* FIXME: Paranoia - allow for compressed build-id sections.
      Maybe we should complain if this size is different from