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

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