2e9b04
--- binutils.orig/binutils/dwarf.c	2020-10-15 12:13:21.960799738 +0100
2e9b04
+++ binutils-2.35.1/binutils/dwarf.c	2020-10-15 13:02:39.454692627 +0100
2e9b04
@@ -10427,7 +10427,7 @@ load_separate_debug_info (const char *
2e9b04
     {
2e9b04
       warn (_("Corrupt debuglink section: %s\n"),
2e9b04
 	    xlink->name ? xlink->name : xlink->uncompressed_name);
2e9b04
-      return FALSE;
2e9b04
+      return NULL;
2e9b04
     }
2e9b04
     
2e9b04
   /* Attempt to locate the separate file.
2e9b04
@@ -10587,7 +10587,7 @@ load_separate_debug_info (const char *
2e9b04
     {
2e9b04
       warn (_("failed to open separate debug file: %s\n"), debug_filename);
2e9b04
       free (debug_filename);
2e9b04
-      return FALSE;
2e9b04
+      return NULL;
2e9b04
     }
2e9b04
 
2e9b04
   /* FIXME: We do not check to see if there are any other separate debug info
2e9b04
@@ -10632,6 +10632,52 @@ load_dwo_file (const char * main_filenam
2e9b04
   return separate_handle;
2e9b04
 }
2e9b04
 
2e9b04
+/* Load a debuglink section and/or a debugaltlink section, if either are present.
2e9b04
+   Recursively check the loaded files for more of these sections.
2e9b04
+   FIXME: Should also check for DWO_* entries in the newlu loaded files.  */
2e9b04
+
2e9b04
+static void
2e9b04
+check_for_and_load_links (void * file, const char * filename)
2e9b04
+{
2e9b04
+  void * handle = NULL;
2e9b04
+
2e9b04
+  if (load_debug_section (gnu_debugaltlink, file))
2e9b04
+    {
2e9b04
+      Build_id_data build_id_data;
2e9b04
+
2e9b04
+      handle = load_separate_debug_info (filename,
2e9b04
+					 & debug_displays[gnu_debugaltlink].section,
2e9b04
+					 parse_gnu_debugaltlink,
2e9b04
+					 check_gnu_debugaltlink,
2e9b04
+					 & build_id_data,
2e9b04
+					 file);
2e9b04
+      if (handle)
2e9b04
+	{
2e9b04
+	  assert (handle == first_separate_info->handle);
2e9b04
+	  check_for_and_load_links (first_separate_info->handle,
2e9b04
+				    first_separate_info->filename);
2e9b04
+	}
2e9b04
+    }
2e9b04
+
2e9b04
+  if (load_debug_section (gnu_debuglink, file))
2e9b04
+    {
2e9b04
+      unsigned long crc32;
2e9b04
+
2e9b04
+      handle = load_separate_debug_info (filename,
2e9b04
+					 & debug_displays[gnu_debuglink].section,
2e9b04
+					 parse_gnu_debuglink,
2e9b04
+					 check_gnu_debuglink,
2e9b04
+					 & crc32,
2e9b04
+					 file);
2e9b04
+      if (handle)
2e9b04
+	{
2e9b04
+	  assert (handle == first_separate_info->handle);
2e9b04
+	  check_for_and_load_links (first_separate_info->handle,
2e9b04
+				    first_separate_info->filename);
2e9b04
+	}
2e9b04
+    }
2e9b04
+}
2e9b04
+
2e9b04
 /* Load the separate debug info file(s) attached to FILE, if any exist.
2e9b04
    Returns TRUE if any were found, FALSE otherwise.
2e9b04
    If TRUE is returned then the linked list starting at first_separate_info
2e9b04
@@ -10707,34 +10753,10 @@ load_separate_debug_files (void * file,
2e9b04
     return FALSE;
2e9b04
 
2e9b04
   /* FIXME: We do not check for the presence of both link sections in the same file.  */
2e9b04
-  /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks.  */
2e9b04
   /* FIXME: We do not check for the presence of multiple, same-name debuglink sections.  */
2e9b04
   /* FIXME: We do not check for the presence of a dwo link as well as a debuglink.  */
2e9b04
 
2e9b04
-  if (load_debug_section (gnu_debugaltlink, file))
2e9b04
-    {
2e9b04
-      Build_id_data * build_id_data;
2e9b04
-
2e9b04
-      load_separate_debug_info (filename,
2e9b04
-				& debug_displays[gnu_debugaltlink].section,
2e9b04
-				parse_gnu_debugaltlink,
2e9b04
-				check_gnu_debugaltlink,
2e9b04
-				& build_id_data,
2e9b04
-				file);
2e9b04
-    }
2e9b04
-
2e9b04
-  if (load_debug_section (gnu_debuglink, file))
2e9b04
-    {
2e9b04
-      unsigned long crc32;
2e9b04
-
2e9b04
-      load_separate_debug_info (filename,
2e9b04
-				& debug_displays[gnu_debuglink].section,
2e9b04
-				parse_gnu_debuglink,
2e9b04
-				check_gnu_debuglink,
2e9b04
-				& crc32,
2e9b04
-				file);
2e9b04
-    }
2e9b04
-
2e9b04
+  check_for_and_load_links (file, filename);
2e9b04
   if (first_separate_info != NULL)
2e9b04
     return TRUE;
2e9b04