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

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