Blame SOURCES/binutils-do-not-use-debuginfod.patch

fcd040
diff -rupN --no-dereference binutils-2.38/binutils/doc/binutils.texi binutils-2.38-new/binutils/doc/binutils.texi
fcd040
--- binutils-2.38/binutils/doc/binutils.texi	2022-01-22 13:14:07.000000000 +0100
fcd040
+++ binutils-2.38-new/binutils/doc/binutils.texi	2022-04-26 13:55:05.297550720 +0200
fcd040
@@ -2246,6 +2246,8 @@ objdump [@option{-a}|@option{--archive-h
fcd040
          @option{--dwarf}[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,=trace_info,=trace_abbrev,=trace_aranges,=gdb_index,=addr,=cu_index,=links]]
fcd040
         [@option{-WK}|@option{--dwarf=follow-links}]
fcd040
         [@option{-WN}|@option{--dwarf=no-follow-links}]
fcd040
+        [@option{-wD}|@option{--dwarf=use-debuginfod}]
fcd040
+        [@option{-wE}|@option{--dwarf=do-not-use-debuginfod}]
fcd040
         [@option{-L}|@option{--process-links}]
fcd040
         [@option{--ctf=}@var{section}]
fcd040
         [@option{-G}|@option{--stabs}]
fcd040
@@ -4879,6 +4881,8 @@ readelf [@option{-a}|@option{--all}]
fcd040
          @option{--debug-dump}[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,=trace_info,=trace_abbrev,=trace_aranges,=gdb_index,=addr,=cu_index,=links]]
fcd040
         [@option{-wK}|@option{--debug-dump=follow-links}]
fcd040
         [@option{-wN}|@option{--debug-dump=no-follow-links}]
fcd040
+        [@option{-wD}|@option{--debug-dump=use-debuginfod}]
fcd040
+        [@option{-wE}|@option{--debug-dump=do-not-use-debuginfod}]
fcd040
         [@option{-P}|@option{--process-links}]
fcd040
         [@option{--dwarf-depth=@var{n}}]
fcd040
         [@option{--dwarf-start=@var{n}}]
fcd040
@@ -5504,7 +5508,8 @@ deduced from the input file
fcd040
 @cindex separate debug files
fcd040
 
fcd040
 debuginfod is a web service that indexes ELF/DWARF debugging resources
fcd040
-by build-id and serves them over HTTP.
fcd040
+by build-id and serves them over HTTP.  For more information see:
fcd040
+@emph{https://sourceware.org/elfutils/Debuginfod.html}
fcd040
 
fcd040
 Binutils can be built with the debuginfod client library
fcd040
 @code{libdebuginfod} using the @option{--with-debuginfod} configure option.
fcd040
@@ -5516,6 +5521,10 @@ separate debug files when the files are
fcd040
 debuginfod is packaged with elfutils, starting with version 0.178.
fcd040
 You can get the latest version from `https://sourceware.org/elfutils/'.
fcd040
 
fcd040
+The DWARF info dumping tools (@command{readelf} and @command{objdump})
fcd040
+have options to control when they should access the debuginfod
fcd040
+servers.  By default this access is enabled.
fcd040
+
fcd040
 @node Reporting Bugs
fcd040
 @chapter Reporting Bugs
fcd040
 @cindex bugs
fcd040
diff -rupN --no-dereference binutils-2.38/binutils/doc/debug.options.texi binutils-2.38-new/binutils/doc/debug.options.texi
fcd040
--- binutils-2.38/binutils/doc/debug.options.texi	2022-01-22 13:14:07.000000000 +0100
fcd040
+++ binutils-2.38-new/binutils/doc/debug.options.texi	2022-04-26 13:55:05.298550721 +0200
fcd040
@@ -68,10 +68,27 @@ chosen when configuring the binutils via
fcd040
 @option{--enable-follow-debug-links=no} options.  If these are not
fcd040
 used then the default is to enable the following of debug links.
fcd040
 
fcd040
+Note - if support for the debuginfod protocol was enabled when the
fcd040
+binutils were built then this option will also include an attempt to
fcd040
+contact any debuginfod servers mentioned in the @var{DEBUGINFOD_URLS}
fcd040
+environment variable.  This could take some time to resolve.  This
fcd040
+behaviour can be disabled via the @option{=do-not-use-debuginfod} debug
fcd040
+option.
fcd040
+
fcd040
 @item N
fcd040
 @itemx =no-follow-links
fcd040
 Disables the following of links to separate debug info files.
fcd040
 
fcd040
+@item D
fcd040
+@itemx =use-debuginfod
fcd040
+Enables contacting debuginfod servers if there is a need to follow
fcd040
+debug links.  This is the default behaviour.
fcd040
+
fcd040
+@item E
fcd040
+@itemx =do-not-use-debuginfod
fcd040
+Disables contacting debuginfod servers when there is a need to follow
fcd040
+debug links.
fcd040
+
fcd040
 @item l
fcd040
 @itemx =rawline
fcd040
 Displays the contents of the @samp{.debug_line} section in a raw
fcd040
diff -rupN --no-dereference binutils-2.38/binutils/dwarf.c binutils-2.38-new/binutils/dwarf.c
fcd040
--- binutils-2.38/binutils/dwarf.c	2022-01-22 13:14:07.000000000 +0100
fcd040
+++ binutils-2.38-new/binutils/dwarf.c	2022-04-26 13:55:05.299550722 +0200
fcd040
@@ -109,6 +109,9 @@ int do_debug_cu_index;
fcd040
 int do_wide;
fcd040
 int do_debug_links;
fcd040
 int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS;
fcd040
+#ifdef HAVE_LIBDEBUGINFOD
fcd040
+int use_debuginfod = 1;
fcd040
+#endif
fcd040
 bool do_checks;
fcd040
 
fcd040
 int dwarf_cutoff_level = -1;
fcd040
@@ -11038,7 +11041,7 @@ debuginfod_fetch_separate_debug_info (st
fcd040
 
fcd040
   return false;
fcd040
 }
fcd040
-#endif
fcd040
+#endif /* HAVE_LIBDEBUGINFOD  */
fcd040
 
fcd040
 static void *
fcd040
 load_separate_debug_info (const char *            main_filename,
fcd040
@@ -11157,9 +11160,10 @@ load_separate_debug_info (const char *
fcd040
   {
fcd040
     char * tmp_filename;
fcd040
 
fcd040
-    if (debuginfod_fetch_separate_debug_info (xlink,
fcd040
-                                              & tmp_filename,
fcd040
-                                              file))
fcd040
+    if (use_debuginfod
fcd040
+	&& debuginfod_fetch_separate_debug_info (xlink,
fcd040
+						 & tmp_filename,
fcd040
+						 file))
fcd040
       {
fcd040
         /* File successfully downloaded from server, replace
fcd040
            debug_filename with the file's path.  */
fcd040
@@ -11207,13 +11211,15 @@ load_separate_debug_info (const char *
fcd040
       warn (_("tried: %s\n"), debug_filename);
fcd040
 
fcd040
 #if HAVE_LIBDEBUGINFOD
fcd040
-      {
fcd040
-	char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR);
fcd040
-	if (urls == NULL)
fcd040
-	  urls = "";
fcd040
+      if (use_debuginfod)
fcd040
+	{
fcd040
+	  char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR);
fcd040
 
fcd040
-	warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls);
fcd040
-      }
fcd040
+	  if (urls == NULL)
fcd040
+	    urls = "";
fcd040
+
fcd040
+	  warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls);
fcd040
+	}
fcd040
 #endif
fcd040
     }
fcd040
 
fcd040
@@ -11707,6 +11713,9 @@ dwarf_select_sections_by_names (const ch
fcd040
       { "aranges", & do_debug_aranges, 1 },
fcd040
       { "cu_index", & do_debug_cu_index, 1 },
fcd040
       { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
fcd040
+#ifdef HAVE_LIBDEBUGINFOD
fcd040
+      { "do-not-use-debuginfod", & use_debuginfod, 0 },
fcd040
+#endif
fcd040
       { "follow-links", & do_follow_links, 1 },
fcd040
       { "frames", & do_debug_frames, 1 },
fcd040
       { "frames-interp", & do_debug_frames_interp, 1 },
fcd040
@@ -11730,6 +11739,9 @@ dwarf_select_sections_by_names (const ch
fcd040
       { "trace_abbrev", & do_trace_abbrevs, 1 },
fcd040
       { "trace_aranges", & do_trace_aranges, 1 },
fcd040
       { "trace_info", & do_trace_info, 1 },
fcd040
+#ifdef HAVE_LIBDEBUGINFOD
fcd040
+      { "use-debuginfod", & use_debuginfod, 1 },
fcd040
+#endif
fcd040
       { NULL, NULL, 0 }
fcd040
     };
fcd040
 
fcd040
@@ -11783,6 +11795,10 @@ dwarf_select_sections_by_letters (const
fcd040
       case 'A':	do_debug_addr = 1; break;
fcd040
       case 'a':	do_debug_abbrevs = 1; break;
fcd040
       case 'c':	do_debug_cu_index = 1; break;
fcd040
+#ifdef HAVE_LIBDEBUGINFOD
fcd040
+      case 'D': use_debuginfod = 1; break;
fcd040
+      case 'E': use_debuginfod = 0; break;
fcd040
+#endif
fcd040
       case 'F':	do_debug_frames_interp = 1; /* Fall through.  */
fcd040
       case 'f':	do_debug_frames = 1; break;
fcd040
       case 'g':	do_gdb_index = 1; break;
fcd040
diff -rupN --no-dereference binutils-2.38/binutils/dwarf.h binutils-2.38-new/binutils/dwarf.h
fcd040
--- binutils-2.38/binutils/dwarf.h	2022-01-22 13:14:07.000000000 +0100
fcd040
+++ binutils-2.38-new/binutils/dwarf.h	2022-04-26 13:55:05.299550722 +0200
fcd040
@@ -224,6 +224,9 @@ extern int do_debug_cu_index;
fcd040
 extern int do_wide;
fcd040
 extern int do_debug_links;
fcd040
 extern int do_follow_links;
fcd040
+#ifdef HAVE_LIBDEBUGINFOD
fcd040
+extern int use_debuginfod;
fcd040
+#endif
fcd040
 extern bool do_checks;
fcd040
 
fcd040
 extern int dwarf_cutoff_level;
fcd040
diff -rupN --no-dereference binutils-2.38/binutils/NEWS binutils-2.38-new/binutils/NEWS
fcd040
--- binutils-2.38/binutils/NEWS	2022-01-22 13:14:07.000000000 +0100
fcd040
+++ binutils-2.38-new/binutils/NEWS	2022-04-26 13:55:05.297550720 +0200
fcd040
@@ -1,5 +1,8 @@
fcd040
 -*- text -*-
fcd040
 
fcd040
+* Add an option to objdump and readelf to prevent attempts to access debuginfod
fcd040
+  servers when following links.
fcd040
+
fcd040
 Changes in 2.38:
fcd040
 
fcd040
 * elfedit: Add --output-abiversion option to update ABIVERSION.
fcd040
diff -rupN --no-dereference binutils-2.38/binutils/objdump.c binutils-2.38-new/binutils/objdump.c
fcd040
--- binutils-2.38/binutils/objdump.c	2022-01-22 13:14:07.000000000 +0100
fcd040
+++ binutils-2.38-new/binutils/objdump.c	2022-04-26 13:55:05.300550724 +0200
fcd040
@@ -281,6 +281,14 @@ usage (FILE *stream, int status)
fcd040
                            Do not follow links to separate debug info files\n\
fcd040
                             (default)\n"));
fcd040
 #endif
fcd040
+#if HAVE_LIBDEBUGINFOD
fcd040
+  fprintf (stream, _("\
fcd040
+  -WD --dwarf=use-debuginfod\n\
fcd040
+                           When following links, also query debuginfod servers (default)\n"));
fcd040
+  fprintf (stream, _("\
fcd040
+  -WE --dwarf=do-not-use-debuginfod\n\
fcd040
+                           When following links, do not query debuginfod servers\n"));
fcd040
+#endif
fcd040
   fprintf (stream, _("\
fcd040
   -L, --process-links      Display the contents of non-debug sections in\n\
fcd040
                             separate debuginfo files.  (Implies -WK)\n"));
fcd040
diff -rupN --no-dereference binutils-2.38/binutils/readelf.c binutils-2.38-new/binutils/readelf.c
fcd040
--- binutils-2.38/binutils/readelf.c	2022-04-26 13:54:52.269532121 +0200
fcd040
+++ binutils-2.38-new/binutils/readelf.c	2022-04-26 13:55:05.303550728 +0200
fcd040
@@ -5126,6 +5126,14 @@ usage (FILE * stream)
fcd040
                          Do not follow links to separate debug info files\n\
fcd040
                           (default)\n"));
fcd040
 #endif
fcd040
+#if HAVE_LIBDEBUGINFOD
fcd040
+  fprintf (stream, _("\
fcd040
+  -wD --debug-dump=use-debuginfod\n\
fcd040
+                         When following links, also query debuginfod servers (default)\n"));
fcd040
+  fprintf (stream, _("\
fcd040
+  -wE --debug-dump=do-not-use-debuginfod\n\
fcd040
+                         When following links, do not query debuginfod servers\n"));
fcd040
+#endif
fcd040
   fprintf (stream, _("\
fcd040
   --dwarf-depth=N        Do not display DIEs at depth N or greater\n"));
fcd040
   fprintf (stream, _("\
fcd040
diff -rupN --no-dereference binutils-2.38/binutils/testsuite/binutils-all/debuginfod.exp binutils-2.38-new/binutils/testsuite/binutils-all/debuginfod.exp
fcd040
--- binutils-2.38/binutils/testsuite/binutils-all/debuginfod.exp	2022-01-22 13:14:07.000000000 +0100
fcd040
+++ binutils-2.38-new/binutils/testsuite/binutils-all/debuginfod.exp	2022-04-26 13:55:05.303550728 +0200
fcd040
@@ -185,8 +185,14 @@ proc test_fetch_debugaltlink { prog prog
fcd040
 }
fcd040
 
fcd040
 if { [regexp ".*DEBUGINFOD.*" $conf_objdump] } {
fcd040
-    test_fetch_debuglink $OBJDUMP "-W"
fcd040
+    test_fetch_debuglink $OBJDUMP "-W -WD"
fcd040
     test_fetch_debugaltlink $OBJDUMP "-Wk"
fcd040
+
fcd040
+    set test "disabling debuginfod access"
fcd040
+    setup_xfail *-*-*
fcd040
+    test_fetch_debuglink $OBJDUMP "-W -WE"
fcd040
+    set test "debuginfod"
fcd040
+
fcd040
 } else {
fcd040
     untested "$test (objdump not configured with debuginfod)"
fcd040
 }
fcd040
@@ -194,6 +200,12 @@ if { [regexp ".*DEBUGINFOD.*" $conf_objd
fcd040
 if { [regexp ".*DEBUGINFOD.*" $conf_readelf] } {
fcd040
     test_fetch_debuglink $READELF "-w"
fcd040
     test_fetch_debugaltlink $READELF "-wk"
fcd040
+
fcd040
+    set test "disabling debuginfod access"
fcd040
+    setup_xfail *-*-*
fcd040
+    test_fetch_debuglink $READELF "-w -wE"
fcd040
+    set test "debuginfod"
fcd040
+
fcd040
 } else {
fcd040
     untested "$test (readelf not configured with debuginfod)"
fcd040
 }