9a84451
diff -rcp ../binutils-2.23.2.orig/bfd/bfd-in2.h bfd/bfd-in2.h
9a84451
*** ../binutils-2.23.2.orig/bfd/bfd-in2.h	2013-05-29 15:56:00.512051112 +0100
9a84451
--- bfd/bfd-in2.h	2013-05-29 15:58:54.994055949 +0100
9a84451
*************** void *bfd_zalloc (bfd *abfd, bfd_size_ty
9a84451
*** 1042,1049 ****
9a84451
--- 1042,1053 ----
9a84451
  unsigned long bfd_calc_gnu_debuglink_crc32
9a84451
     (unsigned long crc, const unsigned char *buf, bfd_size_type len);
9a84451
  
9a84451
+ char *bfd_get_alt_debug_link_info (bfd *abfd, unsigned long *crc32_out);
9a84451
+ 
9a84451
  char *bfd_follow_gnu_debuglink (bfd *abfd, const char *dir);
9a84451
  
9a84451
+ char *bfd_follow_gnu_debugaltlink (bfd *abfd, const char *dir);
9a84451
+ 
9a84451
  struct bfd_section *bfd_create_gnu_debuglink_section
9a84451
     (bfd *abfd, const char *filename);
9a84451
  
9a84451
diff -rcp ../binutils-2.23.2.orig/bfd/dwarf2.c bfd/dwarf2.c
9a84451
*** ../binutils-2.23.2.orig/bfd/dwarf2.c	2013-05-29 15:56:00.296051106 +0100
9a84451
--- bfd/dwarf2.c	2013-05-29 16:00:03.490057848 +0100
9a84451
*************** struct dwarf2_debug
9a84451
*** 108,113 ****
9a84451
--- 108,123 ----
9a84451
    asection *sec;
9a84451
    bfd_byte *sec_info_ptr;
9a84451
  
9a84451
+   /* Support for alternate debug info sections created by the DWZ utility:
9a84451
+      This includes a pointer to an alternate bfd which contains *extra*,
9a84451
+      possibly duplicate debug sections, and pointers to the loaded
9a84451
+      .debug_str and .debug_info sections from this bfd.  */
9a84451
+   bfd *          alt_bfd_ptr;
9a84451
+   bfd_byte *     alt_dwarf_str_buffer;
9a84451
+   bfd_size_type  alt_dwarf_str_size;
9a84451
+   bfd_byte *     alt_dwarf_info_buffer;
9a84451
+   bfd_size_type  alt_dwarf_info_size;
9a84451
+ 
9a84451
    /* A pointer to the memory block allocated for info_ptr.  Neither
9a84451
       info_ptr nor sec_info_ptr are guaranteed to stay pointing to the
9a84451
       beginning of the malloc block.  This is used only to free the
9a84451
*************** const struct dwarf_debug_section dwarf_d
9a84451
*** 287,292 ****
9a84451
--- 297,303 ----
9a84451
    { ".debug_aranges",		".zdebug_aranges" },
9a84451
    { ".debug_frame",		".zdebug_frame" },
9a84451
    { ".debug_info",		".zdebug_info" },
9a84451
+   { ".debug_info",		".zdebug_info" },
9a84451
    { ".debug_line",		".zdebug_line" },
9a84451
    { ".debug_loc",		".zdebug_loc" },
9a84451
    { ".debug_macinfo",		".zdebug_macinfo" },
9a84451
*************** const struct dwarf_debug_section dwarf_d
9a84451
*** 297,302 ****
9a84451
--- 308,314 ----
9a84451
    { ".debug_static_func",	".zdebug_static_func" },
9a84451
    { ".debug_static_vars",	".zdebug_static_vars" },
9a84451
    { ".debug_str",		".zdebug_str", },
9a84451
+   { ".debug_str",		".zdebug_str", },
9a84451
    { ".debug_types",		".zdebug_types" },
9a84451
    /* GNU DWARF 1 extensions */
9a84451
    { ".debug_sfnames",		".zdebug_sfnames" },
9a84451
*************** const struct dwarf_debug_section dwarf_d
9a84451
*** 309,320 ****
9a84451
--- 321,335 ----
9a84451
    { NULL,			NULL },
9a84451
  };
9a84451
  
9a84451
+ /* NB/ Numbers in this enum must match up with indicies
9a84451
+    into the dwarf_debug_sections[] array above.  */
9a84451
  enum dwarf_debug_section_enum
9a84451
  {
9a84451
    debug_abbrev = 0,
9a84451
    debug_aranges,
9a84451
    debug_frame,
9a84451
    debug_info,
9a84451
+   debug_info_alt,
9a84451
    debug_line,
9a84451
    debug_loc,
9a84451
    debug_macinfo,
9a84451
*************** enum dwarf_debug_section_enum
9a84451
*** 325,330 ****
9a84451
--- 340,346 ----
9a84451
    debug_static_func,
9a84451
    debug_static_vars,
9a84451
    debug_str,
9a84451
+   debug_str_alt,
9a84451
    debug_types,
9a84451
    debug_sfnames,
9a84451
    debug_srcinfo,
9a84451
*************** read_section (bfd *           abfd,
9a84451
*** 481,488 ****
9a84451
    asection *msec;
9a84451
    const char *section_name = sec->uncompressed_name;
9a84451
  
9a84451
!   /* read_section is a noop if the section has already been read.  */
9a84451
!   if (!*section_buffer)
9a84451
      {
9a84451
        msec = bfd_get_section_by_name (abfd, section_name);
9a84451
        if (! msec)
9a84451
--- 497,504 ----
9a84451
    asection *msec;
9a84451
    const char *section_name = sec->uncompressed_name;
9a84451
  
9a84451
!   /* The section may have already been read.  */
9a84451
!   if (*section_buffer == NULL)
9a84451
      {
9a84451
        msec = bfd_get_section_by_name (abfd, section_name);
9a84451
        if (! msec)
9a84451
*************** read_indirect_string (struct comp_unit *
9a84451
*** 623,628 ****
9a84451
--- 639,742 ----
9a84451
    return str;
9a84451
  }
9a84451
  
9a84451
+ /* Like read_indirect_string but uses a .debug_str located in
9a84451
+    an alternate filepointed to by the .gnu_debuglink section.
9a84451
+    Used to impement DW_FORM_GNU_strp_alt.  */
9a84451
+ 
9a84451
+ static char *
9a84451
+ read_alt_indirect_string (struct comp_unit * unit,
9a84451
+ 			  bfd_byte *         buf,
9a84451
+ 			  unsigned int *     bytes_read_ptr)
9a84451
+ {
9a84451
+   bfd_uint64_t offset;
9a84451
+   struct dwarf2_debug *stash = unit->stash;
9a84451
+   char *str;
9a84451
+ 
9a84451
+   if (unit->offset_size == 4)
9a84451
+     offset = read_4_bytes (unit->abfd, buf);
9a84451
+   else
9a84451
+     offset = read_8_bytes (unit->abfd, buf);
9a84451
+ 
9a84451
+   *bytes_read_ptr = unit->offset_size;
9a84451
+ 
9a84451
+   if (stash->alt_bfd_ptr == NULL)
9a84451
+     {
9a84451
+       bfd *  debug_bfd;
9a84451
+       char * debug_filename = bfd_follow_gnu_debugaltlink (unit->abfd, DEBUGDIR);
9a84451
+ 
9a84451
+       if (debug_filename == NULL)
9a84451
+ 	return NULL;
9a84451
+ 
9a84451
+       if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
9a84451
+ 	  || ! bfd_check_format (debug_bfd, bfd_object))
9a84451
+ 	{
9a84451
+ 	  if (debug_bfd)
9a84451
+ 	    bfd_close (debug_bfd);
9a84451
+ 
9a84451
+ 	  /* FIXME: Should we report our failure to follow the debuglink ?  */
9a84451
+ 	  free (debug_filename);
9a84451
+ 	  return NULL;
9a84451
+ 	}
9a84451
+       stash->alt_bfd_ptr = debug_bfd;
9a84451
+     }
9a84451
+   
9a84451
+   if (! read_section (unit->stash->alt_bfd_ptr,
9a84451
+ 		      stash->debug_sections + debug_str_alt,
9a84451
+ 		      NULL, /* FIXME: Do we need to load alternate symbols ?  */
9a84451
+ 		      offset,
9a84451
+ 		      &stash->alt_dwarf_str_buffer,
9a84451
+ 		      &stash->alt_dwarf_str_size))
9a84451
+     return NULL;
9a84451
+ 
9a84451
+   str = (char *) stash->alt_dwarf_str_buffer + offset;
9a84451
+   if (*str == '\0')
9a84451
+     return NULL;
9a84451
+ 
9a84451
+   return str;
9a84451
+ }
9a84451
+ 
9a84451
+ /* Resolve an alternate reference from UNIT at OFFSET.
9a84451
+    Returns a pointer into the loaded alternate CU upon success
9a84451
+    or NULL upon failure.  */
9a84451
+ 
9a84451
+ static bfd_byte *
9a84451
+ read_alt_indirect_ref (struct comp_unit * unit,
9a84451
+ 		       bfd_uint64_t       offset)
9a84451
+ {
9a84451
+   struct dwarf2_debug *stash = unit->stash;
9a84451
+ 
9a84451
+   if (stash->alt_bfd_ptr == NULL)
9a84451
+     {
9a84451
+       bfd *  debug_bfd;
9a84451
+       char * debug_filename = bfd_follow_gnu_debugaltlink (unit->abfd, DEBUGDIR);
9a84451
+ 
9a84451
+       if (debug_filename == NULL)
9a84451
+ 	return FALSE;
9a84451
+ 
9a84451
+       if ((debug_bfd = bfd_openr (debug_filename, NULL)) == NULL
9a84451
+ 	  || ! bfd_check_format (debug_bfd, bfd_object))
9a84451
+ 	{
9a84451
+ 	  if (debug_bfd)
9a84451
+ 	    bfd_close (debug_bfd);
9a84451
+ 
9a84451
+ 	  /* FIXME: Should we report our failure to follow the debuglink ?  */
9a84451
+ 	  free (debug_filename);
9a84451
+ 	  return NULL;
9a84451
+ 	}
9a84451
+       stash->alt_bfd_ptr = debug_bfd;
9a84451
+     }
9a84451
+   
9a84451
+   if (! read_section (unit->stash->alt_bfd_ptr,
9a84451
+ 		      stash->debug_sections + debug_info_alt,
9a84451
+ 		      NULL, /* FIXME: Do we need to load alternate symbols ?  */
9a84451
+ 		      offset,
9a84451
+ 		      &stash->alt_dwarf_info_buffer,
9a84451
+ 		      &stash->alt_dwarf_info_size))
9a84451
+     return NULL;
9a84451
+ 
9a84451
+   return stash->alt_dwarf_info_buffer + offset;
9a84451
+ }
9a84451
+ 
9a84451
  static bfd_uint64_t
9a84451
  read_address (struct comp_unit *unit, bfd_byte *buf)
9a84451
  {
9a84451
*************** read_attribute_value (struct attribute *
9a84451
*** 826,831 ****
9a84451
--- 940,946 ----
9a84451
        attr->u.val = read_address (unit, info_ptr);
9a84451
        info_ptr += unit->addr_size;
9a84451
        break;
9a84451
+     case DW_FORM_GNU_ref_alt:
9a84451
      case DW_FORM_sec_offset:
9a84451
        if (unit->offset_size == 4)
9a84451
  	attr->u.val = read_4_bytes (unit->abfd, info_ptr);
9a84451
*************** read_attribute_value (struct attribute *
9a84451
*** 875,880 ****
9a84451
--- 990,999 ----
9a84451
        attr->u.str = read_indirect_string (unit, info_ptr, &bytes_read);
9a84451
        info_ptr += bytes_read;
9a84451
        break;
9a84451
+     case DW_FORM_GNU_strp_alt:
9a84451
+       attr->u.str = read_alt_indirect_string (unit, info_ptr, &bytes_read);
9a84451
+       info_ptr += bytes_read;
9a84451
+       break;
9a84451
      case DW_FORM_exprloc:
9a84451
      case DW_FORM_block:
9a84451
        amt = sizeof (struct dwarf_block);
9a84451
*************** find_abstract_instance_name (struct comp
9a84451
*** 2006,2011 ****
9a84451
--- 2125,2141 ----
9a84451
  
9a84451
        info_ptr = unit->sec_info_ptr + die_ref;
9a84451
      }
9a84451
+   else if (attr_ptr->form == DW_FORM_GNU_ref_alt)
9a84451
+     {
9a84451
+       info_ptr = read_alt_indirect_ref (unit, die_ref);
9a84451
+       if (info_ptr == NULL)
9a84451
+ 	{
9a84451
+ 	  (*_bfd_error_handler)
9a84451
+ 	    (_("Dwarf Error: Unable to read alt ref %u."), die_ref);
9a84451
+ 	  bfd_set_error (bfd_error_bad_value);
9a84451
+ 	  return name;
9a84451
+ 	}
9a84451
+     }
9a84451
    else 
9a84451
      info_ptr = unit->info_ptr_unit + die_ref;
9a84451
    abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9a84451
*************** _bfd_dwarf2_cleanup_debug_info (bfd *abf
9a84451
*** 3720,3723 ****
9a84451
--- 3850,3859 ----
9a84451
      free (stash->dwarf_ranges_buffer);
9a84451
    if (stash->info_ptr_memory)
9a84451
      free (stash->info_ptr_memory);
9a84451
+   if (stash->alt_dwarf_str_buffer)
9a84451
+     free (stash->alt_dwarf_str_buffer);
9a84451
+   if (stash->alt_dwarf_info_buffer)
9a84451
+     free (stash->alt_dwarf_info_buffer);
9a84451
+   if (stash->alt_bfd_ptr)
9a84451
+     bfd_close (stash->alt_bfd_ptr);
9a84451
  }
9a84451
diff -rcp ../binutils-2.23.2.orig/bfd/opncls.c bfd/opncls.c
9a84451
*** ../binutils-2.23.2.orig/bfd/opncls.c	2013-05-29 15:55:59.990051098 +0100
9a84451
--- bfd/opncls.c	2013-05-29 16:01:00.052059415 +0100
9a84451
*************** bfd_release (bfd *abfd, void *block)
9a84451
*** 1056,1065 ****
9a84451
  
9a84451
     This facilitates "optional" provision of debugging information, without
9a84451
     having to provide two complete copies of every binary object (with and
9a84451
!    without debug symbols).
9a84451
! */
9a84451
  
9a84451
- #define GNU_DEBUGLINK	".gnu_debuglink"
9a84451
  /*
9a84451
  FUNCTION
9a84451
  	bfd_calc_gnu_debuglink_crc32
9a84451
--- 1056,1066 ----
9a84451
  
9a84451
     This facilitates "optional" provision of debugging information, without
9a84451
     having to provide two complete copies of every binary object (with and
9a84451
!    without debug symbols).  */
9a84451
! 
9a84451
! #define GNU_DEBUGLINK		".gnu_debuglink"
9a84451
! #define GNU_DEBUGALTLINK	".gnu_debugaltlink"
9a84451
  
9a84451
  /*
9a84451
  FUNCTION
9a84451
  	bfd_calc_gnu_debuglink_crc32
9a84451
*************** get_debug_link_info (bfd *abfd, unsigned
9a84451
*** 1195,1200 ****
9a84451
--- 1196,1249 ----
9a84451
  }
9a84451
  
9a84451
  /*
9a84451
+ FUNCTION
9a84451
+ 	bfd_get_alt_debug_link_info
9a84451
+ 
9a84451
+ SYNOPSIS
9a84451
+ 	char *bfd_get_alt_debug_link_info (bfd *abfd, unsigned long *crc32_out);
9a84451
+ 
9a84451
+ DESCRIPTION
9a84451
+ 	Fetch the filename and BuildID value for any alternate debuginfo
9a84451
+ 	associated with @var{abfd}.  Return NULL if no such info found,
9a84451
+ 	otherwise return filename and update @var{buildid_out}.  The
9a84451
+ 	returned filename is allocated with @code{malloc}; freeing it
9a84451
+ 	is the responsibility of the caller.
9a84451
+ */
9a84451
+ 
9a84451
+ char *
9a84451
+ bfd_get_alt_debug_link_info (bfd * abfd, unsigned long * buildid_out)
9a84451
+ {
9a84451
+   asection *sect;
9a84451
+   bfd_byte *contents;
9a84451
+   int buildid_offset;
9a84451
+   char *name;
9a84451
+ 
9a84451
+   BFD_ASSERT (abfd);
9a84451
+   BFD_ASSERT (buildid_out);
9a84451
+ 
9a84451
+   sect = bfd_get_section_by_name (abfd, GNU_DEBUGALTLINK);
9a84451
+ 
9a84451
+   if (sect == NULL)
9a84451
+     return NULL;
9a84451
+ 
9a84451
+   if (!bfd_malloc_and_get_section (abfd, sect, & contents))
9a84451
+     {
9a84451
+       if (contents != NULL)
9a84451
+ 	free (contents);
9a84451
+       return NULL;
9a84451
+     }
9a84451
+ 
9a84451
+   /* BuildID value is stored after the filename, aligned up to 4 bytes.  */
9a84451
+   name = (char *) contents;
9a84451
+   buildid_offset = strlen (name) + 1;
9a84451
+   buildid_offset = (buildid_offset + 3) & ~3;
9a84451
+ 
9a84451
+   * buildid_out = bfd_get_32 (abfd, contents + buildid_offset);
9a84451
+ 
9a84451
+   return name;
9a84451
+ }
9a84451
+ 
9a84451
+ /*
9a84451
  INTERNAL_FUNCTION
9a84451
  	separate_debug_file_exists
9a84451
  
9a84451
*************** separate_debug_file_exists (const char *
9a84451
*** 1229,1234 ****
9a84451
--- 1278,1314 ----
9a84451
    return crc == file_crc;
9a84451
  }
9a84451
  
9a84451
+ /*
9a84451
+ INTERNAL_FUNCTION
9a84451
+ 	separate_alt_debug_file_exists
9a84451
+ 
9a84451
+ SYNOPSIS
9a84451
+ 	bfd_boolean separate_alt_debug_file_exists
9a84451
+ 	  (char *name, unsigned long crc32);
9a84451
+ 
9a84451
+ DESCRIPTION
9a84451
+ 	Checks to see if @var{name} is a file and if its BuildID
9a84451
+ 	matches @var{buildid}.
9a84451
+ */
9a84451
+ 
9a84451
+ static bfd_boolean
9a84451
+ separate_alt_debug_file_exists (const char *name,
9a84451
+ 				const unsigned long buildid ATTRIBUTE_UNUSED)
9a84451
+ {
9a84451
+   FILE *f;
9a84451
+ 
9a84451
+   BFD_ASSERT (name);
9a84451
+ 
9a84451
+   f = real_fopen (name, FOPEN_RB);
9a84451
+   if (f == NULL)
9a84451
+     return FALSE;
9a84451
+ 
9a84451
+   /* FIXME: Add code to check buildid.  */
9a84451
+ 
9a84451
+   fclose (f);
9a84451
+ 
9a84451
+   return TRUE;
9a84451
+ }
9a84451
  
9a84451
  /*
9a84451
  INTERNAL_FUNCTION
9a84451
*************** SYNOPSIS
9a84451
*** 1238,1253 ****
9a84451
  	char *find_separate_debug_file (bfd *abfd);
9a84451
  
9a84451
  DESCRIPTION
9a84451
! 	Searches @var{abfd} for a reference to separate debugging
9a84451
! 	information, scans various locations in the filesystem, including
9a84451
! 	the file tree rooted at @var{debug_file_directory}, and returns a
9a84451
! 	filename of such debugging information if the file is found and has
9a84451
! 	matching CRC32.  Returns NULL if no reference to debugging file
9a84451
! 	exists, or file cannot be found.
9a84451
  */
9a84451
  
9a84451
  static char *
9a84451
! find_separate_debug_file (bfd *abfd, const char *debug_file_directory)
9a84451
  {
9a84451
    char *base;
9a84451
    char *dir;
9a84451
--- 1318,1341 ----
9a84451
  	char *find_separate_debug_file (bfd *abfd);
9a84451
  
9a84451
  DESCRIPTION
9a84451
! 	Searches @var{abfd} for a section called @var{section_name} which
9a84451
! 	is expected to contain a reference to a file containing separate
9a84451
! 	debugging information.  The function scans various locations in
9a84451
! 	the filesystem, including the file tree rooted at
9a84451
! 	@var{debug_file_directory}, and returns the first matching
9a84451
! 	filename that it finds.  If @var{check_crc} is TRUE then the
9a84451
! 	contents of the file must also match the CRC value contained in
9a84451
! 	@var{section_name}.  Returns NULL if no valid file could be found.
9a84451
  */
9a84451
  
9a84451
+ typedef char *      (* get_func_type) (bfd *, unsigned long *);
9a84451
+ typedef bfd_boolean (* check_func_type) (const char *, const unsigned long);
9a84451
+ 
9a84451
  static char *
9a84451
! find_separate_debug_file (bfd *           abfd,
9a84451
! 			  const char *    debug_file_directory,
9a84451
! 			  get_func_type   get_func,
9a84451
! 			  check_func_type check_func)
9a84451
  {
9a84451
    char *base;
9a84451
    char *dir;
9a84451
*************** find_separate_debug_file (bfd *abfd, con
9a84451
*** 1268,1274 ****
9a84451
        return NULL;
9a84451
      }
9a84451
  
9a84451
!   base = get_debug_link_info (abfd, & crc32);
9a84451
    if (base == NULL)
9a84451
      return NULL;
9a84451
  
9a84451
--- 1356,1362 ----
9a84451
        return NULL;
9a84451
      }
9a84451
  
9a84451
!   base = get_func (abfd, & crc32);
9a84451
    if (base == NULL)
9a84451
      return NULL;
9a84451
  
9a84451
*************** find_separate_debug_file (bfd *abfd, con
9a84451
*** 1309,1345 ****
9a84451
                    + strlen (base)
9a84451
                    + 1);
9a84451
    if (debugfile == NULL)
9a84451
!     {
9a84451
!       free (base);
9a84451
!       free (dir);
9a84451
!       free (canon_dir);
9a84451
!       return NULL;
9a84451
!     }
9a84451
  
9a84451
    /* First try in the same directory as the original file:  */
9a84451
    strcpy (debugfile, dir);
9a84451
    strcat (debugfile, base);
9a84451
  
9a84451
!   if (separate_debug_file_exists (debugfile, crc32))
9a84451
!     {
9a84451
!       free (base);
9a84451
!       free (dir);
9a84451
!       free (canon_dir);
9a84451
!       return debugfile;
9a84451
!     }
9a84451
  
9a84451
    /* Then try in a subdirectory called .debug.  */
9a84451
    strcpy (debugfile, dir);
9a84451
    strcat (debugfile, ".debug/");
9a84451
    strcat (debugfile, base);
9a84451
  
9a84451
!   if (separate_debug_file_exists (debugfile, crc32))
9a84451
!     {
9a84451
!       free (base);
9a84451
!       free (dir);
9a84451
!       free (canon_dir);
9a84451
!       return debugfile;
9a84451
!     }
9a84451
  
9a84451
    /* Then try in the global debug dir for Fedora libraries.  */
9a84451
    sprintf (debugfile, "%s%s%s", FEDORA_LIB_DEBUG_DIR, dir, base);
9a84451
--- 1397,1418 ----
9a84451
                    + strlen (base)
9a84451
                    + 1);
9a84451
    if (debugfile == NULL)
9a84451
!     goto found; /* Actually this returns NULL.  */
9a84451
  
9a84451
    /* First try in the same directory as the original file:  */
9a84451
    strcpy (debugfile, dir);
9a84451
    strcat (debugfile, base);
9a84451
  
9a84451
!   if (check_func (debugfile, crc32))
9a84451
!     goto found;
9a84451
  
9a84451
    /* Then try in a subdirectory called .debug.  */
9a84451
    strcpy (debugfile, dir);
9a84451
    strcat (debugfile, ".debug/");
9a84451
    strcat (debugfile, base);
9a84451
  
9a84451
!   if (check_func (debugfile, crc32))
9a84451
!     goto found;
9a84451
  
9a84451
    /* Then try in the global debug dir for Fedora libraries.  */
9a84451
    sprintf (debugfile, "%s%s%s", FEDORA_LIB_DEBUG_DIR, dir, base);
9a84451
*************** find_separate_debug_file (bfd *abfd, con
9a84451
*** 1371,1389 ****
9a84451
    strcat (debugfile, canon_dir);
9a84451
    strcat (debugfile, base);
9a84451
  
9a84451
!   if (separate_debug_file_exists (debugfile, crc32))
9a84451
!     {
9a84451
!       free (base);
9a84451
!       free (dir);
9a84451
!       free (canon_dir);
9a84451
!       return debugfile;
9a84451
!     }
9a84451
  
9a84451
    free (debugfile);
9a84451
    free (base);
9a84451
    free (dir);
9a84451
    free (canon_dir);
9a84451
!   return NULL;
9a84451
  }
9a84451
  
9a84451
  
9a84451
--- 1444,1461 ----
9a84451
    strcat (debugfile, canon_dir);
9a84451
    strcat (debugfile, base);
9a84451
  
9a84451
!   if (check_func (debugfile, crc32))
9a84451
!     goto found;
9a84451
  
9a84451
+   /* Failed to find the file.  */
9a84451
    free (debugfile);
9a84451
+   debugfile = NULL;
9a84451
+ 
9a84451
+  found:
9a84451
    free (base);
9a84451
    free (dir);
9a84451
    free (canon_dir);
9a84451
!   return debugfile;
9a84451
  }
9a84451
  
9a84451
  
9a84451
*************** RETURNS
9a84451
*** 1416,1422 ****
9a84451
  char *
9a84451
  bfd_follow_gnu_debuglink (bfd *abfd, const char *dir)
9a84451
  {
9a84451
!   return find_separate_debug_file (abfd, dir);
9a84451
  }
9a84451
  
9a84451
  /*
9a84451
--- 1488,1530 ----
9a84451
  char *
9a84451
  bfd_follow_gnu_debuglink (bfd *abfd, const char *dir)
9a84451
  {
9a84451
!   return find_separate_debug_file (abfd, dir,
9a84451
! 				   get_debug_link_info,
9a84451
! 				   separate_debug_file_exists);
9a84451
! }
9a84451
! 
9a84451
! /*
9a84451
! FUNCTION
9a84451
! 	bfd_follow_gnu_debugaltlink
9a84451
! 
9a84451
! SYNOPSIS
9a84451
! 	char *bfd_follow_gnu_debugaltlink (bfd *abfd, const char *dir);
9a84451
! 
9a84451
! DESCRIPTION
9a84451
! 
9a84451
! 	Takes a BFD and searches it for a .gnu_debugaltlink section.  If this
9a84451
! 	section is found, it examines the section for the name of a file
9a84451
! 	containing auxiliary debugging information.  It	then searches the
9a84451
! 	filesystem for this file in a set of standard locations, including
9a84451
! 	the directory tree rooted at @var{dir}, and if found returns the
9a84451
! 	full filename.
9a84451
! 
9a84451
! 	If @var{dir} is NULL, it will search a default path configured into
9a84451
! 	libbfd at build time.  [FIXME: This feature is not currently
9a84451
! 	implemented].
9a84451
! 
9a84451
! RETURNS
9a84451
! 	<<NULL>> on any errors or failure to locate the debug file,
9a84451
! 	otherwise a pointer to a heap-allocated string containing the
9a84451
! 	filename.  The caller is responsible for freeing this string.
9a84451
! */
9a84451
! 
9a84451
! char *
9a84451
! bfd_follow_gnu_debugaltlink (bfd *abfd, const char *dir)
9a84451
! {
9a84451
!   return find_separate_debug_file (abfd, dir,
9a84451
! 				   bfd_get_alt_debug_link_info,
9a84451
! 				   separate_alt_debug_file_exists);
9a84451
  }
9a84451
  
9a84451
  /*
9a84451